nw-builder 4.21.4 → 4.22.0

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
@@ -195,7 +195,7 @@ const packagePath = await nwbuild({
195
195
  });
196
196
  ```
197
197
 
198
- `format` selects the packager to run and defaults to `"AppImage"` on Linux. Only `"AppImage"` is implemented today - `deb`, `rpm`, `msix`, `nsis` and `dmg` are reserved for later.
198
+ `format` selects the packager to run. It defaults to `"AppImage"` on Linux and `"nsis"` on Windows. Only `"AppImage"` and `"nsis"` are implemented today - `deb`, `rpm`, `msix` and `dmg` are reserved for later.
199
199
 
200
200
  ```javascript
201
201
  const appImagePath = await nwbuild({
@@ -250,6 +250,51 @@ With the CLI, pass `--publish.provider=github --publish.owner=nwutils
250
250
  [`@nwutils/packager` docs](https://www.npmjs.com/package/@nwutils/packager) for
251
251
  the `generic` provider and more details.
252
252
 
253
+ #### Windows installer (NSIS)
254
+
255
+ With `platform: "win"`, package mode builds an NSIS installer,
256
+ `<app.name>-<arch>-Setup.exe`, next to `outDir`. It installs for the current
257
+ user without asking for administrator rights, adds an uninstaller to Windows'
258
+ installed apps list, and replaces the previous version on upgrade. It needs the
259
+ NSIS compiler, `makensis`, on the host: `apt install nsis` on Linux,
260
+ `brew install makensis` on MacOS or `choco install nsis` on Windows. Wine isn't
261
+ needed, so the installer can be built on any platform.
262
+
263
+ The installer takes its details from the Windows `app` options:
264
+
265
+ - Version: `app.productVersion`, falling back to `app.version`. Both default to the `package.json` `version`, and packaging stops before building if there is none.
266
+ - Publisher: `app.company`.
267
+ - Copyright: `app.legalCopyright`.
268
+ - Icon: `app.icon`, if it's a `.ico` file. Otherwise the installer uses NSIS' default icon and a warning is logged.
269
+
270
+ Options with no `app` equivalent go in `nsis`:
271
+
272
+ | Name | Type | Default | Description |
273
+ | ----------------- | --------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
274
+ | appId | `string` | Value of `app.name` | Name of the registry key the installation is recorded under. Keep it the same across releases, so upgrades replace the old version. |
275
+ | license | `string` | | Path to a `.txt` or `.rtf` license file the user has to accept. |
276
+ | desktopShortcut | `boolean` | `true` | If true, create a desktop shortcut. |
277
+ | startMenuShortcut | `boolean` | `true` | If true, create a Start Menu shortcut. |
278
+ | makensisPath | `string` | `"makensis"` | Path to the NSIS compiler. |
279
+
280
+ ```javascript
281
+ const installerPath = await nwbuild({
282
+ mode: "package",
283
+ platform: "win",
284
+ app: {
285
+ name: "Demo",
286
+ icon: "./icon.ico",
287
+ company: "ACME",
288
+ },
289
+ nsis: {
290
+ appId: "com.example.demo",
291
+ license: "./LICENSE.txt",
292
+ },
293
+ });
294
+ ```
295
+
296
+ With the CLI, pass `--nsis.appId=com.example.demo --nsis.desktopShortcut=false`.
297
+
253
298
  ## API Reference
254
299
 
255
300
  Options
@@ -275,11 +320,12 @@ Options
275
320
  | managedManifest | `boolean \| string \| object` | `false` | Managed manifest |
276
321
  | nodeAddon | `boolean` | `false` | Rebuild Node native addons |
277
322
  | zip | `boolean \| "zip" \| "tar" \| "tgz"` | `false` | If true, "zip", "tar" or "tgz" the `outDir` directory is compressed. |
278
- | format | `"AppImage" \| "deb" \| "rpm" \| "msix" \| "nsis" \| "dmg"` | `"AppImage"` on Linux | Packaged output format, used in package mode. Only `"AppImage"` is implemented today. |
323
+ | format | `"AppImage" \| "deb" \| "rpm" \| "msix" \| "nsis" \| "dmg"` | `"AppImage"` on Linux, `"nsis"` on Windows | Packaged output format, used in package mode. Only `"AppImage"` and `"nsis"` are implemented today. |
279
324
  | sign | `boolean` | `false` | If true, embed a GPG signature in the AppImage. Used in package mode. |
280
325
  | signKey | `string` | | ID of the GPG key to sign with. Requires `sign`. Used in package mode. |
281
326
  | publish | `{provider: "github", owner, repo} \| {provider: "generic", url}` | | Where releases are published. Makes the AppImage self updatable with `@nwutils/updater`. Used in package mode. |
282
327
  | updateInformation | `boolean \| string` | | AppImage zsync update information. `true` derives it from `publish`. Used in package mode. |
328
+ | nsis | `object` | | NSIS installer options, used in package mode. See [Windows installer (NSIS)](#windows-installer-nsis). |
283
329
  | app | `LinuxRc \| WinRc \| OsxRc` | Additional options for each platform. (See below.) |
284
330
 
285
331
  ### `app` configuration object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.21.4",
3
+ "version": "4.22.0",
4
4
  "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -55,10 +55,10 @@
55
55
  "demo:cli": "nwbuild --mode=build --flavor=sdk --glob=false --cacheDir=./node_modules/nw --logLevel=debug --managedManifest=../../tests/fixtures/nw-builder/app/package.json --outDir=../../tests/fixtures/nw-builder/out/linux --app.name=Demo --app.icon=../../tests/fixtures/nw-builder/app/icon.png ../../tests/fixtures/nw-builder/app"
56
56
  },
57
57
  "dependencies": {
58
- "@nwutils/builder": "^0.1.2",
59
- "@nwutils/getter": "^0.2.5",
60
- "@nwutils/packager": "^0.5.0",
61
- "@nwutils/runner": "^0.2.6",
58
+ "@nwutils/builder": "^0.1.3",
59
+ "@nwutils/getter": "^0.3.1",
60
+ "@nwutils/packager": "^0.6.0",
61
+ "@nwutils/runner": "^0.2.7",
62
62
  "commander": "^15.0.0",
63
63
  "glob": "^13.0.6"
64
64
  },
package/src/cli.js CHANGED
@@ -63,17 +63,21 @@ program
63
63
  .allowUnknownOption(true)
64
64
  .allowExcessArguments(true);
65
65
 
66
- // Handle unknown --app.* and --publish.* arguments
66
+ // Handle unknown --app.*, --publish.* and --nsis.* arguments
67
67
  const unknownArgs = program.parse(process.argv).args;
68
68
  /** @type {Record<string, string>} */
69
69
  const appConfig = {};
70
70
  /** @type {Record<string, string>} */
71
71
  const publishConfig = {};
72
+ /** @type {Record<string, string>} */
73
+ const nsisConfig = {};
74
+ /** @type {Record<string, Record<string, string>>} */
75
+ const configs = { app: appConfig, publish: publishConfig, nsis: nsisConfig };
72
76
  for (const arg of unknownArgs) {
73
- const match = arg.match(/^--(app|publish)\.([^.=]+)=(.*)$/);
77
+ const match = arg.match(/^--(app|publish|nsis)\.([^.=]+)=(.*)$/);
74
78
  if (match) {
75
79
  const [, group, key, value] = match;
76
- (group === "app" ? appConfig : publishConfig)[key] = value;
80
+ configs[group][key] = value;
77
81
  }
78
82
  }
79
83
 
@@ -82,8 +86,12 @@ const opts = {
82
86
  ...program.opts(),
83
87
  app: appConfig,
84
88
  publish: Object.keys(publishConfig).length > 0 ? publishConfig : undefined,
89
+ nsis: Object.keys(nsisConfig).length > 0 ? nsisConfig : undefined,
85
90
  srcDir: program.args.find(
86
- (arg) => !arg.startsWith("--app") && !arg.startsWith("--publish"),
91
+ (arg) =>
92
+ !arg.startsWith("--app") &&
93
+ !arg.startsWith("--publish") &&
94
+ !arg.startsWith("--nsis"),
87
95
  ),
88
96
  cli: true,
89
97
  };
package/src/index.d.ts CHANGED
@@ -42,8 +42,24 @@ export interface Options<P extends SupportedPlatform = SupportedPlatform> {
42
42
  logLevel?: "error" | "warn" | "info" | "debug";
43
43
  /** Managed manifest */
44
44
  managedManifest?: boolean | string | object;
45
- /** Packaged output format, used in package mode. Defaults to `"AppImage"` on Linux. Only `"AppImage"` is implemented today - the others are reserved. */
45
+ /** Packaged output format, used in package mode. Defaults to `"AppImage"` on Linux and `"nsis"` on Windows. Only `"AppImage"` and `"nsis"` are implemented today - the others are reserved. */
46
46
  format?: "AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg";
47
+ /** NSIS installer options, used in package mode. The installer's version, publisher, copyright and `.ico` icon come from `app`. */
48
+ nsis?: NsisOptions;
49
+ }
50
+
51
+ /** NSIS installer options that have no equivalent in `app` */
52
+ export interface NsisOptions {
53
+ /** Name of the registry key the installation is recorded under. Defaults to `app.name`. Keep it the same across releases, so installing a new version replaces the previous one. */
54
+ appId?: string;
55
+ /** Path to a `.txt` or `.rtf` license file the user has to accept. */
56
+ license?: string;
57
+ /** If true, create a desktop shortcut. Defaults to true. */
58
+ desktopShortcut?: boolean;
59
+ /** If true, create a Start Menu shortcut. Defaults to true. */
60
+ startMenuShortcut?: boolean;
61
+ /** Path to the NSIS compiler. Defaults to `makensis` on the `PATH`. */
62
+ makensisPath?: string;
47
63
  }
48
64
 
49
65
  /** Platform-specific application options */
package/src/index.js CHANGED
@@ -33,11 +33,12 @@ import util from "./util.js";
33
33
  * @property {boolean} [nativeAddon = false] Get Node native addons
34
34
  * @property {boolean} [cli=false] If true the CLI is used to parse options. This option is used internally.
35
35
  * @property {string[]} [argv = []] CLI arguments passed to the NW.js process in run mode
36
- * @property {"AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg"} [format] Packaged output format, used in package mode. Defaults to `"AppImage"` on Linux. Only `"AppImage"` is implemented today - the others are reserved.
36
+ * @property {"AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg"} [format] Packaged output format, used in package mode. Defaults to `"AppImage"` on Linux and `"nsis"` on Windows. Only `"AppImage"` and `"nsis"` are implemented today - the others are reserved.
37
37
  * @property {boolean} [sign=false] If true, embed a GPG signature in the AppImage, used in package mode.
38
38
  * @property {string} [signKey] ID of the GPG key to sign the AppImage with, used in package mode. Requires `sign`.
39
39
  * @property {import("@nwutils/packager").PublishOptions} [publish] Where releases are published, used in package mode. Makes the AppImage self updatable with `@nwutils/updater`.
40
40
  * @property {boolean | string} [updateInformation] AppImage zsync update information, used in package mode. `true` derives it from `publish`.
41
+ * @property {import("./util.js").NsisOptions} [nsis] NSIS installer options, used in package mode. The installer's version, publisher, copyright and `.ico` icon come from `app`.
41
42
  */
42
43
 
43
44
  /**
@@ -204,20 +205,39 @@ async function nwbuild(options) {
204
205
  resolved.logLevel,
205
206
  `Packaging NW.js application as ${resolved.format}...`,
206
207
  );
207
- const packagePath = await pkg({
208
- format: resolved.format,
209
- appDir: resolved.outDir,
210
- appName: resolved.app.name,
211
- icon: resolved.app.icon,
212
- arch: resolved.arch,
213
- cacheDir: resolved.cacheDir,
214
- cache: resolved.cache,
215
- sign: resolved.sign,
216
- signKey: resolved.signKey,
217
- version: manifest.json?.version,
218
- publish: resolved.publish,
219
- updateInformation: resolved.updateInformation,
220
- });
208
+ let packagePath;
209
+ if (resolved.format === "nsis") {
210
+ const nsisOptions = util.nsisOptions(resolved);
211
+ if (resolved.app.icon && nsisOptions.icon === undefined) {
212
+ util.log(
213
+ "warn",
214
+ resolved.logLevel,
215
+ `The installer uses NSIS' default icon, since options.app.icon isn't a .ico file: ${resolved.app.icon}`,
216
+ );
217
+ }
218
+ packagePath = await pkg({
219
+ format: resolved.format,
220
+ appDir: resolved.outDir,
221
+ appName: resolved.app.name,
222
+ arch: resolved.arch,
223
+ ...nsisOptions,
224
+ });
225
+ } else {
226
+ packagePath = await pkg({
227
+ format: resolved.format,
228
+ appDir: resolved.outDir,
229
+ appName: resolved.app.name,
230
+ icon: resolved.app.icon,
231
+ arch: resolved.arch,
232
+ cacheDir: resolved.cacheDir,
233
+ cache: resolved.cache,
234
+ sign: resolved.sign,
235
+ signKey: resolved.signKey,
236
+ version: manifest.json?.version,
237
+ publish: resolved.publish,
238
+ updateInformation: resolved.updateInformation,
239
+ });
240
+ }
221
241
  util.log(
222
242
  "info",
223
243
  resolved.logLevel,
package/src/util.js CHANGED
@@ -113,6 +113,7 @@ import * as GlobModule from "glob";
113
113
  * @property {string} [signKey] GPG key to sign the AppImage with, used in package mode
114
114
  * @property {import("@nwutils/packager").PublishOptions} [publish] Where releases are published, used in package mode
115
115
  * @property {boolean | string} [updateInformation] AppImage zsync update information, used in package mode
116
+ * @property {NsisOptions} [nsis] NSIS installer options, used in package mode
116
117
  * @property {string[]} [argv] CLI arguments passed to the NW.js process in run mode
117
118
  * @property {boolean | string} [glob] If true file globbing is enabled when parsing srcDir
118
119
  * @property {string | string[]} [srcDir] File paths to application code
@@ -123,6 +124,54 @@ import * as GlobModule from "glob";
123
124
  * @property {boolean} [cli] If true the CLI is used to parse options
124
125
  */
125
126
 
127
+ /**
128
+ * NSIS installer options that have no equivalent in `options.app`. Values
129
+ * may arrive as strings from the CLI - `parse()` normalizes the booleans.
130
+ * @typedef {object} NsisOptions
131
+ * @property {string} [appId] Name of the registry key the installation is recorded under. Defaults to `app.name`. Keep it the same across releases.
132
+ * @property {string} [license] Path to a `.txt` or `.rtf` license file the user has to accept.
133
+ * @property {boolean | string} [desktopShortcut] If true, create a desktop shortcut. Defaults to true.
134
+ * @property {boolean | string} [startMenuShortcut] If true, create a Start Menu shortcut. Defaults to true.
135
+ * @property {string} [makensisPath] Path to the NSIS compiler. Defaults to `makensis` on the `PATH`.
136
+ */
137
+
138
+ /**
139
+ * Map resolved options to the options `@nwutils/packager`'s `nsis()` takes,
140
+ * besides `appDir`, `appName` and `arch`. Installer metadata comes from the
141
+ * Windows `options.app` values `@nwutils/builder` also writes into the
142
+ * executable, so both agree.
143
+ * @param {Options} options Options after `parse()`.
144
+ * @returns {{version: string, icon: string | undefined, publisher: string | undefined, copyright: string | undefined, appId: string | undefined, license: string | undefined, desktopShortcut: boolean, startMenuShortcut: boolean, makensisPath: string | undefined}} Options for `nsis()`.
145
+ */
146
+ function nsisOptions(options) {
147
+ const app = options.app ?? {};
148
+ const nsis = options.nsis ?? {};
149
+
150
+ const version = app.productVersion ?? app.version;
151
+ if (typeof version !== "string" || version === "") {
152
+ throw new Error(
153
+ 'options.format "nsis" needs the application\'s version. Set "version" in package.json, or options.app.productVersion.',
154
+ );
155
+ }
156
+
157
+ return {
158
+ version,
159
+ /* The installer icon has to be a `.ico` file, but `app.icon` is often the window's `.png` icon. */
160
+ icon:
161
+ typeof app.icon === "string" &&
162
+ path.extname(app.icon).toLowerCase() === ".ico"
163
+ ? app.icon
164
+ : undefined,
165
+ publisher: app.company === "" ? undefined : app.company,
166
+ copyright: app.legalCopyright,
167
+ appId: nsis.appId,
168
+ license: nsis.license,
169
+ desktopShortcut: /** @type {boolean} */ (nsis.desktopShortcut ?? true),
170
+ startMenuShortcut: /** @type {boolean} */ (nsis.startMenuShortcut ?? true),
171
+ makensisPath: nsis.makensisPath,
172
+ };
173
+ }
174
+
126
175
  /**
127
176
  * Get manifest (array of NW release metadata) from URL.
128
177
  * @param {string} manifestUrl Versions manifest URI, https or file path
@@ -355,9 +404,23 @@ export const parse = async (options, pkg) => {
355
404
 
356
405
  if (options.mode === "package") {
357
406
  options.format =
358
- options.format ?? (options.platform === "linux" ? "AppImage" : undefined);
407
+ options.format ??
408
+ (options.platform === "linux"
409
+ ? "AppImage"
410
+ : options.platform === "win"
411
+ ? "nsis"
412
+ : undefined);
359
413
  options.sign = str2Bool(options.sign ?? false);
360
414
  options.updateInformation = str2Bool(options.updateInformation);
415
+ if (options.format === "nsis") {
416
+ options.nsis = options.nsis ?? {};
417
+ options.nsis.desktopShortcut = str2Bool(
418
+ options.nsis.desktopShortcut ?? true,
419
+ );
420
+ options.nsis.startMenuShortcut = str2Bool(
421
+ options.nsis.startMenuShortcut ?? true,
422
+ );
423
+ }
361
424
  }
362
425
 
363
426
  options.argv = options.argv ?? [];
@@ -638,6 +701,40 @@ export const validate = async (options, releaseInfo) => {
638
701
  `options.format "AppImage" requires options.platform to be "linux". Got ${JSON.stringify(options.platform)}.`,
639
702
  );
640
703
  }
704
+ if (options.format === "nsis") {
705
+ if (options.platform !== "win") {
706
+ throw new Error(
707
+ `options.format "nsis" requires options.platform to be "win". Got ${JSON.stringify(options.platform)}.`,
708
+ );
709
+ }
710
+ const nsis = options.nsis ?? {};
711
+ for (const key of /** @type {const} */ ([
712
+ "appId",
713
+ "license",
714
+ "makensisPath",
715
+ ])) {
716
+ if (
717
+ nsis[key] !== undefined &&
718
+ (typeof nsis[key] !== "string" || nsis[key] === "")
719
+ ) {
720
+ throw new Error(
721
+ `Expected options.nsis.${key} to be a non-empty string. Got ${JSON.stringify(nsis[key])}`,
722
+ );
723
+ }
724
+ }
725
+ for (const key of /** @type {const} */ ([
726
+ "desktopShortcut",
727
+ "startMenuShortcut",
728
+ ])) {
729
+ if (nsis[key] !== undefined && typeof nsis[key] !== "boolean") {
730
+ throw new Error(
731
+ `Expected options.nsis.${key} to be a boolean. Got ${JSON.stringify(nsis[key])}`,
732
+ );
733
+ }
734
+ }
735
+ /* Throws now, before building, if the installer would have no version. */
736
+ nsisOptions(options);
737
+ }
641
738
  }
642
739
 
643
740
  /* By the time validate() runs, parse() has already defaulted options.app to {}. */
@@ -1096,4 +1193,5 @@ export default {
1096
1193
  parse,
1097
1194
  validate,
1098
1195
  log,
1196
+ nsisOptions,
1099
1197
  };