Skip to content

Commit 8ab84ea

Browse files
fix: missing symlinks in macos (#990)
1 parent eb7906a commit 8ab84ea

File tree

8 files changed

+105
-12
lines changed

8 files changed

+105
-12
lines changed

.github/workflows/e2e.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ jobs:
3636
run: npm ci
3737
- name: Check for linting errors
3838
run: npm run lint
39-
- name: Link module
40-
run: npm link nw-builder
4139
- name: Run tests
4240
run: npm run test

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [4.5.1] - 2023-12-19
11+
12+
### Changed
13+
14+
- Manually create symbolic links for MacOS builds.
15+
16+
## [4.5.0] - 2023-12-18
17+
18+
## Added
19+
20+
- Use `unzipper` to decompress ZIP files.
21+
1022
## Changed
1123

1224
- Use `tar` to extract tarballs.
25+
- Disable `options.nativeAddon`.
1326

1427
### Removed
1528

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"scripts": {
4545
"lint": "eslint src/get.js",
4646
"docs": "jsdoc -d docs ./src/get.js ./src/run.js ./src/bld.js",
47-
"test": "node test/index.js",
47+
"test": "node test/get.pre.js && node --test test/get.test.js",
4848
"demo": "cd test/fixture && node demo.js"
4949
},
5050
"devDependencies": {

src/get.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ import util from "./util.js";
8484
* });
8585
*/
8686
async function get(options) {
87+
if (fs.existsSync(options.cacheDir) === false) {
88+
await fsm.mkdir(options.cacheDir, { recursive: true });
89+
}
8790
await getNwjs(options);
8891
if (options.ffmpeg === true) {
8992
await getFfmpeg(options);
@@ -123,7 +126,12 @@ const getNwjs = async (options) => {
123126
});
124127
} else {
125128
fs.createReadStream(out)
126-
.pipe(unzipper.Extract({ path: options.cacheDir }));
129+
.pipe(unzipper.Extract({ path: options.cacheDir }))
130+
.on("finish", async () => {
131+
if (options.platform === "osx") {
132+
await createSymlinks(options);
133+
}
134+
});
127135
}
128136
return;
129137
}
@@ -194,7 +202,12 @@ const getNwjs = async (options) => {
194202
});
195203
} else {
196204
fs.createReadStream(out)
197-
.pipe(unzipper.Extract({ path: options.cacheDir }));
205+
.pipe(unzipper.Extract({ path: options.cacheDir }))
206+
.on("finish", async () => {
207+
if (options.platform === "osx") {
208+
await createSymlinks(options);
209+
}
210+
});
198211
}
199212
}
200213

@@ -346,4 +359,20 @@ const getNodeHeaders = async (options) => {
346359
);
347360
}
348361

362+
const createSymlinks = async (options) => {
363+
const frameworksPath = path.join(process.cwd(), options.cacheDir, `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`, "nwjs.app", "Contents", "Frameworks", "nwjs Framework.framework");
364+
const symlinks = [
365+
path.join(frameworksPath, "Helpers"),
366+
path.join(frameworksPath, "Libraries"),
367+
path.join(frameworksPath, "nwjs Framework"),
368+
path.join(frameworksPath, "Resources"),
369+
path.join(frameworksPath, "Versions", "Current"),
370+
];
371+
for await (const symlink of symlinks) {
372+
const link = String(await fsm.readFile(symlink));
373+
await fsm.rm(symlink);
374+
await fsm.symlink(link, symlink);
375+
}
376+
};
377+
349378
export default get;

test/get.pre.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import get from "../src/get.js";
2+
3+
// TODO: fix get function and move this into a before hook
4+
// Running this inside a before hook makes the test suite fail.
5+
// There is likely some asyncronous behaviour that is not being handled properly.
6+
// This allows the test suite to pass.
7+
await get({
8+
version: "0.82.0",
9+
flavor: "sdk",
10+
platform: "osx",
11+
arch: "x64",
12+
downloadUrl: "https://dl.nwjs.io",
13+
cacheDir: "test/fixture/cache",
14+
cache: true,
15+
ffmpeg: false,
16+
nativeAddon: false,
17+
});

test/get.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import assert from "node:assert";
2+
import fs from "node:fs";
3+
import fsm from "node:fs/promises";
4+
import path from "node:path";
5+
import process from "node:process";
6+
import { describe, it } from "node:test";
7+
8+
describe("get", async () => {
9+
10+
const options = {
11+
version: "0.82.0",
12+
flavor: "sdk",
13+
platform: "osx",
14+
arch: "x64",
15+
downloadUrl: "https://dl.nwjs.io",
16+
cacheDir: "test/fixture/cache",
17+
cache: true,
18+
ffmpeg: false,
19+
nativeAddon: false,
20+
};
21+
22+
it("downloads macos binary", async function () {
23+
assert.strictEqual(fs.existsSync(path.resolve(process.cwd(), options.cacheDir, `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`, "nwjs.app")), true);
24+
});
25+
26+
it("preserves symlinks on macos build", async function () {
27+
// await get({...options})
28+
const frameworksPath = path.resolve(process.cwd(), options.cacheDir, `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`, "nwjs.app", "Contents", "Frameworks", "nwjs Framework.framework");
29+
const symlinks = [
30+
path.join(frameworksPath, "Helpers"),
31+
path.join(frameworksPath, "Libraries"),
32+
path.join(frameworksPath, "nwjs Framework"),
33+
path.join(frameworksPath, "Resources"),
34+
path.join(frameworksPath, "Versions", "Current"),
35+
];
36+
37+
for (const symlink of symlinks) {
38+
const stats = await fsm.lstat(symlink);
39+
assert.strictEqual(stats.isSymbolicLink(), true);
40+
}
41+
});
42+
});

test/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/mode.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ describe("test modes", async () => {
3838

3939
const chromedriverPath = resolve(
4040
nwOptions.cacheDir,
41-
`nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${
42-
nwOptions.platform
41+
`nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${nwOptions.platform
4342
}-${nwOptions.arch}`,
4443
`chromedriver${nwOptions.platform === "win" ? ".exe" : ""}`,
4544
);

0 commit comments

Comments
 (0)