@yao-pkg/pkg 6.12.0 → 6.13.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 +63 -26
- package/lib-es5/common.js +94 -1
- package/lib-es5/detector.js +4 -2
- package/lib-es5/esm-transformer.js +366 -0
- package/lib-es5/follow.js +154 -55
- package/lib-es5/index.js +10 -8
- package/lib-es5/mach-o.js +1 -1
- package/lib-es5/options.js +2 -1
- package/lib-es5/packer.js +11 -2
- package/lib-es5/producer.js +3 -4
- package/lib-es5/resolver.js +142 -0
- package/lib-es5/sea.js +13 -6
- package/lib-es5/walker.js +131 -21
- package/package.json +6 -4
package/lib-es5/follow.js
CHANGED
|
@@ -8,6 +8,7 @@ const resolve_1 = require("resolve");
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const common_1 = require("./common");
|
|
11
|
+
const resolver_1 = require("./resolver");
|
|
11
12
|
const PROOF = 'a-proof-that-main-is-captured.js';
|
|
12
13
|
function parentDirectoriesContain(parent, directory) {
|
|
13
14
|
let currentParent = parent;
|
|
@@ -22,69 +23,167 @@ function parentDirectoriesContain(parent, directory) {
|
|
|
22
23
|
currentParent = newParent;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a specifier looks like a valid npm package name
|
|
28
|
+
* npm package names must be lowercase and can only contain:
|
|
29
|
+
* - lowercase letters, digits, hyphens, underscores, dots
|
|
30
|
+
* - can be scoped (@scope/package)
|
|
31
|
+
* This helps filter out generated aliases like "connectNonLiteral"
|
|
32
|
+
*/
|
|
33
|
+
function isValidPackageName(specifier) {
|
|
34
|
+
// Scoped packages: @scope/package
|
|
35
|
+
if (specifier.startsWith('@')) {
|
|
36
|
+
const parts = specifier.split('/');
|
|
37
|
+
if (parts.length < 2)
|
|
38
|
+
return false;
|
|
39
|
+
// Scope must start with @ and both parts must be valid
|
|
40
|
+
return /^@[a-z0-9_.-]+$/.test(parts[0]) && /^[a-z0-9_.-]+$/.test(parts[1]);
|
|
41
|
+
}
|
|
42
|
+
// Regular package: must be lowercase with allowed characters
|
|
43
|
+
// Package name is the part before the first '/' (if any)
|
|
44
|
+
const packageName = specifier.split('/')[0];
|
|
45
|
+
return /^[a-z0-9_.-]+$/.test(packageName);
|
|
46
|
+
}
|
|
25
47
|
function follow(x, opts) {
|
|
26
48
|
// TODO async version
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
// Try ESM-aware resolution first for non-relative specifiers
|
|
51
|
+
// Skip if the specifier doesn't look like a valid npm package name
|
|
52
|
+
// (e.g., generated aliases like "connectNonLiteral")
|
|
53
|
+
if (!x.startsWith('.') &&
|
|
54
|
+
!x.startsWith('/') &&
|
|
55
|
+
!path_1.default.isAbsolute(x) &&
|
|
56
|
+
isValidPackageName(x)) {
|
|
57
|
+
try {
|
|
58
|
+
let extensions;
|
|
59
|
+
if (Array.isArray(opts.extensions)) {
|
|
60
|
+
extensions = opts.extensions;
|
|
35
61
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
stat = fs_1.default.statSync(file);
|
|
62
|
+
else if (opts.extensions) {
|
|
63
|
+
extensions = [opts.extensions];
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR'))
|
|
43
|
-
return false;
|
|
44
|
-
throw ex;
|
|
45
|
-
}
|
|
46
|
-
return stat.isFile() || stat.isFIFO();
|
|
47
|
-
},
|
|
48
|
-
isDirectory: (directory) => {
|
|
49
|
-
if (opts.ignoreFile &&
|
|
50
|
-
parentDirectoriesContain(opts.ignoreFile, directory)) {
|
|
51
|
-
return false;
|
|
65
|
+
else {
|
|
66
|
+
extensions = ['.js', '.json', '.node'];
|
|
52
67
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
const result = (0, resolver_1.resolveModule)(x, {
|
|
69
|
+
basedir: opts.basedir || process.cwd(),
|
|
70
|
+
extensions,
|
|
71
|
+
});
|
|
72
|
+
// Only use ESM resolution result if it's an actual ESM package
|
|
73
|
+
// For CJS packages, fall through to standard CommonJS resolution
|
|
74
|
+
// to ensure all callbacks (catchReadFile, catchPackageFilter) are handled correctly
|
|
75
|
+
if (result.isESM) {
|
|
76
|
+
// This is a real ESM package, handle it here
|
|
77
|
+
if (opts.catchReadFile) {
|
|
78
|
+
// Find the package.json for this resolved module
|
|
79
|
+
let currentDir = path_1.default.dirname(result.resolved);
|
|
80
|
+
while (currentDir !== path_1.default.dirname(currentDir)) {
|
|
81
|
+
const pkgPath = path_1.default.join(currentDir, 'package.json');
|
|
82
|
+
// Honor ignoreFile to ensure correct package marker determination
|
|
83
|
+
if (opts.ignoreFile &&
|
|
84
|
+
path_1.default.normalize(pkgPath) === path_1.default.normalize(opts.ignoreFile)) {
|
|
85
|
+
// Skip this package.json as it's marked to be ignored
|
|
86
|
+
currentDir = path_1.default.dirname(currentDir);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (fs_1.default.existsSync(pkgPath)) {
|
|
90
|
+
// Check if this package.json is in node_modules (not the root package)
|
|
91
|
+
if (currentDir.includes('node_modules')) {
|
|
92
|
+
opts.catchReadFile(pkgPath);
|
|
93
|
+
// Also call catchPackageFilter if provided
|
|
94
|
+
if (opts.catchPackageFilter) {
|
|
95
|
+
const pkgContent = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
|
|
96
|
+
// If package doesn't have a "main" field but we resolved via exports,
|
|
97
|
+
// add a synthetic "main" field so runtime resolution works
|
|
98
|
+
if (!pkgContent.main) {
|
|
99
|
+
const relativePath = path_1.default.relative(currentDir, result.resolved);
|
|
100
|
+
pkgContent.main = `./${relativePath.replace(/\\/g, '/')}`;
|
|
101
|
+
}
|
|
102
|
+
opts.catchPackageFilter(pkgContent, currentDir, currentDir);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
currentDir = path_1.default.dirname(currentDir);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ESM package resolved successfully
|
|
111
|
+
resolve(result.resolved);
|
|
112
|
+
return;
|
|
56
113
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
114
|
+
// CJS package - fall through to standard CommonJS resolution
|
|
115
|
+
// to handle all callbacks properly
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// ESM resolution failed - fall through to standard CommonJS resolution
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Use standard CommonJS resolution
|
|
122
|
+
try {
|
|
123
|
+
resolve((0, resolve_1.sync)(x, {
|
|
124
|
+
basedir: opts.basedir,
|
|
125
|
+
extensions: opts.extensions,
|
|
126
|
+
isFile: (file) => {
|
|
127
|
+
if (opts.ignoreFile &&
|
|
128
|
+
path_1.default.join(path_1.default.dirname(opts.ignoreFile), PROOF) === file) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
let stat;
|
|
132
|
+
try {
|
|
133
|
+
stat = fs_1.default.statSync(file);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
const ex = e;
|
|
137
|
+
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR'))
|
|
138
|
+
return false;
|
|
139
|
+
throw ex;
|
|
140
|
+
}
|
|
141
|
+
return stat.isFile() || stat.isFIFO();
|
|
142
|
+
},
|
|
143
|
+
isDirectory: (directory) => {
|
|
144
|
+
if (opts.ignoreFile &&
|
|
145
|
+
parentDirectoriesContain(opts.ignoreFile, directory)) {
|
|
60
146
|
return false;
|
|
61
147
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
148
|
+
let stat;
|
|
149
|
+
try {
|
|
150
|
+
stat = fs_1.default.statSync(directory);
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
const ex = e;
|
|
154
|
+
if (ex && (ex.code === 'ENOENT' || ex.code === 'ENOTDIR')) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
throw ex;
|
|
158
|
+
}
|
|
159
|
+
return stat.isDirectory();
|
|
160
|
+
},
|
|
161
|
+
readFileSync: (file) => {
|
|
162
|
+
if (opts.ignoreFile && opts.ignoreFile === file) {
|
|
163
|
+
return Buffer.from(`{"main":"${PROOF}"}`);
|
|
164
|
+
}
|
|
165
|
+
if (opts.catchReadFile) {
|
|
166
|
+
opts.catchReadFile(file);
|
|
167
|
+
}
|
|
168
|
+
return fs_1.default.readFileSync(file);
|
|
169
|
+
},
|
|
170
|
+
packageFilter: (config, base, dir) => {
|
|
171
|
+
if (opts.catchPackageFilter) {
|
|
172
|
+
opts.catchPackageFilter(config, base, dir);
|
|
173
|
+
}
|
|
174
|
+
return config;
|
|
175
|
+
},
|
|
176
|
+
/** function to synchronously resolve a potential symlink to its real path */
|
|
177
|
+
// realpathSync?: (file: string) => string;
|
|
178
|
+
realpathSync: (file) => {
|
|
179
|
+
const file2 = (0, common_1.toNormalizedRealPath)(file);
|
|
180
|
+
return file2;
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
reject(error);
|
|
186
|
+
}
|
|
88
187
|
});
|
|
89
188
|
}
|
|
90
189
|
exports.follow = follow;
|
package/lib-es5/index.js
CHANGED
|
@@ -149,7 +149,6 @@ async function needViaCache(target) {
|
|
|
149
149
|
return c;
|
|
150
150
|
}
|
|
151
151
|
async function exec(argv2) {
|
|
152
|
-
var _a, _b;
|
|
153
152
|
const argv = (0, minimist_1.default)(argv2, {
|
|
154
153
|
boolean: [
|
|
155
154
|
'b',
|
|
@@ -413,7 +412,10 @@ async function exec(argv2) {
|
|
|
413
412
|
await needWithDryRun(target);
|
|
414
413
|
target.fabricator = fabricatorForTarget(target);
|
|
415
414
|
if (bytecode) {
|
|
416
|
-
await needWithDryRun(
|
|
415
|
+
await needWithDryRun({
|
|
416
|
+
...target.fabricator,
|
|
417
|
+
forceBuild,
|
|
418
|
+
});
|
|
417
419
|
}
|
|
418
420
|
}
|
|
419
421
|
if (dryRunResults.fetched && !dryRunResults.built) {
|
|
@@ -433,7 +435,7 @@ async function exec(argv2) {
|
|
|
433
435
|
try {
|
|
434
436
|
(0, mach_o_1.signMachOExecutable)(signedBinaryPath);
|
|
435
437
|
}
|
|
436
|
-
catch
|
|
438
|
+
catch {
|
|
437
439
|
throw (0, log_1.wasReported)('Cannot generate bytecode', [
|
|
438
440
|
'pkg fails to run "codesign" utility. Due to the mandatory signing',
|
|
439
441
|
'requirement of macOS, executables must be signed. Please ensure the',
|
|
@@ -450,7 +452,7 @@ async function exec(argv2) {
|
|
|
450
452
|
// marker
|
|
451
453
|
let marker;
|
|
452
454
|
if (configJson) {
|
|
453
|
-
options_1.default.set(configJson
|
|
455
|
+
options_1.default.set(configJson?.pkg);
|
|
454
456
|
marker = {
|
|
455
457
|
config: configJson,
|
|
456
458
|
base: path_1.default.dirname(config),
|
|
@@ -458,7 +460,7 @@ async function exec(argv2) {
|
|
|
458
460
|
};
|
|
459
461
|
}
|
|
460
462
|
else {
|
|
461
|
-
options_1.default.set(inputJson
|
|
463
|
+
options_1.default.set(inputJson?.pkg);
|
|
462
464
|
marker = {
|
|
463
465
|
config: inputJson || {},
|
|
464
466
|
base: path_1.default.dirname(input),
|
|
@@ -473,13 +475,13 @@ async function exec(argv2) {
|
|
|
473
475
|
}
|
|
474
476
|
if (argv['public-packages']) {
|
|
475
477
|
params.publicPackages = argv['public-packages'].split(',');
|
|
476
|
-
if (
|
|
478
|
+
if (params.publicPackages?.indexOf('*') !== -1) {
|
|
477
479
|
params.publicPackages = ['*'];
|
|
478
480
|
}
|
|
479
481
|
}
|
|
480
482
|
if (argv['no-dict']) {
|
|
481
483
|
params.noDictionary = argv['no-dict'].split(',');
|
|
482
|
-
if (
|
|
484
|
+
if (params.noDictionary?.indexOf('*') !== -1) {
|
|
483
485
|
params.noDictionary = ['*'];
|
|
484
486
|
}
|
|
485
487
|
}
|
|
@@ -531,7 +533,7 @@ async function exec(argv2) {
|
|
|
531
533
|
// users can always replace the signature if necessary
|
|
532
534
|
(0, mach_o_1.signMachOExecutable)(target.output);
|
|
533
535
|
}
|
|
534
|
-
catch
|
|
536
|
+
catch {
|
|
535
537
|
if (target.arch === 'arm64') {
|
|
536
538
|
log_1.log.warn('Unable to sign the macOS executable', [
|
|
537
539
|
'Due to the mandatory code signing requirement, before the',
|
package/lib-es5/mach-o.js
CHANGED
package/lib-es5/options.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class Options {
|
|
4
|
+
options;
|
|
4
5
|
constructor() {
|
|
5
6
|
this.options = {
|
|
6
7
|
dictionary: {},
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
set(options) {
|
|
10
|
-
this.options = options
|
|
11
|
+
this.options = options ?? this.options;
|
|
11
12
|
}
|
|
12
13
|
get() {
|
|
13
14
|
return this.options;
|
package/lib-es5/packer.js
CHANGED
|
@@ -27,13 +27,22 @@ function hasAnyStore(record) {
|
|
|
27
27
|
}
|
|
28
28
|
function packer({ records, entrypoint, bytecode, }) {
|
|
29
29
|
const stripes = [];
|
|
30
|
-
|
|
30
|
+
// If the entrypoint was a .mjs file that got transformed, update its extension
|
|
31
|
+
if (records[entrypoint]?.wasTransformed && entrypoint.endsWith('.mjs')) {
|
|
32
|
+
entrypoint = `${entrypoint.slice(0, -4)}.js`;
|
|
33
|
+
}
|
|
34
|
+
for (let snap in records) {
|
|
31
35
|
if (records[snap]) {
|
|
32
36
|
const record = records[snap];
|
|
33
37
|
const { file } = record;
|
|
34
38
|
if (!hasAnyStore(record)) {
|
|
35
39
|
continue;
|
|
36
40
|
}
|
|
41
|
+
// If .mjs file was transformed to CJS, rename it to .js in the snapshot
|
|
42
|
+
// This prevents Node.js from treating it as an ES module
|
|
43
|
+
if (record.wasTransformed && snap.endsWith('.mjs')) {
|
|
44
|
+
snap = `${snap.slice(0, -4)}.js`;
|
|
45
|
+
}
|
|
37
46
|
(0, assert_1.default)(record[common_1.STORE_STAT], 'packer: no STORE_STAT');
|
|
38
47
|
(0, assert_1.default)(record[common_1.STORE_BLOB] ||
|
|
39
48
|
record[common_1.STORE_CONTENT] ||
|
|
@@ -87,7 +96,7 @@ function packer({ records, entrypoint, bytecode, }) {
|
|
|
87
96
|
}
|
|
88
97
|
else if (store === common_1.STORE_STAT) {
|
|
89
98
|
if (typeof value === 'object') {
|
|
90
|
-
const newStat =
|
|
99
|
+
const newStat = { ...value };
|
|
91
100
|
const buffer = Buffer.from(JSON.stringify(newStat));
|
|
92
101
|
stripes.push({ snap, store, buffer });
|
|
93
102
|
}
|
package/lib-es5/producer.js
CHANGED
|
@@ -127,14 +127,13 @@ function getPrebuildEnvPrefix(pkgName) {
|
|
|
127
127
|
.replace(/^_/, '')}`;
|
|
128
128
|
}
|
|
129
129
|
function nativePrebuildInstall(target, nodeFile) {
|
|
130
|
-
var _a, _b;
|
|
131
130
|
const prebuildInstall = path_1.default.join(__dirname, '../node_modules/.bin/prebuild-install');
|
|
132
131
|
const dir = findPackageJson(nodeFile);
|
|
133
132
|
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dir, 'package.json'), { encoding: 'utf-8' }));
|
|
134
133
|
// only try prebuild-install for packages that actually use it or if
|
|
135
134
|
// explicitly configured via environment variables
|
|
136
135
|
const envPrefix = getPrebuildEnvPrefix(packageJson.name);
|
|
137
|
-
if (
|
|
136
|
+
if (packageJson.dependencies?.['prebuild-install'] == null &&
|
|
138
137
|
![
|
|
139
138
|
`${envPrefix}_binary_host`,
|
|
140
139
|
`${envPrefix}_binary_host_mirror`,
|
|
@@ -155,7 +154,7 @@ function nativePrebuildInstall(target, nodeFile) {
|
|
|
155
154
|
if (!fs_1.default.existsSync(`${nodeFile}.bak`)) {
|
|
156
155
|
fs_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
|
|
157
156
|
}
|
|
158
|
-
const napiVersions =
|
|
157
|
+
const napiVersions = packageJson?.binary?.napi_versions;
|
|
159
158
|
const options = [
|
|
160
159
|
'--platform',
|
|
161
160
|
types_1.platform[target.platform],
|
|
@@ -298,7 +297,7 @@ function producer({ backpack, bakes, slash, target, symLinks, doCompress, native
|
|
|
298
297
|
// clone to prevent 'skip' propagate
|
|
299
298
|
// to other targets, since same stripe
|
|
300
299
|
// is used for several targets
|
|
301
|
-
const stripe =
|
|
300
|
+
const stripe = { ...stripes.shift() };
|
|
302
301
|
prevStripe = stripe;
|
|
303
302
|
if (stripe.buffer) {
|
|
304
303
|
if (stripe.store === common_1.STORE_BLOB) {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveModule = void 0;
|
|
7
|
+
const resolve_1 = require("resolve");
|
|
8
|
+
const resolve_exports_1 = require("resolve.exports");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const common_1 = require("./common");
|
|
12
|
+
const log_1 = require("./log");
|
|
13
|
+
/**
|
|
14
|
+
* Resolve using package.json "exports" field (ESM-style)
|
|
15
|
+
* @param packageName - Package name (e.g., 'nanoid')
|
|
16
|
+
* @param subpath - Subpath within package (e.g., './url-alphabet')
|
|
17
|
+
* @param packageRoot - Absolute path to package root
|
|
18
|
+
* @returns Resolved path or null if not found
|
|
19
|
+
*/
|
|
20
|
+
function resolveWithExports(packageName, subpath, packageRoot) {
|
|
21
|
+
try {
|
|
22
|
+
const packageJsonPath = path_1.default.join(packageRoot, 'package.json');
|
|
23
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
27
|
+
// Check if package has exports field
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
const pkgAny = pkg;
|
|
30
|
+
if (!pkgAny.exports) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
// Use resolve.exports to handle the exports field
|
|
34
|
+
// For pkg's context, we're bundling CJS code, so try 'require' condition first
|
|
35
|
+
// Then fallback to 'import' for ESM-only packages
|
|
36
|
+
let resolved = (0, resolve_exports_1.exports)(pkgAny, subpath, {
|
|
37
|
+
require: true, // Try require first
|
|
38
|
+
});
|
|
39
|
+
// Fallback to import condition for ESM-only packages
|
|
40
|
+
if (!resolved) {
|
|
41
|
+
resolved = (0, resolve_exports_1.exports)(pkgAny, subpath, {
|
|
42
|
+
require: false, // This enables import condition
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (resolved) {
|
|
46
|
+
// resolved can be a string or array
|
|
47
|
+
const resolvedPath = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
48
|
+
const fullPath = path_1.default.join(packageRoot, resolvedPath);
|
|
49
|
+
if (fs_1.default.existsSync(fullPath)) {
|
|
50
|
+
return fullPath;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
log_1.log.debug(`Failed to resolve with exports field: ${packageName}${subpath}`);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Try to resolve a module specifier as an ESM package
|
|
62
|
+
* @param specifier - Module specifier (e.g., 'nanoid', 'nanoid/url-alphabet')
|
|
63
|
+
* @param basedir - Base directory for resolution
|
|
64
|
+
* @returns Resolved path or null
|
|
65
|
+
*/
|
|
66
|
+
function tryResolveESM(specifier, basedir) {
|
|
67
|
+
try {
|
|
68
|
+
// Parse package name and subpath
|
|
69
|
+
let packageName;
|
|
70
|
+
let subpath;
|
|
71
|
+
if (specifier.startsWith('@')) {
|
|
72
|
+
// Scoped package: @org/pkg or @org/pkg/subpath
|
|
73
|
+
const parts = specifier.split('/');
|
|
74
|
+
packageName = `${parts[0]}/${parts[1]}`;
|
|
75
|
+
subpath = parts.length > 2 ? `./${parts.slice(2).join('/')}` : '.';
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Regular package: pkg or pkg/subpath
|
|
79
|
+
const slashIndex = specifier.indexOf('/');
|
|
80
|
+
if (slashIndex === -1) {
|
|
81
|
+
packageName = specifier;
|
|
82
|
+
subpath = '.';
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
packageName = specifier.substring(0, slashIndex);
|
|
86
|
+
subpath = `./${specifier.substring(slashIndex + 1)}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Use resolveSync to find the package root (works with pnpm and other layouts)
|
|
90
|
+
// Try to resolve the package.json to get the package root
|
|
91
|
+
try {
|
|
92
|
+
const pkgJsonPath = (0, resolve_1.sync)(path_1.default.join(packageName, 'package.json'), {
|
|
93
|
+
basedir,
|
|
94
|
+
preserveSymlinks: false,
|
|
95
|
+
});
|
|
96
|
+
const packageRoot = path_1.default.dirname(pkgJsonPath);
|
|
97
|
+
// Try to resolve with exports field
|
|
98
|
+
const resolved = resolveWithExports(packageName, subpath, packageRoot);
|
|
99
|
+
if (resolved) {
|
|
100
|
+
return resolved;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// If package.json resolution fails, fall through to return null
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolve a module specifier with ESM support
|
|
114
|
+
* Falls back to standard CommonJS resolution if ESM resolution fails
|
|
115
|
+
*
|
|
116
|
+
* @param specifier - Module specifier to resolve
|
|
117
|
+
* @param options - Resolution options
|
|
118
|
+
* @returns Resolved file path and ESM flag
|
|
119
|
+
*/
|
|
120
|
+
function resolveModule(specifier, options) {
|
|
121
|
+
const { basedir, extensions = ['.js', '.json', '.node'] } = options;
|
|
122
|
+
// First, try ESM-style resolution with exports field
|
|
123
|
+
const esmResolved = tryResolveESM(specifier, basedir);
|
|
124
|
+
if (esmResolved) {
|
|
125
|
+
// Use isESMFile which walks up to find the correct package.json
|
|
126
|
+
return {
|
|
127
|
+
resolved: esmResolved,
|
|
128
|
+
isESM: (0, common_1.isESMFile)(esmResolved),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Fallback to standard CommonJS resolution
|
|
132
|
+
const resolved = (0, resolve_1.sync)(specifier, {
|
|
133
|
+
basedir,
|
|
134
|
+
extensions,
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
resolved,
|
|
138
|
+
isESM: false, // CJS resolution
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
exports.resolveModule = resolveModule;
|
|
142
|
+
//# sourceMappingURL=resolver.js.map
|
package/lib-es5/sea.js
CHANGED
|
@@ -21,7 +21,7 @@ const exists = async (path) => {
|
|
|
21
21
|
try {
|
|
22
22
|
return await (0, promises_1.stat)(path);
|
|
23
23
|
}
|
|
24
|
-
catch
|
|
24
|
+
catch {
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -75,15 +75,15 @@ async function extract(os, archivePath) {
|
|
|
75
75
|
}
|
|
76
76
|
/** Verify the checksum of downloaded NodeJS archive */
|
|
77
77
|
async function verifyChecksum(filePath, checksumUrl, fileName) {
|
|
78
|
-
var _a;
|
|
79
78
|
const response = await fetch(checksumUrl);
|
|
80
79
|
if (!response.ok) {
|
|
81
80
|
throw new Error(`Failed to download checksum file from ${checksumUrl}`);
|
|
82
81
|
}
|
|
83
82
|
const checksums = await response.text();
|
|
84
|
-
const expectedChecksum =
|
|
83
|
+
const expectedChecksum = checksums
|
|
85
84
|
.split('\n')
|
|
86
|
-
.find((line) => line.includes(fileName))
|
|
85
|
+
.find((line) => line.includes(fileName))
|
|
86
|
+
?.split(' ')[0];
|
|
87
87
|
if (!expectedChecksum) {
|
|
88
88
|
throw new Error(`Checksum for ${fileName} not found`);
|
|
89
89
|
}
|
|
@@ -252,7 +252,14 @@ async function sea(entryPoint, opts) {
|
|
|
252
252
|
// docs: https://nodejs.org/api/single-executable-applications.html
|
|
253
253
|
const blobPath = (0, path_1.join)(tmpDir, 'sea-prep.blob');
|
|
254
254
|
const seaConfigFilePath = (0, path_1.join)(tmpDir, 'sea-config.json');
|
|
255
|
-
const seaConfig =
|
|
255
|
+
const seaConfig = {
|
|
256
|
+
main: entryPoint,
|
|
257
|
+
output: blobPath,
|
|
258
|
+
...{
|
|
259
|
+
...defaultSeaConfig,
|
|
260
|
+
...(opts.seaConfig || {}),
|
|
261
|
+
},
|
|
262
|
+
};
|
|
256
263
|
log_1.log.info('Creating sea-config.json file...');
|
|
257
264
|
await (0, promises_1.writeFile)(seaConfigFilePath, JSON.stringify(seaConfig));
|
|
258
265
|
log_1.log.info('Generating the blob...');
|
|
@@ -269,7 +276,7 @@ async function sea(entryPoint, opts) {
|
|
|
269
276
|
// users can always replace the signature if necessary
|
|
270
277
|
(0, mach_o_1.signMachOExecutable)(output);
|
|
271
278
|
}
|
|
272
|
-
catch
|
|
279
|
+
catch {
|
|
273
280
|
if (target.arch === 'arm64') {
|
|
274
281
|
log_1.log.warn('Unable to sign the macOS executable', [
|
|
275
282
|
'Due to the mandatory code signing requirement, before the',
|