nw-builder 4.5.2 → 4.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,80 +15,292 @@ For version 3, please go to the [corresponding branch](https://github.com/nwutil
15
15
  - Downloading from mirrors
16
16
  - Node Native Addon support
17
17
 
18
- Check out the [documentation](https://nwutils.io/nw-builder/) if you wish to give `nw-builder` a try.
18
+ ## Table of Contents
19
19
 
20
- > Please note that the documentation assumes you know [how to write NW.js applications](https://nwjs.readthedocs.io/en/latest/For%20Users/Getting%20Started/).
20
+ - [Installation](https://github.com/nwutils/nw-builder#install)
21
+ - [Usage](https://github.com/nwutils/nw-builder#usage)
22
+ - [Concepts](https://github.com/nwutils/nw-builder#concepts)
23
+ - [API Reference](https://github.com/nwutils/nw-builder#api-reference)
24
+ - [Guides](https://github.com/nwutils/nw-builder#guides)
25
+ - [Contributing](https://github.com/nwutils/nw-builder#contributing)
26
+ - [Roadmap](https://github.com/nwutils/nw-builder#roadmap)
27
+ - [FAQ](https://github.com/nwutils/nw-builder#faq)
28
+ - [License](https://github.com/nwutils/nw-builder#license)
21
29
 
22
- ## Installation
30
+ ## Install
23
31
 
24
- With npm:
32
+ Every NW.js release includes a modified Node.js binary at a specific version. It is recommended to [install](https://nodejs.org/en/download/package-manager) exactly that version on the host system. Not doing so may download ABI incompatible Node modules. Consult the NW.js [versions manifest](https://nwjs.io/versions) for what Node.js version to install. It is recommended to use a Node version manager (such as [volta](https://volta.sh), n, nvm, or nvm-windows) to be able to easily install and switch between Node versions.
33
+
34
+ For example, NW.js v0.83.0 comes with Node.js v21.1.0.
25
35
 
26
36
  ```shell
27
- npm install nw-builder -D
37
+ $: node --version
38
+ v21.1.0
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ This package can be used via a command line interface, be imported as a JavaScript module, or configured via the Node manifest as a JSON object.
44
+
45
+ ESM import:
46
+
47
+ ```javascript
48
+ import nwbuild from "nw-builder";
49
+ ```
50
+
51
+ CJS import:
52
+
53
+ ```javascript
54
+ let nwbuild;
55
+ import("nwbuild")
56
+ .then((object) => {
57
+ nwbuild = obj;
58
+ })
59
+ .catch((error) => {
60
+ console.error(error);
61
+ });
62
+ ```
63
+
64
+ Node manifest usage:
65
+
66
+ ```json
67
+ {
68
+ "nwbuild": {
69
+ // user specified options
70
+ }
71
+ }
72
+ ```
73
+
74
+ > From here on we will show `nw-builder` functionality by using the JavaScript module. Please note that the same method applies when using a command line or Node manifest.
75
+
76
+ ## Concepts
77
+
78
+ `nw-builder` can get, run and build NW.js applications. We refer to them as get, run and build modes.
79
+
80
+ ### Get Mode
81
+
82
+ By default you get the normal build of the latest NW.js release for your specific platform and arch. For more information, please refer to the API reference.
83
+
84
+ ```javascript
85
+ nwbuild({
86
+ mode: "get"
87
+ });
88
+ ```
89
+
90
+ Get the community built FFmeg which contains proprietary codecs. This options is disabled by default. Please read the [license's constraints](https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community) before enabling this option.
91
+
92
+ ```javascript
93
+ nwbuild({
94
+ mode: "get",
95
+ ffmpeg: true
96
+ });
97
+ ```
98
+
99
+ Get Node headers if you have to rebuild Node addons.
100
+
101
+ ```javascript
102
+ nwbuild({
103
+ mode: "get",
104
+ nativeAddon: "gyp"
105
+ });
106
+ ```
107
+
108
+ ### Run Mode
109
+
110
+ ```javascript
111
+ nwbuild({
112
+ mode: "run",
113
+ srcDir: "./app",
114
+ glob: false,
115
+ });
116
+ ```
117
+
118
+ ### Build Mode
119
+
120
+ Build with defaults:
121
+
122
+ ```javascript
123
+ nwbuild({
124
+ mode: "build",
125
+ });
126
+ ```
127
+
128
+ Managed Manifest
129
+
130
+ You can let `nw-builder` manage your node modules. The `managedManifest` options accepts a `boolean`, `string` or `object` type. It will then remove `devDependencies`, autodetect and download `dependencies` via the relevant `packageManager`. If none is specified, it uses `npm` as default.
131
+
132
+ Setting it to `true` will parse the first Node manifest it encounters as the NW manifest.
133
+
134
+ ```javascript
135
+ nwbuild({
136
+ mode: "build",
137
+ managedManifest: true,
138
+ });
139
+ ```
140
+
141
+ Setting it to a `string` implies that you are passing the file path to the NW manifest.
142
+
143
+ ```javascript
144
+ nwbuild({
145
+ mode: "build",
146
+ managedManifest: "./nw.js",
147
+ });
28
148
  ```
29
149
 
30
- With yarn:
150
+ Setting it to a `object` implies you are directly passing the NW manifest as a JavaScript object.
151
+
152
+ ```javascript
153
+ nwbuild({
154
+ mode: "build",
155
+ managedManifest: {
156
+ name: "nwdemo",
157
+ main: "index.html"
158
+ },
159
+ });
160
+ ```
161
+
162
+ Rebuild Node addons
163
+
164
+ Currently this feature is quite limited. It only builds node addons which have a `binding.gyp` file in the `srcDir`. There are plans to support nan, cmake, ffi and gn and auto rebuild native addons which are installed as node modules.
165
+
166
+ ```javascript
167
+ nwbuild({
168
+ mode: "build",
169
+ nodeAddon: "gyp",
170
+ });
171
+ ```
172
+
173
+ We recommend rebuilding Node addons for NW.js via `node-gyp` if you are using NW.js v0.83.0 or above.
31
174
 
32
175
  ```shell
33
- yarn add nw-builder -D
176
+ node-gyp rebuild --target=21.1.0 --nodedir=/path/to/nw/node/headers
34
177
  ```
35
178
 
36
- With pnpm:
179
+ NW.js's Node version should match the Node version on the host machine due to [ABI differences in V8](https://github.com/nwjs/nw.js/issues/5025).
180
+
181
+ ## API Reference
182
+
183
+ Options
184
+
185
+ | Name | Type | Default | Description |
186
+ | ---- | ------- | --------- | ----------- |
187
+ | mode | `"get" \| "run" \| "build"` | `"build"` | Choose between get, run or build mode |
188
+ | version | `string \| "latest" \| "stable"` | `"latest"` | Runtime version |
189
+ | flavor | `"normal" \| "sdk"` | `"normal"` | Runtime flavor |
190
+ | platform | `"linux" \| "osx" \| "win"` | | Host platform |
191
+ | arch | `"ia32" \| "x64" \| "arm64"` | | Host architecture |
192
+ | downloadUrl | `"https://dl.nwjs.io" \| "https://npm.taobao.org/mirrors/nwjs" \| https://npmmirror.com/mirrors/nwjs \| "https://github.com/corwin-of-amber/nw.js/releases/"` | `"https://dl.nwjs.io"` | Download server |
193
+ | manifestUrl | `"https://nwjs.io/versions" \| "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json"` | `"https://nwjs.io/versions"` | Versions manifest |
194
+ | cacheDir | `string` | `"./cache"` | Directory to cache NW binaries |
195
+ | srcDir | `string` | `"./"` | File paths to application code |
196
+ | outDir | `string` | `"./out"` | Directory to store build artifacts |
197
+ | managedManifest | `boolean \| string \| object` | `false` | Managed manifest |
198
+ | nodeAddon | `false \| "gyp"` | `false` | Rebuild Node native addons |
199
+ | cache | `boolean` | `true`| If true the existing cache is used. Otherwise it removes and redownloads it. |
200
+ | ffmpeg | `boolean` | `false`| If true the chromium ffmpeg is replaced by community version with proprietary codecs. |
201
+ | glob | `boolean` | `true`| If true file globbing is enabled when parsing `srcDir`. |
202
+ | logLevel | `"error" \| "warn" \| "info" \| "debug"` | `"info"`| Specify level of logging. |
203
+ | zip | `boolean \| "zip" \| "tar" \| "tgz"` | `false`| If true, "zip", "tar" or "tgz" the `outDir` directory is compressed. |
204
+
205
+ ## Guides
206
+
207
+ ### Get unofficial MacOS builds
208
+
209
+ If you're running older Apple machines, you can download the unofficial builds.
210
+
211
+ > Note: You will have to manually remove quarantine flag.
37
212
 
38
213
  ```shell
39
- pnpm add nw-builder -D
214
+ sudo xattr -r -d com.apple.quarantine /path/to/nwjs.app
40
215
  ```
41
216
 
42
- ## Usage
217
+ ```javascript
218
+ nwbuild({
219
+ mode: "get",
220
+ platform: "osx",
221
+ arch: "arm64",
222
+ downloadUrl: "https://github.com/corwin-of-amber/nw.js/releases/download",
223
+ manifestUrl: "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json",
224
+ });
225
+ ```
43
226
 
44
- Here is two way to use nw-build to build your nwjs applications
45
-
46
- ### CLI
47
-
48
- 1. To get nwjs cache
49
- ```bash
50
- nwbuild --mode=get
51
- ```
52
- 2. To run nwjs application
53
- ```bash
54
- nwbuild --mode=run
55
- ```
56
- 3. To build nwjs application
57
- ```bash
58
- nwbuild --mode=build
59
- ```
60
-
61
- ### JavaScript API
62
- 1. Define an npm script
63
- ```json
64
- {
65
- "scripts": {
66
- "build": "node scripts/build.js"
67
- }
68
- }
69
- ```
70
- 2. Create a build script
71
- ```javascript
72
- // scripts/build.js
73
- const { nwbuild } = require("nw-builder");
74
- await nwbuild({
75
- srcDir: "./nwapp/**/* ./other/**/*.js",
76
- mode: "build",
77
- version: "latest",
78
- flavor: "normal",
79
- platform: "linux",
80
- arch: "x64",
81
- outDir: "./build",
82
- cache: false,
83
- app: { ... },
84
- });
85
- ```
86
- 3. Run the script
87
- ```bash
88
- npm run build
89
- ```
90
-
91
- ## Alternatives
92
-
93
- - [nw-builder-platforms](https://github.com/naviapps/nw-builder-platforms) - Fork of this repo with platform specific build options
94
- - [nwjs-builder-phoenix](https://github.com/evshiron/nwjs-builder-phoenix) - Previously the most used build tool, however it is no longer maintained
227
+ > Note: Community FFmpeg binaries may not be available for unofficial builds. You will have to rebuild them yourself.
228
+
229
+ ### Get binaries via mirrors
230
+
231
+ China mirror:
232
+
233
+ ```javascript
234
+ nwbuild({
235
+ mode: "get",
236
+ downloadUrl: "https://npm.taobao.org/mirrors/nwjs",
237
+ });
238
+ ```
239
+
240
+ Singapore mirror:
241
+
242
+ ```javascript
243
+ nwbuild({
244
+ mode: "get",
245
+ downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
246
+ });
247
+ ```
248
+
249
+ ### Let `nw-builder` manage your native addons
250
+
251
+ > Note: this behaviour is buggy and quite limited. This guide is to show what will be possible in the coming minor releases.
252
+
253
+ ```javascript
254
+ nwbuild({
255
+ mode: "build",
256
+ managedManifest: true,
257
+ nativeAddon: "gyp",
258
+ });
259
+ ```
260
+
261
+ ## Contributing
262
+
263
+ ### External contributor
264
+
265
+ - We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) style of commit messages.
266
+ - Pull requests are squashed and merged onto the `main` branch.
267
+ - Lint your code before commiting your change.
268
+ - Add tests whenever possible.
269
+
270
+ ### Maintainer guidelines
271
+
272
+ ## Roadmap
273
+
274
+ ### Bugs
275
+
276
+ - Add back error, info, warn and debug logs
277
+
278
+ ### Features
279
+
280
+ - feat(get): support canary releases
281
+ - feat(bld): rename MacOS Helper apps
282
+ - feat(pkg): add `AppImage` installer
283
+ - feat(pkg): add `NSIS` installer
284
+ - feat(pkg): add `DMG` installer
285
+ - feat(get): add Linux ARM unofficial support
286
+ - feat(bld): add source code protection
287
+ - feat(pkg): add code signing
288
+
289
+ ### Chores
290
+
291
+ - chore(cicd): use `google-github-actions/release-please-action` to automate publishing to npm, updating changelog and creating releases
292
+ - chore(test): add test cases for current features
293
+ - chore(yargs): migrate to `commander`
294
+ - chore(util): factor out nw file paths finder
295
+ - chore(get): factor out https downloader
296
+ - chore(get): factor out nwjs downloader
297
+ - chore(get): factor out ffmpeg downloader
298
+ - chore(get): factor out node headers downloader
299
+ - chore(get): verify sha checksum for downloads
300
+ - chore(bld): move `.desktop` entry file logic to `create-desktop-shortcuts` package
301
+
302
+ ## FAQ
303
+
304
+ ## License
305
+
306
+ MIT License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.5.2",
3
+ "version": "4.5.4",
4
4
  "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -33,7 +33,6 @@
33
33
  "type": "module",
34
34
  "files": [
35
35
  "LICENSE",
36
- "patches",
37
36
  "src"
38
37
  ],
39
38
  "homepage": "https://github.com/nwutils/nw-builder",
@@ -42,16 +41,22 @@
42
41
  "url": "https://github.com/nwutils/nw-builder.git"
43
42
  },
44
43
  "scripts": {
45
- "lint": "eslint src/get.js",
46
- "docs": "jsdoc -d docs ./src/get.js ./src/run.js ./src/bld.js",
47
- "test": "node test/get.pre.js && node --test test/get.test.js",
44
+ "lint": "eslint ./src/**/*.js ./test/**/*.js",
45
+ "lint:fix": "eslint --fix ./**/*.{js,md} && markdownlint --fix ./README.md",
46
+ "docs": "jsdoc -d docs ./README.md ./src/index.js ./src/get.js ./src/run.js ./src/bld.js",
47
+ "test": "vitest",
48
48
  "demo": "cd test/fixture && node demo.js"
49
49
  },
50
50
  "devDependencies": {
51
+ "@stylistic/eslint-plugin-js": "^1.5.4",
51
52
  "eslint": "^8.56.0",
52
- "eslint-plugin-jsdoc": "^46.9.1",
53
+ "eslint-plugin-jsdoc": "^48.0.2",
54
+ "eslint-plugin-markdown": "^3.0.1",
53
55
  "jsdoc": "^4.0.2",
54
- "selenium-webdriver": "^4.16.0"
56
+ "markdownlint": "^0.33.0",
57
+ "markdownlint-cli": "^0.38.0",
58
+ "selenium-webdriver": "^4.16.0",
59
+ "vitest": "^1.2.1"
55
60
  },
56
61
  "dependencies": {
57
62
  "cli-progress": "^3.12.0",
@@ -60,11 +65,12 @@
60
65
  "node-gyp": "^10.0.1",
61
66
  "plist": "^3.1.0",
62
67
  "rcedit": "^4.0.1",
68
+ "semver": "^7.5.4",
63
69
  "tar": "^6.2.0",
64
- "unzipper": "^0.10.14",
65
- "yargs": "^17.7.2"
70
+ "yargs": "^17.7.2",
71
+ "yauzl-promise": "^4.0.0"
66
72
  },
67
- "packageManager": "npm@10.2.4",
73
+ "packageManager": "npm@10.3.0",
68
74
  "engines": {
69
75
  "node": ">=14"
70
76
  },
@@ -79,9 +85,17 @@
79
85
  },
80
86
  "extends": [
81
87
  "eslint:recommended",
82
- "plugin:jsdoc/recommended"
88
+ "plugin:jsdoc/recommended",
89
+ "plugin:markdown/recommended"
90
+ ],
91
+ "plugins": [
92
+ "@stylistic/js"
83
93
  ],
84
94
  "rules": {
95
+ "@stylistic/js/indent": [
96
+ "error",
97
+ 2
98
+ ],
85
99
  "jsdoc/tag-lines": "off",
86
100
  "jsdoc/check-property-names": "off"
87
101
  }
package/src/bld.js CHANGED
@@ -101,54 +101,8 @@ import util from "./util.js"
101
101
  /**
102
102
  * @async
103
103
  * @function
104
- * @param {BuildOptions} options
105
- * @return {Promise<void>}
106
- *
107
- * @example
108
- * // Minimal Usage (uses default values)
109
- * nwbuild({
110
- * mode: "build",
111
- * });
112
- *
113
- * @example
114
- * // Managed Manifest mode
115
- * // Parse first Node manifest it encounters as NW manifest
116
- * // Remove development dependencies
117
- * // Auto detect and download dependencies via relevant package manager
118
- * nwbuild({
119
- * mode: "build",
120
- * managedManifest: true
121
- * });
122
- *
123
- * @example
124
- * // Managed Manifest JSON
125
- * // Use JSON object provided as NW manifest
126
- * nwbuild({
127
- * mode: "build",
128
- * managedManifest: { name: "demo", "main": "index.html" }
129
- * });
130
- *
131
- * @example
132
- * // Managed Manifest File
133
- * // Use file path provided as NW manifest
134
- * nwbuild({
135
- * mode: "build",
136
- * managedManifest: "./manifest.json"
137
- * });
138
- *
139
- * @example
140
- * // Rebuild Node native modules
141
- * // This behaviour is currently disabled.
142
- * // Tracking issue: https://github.com/nwutils/nw-builder/pull/993
143
- * nwbuild({
144
- * mode: "build",
145
- * nodeAddon: "gyp"
146
- * });
147
- *
148
- * @example
149
- * // For MacOS ARM unofficial builds (<= v0.75), remove quarantine flag post build.
150
- * sudo xattr -r -d com.apple.quarantine /path/to/nwjs.app
151
- *
104
+ * @param {BuildOptions} options - Build options
105
+ * @returns {Promise<void>}
152
106
  */
153
107
  async function bld({
154
108
  version = "latest",
@@ -218,7 +172,7 @@ async function bld({
218
172
  typeof managedManifest === "object" ||
219
173
  typeof managedManifest === "string"
220
174
  ) {
221
- manageManifest({ manifest, managedManifest, outDir, platform });
175
+ await manageManifest({ manifest, managedManifest, outDir, platform });
222
176
  }
223
177
 
224
178
  if (platform === "linux") {
@@ -280,11 +234,11 @@ const manageManifest = async ({ nwPkg, managedManifest, outDir, platform }) => {
280
234
  );
281
235
 
282
236
  if (manifest.packageManager.startsWith("npm")) {
283
- child_process.exec(`npm install`);
237
+ child_process.execSync(`npm install`);
284
238
  } else if (manifest.packageManager.startsWith("yarn")) {
285
- child_process.exec(`yarn install`);
239
+ child_process.execSync(`yarn install`);
286
240
  } else if (manifest.packageManager.startsWith("pnpm")) {
287
- child_process.exec(`pnpm install`);
241
+ child_process.execSync(`pnpm install`);
288
242
  }
289
243
  };
290
244
 
@@ -370,10 +324,12 @@ const setWinConfig = async ({ app, outDir }) => {
370
324
  await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
371
325
  await rcedit(outDirAppExe, rcEditOptions);
372
326
  } catch (error) {
373
- console.warn(
374
- "Renaming EXE failed or unable to modify EXE. If it's the latter, ensure WINE is installed or build your application Windows platform",
375
- );
376
- console.error(error);
327
+ if (process.platform !== "win32") {
328
+ console.warn(
329
+ "Ensure WINE is installed or build your application on Windows platform",
330
+ );
331
+ }
332
+ throw error;
377
333
  }
378
334
  };
379
335
 
@@ -453,14 +409,7 @@ const buildNativeAddon = ({ cacheDir, version, platform, arch, outDir, nodeVersi
453
409
  ),
454
410
  );
455
411
 
456
- child_process.exec(
457
- `node-gyp rebuild --target=${nodeVersion} --nodedir=${nodePath}`,
458
- (error) => {
459
- if (error !== null) {
460
- console.error(error);
461
- }
462
- },
463
- );
412
+ child_process.execSync(`node-gyp rebuild --target=${nodeVersion} --nodedir=${nodePath}`);
464
413
  };
465
414
 
466
415
  const compress = async ({