mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* chore: bump rollup plugins * fix: resolve from "node" exports * bump rollup-plugin-commonjs Also patched for ES5 compatibility required by babel-standalone * fix: dynamicRequireTargets accepts relative path * update artifact
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import path from "node:path";
|
|
import { readFileSync, writeFileSync } from "node: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 "node:crypto";
|
|
|
|
const { __dirname, require } = commonJS(import.meta.url);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
pack("../Makefile.source.ts", "../Makefile.js", [
|
|
"node_modules/shelljs/src/*.js",
|
|
]);
|
|
|
|
async function pack(
|
|
inputPath: string,
|
|
outputPath: string,
|
|
dynamicRequireTargets: string[]
|
|
) {
|
|
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({ exportConditions: ["node"], preferBuiltins: true }),
|
|
commonjs({
|
|
dynamicRequireTargets: dynamicRequireTargets,
|
|
}),
|
|
babel({
|
|
extensions: [".ts"],
|
|
babelrc: false,
|
|
configFile: false,
|
|
babelHelpers: "bundled",
|
|
exclude: ["node_modules/core-js/**"],
|
|
parserOpts: { sourceType: "module" },
|
|
presets: [
|
|
"@babel/preset-typescript",
|
|
[
|
|
"@babel/preset-env",
|
|
{
|
|
useBuiltIns: "usage",
|
|
corejs: require("core-js/package.json").version,
|
|
},
|
|
],
|
|
],
|
|
targets: "maintained node versions",
|
|
}),
|
|
terser(),
|
|
],
|
|
});
|
|
const result = await bundle.generate({
|
|
format: "esm",
|
|
});
|
|
|
|
const output = `// source hash: ${hash}
|
|
/* eslint-disable */
|
|
// prettier-ignore
|
|
${result.output[0].code}`;
|
|
writeFileSync(outputPath, output);
|
|
}
|