Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,43 @@ jobs:
- name: Build
run: npm run build

- name: Smoke test
run: |
dist/cli.js

- name: Store dist
uses: actions/upload-artifact@v4
with:
name: dist
if-no-files-found: error
path: dist/**

test:
name: Smoke Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: npm

- name: Setup NPM dependencies
run: npm install

- name: Download dist
uses: actions/download-artifact@v4
with:
name: dist
path: dist
merge-multiple: true

- name: Smoke test
run: |
node dist/cli.js
5 changes: 4 additions & 1 deletion src/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export default async function (
outputName = path.basename(entrypoint).split(".")[0];
}
outputName = flags.outputName || outputName || "bundled";
const currentPlatform = `${process.platform}-${process.arch}`;
// For Windows, `process.platform` is `win32` but the archives just use `win`, sigh...
const normalizedPlatform =
process.platform === "win32" ? "win" : process.platform;
const currentPlatform = `${normalizedPlatform}-${process.arch}`;
const platforms =
!flags.platforms || flags.platforms.length === 0
? (process.env["FOSSILIZE_PLATFORMS"] || currentPlatform)
Expand Down
45 changes: 24 additions & 21 deletions src/node-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ async function getNodeBinaryFromCache(
return cacheSourceFile;
}
const targetFile = `${targetPath}-${platform}${ext}`;
await fs.copyFile(cacheSourceFile, targetFile);
if (platform.startsWith("darwin") || platform.startsWith("win")) {
const nodeBuffer = await fs.readFile(cacheSourceFile);
let unsigned: ArrayBufferLike | null = null;
if (platform.startsWith("win")) {
unsigned = signatureSet(nodeBuffer, null);
} else if (platform.startsWith("darwin")) {
unsigned = unsign(nodeBuffer.buffer);
}
if (!unsigned) {
throw new Error(`Failed to unsign binary: ${cacheSourceFile}`);
}
await fs.writeFile(targetFile, Buffer.from(unsigned));
} else {
await fs.copyFile(cacheSourceFile, targetFile);
}
return targetFile;
}

Expand Down Expand Up @@ -91,7 +105,7 @@ export async function _resolveNodeVersion(version: string): Promise<string> {
resolvedVersion = versionBits.join(".");
}
console.log(`Resolved Node.js version '${version}' to ${resolvedVersion}`);
const [nodeVersionMajor, nodeVersionMinor] = resolvedVersion
const [nodeVersionMajor, _nodeVersionMinor] = resolvedVersion
.match(NODE_VERSION_REGEX)!
.slice(1, 3)
.map(Number) as [number, number];
Expand Down Expand Up @@ -169,28 +183,17 @@ export async function getNodeBinary(
if (platform.startsWith("win")) {
const stream = createWriteStream(path.join(nodeDir, remoteArchiveName));
await finished(Readable.fromWeb(resp.body).pipe(stream));
const sourceFile = path.join(
`node-v${resolvedVersion}-${platform}`,
"node.exe"
const data = await unzip(
stream.path as string,
// Need `/` as path separator, even on Windows as that's how `unzip` works
`node-v${resolvedVersion}-${platform}/node.exe`
);
const data = await unzip(stream.path as string, sourceFile);
const unsigned = signatureSet(data, null);
await fs.writeFile(cacheTargetFile, Buffer.from(unsigned));
await fs.writeFile(cacheTargetFile, data);
} else {
const sourceFile = path.join(
`node-v${resolvedVersion}-${platform}`,
"bin",
"node"
await fs.writeFile(
cacheTargetFile,
await untar(resp.body, `node-v${resolvedVersion}-${platform}/bin/node`)
);
let nodeBuffer: Buffer = await untar(resp.body, sourceFile);
if (platform.startsWith("darwin")) {
const unsigned = unsign(nodeBuffer.buffer);
if (!unsigned) {
throw new Error(`Failed to unsign macOS binary: ${sourceFile}`);
}
nodeBuffer = Buffer.from(unsigned);
}
await fs.writeFile(cacheTargetFile, nodeBuffer);
}
await fs.chmod(cacheTargetFile, 0o755);

Expand Down