( inputPath: string, outputPath: string, dynamicRequireTargets: string[] )
| 17 | ]); |
| 18 | |
| 19 | async function pack( |
| 20 | inputPath: string, |
| 21 | outputPath: string, |
| 22 | dynamicRequireTargets: string[] |
| 23 | ) { |
| 24 | inputPath = path.join(__dirname, inputPath); |
| 25 | outputPath = path.join(__dirname, outputPath); |
| 26 | |
| 27 | const hash = createHash("sha1") |
| 28 | .update(readFileSync(inputPath, "utf8")) |
| 29 | .digest("hex"); |
| 30 | |
| 31 | if (process.argv[2] === "--auto") { |
| 32 | if (readFileSync(outputPath, "utf8").includes(hash)) { |
| 33 | return; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | const bundle = await rollup({ |
| 38 | input: inputPath, |
| 39 | |
| 40 | plugins: [ |
| 41 | nodeResolve({ exportConditions: ["node"], preferBuiltins: true }), |
| 42 | commonjs({ |
| 43 | dynamicRequireTargets: dynamicRequireTargets, |
| 44 | }), |
| 45 | babel({ |
| 46 | extensions: [".ts"], |
| 47 | babelrc: false, |
| 48 | configFile: false, |
| 49 | babelHelpers: "bundled", |
| 50 | exclude: ["node_modules/core-js/**"], |
| 51 | parserOpts: { sourceType: "module" }, |
| 52 | presets: ["@babel/preset-typescript", "@babel/preset-env"], |
| 53 | plugins: [ |
| 54 | [ |
| 55 | "babel-plugin-polyfill-corejs3", |
| 56 | { |
| 57 | method: "usage-global", |
| 58 | corejs: require("core-js/package.json").version, |
| 59 | }, |
| 60 | ], |
| 61 | ], |
| 62 | targets: "maintained node versions", |
| 63 | }), |
| 64 | replace({ |
| 65 | preventAssignment: true, |
| 66 | values: { |
| 67 | // handle require.main === module usage here |
| 68 | // https://github.com/shelljs/shelljs/blob/2809a872ead82da2d9fd0704dc3c1f690e2475f4/src/exec-child.js#L69 |
| 69 | // we never execute shelljs/src/exec-child.js directly, so it should always be false |
| 70 | "require.main === module": "false", |
| 71 | }, |
| 72 | }), |
| 73 | terser(), |
| 74 | ], |
| 75 | }); |
| 76 | const result = await bundle.generate({ |
no test coverage detected