From 0c9fb931770245ca5be6930db3492daafd5e679c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:21:27 +0530 Subject: [PATCH 01/47] chore(docs): update roadmap --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1a1f9576..a60e1753 100644 --- a/README.md +++ b/README.md @@ -385,7 +385,6 @@ nwbuild({ ### Chores -- chore: add Linux, MacOS and Windows fixtures - chore(docs): don't store JSDoc definitions in `typedef`s - get's hard to understand during development. - chore: annotate file paths as `fs.PathLike` instead of `string`. - chore(bld): factor out core build step From 8125b86b36f525c30633cdb654446aa7ad6eef0b Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:26:53 +0530 Subject: [PATCH 02/47] chore(ci): upgrade MacOS and Ubuntu image runners --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ea229219..05d2ee12 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -14,8 +14,8 @@ jobs: strategy: matrix: os: - - macos-14 - - ubuntu-22.04 + - macos-15 + - ubuntu-24.04 - windows-2022 fail-fast: false runs-on: ${{ matrix.os }} From e305f3a30d445273d5158f8deee0013836adeb18 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:37:31 +0530 Subject: [PATCH 03/47] chore(test): start Windows fixture configuration --- tests/fixtures/demo.win.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/fixtures/demo.win.js diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js new file mode 100644 index 00000000..7454ec90 --- /dev/null +++ b/tests/fixtures/demo.win.js @@ -0,0 +1,16 @@ +import nwbuild from '../../src/index.js'; + +await nwbuild({ + mode: 'build', + flavor: 'sdk', + platform: 'win', + srcDir: './tests/fixtures/app', + cacheDir: './node_modules/nw', + outDir: './tests/fixtures/out', + glob: false, + app: { + name: 'Demo', + /* Relative to where the manifest will be located */ + icon: './icon.ico', + } +}); From ab3e4a6a1ff9cc4b0752bf615f75adb7e600ee16 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:38:18 +0530 Subject: [PATCH 04/47] chore(test): rename demo.js to demo.osx.js --- tests/fixtures/{demo.js => demo.osx.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/fixtures/{demo.js => demo.osx.js} (100%) diff --git a/tests/fixtures/demo.js b/tests/fixtures/demo.osx.js similarity index 100% rename from tests/fixtures/demo.js rename to tests/fixtures/demo.osx.js From 186a32d865b0165a12b3e68c4281930a103445ce Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:40:59 +0530 Subject: [PATCH 05/47] fix: undeprecate options.version --- README.md | 2 +- src/bld.js | 2 +- src/index.d.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a60e1753..8ed0e2ed 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ This object defines additional properties used for building for a specific platf | ---- | ------- | --------- | ----------- | | `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. | | `name` | `string` | Value of `name` in app's `package.json` | The name of the application | -| `version` | `string` | Value of `version` in app's `package.json` | (deprecated, Use `fileVersion` instead) The version of the application | +| `version` | `string` | Value of `version` in app's `package.json` | The version of the application | | `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. | | `company` | `string` | Value of `author` in app's `package.json` | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. | | `fileDescription` | `string` | Value of `description` in app's `package.json` | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. | diff --git a/src/bld.js b/src/bld.js index 9c11bfb2..976e06bf 100644 --- a/src/bld.js +++ b/src/bld.js @@ -66,7 +66,7 @@ import setOsxConfig from './bld/osx.js'; * https://learn.microsoft.com/en-gb/windows/win32/menurc/versioninfo-resource * @typedef {object} WinRc Windows configuration options. More info * @property {string} name The name of the application - * @property {string} version @deprecated Use {@link fileVersion} instead. The version of the application + * @property {string} version The version of the application * @property {string} comments Additional information that should be displayed for diagnostic purposes. * @property {string} company Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. * @property {string} fileDescription File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. diff --git a/src/index.d.ts b/src/index.d.ts index 0b686134..45749d2b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -61,7 +61,7 @@ export type AppOptions

= export interface WindowsAppOptions { /** The name of the application */ name?: string, - /** @deprecated Use {@link fileVersion} instead. The version of the application */ + /** The version of the application */ version?: string, /** Additional information that should be displayed for diagnostic purposes. */ comments?: string, From c1ccd814fd39851652e22921f289e13093da220a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:50:59 +0530 Subject: [PATCH 06/47] chore(bld): update docs link --- src/bld.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld.js b/src/bld.js index 976e06bf..73cf071e 100644 --- a/src/bld.js +++ b/src/bld.js @@ -62,7 +62,7 @@ import setOsxConfig from './bld/osx.js'; * References: * https://learn.microsoft.com/en-us/windows/win32/msi/version * https://learn.microsoft.com/en-gb/windows/win32/sbscs/application-manifests - * https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/deployment/trustinfo-element-clickonce-application?view=vs-2015#requestedexecutionlevel + * https://learn.microsoft.com/en-us/visualstudio/deployment/trustinfo-element-clickonce-application?view=vs-2022#requestedexecutionlevel * https://learn.microsoft.com/en-gb/windows/win32/menurc/versioninfo-resource * @typedef {object} WinRc Windows configuration options. More info * @property {string} name The name of the application From 523b445a93af4fcc9ee69cff79262a70b07e81d9 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:33:45 +0530 Subject: [PATCH 07/47] chore(docs): update roadmap --- src/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/index.js b/src/index.js index b77986d4..ae3a3af8 100644 --- a/src/index.js +++ b/src/index.js @@ -55,8 +55,6 @@ async function nwbuild(options) { options = await util.parse(options, manifest.json); - //TODO: impl logging - built = fs.existsSync(options.cacheDir); if (built === false) { await fs.promises.mkdir(options.cacheDir, { recursive: true }); From c444b69e102eb1f0091b36cf59d5eaa5da888e9a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:09:49 +0530 Subject: [PATCH 08/47] chore(util): add in house log function --- src/util.js | 29 ++++++++++++++++++++++++++++- tests/specs/util.test.js | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/specs/util.test.js diff --git a/src/util.js b/src/util.js index 6ff94c64..754e927e 100644 --- a/src/util.js +++ b/src/util.js @@ -453,4 +453,31 @@ async function fileExists(filePath) { return exists; } -export default { fileExists, getReleaseInfo, getPath, PLATFORM_KV, ARCH_KV, EXE_NAME, globFiles, getNodeManifest, parse, validate }; +/** + * Custom logging function + * @param {'debug' | 'info' | 'warn' | 'error'} severity - severity of message + * @param {'debug' | 'info' | 'warn' | 'error'} logLevel - log level requested by user + * @param {string} message - contents of message + * @returns {string} - stdout + */ +function log(severity, logLevel = 'error', message) { + const sev = { + 'debug': 4, + 'info': 3, + 'warn': 2, + 'error': 1, + }; + let stdout = ''; + const messageSeverity = sev[severity]; + const userDefSeverity = sev[logLevel]; + + if (messageSeverity <= userDefSeverity) { + stdout = `[ ${severity.toUpperCase()} ] ${message}`; + } + + console.log(stdout); + + return stdout; +} + +export default { fileExists, getReleaseInfo, getPath, PLATFORM_KV, ARCH_KV, EXE_NAME, globFiles, getNodeManifest, parse, validate, log }; diff --git a/tests/specs/util.test.js b/tests/specs/util.test.js new file mode 100644 index 00000000..c2f13a62 --- /dev/null +++ b/tests/specs/util.test.js @@ -0,0 +1,14 @@ +import { describe, expect, it } from 'vitest'; + +import util from '../../src/util.js'; + +describe('util/log', function () { + + it('shows only error message if log level is error', async function () { + expect(util.log('error', 'error', 'Sample message with severity of error')).toBe('[ ERROR ] Sample message with severity of error'); + }); + + it('shows only error message if log level is debug', async function () { + expect(util.log('debug', 'error', 'Sample message with severity of error')).toBe(''); + }); +}); From 56905caf3cf65b19a839b97ad477cefb38ca1d9f Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:40:22 +0530 Subject: [PATCH 09/47] chore(util): check for invalid input --- tests/specs/util.test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/specs/util.test.js b/tests/specs/util.test.js index c2f13a62..7c1185c7 100644 --- a/tests/specs/util.test.js +++ b/tests/specs/util.test.js @@ -5,10 +5,19 @@ import util from '../../src/util.js'; describe('util/log', function () { it('shows only error message if log level is error', async function () { - expect(util.log('error', 'error', 'Sample message with severity of error')).toBe('[ ERROR ] Sample message with severity of error'); + expect(util.log('error', 'error', 'Lorem ipsum')).toBe('[ ERROR ] Lorem ipsum'); }); it('shows only error message if log level is debug', async function () { - expect(util.log('debug', 'error', 'Sample message with severity of error')).toBe(''); + expect(util.log('debug', 'error', 'Lorem ipsum')).toBe(''); }); + + it('throws error if message severity is invalid', async function () { + expect(() => util.log('debuggy', 'error', 'Lorem ipsum')).toThrow(); + }); + + it('throws error if user defined log level is invalid', async function () { + expect(() => util.log('debug', 'errory', 'Lorem ipsum')).toThrow(); + }); + }); From 67bc126b0cefb715b70aa494de3c8ecffcb8738a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:41:04 +0530 Subject: [PATCH 10/47] chore(util): check for invalid input --- src/util.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index 754e927e..f998a11c 100644 --- a/src/util.js +++ b/src/util.js @@ -458,9 +458,17 @@ async function fileExists(filePath) { * @param {'debug' | 'info' | 'warn' | 'error'} severity - severity of message * @param {'debug' | 'info' | 'warn' | 'error'} logLevel - log level requested by user * @param {string} message - contents of message + * @throws {Error} - throw error on invalid input * @returns {string} - stdout */ -function log(severity, logLevel = 'error', message) { +function log(severity, logLevel, message) { + if (!['debug', 'info', 'warn', 'error'].includes(severity)) { + throw new Error(`Expected debug, info, warn or error message severity. Got ${severity}`); + } + if (!['debug', 'info', 'warn', 'error'].includes(logLevel)) { + throw new Error(`Expected debug, info, warn or error user defined log level. Got ${logLevel}`); + } + const sev = { 'debug': 4, 'info': 3, From e705ea0df14cfb3d8d0638f5061c86925e50adab Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:52:42 +0530 Subject: [PATCH 11/47] chore(test): try out log function --- package.json | 2 +- src/index.js | 5 +++++ tests/fixtures/demo.osx.js | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2304a678..2aba8140 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "lint:fix": "eslint --fix ./src ./tests", "test": "vitest run --coverage", "test:cov": "vitest --coverage.enabled true", - "demo:bld": "node ./tests/fixtures/demo.js", + "demo:bld": "node ./tests/fixtures/demo.osx.js", "demo:exe": "./tests/fixtures/out/Demo.app/Contents/MacOS/Demo", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" }, diff --git a/src/index.js b/src/index.js index ae3a3af8..8b429407 100644 --- a/src/index.js +++ b/src/index.js @@ -47,13 +47,18 @@ async function nwbuild(options) { try { // Parse options options = await util.parse(options, manifest); + util.log('debug', 'info', 'Parse initial options'); + util.log('debug', 'info', 'Get node manifest...'); manifest = await util.getNodeManifest({ srcDir: options.srcDir, glob: options.glob }); if (typeof manifest.json?.nwbuild === 'object') { options = manifest.json.nwbuild; } + util.log('info', options.logLevel, 'Parse final options'); options = await util.parse(options, manifest.json); + util.log('debug', options.logLevel, 'Manifest path: ', manifest.path); + util.log('debug', options.logLevel, 'Manifest file:\n', manifest.json); built = fs.existsSync(options.cacheDir); if (built === false) { diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index ae29dfee..e65a270e 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -8,6 +8,7 @@ await nwbuild({ cacheDir: './node_modules/nw', outDir: './tests/fixtures/out', glob: false, + logLevel: 'debug', app: { name: 'Demo', // MacOS options From 0ef2df35c4a2ec0bd1fb90bc37aaecb58bcd1afb Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:03:59 +0530 Subject: [PATCH 12/47] fix(get): listen for Ctrl+C and delete partially downloaded file --- src/get/request.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/get/request.js b/src/get/request.js index 2c39c2e8..0e077363 100644 --- a/src/get/request.js +++ b/src/get/request.js @@ -1,4 +1,5 @@ import fs from 'node:fs'; +import process from 'node:process'; import stream from 'node:stream'; import axios from 'axios'; @@ -15,6 +16,15 @@ export default async function request(url, filePath) { const writeStream = fs.createWriteStream(filePath); + // Listen for SIGINT (Ctrl+C) + process.on('SIGINT', function () { + /* Delete file if it exists. This prevents unecessary `Centrol Directory not found` errors. */ + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); + } + process.exit(); + }); + const response = await axios({ method: 'get', url: url, @@ -22,4 +32,5 @@ export default async function request(url, filePath) { }); await stream.promises.pipeline(response.data, writeStream); + } From 79696d3ca6a017537cbd5990bbc8ca304174f38a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:36:00 +0530 Subject: [PATCH 13/47] fix(docs): correct default value of options.app.legalCopyright for Windows --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ed0e2ed..f2395ff5 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ This object defines additional properties used for building for a specific platf | `fileDescription` | `string` | Value of `description` in app's `package.json` | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. | | `fileVersion` | `string` | Value of `version` option or value of `version` in app's `package.json` | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. | | `internalName` | `string` | Value of `name` in app's `package.json` |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. | -| `legalCopyright` | `string` | NW.js' copyright info | Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional. | +| `legalCopyright` | `string` | `undefined` | Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional. | | `legalTrademark` | `string` | `undefined` | Trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. This string is optional. | | `originalFilename` | `string` | Value of `name` option | Original name of the file, not including a path. This information enables an application to determine whether a file has been renamed by a user. The format of the name depends on the file system for which the file was created. This string is required. | | `privateBuild` | `string` | `undefined` | Information about a private version of the file—for example, Built by TESTER1 on \\TESTBED. | From 07248875f6f036fa661cf2931ba252049f62b10c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:38:26 +0530 Subject: [PATCH 14/47] chore(docs): clarify options.app.fileVersion default values --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2395ff5..d4ab4b84 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ This object defines additional properties used for building for a specific platf | `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. | | `company` | `string` | Value of `author` in app's `package.json` | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. | | `fileDescription` | `string` | Value of `description` in app's `package.json` | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. | -| `fileVersion` | `string` | Value of `version` option or value of `version` in app's `package.json` | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. | +| `fileVersion` | `string` | Value of `version` or value of `version` in NW.js manifest | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. | | `internalName` | `string` | Value of `name` in app's `package.json` |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. | | `legalCopyright` | `string` | `undefined` | Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional. | | `legalTrademark` | `string` | `undefined` | Trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. This string is optional. | From 92d8dab164ae8368046a0c7685ca20a7b0843070 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:42:43 +0530 Subject: [PATCH 15/47] chore(docs): clarify terminology regarding package.json --- README.md | 14 +++++++------- tests/fixtures/demo.win.js | 9 +++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4ab4b84..04490da1 100644 --- a/README.md +++ b/README.md @@ -229,19 +229,19 @@ This object defines additional properties used for building for a specific platf | Name | Type | Default | Description | | ---- | ------- | --------- | ----------- | | `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. | -| `name` | `string` | Value of `name` in app's `package.json` | The name of the application | -| `version` | `string` | Value of `version` in app's `package.json` | The version of the application | +| `name` | `string` | Value of `name` in NW.js manifest | The name of the application | +| `version` | `string` | Value of `version` in NW.js manifest | The version of the application | | `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. | -| `company` | `string` | Value of `author` in app's `package.json` | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. | -| `fileDescription` | `string` | Value of `description` in app's `package.json` | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. | +| `company` | `string` | Value of `author` in NW.js manifest | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. | +| `fileDescription` | `string` | Value of `description` in NW.js manifest | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. | | `fileVersion` | `string` | Value of `version` or value of `version` in NW.js manifest | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. | -| `internalName` | `string` | Value of `name` in app's `package.json` |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. | +| `internalName` | `string` | Value of `name` in NW.js manifest |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. | | `legalCopyright` | `string` | `undefined` | Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional. | | `legalTrademark` | `string` | `undefined` | Trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. This string is optional. | | `originalFilename` | `string` | Value of `name` option | Original name of the file, not including a path. This information enables an application to determine whether a file has been renamed by a user. The format of the name depends on the file system for which the file was created. This string is required. | | `privateBuild` | `string` | `undefined` | Information about a private version of the file—for example, Built by TESTER1 on \\TESTBED. | -| `productName` | `string` | Matches the package name defined in app's `package.json` | Name of the product with which the file is distributed. This string is required. | -| `productVersion` | `string` | Value of `version` in app's `package.json` | Version of the product with which the file is distributed—for example, 3.10 or 5.00.RC2. | +| `productName` | `string` | `name` in NW.js manifest | Name of the product with which the file is distributed. This string is required. | +| `productVersion` | `string` | Value of `version` in NW.js manifest | Version of the product with which the file is distributed—for example, 3.10 or 5.00.RC2. | | `specialBuild` | `string` | `undefined` | Text that specifies how this version of the file differs from the standard version—for example, Private build for TESTER1 solving mouse problems on M250 and M250E computers. | | `languageCode` | `number` | `1033` | Language of the file, defined by Microsoft, see: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a | diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index 7454ec90..b16eb446 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -12,5 +12,14 @@ await nwbuild({ name: 'Demo', /* Relative to where the manifest will be located */ icon: './icon.ico', + version: '0.0.0', + comments: 'Diagnostic information', + company: 'NW.js Utilities', + fileDescription: 'This is a demo app to test nw-builder functionality', + fileVersion: '0.0.0', + internalName: 'Demo', + legalCopyright: '2024 (c) NW.js Utilties. All Rights Reserved', + originalFilename: 'Demo', + } }); From 2c774d8f8019cfaca1e3b66dc096a52eaa69bbb9 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:44:00 +0530 Subject: [PATCH 16/47] chore(test): configure initial Windows build --- tests/fixtures/demo.win.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index b16eb446..e2b69ad8 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -20,6 +20,7 @@ await nwbuild({ internalName: 'Demo', legalCopyright: '2024 (c) NW.js Utilties. All Rights Reserved', originalFilename: 'Demo', - + productName: 'Demo', + productVersion: '0.0.0', } }); From 8bfbcea07ad3fe56b3babc863cba8fcde67d2a63 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:50:58 +0530 Subject: [PATCH 17/47] chore: create CLI command to build and execute Windows NW.js demo app --- package.json | 6 ++++-- tests/fixtures/demo.osx.js | 2 +- tests/fixtures/demo.win.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2aba8140..8ef4a8f2 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,10 @@ "lint:fix": "eslint --fix ./src ./tests", "test": "vitest run --coverage", "test:cov": "vitest --coverage.enabled true", - "demo:bld": "node ./tests/fixtures/demo.osx.js", - "demo:exe": "./tests/fixtures/out/Demo.app/Contents/MacOS/Demo", + "demo:bld:osx": "node ./tests/fixtures/demo.osx.js", + "demo:bld:win": "node ./tests/fixtures/demo.osx.js", + "demo:exe:osx": "./tests/fixtures/out/osx/Demo.app/Contents/MacOS/Demo", + "demo:exe:win": "./tests/fixtures/out/win/Demo.exe", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" }, "devDependencies": { diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index e65a270e..5a6e73fa 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -6,7 +6,7 @@ await nwbuild({ platform: 'osx', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', - outDir: './tests/fixtures/out', + outDir: './tests/fixtures/out/osx', glob: false, logLevel: 'debug', app: { diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index e2b69ad8..4194c976 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -6,7 +6,7 @@ await nwbuild({ platform: 'win', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', - outDir: './tests/fixtures/out', + outDir: './tests/fixtures/out/win', glob: false, app: { name: 'Demo', From 9aaa5d76d96a2696b1b2f7e7fc36173eb1c65d6c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:57:18 +0530 Subject: [PATCH 18/47] chore: create CLI command to build and execute Windows NW.js demo app --- package.json | 2 +- tests/fixtures/demo.win.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ef4a8f2..605422b8 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "test": "vitest run --coverage", "test:cov": "vitest --coverage.enabled true", "demo:bld:osx": "node ./tests/fixtures/demo.osx.js", - "demo:bld:win": "node ./tests/fixtures/demo.osx.js", + "demo:bld:win": "node ./tests/fixtures/demo.win.js", "demo:exe:osx": "./tests/fixtures/out/osx/Demo.app/Contents/MacOS/Demo", "demo:exe:win": "./tests/fixtures/out/win/Demo.exe", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index 4194c976..828ac880 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -8,6 +8,7 @@ await nwbuild({ cacheDir: './node_modules/nw', outDir: './tests/fixtures/out/win', glob: false, + logLevel: 'debug', app: { name: 'Demo', /* Relative to where the manifest will be located */ From 3652910edb22e8d9c126ad08e8373735f7b02395 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:21:10 +0530 Subject: [PATCH 19/47] fix(test): point to valid icon path --- tests/fixtures/demo.win.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index 828ac880..e7c833c1 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -12,7 +12,7 @@ await nwbuild({ app: { name: 'Demo', /* Relative to where the manifest will be located */ - icon: './icon.ico', + icon: './tests/fixtures/app/icon.ico', version: '0.0.0', comments: 'Diagnostic information', company: 'NW.js Utilities', From 60470f4e369ce5e861bb3b04b93c1047b6650844 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:22:26 +0530 Subject: [PATCH 20/47] chore(get): correct spelling in code comments --- src/get/request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/get/request.js b/src/get/request.js index 0e077363..d8fede5b 100644 --- a/src/get/request.js +++ b/src/get/request.js @@ -16,9 +16,9 @@ export default async function request(url, filePath) { const writeStream = fs.createWriteStream(filePath); - // Listen for SIGINT (Ctrl+C) + /* Listen for SIGINT (Ctrl+C) */ process.on('SIGINT', function () { - /* Delete file if it exists. This prevents unecessary `Centrol Directory not found` errors. */ + /* Delete file if it exists. This prevents unnecessary `Central Directory not found` errors. */ if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); } From c0e1fed676cbdeb22a822e319f0d1feb9cdcd8d4 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:47:58 +0530 Subject: [PATCH 21/47] chore(bld): improve readability --- src/bld.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bld.js b/src/bld.js index 73cf071e..ce156700 100644 --- a/src/bld.js +++ b/src/bld.js @@ -319,10 +319,11 @@ const setWinConfig = async ({ app, outDir }) => { if (app.icon) { const iconBuffer = await fs.promises.readFile(path.resolve(app.icon)); const iconFile = resedit.Data.IconFile.from(iconBuffer); + const iconGroupIDs = resedit.Resource.IconGroupEntry.fromEntries(res.entries).map((entry) => entry.id); resedit.Resource.IconGroupEntry.replaceIconsForResource( res.entries, - // This is the name of the icon group nw.js uses that gets shown in file exlorers - 'IDR_MAINFRAME', + /* Should be `IDR_MAINFRAME` */ + iconGroupIDs[0], EN_US, iconFile.icons.map(i => i.data) ); From ba081f5cbe5931fd4c86624410f0e284dae41189 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:48:22 +0530 Subject: [PATCH 22/47] chore(test): update title from NW.js Demo to Demo since it shows in Taskbarc --- tests/fixtures/app/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/app/index.html b/tests/fixtures/app/index.html index d5b84f9f..cdc892c0 100644 --- a/tests/fixtures/app/index.html +++ b/tests/fixtures/app/index.html @@ -2,7 +2,7 @@ - NW.js Demo + Demo From 8124ad5e9438b7597f9972bad3c3fa1f080ba527 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:42:55 +0530 Subject: [PATCH 23/47] chore: add some logs so user knows status of process --- src/index.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 8b429407..29e7431f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import console from 'node:console'; import fs from 'node:fs'; +import path from 'node:path'; import bld from './bld.js'; import get from './get/index.js'; @@ -45,7 +46,7 @@ async function nwbuild(options) { }; try { - // Parse options + /* Parse options */ options = await util.parse(options, manifest); util.log('debug', 'info', 'Parse initial options'); @@ -55,10 +56,9 @@ async function nwbuild(options) { options = manifest.json.nwbuild; } - util.log('info', options.logLevel, 'Parse final options'); + util.log('info', options.logLevel, 'Parse final options using node manifest'); options = await util.parse(options, manifest.json); - util.log('debug', options.logLevel, 'Manifest path: ', manifest.path); - util.log('debug', options.logLevel, 'Manifest file:\n', manifest.json); + util.log('debug', options.logLevel, 'Manifest: ', `${manifest.path}\n${manifest.json}\n`); built = fs.existsSync(options.cacheDir); if (built === false) { @@ -72,7 +72,8 @@ async function nwbuild(options) { } } - // Validate options.version to get the version specific release info + /* Validate options.version to get the version specific release info */ + util.log('info', options.logLevel, 'Get version specific release info...'); releaseInfo = await util.getReleaseInfo( options.version, options.platform, @@ -80,13 +81,16 @@ async function nwbuild(options) { options.cacheDir, options.manifestUrl, ); + util.log('debug', options.logLevel, `Release info:\n${JSON.stringify(releaseInfo, null, 2)}\n`); + util.log('info', options.logLevel, 'Validate options.* ...'); await util.validate(options, releaseInfo); + util.log('debug', options.logLevel, `Options:\n${JSON.stringify(options, null, 2)}`); - // Remove leading "v" from version string + /* Remove leading "v" from version string */ options.version = releaseInfo.version.slice(1); - // Download binaries + util.log('info', options.logLevel, 'Getting NW.js and related binaries...'); await get({ version: options.version, flavor: options.flavor, @@ -105,6 +109,7 @@ async function nwbuild(options) { } if (options.mode === 'run') { + util.log('info', options.logLevel, 'Running NW.js in run mode...'); await run({ version: options.version, flavor: options.flavor, @@ -116,6 +121,7 @@ async function nwbuild(options) { argv: options.argv, }); } else if (options.mode === 'build') { + util.log('info', options.logLevel, `Build a NW.js application for ${options.platform} ${options.arch}...`); await bld({ version: options.version, flavor: options.flavor, @@ -132,6 +138,7 @@ async function nwbuild(options) { zip: options.zip, releaseInfo: releaseInfo, }); + util.log('info', options.logLevel, `Appliction is available at ${path.resolve(options.outDir)}`); } } catch (error) { console.error(error); From 1bee7292b359e7a4b7295b164b7060267801a6be Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:56:05 +0530 Subject: [PATCH 24/47] chore(test): update options.app.legalCopyright --- tests/fixtures/demo.win.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index e7c833c1..995357cd 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -11,7 +11,7 @@ await nwbuild({ logLevel: 'debug', app: { name: 'Demo', - /* Relative to where the manifest will be located */ + /* File path of icon from where it is copied. */ icon: './tests/fixtures/app/icon.ico', version: '0.0.0', comments: 'Diagnostic information', @@ -19,7 +19,7 @@ await nwbuild({ fileDescription: 'This is a demo app to test nw-builder functionality', fileVersion: '0.0.0', internalName: 'Demo', - legalCopyright: '2024 (c) NW.js Utilties. All Rights Reserved', + legalCopyright: 'Copyright (c) 2024 NW.js Utilities', originalFilename: 'Demo', productName: 'Demo', productVersion: '0.0.0', From 1963641f57805b53146a26e1534044d834740970 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:56:48 +0530 Subject: [PATCH 25/47] chore(test): add options.app.NSLocalNetworkUsageDescription to MacOS demo --- tests/fixtures/demo.osx.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index 5a6e73fa..dce458cb 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -11,7 +11,8 @@ await nwbuild({ logLevel: 'debug', app: { name: 'Demo', - // MacOS options + /* File path of icon from where it is copied. */ + icon: './tests/fixtures/app/icon.icns', LSApplicationCategoryType: 'public.app-category.utilities', CFBundleIdentifier: 'io.nwutils.demo', CFBundleName: 'Demo', @@ -19,6 +20,7 @@ await nwbuild({ CFBundleSpokenName: 'Demo', CFBundleVersion: '0.0.0', CFBundleShortVersionString: '0.0.0', - NSHumanReadableCopyright: 'Copyright (c) 2024 NW.js Utilities' + NSHumanReadableCopyright: 'Copyright (c) 2024 NW.js Utilities', + NSLocalNetworkUsageDescription: 'Demo requires access to network to showcase its capabilities', } }); From 506e4f2700591ed8b4e522cb91904e2e086e35da Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:06:36 +0530 Subject: [PATCH 26/47] fix(util): parse options.app.exec path correctly --- src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index f998a11c..c620fbac 100644 --- a/src/util.js +++ b/src/util.js @@ -243,7 +243,7 @@ export const parse = async (options, pkg) => { options.app.notShowIn = options.app.notShowIn ?? undefined; options.app.dBusActivatable = options.app.dBusActivatable ?? undefined; options.app.tryExec = options.app.tryExec ?? undefined; - options.app.exec = options.app.name ?? undefined; + options.app.exec = path.resolve(options.app.exec) ?? undefined; options.app.path = options.app.path ?? undefined; options.app.terminal = options.app.terminal ?? undefined; options.app.actions = options.app.actions ?? undefined; From 243256f73b2f7bed02417d9febd79c698fd1150d Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:13:37 +0530 Subject: [PATCH 27/47] chore(test): create linux fixture --- tests/fixtures/demo.linux.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/fixtures/demo.linux.js diff --git a/tests/fixtures/demo.linux.js b/tests/fixtures/demo.linux.js new file mode 100644 index 00000000..f2489674 --- /dev/null +++ b/tests/fixtures/demo.linux.js @@ -0,0 +1,28 @@ +import nwbuild from '../../src/index.js'; + +await nwbuild({ + mode: 'build', + flavor: 'sdk', + platform: 'linux', + srcDir: './tests/fixtures/app', + cacheDir: './node_modules/nw', + outDir: './tests/fixtures/out/linux', + glob: false, + logLevel: 'debug', + app: { + name: 'Demo', + genericName: 'Demo', + noDisplay: false, + comment: 'Tooltip information', + /* File path of icon from where it is copied. */ + icon: './tests/fixtures/app/icon.png', + hidden: false, + // TODO: test in different Linux desktop environments + // onlyShowIn: [], + // notShowIn: [], + dBusActivatable: true, + // TODO: test in Linux environment + // tryExec: '/path/to/exe?' + exec: './tests/fixtures/out/linux/Demo', + } +}); From 75ae2a69c437e934bf45460860e6bc4b501c84e2 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:15:15 +0530 Subject: [PATCH 28/47] chore(test): switch demo configs to normal build flavor --- tests/fixtures/demo.linux.js | 2 +- tests/fixtures/demo.osx.js | 2 +- tests/fixtures/demo.win.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/demo.linux.js b/tests/fixtures/demo.linux.js index f2489674..21e55561 100644 --- a/tests/fixtures/demo.linux.js +++ b/tests/fixtures/demo.linux.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'sdk', + flavor: 'normal', platform: 'linux', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index dce458cb..e5dd783a 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'sdk', + flavor: 'normal', platform: 'osx', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index 995357cd..b6a99fbb 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'sdk', + flavor: 'normal', platform: 'win', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', From a2bd73d57c19da0f32227df5320352206f5c65e4 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:16:52 +0530 Subject: [PATCH 29/47] chore(test): add command to build and execute demo linux app --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 605422b8..a15558a0 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,10 @@ "lint:fix": "eslint --fix ./src ./tests", "test": "vitest run --coverage", "test:cov": "vitest --coverage.enabled true", + "demo:bld:linux": "node ./tests/fixtures/demo.linux.js", "demo:bld:osx": "node ./tests/fixtures/demo.osx.js", "demo:bld:win": "node ./tests/fixtures/demo.win.js", + "demo:exe:linux": "node ./tests/fixtures/linux/Demo", "demo:exe:osx": "./tests/fixtures/out/osx/Demo.app/Contents/MacOS/Demo", "demo:exe:win": "./tests/fixtures/out/win/Demo.exe", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" From 8b388eca5e9de12cb0fe3ebd3fb1ace6b6586fa9 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:19:47 +0530 Subject: [PATCH 30/47] chore(test): switch demo config to sdk build flavor --- tests/fixtures/demo.linux.js | 2 +- tests/fixtures/demo.osx.js | 2 +- tests/fixtures/demo.win.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/demo.linux.js b/tests/fixtures/demo.linux.js index 21e55561..f2489674 100644 --- a/tests/fixtures/demo.linux.js +++ b/tests/fixtures/demo.linux.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'normal', + flavor: 'sdk', platform: 'linux', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index e5dd783a..dce458cb 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'normal', + flavor: 'sdk', platform: 'osx', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index b6a99fbb..995357cd 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -2,7 +2,7 @@ import nwbuild from '../../src/index.js'; await nwbuild({ mode: 'build', - flavor: 'normal', + flavor: 'sdk', platform: 'win', srcDir: './tests/fixtures/app', cacheDir: './node_modules/nw', From 88f610453a2a4aa1740937456bacbce66a7904d3 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:23:17 +0530 Subject: [PATCH 31/47] chore(test): update demo app name in manifest --- tests/fixtures/app/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/app/package.json b/tests/fixtures/app/package.json index 9e018ac2..bb167b13 100644 --- a/tests/fixtures/app/package.json +++ b/tests/fixtures/app/package.json @@ -1,6 +1,6 @@ { - "name": "nwapp", + "name": "Demo", "main": "index.html", "version": "0.0.0", - "product_string": "nwapp" + "product_string": "Demo" } From e6881b8c512e165217a75023b83e679af29dd925 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:25:20 +0530 Subject: [PATCH 32/47] fix(util): resolve path for icon --- src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index c620fbac..9d67f544 100644 --- a/src/util.js +++ b/src/util.js @@ -230,7 +230,7 @@ export const parse = async (options, pkg) => { /* Remove special and control characters from app.name to mitigate potential path traversal. */ options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, ''); } - options.app.icon = options.app.icon ?? undefined; + options.app.icon = path.resolve(options.app.icon) ?? undefined; // TODO(#737): move this out if (options.platform === 'linux') { From 9a212fa55e48fb30d0da4eeb463139a74cee51ed Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:29:40 +0530 Subject: [PATCH 33/47] fix(bld): correct options.app.exec assignment --- src/bld.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld.js b/src/bld.js index ce156700..9c3fc603 100644 --- a/src/bld.js +++ b/src/bld.js @@ -262,7 +262,7 @@ const setLinuxConfig = async ({ app, outDir }) => { NotShowIn: app.notShowIn, DBusActivatable: app.dBusActivatable, TryExec: app.tryExec, - Exec: app.name, + Exec: app.exec, Path: app.path, Terminal: app.terminal, Actions: app.actions, From 53f8b61cfac60045290e56e2254f2b0dcf9c46da Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:33:09 +0530 Subject: [PATCH 34/47] fix(util): point to icon in built app --- src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index 9d67f544..7e66be21 100644 --- a/src/util.js +++ b/src/util.js @@ -230,7 +230,7 @@ export const parse = async (options, pkg) => { /* Remove special and control characters from app.name to mitigate potential path traversal. */ options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, ''); } - options.app.icon = path.resolve(options.app.icon) ?? undefined; + options.app.icon = path.resolve(options.outDir, path.basename(options.app.icon)) ?? undefined; // TODO(#737): move this out if (options.platform === 'linux') { From 5c380b8214f4d89f1730f9092cbb4f8ab97d6de4 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:36:38 +0530 Subject: [PATCH 35/47] fix(bld): update icon for linux post parsing --- src/bld.js | 2 +- src/util.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bld.js b/src/bld.js index 9c3fc603..9434a1f8 100644 --- a/src/bld.js +++ b/src/bld.js @@ -256,7 +256,7 @@ const setLinuxConfig = async ({ app, outDir }) => { GenericName: app.genericName, NoDisplay: app.noDisplay, Comment: app.comment, - Icon: app.icon, + Icon: path.resolve(options.outDir, 'package.nw', path.basename(options.app.icon)), Hidden: app.hidden, OnlyShowIn: app.onlyShowIn, NotShowIn: app.notShowIn, diff --git a/src/util.js b/src/util.js index 7e66be21..c387ca2f 100644 --- a/src/util.js +++ b/src/util.js @@ -230,7 +230,7 @@ export const parse = async (options, pkg) => { /* Remove special and control characters from app.name to mitigate potential path traversal. */ options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, ''); } - options.app.icon = path.resolve(options.outDir, path.basename(options.app.icon)) ?? undefined; + options.app.icon = path.basename(options.app.icon) ?? undefined; // TODO(#737): move this out if (options.platform === 'linux') { From fd1f41a407c192d39149b4e1db0e9a88dd108c83 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:38:01 +0530 Subject: [PATCH 36/47] fix(bld): update icon for linux post parsing --- src/bld.js | 2 +- src/util.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bld.js b/src/bld.js index 9434a1f8..b7215523 100644 --- a/src/bld.js +++ b/src/bld.js @@ -256,7 +256,7 @@ const setLinuxConfig = async ({ app, outDir }) => { GenericName: app.genericName, NoDisplay: app.noDisplay, Comment: app.comment, - Icon: path.resolve(options.outDir, 'package.nw', path.basename(options.app.icon)), + Icon: path.resolve(outDir, 'package.nw', path.basename(app.icon)), Hidden: app.hidden, OnlyShowIn: app.onlyShowIn, NotShowIn: app.notShowIn, diff --git a/src/util.js b/src/util.js index c387ca2f..4bfd74f4 100644 --- a/src/util.js +++ b/src/util.js @@ -230,6 +230,7 @@ export const parse = async (options, pkg) => { /* Remove special and control characters from app.name to mitigate potential path traversal. */ options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, ''); } + /* Path to where the icon currently is in the filesystem */ options.app.icon = path.basename(options.app.icon) ?? undefined; // TODO(#737): move this out From 6a73cc6ad711dcae5f460c1b986147e694df4ff2 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:38:24 +0530 Subject: [PATCH 37/47] fix(bld): update icon for linux post parsing --- src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index 4bfd74f4..ae2a1207 100644 --- a/src/util.js +++ b/src/util.js @@ -231,7 +231,7 @@ export const parse = async (options, pkg) => { options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, ''); } /* Path to where the icon currently is in the filesystem */ - options.app.icon = path.basename(options.app.icon) ?? undefined; + options.app.icon = path.resolve(options.app.icon) ?? undefined; // TODO(#737): move this out if (options.platform === 'linux') { From 4ba840d9dee17e8246921088372c310e1734818b Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:46:57 +0530 Subject: [PATCH 38/47] chore(docs): add note on how to build and execute demo applications --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 04490da1..e8aae7c9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ Every NW.js release includes a modified Node.js binary at a specific version. It ## Usage +> Using this package might feel overwhelming due to the abundence of options. There are demo applications built for Linux, MacOS and Windows which can be found in `/tests/fixtures/app`. You can build a Linux application by cloning this repo and running `npm run demo:bld:linux && npm run demo:exe:linux`. Commands for the other operating systems can be found inside `scripts` prefixed with `demo:*` in the `package.json`. + 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. If options are defined in Node manifest, then they will be used over options defined in CLI or JavaScript API. CLI interface: From 769220531da02b2f166add54c94110c8e20ea53a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:49:14 +0530 Subject: [PATCH 39/47] chore(test): reference icon from manifest --- tests/fixtures/app/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/app/package.json b/tests/fixtures/app/package.json index bb167b13..3790da7e 100644 --- a/tests/fixtures/app/package.json +++ b/tests/fixtures/app/package.json @@ -2,5 +2,8 @@ "name": "Demo", "main": "index.html", "version": "0.0.0", - "product_string": "Demo" + "product_string": "Demo", + "window": { + "icon": "./icon.png" + } } From 41993fea3152462b4e84d1485e444e0fa54e687c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:51:04 +0530 Subject: [PATCH 40/47] chore(test): add comment about icon file path --- tests/fixtures/app/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fixtures/app/package.json b/tests/fixtures/app/package.json index 3790da7e..13e8432c 100644 --- a/tests/fixtures/app/package.json +++ b/tests/fixtures/app/package.json @@ -4,6 +4,7 @@ "version": "0.0.0", "product_string": "Demo", "window": { + // This icon file path should be relative to the manifest file path "icon": "./icon.png" } } From f15ec3ad6f8d4f85ae80596bda7912131f5a5258 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:52:19 +0530 Subject: [PATCH 41/47] chore(test): remove comment about icon file path --- tests/fixtures/app/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fixtures/app/package.json b/tests/fixtures/app/package.json index 13e8432c..3790da7e 100644 --- a/tests/fixtures/app/package.json +++ b/tests/fixtures/app/package.json @@ -4,7 +4,6 @@ "version": "0.0.0", "product_string": "Demo", "window": { - // This icon file path should be relative to the manifest file path "icon": "./icon.png" } } From 29ca824417230e80184e93b8f17e4dc7839fcb63 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:53:37 +0530 Subject: [PATCH 42/47] chore(test): add comment for how to execute built demo app --- tests/fixtures/demo.linux.js | 2 ++ tests/fixtures/demo.osx.js | 2 ++ tests/fixtures/demo.win.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/fixtures/demo.linux.js b/tests/fixtures/demo.linux.js index f2489674..b581d101 100644 --- a/tests/fixtures/demo.linux.js +++ b/tests/fixtures/demo.linux.js @@ -26,3 +26,5 @@ await nwbuild({ exec: './tests/fixtures/out/linux/Demo', } }); + +console.log('Execute npm run demo:exe:linux to run the application.'); diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index dce458cb..36f4ac15 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -24,3 +24,5 @@ await nwbuild({ NSLocalNetworkUsageDescription: 'Demo requires access to network to showcase its capabilities', } }); + +console.log('Execute npm run demo:exe:osx to run the application.'); diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index 995357cd..e89911e9 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -25,3 +25,5 @@ await nwbuild({ productVersion: '0.0.0', } }); + +console.log('Execute npm run demo:exe:win to run the application.'); From c26c17591fbcd41435861cd41ecd5f7116bd8cfc Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:54:43 +0530 Subject: [PATCH 43/47] chore(test): update comment for how to execute built demo app --- tests/fixtures/demo.linux.js | 2 +- tests/fixtures/demo.osx.js | 2 +- tests/fixtures/demo.win.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/demo.linux.js b/tests/fixtures/demo.linux.js index b581d101..5a2d2e09 100644 --- a/tests/fixtures/demo.linux.js +++ b/tests/fixtures/demo.linux.js @@ -27,4 +27,4 @@ await nwbuild({ } }); -console.log('Execute npm run demo:exe:linux to run the application.'); +console.log('\nExecute `npm run demo:exe:linux` to run the application.'); diff --git a/tests/fixtures/demo.osx.js b/tests/fixtures/demo.osx.js index 36f4ac15..5d9f0440 100644 --- a/tests/fixtures/demo.osx.js +++ b/tests/fixtures/demo.osx.js @@ -25,4 +25,4 @@ await nwbuild({ } }); -console.log('Execute npm run demo:exe:osx to run the application.'); +console.log('\nExecute `npm run demo:exe:osx` to run the application.'); diff --git a/tests/fixtures/demo.win.js b/tests/fixtures/demo.win.js index e89911e9..d7ca6c37 100644 --- a/tests/fixtures/demo.win.js +++ b/tests/fixtures/demo.win.js @@ -26,4 +26,4 @@ await nwbuild({ } }); -console.log('Execute npm run demo:exe:win to run the application.'); +console.log('\nExecute `npm run demo:exe:win` to run the application.'); From 6401d30abcc95866ae91ab1912120c327f895bd2 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:57:06 +0530 Subject: [PATCH 44/47] chore(test): fix outDir path --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a15558a0..271f5bb5 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "demo:bld:linux": "node ./tests/fixtures/demo.linux.js", "demo:bld:osx": "node ./tests/fixtures/demo.osx.js", "demo:bld:win": "node ./tests/fixtures/demo.win.js", - "demo:exe:linux": "node ./tests/fixtures/linux/Demo", + "demo:exe:linux": "node ./tests/fixtures/out/linux/Demo", "demo:exe:osx": "./tests/fixtures/out/osx/Demo.app/Contents/MacOS/Demo", "demo:exe:win": "./tests/fixtures/out/win/Demo.exe", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" From 1978370fb36cbb7a9d1ea686b82563e6371036cf Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 08:59:36 +0530 Subject: [PATCH 45/47] chore(test): remove node prefix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 271f5bb5..d6329142 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "demo:bld:linux": "node ./tests/fixtures/demo.linux.js", "demo:bld:osx": "node ./tests/fixtures/demo.osx.js", "demo:bld:win": "node ./tests/fixtures/demo.win.js", - "demo:exe:linux": "node ./tests/fixtures/out/linux/Demo", + "demo:exe:linux": "./tests/fixtures/out/linux/Demo", "demo:exe:osx": "./tests/fixtures/out/osx/Demo.app/Contents/MacOS/Demo", "demo:exe:win": "./tests/fixtures/out/win/Demo.exe", "demo:cli": "nwbuild --mode=run --flavor=sdk --glob=false --cacheDir=./node_modules/nw ./tests/fixtures/app" From 5a441610dccc94b5ad41ecf4f802d1d42fe2782c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 09:01:57 +0530 Subject: [PATCH 46/47] chore(docs): mention a gotcha regarding icon --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8aae7c9..61cdee18 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ This object defines additional properties used for building for a specific platf | Name | Type | Default | Description | | ---- | ------- | --------- | ----------- | -| `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. | +| `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. (Please define the icon in the NW.js manifest instead) | | `name` | `string` | Value of `name` in NW.js manifest | The name of the application | | `version` | `string` | Value of `version` in NW.js manifest | The version of the application | | `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. | @@ -255,7 +255,7 @@ This object defines additional properties used for building for a specific platf | genericName | `string` | Generic name of the application | | noDisplay | `boolean` | If true the application is not displayed | | comment | `string` | Tooltip for the entry, for example "View sites on the Internet". | -| icon | `string` | Icon to display in file manager, menus, etc. | +| icon | `string` | Icon to display in file manager, menus, etc. (Please define the icon in the NW.js manifest instead) | | hidden | `boolean` | TBD | | onlyShowIn | `string[]` | A list of strings identifying the desktop environments that should display a given desktop entry | | notShowIn | `string[]` | A list of strings identifying the desktop environments that should not display a given desktop entry | @@ -279,7 +279,7 @@ This object defines additional properties used for building for a specific platf | Name | Type | Description | | ---- | ------- | ----------- | | name | `string` | The name of the application | -| icon | `string` | The path to the icon file. It should be a .icns file. | +| icon | `string` | The path to the icon file. It should be a .icns file. (Please define the icon in the NW.js manifest instead) | | LSApplicationCategoryType | `string` | The category that best describes your app for the App Store. | | CFBundleIdentifier | `string` | A unique identifier for a bundle usually in reverse DNS format. | | CFBundleName | `string` | A user-visible short name for the bundle. | From 582591d0a356ecf673b02e12b9d8cdb4a820a0fa Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Nov 2024 09:03:57 +0530 Subject: [PATCH 47/47] chore(docs): mention a gotcha regarding icon --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 61cdee18..9ca34076 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ This object defines additional properties used for building for a specific platf | Name | Type | Default | Description | | ---- | ------- | --------- | ----------- | -| `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. (Please define the icon in the NW.js manifest instead) | +| `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. (**WARNING**: Please define the icon in the NW.js manifest instead) | | `name` | `string` | Value of `name` in NW.js manifest | The name of the application | | `version` | `string` | Value of `version` in NW.js manifest | The version of the application | | `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. | @@ -255,7 +255,7 @@ This object defines additional properties used for building for a specific platf | genericName | `string` | Generic name of the application | | noDisplay | `boolean` | If true the application is not displayed | | comment | `string` | Tooltip for the entry, for example "View sites on the Internet". | -| icon | `string` | Icon to display in file manager, menus, etc. (Please define the icon in the NW.js manifest instead) | +| icon | `string` | Icon to display in file manager, menus, etc. (**WARNING**: Please define the icon in the NW.js manifest instead) | | hidden | `boolean` | TBD | | onlyShowIn | `string[]` | A list of strings identifying the desktop environments that should display a given desktop entry | | notShowIn | `string[]` | A list of strings identifying the desktop environments that should not display a given desktop entry | @@ -279,7 +279,7 @@ This object defines additional properties used for building for a specific platf | Name | Type | Description | | ---- | ------- | ----------- | | name | `string` | The name of the application | -| icon | `string` | The path to the icon file. It should be a .icns file. (Please define the icon in the NW.js manifest instead) | +| icon | `string` | The path to the icon file. It should be a .icns file. (**WARNING**: Please define the icon in the NW.js manifest instead) | | LSApplicationCategoryType | `string` | The category that best describes your app for the App Store. | | CFBundleIdentifier | `string` | A unique identifier for a bundle usually in reverse DNS format. | | CFBundleName | `string` | A user-visible short name for the bundle. |