@yao-pkg/pkg 6.1.1 → 6.3.0
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/lib-es5/sea.js +44 -11
- package/package.json +2 -2
package/lib-es5/sea.js
CHANGED
|
@@ -109,14 +109,22 @@ function getNodeOs(platform) {
|
|
|
109
109
|
}
|
|
110
110
|
/** Get the node arch based on target arch */
|
|
111
111
|
function getNodeArch(arch) {
|
|
112
|
-
const allowedArchs = [
|
|
112
|
+
const allowedArchs = [
|
|
113
|
+
'x64',
|
|
114
|
+
'arm64',
|
|
115
|
+
'armv7l',
|
|
116
|
+
'ppc64',
|
|
117
|
+
's390x',
|
|
118
|
+
'riscv64',
|
|
119
|
+
'loong64',
|
|
120
|
+
];
|
|
113
121
|
if (!allowedArchs.includes(arch)) {
|
|
114
122
|
throw new Error(`Unsupported architecture: ${arch}`);
|
|
115
123
|
}
|
|
116
124
|
return arch;
|
|
117
125
|
}
|
|
118
126
|
/** Get latest node version based on the provided partial version */
|
|
119
|
-
async function getNodeVersion(nodeVersion) {
|
|
127
|
+
async function getNodeVersion(os, arch, nodeVersion) {
|
|
120
128
|
// validate nodeVersion using regex. Allowed formats: 16, 16.0, 16.0.0
|
|
121
129
|
const regex = /^\d{1,2}(\.\d{1,2}){0,2}$/;
|
|
122
130
|
if (!regex.test(nodeVersion)) {
|
|
@@ -129,18 +137,30 @@ async function getNodeVersion(nodeVersion) {
|
|
|
129
137
|
if (parts.length === 3) {
|
|
130
138
|
return nodeVersion;
|
|
131
139
|
}
|
|
132
|
-
|
|
140
|
+
let url;
|
|
141
|
+
switch (arch) {
|
|
142
|
+
case 'riscv64':
|
|
143
|
+
case 'loong64':
|
|
144
|
+
url = 'https://unofficial-builds.nodejs.org/download/release/index.json';
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
url = 'https://nodejs.org/dist/index.json';
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const response = await fetch(url);
|
|
133
151
|
if (!response.ok) {
|
|
134
152
|
throw new Error('Failed to fetch node versions');
|
|
135
153
|
}
|
|
136
154
|
const versions = await response.json();
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
.
|
|
140
|
-
|
|
155
|
+
const nodeOS = os === 'darwin' ? 'osx' : os;
|
|
156
|
+
const latestVersionAndFiles = versions
|
|
157
|
+
.map((v) => [v.version, v.files])
|
|
158
|
+
.find(([v, files]) => v.startsWith(`v${nodeVersion}`) &&
|
|
159
|
+
files.find((f) => f.startsWith(`${nodeOS}-${arch}`)));
|
|
160
|
+
if (!latestVersionAndFiles) {
|
|
141
161
|
throw new Error(`Node version ${nodeVersion} not found`);
|
|
142
162
|
}
|
|
143
|
-
return
|
|
163
|
+
return latestVersionAndFiles[0];
|
|
144
164
|
}
|
|
145
165
|
/** Fetch, validate and extract nodejs binary. Returns a path to it */
|
|
146
166
|
async function getNodejsExecutable(target, opts) {
|
|
@@ -154,12 +174,23 @@ async function getNodejsExecutable(target, opts) {
|
|
|
154
174
|
if (opts.useLocalNode) {
|
|
155
175
|
return process.execPath;
|
|
156
176
|
}
|
|
157
|
-
const nodeVersion = await getNodeVersion(target.nodeRange.replace('node', ''));
|
|
158
177
|
const os = getNodeOs(target.platform);
|
|
159
178
|
const arch = getNodeArch(target.arch);
|
|
179
|
+
const nodeVersion = await getNodeVersion(os, arch, target.nodeRange.replace('node', ''));
|
|
160
180
|
const fileName = `node-${nodeVersion}-${os}-${arch}.${os === 'win' ? 'zip' : 'tar.gz'}`;
|
|
161
|
-
|
|
162
|
-
|
|
181
|
+
let url;
|
|
182
|
+
let checksumUrl;
|
|
183
|
+
switch (arch) {
|
|
184
|
+
case 'riscv64':
|
|
185
|
+
case 'loong64':
|
|
186
|
+
url = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/${fileName}`;
|
|
187
|
+
checksumUrl = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/SHASUMS256.txt`;
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
url = `https://nodejs.org/dist/${nodeVersion}/${fileName}`;
|
|
191
|
+
checksumUrl = `https://nodejs.org/dist/${nodeVersion}/SHASUMS256.txt`;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
163
194
|
const downloadDir = (0, path_1.join)((0, os_1.homedir)(), '.pkg-cache', 'sea');
|
|
164
195
|
// Ensure the download directory exists
|
|
165
196
|
if (!(await exists(downloadDir))) {
|
|
@@ -215,6 +246,7 @@ async function sea(entryPoint, opts) {
|
|
|
215
246
|
// create a temporary directory for the processing work
|
|
216
247
|
const tmpDir = (0, path_1.join)((0, os_1.tmpdir)(), 'pkg-sea', `${Date.now()}`);
|
|
217
248
|
await (0, promises_1.mkdir)(tmpDir, { recursive: true });
|
|
249
|
+
const previousDirectory = process.cwd();
|
|
218
250
|
try {
|
|
219
251
|
// change working directory to the temp directory
|
|
220
252
|
process.chdir(tmpDir);
|
|
@@ -262,6 +294,7 @@ async function sea(entryPoint, opts) {
|
|
|
262
294
|
await (0, promises_1.rm)(tmpDir, { recursive: true }).catch(() => {
|
|
263
295
|
log_1.log.warn(`Failed to cleanup the temp directory ${tmpDir}`);
|
|
264
296
|
});
|
|
297
|
+
process.chdir(previousDirectory);
|
|
265
298
|
}
|
|
266
299
|
}
|
|
267
300
|
exports.default = sea;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yao-pkg/pkg",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Package your Node.js project into an executable",
|
|
5
5
|
"main": "lib-es5/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@babel/generator": "^7.23.0",
|
|
26
26
|
"@babel/parser": "^7.23.0",
|
|
27
27
|
"@babel/types": "^7.23.0",
|
|
28
|
-
"@yao-pkg/pkg-fetch": "3.5.
|
|
28
|
+
"@yao-pkg/pkg-fetch": "3.5.19",
|
|
29
29
|
"into-stream": "^6.0.0",
|
|
30
30
|
"minimist": "^1.2.6",
|
|
31
31
|
"multistream": "^4.1.0",
|