Files
babel/scripts/pack-script.js
T
renovate[bot]GitHubrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>Huáng Jùnliàng
3c32f3fa65 chore(deps): update dependency execa to v9 and bump Makefile.js targets (#16662)
* chore(deps): update dependency execa to v9

* add pack-script to post upgrade tasks

* update artifacts

* pin get-stream to 8.0.1

* bump makefile.js targets

* update artifacts

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Huáng Jùnliàng <[email protected]>
2024-07-24 11:09:23 -04:00

68 lines
1.8 KiB
JavaScript

import path from "path";
import { readFileSync, writeFileSync } from "fs";
import { rollup } from "rollup";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { babel } from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser";
import { commonJS } from "$repo-utils";
import { createHash } from "crypto";
const { __dirname, require } = commonJS(import.meta.url);
pack("../Makefile.source.mjs", "../Makefile.js", [
"node_modules/shelljs/src/*.js",
]);
async function pack(inputPath, outputPath, dynamicRequireTargets) {
inputPath = path.join(__dirname, inputPath);
outputPath = path.join(__dirname, outputPath);
const hash = createHash("sha1")
.update(readFileSync(inputPath, "utf8"))
.digest("hex");
if (process.argv[2] === "--auto") {
if (readFileSync(outputPath, "utf8").includes(hash)) {
return;
}
}
const bundle = await rollup({
input: inputPath,
plugins: [
nodeResolve({ preferBuiltins: true }),
commonjs({
dynamicRequireTargets: dynamicRequireTargets,
}),
babel({
babelrc: false,
babelHelpers: "bundled",
exclude: ["node_modules/core-js/**"],
parserOpts: { sourceType: "module" },
presets: [
[
"@babel/preset-env",
{
targets: "maintained node versions",
useBuiltIns: "usage",
corejs: require("core-js/package.json").version,
},
],
],
}),
terser(),
],
});
const result = await bundle.generate({
format: "cjs",
});
const output = `// source hash: ${hash}
/* eslint-disable */
// prettier-ignore
${result.output[0].code}`;
writeFileSync(outputPath, output);
}