Skip to content

Commit ef3d86c

Browse files
authored
Merge branch 'main' into fix/less-globbing
2 parents 6e1c109 + 20e8dda commit ef3d86c

File tree

5 files changed

+79
-17
lines changed

5 files changed

+79
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [6.1.1](https://github.com/yao-pkg/pkg/compare/v6.1.0...v6.1.1) (2024-11-13)
2+
3+
### Bug Fixes
4+
5+
- missing `fs/promises` patches to resolve `Not found` error ([#124](https://github.com/yao-pkg/pkg/issues/124)) ([93fed60](https://github.com/yao-pkg/pkg/commit/93fed60943fef354e0cefde58b72fa48eb8ff23e))
6+
17
## [6.1.0](https://github.com/yao-pkg/pkg/compare/v6.0.1...v6.1.0) (2024-11-04)
28

39
### Features

lib/sea.ts

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@ function getNodeOs(platform: string) {
156156

157157
/** Get the node arch based on target arch */
158158
function getNodeArch(arch: string) {
159-
const allowedArchs = ['x64', 'arm64', 'armv7l', 'ppc64', 's390x'];
159+
const allowedArchs = [
160+
'x64',
161+
'arm64',
162+
'armv7l',
163+
'ppc64',
164+
's390x',
165+
'riscv64',
166+
'loong64',
167+
];
160168

161169
if (!allowedArchs.includes(arch)) {
162170
throw new Error(`Unsupported architecture: ${arch}`);
@@ -166,7 +174,7 @@ function getNodeArch(arch: string) {
166174
}
167175

168176
/** Get latest node version based on the provided partial version */
169-
async function getNodeVersion(nodeVersion: string) {
177+
async function getNodeVersion(os: string, arch: string, nodeVersion: string) {
170178
// validate nodeVersion using regex. Allowed formats: 16, 16.0, 16.0.0
171179
const regex = /^\d{1,2}(\.\d{1,2}){0,2}$/;
172180
if (!regex.test(nodeVersion)) {
@@ -183,23 +191,39 @@ async function getNodeVersion(nodeVersion: string) {
183191
return nodeVersion;
184192
}
185193

186-
const response = await fetch('https://nodejs.org/dist/index.json');
194+
let url;
195+
switch (arch) {
196+
case 'riscv64':
197+
case 'loong64':
198+
url = 'https://unofficial-builds.nodejs.org/download/release/index.json';
199+
break;
200+
default:
201+
url = 'https://nodejs.org/dist/index.json';
202+
break;
203+
}
204+
205+
const response = await fetch(url);
187206

188207
if (!response.ok) {
189208
throw new Error('Failed to fetch node versions');
190209
}
191210

192211
const versions = await response.json();
193212

194-
const latestVersion = versions
195-
.map((v: { version: string }) => v.version)
196-
.find((v: string) => v.startsWith(`v${nodeVersion}`));
213+
const nodeOS = os === 'darwin' ? 'osx' : os;
214+
const latestVersionAndFiles = versions
215+
.map((v: { version: string; files: string[] }) => [v.version, v.files])
216+
.find(
217+
([v, files]: [string, string[]]) =>
218+
v.startsWith(`v${nodeVersion}`) &&
219+
files.find((f: string) => f.startsWith(`${nodeOS}-${arch}`)),
220+
);
197221

198-
if (!latestVersion) {
222+
if (!latestVersionAndFiles) {
199223
throw new Error(`Node version ${nodeVersion} not found`);
200224
}
201225

202-
return latestVersion;
226+
return latestVersionAndFiles[0];
203227
}
204228

205229
/** Fetch, validate and extract nodejs binary. Returns a path to it */
@@ -222,16 +246,31 @@ async function getNodejsExecutable(
222246
return process.execPath;
223247
}
224248

249+
const os = getNodeOs(target.platform);
250+
const arch = getNodeArch(target.arch);
251+
225252
const nodeVersion = await getNodeVersion(
253+
os,
254+
arch,
226255
target.nodeRange.replace('node', ''),
227256
);
228257

229-
const os = getNodeOs(target.platform);
230-
const arch = getNodeArch(target.arch);
231-
232258
const fileName = `node-${nodeVersion}-${os}-${arch}.${os === 'win' ? 'zip' : 'tar.gz'}`;
233-
const url = `https://nodejs.org/dist/${nodeVersion}/${fileName}`;
234-
const checksumUrl = `https://nodejs.org/dist/${nodeVersion}/SHASUMS256.txt`;
259+
260+
let url;
261+
let checksumUrl;
262+
switch (arch) {
263+
case 'riscv64':
264+
case 'loong64':
265+
url = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/${fileName}`;
266+
checksumUrl = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/SHASUMS256.txt`;
267+
break;
268+
default:
269+
url = `https://nodejs.org/dist/${nodeVersion}/${fileName}`;
270+
checksumUrl = `https://nodejs.org/dist/${nodeVersion}/SHASUMS256.txt`;
271+
break;
272+
}
273+
235274
const downloadDir = join(homedir(), '.pkg-cache', 'sea');
236275

237276
// Ensure the download directory exists

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yao-pkg/pkg",
3-
"version": "6.1.0",
3+
"version": "6.1.1",
44
"description": "Package your Node.js project into an executable",
55
"main": "lib-es5/index.js",
66
"license": "MIT",

prelude/bootstrap.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,12 +1722,16 @@ function payloadFileSync(pointer) {
17221722
fs.promises.stat = util.promisify(fs.stat);
17231723
fs.promises.lstat = util.promisify(fs.lstat);
17241724

1725-
/*
17261725
fs.promises.read = util.promisify(fs.read);
17271726
fs.promises.realpath = util.promisify(fs.realpath);
17281727
fs.promises.fstat = util.promisify(fs.fstat);
1728+
fs.promises.statfs = util.promisify(fs.fstat);
17291729
fs.promises.access = util.promisify(fs.access);
1730-
*/
1730+
1731+
// TODO: all promises methods that try to edit files in snapshot should throw
1732+
// TODO implement missing methods
1733+
// fs.promises.readlink ?
1734+
// fs.promises.opendir ?
17311735
}
17321736

17331737
// ///////////////////////////////////////////////////////////////

prelude/diagnostic.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function humanSize(bytes) {
8080
return totalSize;
8181
}
8282
function wrap(obj, name) {
83-
const f = fs[name];
83+
const f = obj[name];
8484
obj[name] = (...args) => {
8585
const args1 = Object.values(args);
8686
console.log(
@@ -111,6 +111,7 @@ function humanSize(bytes) {
111111
wrap(fs, 'open');
112112
wrap(fs, 'readSync');
113113
wrap(fs, 'read');
114+
wrap(fs, 'readFile');
114115
wrap(fs, 'writeSync');
115116
wrap(fs, 'write');
116117
wrap(fs, 'closeSync');
@@ -131,6 +132,18 @@ function humanSize(bytes) {
131132
wrap(fs, 'exists');
132133
wrap(fs, 'accessSync');
133134
wrap(fs, 'access');
135+
136+
wrap(fs.promises, 'open');
137+
wrap(fs.promises, 'read');
138+
wrap(fs.promises, 'readFile');
139+
wrap(fs.promises, 'write');
140+
wrap(fs.promises, 'readdir');
141+
wrap(fs.promises, 'realpath');
142+
wrap(fs.promises, 'stat');
143+
wrap(fs.promises, 'lstat');
144+
wrap(fs.promises, 'fstat');
145+
wrap(fs.promises, 'access');
146+
wrap(fs.promises, 'copyFile');
134147
}
135148
}
136149
})();

0 commit comments

Comments
 (0)