Skip to content

Commit

Permalink
fix: missing symlinks in macos (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra authored Dec 20, 2023
1 parent eb7906a commit 8ab84ea
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ jobs:
run: npm ci
- name: Check for linting errors
run: npm run lint
- name: Link module
run: npm link nw-builder
- name: Run tests
run: npm run test
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.5.1] - 2023-12-19

### Changed

- Manually create symbolic links for MacOS builds.

## [4.5.0] - 2023-12-18

## Added

- Use `unzipper` to decompress ZIP files.

## Changed

- Use `tar` to extract tarballs.
- Disable `options.nativeAddon`.

### Removed

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"scripts": {
"lint": "eslint src/get.js",
"docs": "jsdoc -d docs ./src/get.js ./src/run.js ./src/bld.js",
"test": "node test/index.js",
"test": "node test/get.pre.js && node --test test/get.test.js",
"demo": "cd test/fixture && node demo.js"
},
"devDependencies": {
Expand Down
33 changes: 31 additions & 2 deletions src/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ import util from "./util.js";
* });
*/
async function get(options) {
if (fs.existsSync(options.cacheDir) === false) {
await fsm.mkdir(options.cacheDir, { recursive: true });
}
await getNwjs(options);
if (options.ffmpeg === true) {
await getFfmpeg(options);
Expand Down Expand Up @@ -123,7 +126,12 @@ const getNwjs = async (options) => {
});
} else {
fs.createReadStream(out)
.pipe(unzipper.Extract({ path: options.cacheDir }));
.pipe(unzipper.Extract({ path: options.cacheDir }))
.on("finish", async () => {
if (options.platform === "osx") {
await createSymlinks(options);
}
});
}
return;
}
Expand Down Expand Up @@ -194,7 +202,12 @@ const getNwjs = async (options) => {
});
} else {
fs.createReadStream(out)
.pipe(unzipper.Extract({ path: options.cacheDir }));
.pipe(unzipper.Extract({ path: options.cacheDir }))
.on("finish", async () => {
if (options.platform === "osx") {
await createSymlinks(options);
}
});
}
}

Expand Down Expand Up @@ -346,4 +359,20 @@ const getNodeHeaders = async (options) => {
);
}

const createSymlinks = async (options) => {
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");
const symlinks = [
path.join(frameworksPath, "Helpers"),
path.join(frameworksPath, "Libraries"),
path.join(frameworksPath, "nwjs Framework"),
path.join(frameworksPath, "Resources"),
path.join(frameworksPath, "Versions", "Current"),
];
for await (const symlink of symlinks) {
const link = String(await fsm.readFile(symlink));
await fsm.rm(symlink);
await fsm.symlink(link, symlink);
}
};

export default get;
17 changes: 17 additions & 0 deletions test/get.pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import get from "../src/get.js";

// TODO: fix get function and move this into a before hook
// Running this inside a before hook makes the test suite fail.
// There is likely some asyncronous behaviour that is not being handled properly.
// This allows the test suite to pass.
await get({
version: "0.82.0",
flavor: "sdk",
platform: "osx",
arch: "x64",
downloadUrl: "https://dl.nwjs.io",
cacheDir: "test/fixture/cache",
cache: true,
ffmpeg: false,
nativeAddon: false,
});
42 changes: 42 additions & 0 deletions test/get.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import assert from "node:assert";
import fs from "node:fs";
import fsm from "node:fs/promises";
import path from "node:path";
import process from "node:process";
import { describe, it } from "node:test";

describe("get", async () => {

const options = {
version: "0.82.0",
flavor: "sdk",
platform: "osx",
arch: "x64",
downloadUrl: "https://dl.nwjs.io",
cacheDir: "test/fixture/cache",
cache: true,
ffmpeg: false,
nativeAddon: false,
};

it("downloads macos binary", async function () {
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);
});

it("preserves symlinks on macos build", async function () {
// await get({...options})
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");
const symlinks = [
path.join(frameworksPath, "Helpers"),
path.join(frameworksPath, "Libraries"),
path.join(frameworksPath, "nwjs Framework"),
path.join(frameworksPath, "Resources"),
path.join(frameworksPath, "Versions", "Current"),
];

for (const symlink of symlinks) {
const stats = await fsm.lstat(symlink);
assert.strictEqual(stats.isSymbolicLink(), true);
}
});
});
5 changes: 0 additions & 5 deletions test/index.js

This file was deleted.

3 changes: 1 addition & 2 deletions test/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ describe("test modes", async () => {

const chromedriverPath = resolve(
nwOptions.cacheDir,
`nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${
nwOptions.platform
`nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${nwOptions.platform
}-${nwOptions.arch}`,
`chromedriver${nwOptions.platform === "win" ? ".exe" : ""}`,
);
Expand Down

0 comments on commit 8ab84ea

Please sign in to comment.