diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 27f9ec8a7..c1c94bd9f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c430e95b..3cdaa92c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index 9ff0a02fc..0e24749fd 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/get.js b/src/get.js index c071d79c2..455d9f7c8 100644 --- a/src/get.js +++ b/src/get.js @@ -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); @@ -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; } @@ -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); + } + }); } } @@ -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; diff --git a/test/get.pre.js b/test/get.pre.js new file mode 100644 index 000000000..b1b544560 --- /dev/null +++ b/test/get.pre.js @@ -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, +}); diff --git a/test/get.test.js b/test/get.test.js new file mode 100644 index 000000000..384360aaa --- /dev/null +++ b/test/get.test.js @@ -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); + } + }); +}); diff --git a/test/index.js b/test/index.js deleted file mode 100644 index ae9d3d1d4..000000000 --- a/test/index.js +++ /dev/null @@ -1,5 +0,0 @@ -// import * as addonTests from "./addon.js"; -import * as modeTests from "./mode.js"; - -// addonTests; -modeTests; diff --git a/test/mode.js b/test/mode.js index d72f12a62..3fb60b834 100644 --- a/test/mode.js +++ b/test/mode.js @@ -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" : ""}`, );