diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 0ef9e4fdb..000000000 --- a/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -node_modules - -cache -build -dist -out diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 2344bddf9..99290750a 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: v3-cd +name: cd on: push: branches: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09c52f9a7..20379a82b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: v3-ci +name: ci on: pull_request: branches: @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [macos-13, ubuntu-22.04, windows-2022] - node: [16, 18, 20] + node: [21] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -37,8 +37,6 @@ jobs: run: npm link nw-builder - name: Prepare test environment run: npm run test:prep - - name: Run unit tests - run: npm run test:unit # - name: Run Tape tests # run: npm run test:tape # - name: Run ChromeDriver tests diff --git a/cfg/eslint.config.cjs b/cfg/eslint.config.cjs deleted file mode 100644 index 99ec96d11..000000000 --- a/cfg/eslint.config.cjs +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - parserOptions: { - ecmaVersion: 2023, - sourceType: "module", - }, - env: { - es6: true, - node: true, - }, - extends: ["eslint:recommended", "tjw-jsdoc"], - rules: { - "jsdoc/require-file-overview": "off", - "jsdoc/require-returns-description": "off", - "jsdoc/match-description": "off", - "jsdoc/valid-types": "off", - }, -}; diff --git a/lib/cli.cjs b/lib/cli.cjs index ed9cd189e..fdfdfe87a 100755 --- a/lib/cli.cjs +++ b/lib/cli.cjs @@ -4,7 +4,7 @@ const yargs = require("yargs/yargs"); const { hideBin } = require("yargs/helpers"); const { nwbuild } = require("./index.cjs"); -const { detectCurrentPlatform } = require("../dist/index.cjs"); +const detectCurrentPlatform = require("./util/detectCurrentPlatform.cjs"); const cli = yargs(hideBin(process.argv)) .version(false) diff --git a/lib/util/detectCurrentPlatform.cjs b/lib/util/detectCurrentPlatform.cjs new file mode 100644 index 000000000..2b11a2f1a --- /dev/null +++ b/lib/util/detectCurrentPlatform.cjs @@ -0,0 +1,35 @@ +/** + * @readonly + * @enum {string} + */ +const Platform = { + NIX_32: "linux32", + NIX_64: "linux64", + OSX_32: "osx32", + OSX_64: "osx64", + WIN_32: "win32", + WIN_64: "win64", +}; + +/** + * Get current platform and arch. + * + * @param {NodeJS.Process} process - Node.js process object + * @return {Platform | undefined} - Current platform and arch + */ +function detectCurrentPlatform (process) { + switch (process.platform) { + case "darwin": + return process.arch === "x64" ? Platform.OSX_64 : Platform.OSX_32; + + case "win32": + return process.arch === "x64" ? Platform.WIN_64 : Platform.WIN_32; + + case "linux": + return process.arch === "x64" ? Platform.NIX_64 : Platform.NIX_32; + default: + return undefined; + } +} + +module.exports = detectCurrentPlatform; diff --git a/package.json b/package.json index 77994f105..d6bf1069f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "bin": { "nwbuild": "./lib/cli.cjs" }, - "type": "module", "files": [ "bin", "lib", @@ -42,10 +41,9 @@ }, "scripts": { "postinstall": "npm run test:prep", - "lint": "eslint --config=cfg/eslint.config.cjs src test", - "lint:fix": "eslint --config=cfg/eslint.config.cjs --fix src test", + "lint": "eslint ./lib/**/*.cjs", + "lint:fix": "eslint --fix ./lib/**/*.cjs", "test:prep": "esbuild src/index.js --bundle --platform=node --outfile=./dist/index.cjs", - "test:unit": "node --test test/unit/detectCurrentPlatform.js ", "test:tape": "tape './test/*.cjs'", "test:sanity": "node --test-reporter=spec --test e2e/test.js", "demo": "npm run test:prep && npm link nw-builder && cd test && node demo.cjs" @@ -78,5 +76,22 @@ "winston": "^3.11.0", "yargs": "^17.7.2" }, - "packageManager": "npm@9.8.1" + "packageManager": "npm@10.4.0", + "eslintConfig": { + "parserOptions": { + "ecmaVersion": 2023, + "sourceType": "commonjs" + }, + "env": { + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "tjw-jsdoc" + ], + "rules": { + "jsdoc/require-file-overview": "off" + } + } } diff --git a/src/constants/Platform.js b/src/constants/Platform.js deleted file mode 100644 index bbc27d344..000000000 --- a/src/constants/Platform.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @readonly - * @enum {string} - */ -const Platform = { - NIX_32: "linux32", - NIX_64: "linux64", - OSX_32: "osx32", - OSX_64: "osx64", - WIN_32: "win32", - WIN_64: "win64", -}; - -Object.freeze(Platform); - -export default Platform; diff --git a/src/index.js b/src/index.js index 239d55c5a..d28055fe4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,5 @@ import Options from "./constants/Options"; -import Platform from "./constants/Platform"; import Platforms from "./constants/Platforms"; -import detectCurrentPlatform from "./utilities/detectCurrentPlatform"; import { get } from "./get.js"; import { log, setLogLevel } from "./log.js"; @@ -10,9 +8,7 @@ import { isCached, parse, getReleaseInfo, validate } from "./util.js"; export { Options, - Platform, Platforms, - detectCurrentPlatform, get, getReleaseInfo, isCached, diff --git a/src/util.js b/src/util.js index 2e3c02af8..a1a127550 100644 --- a/src/util.js +++ b/src/util.js @@ -3,7 +3,7 @@ import { get } from "node:https"; import { resolve } from "node:path"; import process from "node:process"; -import detectCurrentPlatform from "./utilities/detectCurrentPlatform.js"; +import detectCurrentPlatform from "../lib/util/detectCurrentPlatform.cjs"; import { log } from "./log.js"; /** diff --git a/src/utilities/detectCurrentPlatform.js b/src/utilities/detectCurrentPlatform.js index 777711791..e69de29bb 100644 --- a/src/utilities/detectCurrentPlatform.js +++ b/src/utilities/detectCurrentPlatform.js @@ -1,22 +0,0 @@ -import Platform from "../constants/Platform.js"; -/** - * - * @param {NodeJS.Process} process - * @return {Platform | undefined} - */ -const detectCurrentPlatform = (process) => { - switch (process.platform) { - case "darwin": - return process.arch === "x64" ? Platform.OSX_64 : Platform.OSX_32; - - case "win32": - return process.arch === "x64" ? Platform.WIN_64 : Platform.WIN_32; - - case "linux": - return process.arch === "x64" ? Platform.NIX_64 : Platform.NIX_32; - default: - return undefined; - } -}; - -export default detectCurrentPlatform; diff --git a/test/unit/detectCurrentPlatform.js b/test/unit/detectCurrentPlatform.js deleted file mode 100644 index 8303701da..000000000 --- a/test/unit/detectCurrentPlatform.js +++ /dev/null @@ -1,63 +0,0 @@ -import { strictEqual } from "node:assert"; -import { describe, it } from "node:test"; - -import detectCurrentPlatform from "../../src/utilities/detectCurrentPlatform.js"; -import Platform from "../../src/constants/Platform.js"; - -describe("detectCurrentPlatform", () => { - it("for OSX 32 platform", () => { - const process = { - platform: "darwin", - arch: "x32", - }; - - strictEqual(detectCurrentPlatform(process), Platform.OSX_32); - }); - - it("for OSX 64 platform", () => { - const process = { - platform: "darwin", - arch: "x64", - }; - - strictEqual(detectCurrentPlatform(process), Platform.OSX_64); - }); - - it("for Linux 32 platform", () => { - const process = { - platform: "linux", - arch: "x32", - }; - - strictEqual(detectCurrentPlatform(process), Platform.NIX_32); - }); - - it("for Linux 64 platform", () => { - const process = { - platform: "linux", - arch: "x64", - }; - - strictEqual(detectCurrentPlatform(process), Platform.NIX_64); - }); - - it("for Windows 32 platform", () => { - const process = { - platform: "win32", - arch: "x32", - }; - - strictEqual(detectCurrentPlatform(process), Platform.WIN_32); - }); - - it("for Windows 64 platform", () => { - const process = { - platform: "win32", - arch: "x64", - }; - - strictEqual(detectCurrentPlatform(process), Platform.WIN_64); - }); -}); - -export {};