@yao-pkg/pkg 6.13.1 → 6.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ After installing it, run `pkg --help` without arguments to see list of options:
53
53
  – Makes executable for particular target machine
54
54
  $ pkg -t node14-win-arm64 index.js
55
55
  – Makes executables for target machines of your choice
56
- $ pkg -t node16-linux,node18-linux,node18-win index.js
56
+ $ pkg -t node20-linux,node22-linux,node22-win index.js
57
57
  – Bakes '--expose-gc' and '--max-heap-size=34' into executable
58
58
  $ pkg --options "expose-gc,max-heap-size=34" index.js
59
59
  – Consider packageA and packageB to be public
@@ -82,7 +82,7 @@ The entrypoint of your project is a mandatory CLI argument. It may be:
82
82
  `pkg` can generate executables for several target machines at a
83
83
  time. You can specify a comma-separated list of targets via `--targets`
84
84
  option. A canonical target consists of 3 elements, separated by
85
- dashes, for example `node18-macos-x64` or `node14-linux-arm64`:
85
+ dashes, for example `node20-macos-x64` or `node22-linux-arm64`:
86
86
 
87
87
  - **nodeRange** (node8), node10, node12, node14, node16 or latest
88
88
  - **platform** alpine, linux, linuxstatic, win, macos, (freebsd)
@@ -86,7 +86,6 @@ function reconstructSpecifiers(specs) {
86
86
  return defaults.join(', ');
87
87
  }
