Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert esm code to cjs #1047

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: v3-cd
name: cd
on:
push:
branches:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: v3-ci
name: ci
on:
pull_request:
branches:
Expand All @@ -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:
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions cfg/eslint.config.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion lib/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions lib/util/detectCurrentPlatform.cjs
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 17 in lib/util/detectCurrentPlatform.cjs

View workflow job for this annotation

GitHub Actions / e2e (macos-13, 21)

The type 'NodeJS' is undefined

Check warning on line 17 in lib/util/detectCurrentPlatform.cjs

View workflow job for this annotation

GitHub Actions / e2e (ubuntu-22.04, 21)

The type 'NodeJS' is undefined
* @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;
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"bin": {
"nwbuild": "./lib/cli.cjs"
},
"type": "module",
"files": [
"bin",
"lib",
Expand All @@ -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"
Expand Down Expand Up @@ -78,5 +76,22 @@
"winston": "^3.11.0",
"yargs": "^17.7.2"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 2023,
"sourceType": "commonjs"
},
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"tjw-jsdoc"
],
"rules": {
"jsdoc/require-file-overview": "off"
}
}
}
16 changes: 0 additions & 16 deletions src/constants/Platform.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -10,9 +8,7 @@ import { isCached, parse, getReleaseInfo, validate } from "./util.js";

export {
Options,
Platform,
Platforms,
detectCurrentPlatform,
get,
getReleaseInfo,
isCached,
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down
22 changes: 0 additions & 22 deletions src/utilities/detectCurrentPlatform.js
Original file line number Diff line number Diff line change
@@ -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;
63 changes: 0 additions & 63 deletions test/unit/detectCurrentPlatform.js

This file was deleted.

Loading