From b37068f9228c1f00877d51c5fe607be7096b6564 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:34:49 +0530 Subject: [PATCH] chore(get): improve error message when comparing shasums (#1213) * Apply eslint rules to codebase Refs: #1209 --- eslint.config.js | 36 +- package-lock.json | 635 +++------------------------------ package.json | 12 +- src/bld.js | 121 +++---- src/bld/osx.js | 221 ++++++------ src/cli.js | 160 ++++----- src/get/decompress.js | 23 +- src/get/ffmpeg.js | 8 +- src/get/index.js | 79 ++-- src/get/node.js | 12 +- src/get/nw.js | 14 +- src/get/request.js | 14 +- src/get/verify.js | 5 +- src/index.js | 26 +- src/run.js | 35 +- src/util.js | 182 +++++----- tests/fixtures/demo.js | 12 +- tests/specs/decompress.test.js | 34 +- tests/specs/ffmpeg.test.js | 20 +- tests/specs/node.test.js | 18 +- tests/specs/nw.test.js | 22 +- tests/specs/osx.test.js | 190 +++++----- tests/specs/request.test.js | 14 +- tests/specs/run.test.js | 50 +-- tests/specs/verify.test.js | 14 +- 25 files changed, 680 insertions(+), 1277 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 7e8e64b2d..b097bc203 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,21 +1,21 @@ +import js from "@eslint/js"; +import jsdoc from 'eslint-plugin-jsdoc'; +import globals from "globals"; -import stylistic from "@stylistic/eslint-plugin-js"; -import jsdoc from "eslint-plugin-jsdoc"; -import markdownPlugin from "eslint-plugin-markdown"; - -export default { - languageOptions: { - parserOptions: { - ecmaVersion: "latest", - sourceType: "module" - }, - }, - plugins: { - "@stylistic/js": stylistic.configs["all-flat"], - "plugin:markdown/recommended": markdownPlugin.configs.recommended, - "jsdoc": jsdoc.configs.recommended, +export default [ + { + languageOptions: + { + globals: globals.node + } }, - rules: { - "jsdoc/require-file-overview": "off" + js.configs.recommended, + jsdoc.configs['flat/recommended'], + { + rules: { + "semi": ["error", "always"], + "quotes": ["error", "single"], + } } -} + +]; diff --git a/package-lock.json b/package-lock.json index 476c335b6..baf308909 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,14 +25,12 @@ "nwbuild": "src/cli.js" }, "devDependencies": { - "@stylistic/eslint-plugin-js": "^2.6.4", + "@eslint/js": "^9.9.1", "@vitest/coverage-v8": "^2.0.5", "base-volta-off-of-nwjs": "^1.0.5", - "eslint": "^9.9.0", - "eslint-config-tjw-jsdoc": "^1.0.5", + "eslint": "^9.9.1", "eslint-plugin-jsdoc": "^50.2.2", - "eslint-plugin-markdown": "^5.0.0", - "jsdoc": "^4.0.3", + "globals": "^15.9.0", "nw": "^0.91.0", "selenium-webdriver": "^4.23.0", "vitest": "^2.0.4" @@ -161,6 +159,7 @@ "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.48.0.tgz", "integrity": "sha512-G6QUWIcC+KvSwXNsJyDTHvqUdNoAVJPPgkc3+Uk4WBKqZvoXhlvazOgm9aL0HwihJLQf0l+tOE2UFzXBqCqgDw==", "dev": true, + "license": "MIT", "dependencies": { "comment-parser": "1.4.1", "esquery": "^1.6.0", @@ -170,15 +169,6 @@ "node": ">=16" } }, - "node_modules/@es-joy/jsdoccomment/node_modules/jsdoc-type-pratt-parser": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.1.0.tgz", - "integrity": "sha512-Hicd6JK5Njt2QB6XYFS7ok9e37O8AYk3jTcppG4YVQnYjOemymvTcmc7OWsmq/Qqj5TdRFO5/x/tIPmBeRtGHg==", - "dev": true, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -587,10 +577,11 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.17.1", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.1.tgz", - "integrity": "sha512-BlYOpej8AQ8Ev9xVqroV7a02JK3SkBAaN9GfMMH9W6Ch8FlQlkjGw4Ir7+FgYwfirivAf4t+GtzuAxqfukmISA==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", + "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^2.1.4", "debug": "^4.3.1", @@ -624,11 +615,25 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { - "version": "9.9.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.0.tgz", - "integrity": "sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug==", + "version": "9.9.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", + "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", "dev": true, + "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -638,6 +643,7 @@ "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", "dev": true, + "license": "Apache-2.0", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -806,19 +812,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jsdoc/salty": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.8.tgz", - "integrity": "sha512-5e+SFVavj1ORKlKaKr2BmTOekmXbelU7dC0cDkQLqag7xfuTPuGMUFx7KWJuv4bYZrTsoL2Z18VVCOKYxzoHcg==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "lodash": "^4.17.21" - }, - "engines": { - "node": ">=v12.0.0" - } - }, "node_modules/@napi-rs/wasm-runtime": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.4.tgz", @@ -1405,24 +1398,6 @@ "win32" ] }, - "node_modules/@stylistic/eslint-plugin-js": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-js/-/eslint-plugin-js-2.6.4.tgz", - "integrity": "sha512-kx1hS3xTvzxZLdr/DCU/dLBE++vcP97sHeEFX2QXhk1Ipa4K1rzPOLw1HCbf4mU3s+7kHP5eYpDe+QteEOFLug==", - "dev": true, - "dependencies": { - "@types/eslint": "^9.6.0", - "acorn": "^8.12.1", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "peerDependencies": { - "eslint": ">=8.40.0" - } - }, "node_modules/@tybys/wasm-util": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.9.0.tgz", @@ -1433,16 +1408,6 @@ "tslib": "^2.4.0" } }, - "node_modules/@types/eslint": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.0.tgz", - "integrity": "sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==", - "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -1450,47 +1415,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/json-schema": { - "version": "7.0.15", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", - "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", - "dev": true - }, - "node_modules/@types/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/markdown-it": { - "version": "14.1.1", - "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.1.tgz", - "integrity": "sha512-4NpsnpYl2Gt1ljyBGrKMxFYAYvpqbnnkgP/i/g+NLpjEUa3obn1XJCur9YbEXKDAkaXqsR1LbDnGEJ0MmKFxfg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/linkify-it": "^5", - "@types/mdurl": "^2" - } - }, - "node_modules/@types/mdast": { - "version": "3.0.15", - "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.15.tgz", - "integrity": "sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^2" - } - }, - "node_modules/@types/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/node": { "version": "20.14.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", @@ -1503,13 +1427,6 @@ "undici-types": "~5.26.4" } }, - "node_modules/@types/unist": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", - "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==", - "dev": true, - "license": "MIT" - }, "node_modules/@vitest/coverage-v8": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-2.0.5.tgz", @@ -2040,13 +1957,6 @@ ], "license": "MIT" }, - "node_modules/bluebird": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true, - "license": "MIT" - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2082,19 +1992,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/builtin-modules": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", - "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -2278,19 +2175,6 @@ "node": ">=6" } }, - "node_modules/catharsis": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.9.0.tgz", - "integrity": "sha512-prMTQVpcns/tzFgFVkVp6ak6RykZyWb3gu8ckUpd6YkTlacOd3DXGJjIpD4Q6zJirizvaiAjSSHlOsA+6sNh2A==", - "dev": true, - "license": "MIT", - "dependencies": { - "lodash": "^4.17.15" - }, - "engines": { - "node": ">= 10" - } - }, "node_modules/chai": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/chai/-/chai-5.1.1.tgz", @@ -2324,39 +2208,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/character-entities": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/character-entities/-/character-entities-1.2.4.tgz", - "integrity": "sha512-iBMyeEHxfVnIakwOuDXpVkc54HijNgCyQB2w0VfGQThle6NXn50zU6V/u+LDhxHcDUPojn6Kpga3PTAD8W1bQw==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/character-entities-legacy": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz", - "integrity": "sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/character-reference-invalid": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz", - "integrity": "sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/check-error": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", @@ -2732,19 +2583,6 @@ "node": ">=0.10.0" } }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "dev": true, - "license": "BSD-2-Clause", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, "node_modules/env-paths": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", @@ -2849,16 +2687,17 @@ } }, "node_modules/eslint": { - "version": "9.9.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.0.tgz", - "integrity": "sha512-JfiKJrbx0506OEerjK2Y1QlldtBxkAlLxT5OEcRF8uaQ86noDe2k31Vw9rnSWv+MXZHj7OOUV/dA0AhdLFcyvA==", + "version": "9.9.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", + "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", - "@eslint/config-array": "^0.17.1", + "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.9.0", + "@eslint/js": "9.9.1", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -2907,60 +2746,12 @@ } } }, - "node_modules/eslint-config-tjw-jsdoc": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/eslint-config-tjw-jsdoc/-/eslint-config-tjw-jsdoc-1.0.5.tgz", - "integrity": "sha512-xCXNrV3+5DHNTKJX6DFBPdwzwLFKK4q+7WBVPrAtAm4BXx6wH2CdbMMLxs+y3W6+H+nO9YhhAtMQ0dXvhTsLVA==", - "dev": true, - "license": "MIT", - "dependencies": { - "eslint-plugin-jsdoc": "^46.8.1" - } - }, - "node_modules/eslint-config-tjw-jsdoc/node_modules/@es-joy/jsdoccomment": { - "version": "0.41.0", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.41.0.tgz", - "integrity": "sha512-aKUhyn1QI5Ksbqcr3fFJj16p99QdjUxXAEuFst1Z47DRyoiMwivIH9MV/ARcJOCXVjPfjITciej8ZD2O/6qUmw==", - "dev": true, - "license": "MIT", - "dependencies": { - "comment-parser": "1.4.1", - "esquery": "^1.5.0", - "jsdoc-type-pratt-parser": "~4.0.0" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/eslint-config-tjw-jsdoc/node_modules/eslint-plugin-jsdoc": { - "version": "46.10.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-46.10.1.tgz", - "integrity": "sha512-x8wxIpv00Y50NyweDUpa+58ffgSAI5sqe+zcZh33xphD0AVh+1kqr1ombaTRb7Fhpove1zfUuujlX9DWWBP5ag==", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@es-joy/jsdoccomment": "~0.41.0", - "are-docs-informative": "^0.0.2", - "comment-parser": "1.4.1", - "debug": "^4.3.4", - "escape-string-regexp": "^4.0.0", - "esquery": "^1.5.0", - "is-builtin-module": "^3.2.1", - "semver": "^7.5.4", - "spdx-expression-parse": "^4.0.0" - }, - "engines": { - "node": ">=16" - }, - "peerDependencies": { - "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" - } - }, "node_modules/eslint-plugin-jsdoc": { "version": "50.2.2", "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.2.2.tgz", "integrity": "sha512-i0ZMWA199DG7sjxlzXn5AeYZxpRfMJjDPUl7lL9eJJX8TPRoIaxJU4ys/joP5faM5AXE1eqW/dslCj3uj4Nqpg==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@es-joy/jsdoccomment": "~0.48.0", "are-docs-informative": "^0.0.2", @@ -2981,22 +2772,6 @@ "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" } }, - "node_modules/eslint-plugin-markdown": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-markdown/-/eslint-plugin-markdown-5.1.0.tgz", - "integrity": "sha512-SJeyKko1K6GwI0AN6xeCDToXDkfKZfXcexA6B+O2Wr2btUS9GrC+YgwSyVli5DJnctUHjFXcQ2cqTaAmVoLi2A==", - "dev": true, - "license": "MIT", - "dependencies": { - "mdast-util-from-markdown": "^0.8.5" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "peerDependencies": { - "eslint": ">=8" - } - }, "node_modules/eslint-scope": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", @@ -3442,9 +3217,9 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "15.9.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", + "integrity": "sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA==", "dev": true, "license": "MIT", "engines": { @@ -3615,9 +3390,9 @@ "license": "BSD-3-Clause" }, "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, "license": "MIT", "engines": { @@ -3685,59 +3460,6 @@ "node": ">= 12" } }, - "node_modules/is-alphabetical": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-1.0.4.tgz", - "integrity": "sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/is-alphanumerical": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-1.0.4.tgz", - "integrity": "sha512-UzoZUr+XfVz3t3v4KyGEniVL9BDRoQtY7tOyrRybkVNjDFWyo1yhXNGrrBTQxp3ib9BLAWs7k2YKBQsFRkZG9A==", - "dev": true, - "license": "MIT", - "dependencies": { - "is-alphabetical": "^1.0.0", - "is-decimal": "^1.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/is-builtin-module": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", - "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", - "dev": true, - "license": "MIT", - "dependencies": { - "builtin-modules": "^3.3.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-decimal": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-1.0.4.tgz", - "integrity": "sha512-RGdriMmQQvZ2aqaQq3awNA6dCGtKpiDFcOzrTWrDAT2MiWrKQVPmxLGHl7Y2nNu6led0kEyoX0enY0qXYsv9zw==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3770,17 +3492,6 @@ "node": ">=0.10.0" } }, - "node_modules/is-hexadecimal": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz", - "integrity": "sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/is-it-type": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/is-it-type/-/is-it-type-5.1.2.tgz", @@ -3912,85 +3623,22 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/js2xmlparser": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.2.tgz", - "integrity": "sha512-6n4D8gLlLf1n5mNLQPRfViYzu9RATblzPEtm1SthMX1Pjao0r9YI9nw7ZIfRxQMERS87mcswrg+r/OYrPRX6jA==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "xmlcreate": "^2.0.4" - } - }, "node_modules/jsbn": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", "license": "MIT" }, - "node_modules/jsdoc": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.3.tgz", - "integrity": "sha512-Nu7Sf35kXJ1MWDZIMAuATRQTg1iIPdzh7tqJ6jjvaU/GfDf+qi5UV8zJR3Mo+/pYFvm8mzay4+6O5EWigaQBQw==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@babel/parser": "^7.20.15", - "@jsdoc/salty": "^0.2.1", - "@types/markdown-it": "^14.1.1", - "bluebird": "^3.7.2", - "catharsis": "^0.9.0", - "escape-string-regexp": "^2.0.0", - "js2xmlparser": "^4.0.2", - "klaw": "^3.0.0", - "markdown-it": "^14.1.0", - "markdown-it-anchor": "^8.6.7", - "marked": "^4.0.10", - "mkdirp": "^1.0.4", - "requizzle": "^0.2.3", - "strip-json-comments": "^3.1.0", - "underscore": "~1.13.2" - }, - "bin": { - "jsdoc": "jsdoc.js" - }, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/jsdoc-type-pratt-parser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz", - "integrity": "sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.1.0.tgz", + "integrity": "sha512-Hicd6JK5Njt2QB6XYFS7ok9e37O8AYk3jTcppG4YVQnYjOemymvTcmc7OWsmq/Qqj5TdRFO5/x/tIPmBeRtGHg==", "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" } }, - "node_modules/jsdoc/node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/jsdoc/node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true, - "license": "MIT", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -4035,16 +3683,6 @@ "json-buffer": "3.0.1" } }, - "node_modules/klaw": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", - "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", - "dev": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.1.9" - } - }, "node_modules/lazystream": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz", @@ -4081,16 +3719,6 @@ "immediate": "~3.0.5" } }, - "node_modules/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "uc.micro": "^2.0.0" - } - }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -4196,84 +3824,6 @@ "node": "^16.14.0 || >=18.0.0" } }, - "node_modules/markdown-it": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", - "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", - "dev": true, - "license": "MIT", - "dependencies": { - "argparse": "^2.0.1", - "entities": "^4.4.0", - "linkify-it": "^5.0.0", - "mdurl": "^2.0.0", - "punycode.js": "^2.3.1", - "uc.micro": "^2.1.0" - }, - "bin": { - "markdown-it": "bin/markdown-it.mjs" - } - }, - "node_modules/markdown-it-anchor": { - "version": "8.6.7", - "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.7.tgz", - "integrity": "sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==", - "dev": true, - "license": "Unlicense", - "peerDependencies": { - "@types/markdown-it": "*", - "markdown-it": "*" - } - }, - "node_modules/marked": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", - "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", - "dev": true, - "license": "MIT", - "bin": { - "marked": "bin/marked.js" - }, - "engines": { - "node": ">= 12" - } - }, - "node_modules/mdast-util-from-markdown": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-0.8.5.tgz", - "integrity": "sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/mdast": "^3.0.0", - "mdast-util-to-string": "^2.0.0", - "micromark": "~2.11.0", - "parse-entities": "^2.0.0", - "unist-util-stringify-position": "^2.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/mdast-util-to-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-2.0.0.tgz", - "integrity": "sha512-AW4DRS3QbBayY/jJmD8437V1Gombjf8RSOUCMFBuo5iHi58AGEgVCKQ+ezHkZZDpAQS75hcBMpLqjpJTjtUL7w==", - "dev": true, - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", - "dev": true, - "license": "MIT" - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4281,27 +3831,6 @@ "dev": true, "license": "MIT" }, - "node_modules/micromark": { - "version": "2.11.4", - "resolved": "https://registry.npmjs.org/micromark/-/micromark-2.11.4.tgz", - "integrity": "sha512-+WoovN/ppKolQOFIAajxi7Lu9kInbPxFuTBVEavFcL8eAfVstoc5MocPmqBeAdBOJV00uaVjegzH4+MA0DN/uA==", - "dev": true, - "funding": [ - { - "type": "GitHub Sponsors", - "url": "https://github.com/sponsors/unifiedjs" - }, - { - "type": "OpenCollective", - "url": "https://opencollective.com/unified" - } - ], - "license": "MIT", - "dependencies": { - "debug": "^4.0.0", - "parse-entities": "^2.0.0" - } - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -4907,25 +4436,6 @@ "node": ">=6" } }, - "node_modules/parse-entities": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz", - "integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "character-entities": "^1.0.0", - "character-entities-legacy": "^1.0.0", - "character-reference-invalid": "^1.0.0", - "is-alphanumerical": "^1.0.0", - "is-decimal": "^1.0.0", - "is-hexadecimal": "^1.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/parse-imports": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/parse-imports/-/parse-imports-2.1.1.tgz", @@ -5123,16 +4633,6 @@ "node": ">=6" } }, - "node_modules/punycode.js": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", - "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -5226,16 +4726,6 @@ "node": ">=0.10.0" } }, - "node_modules/requizzle": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.4.tgz", - "integrity": "sha512-JRrFk1D4OQ4SqovXOgdav+K8EAhSB/LJZqCz8tbX0KObcdeM15Ss59ozWMBWmmINMagCwmqn4ZNryUGpBsl6Jw==", - "dev": true, - "license": "MIT", - "dependencies": { - "lodash": "^4.17.21" - } - }, "node_modules/resedit": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/resedit/-/resedit-2.0.2.tgz", @@ -5533,9 +5023,9 @@ } }, "node_modules/spdx-license-ids": { - "version": "3.0.18", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.18.tgz", - "integrity": "sha512-xxRs31BqRYHwiMzudOrpSiHtZ8i/GeionCBDSilhYRj+9gIcI8wCZTlXZKu9vZIVqViP3dcp9qE5G6AlIaD+TQ==", + "version": "3.0.20", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.20.tgz", + "integrity": "sha512-jg25NiDV/1fLtSgEgyvVyDunvaNHbuwF9lfNV17gSmPFAlYzdfNBlLtLzXTevwkPj7DhGbmN9VnmJIgLnhvaBw==", "dev": true, "license": "CC0-1.0" }, @@ -6012,20 +5502,6 @@ "node": ">= 0.8.0" } }, - "node_modules/uc.micro": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", - "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", - "dev": true, - "license": "MIT" - }, - "node_modules/underscore": { - "version": "1.13.6", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz", - "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", - "dev": true, - "license": "MIT" - }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", @@ -6059,20 +5535,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/unist-util-stringify-position": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz", - "integrity": "sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/unist": "^2.0.2" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -6393,13 +5855,6 @@ "node": ">=8.0" } }, - "node_modules/xmlcreate": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz", - "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==", - "dev": true, - "license": "Apache-2.0" - }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index b406462bb..862134823 100644 --- a/package.json +++ b/package.json @@ -42,22 +42,20 @@ }, "scripts": { "postinstall": "node ./src/postinstall.js", - "lint": "eslint ./src/**/*.js ./tests/**/*.js", - "lint:fix": "eslint --fix ./src/**/*.js ./tests/**/*.js", + "lint": "eslint ./src ./tests", + "lint:fix": "eslint --fix ./src ./tests", "test": "vitest run --coverage", "test:cov": "vitest --coverage.enabled true", "demo:bld": "node ./tests/fixtures/demo.js", "demo:exe": "./tests/fixtures/out/nwapp.app/Contents/MacOS/nwapp" }, "devDependencies": { - "@stylistic/eslint-plugin-js": "^2.6.4", + "@eslint/js": "^9.9.1", "@vitest/coverage-v8": "^2.0.5", "base-volta-off-of-nwjs": "^1.0.5", - "eslint": "^9.9.0", - "eslint-config-tjw-jsdoc": "^1.0.5", + "eslint": "^9.9.1", "eslint-plugin-jsdoc": "^50.2.2", - "eslint-plugin-markdown": "^5.0.0", - "jsdoc": "^4.0.3", + "globals": "^15.9.0", "nw": "^0.91.0", "selenium-webdriver": "^4.23.0", "vitest": "^2.0.4" diff --git a/src/bld.js b/src/bld.js index f357c9e9d..073ec84c5 100644 --- a/src/bld.js +++ b/src/bld.js @@ -1,22 +1,21 @@ -import child_process from "node:child_process"; -import console from "node:console"; -import fs from "node:fs"; -import path from "node:path"; -import process from "node:process"; - -import archiver from "archiver"; -import * as resedit from "resedit"; +import child_process from 'node:child_process'; +import console from 'node:console'; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; + +import archiver from 'archiver'; +import * as resedit from 'resedit'; // pe-library is a direct dependency of resedit import * as peLibrary from 'pe-library'; import * as tar from 'tar'; -import util from "./util.js"; -import setOsxConfig from "./bld/osx.js"; +import util from './util.js'; +import setOsxConfig from './bld/osx.js'; /** * References: * https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html - * * @typedef {object} LinuxRc Linux configuration options * @property {string} name Name of the application * @property {string} genericName Generic name of the application @@ -45,7 +44,6 @@ import setOsxConfig from "./bld/osx.js"; /** * References: * https://developer.apple.com/documentation/bundleresources/information_property_list - * * @typedef {object} OsxRc OSX resource configuration options * @property {string} name The name of the application * @property {string} icon The path to the icon file. It should be a .icns file. @@ -65,7 +63,6 @@ import setOsxConfig from "./bld/osx.js"; * 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-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 @@ -105,21 +102,19 @@ import setOsxConfig from "./bld/osx.js"; /** * Build NW.js application. - * * @async * @function * @param {BuildOptions} options - Build options - * @return {Promise} + * @returns {Promise} */ async function bld({ - version = "latest", - flavor = "normal", + version = 'latest', + flavor = 'normal', platform = util.PLATFORM_KV[process.platform], arch = util.ARCH_KV[process.arch], - manifestUrl = "https://nwjs.io/versions", - srcDir = "./src", - cacheDir = "./cache", - outDir = "./out", + srcDir = './src', + cacheDir = './cache', + outDir = './out', app, glob = true, managedManifest = false, @@ -129,7 +124,7 @@ async function bld({ }) { const nwDir = path.resolve( cacheDir, - `nwjs${flavor === "sdk" ? "-sdk" : ""}-v${version}-${platform + `nwjs${flavor === 'sdk' ? '-sdk' : ''}-v${version}-${platform }-${arch}`, ); @@ -145,9 +140,9 @@ async function bld({ file, path.resolve( outDir, - platform !== "osx" - ? "package.nw" - : "nwjs.app/Contents/Resources/app.nw", + platform !== 'osx' + ? 'package.nw' + : 'nwjs.app/Contents/Resources/app.nw', file, ), { recursive: true, verbatimSymlinks: true }, @@ -158,9 +153,9 @@ async function bld({ files, path.resolve( outDir, - platform !== "osx" - ? "package.nw" - : "nwjs.app/Contents/Resources/app.nw", + platform !== 'osx' + ? 'package.nw' + : 'nwjs.app/Contents/Resources/app.nw', ), { recursive: true, verbatimSymlinks: true }, ); @@ -170,21 +165,21 @@ async function bld({ if ( managedManifest === true || - typeof managedManifest === "object" || - typeof managedManifest === "string" + typeof managedManifest === 'object' || + typeof managedManifest === 'string' ) { await manageManifest({ nwPkg: manifest, managedManifest, outDir, platform }); } - if (platform === "linux") { + if (platform === 'linux') { await setLinuxConfig({ app, outDir }); - } else if (platform === "win") { + } else if (platform === 'win') { await setWinConfig({ app, outDir }); - } else if (platform === "osx") { + } else if (platform === 'osx') { await setOsxConfig({ app, outDir, releaseInfo }); } - if (nativeAddon === "gyp") { + if (nativeAddon === 'gyp') { buildNativeAddon({ cacheDir, version, platform, arch, outDir, nodeVersion }); } @@ -200,56 +195,56 @@ const manageManifest = async ({ nwPkg, managedManifest, outDir, platform }) => { manifest = nwPkg; } - if (typeof managedManifest === "object") { + if (typeof managedManifest === 'object') { manifest = managedManifest; } - if (typeof managedManifest === "string") { + if (typeof managedManifest === 'string') { manifest = JSON.parse(await fs.promises.readFile(managedManifest)); } if (manifest.devDependencies) { manifest.devDependencies = undefined; } - manifest.packageManager = manifest.packageManager ?? "npm@*"; + manifest.packageManager = manifest.packageManager ?? 'npm@*'; await fs.promises.writeFile( path.resolve( outDir, - platform !== "osx" - ? "package.nw" - : "nwjs.app/Contents/Resources/app.nw", - "package.json", + platform !== 'osx' + ? 'package.nw' + : 'nwjs.app/Contents/Resources/app.nw', + 'package.json', ), JSON.stringify(manifest, null, 2), - "utf8", + 'utf8', ); const cwd = path.resolve( outDir, - platform !== "osx" - ? "package.nw" - : "nwjs.app/Contents/Resources/app.nw", + platform !== 'osx' + ? 'package.nw' + : 'nwjs.app/Contents/Resources/app.nw', ); - if (manifest.packageManager.startsWith("npm")) { - child_process.execSync(`npm install`, { cwd }); - } else if (manifest.packageManager.startsWith("yarn")) { - child_process.execSync(`yarn install`, { cwd }); - } else if (manifest.packageManager.startsWith("pnpm")) { - child_process.execSync(`pnpm install`, { cwd }); + if (manifest.packageManager.startsWith('npm')) { + child_process.execSync('npm install', { cwd }); + } else if (manifest.packageManager.startsWith('yarn')) { + child_process.execSync('yarn install', { cwd }); + } else if (manifest.packageManager.startsWith('pnpm')) { + child_process.execSync('pnpm install', { cwd }); } }; const setLinuxConfig = async ({ app, outDir }) => { - if (process.platform === "win32") { + if (process.platform === 'win32') { console.warn( - "Linux apps built on Windows platform do not preserve all file permissions. See #716", + 'Linux apps built on Windows platform do not preserve all file permissions. See #716', ); } let desktopEntryFile = { - Type: "Application", - Version: "1.5", + Type: 'Application', + Version: '1.5', Name: app.name, GenericName: app.genericName, NoDisplay: app.noDisplay, @@ -276,7 +271,7 @@ const setLinuxConfig = async ({ app, outDir }) => { await fs.promises.rename(`${outDir}/nw`, `${outDir}/${app.name}`); - let fileContent = `[Desktop Entry]\n`; + let fileContent = '[Desktop Entry]\n'; Object.keys(desktopEntryFile).forEach((key) => { if (desktopEntryFile[key] !== undefined) { fileContent += `${key}=${desktopEntryFile[key]}\n`; @@ -309,7 +304,7 @@ const setWinConfig = async ({ app, outDir }) => { }); const outDirAppExe = path.resolve(outDir, `${app.name}.exe`); - await fs.promises.rename(path.resolve(outDir, "nw.exe"), outDirAppExe); + await fs.promises.rename(path.resolve(outDir, 'nw.exe'), outDirAppExe); const exe = peLibrary.NtExecutable.from(await fs.promises.readFile(outDirAppExe)); const res = peLibrary.NtExecutableResource.from(exe); // English (United States) @@ -350,9 +345,9 @@ const buildNativeAddon = ({ cacheDir, version, platform, arch, outDir, nodeVersi let nodePath = path.resolve(cacheDir, `node-v${version}-${platform}-${arch}`); const cwd = path.resolve( outDir, - platform !== "osx" - ? "package.nw" - : "nwjs.app/Contents/Resources/app.nw", + platform !== 'osx' + ? 'package.nw' + : 'nwjs.app/Contents/Resources/app.nw', ); child_process.execSync(`node-gyp rebuild --target=${nodeVersion} --nodedir=${nodePath}`, { cwd }); @@ -362,18 +357,18 @@ const compress = async ({ zip, outDir, }) => { - if (zip === true || zip === "zip") { + if (zip === true || zip === 'zip') { const archive = archiver('zip'); const writeStream = fs.createWriteStream(`${outDir}.zip`); archive.pipe(writeStream); archive.directory(outDir, false); archive.finalize(); - } else if (zip === "tar") { + } else if (zip === 'tar') { await tar.create({ gzip: false, file: `${outDir}.tar`, }, [outDir]); - } else if (zip === "tgz") { + } else if (zip === 'tgz') { await tar.create({ gzip: true, file: `${outDir}.tgz`, diff --git a/src/bld/osx.js b/src/bld/osx.js index 48c4ead16..dd128811e 100644 --- a/src/bld/osx.js +++ b/src/bld/osx.js @@ -5,10 +5,18 @@ import process from 'node:process'; import plist from 'plist'; +/** + * + * @param {object} options - Options. + * @param {object} options.app - Application configuration. + * @param {string} options.outDir - Output directory. + * @param {string} options.releaseInfo - Release information. + * @returns {Promise} - Promise. + */ export default async function setOsxConfig({ app, outDir, releaseInfo }) { - if (process.platform === "win32") { + if (process.platform === 'win32') { console.warn( - "MacOS apps built on Windows platform do not preserve all file permissions. See #716", + 'MacOS apps built on Windows platform do not preserve all file permissions. See #716', ); } @@ -18,124 +26,122 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) { */ const chromiumVersion = releaseInfo?.components?.chromium; if (!chromiumVersion) { - throw new Error("Chromium version is missing."); + throw new Error('Chromium version is missing.'); } /** * Path to MacOS application. - * * @type {string} */ const nwjsApp = path.resolve(outDir, 'nwjs.app'); /** * Path to renamed MacOS application. - * * @type {string} */ const outApp = path.resolve(outDir, `${app.name}.app`); const nwjsHelperAlertsAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwjs Helper (Alerts).app`, + 'Helpers', + 'nwjs Helper (Alerts).app', ); const HelperAlertsAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", + 'Helpers', `${app.name} Helper (Alerts).app`, ); const nwjsHelperGpuAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwjs Helper (GPU).app`, + 'Helpers', + 'nwjs Helper (GPU).app', ); const HelperGpuAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", + 'Helpers', `${app.name} Helper (GPU).app`, ); const nwjsHelperPluginAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwjs Helper (Plugin).app`, + 'Helpers', + 'nwjs Helper (Plugin).app', ); const HelperPluginAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", + 'Helpers', `${app.name} Helper (Plugin).app`, ); const nwjsHelperRendererAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwjs Helper (Renderer).app`, + 'Helpers', + 'nwjs Helper (Renderer).app', ); const HelperRendererAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", + 'Helpers', `${app.name} Helper (Renderer).app`, ); const nwjsHelperAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwjs Helper.app`, + 'Helpers', + 'nwjs Helper.app', ); const HelperAppPath = path.resolve( outApp, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", + 'Helpers', `${app.name} Helper.app`, ); @@ -144,8 +150,8 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) { /* Rename `Contents/MacOS/nwjs` to `Contents/MacOS/${app.name}` */ await fs.promises.rename( - path.resolve(outApp, "Contents", "MacOS", "nwjs"), - path.resolve(outApp, "Contents", "MacOS", app.name), + path.resolve(outApp, 'Contents', 'MacOS', 'nwjs'), + path.resolve(outApp, 'Contents', 'MacOS', app.name), ); /* Rename Helper (Alert) */ @@ -180,155 +186,147 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) { /* Rename `nwjs Helper (Alerts)/Contents/MacOS/nwjs Helper (Alerts)` to `${app.name} Helper (Alerts)/Contents/MacOS/${app.name} Helper (Alerts)` */ await fs.promises.rename( - path.resolve(HelperAlertsAppPath, "Contents", "MacOS", "nwjs Helper (Alerts)"), - path.resolve(HelperAlertsAppPath, "Contents", "MacOS", `${app.name} Helper (Alerts)`), + path.resolve(HelperAlertsAppPath, 'Contents', 'MacOS', 'nwjs Helper (Alerts)'), + path.resolve(HelperAlertsAppPath, 'Contents', 'MacOS', `${app.name} Helper (Alerts)`), ); /* Rename `${app.name} Helper (GPU)/Contents/MacOS/nwjs Helper (GPU)` to `${app.name} Helper (GPU)/Contents/MacOS/${app.name} Helper (GPU)` */ await fs.promises.rename( - path.resolve(HelperGpuAppPath, "Contents", "MacOS", "nwjs Helper (GPU)"), - path.resolve(HelperGpuAppPath, "Contents", "MacOS", `${app.name} Helper (GPU)`), + path.resolve(HelperGpuAppPath, 'Contents', 'MacOS', 'nwjs Helper (GPU)'), + path.resolve(HelperGpuAppPath, 'Contents', 'MacOS', `${app.name} Helper (GPU)`), ); /* Rename `${app.name} Helper (Plugin)/Contents/MacOS/nwjs Helper (Plugin)` to `${app.name} Helper (Plugin)/Contents/MacOS/${app.name} Helper (Plugin)` */ await fs.promises.rename( - path.resolve(HelperPluginAppPath, "Contents", "MacOS", "nwjs Helper (Plugin)"), - path.resolve(HelperPluginAppPath, "Contents", "MacOS", `${app.name} Helper (Plugin)`), + path.resolve(HelperPluginAppPath, 'Contents', 'MacOS', 'nwjs Helper (Plugin)'), + path.resolve(HelperPluginAppPath, 'Contents', 'MacOS', `${app.name} Helper (Plugin)`), ); /* Rename `${app.name} Helper (Renderer)/Contents/MacOS/nwjs Helper (Renderer)` to `${app.name} Helper (Renderer)/Contents/MacOS/${app.name} Helper (Renderer)` */ await fs.promises.rename( - path.resolve(HelperRendererAppPath, "Contents", "MacOS", "nwjs Helper (Renderer)"), - path.resolve(HelperRendererAppPath, "Contents", "MacOS", `${app.name} Helper (Renderer)`), + path.resolve(HelperRendererAppPath, 'Contents', 'MacOS', 'nwjs Helper (Renderer)'), + path.resolve(HelperRendererAppPath, 'Contents', 'MacOS', `${app.name} Helper (Renderer)`), ); /* Rename `${app.name} Helper/Contents/MacOS/nwjs Helper` to `${app.name} Helper/Contents/MacOS/${app.name} Helper` */ await fs.promises.rename( - path.resolve(HelperAppPath, "Contents", "MacOS", "nwjs Helper"), - path.resolve(HelperAppPath, "Contents", "MacOS", `${app.name} Helper`), + path.resolve(HelperAppPath, 'Contents', 'MacOS', 'nwjs Helper'), + path.resolve(HelperAppPath, 'Contents', 'MacOS', `${app.name} Helper`), ); /* Replace default icon with user defined icon if specified. */ if (app.icon !== undefined) { await fs.promises.copyFile( path.resolve(app.icon), - path.resolve(outApp, "Contents", "Resources", "app.icns"), + path.resolve(outApp, 'Contents', 'Resources', 'app.icns'), ); } /** * Path to `nwjs.app/Contents/Info.plist` - * * @type {string} */ const ContentsInfoPlistPath = path.resolve( outApp, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ); /** * Path to `nwjs.app/Contents/Resources/en.lproj/InfoPlist.settings` - * * @type {string} */ const ContentsResourcesEnLprojInfoPlistStringsPath = path.resolve( outApp, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", + 'Contents', + 'Resources', + 'en.lproj', + 'InfoPlist.strings', ); /** * JSON from `nwjs.app/Contents/Info.plist` - * * @type {object} */ const ContentsInfoPlistJson = plist.parse( await fs.promises.readFile( ContentsInfoPlistPath, - "utf-8" + 'utf-8' ) ); /** * JSON from `${app.name} Helper.app (Alerts)/Contents/Info.plist` - * * @type {object} */ const HelperAlertsAppJson = plist.parse( await fs.promises.readFile( path.resolve( HelperAlertsAppPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); /** * JSON from `${app.name} Helper (GPU).app/Contents/Info.plist` - * * @type {object} */ const HelperGpuAppJson = plist.parse( await fs.promises.readFile( path.resolve( HelperGpuAppPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); /** * JSON from `${app.name} Helper (Plugin).app/Contents/Info.plist` - * * @type {object} */ const HelperPluginAppJson = plist.parse( await fs.promises.readFile( path.resolve( HelperPluginAppPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); /** * JSON from `${app.name} Helper (Renderer).app/Contents/Info.plist` - * * @type {object} */ const HelperRendererAppJson = plist.parse( await fs.promises.readFile( path.resolve( HelperRendererAppPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); /** * JSON from `${app.name} Helper.app/Contents/Info.plist` - * * @type {object} */ const HelperAppJson = plist.parse( await fs.promises.readFile( path.resolve( HelperAppPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); @@ -381,15 +379,14 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) { /** * Data from `nwjs.app/Contents/Resources/en.lproj/InfoPlist.settings` - * * @type {string[]} */ const ContentsResourcesEnLprojInfoPlistStringsArray = (await fs.promises.readFile( ContentsResourcesEnLprojInfoPlistStringsPath, - "utf-8", + 'utf-8', )).split('\n'); ContentsResourcesEnLprojInfoPlistStringsArray.forEach((line, idx, arr) => { - if (line.includes("NSHumanReadableCopyright")) { + if (line.includes('NSHumanReadableCopyright')) { arr[idx] = `NSHumanReadableCopyright = "${app.NSHumanReadableCopyright}";`; } @@ -401,26 +398,26 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) { plist.build(ContentsInfoPlistJson)); await fs.promises.writeFile( ContentsResourcesEnLprojInfoPlistStringsPath, - ContentsResourcesEnLprojInfoPlistStringsArray.toString().replace(/,/g, "\n"), + ContentsResourcesEnLprojInfoPlistStringsArray.toString().replace(/,/g, '\n'), ); await fs.promises.writeFile( - path.resolve(HelperAlertsAppPath, "Contents", "Info.plist"), + path.resolve(HelperAlertsAppPath, 'Contents', 'Info.plist'), plist.build(HelperAlertsAppJson) ); await fs.promises.writeFile( - path.resolve(HelperGpuAppPath, "Contents", "Info.plist"), + path.resolve(HelperGpuAppPath, 'Contents', 'Info.plist'), plist.build(HelperGpuAppJson) ); await fs.promises.writeFile( - path.resolve(HelperPluginAppPath, "Contents", "Info.plist"), + path.resolve(HelperPluginAppPath, 'Contents', 'Info.plist'), plist.build(HelperPluginAppJson) ); await fs.promises.writeFile( - path.resolve(HelperRendererAppPath, "Contents", "Info.plist"), + path.resolve(HelperRendererAppPath, 'Contents', 'Info.plist'), plist.build(HelperRendererAppJson) ); await fs.promises.writeFile( - path.resolve(HelperAppPath, "Contents", "Info.plist"), + path.resolve(HelperAppPath, 'Contents', 'Info.plist'), plist.build(HelperAppJson) ); } catch (error) { diff --git a/src/cli.js b/src/cli.js index b39726017..b0dd33da0 100755 --- a/src/cli.js +++ b/src/cli.js @@ -1,95 +1,95 @@ #!/usr/bin/env node -import process from "node:process"; +import process from 'node:process'; -import yargs from "yargs/yargs"; -import * as yargs_helpers from "yargs/helpers"; +import yargs from 'yargs/yargs'; +import * as yargs_helpers from 'yargs/helpers'; -import nwbuild from "./index.js"; +import nwbuild from './index.js'; const cli = yargs(yargs_helpers.hideBin(process.argv)) .version(false) - .command("[srcDir] [options]") - .option("mode", { - type: "string", - description: "`get`, `run` or `build` application", - choices: ["get", "run", "build"] - }) - .option("version", { - type: "string", - description: "NW.js version", - }) - .option("flavor", { - type: "string", - description: "NW.js build flavor", - choices: ["normal", "sdk"] - }) - .option("platform", { - type: "string", - description: "NW.js supported platform", - choices: ["linux", "osx", "win"] - }) - .option("arch", { - type: "string", - description: "NW.js supported architecture", - choices: ["ia32", "x64", "arm64"] - }) - .option("downloadUrl", { - type: "string", - description: "NW.js download server", - }) - .option("manifestUrl", { - type: "string", - description: "NW.js version info", - }) - .option("cacheDir", { - type: "string", - description: "Cache NW.js binaries", - }) - .option("outDir", { - type: "string", - description: "NW.js build artifacts", - }) - .option("app", { - type: "object", - description: "Platform specific app metadata. Refer to docs for more info", - }) - .option("cache", { - type: "boolean", - description: "Flag to enable/disable caching", - }) - .option("ffmpeg", { - type: "boolean", - description: "Flag to enable/disable downloading community ffmpeg", - }) - .option("glob", { - type: "boolean", - description: "Flag to enable/disable globbing", - }) - .option("logLevel", { - type: "string", - description: "Specify log level", - choices: ["error", "warn", "info", "debug"] - }) - .option("zip", { - type: "string", - description: "Flag to enable/disable compression", - choices: ["zip", "tar", "tgz"] - }) - .option("managedManifest", { - type: "string", - description: "Managed manifest mode", - }) - .option("nodeAddon", { - type: "string", - description: "Download NW.js Node headers", - choices: [false, "gyp"] + .command('[srcDir] [options]') + .option('mode', { + type: 'string', + description: '`get`, `run` or `build` application', + choices: ['get', 'run', 'build'] + }) + .option('version', { + type: 'string', + description: 'NW.js version', + }) + .option('flavor', { + type: 'string', + description: 'NW.js build flavor', + choices: ['normal', 'sdk'] + }) + .option('platform', { + type: 'string', + description: 'NW.js supported platform', + choices: ['linux', 'osx', 'win'] + }) + .option('arch', { + type: 'string', + description: 'NW.js supported architecture', + choices: ['ia32', 'x64', 'arm64'] + }) + .option('downloadUrl', { + type: 'string', + description: 'NW.js download server', + }) + .option('manifestUrl', { + type: 'string', + description: 'NW.js version info', + }) + .option('cacheDir', { + type: 'string', + description: 'Cache NW.js binaries', + }) + .option('outDir', { + type: 'string', + description: 'NW.js build artifacts', + }) + .option('app', { + type: 'object', + description: 'Platform specific app metadata. Refer to docs for more info', + }) + .option('cache', { + type: 'boolean', + description: 'Flag to enable/disable caching', + }) + .option('ffmpeg', { + type: 'boolean', + description: 'Flag to enable/disable downloading community ffmpeg', + }) + .option('glob', { + type: 'boolean', + description: 'Flag to enable/disable globbing', + }) + .option('logLevel', { + type: 'string', + description: 'Specify log level', + choices: ['error', 'warn', 'info', 'debug'] + }) + .option('zip', { + type: 'string', + description: 'Flag to enable/disable compression', + choices: ['zip', 'tar', 'tgz'] + }) + .option('managedManifest', { + type: 'string', + description: 'Managed manifest mode', + }) + .option('nodeAddon', { + type: 'string', + description: 'Download NW.js Node headers', + choices: [false, 'gyp'] }) .strictOptions() .parse(); nwbuild({ ...cli, - srcDir: cli._.join(" "), + srcDir: cli._.join(' '), cli: true, }); diff --git a/src/get/decompress.js b/src/get/decompress.js index 449b125f5..36ce4ae7a 100644 --- a/src/get/decompress.js +++ b/src/get/decompress.js @@ -1,18 +1,17 @@ -import fs from "node:fs"; -import path from "node:path"; -import stream from "node:stream"; +import fs from 'node:fs'; +import path from 'node:path'; +import stream from 'node:stream'; -import * as tar from "tar"; -import yauzl from "yauzl-promise"; +import * as tar from 'tar'; +import yauzl from 'yauzl-promise'; /** * Decompresses a file at `filePath` to `cacheDir` directory. - * * @param {string} filePath - file path to compressed binary * @param {string} cacheDir - directory to decompress into */ export default async function decompress(filePath, cacheDir) { - if (filePath.endsWith(".zip")) { + if (filePath.endsWith('.zip')) { await unzip(filePath, cacheDir); } else { await tar.extract({ @@ -24,9 +23,8 @@ export default async function decompress(filePath, cacheDir) { /** * Get file mode from entry. Reference implementation is [here](https://github.com/fpsqdb/zip-lib/blob/ac447d269218d396e05cd7072d0e9cd82b5ec52c/src/unzip.ts#L380). - * * @param {yauzl.Entry} entry - Yauzl entry - * @return {number} - entry's file mode + * @returns {number} - entry's file mode */ function modeFromEntry(entry) { const attr = entry.externalFileAttributes >> 16 || 33188; @@ -38,12 +36,11 @@ function modeFromEntry(entry) { /** * Unzip `zippedFile` to `cacheDir`. - * * @async * @function * @param {string} zippedFile - file path to .zip file * @param {string} cacheDir - directory to unzip in - * @return {Promise} + * @returns {Promise} */ async function unzip(zippedFile, cacheDir) { const zip = await yauzl.open(zippedFile); @@ -81,8 +78,8 @@ async function unzip(zippedFile, cacheDir) { let entryPathAbs = path.join(cacheDir, symlinkEntry.filename); const readStream = await symlinkEntry.openReadStream(); const chunks = []; - readStream.on("data", (chunk) => chunks.push(chunk)); - await new Promise(resolve => readStream.on("end", resolve)); + readStream.on('data', (chunk) => chunks.push(chunk)); + await new Promise(resolve => readStream.on('end', resolve)); const linkTarget = Buffer.concat(chunks).toString('utf8').trim(); // Check if the symlink or a file/directory already exists at the destination diff --git a/src/get/ffmpeg.js b/src/get/ffmpeg.js index 4db8a869c..65fbf375f 100644 --- a/src/get/ffmpeg.js +++ b/src/get/ffmpeg.js @@ -1,22 +1,20 @@ -import path from "node:path"; +import path from 'node:path'; -import request from "./request.js"; +import request from './request.js'; /** * Download community FFmpeg binary from `https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt`. - * * @param {string} downloadUrl - Download server * @param {string} version - Runtime version * @param {string} platform - NW supported platform * @param {string} arch - NW supported architecture * @param {string} cacheDir - Directory to store FFmpeg binary - * @return {Promise} Path of compressed file which containscommunity FFmpeg binary. + * @returns {Promise} Path of compressed file which containscommunity FFmpeg binary. */ export default async function ffmpeg(downloadUrl, version, platform, arch, cacheDir) { /** * URL to download specific FFmpeg binary from. - * * @type {string} */ const url = [ diff --git a/src/get/index.js b/src/get/index.js index 8b74795b3..aeeecbd59 100644 --- a/src/get/index.js +++ b/src/get/index.js @@ -1,14 +1,14 @@ -import fs from "node:fs"; -import path from "node:path"; -import url from "node:url"; - -import decompress from "./decompress.js"; -import ffmpeg from "./ffmpeg.js"; -import node from "./node.js"; -import nw from "./nw.js"; +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; + +import decompress from './decompress.js'; +import ffmpeg from './ffmpeg.js'; +import node from './node.js'; +import nw from './nw.js'; import verify from './verify.js'; -import util from "../util.js"; +import util from '../util.js'; /** * @typedef {object} GetOptions @@ -25,13 +25,11 @@ import util from "../util.js"; /** * Get binaries. - * * @deprecated since v4.6.4. This logic will be ported over to `nwjs/npm-installer` repo and removed in the next major release (v5.0). - * * @async * @function * @param {GetOptions} options Get mode options - * @return {Promise} + * @returns {Promise} */ async function get(options) { @@ -44,7 +42,6 @@ async function get(options) { /** * If `options.cacheDir` exists, then `true`. Otherwise, it is `false`. - * * @type {boolean} */ const cacheDirExists = await util.fileExists(options.cacheDir); @@ -54,23 +51,21 @@ async function get(options) { /** * File path to compressed binary. - * * @type {string} */ let nwFilePath = path.resolve( options.cacheDir, - `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}.${options.platform === "linux" ? "tar.gz" : "zip" + `nwjs${options.flavor === 'sdk' ? '-sdk' : ''}-v${options.version}-${options.platform}-${options.arch}.${options.platform === 'linux' ? 'tar.gz' : 'zip' }`, ); /** * File path to directory which contain NW.js and related binaries. - * * @type {string} */ let nwDirPath = path.resolve( options.cacheDir, - `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`, + `nwjs${options.flavor === 'sdk' ? '-sdk' : ''}-v${options.version}-${options.platform}-${options.arch}`, ); // If `options.cache` is false, then remove the compressed binary. @@ -89,7 +84,6 @@ async function get(options) { /** * If the compressed binary exists, then `true`. Otherwise, it is `false`. - * * @type {boolean} */ const nwFilePathExists = await util.fileExists(nwFilePath); @@ -103,7 +97,6 @@ async function get(options) { /** * File path to compressed binary which contains community FFmpeg binary. - * * @type {string} */ let ffmpegFilePath = path.resolve( @@ -121,14 +114,13 @@ async function get(options) { /** * If the compressed binary exists, then `true`. Otherwise, it is `false`. - * * @type {boolean} */ const ffmpegFilePathExists = await util.fileExists(ffmpegFilePath); if (ffmpegFilePathExists === false) { // Do not update the options.downloadUrl with the ffmpeg URL here. Doing so would lead to error when options.ffmpeg and options.nativeAddon are both enabled. const downloadUrl = - "https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download"; + 'https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download'; ffmpegFilePath = await ffmpeg(downloadUrl, options.version, options.platform, options.arch, options.cacheDir); } @@ -142,46 +134,43 @@ async function get(options) { /** * Platform dependant file name of FFmpeg binary. - * * @type {string} */ - let ffmpegFileName = ""; - - if (options.platform === "linux") { - ffmpegFileName = "libffmpeg.so"; - } else if (options.platform === "win") { - ffmpegFileName = "ffmpeg.dll"; - } else if (options.platform === "osx") { - ffmpegFileName = "libffmpeg.dylib"; + let ffmpegFileName = ''; + + if (options.platform === 'linux') { + ffmpegFileName = 'libffmpeg.so'; + } else if (options.platform === 'win') { + ffmpegFileName = 'ffmpeg.dll'; + } else if (options.platform === 'osx') { + ffmpegFileName = 'libffmpeg.dylib'; } /** * File path to platform specific FFmpeg file. - * * @type {string} */ let ffmpegBinaryPath = path.resolve(options.cacheDir, ffmpegFileName); /** * File path of where FFmpeg will be copied to. - * * @type {string} */ - let ffmpegBinaryDest = ""; + let ffmpegBinaryDest = ''; - if (options.platform === "linux") { - ffmpegBinaryDest = path.resolve(nwDirPath, "lib", ffmpegFileName); - } else if (options.platform === "win") { + if (options.platform === 'linux') { + ffmpegBinaryDest = path.resolve(nwDirPath, 'lib', ffmpegFileName); + } else if (options.platform === 'win') { ffmpegBinaryDest = path.resolve(nwDirPath, ffmpegFileName); - } else if (options.platform === "osx") { + } else if (options.platform === 'osx') { ffmpegBinaryDest = path.resolve( nwDirPath, - "nwjs.app", - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", - "Current", + 'nwjs.app', + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', + 'Current', ffmpegFileName, ); } @@ -190,11 +179,10 @@ async function get(options) { } - if (options.nativeAddon === "gyp") { + if (options.nativeAddon === 'gyp') { /** * File path to NW'js Node headers tarball. - * * @type {string} */ let nodeFilePath = path.resolve( @@ -212,7 +200,6 @@ async function get(options) { /** * If the compressed binary exists, then `true`. Otherwise, it is `false`. - * * @type {boolean} */ const nodeFilePathExists = await util.fileExists(nodeFilePath); diff --git a/src/get/node.js b/src/get/node.js index b69864482..31cc3419f 100644 --- a/src/get/node.js +++ b/src/get/node.js @@ -1,34 +1,30 @@ -import path from "node:path"; +import path from 'node:path'; -import request from "./request.js"; +import request from './request.js'; /** * Download NW.js's Node.js headers. - * * @param {string} downloadUrl - Download server * @param {string} version - Runtime version * @param {string} cacheDir - Directory to store NW binaries - * @return {Promise} - path of compressed file which contains the Node headers. + * @returns {Promise} - path of compressed file which contains the Node headers. */ export default async function nw(downloadUrl, version, cacheDir) { /** * Name of directory which contains Node headers. - * * @type {string} */ const nodeDir = `node-v${version}`; /** * Name of compressed file which contains Node headers. - * * @type {string} */ - const nwFile = `${nodeDir}.tar.gz` + const nwFile = `${nodeDir}.tar.gz`; /** * URL to download specific Node headers from. - * * @type {string} */ const url = [ diff --git a/src/get/nw.js b/src/get/nw.js index e26b5ffb5..2a4127bbf 100644 --- a/src/get/nw.js +++ b/src/get/nw.js @@ -1,44 +1,40 @@ -import path from "node:path"; +import path from 'node:path'; -import request from "./request.js"; +import request from './request.js'; /** * Download NW.js binary. - * * @param {string} downloadUrl - Download server * @param {string} version - Runtime version * @param {string} flavor - Runtime build flavor * @param {string} platform - NW supported platform * @param {string} arch - NW supported architecture * @param {string} cacheDir - Directory to store NW binaries - * @return {Promise} - path of compressed file which contains NW.js binaries. + * @returns {Promise} - path of compressed file which contains NW.js binaries. */ export default async function nw(downloadUrl, version, flavor, platform, arch, cacheDir) { /** * Name of directory which contains NW.js binaries. - * * @type {string} */ const nwDir = [ - `nwjs`, + 'nwjs', flavor === 'sdk' ? '-sdk' : '', `-v${version}-${platform}-${arch}`, ].join(''); /** * Name of compressed file which contains NW.js binaries. - * * @type {string} */ const nwFile = [ nwDir, - platform === 'linux' ? "tar.gz" : "zip" + platform === 'linux' ? 'tar.gz' : 'zip' ].join('.'); /** * URL to download specific NW.js binary from. - * * @type {string} */ const url = [ diff --git a/src/get/request.js b/src/get/request.js index bc5768443..2c39c2e80 100644 --- a/src/get/request.js +++ b/src/get/request.js @@ -1,26 +1,24 @@ -import fs from "node:fs"; -import stream from "node:stream"; +import fs from 'node:fs'; +import stream from 'node:stream'; -import axios from "axios"; +import axios from 'axios'; /** * Download from `url`. - * * @async * @function - * * @param {string} url - Download server * @param {string} filePath - file path of downloaded content - * @return {Promise} + * @returns {Promise} */ export default async function request(url, filePath) { const writeStream = fs.createWriteStream(filePath); const response = await axios({ - method: "get", + method: 'get', url: url, - responseType: "stream" + responseType: 'stream' }); await stream.promises.pipeline(response.data, writeStream); diff --git a/src/get/verify.js b/src/get/verify.js index 2378c1b80..516b689dc 100644 --- a/src/get/verify.js +++ b/src/get/verify.js @@ -8,12 +8,11 @@ import util from '../util.js'; /** * Verify the SHA256 checksum of downloaded artifacts. - * * @param {string} shaUrl - URL to get the shasum text file from. * @param {string} shaOut - File path to shasum text file. * @param {string} cacheDir - File path to cache directory. * @throws {Error} - * @returns {Promise} + * @returns {Promise} - Returns true if the checksums match. */ export default async function verify(shaUrl, shaOut, cacheDir) { const shaOutExists = await util.fileExists(shaOut); @@ -39,7 +38,7 @@ export default async function verify(shaUrl, shaOut, cacheDir) { hash.update(fileBuffer); const generatedSha = hash.digest('hex'); if (storedSha !== generatedSha) { - throw new Error('SHA256 checksums do not match.'); + throw new Error(`SHA256 checksums do not match. The file ${filePath} expected shasum is ${storedSha} but the actual shasum is ${generatedSha}.`); } } } diff --git a/src/index.js b/src/index.js index 6ef4dd9ef..995a32273 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ -import console from "node:console"; -import fs from "node:fs"; +import console from 'node:console'; +import fs from 'node:fs'; -import bld from "./bld.js"; -import get from "./get/index.js"; -import run from "./run.js"; -import util from "./util.js"; +import bld from './bld.js'; +import get from './get/index.js'; +import run from './run.js'; +import util from './util.js'; /** * @typedef {object} Options Configuration options @@ -31,12 +31,10 @@ import util from "./util.js"; /** * Main module exported. - * * @async * @function - * * @param {Options} options Options - * @return {Promise} + * @returns {Promise} */ async function nwbuild(options) { let built; @@ -48,7 +46,7 @@ async function nwbuild(options) { options = await util.parse(options, manifest); manifest = await util.getNodeManifest({ srcDir: options.srcDir, glob: options.glob }); - if (typeof manifest?.nwbuild === "object") { + if (typeof manifest?.nwbuild === 'object') { options = manifest.nwbuild; } @@ -61,7 +59,7 @@ async function nwbuild(options) { await fs.promises.mkdir(options.cacheDir, { recursive: true }); } - if (options.mode === "build") { + if (options.mode === 'build') { built = fs.existsSync(options.outDir); if (built === false) { await fs.promises.mkdir(options.outDir, { recursive: true }); @@ -95,12 +93,12 @@ async function nwbuild(options) { nativeAddon: options.nativeAddon, }); - if (options.mode === "get") { + if (options.mode === 'get') { // Do nothing else since we have already downloaded the binaries. return; } - if (options.mode === "run") { + if (options.mode === 'run') { await run({ version: options.version, flavor: options.flavor, @@ -111,7 +109,7 @@ async function nwbuild(options) { glob: options.glob, argv: options.argv, }); - } else if (options.mode === "build") { + } else if (options.mode === 'build') { await bld({ version: options.version, flavor: options.flavor, diff --git a/src/run.js b/src/run.js index d904cbbe5..649852a70 100644 --- a/src/run.js +++ b/src/run.js @@ -1,9 +1,9 @@ -import child_process from "node:child_process"; -import console from "node:console"; -import path from "node:path"; -import process from "node:process"; +import child_process from 'node:child_process'; +import console from 'node:console'; +import path from 'node:path'; +import process from 'node:process'; -import util from "./util.js"; +import util from './util.js'; /** * @typedef {object} RunOptions @@ -19,36 +19,33 @@ import util from "./util.js"; /** * Run NW.js application. - * * @deprecated since v4.6.0. This logic will be ported over to `nwjs/npm-installer` repo and removed in the next major release (v5.0). - * * @async * @function - * * @param {RunOptions} options Run mode options - * @return {Promise} + * @returns {Promise} */ async function run({ - version = "latest", - flavor = "normal", + version = 'latest', + flavor = 'normal', platform = util.PLATFORM_KV[process.platform], arch = util.ARCH_KV[process.arch], - srcDir = "./src", - cacheDir = "./cache", + srcDir = './src', + cacheDir = './cache', glob = false, argv = [], }) { try { if (util.EXE_NAME[platform] === undefined) { - throw new Error("Unsupported platform."); + throw new Error('Unsupported platform.'); } if (glob === true) { - throw new Error("Globbing is not supported with run mode."); + throw new Error('Globbing is not supported with run mode.'); } const nwDir = path.resolve( cacheDir, - `nwjs${flavor === "sdk" ? "-sdk" : ""}-v${version}-${platform}-${arch}`, + `nwjs${flavor === 'sdk' ? '-sdk' : ''}-v${version}-${platform}-${arch}`, ); return new Promise((res, rej) => { @@ -56,14 +53,14 @@ async function run({ const nwProcess = child_process.spawn( path.resolve(nwDir, util.EXE_NAME[platform]), [...[srcDir], ...argv], - { stdio: "inherit" }, + { stdio: 'inherit' }, ); - nwProcess.on("close", () => { + nwProcess.on('close', () => { res(); }); - nwProcess.on("error", (error) => { + nwProcess.on('error', (error) => { console.error(error); rej(error); }); diff --git a/src/util.js b/src/util.js index ccf9bf7b7..259b2b986 100644 --- a/src/util.js +++ b/src/util.js @@ -1,37 +1,36 @@ -import console from "node:console"; -import fs from "node:fs"; -import https from "node:https"; -import path from "node:path"; -import process from "node:process"; +import console from 'node:console'; +import fs from 'node:fs'; +import https from 'node:https'; +import path from 'node:path'; +import process from 'node:process'; -import * as GlobModule from "glob"; -import semver from "semver"; +import * as GlobModule from 'glob'; +import semver from 'semver'; /** * Get manifest (array of NW release metadata) from URL. - * * @param {string} manifestUrl Url to manifest - * @return {Promise} - Manifest object + * @returns {Promise} - Manifest object */ function getManifest(manifestUrl) { let chunks = undefined; return new Promise((resolve) => { const req = https.get(manifestUrl, (response) => { - response.on("data", (chunk) => { + response.on('data', (chunk) => { chunks += chunk; }); - response.on("error", (e) => { + response.on('error', (e) => { console.error(e); resolve(undefined); }); - response.on("end", () => { + response.on('end', () => { resolve(chunks); }); }); - req.on("error", (e) => { + req.on('error', (e) => { console.error(e); resolve(undefined); }); @@ -40,13 +39,12 @@ function getManifest(manifestUrl) { /** * Get version specific release metadata. - * * @param {string} version NW version * @param {string} platform NW platform * @param {string} arch NW architecture * @param {string} cacheDir Directory to store NW binaries * @param {string} manifestUrl Url to manifest - * @return {object} Version specific release info + * @returns {object} Version specific release info */ async function getReleaseInfo( version, @@ -57,10 +55,10 @@ async function getReleaseInfo( ) { let releaseData = undefined; let manifestPath = undefined; - if (platform === "osx" && arch === "arm64") { - manifestPath = path.resolve(cacheDir, "manifest.mac.arm.json"); + if (platform === 'osx' && arch === 'arm64') { + manifestPath = path.resolve(cacheDir, 'manifest.mac.arm.json'); } else { - manifestPath = path.resolve(cacheDir, "manifest.json"); + manifestPath = path.resolve(cacheDir, 'manifest.json'); } try { @@ -70,7 +68,7 @@ async function getReleaseInfo( } let manifest = JSON.parse(await fs.promises.readFile(manifestPath)); - if (version === "latest" || version === "stable" || version === "lts") { + if (version === 'latest' || version === 'stable' || version === 'lts') { // Remove leading "v" from version string version = manifest[version].slice(1); } @@ -78,42 +76,40 @@ async function getReleaseInfo( releaseData = manifest.versions.find( (release) => release.version === `v${version}`, ); - } catch (e) { + } catch { console.error( - "The version manifest does not exist/was not downloaded. Please try again in some time.", + 'The version manifest does not exist/was not downloaded. Please try again in some time.', ); } return releaseData; } const PLATFORM_KV = { - darwin: "osx", - linux: "linux", - win32: "win", + darwin: 'osx', + linux: 'linux', + win32: 'win', }; const ARCH_KV = { - x64: "x64", - ia32: "ia32", - arm64: "arm64", + x64: 'x64', + ia32: 'ia32', + arm64: 'arm64', }; const EXE_NAME = { - win: "nw.exe", - osx: "nwjs.app/Contents/MacOS/nwjs", - linux: "nw", + win: 'nw.exe', + osx: 'nwjs.app/Contents/MacOS/nwjs', + linux: 'nw', }; /** * Glob files. - * * @async * @function - * * @param {object} options - glob file options * @param {string | string[]} options.srcDir - app src dir * @param {boolean} options.glob - glob flag - * @return {Promise} - Returns array of file paths + * @returns {Promise} - Returns array of file paths */ async function globFiles({ srcDir, @@ -122,7 +118,7 @@ async function globFiles({ let files; if (glob) { files = []; - const patterns = srcDir.split(" "); + const patterns = srcDir.split(' '); for (const pattern of patterns) { let filePath = await GlobModule.glob(pattern); files.push(...filePath); @@ -135,13 +131,12 @@ async function globFiles({ /** * Get Node manifest. - * * @async * @function * @param {object} options - node manifest options * @param {string | string []} options.srcDir - src dir * @param {boolean} options.glob - glob flag - * @return {object} - Node manifest + * @returns {object} - Node manifest */ async function getNodeManifest({ srcDir, glob @@ -151,16 +146,16 @@ async function getNodeManifest({ if (glob) { files = await globFiles({ srcDir, glob }); for (const file of files) { - if (path.basename(file) === "package.json" && manifest === undefined) { + if (path.basename(file) === 'package.json' && manifest === undefined) { manifest = JSON.parse(await fs.promises.readFile(file)); } } } else { - manifest = JSON.parse(await fs.promises.readFile(path.resolve(srcDir, "package.json"))); + manifest = JSON.parse(await fs.promises.readFile(path.resolve(srcDir, 'package.json'))); } if (manifest === undefined) { - throw new Error("package.json not found in srcDir file glob patterns."); + throw new Error('package.json not found in srcDir file glob patterns.'); } return manifest; @@ -168,39 +163,38 @@ async function getNodeManifest({ /** * Parse options. - * * @param {import("../../index.js").Options} options Options * @param {object} pkg Package.json as JSON - * @return {Promise} Options + * @returns {Promise} Options */ export const parse = async (options, pkg) => { options = options ?? {}; - options.mode = options.mode ?? "build"; + options.mode = options.mode ?? 'build'; - options.version = options.version ?? "latest"; - options.flavor = options.flavor ?? "normal"; + options.version = options.version ?? 'latest'; + options.flavor = options.flavor ?? 'normal'; options.platform = options.platform ?? PLATFORM_KV[process.platform]; options.arch = options.arch ?? ARCH_KV[process.arch]; - options.downloadUrl = options.downloadUrl ?? "https://dl.nwjs.io"; - options.manifestUrl = options.manifestUrl ?? "https://nwjs.io/versions"; - options.cacheDir = options.cacheDir ?? "./cache"; + options.downloadUrl = options.downloadUrl ?? 'https://dl.nwjs.io'; + options.manifestUrl = options.manifestUrl ?? 'https://nwjs.io/versions'; + options.cacheDir = options.cacheDir ?? './cache'; options.cache = options.cache ?? true; options.ffmpeg = options.ffmpeg ?? false; - options.logLevel = options.logLevel ?? "info"; + options.logLevel = options.logLevel ?? 'info'; - if (options.mode === "get") { + if (options.mode === 'get') { return { ...options }; } options.argv = options.argv ?? []; options.glob = options.glob ?? true; - options.srcDir = options.srcDir ?? (options.glob ? "./*" : "."); + options.srcDir = options.srcDir ?? (options.glob ? './*' : '.'); - if (options.mode === "run") { + if (options.mode === 'run') { return { ...options }; } - options.outDir = path.resolve(options.outDir ?? "./out"); + options.outDir = path.resolve(options.outDir ?? './out'); options.zip = options.zip ?? false; options.managedManifest = options.managedManifest ?? false; @@ -211,7 +205,7 @@ export const parse = async (options, pkg) => { options.app.icon = options.app.icon ?? undefined; // TODO(#737): move this out - if (options.platform === "linux") { + if (options.platform === 'linux') { // linux desktop entry file configurations options options.app.genericName = options.app.genericName ?? undefined; options.app.noDisplay = options.app.noDisplay ?? undefined; @@ -235,7 +229,7 @@ export const parse = async (options, pkg) => { options.app.prefersNonDefaultGPU ?? undefined; options.app.singleMainWindow = options.app.singleMainWindow ?? undefined; } - if (options.platform === "win") { + if (options.platform === 'win') { // windows configuration options options.app.version = options.app.version ?? pkg.version; options.app.comments = options.app.comments ?? undefined; @@ -254,7 +248,7 @@ export const parse = async (options, pkg) => { options.app.languageCode = options.app.languageCode ?? 1033; } - if (options.platform === "osx") { + if (options.platform === 'osx') { options.app.LSApplicationCategoryType = options.app.LSApplicationCategoryType ?? undefined; options.app.CFBundleIdentifier = @@ -276,21 +270,20 @@ export const parse = async (options, pkg) => { /** * Validate options. - * * @param {import("../index.js").Options} options Options * @param {object} releaseInfo Version specific NW release info - * @return {Promise} Return undefined if options are valid + * @returns {Promise} Return undefined if options are valid * @throws {Error} Throw error if options are invalid */ export const validate = async (options, releaseInfo) => { - if (!["get", "run", "build"].includes(options.mode)) { + if (!['get', 'run', 'build'].includes(options.mode)) { throw new Error( `Unknown mode ${options.mode}. Expected "get", "run" or "build".`, ); } - if (typeof releaseInfo === "undefined") { + if (typeof releaseInfo === 'undefined') { throw new Error( - "Either the specific version info does not exist or the version manifest itself does not exist. In case of the latter, please check your internet connection and try again later.", + 'Either the specific version info does not exist or the version manifest itself does not exist. In case of the latter, please check your internet connection and try again later.', ); } if (!releaseInfo.flavors.includes(options.flavor)) { @@ -310,40 +303,40 @@ export const validate = async (options, releaseInfo) => { // if (typeof options.cacheDir !== "string") { // throw new Error("Expected options.cacheDir to be a string. Got " + typeof options.cacheDir); // } - if (typeof options.cache !== "boolean") { + if (typeof options.cache !== 'boolean') { return new Error( - "Expected options.cache to be a boolean. Got " + typeof options.cache, + 'Expected options.cache to be a boolean. Got ' + typeof options.cache, ); } - if (typeof options.ffmpeg !== "boolean") { + if (typeof options.ffmpeg !== 'boolean') { return new Error( - "Expected options.ffmpeg to be a boolean. Got " + typeof options.ffmpeg, + 'Expected options.ffmpeg to be a boolean. Got ' + typeof options.ffmpeg, ); } if ( - options.logLevel !== "error" && - options.logLevel !== "warn" && - options.logLevel !== "info" && - options.logLevel !== "debug" + options.logLevel !== 'error' && + options.logLevel !== 'warn' && + options.logLevel !== 'info' && + options.logLevel !== 'debug' ) { throw new Error( - "Expected options.logLevel to be 'error', 'warn', 'info' or 'debug'. Got " + + 'Expected options.logLevel to be \'error\', \'warn\', \'info\' or \'debug\'. Got ' + options.logLevel, ); } - if (options.mode === "get") { + if (options.mode === 'get') { return undefined; } if (Array.isArray(options.argv)) { return new Error( - "Expected options.argv to be an array. Got " + typeof options.argv, + 'Expected options.argv to be an array. Got ' + typeof options.argv, ); } - if (typeof options.glob !== "boolean") { + if (typeof options.glob !== 'boolean') { return new Error( - "Expected options.glob to be a boolean. Got " + typeof options.glob, + 'Expected options.glob to be a boolean. Got ' + typeof options.glob, ); } @@ -351,7 +344,7 @@ export const validate = async (options, releaseInfo) => { await fs.promises.readdir(options.srcDir); } - if (options.mode === "run") { + if (options.mode === 'run') { return undefined; } @@ -360,32 +353,32 @@ export const validate = async (options, releaseInfo) => { } if ( - typeof options.managedManifest !== "boolean" && - typeof options.managedManifest !== "object" && - typeof options.managedManifest !== "string" + typeof options.managedManifest !== 'boolean' && + typeof options.managedManifest !== 'object' && + typeof options.managedManifest !== 'string' ) { return new Error( - "Expected options.managedManifest to be a boolean, object or string. Got " + + 'Expected options.managedManifest to be a boolean, object or string. Got ' + typeof options.managedManifest, ); } - if (typeof options.managedManifest === "object") { + if (typeof options.managedManifest === 'object') { if (options.managedManifest.name === undefined) { - return new Error("Expected NW.js Manifest to have a `name` property."); + return new Error('Expected NW.js Manifest to have a `name` property.'); } if (options.managedManifest.main === undefined) { - return new Error("Expected NW.js Manifest to have a `main` property."); + return new Error('Expected NW.js Manifest to have a `main` property.'); } } - if (typeof options.nativeAddon !== "boolean") { - if (typeof options.nativeAddon !== "boolean" && typeof options.nativeAddon !== "string") { - return new Error("Expected options.nativeAddon to be a boolean or string type. Got " + typeof options.nativeAddon); + if (typeof options.nativeAddon !== 'boolean') { + if (typeof options.nativeAddon !== 'boolean' && typeof options.nativeAddon !== 'string') { + return new Error('Expected options.nativeAddon to be a boolean or string type. Got ' + typeof options.nativeAddon); } - if (semver.parse(options.version).minor >= "83" && options.nativeAddon !== false) { - return new Error("Native addons are not supported for NW.js v0.82.0 and below"); + if (semver.parse(options.version).minor >= '83' && options.nativeAddon !== false) { + return new Error('Native addons are not supported for NW.js v0.82.0 and below'); } } @@ -395,39 +388,36 @@ export const validate = async (options, releaseInfo) => { /** * Get path to various NW specific file paths. - * * @async * @function - * * @param {"chromedriver"} type - NW specific file or directory * @param {object} options - nwbuild options - * @return {string} - Path to chromedriver + * @returns {string} - Path to chromedriver * @throws {Error} */ async function getPath(type, options) { - if (type === "chromedriver") { + if (type === 'chromedriver') { return path.resolve( options.cacheDir, - `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform + `nwjs${options.flavor === 'sdk' ? '-sdk' : ''}-v${options.version}-${options.platform }-${options.arch}`, - `chromedriver${options.platform === "win" ? ".exe" : ""}`, + `chromedriver${options.platform === 'win' ? '.exe' : ''}`, ); } else { - throw new Error("Invalid type. Expected `chromedriver` but got ", type); + throw new Error('Invalid type. Expected `chromedriver` but got ', type); } } /** * Check if file exists at specified path. - * * @param {string} filePath - File path to check existence of - * @return {Promise} `true` if exists, otherwise `false` + * @returns {Promise} `true` if exists, otherwise `false` */ async function fileExists(filePath) { let exists = true; try { await fs.promises.stat(filePath); - } catch (_) { + } catch { exists = false; } return exists; diff --git a/tests/fixtures/demo.js b/tests/fixtures/demo.js index 4aa41a498..1dd5455f1 100644 --- a/tests/fixtures/demo.js +++ b/tests/fixtures/demo.js @@ -1,11 +1,11 @@ -import nwbuild from "../../src/index.js"; +import nwbuild from '../../src/index.js'; await nwbuild({ - mode: "build", - flavor: "sdk", - platform: "osx", - srcDir: "./tests/fixtures/app", - cacheDir: "./node_modules/nw", + mode: 'build', + flavor: 'sdk', + platform: 'osx', + srcDir: './tests/fixtures/app', + cacheDir: './node_modules/nw', outDir: './tests/fixtures/out', glob: false, app: { diff --git a/tests/specs/decompress.test.js b/tests/specs/decompress.test.js index 062f6659c..be8101934 100644 --- a/tests/specs/decompress.test.js +++ b/tests/specs/decompress.test.js @@ -1,19 +1,19 @@ -import fs from "node:fs"; -import path from "node:path"; -import process from "node:process"; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; -import * as nw from "nw"; -import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; +import * as nw from 'nw'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import decompress from "../../src/get/decompress.js"; +import decompress from '../../src/get/decompress.js'; import util from '../../src/util.js'; -describe("get/decompress", async function () { +describe('get/decompress', async function () { let nwFilePath = ''; let nwDirPath = ''; - let nwOutPath = "./tests/fixtures/cache"; + let nwOutPath = './tests/fixtures/cache'; afterAll(async function () { await fs.promises.rm(nwOutPath, { recursive: true, force: true }); @@ -22,7 +22,7 @@ describe("get/decompress", async function () { beforeAll(async function () { nwDirPath = await nw.findpath('all', { flavor: 'sdk' }); - const cacheExists = await util.fileExists(nwOutPath) + const cacheExists = await util.fileExists(nwOutPath); if (!cacheExists) { await fs.promises.mkdir(nwOutPath); } @@ -34,18 +34,18 @@ describe("get/decompress", async function () { } }); - it("decompresses a NW.js binary", async function () { + it('decompresses a NW.js binary', async function () { await decompress(nwFilePath, nwOutPath); }, Infinity); - it.runIf(process.platform === 'darwin')("preserves symlinks on macos", async function () { - const frameworksPath = path.resolve(process.cwd(), nwOutPath, nwDirPath, "nwjs.app", "Contents", "Frameworks", "nwjs Framework.framework"); + it.runIf(process.platform === 'darwin')('preserves symlinks on macos', async function () { + const frameworksPath = path.resolve(process.cwd(), nwOutPath, nwDirPath, 'nwjs.app', 'Contents', 'Frameworks', 'nwjs Framework.framework'); const symlinks = [ - path.join(frameworksPath, "Helpers"), - path.join(frameworksPath, "Libraries"), - path.join(frameworksPath, "nwjs Framework"), - path.join(frameworksPath, "Resources"), - path.join(frameworksPath, "Versions", "Current"), + path.join(frameworksPath, 'Helpers'), + path.join(frameworksPath, 'Libraries'), + path.join(frameworksPath, 'nwjs Framework'), + path.join(frameworksPath, 'Resources'), + path.join(frameworksPath, 'Versions', 'Current'), ]; for (const symlink of symlinks) { diff --git a/tests/specs/ffmpeg.test.js b/tests/specs/ffmpeg.test.js index 4cd3f3fd2..ee5299329 100644 --- a/tests/specs/ffmpeg.test.js +++ b/tests/specs/ffmpeg.test.js @@ -1,13 +1,13 @@ -import fs from "node:fs"; -import process from "node:process"; +import fs from 'node:fs'; +import process from 'node:process'; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from 'vitest'; -import util from "../../src/util.js"; +import util from '../../src/util.js'; -import ffmpeg from "../../src/get/ffmpeg.js"; +import ffmpeg from '../../src/get/ffmpeg.js'; -describe("get/ffmpeg", function () { +describe('get/ffmpeg', function () { let ffmpegFile = ''; @@ -15,13 +15,13 @@ describe("get/ffmpeg", function () { fs.promises.rm(ffmpegFile, { recursive: true, force: true }); }); - it("downloades community prebuild FFmpeg for specifc platform", async function () { + it('downloades community prebuild FFmpeg for specifc platform', async function () { ffmpegFile = await ffmpeg( - "https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download", - "0.83.0", + 'https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download', + '0.83.0', util.PLATFORM_KV[process.platform], util.ARCH_KV[process.arch], - "./tests/fixtures" + './tests/fixtures' ); expect(util.fileExists(ffmpegFile)).resolves.toBe(true); }, Infinity); diff --git a/tests/specs/node.test.js b/tests/specs/node.test.js index 423c3e588..190c71f1b 100644 --- a/tests/specs/node.test.js +++ b/tests/specs/node.test.js @@ -1,12 +1,12 @@ -import fs from "node:fs"; +import fs from 'node:fs'; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from 'vitest'; -import util from "../../src/util.js"; +import util from '../../src/util.js'; -import node from "../../src/get/node.js"; +import node from '../../src/get/node.js'; -describe("get/node", function () { +describe('get/node', function () { let nodeFile = ''; @@ -14,11 +14,11 @@ describe("get/node", function () { fs.promises.rm(nodeFile, { recursive: true, force: true }); }); - it("downloades Node headers", async function () { + it('downloades Node headers', async function () { nodeFile = await node( - "https://dl.nwjs.io", - "0.83.0", - "./tests/fixtures" + 'https://dl.nwjs.io', + '0.83.0', + './tests/fixtures' ); expect(util.fileExists(nodeFile)).resolves.toBe(true); }, Infinity); diff --git a/tests/specs/nw.test.js b/tests/specs/nw.test.js index d43f63485..416c01ace 100644 --- a/tests/specs/nw.test.js +++ b/tests/specs/nw.test.js @@ -1,13 +1,13 @@ -import fs from "node:fs"; -import process from "node:process"; +import fs from 'node:fs'; +import process from 'node:process'; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from 'vitest'; -import util from "../../src/util.js"; +import util from '../../src/util.js'; -import nw from "../../src/get/nw.js"; +import nw from '../../src/get/nw.js'; -describe("get/nw", function () { +describe('get/nw', function () { let nwFile = ''; @@ -15,14 +15,14 @@ describe("get/nw", function () { fs.promises.rm(nwFile, { recursive: true, force: true }); }); - it("downloades a NW.js Linux tarball or Windows/MacOS zip", async function () { + it('downloades a NW.js Linux tarball or Windows/MacOS zip', async function () { nwFile = await nw( - "https://dl.nwjs.io", - "0.83.0", - "sdk", + 'https://dl.nwjs.io', + '0.83.0', + 'sdk', util.PLATFORM_KV[process.platform], util.ARCH_KV[process.arch], - "./tests/fixtures" + './tests/fixtures' ); expect(util.fileExists(nwFile)).resolves.toBe(true); }, Infinity); diff --git a/tests/specs/osx.test.js b/tests/specs/osx.test.js index 36a4140e9..ed4dabaf5 100644 --- a/tests/specs/osx.test.js +++ b/tests/specs/osx.test.js @@ -1,17 +1,17 @@ -import fs from "node:fs"; -import path from "node:path"; -import process from "node:process"; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; import * as nw from 'nw'; import plist from 'plist'; -import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import setOsxConfig from "../../src/bld/osx.js"; -import util from "../../src/util.js"; +import setOsxConfig from '../../src/bld/osx.js'; +import util from '../../src/util.js'; -import nodeManifest from "../../package.json"; +import nodeManifest from '../../package.json'; -describe.runIf(process.platform === 'darwin')("bld/setOsxConfig", async function () { +describe.runIf(process.platform === 'darwin')('bld/setOsxConfig', async function () { const outDir = './tests/fixtures/macos'; const appPath = path.join(outDir, 'nwapp.app'); @@ -24,49 +24,49 @@ describe.runIf(process.platform === 'darwin')("bld/setOsxConfig", async function ); const chromiumVersion = releaseInfo.components.chromium; const helperAlertsPath = path.join(appPath, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwapp Helper (Alerts).app`); + 'Helpers', + 'nwapp Helper (Alerts).app'); const helperGPUPath = path.join(appPath, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwapp Helper (GPU).app`); + 'Helpers', + 'nwapp Helper (GPU).app'); const helperPluginPath = path.join(appPath, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwapp Helper (Plugin).app`); + 'Helpers', + 'nwapp Helper (Plugin).app'); const helperRendererPath = path.join(appPath, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwapp Helper (Renderer).app`); + 'Helpers', + 'nwapp Helper (Renderer).app'); const helperPath = path.join(appPath, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Versions", + 'Contents', + 'Frameworks', + 'nwjs Framework.framework', + 'Versions', chromiumVersion, - "Helpers", - `nwapp Helper.app`); + 'Helpers', + 'nwapp Helper.app'); beforeAll(async function () { /* Copy the cached NW.js into a specific `outDir`. */ - const nwDir = await nw.findpath('all', { flavor: 'sdk' }) + const nwDir = await nw.findpath('all', { flavor: 'sdk' }); await fs.promises.cp(nwDir, outDir, { recursive: true, force: true }); /* Rename relevant bundles' plists and executables. */ @@ -91,7 +91,7 @@ describe.runIf(process.platform === 'darwin')("bld/setOsxConfig", async function }); }); - it("renames the .app files correctly", async function () { + it('renames the .app files correctly', async function () { const appPathExists = await util.fileExists(appPath); expect(appPathExists).toEqual(true); @@ -111,135 +111,135 @@ describe.runIf(process.platform === 'darwin')("bld/setOsxConfig", async function expect(helperPathExists).toEqual(true); }); - it("renames the executables correctly", async function () { - const appExePath = path.join(appPath, "Contents", "MacOS", "nwapp"); + it('renames the executables correctly', async function () { + const appExePath = path.join(appPath, 'Contents', 'MacOS', 'nwapp'); const appExePathExists = await util.fileExists(appExePath); expect(appExePathExists).toEqual(true); - const helperAlertsExePath = path.join(helperAlertsPath, "Contents", "MacOS", "nwapp Helper (Alerts)"); + const helperAlertsExePath = path.join(helperAlertsPath, 'Contents', 'MacOS', 'nwapp Helper (Alerts)'); const helperAlertsExePathExists = await util.fileExists(helperAlertsExePath); expect(helperAlertsExePathExists).toEqual(true); - const helperGPUExePath = path.join(helperGPUPath, "Contents", "MacOS", "nwapp Helper (GPU)"); + const helperGPUExePath = path.join(helperGPUPath, 'Contents', 'MacOS', 'nwapp Helper (GPU)'); const helperGPUExePathExists = await util.fileExists(helperGPUExePath); expect(helperGPUExePathExists).toEqual(true); - const helperPluginExePath = path.join(helperPluginPath, "Contents", "MacOS", "nwapp Helper (Plugin)"); + const helperPluginExePath = path.join(helperPluginPath, 'Contents', 'MacOS', 'nwapp Helper (Plugin)'); const helperPluginExePathExists = await util.fileExists(helperPluginExePath); expect(helperPluginExePathExists).toEqual(true); - const helperRendererExePath = path.join(helperRendererPath, "Contents", "MacOS", "nwapp Helper (Renderer)"); + const helperRendererExePath = path.join(helperRendererPath, 'Contents', 'MacOS', 'nwapp Helper (Renderer)'); const helperRendererExePathExists = await util.fileExists(helperRendererExePath); expect(helperRendererExePathExists).toEqual(true); - const helperExePath = path.join(helperPath, "Contents", "MacOS", "nwapp Helper"); + const helperExePath = path.join(helperPath, 'Contents', 'MacOS', 'nwapp Helper'); const helperExePathExists = await util.fileExists(helperExePath); expect(helperExePathExists).toEqual(true); }); - it("", async function () { + it('', async function () { const ContentsInfoPlistPath = path.resolve( appPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ); const ContentsInfoPlistJson = plist.parse( await fs.promises.readFile( ContentsInfoPlistPath, - "utf-8" + 'utf-8' ) ); - expect(ContentsInfoPlistJson.LSApplicationCategoryType).toEqual("public.app-category.utilities"); - expect(ContentsInfoPlistJson.CFBundleIdentifier).toEqual("io.nwutils.demo"); - expect(ContentsInfoPlistJson.CFBundleName).toEqual("Demo"); - expect(ContentsInfoPlistJson.CFBundleDisplayName).toEqual("Demo"); - expect(ContentsInfoPlistJson.CFBundleSpokenName).toEqual("Demo"); - expect(ContentsInfoPlistJson.CFBundleVersion).toEqual("0.0.0"); - expect(ContentsInfoPlistJson.CFBundleShortVersionString).toEqual("0.0.0"); - expect(ContentsInfoPlistJson.CFBundleExecutable).toEqual("nwapp"); + expect(ContentsInfoPlistJson.LSApplicationCategoryType).toEqual('public.app-category.utilities'); + expect(ContentsInfoPlistJson.CFBundleIdentifier).toEqual('io.nwutils.demo'); + expect(ContentsInfoPlistJson.CFBundleName).toEqual('Demo'); + expect(ContentsInfoPlistJson.CFBundleDisplayName).toEqual('Demo'); + expect(ContentsInfoPlistJson.CFBundleSpokenName).toEqual('Demo'); + expect(ContentsInfoPlistJson.CFBundleVersion).toEqual('0.0.0'); + expect(ContentsInfoPlistJson.CFBundleShortVersionString).toEqual('0.0.0'); + expect(ContentsInfoPlistJson.CFBundleExecutable).toEqual('nwapp'); const HelperAlertsAppJson = plist.parse( await fs.promises.readFile( path.resolve( helperAlertsPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); - expect(HelperAlertsAppJson.CFBundleDisplayName).toEqual("nwapp Helper (Alerts)"); - expect(HelperAlertsAppJson.CFBundleName).toEqual("nwapp Helper (Alerts)"); - expect(HelperAlertsAppJson.CFBundleIdentifier).toEqual("io.nwutils.demo.helper.alert"); - expect(HelperAlertsAppJson.CFBundleExecutable).toEqual("nwapp Helper (Alerts)"); + expect(HelperAlertsAppJson.CFBundleDisplayName).toEqual('nwapp Helper (Alerts)'); + expect(HelperAlertsAppJson.CFBundleName).toEqual('nwapp Helper (Alerts)'); + expect(HelperAlertsAppJson.CFBundleIdentifier).toEqual('io.nwutils.demo.helper.alert'); + expect(HelperAlertsAppJson.CFBundleExecutable).toEqual('nwapp Helper (Alerts)'); const HelperGpuAppJson = plist.parse( await fs.promises.readFile( path.resolve( helperGPUPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); - expect(HelperGpuAppJson.CFBundleDisplayName).toEqual("nwapp Helper (GPU)"); - expect(HelperGpuAppJson.CFBundleName).toEqual("nwapp Helper (GPU)"); - expect(HelperGpuAppJson.CFBundleIdentifier).toEqual("io.nwutils.demo.helper.gpu"); - expect(HelperGpuAppJson.CFBundleExecutable).toEqual("nwapp Helper (GPU)"); + expect(HelperGpuAppJson.CFBundleDisplayName).toEqual('nwapp Helper (GPU)'); + expect(HelperGpuAppJson.CFBundleName).toEqual('nwapp Helper (GPU)'); + expect(HelperGpuAppJson.CFBundleIdentifier).toEqual('io.nwutils.demo.helper.gpu'); + expect(HelperGpuAppJson.CFBundleExecutable).toEqual('nwapp Helper (GPU)'); const HelperPluginAppJson = plist.parse( await fs.promises.readFile( path.resolve( helperPluginPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); - expect(HelperPluginAppJson.CFBundleDisplayName).toEqual("nwapp Helper (Plugin)"); - expect(HelperPluginAppJson.CFBundleName).toEqual("nwapp Helper (Plugin)"); - expect(HelperPluginAppJson.CFBundleIdentifier).toEqual("io.nwutils.demo.helper.plugin"); - expect(HelperPluginAppJson.CFBundleExecutable).toEqual("nwapp Helper (Plugin)"); + expect(HelperPluginAppJson.CFBundleDisplayName).toEqual('nwapp Helper (Plugin)'); + expect(HelperPluginAppJson.CFBundleName).toEqual('nwapp Helper (Plugin)'); + expect(HelperPluginAppJson.CFBundleIdentifier).toEqual('io.nwutils.demo.helper.plugin'); + expect(HelperPluginAppJson.CFBundleExecutable).toEqual('nwapp Helper (Plugin)'); const HelperRendererAppJson = plist.parse( await fs.promises.readFile( path.resolve( helperRendererPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); - expect(HelperRendererAppJson.CFBundleDisplayName).toEqual("nwapp Helper (Renderer)"); - expect(HelperRendererAppJson.CFBundleName).toEqual("nwapp Helper (Renderer)"); - expect(HelperRendererAppJson.CFBundleIdentifier).toEqual("io.nwutils.demo.helper.renderer"); - expect(HelperRendererAppJson.CFBundleExecutable).toEqual("nwapp Helper (Renderer)"); + expect(HelperRendererAppJson.CFBundleDisplayName).toEqual('nwapp Helper (Renderer)'); + expect(HelperRendererAppJson.CFBundleName).toEqual('nwapp Helper (Renderer)'); + expect(HelperRendererAppJson.CFBundleIdentifier).toEqual('io.nwutils.demo.helper.renderer'); + expect(HelperRendererAppJson.CFBundleExecutable).toEqual('nwapp Helper (Renderer)'); const HelperAppJson = plist.parse( await fs.promises.readFile( path.resolve( helperPath, - "Contents", - "Info.plist" + 'Contents', + 'Info.plist' ), - "utf-8" + 'utf-8' ) ); - expect(HelperAppJson.CFBundleDisplayName).toEqual("nwapp Helper"); - expect(HelperAppJson.CFBundleName).toEqual("nwapp Helper"); - expect(HelperAppJson.CFBundleIdentifier).toEqual("io.nwutils.demo.helper"); - expect(HelperAppJson.CFBundleExecutable).toEqual("nwapp Helper"); + expect(HelperAppJson.CFBundleDisplayName).toEqual('nwapp Helper'); + expect(HelperAppJson.CFBundleName).toEqual('nwapp Helper'); + expect(HelperAppJson.CFBundleIdentifier).toEqual('io.nwutils.demo.helper'); + expect(HelperAppJson.CFBundleExecutable).toEqual('nwapp Helper'); afterAll(async function () { await fs.promises.rm('./tests/fixtures/macos', { recursive: true, force: true }); }); - }) + }); }); diff --git a/tests/specs/request.test.js b/tests/specs/request.test.js index bd28eaa7e..a0b2319ac 100644 --- a/tests/specs/request.test.js +++ b/tests/specs/request.test.js @@ -1,15 +1,15 @@ -import { describe, expect, it } from "vitest"; +import { describe, expect, it } from 'vitest'; -import util from "../../src/util.js"; +import util from '../../src/util.js'; -import request from "../../src/get/request.js"; +import request from '../../src/get/request.js'; -describe.skip("get/request", function () { +describe.skip('get/request', function () { - let url = "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json" - const filePath = "./tests/fixtures/cache/request.test.json"; + let url = 'https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json'; + const filePath = './tests/fixtures/cache/request.test.json'; - it("downloads from specific url", async function () { + it('downloads from specific url', async function () { await request(url, filePath); expect(util.fileExists(filePath)).resolves.toBe(true); }); diff --git a/tests/specs/run.test.js b/tests/specs/run.test.js index c53d56e75..dbd16fc46 100644 --- a/tests/specs/run.test.js +++ b/tests/specs/run.test.js @@ -1,30 +1,30 @@ -import path from "node:path"; -import process from "node:process"; +import path from 'node:path'; +import process from 'node:process'; -import { By } from "selenium-webdriver"; -import chrome from "selenium-webdriver/chrome.js"; -import { beforeAll, describe, expect, it } from "vitest"; +import { By } from 'selenium-webdriver'; +import chrome from 'selenium-webdriver/chrome.js'; +import { beforeAll, describe, expect, it } from 'vitest'; -import build from "../../src/bld.js"; -import get from "../../src/get/index.js"; -import util from "../../src/util.js"; +import build from '../../src/bld.js'; +import get from '../../src/get/index.js'; +import util from '../../src/util.js'; const { Driver, ServiceBuilder, Options } = chrome; -describe.skip("build test suite", async () => { +describe.skip('build test suite', async () => { let driver = undefined; const nwOptions = { - srcDir: "tests/fixtures/app", - mode: "build", - version: "0.83.0", - flavor: "sdk", + srcDir: 'tests/fixtures/app', + mode: 'build', + version: '0.83.0', + flavor: 'sdk', platform: util.PLATFORM_KV[process.platform], arch: util.ARCH_KV[process.arch], - downloadUrl: "https://dl.nwjs.io", - manifestUrl: "https://nwjs.io/versions", - outDir: "tests/fixtures/out/app", - cacheDir: "tests/fixtures/cache", + downloadUrl: 'https://dl.nwjs.io', + manifestUrl: 'https://nwjs.io/versions', + outDir: 'tests/fixtures/out/app', + cacheDir: 'tests/fixtures/cache', cache: true, ffmpeg: false, glob: false, @@ -32,7 +32,7 @@ describe.skip("build test suite", async () => { nativeAddon: false, zip: false, app: { - name: "demo" + name: 'demo' } }; @@ -40,24 +40,24 @@ describe.skip("build test suite", async () => { await get(nwOptions); }, Infinity); - it("builds without errors", async () => { + it('builds without errors', async () => { await build(nwOptions); }); - it("runs after build", async () => { + it('runs after build', async () => { const options = new Options(); const args = [ - `--nwapp=${path.resolve("test", "fixture", "app")}`, - "--headless=new", + `--nwapp=${path.resolve('test', 'fixture', 'app')}`, + '--headless=new', ]; options.addArguments(args); - const chromedriverPath = util.getPath("chromedriver", nwOptions); + const chromedriverPath = util.getPath('chromedriver', nwOptions); const service = new ServiceBuilder(chromedriverPath).build(); driver = Driver.createSession(options, service); - const text = await driver.findElement(By.id("test")).getText(); - expect(text).toBe("Hello, World!"); + const text = await driver.findElement(By.id('test')).getText(); + expect(text).toBe('Hello, World!'); }, { timeout: Infinity }); }); diff --git a/tests/specs/verify.test.js b/tests/specs/verify.test.js index c1ba218af..80d567be6 100644 --- a/tests/specs/verify.test.js +++ b/tests/specs/verify.test.js @@ -1,13 +1,15 @@ -import { describe, expect, it } from "vitest"; +import { describe, expect, it } from 'vitest'; -import verify from "../../src/get/verify.js"; +import verify from '../../src/get/verify.js'; -describe("get/verify", function () { +import nodeManifest from '../../package.json'; - it("verify shasums", async function () { +describe('get/verify', function () { + + it('verify shasums', async function () { const status = await verify( - 'https://dl.nwjs.io/v0.90.0/SHASUMS256.txt', - './node_modules/nw/shasum/0.90.0.txt', + `https://dl.nwjs.io/v${nodeManifest.devDependencies.nw.split('^')[1]}/SHASUMS256.txt`, + `./node_modules/nw/shasum/${nodeManifest.devDependencies.nw.split('^')[1]}.txt`, './node_modules/nw' ); expect(status).toBe(true);