88
88
  function reconstruct(node) {
89
- // @ts-expect-error Type mismatch due to @babel/types version in @types/babel__generator
90
89
  let v = (0, generator_1.default)(node, { comments: false }).code.replace(/\n/g, '');
91
90
  let v2;
92
91
  while (true) {
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.transformESMtoCJS = void 0;
29
+ exports.transformESMtoCJS = exports.rewriteMjsRequirePaths = void 0;
30
30
  const babel = __importStar(require("@babel/parser"));
31
31
  const traverse_1 = __importDefault(require("@babel/traverse"));
32
32
  const esbuild = __importStar(require("esbuild"));
@@ -56,7 +56,6 @@ function hasImportMeta(code) {
56
56
  return false;
57
57
  }
58
58
  let found = false;
59
- // @ts-expect-error Type mismatch due to @babel/types version in @types/babel__traverse
60
59
  (0, traverse_1.default)(ast, {
61
60
  // Detect import.meta usage
62
61
  MetaProperty(path) {
@@ -69,7 +68,7 @@ function hasImportMeta(code) {
69
68
  });
70
69
  return found;
71
70
  }
72
- catch (error) {
71
+ catch (_error) {
73
72
  // If we can't parse, assume no import.meta
74
73
  return false;
75
74
  }
@@ -96,7 +95,6 @@ function detectESMFeatures(code, filename) {
96
95
  }
97
96
  const topLevelAwait = [];
98
97
  const unsupportedFeatures = [];
99
- // @ts-expect-error Type mismatch due to @babel/types version in @types/babel__traverse
100
98
  (0, traverse_1.default)(ast, {
101
99
  // Detect top-level await - can be handled with async IIFE wrapper
102
100
  AwaitExpression(path) {
@@ -193,6 +191,21 @@ function replaceImportMetaObject(code) {
193
191
  // Match: const import_meta = {};
194
192
  return code.replace(/const import_meta\s*=\s*\{\s*\};/, shimImplementation);
195
193
  }
194
+ /**
195
+ * Rewrite relative `.mjs` require paths to `.js` in CJS output
196
+ *
197
+ * When esbuild transforms ESM to CJS, it converts `import './foo.mjs'` to `require('./foo.mjs')`.
198
+ * Since the packer renames `.mjs` files to `.js` in the snapshot, the require paths must be
199
+ * updated to match. This handles the rewriting at build time.
200
+ *
201
+ * @param code - The CJS code after esbuild transformation
202
+ * @returns Code with relative .mjs require paths rewritten to .js
203
+ */
204
+ function rewriteMjsRequirePaths(code) {
205
+ // Match require("./path.mjs") or require('../path.mjs') with relative paths only
206
+ return code.replace(/require\((["'])(\.\.?\/[^"']*?)\.mjs\1\)/g, 'require($1$2.js$1)');
207
+ }
208
+ exports.rewriteMjsRequirePaths = rewriteMjsRequirePaths;
196
209
  /**
197
210
  * Transform ESM code to CommonJS using esbuild
198
211
  * This allows ESM modules to be compiled to bytecode via vm.Script
@@ -259,7 +272,6 @@ function transformESMtoCJS(code, filename) {
259
272
  let hasExports = false;
260
273
  const codeLines = code.split('\n');
261
274
  const importLineIndices = new Set();
262
- // @ts-expect-error Type mismatch due to @babel/types version
263
275
  (0, traverse_1.default)(ast, {
264
276
  ExportNamedDeclaration() {
265
277
  hasExports = true;
@@ -331,7 +343,7 @@ function transformESMtoCJS(code, filename) {
331
343
  const esbuildOptions = {
332
344
  loader: 'js',
333
345
  format: 'cjs',
334
- target: 'node18',
346
+ target: 'node20',
335
347
  sourcemap: false,
336
348
  minify: false,
337
349
  keepNames: true,
@@ -347,7 +359,7 @@ function transformESMtoCJS(code, filename) {
347
359
  // Inject import.meta shims after esbuild transformation if needed
348
360
  let finalCode = result.code;
349
361
  if (usesImportMeta) {
350
- finalCode = replaceImportMetaObject(result.code);
362
+ finalCode = replaceImportMetaObject(finalCode);
351
363
  }
352
364
  return {
353
365
  code: finalCode,
@@ -64,19 +64,16 @@ function fabricate(bakes, fabricator, snap, body, cb) {
64
64
  }
65
65
  let stdout = Buffer.alloc(0);
66
66
  function onError(error) {
67
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
68
67
  removeListeners();
69
68
  kill();
70
69
  cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap} error (${error.message})`));
71
70
  }
72
71
  function onClose(code) {
73
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
74
72
  removeListeners();
75
73
  kill();
76
74
  if (code !== 0) {
77
75
  return cb(new Error(`Failed to make bytecode ${fabricator.nodeRange}-${fabricator.arch} for file ${snap}`));
78
76
  }
79
- // eslint-disable-next-line no-console
80
77
  console.log(stdout.toString());
81
78
  return cb(new Error(`${cmd} closed unexpectedly`));
82
79
  }
@@ -87,7 +84,6 @@ function fabricate(bakes, fabricator, snap, body, cb) {
87
84
  if (stdout.length >= 4 + sizeOfBlob) {
88
85
  const blob = Buffer.alloc(sizeOfBlob);
89
86
  stdout.copy(blob, 0, 4, 4 + sizeOfBlob);
90
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
91
87
  removeListeners();
92
88
  return cb(undefined, blob);
93
89
  }
package/lib-es5/follow.js CHANGED
@@ -114,7 +114,7 @@ function follow(x, opts) {
114
114
  // CJS package - fall through to standard CommonJS resolution
115
115
  // to handle all callbacks properly
116
116
  }
117
- catch (error) {
117
+ catch (_error) {
118
118
  // ESM resolution failed - fall through to standard CommonJS resolution
119
119
  }
120
120
  }
package/lib-es5/help.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const colors_1 = require("./colors");
4
4
  function help() {
5
- // eslint-disable-next-line no-console
6
5
  console.log(`
7
6
  ${colors_1.pc.bold('pkg')} [options] <input>
8
7
 
@@ -34,7 +33,7 @@ function help() {
34
33
  ${colors_1.pc.gray('–')} Makes executable for particular target machine
35
34
  ${colors_1.pc.cyan('$ pkg -t node14-win-arm64 index.js')}
36
35
  ${colors_1.pc.gray('–')} Makes executables for target machines of your choice
37
- ${colors_1.pc.cyan('$ pkg -t node16-linux,node18-linux,node18-win index.js')}
36
+ ${colors_1.pc.cyan('$ pkg -t node22-linux,node24-linux,node24-win index.js')}
38
37
  ${colors_1.pc.gray('–')} Bakes '--expose-gc' and '--max-heap-size=34' into executable
39
38
  ${colors_1.pc.cyan('$ pkg --options "expose-gc,max-heap-size=34" index.js')}
40
39
  ${colors_1.pc.gray('–')} Consider packageA and packageB to be public
package/lib-es5/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable require-atomic-updates */
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
@@ -30,7 +29,6 @@ function isConfiguration(file) {
30
29
  }
31
30
  // http://www.openwall.com/lists/musl/2012/12/08/4
32
31
  const { hostArch, hostPlatform, isValidNodeRange, knownArchs, knownPlatforms, toFancyArch, toFancyPlatform, } = pkg_fetch_1.system;
33
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
34
32
  const hostNodeRange = `node${process.version.match(/^v(\d+)/)[1]}`;
35
33
  function parseTargets(items) {
36
34
  // [ 'node6-macos-x64', 'node6-linux-x64' ]
@@ -191,7 +189,6 @@ async function exec(argv2) {
191
189
  }
192
190
  // version
193
191
  if (argv.v || argv.version) {
194
- // eslint-disable-next-line no-console
195
192
  console.log(version);
196
193
  return;
197
194
  }
@@ -218,7 +215,6 @@ async function exec(argv2) {
218
215
  throw (0, log_1.wasReported)(`Invalid compression algorithm ${algo} ( should be None, Brotli or Gzip)`);
219
216
  }
220
217
  if (doCompress !== compress_type_1.CompressType.None) {
221
- // eslint-disable-next-line no-console
222
218
  console.log('compression: ', compress_type_1.CompressType[doCompress]);
223
219
  }
224
220
  // _
@@ -288,7 +284,7 @@ async function exec(argv2) {
288
284
  if (!(0, fs_1.existsSync)(config)) {
289
285
  throw (0, log_1.wasReported)('Config file does not exist', [config]);
290
286
  }
291
- // eslint-disable-next-line import/no-dynamic-require, global-require
287
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
292
288
  configJson = require(config); // may be either json or js
293
289
  if (!configJson.name &&
294
290
  !configJson.files &&
package/lib-es5/packer.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable complexity */
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
@@ -52,7 +52,7 @@ function resolveWithExports(packageName, subpath, packageRoot) {
52
52
  }
53
53
  return null;
54
54
  }
55
- catch (error) {
55
+ catch (_error) {
56
56
  log_1.log.debug(`Failed to resolve with exports field: ${packageName}${subpath}`);
57
57
  return null;
58
58
  }
package/lib-es5/walker.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable require-atomic-updates */
3
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
3
  if (k2 === undefined) k2 = k;
5
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -49,6 +48,9 @@ const options_1 = __importDefault(require("./options"));
49
48
  // performance hit.
50
49
  const strictVerify = Boolean(process.env.PKG_STRICT_VER);
51
50
  const win32 = process.platform === 'win32';
51
+ // Extensions to try when resolving modules
52
+ // Includes .mjs to support ESM files that get transformed to .js
53
+ const MODULE_RESOLVE_EXTENSIONS = ['.js', '.json', '.node', '.mjs'];
52
54
  /**
53
55
  * Checks if a module is a core module
54
56
  * module.isBuiltin is available in Node.js 16.17.0 or later. Use that if available
@@ -633,7 +635,8 @@ class Walker {
633
635
  // it is not enough because 'typos.json'
634
636
  // is not taken in require('./typos')
635
637
  // in 'normalize-package-data/lib/fixer.js'
636
- extensions: ['.js', '.json', '.node'],
638
+ // Also include .mjs to support ESM files that get transformed to .js
639
+ extensions: MODULE_RESOLVE_EXTENSIONS,
637
640
  catchReadFile,
638
641
  catchPackageFilter,
639
642
  });
@@ -666,7 +669,7 @@ class Walker {
666
669
  try {
667
670
  newFile2 = await (0, follow_1.follow)(derivative.alias, {
668
671
  basedir: path_1.default.dirname(record.file),
669
- extensions: ['.js', '.json', '.node'],
672
+ extensions: MODULE_RESOLVE_EXTENSIONS,
670
673
  ignoreFile: newPackage.packageJson,
671
674
  });
672
675
  if (strictVerify) {
@@ -838,7 +841,7 @@ class Walker {
838
841
  record.body = Buffer.from(JSON.stringify(pkgContent, null, 2), 'utf8');
839
842
  }
840
843
  }
841
- catch (error) {
844
+ catch (_error) {
842
845
  // Ignore JSON parsing errors
843
846
  }
844
847
  }
@@ -868,6 +871,11 @@ class Walker {
868
871
  const derivatives2 = [];
869
872
  stepDetect(record, marker, derivatives2);
870
873
  await this.stepDerivatives(record, marker, derivatives2);
874
+ // After dependencies are resolved, rewrite .mjs require paths to .js
875
+ // since the packer renames .mjs files to .js in the snapshot
876
+ if (record.wasTransformed && record.body) {
877
+ record.body = Buffer.from((0, esm_transformer_1.rewriteMjsRequirePaths)(record.body.toString('utf8')), 'utf8');
878
+ }
871
879
  }
872
880
  }
873
881
  record[store] = true;
@@ -931,7 +939,6 @@ class Walker {
931
939
  switch (store) {
932
940
  case common_1.STORE_BLOB:
933
941
  case common_1.STORE_CONTENT:
934
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
935
942
  await this.step_STORE_ANY(record, task.marker, store);
936
943
  break;
937
944
  case common_1.STORE_LINKS:
@@ -956,7 +963,7 @@ class Walker {
956
963
  if (this.params.noDictionary?.includes(file)) {
957
964
  continue;
958
965
  }
959
- // eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
966
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
960
967
  const config = require(path_1.default.join(dd, file));
961
968
  this.dictionary[name] = config;
962
969
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yao-pkg/pkg",
3
- "version": "6.13.1",
3
+ "version": "6.14.1",
4
4
  "description": "Package your Node.js project into an executable",
5
5
  "main": "lib-es5/index.js",
6
6
  "license": "MIT",
@@ -26,9 +26,9 @@
26
26
  "@babel/parser": "^7.23.0",
27
27
  "@babel/traverse": "^7.23.0",
28
28
  "@babel/types": "^7.23.0",
29
- "esbuild": "^0.24.0",
30
29
  "@yao-pkg/pkg-fetch": "3.5.32",
31
- "into-stream": "^6.0.0",
30
+ "esbuild": "^0.27.3",
31
+ "into-stream": "^9.1.0",
32
32
  "minimist": "^1.2.6",
33
33
  "multistream": "^4.1.0",
34
34
  "picocolors": "^1.1.0",
@@ -37,35 +37,36 @@
37
37
  "resolve": "^1.22.10",
38
38
  "resolve.exports": "^2.0.3",
39
39
  "stream-meter": "^1.0.4",
40
- "tar": "^7.5.6",
40
+ "tar": "^7.5.7",
41
41
  "tinyglobby": "^0.2.11",
42
42
  "unzipper": "^0.12.3"
43
43
  },
44
44
  "devDependencies": {
45
- "@release-it/conventional-changelog": "^7.0.2",
45
+ "@release-it/conventional-changelog": "^10.0.5",
46
46
  "@types/babel__generator": "^7.6.5",
47
47
  "@types/babel__traverse": "^7.20.3",
48
48
  "@types/minimist": "^1.2.2",
49
49
  "@types/multistream": "^4.1.0",
50
- "@types/node": "^16.18.113",
50
+ "@types/node": "^20.0.0",
51
51
  "@types/picomatch": "^3.0.1",
52
52
  "@types/resolve": "^1.20.2",
53
53
  "@types/stream-meter": "^0.0.22",
54
54
  "@types/tar": "^6.1.13",
55
55
  "@types/unzipper": "^0.10.10",
56
- "@typescript-eslint/eslint-plugin": "^6.7.4",
57
- "@typescript-eslint/parser": "^6.7.4",
56
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
57
+ "@typescript-eslint/parser": "^8.0.0",
58
58
  "esbuild-register": "^3.6.0",
59
- "eslint": "^8.50.0",
59
+ "eslint": "^9.0.0",
60
60
  "eslint-config-airbnb-base": "^15.0.0",
61
- "eslint-config-airbnb-typescript": "^17.1.0",
62
- "eslint-config-prettier": "^9.0.0",
63
- "eslint-plugin-import": "^2.28.1",
61
+ "eslint-config-airbnb-typescript": "^18.0.0",
62
+ "eslint-config-prettier": "^10.0.0",
63
+ "eslint-plugin-import": "^2.31.0",
64
+ "globals": "^17.3.0",
64
65
  "json-stable-stringify": "^1.0.1",
65
- "lint-staged": "^15.2.10",
66
+ "lint-staged": "^15.0.0",
66
67
  "prettier": "^3.0.3",
67
- "release-it": "^16.2.1",
68
- "rimraf": "^3.0.2",
68
+ "release-it": "^19.2.4",
69
+ "rimraf": "^6.1.2",
69
70
  "simple-git-hooks": "^2.11.1",
70
71
  "typescript": "^4.7.2"
71
72
  },
@@ -79,9 +80,10 @@
79
80
  "fix": "npm run lint:style -- -w && npm run lint:code -- --fix",
80
81
  "prepare": "npm run build",
81
82
  "prepublishOnly": "npm run lint",
82
- "test": "npm run build && npm run test:host && npm run test:18 && npm run test:20",
83
+ "test": "npm run build && npm run test:host && npm run test:20 && npm run test:22 && npm run test:24",
83
84
  "test:20": "node test/test.js node20 no-npm",
84
- "test:18": "node test/test.js node18 no-npm",
85
+ "test:22": "node test/test.js node22 no-npm",
86
+ "test:24": "node test/test.js node24 no-npm",
85
87
  "test:host": "node test/test.js host only-npm",
86
88
  "bump:fetch": "yarn add @yao-pkg/pkg-fetch --exact",
87
89
  "release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it"
@@ -97,6 +99,15 @@
97
99
  },
98
100
  "packageManager": "yarn@1.22.22",
99
101
  "engines": {
100
- "node": ">=18.0.0"
102
+ "node": ">=20.0.0"
103
+ },
104
+ "resolutions": {
105
+ "lodash": "^4.17.23",
106
+ "@octokit/request-error": "^5.1.1",
107
+ "@octokit/plugin-paginate-rest": "^9.2.2",
108
+ "@octokit/request": "^8.4.1",
109
+ "js-yaml": "^4.1.1",
110
+ "brace-expansion": "^2.0.2",
111
+ "tmp": "^0.2.4"
101
112
  }
102
113
  }
@@ -1,9 +1,3 @@
1
- /* eslint-disable import/no-unresolved */
2
- /* eslint-disable global-require */
3
- /* eslint-disable no-underscore-dangle */
4
- /* eslint-disable prefer-rest-params */
5
- /* eslint-disable prefer-spread */
6
-
7
1
  /* global EXECPATH_FD */
8
2
  /* global PAYLOAD_POSITION */
9
3
  /* global PAYLOAD_SIZE */
@@ -1,5 +1,3 @@
1
- /* eslint-disable global-require */
2
- /* eslint-disable no-console */
3
1
  /* global DICT */
4
2
 
5
3
  'use strict';