diff --git a/docs/changelog.md b/docs/changelog.md index f4d107320..a81d10937 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Validation for `options.version`. + ## [4.2.1] - 2023-03-28 ### Changed diff --git a/docs/contributing.md b/docs/contributing.md index 777688a0d..f675de2ad 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -12,12 +12,12 @@ Install Node. Consult the [version manifest](https://nwjs.io/versions) before in Clone the fork. -Created a new branch. If you are addressing a specific issue (for example #54), then name the branch `dev-54`. If you encounter a problem which has not been documented (even after searching all closed issues), either open an new issue or create a branch such as `fix/glob-nested-dirs`. +Creat a new branch. If you are addressing a specific issue (for example #54), then name the branch `dev-54`. If you encounter a problem which has not been documented (even after searching all closed issues), either open a new issue or create a branch such as `fix/glob-nested-dirs`. ## General Tips -Add inline code comments if the change you make may not be obvious to others. Add tests that cover the behavioru change. We use Node's test runner and Jest (slowly migrating away from it) for unit tests and Chromedriver for e2e tests. +Add inline code comments if the change you make may not be obvious to others. Add tests that cover the behaviour change. We use Node's test runner and Jest (slowly migrating away from it) for unit tests and Chromedriver for e2e tests. -Our test coverage is not great. Do not assume the package works even if all tests pass. Dependency updates are handled by `dependabot` unless your code change requires a version bump. +Our test coverage is not great. Do not assume the package works even if all tests pass. Dependency updates are handled by `dependabot` unless your code change requires a version bump. If certain behaviour can be implemented using Node's standard library, that is always preferred over a third party library. -If you're uncertain about any of the above, make the pull request anyway. A maintainer/community member will help you out. +If you're unsure about any of the above, make the pull request anyway. A maintainer/community member will help you out. diff --git a/docs/install.md b/docs/install.md index 027f28c26..91d9290c6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,8 +1,8 @@ # Installation Guide -Every NW.js release includes a modified Node.js at a specific version. By installing a version greater/equal to NW.js's Node version, you get to use the latest features. In that case tt is recommended to use a [Node Version Manager](https://nodejs.org/en/download/package-manager) to manage multiple Node installations. Consult the [manifest](https://nwjs.io/versions) for what Node version to install. +Every NW.js release includes a modified Node.js at a specific version. It is recommended to [install](https://nodejs.org/en/download/package-manager) a version greater than or equal to NW.js's Node version. Consult the [version manifest](https://nwjs.io/versions) on the version to install. -With the environment setup, install `nw-builder` using npm: +With the environment set up, install `nw-builder` using npm: Using npm: @@ -14,13 +14,13 @@ npm i -D nw-builder You may use alternate package managers: -Enable `corepack` if your Node version is above `v14.19.0` or `v16.9.0`: +Enable `corepack`: ```shell corepack enable ``` -You may install it via npm if your version does not match: +Or install it if your version does not include it: ```shell npm i -g corepack diff --git a/docs/usage-basic.md b/docs/usage-basic.md index a74fc9ffb..3d0efc6fb 100644 --- a/docs/usage-basic.md +++ b/docs/usage-basic.md @@ -1,6 +1,6 @@ # Basic Usage -Depending on your needs, `nw-builder` can be used via a JavaScript module, via command line interface or via `package.json`. Please note that if `package.json` is used, it will override the module or CLI configuration. A single function is exported which performs a single build using a specific [build flavor](https://nwjs.readthedocs.io/en/latest/For%20Users/Advanced/Build%20Flavors/) for a specific platform and architecture. +Depending on your use case, `nw-builder` can be used via a JavaScript module, command line interface or `package.json`. Please note that if `package.json` is used, it will override the module or CLI configuration. ## Import package @@ -29,7 +29,7 @@ let nwbuild = undefined; Module usage: ```javascript -nwbuild({ ...options }); +nwbuild(); ``` CLI usage: @@ -42,8 +42,8 @@ npx nwbuild ```json { - "nwbuild": { - ... - } + "nwbuild": {} } ``` + +By default, it performs a build using the latest version for the host platform and architecture. The next few guides will show you how to customize this behaviour. \ No newline at end of file diff --git a/package.json b/package.json index 68a48288f..1f22ce65c 100644 --- a/package.json +++ b/package.json @@ -48,9 +48,9 @@ "test:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "test:unit": "node --test-reporter=spec --test test/unit/index.js", "test:e2e": "node --test-reporter=spec --test e2e/index.js", - "test:manual:get": "cd test/fixture && nwbuild --mode=get", - "test:manual:dev": "cd test/fixture && nwbuild --mode=run ./app --no-glob", - "test:manual:bld": "cd test/fixture && nwbuild --mode=build ./app --no-glob" + "test:manual:get": "cd test/fixture && nwbuild --mode=get --version=0.74.0", + "test:manual:dev": "cd test/fixture && nwbuild --mode=run --version=0.74.0 ./app --no-glob", + "test:manual:bld": "cd test/fixture && nwbuild --mode=build --version=0.74.0 ./app --no-glob" }, "devDependencies": { "eslint": "^8.36.0", diff --git a/src/nwbuild.js b/src/nwbuild.js index 34b32590f..a6f74d70d 100644 --- a/src/nwbuild.js +++ b/src/nwbuild.js @@ -10,7 +10,7 @@ import { develop } from "./run/develop.js"; import { isCached } from "./util/cache.js"; import { replaceFfmpeg } from "./util/ffmpeg.js"; import { getFiles } from "./util/files.js"; -import { getManifest } from "./util/manifest.js"; +import { getVersionManifest } from "./util/versionManifest.js"; import { parse } from "./util/parse.js"; import { validate } from "./util/validate.js"; import { xattr } from "./util/xattr.js"; @@ -99,7 +99,7 @@ const nwbuild = async (options) => { if (options.mode !== "get") { files = options.glob ? await getFiles(options.srcDir) : options.srcDir; - manifest = await getManifest(files, options.glob); + manifest = await getVersionManifest(files, options.glob); if (typeof manifest?.nwbuild === "object") { options = manifest.nwbuild; } @@ -129,16 +129,16 @@ const nwbuild = async (options) => { options.cacheDir, options.manifestUrl, ); - // Remove leading "v" from version string - options.version = releaseInfo.version.slice(1); await validate(options, releaseInfo); + // Remove leading "v" from version string + options.version = releaseInfo.version.slice(1); + // Variable to store nwDir file path nwDir = resolve( options.cacheDir, - `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${ - options.platform + `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform }-${options.arch}`, ); diff --git a/src/util/parse.js b/src/util/parse.js index 1596cec78..43d241a9f 100644 --- a/src/util/parse.js +++ b/src/util/parse.js @@ -12,6 +12,7 @@ import { getPlatform } from "./platform.js"; * @return {Promise} Options */ export const parse = async (options, pkg) => { + options = options ?? {}; options.mode = options.mode ?? "build"; options.version = options.version ?? "latest"; diff --git a/src/util/validate.js b/src/util/validate.js index 17399cf7e..2ea7b3c6f 100644 --- a/src/util/validate.js +++ b/src/util/validate.js @@ -14,7 +14,9 @@ export const validate = async (options, releaseInfo) => { `Unknown mode ${options.mode}. Expected "get", "run" or "build".`, ); } - // We don't validate version since getReleaseInfo already does that + if (typeof releaseInfo === "undefined") { + throw new Error("The specified version does not exist in the version manifest. Disable cache to redownload the version manifest. If you still get this error, that means the version you've specified is incorrect."); + } if (!releaseInfo.flavors.includes(options.flavor)) { throw new Error( `${options.flavor} flavor is not supported by this download server.`, diff --git a/src/util/manifest.js b/src/util/versionManifest.js similarity index 93% rename from src/util/manifest.js rename to src/util/versionManifest.js index daa547258..f5810e7d0 100644 --- a/src/util/manifest.js +++ b/src/util/versionManifest.js @@ -8,7 +8,7 @@ import { basename } from "node:path"; * @param {boolean} glob Whether or not the files are glob patterns * @return {Promise} NW.js manifest file */ -export const getManifest = async (files, glob) => { +export const getVersionManifest = async (files, glob) => { let manifest; if (glob === false) {