nw-builder 4.11.5 → 4.11.6

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
@@ -385,6 +385,7 @@ nwbuild({
385
385
 
386
386
  ### Chores
387
387
 
388
+ - chore: add Linux, MacOS and Windows fixtures
388
389
  - chore(docs): don't store JSDoc definitions in `typedef`s - get's hard to understand during development.
389
390
  - chore: annotate file paths as `fs.PathLike` instead of `string`.
390
391
  - chore(bld): factor out core build step
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.11.5",
3
+ "version": "4.11.6",
4
4
  "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -47,8 +47,8 @@
47
47
  "test": "vitest run --coverage",
48
48
  "test:cov": "vitest --coverage.enabled true",
49
49
  "demo:bld": "node ./tests/fixtures/demo.js",
50
- "demo:exe": "./tests/fixtures/out/nwapp.app/Contents/MacOS/nwapp",
51
- "demo:cli": "nwbuild --mode=run --version=0.92.0 --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app"
50
+ "demo:exe": "./tests/fixtures/out/Demo.app/Contents/MacOS/Demo",
51
+ "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@eslint/js": "^9.12.0",
package/src/bld.js CHANGED
@@ -133,7 +133,13 @@ async function bld({
133
133
  await fs.promises.cp(nwDir, outDir, { recursive: true, verbatimSymlinks: true });
134
134
 
135
135
  const files = await util.globFiles({ srcDir, glob });
136
- const manifest = await util.getNodeManifest({ srcDir, glob });
136
+ let manifest = await util.getNodeManifest({ srcDir, glob });
137
+
138
+ /* Set `product_string` in manifest for MacOS. This is used in renaming the Helper apps. */
139
+ if (platform === 'osx') {
140
+ manifest.json.product_string = app.name;
141
+ await fs.promises.writeFile(manifest.path, JSON.stringify(manifest.json));
142
+ }
137
143
 
138
144
  if (glob) {
139
145
  for (let file of files) {
@@ -169,7 +175,7 @@ async function bld({
169
175
  typeof managedManifest === 'object' ||
170
176
  typeof managedManifest === 'string'
171
177
  ) {
172
- await manageManifest({ nwPkg: manifest, managedManifest, outDir, platform });
178
+ await manageManifest({ nwPkg: manifest.json, managedManifest, outDir, platform });
173
179
  }
174
180
 
175
181
  if (platform === 'linux') {
package/src/index.js CHANGED
@@ -39,18 +39,21 @@ import util from './util.js';
39
39
  async function nwbuild(options) {
40
40
  let built;
41
41
  let releaseInfo = {};
42
- let manifest = {};
42
+ let manifest = {
43
+ path: '',
44
+ json: undefined,
45
+ };
43
46
 
44
47
  try {
45
48
  // Parse options
46
49
  options = await util.parse(options, manifest);
47
50
 
48
51
  manifest = await util.getNodeManifest({ srcDir: options.srcDir, glob: options.glob });
49
- if (typeof manifest?.nwbuild === 'object') {
50
- options = manifest.nwbuild;
52
+ if (typeof manifest.json?.nwbuild === 'object') {
53
+ options = manifest.json.nwbuild;
51
54
  }
52
55
 
53
- options = await util.parse(options, manifest);
56
+ options = await util.parse(options, manifest.json);
54
57
 
55
58
  //TODO: impl logging
56
59
 
package/src/util.js CHANGED
@@ -136,25 +136,30 @@ async function globFiles({
136
136
  * @param {object} options - node manifest options
137
137
  * @param {string | string []} options.srcDir - src dir
138
138
  * @param {boolean} options.glob - glob flag
139
- * @returns {object} - Node manifest
139
+ * @returns {Promise.<{path: string, json: object}>} - Node manifest
140
140
  */
141
141
  async function getNodeManifest({
142
142
  srcDir, glob
143
143
  }) {
144
- let manifest;
144
+ let manifest = {
145
+ path: '',
146
+ json: undefined,
147
+ };
145
148
  let files;
146
149
  if (glob) {
147
150
  files = await globFiles({ srcDir, glob });
148
151
  for (const file of files) {
149
152
  if (path.basename(file) === 'package.json' && manifest === undefined) {
150
- manifest = JSON.parse(await fs.promises.readFile(file));
153
+ manifest.path = file;
154
+ manifest.json = JSON.parse(await fs.promises.readFile(file));
151
155
  }
152
156
  }
153
157
  } else {
154
- manifest = JSON.parse(await fs.promises.readFile(path.resolve(srcDir, 'package.json')));
158
+ manifest.path = path.resolve(srcDir, 'package.json');
159
+ manifest.json = JSON.parse(await fs.promises.readFile(path.resolve(srcDir, 'package.json')));
155
160
  }
156
161
 
157
- if (manifest === undefined) {
162
+ if (manifest.json === undefined) {
158
163
  throw new Error('package.json not found in srcDir file glob patterns.');
159
164
  }
160
165
 
@@ -220,8 +225,11 @@ export const parse = async (options, pkg) => {
220
225
 
221
226
  options.app = options.app ?? {};
222
227
  options.app.name = options.app.name ?? pkg.name;
223
- /* Remove special and control characters from app.name to mitigate potential path traversal. */
224
- options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, '');
228
+ /* Since the `parse` function is called twice, the first time `pkg` is `{}` and `options.app.name` is `undefined`. */
229
+ if (options.app.name) {
230
+ /* Remove special and control characters from app.name to mitigate potential path traversal. */
231
+ options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, '');
232
+ }
225
233
  options.app.icon = options.app.icon ?? undefined;
226
234
 
227
235
  // TODO(#737): move this out