From 3b58f7fdb39adadd3094ab4db8f75a5de9250e22 Mon Sep 17 00:00:00 2001 From: Brynley Llewellyn-Roux Date: Fri, 11 Apr 2025 13:43:14 +1000 Subject: [PATCH 1/2] ci: trigger From 0a7b16562a126e43d870e621d2a9e2f25bdedaaf Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 11 Apr 2025 13:37:39 +1000 Subject: [PATCH 2/2] feat: migration to ESM --- .eslintrc | 18 +- .npmrc | 2 - Cargo.lock | 60 +- README.md | 2 +- jest.config.js => jest.config.mjs | 27 +- package-lock.json | 612 ++++++++++++++---- package.json | 39 +- scripts/brew-install.sh | 11 +- scripts/choco-install.ps1 | 4 +- scripts/{prebuild.js => prebuild.mjs} | 29 +- .../{prepublishOnly.js => prepublishOnly.mjs} | 22 +- scripts/test.mjs | 43 ++ scripts/{version.js => version.mjs} | 22 +- src/exec.ts | 25 +- src/index.ts | 2 +- tests/Exec.test.ts | 6 +- tests/{callExecvpe.ts => callExecvpe.mjs} | 2 +- tests/setupAfterEnv.ts | 1 + tsconfig.json | 16 +- 19 files changed, 663 insertions(+), 280 deletions(-) delete mode 100644 .npmrc rename jest.config.js => jest.config.mjs (78%) rename scripts/{prebuild.js => prebuild.mjs} (83%) rename scripts/{prepublishOnly.js => prepublishOnly.mjs} (90%) create mode 100644 scripts/test.mjs rename scripts/{version.js => version.mjs} (85%) rename tests/{callExecvpe.ts => callExecvpe.mjs} (87%) diff --git a/.eslintrc b/.eslintrc index c9869cd..05116a2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,19 +7,18 @@ "jest": true }, "parser": "@typescript-eslint/parser", - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "prettier" - ], - "plugins": [ - "import" - ], "parserOptions": { "project": "tsconfig.json", "sourceType": "module" }, + "plugins": [ + "import" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], "rules": { "linebreak-style": ["error", "unix"], "no-empty": 1, @@ -182,3 +181,4 @@ ] } } + diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 7c06da2..0000000 --- a/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -# Enables npm link -prefix=~/.npm diff --git a/Cargo.lock b/Cargo.lock index 08b0117..5ef2c38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,15 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] +version = 3 [[package]] name = "autocfg" @@ -25,18 +16,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" @@ -103,16 +85,10 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "winapi", ] -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - [[package]] name = "napi" version = "2.10.1" @@ -211,32 +187,18 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" [[package]] name = "ryu" @@ -294,12 +256,12 @@ dependencies = [ [[package]] name = "uapi" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "019450240401d342e2a5bc47f7fbaeb002a38fe18197b83788750d7ffb143274" +checksum = "3bf073840d1b16485bfe28b4e752eccee38d9ac53f152adf869708e3136561e6" dependencies = [ "cc", - "cfg-if 0.1.10", + "cfg-if", "libc", "uapi-proc", ] diff --git a/README.md b/README.md index 4d8087a..e7cc855 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ npm run prebuild # build the dist and native objects npm run build # run the repl (this allows you to import from ./src) -npm run ts-node +npm run tsx # run the tests npm run test # lint the source code diff --git a/jest.config.js b/jest.config.mjs similarity index 78% rename from jest.config.js rename to jest.config.mjs index 58d32f3..b3e3b3f 100644 --- a/jest.config.js +++ b/jest.config.mjs @@ -1,18 +1,16 @@ -const path = require('path'); -const { pathsToModuleNameMapper } = require('ts-jest'); -const { compilerOptions } = require('./tsconfig'); +import path from 'node:path'; +import url from 'node:url'; +import tsconfigJSON from './tsconfig.json' assert { type: "json" }; -const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, { - prefix: '/src/', -}); +const projectPath = path.dirname(url.fileURLToPath(import.meta.url)); // Global variables that are shared across the jest worker pool // These variables must be static and serializable const globals = { // Absolute directory to the project root - projectDir: __dirname, + projectDir: projectPath, // Absolute directory to the test root - testDir: path.join(__dirname, 'tests'), + testDir: path.join(projectPath, 'tests'), // Default asynchronous test timeout defaultTimeout: 20000, // Timeouts rely on setTimeout which takes 32 bit numbers @@ -24,7 +22,7 @@ const globals = { // They can however receive the process environment // Use `process.env` to set variables -module.exports = { +const config = { testEnvironment: 'node', verbose: true, collectCoverage: false, @@ -40,10 +38,10 @@ module.exports = { parser: { syntax: "typescript", tsx: true, - decorators: compilerOptions.experimentalDecorators, + decorators: tsconfigJSON.compilerOptions.experimentalDecorators, dynamicImport: true, }, - target: compilerOptions.target.toLowerCase(), + target: tsconfigJSON.compilerOptions.target.toLowerCase(), keepClassNames: true, }, } @@ -77,5 +75,10 @@ module.exports = { 'jest-extended/all', '/tests/setupAfterEnv.ts' ], - moduleNameMapper: moduleNameMapper, + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, + extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'], }; + +export default config; diff --git a/package-lock.json b/package-lock.json index 16a3549..7b8a5e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.1.5", "license": "Apache-2.0", "devDependencies": { - "@fast-check/jest": "^1.1.0", "@napi-rs/cli": "^2.15.2", "@swc/core": "1.3.82", "@swc/jest": "^0.2.29", @@ -17,12 +16,10 @@ "@types/node": "^20.5.7", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.61.0", - "common-tags": "^1.8.2", "eslint": "^8.44.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-prettier": "^5.0.0-alpha.2", - "fast-check": "^3.0.1", "jest": "^29.6.2", "jest-extended": "^4.0.0", "jest-junit": "^16.0.0", @@ -30,9 +27,7 @@ "semver": "^7.3.7", "shx": "^0.3.4", "systeminformation": "^5.18.5", - "ts-jest": "^29.1.1", - "ts-node": "^10.9.1", - "tsconfig-paths": "^3.9.0", + "tsx": "^3.12.7", "typedoc": "^0.24.8", "typescript": "^5.1.6" }, @@ -719,6 +714,8 @@ "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, + "optional": true, + "peer": true, "dependencies": { "@jridgewell/trace-mapping": "0.3.9" }, @@ -731,11 +728,365 @@ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", "dev": true, + "optional": true, + "peer": true, "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@esbuild/android-arm": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", + "integrity": "sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz", + "integrity": "sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.20.tgz", + "integrity": "sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz", + "integrity": "sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz", + "integrity": "sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz", + "integrity": "sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz", + "integrity": "sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz", + "integrity": "sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz", + "integrity": "sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz", + "integrity": "sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz", + "integrity": "sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz", + "integrity": "sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz", + "integrity": "sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz", + "integrity": "sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz", + "integrity": "sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz", + "integrity": "sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz", + "integrity": "sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz", + "integrity": "sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz", + "integrity": "sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz", + "integrity": "sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz", + "integrity": "sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz", + "integrity": "sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -792,38 +1143,6 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, - "node_modules/@fast-check/jest": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/@fast-check/jest/-/jest-1.7.1.tgz", - "integrity": "sha512-5qY1+rVK4S7aN4gYligDzeofuz1CFLgTl8r3PM3YqZ1JHtJIiPpYVYUJuWZHo6pRg1pd2g6x1PQ4uDYSuuuD7Q==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/dubzzz" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/fast-check" - } - ], - "dependencies": { - "fast-check": "^3.0.0" - }, - "peerDependencies": { - "@fast-check/worker": "~0.0.7", - "@jest/expect": ">=28.0.0", - "@jest/globals": ">=25.5.2" - }, - "peerDependenciesMeta": { - "@fast-check/worker": { - "optional": true - }, - "@jest/expect": { - "optional": true - } - } - }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", @@ -1668,25 +1987,33 @@ "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/@tsconfig/node12": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/@tsconfig/node14": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/@tsconfig/node16": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/@types/babel__core": { "version": "7.20.1", @@ -2031,6 +2358,8 @@ "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true, + "optional": true, + "peer": true, "engines": { "node": ">=0.4.0" } @@ -2125,7 +2454,9 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/argparse": { "version": "2.0.1", @@ -2433,18 +2764,6 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, - "node_modules/bs-logger": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", - "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", - "dev": true, - "dependencies": { - "fast-json-stable-stringify": "2.x" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -2637,15 +2956,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/common-tags": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz", - "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==", - "dev": true, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2662,7 +2972,9 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -2910,6 +3222,8 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true, + "optional": true, + "peer": true, "engines": { "node": ">=0.3.1" } @@ -3073,6 +3387,43 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/esbuild": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz", + "integrity": "sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.18.20", + "@esbuild/android-arm64": "0.18.20", + "@esbuild/android-x64": "0.18.20", + "@esbuild/darwin-arm64": "0.18.20", + "@esbuild/darwin-x64": "0.18.20", + "@esbuild/freebsd-arm64": "0.18.20", + "@esbuild/freebsd-x64": "0.18.20", + "@esbuild/linux-arm": "0.18.20", + "@esbuild/linux-arm64": "0.18.20", + "@esbuild/linux-ia32": "0.18.20", + "@esbuild/linux-loong64": "0.18.20", + "@esbuild/linux-mips64el": "0.18.20", + "@esbuild/linux-ppc64": "0.18.20", + "@esbuild/linux-riscv64": "0.18.20", + "@esbuild/linux-s390x": "0.18.20", + "@esbuild/linux-x64": "0.18.20", + "@esbuild/netbsd-x64": "0.18.20", + "@esbuild/openbsd-x64": "0.18.20", + "@esbuild/sunos-x64": "0.18.20", + "@esbuild/win32-arm64": "0.18.20", + "@esbuild/win32-ia32": "0.18.20", + "@esbuild/win32-x64": "0.18.20" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -3485,28 +3836,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/fast-check": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.12.0.tgz", - "integrity": "sha512-SqahE9mlL3+lhjJ39joMLwcj6F+24hfZdf/tchlNO8sHcTdrUUdA5P/ZbSFZM9Xpzs36XaneGwE0FWepm/zyOA==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/dubzzz" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/fast-check" - } - ], - "dependencies": { - "pure-rand": "^6.0.0" - }, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -3768,6 +4097,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.0.tgz", + "integrity": "sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -5178,12 +5519,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash.memoize": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", - "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", - "dev": true - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -5224,7 +5559,9 @@ "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/makeerror": { "version": "1.0.12", @@ -5931,6 +6268,15 @@ "node": ">=4" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/resolve.exports": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.2.tgz", @@ -6454,54 +6800,13 @@ "node": ">=8.0" } }, - "node_modules/ts-jest": { - "version": "29.1.1", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", - "integrity": "sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==", - "dev": true, - "dependencies": { - "bs-logger": "0.x", - "fast-json-stable-stringify": "2.x", - "jest-util": "^29.0.0", - "json5": "^2.2.3", - "lodash.memoize": "4.x", - "make-error": "1.x", - "semver": "^7.5.3", - "yargs-parser": "^21.0.1" - }, - "bin": { - "ts-jest": "cli.js" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - }, - "peerDependencies": { - "@babel/core": ">=7.0.0-beta.0 <8", - "@jest/types": "^29.0.0", - "babel-jest": "^29.0.0", - "jest": "^29.0.0", - "typescript": ">=4.3 <6" - }, - "peerDependenciesMeta": { - "@babel/core": { - "optional": true - }, - "@jest/types": { - "optional": true - }, - "babel-jest": { - "optional": true - }, - "esbuild": { - "optional": true - } - } - }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", "dev": true, + "optional": true, + "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -6600,6 +6905,33 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, + "node_modules/tsx": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-3.14.0.tgz", + "integrity": "sha512-xHtFaKtHxM9LOklMmJdI3BEnQq/D5F73Of2E1GDrITi9sgoVkvIsrQUTY1G8FlmGtA+awCI4EBlTRRYxkL2sRg==", + "dev": true, + "dependencies": { + "esbuild": "~0.18.20", + "get-tsconfig": "^4.7.2", + "source-map-support": "^0.5.21" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/tsx/node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -6832,7 +7164,9 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/v8-to-istanbul": { "version": "9.1.0", @@ -6991,6 +7325,8 @@ "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true, + "optional": true, + "peer": true, "engines": { "node": ">=6" } diff --git a/package.json b/package.json index e3b50eb..1e7f526 100644 --- a/package.json +++ b/package.json @@ -13,21 +13,35 @@ "type": "git", "url": "https://github.com/MatrixAI/js-exec.git" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "type": "module", + "exports": { + "./package.json": "./package.json", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + }, + "./*.js": { + "types": "./dist/*.d.ts", + "import": "./dist/*.js" + }, + "./*": "./dist/*" + }, + "imports": { + "#*": "./dist/*" + }, "napi": { "name": "exec" }, "scripts": { "prepare": "tsc -p ./tsconfig.build.json", - "prebuild": "node ./scripts/prebuild.js", + "prebuild": "node ./scripts/prebuild.mjs", "build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json", - "version": "node ./scripts/version.js", - "prepublishOnly": "node ./scripts/prepublishOnly.js", - "ts-node": "ts-node", - "test": "jest", - "lint": "eslint '{src,tests,scripts}/**/*.{js,ts,json}'", - "lintfix": "eslint '{src,tests,scripts}/**/*.{js,ts,json}' --fix", + "version": "node ./scripts/version.mjs", + "prepublishOnly": "node ./scripts/prepublishOnly.mjs", + "tsx": "tsx", + "test": "node ./scripts/test.mjs", + "lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}'", + "lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}' --fix", "lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +", "docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src" }, @@ -38,7 +52,6 @@ "@matrixai/exec-linux-x64": "0.1.5" }, "devDependencies": { - "@fast-check/jest": "^1.1.0", "@napi-rs/cli": "^2.15.2", "@swc/core": "1.3.82", "@swc/jest": "^0.2.29", @@ -46,12 +59,10 @@ "@types/node": "^20.5.7", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.61.0", - "common-tags": "^1.8.2", "eslint": "^8.44.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-prettier": "^5.0.0-alpha.2", - "fast-check": "^3.0.1", "jest": "^29.6.2", "jest-extended": "^4.0.0", "jest-junit": "^16.0.0", @@ -59,9 +70,7 @@ "semver": "^7.3.7", "shx": "^0.3.4", "systeminformation": "^5.18.5", - "ts-jest": "^29.1.1", - "ts-node": "^10.9.1", - "tsconfig-paths": "^3.9.0", + "tsx": "^3.12.7", "typedoc": "^0.24.8", "typescript": "^5.1.6" } diff --git a/scripts/brew-install.sh b/scripts/brew-install.sh index 0f54b7e..7341272 100755 --- a/scripts/brew-install.sh +++ b/scripts/brew-install.sh @@ -20,7 +20,10 @@ brew link --overwrite rustup-init # Brew does not provide specific versions of rust # However rustup provides specific versions # Here we provide both toolchains -rustup-init \ - --default-toolchain 1.83.0 \ - --target x86_64-apple-darwin aarch64-apple-darwin \ - -y +echo "Running rustup-init" +rustup-init --default-toolchain 1.68.2 -y +echo "Adding x86_64-apple-darwin as target" +rustup target add x86_64-apple-darwin +echo "Adding aarch64-apple-darwin as target" +rustup target add aarch64-apple-darwin +echo "Completed brew setup" diff --git a/scripts/choco-install.ps1 b/scripts/choco-install.ps1 index e150119..b0fd8a4 100755 --- a/scripts/choco-install.ps1 +++ b/scripts/choco-install.ps1 @@ -31,9 +31,9 @@ if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$nodejs\$nodejs.20 # Install rust v1.68.0 (will use cache if exists) $rust = "rust-ms" -choco install "$rust" --version="1.83.0" --require-checksums -y --no-progress +choco install "$rust" --version="1.68.0" --require-checksums -y --no-progress # Internalise rust to cache if doesn't exist -if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$rust\$rust.1.83.0.nupkg" -PathType Leaf) ) { +if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$rust\$rust.1.68.0.nupkg" -PathType Leaf) ) { Save-ChocoPackage -PackageName $rust } diff --git a/scripts/prebuild.js b/scripts/prebuild.mjs similarity index 83% rename from scripts/prebuild.js rename to scripts/prebuild.mjs index 9886492..b1be2f5 100755 --- a/scripts/prebuild.js +++ b/scripts/prebuild.mjs @@ -1,14 +1,19 @@ #!/usr/bin/env node -const os = require('os'); -const fs = require('fs'); -const path = require('path'); -const process = require('process'); -const childProcess = require('child_process'); -const packageJSON = require('../package.json'); +import os from 'node:os'; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; +import childProcess from 'node:child_process'; +import url from 'node:url'; +import packageJSON from '../package.json' assert { type: 'json' }; const platform = os.platform(); +const projectPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); + /* eslint-disable no-console */ async function main(argv = process.argv) { argv = argv.slice(2); @@ -73,12 +78,11 @@ async function main(argv = process.argv) { const target = [targetArch, targetVendor, targetSystem, targetABI] .filter((s) => s != null) .join('-'); - const projectRoot = path.join(__dirname, '..'); - const prebuildPath = path.join(projectRoot, 'prebuild'); + const prebuildPath = path.join(projectPath, 'prebuild'); await fs.promises.mkdir(prebuildPath, { recursive: true, }); - const cargoTOMLPath = path.join(projectRoot, 'Cargo.toml'); + const cargoTOMLPath = path.join(projectPath, 'Cargo.toml'); const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8'); const cargoTOMLVersion = cargoTOML.match(/version\s*=\s*"(.*)"/)?.[1]; if (packageJSON.version !== cargoTOMLVersion) { @@ -120,4 +124,9 @@ async function main(argv = process.argv) { } /* eslint-enable no-console */ -void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } +} diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.mjs similarity index 90% rename from scripts/prepublishOnly.js rename to scripts/prepublishOnly.mjs index 9bb6545..6bea4fa 100755 --- a/scripts/prepublishOnly.js +++ b/scripts/prepublishOnly.mjs @@ -15,15 +15,20 @@ * /README.md */ -const os = require('os'); -const fs = require('fs'); -const path = require('path'); -const process = require('process'); -const childProcess = require('child_process'); -const packageJSON = require('../package.json'); +import os from 'node:os'; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; +import childProcess from 'node:child_process'; +import url from 'node:url'; +import packageJSON from '../package.json' assert { type: 'json' }; const platform = os.platform(); +const projectPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); + /* eslint-disable no-console */ async function main(argv = process.argv) { argv = argv.slice(2); @@ -44,9 +49,8 @@ async function main(argv = process.argv) { if (tag == null) { tag = process.env.npm_config_tag; } - const projectRoot = path.join(__dirname, '..'); - const prebuildPath = path.join(projectRoot, 'prebuild'); - const prepublishOnlyPath = path.join(projectRoot, 'prepublishOnly'); + const prebuildPath = path.join(projectPath, 'prebuild'); + const prepublishOnlyPath = path.join(projectPath, 'prepublishOnly'); const buildNames = (await fs.promises.readdir(prebuildPath)).filter( (filename) => /^(?:[^-]+)-(?:[^-]+)-(?:[^-]+)$/.test(filename), ); diff --git a/scripts/test.mjs b/scripts/test.mjs new file mode 100644 index 0000000..f664b50 --- /dev/null +++ b/scripts/test.mjs @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +import os from 'node:os'; +import url from 'node:url'; +import process from 'node:process'; +import childProcess from 'node:child_process'; + +const platform = os.platform(); + +/* eslint-disable no-console */ +async function main(argv = process.argv) { + argv = argv.slice(2); + const npmArgs = [`run`, 'build']; + console.error('Running build:'); + console.error(['npm', ...npmArgs].join(' ')); + childProcess.execFileSync('npm', npmArgs, { + stdio: ['inherit', 'inherit', 'inherit'], + windowsHide: true, + encoding: 'utf-8', + shell: platform === 'win32' ? true : false, + }); + const jestArgs = [...argv]; + console.error('Running jest:'); + console.error(['jest', ...jestArgs].join(' ')); + childProcess.execFileSync('jest', jestArgs, { + env: { + ...process.env, + NODE_OPTIONS: '--experimental-vm-modules', + }, + stdio: ['inherit', 'inherit', 'inherit'], + windowsHide: true, + encoding: 'utf-8', + shell: platform === 'win32' ? true : false, + }); +} +/* eslint-enable no-console */ + +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } +} diff --git a/scripts/version.js b/scripts/version.mjs similarity index 85% rename from scripts/version.js rename to scripts/version.mjs index 853fe74..b1d26d1 100755 --- a/scripts/version.js +++ b/scripts/version.mjs @@ -13,19 +13,23 @@ * to prevent `npm` from attempting to download unpublished packages. */ -const path = require('path'); -const fs = require('fs'); -const os = require('os'); -const childProcess = require('child_process'); -const packageJSON = require('../package.json'); +import path from 'node:path'; +import fs from 'node:fs'; +import os from 'node:os'; +import url from 'node:url'; +import childProcess from 'node:child_process'; +import packageJSON from '../package.json' assert { type: 'json' }; const platform = os.platform(); +const projectPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); + /* eslint-disable no-console */ async function main() { - const projectRoot = path.join(__dirname, '..'); - const cargoTOMLPath = path.join(projectRoot, 'Cargo.toml'); - const cargoLockPath = path.join(projectRoot, 'Cargo.lock'); + const cargoTOMLPath = path.join(projectPath, 'Cargo.toml'); + const cargoLockPath = path.join(projectPath, 'Cargo.lock'); console.error('Updating the Cargo.toml version to match new version'); const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8'); @@ -37,7 +41,7 @@ async function main() { await fs.promises.writeFile(cargoTOMLPath, cargoTOMLUpdated, 'utf-8'); console.error('Updating the Cargo.lock version to match new version'); - childProcess.execFileSync('cargo', ['update', '--package', 'exec'], { + childProcess.execFileSync('cargo', ['update', '--package', 'quic'], { stdio: ['inherit', 'inherit', 'inherit'], windowsHide: true, encoding: 'utf-8', diff --git a/src/exec.ts b/src/exec.ts index 5302443..d800205 100644 --- a/src/exec.ts +++ b/src/exec.ts @@ -3,8 +3,16 @@ * This code was derived from the auto-generated binding and declaration * files provided by napi-rs. */ -import process from 'process'; -import path from 'path'; +import process from 'node:process'; +import path from 'node:path'; +import url from 'node:url'; +import Module from 'node:module'; + +const require = Module.createRequire(import.meta.url); +const projectPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); +const prebuildPath = path.join(projectPath, 'prebuild'); interface Exec { /** @@ -25,9 +33,6 @@ interface Exec { execvp(cmd: string, argv: Array, envp: Record): never; } -const projectRoot = path.join(__dirname, '../'); -const prebuildPath = path.join(projectRoot, 'prebuild'); - /** * Try require on all prebuild targets first, then * try require on all npm targets second. @@ -42,6 +47,11 @@ function requireBinding(targets: Array): Exec { } catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e; } + try { + return require(url.pathToFileURL(prebuildTarget).href); + } catch (e) { + if (e.code !== 'MODULE_NOT_FOUND') throw e; + } } const npmTargets = targets.map((target) => `@matrixai/exec-${target}`); for (const npmTarget of npmTargets) { @@ -50,6 +60,11 @@ function requireBinding(targets: Array): Exec { } catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e; } + try { + return require(url.pathToFileURL(npmTarget).href); + } catch (e) { + if (e.code !== 'MODULE_NOT_FOUND') throw e; + } } throw new Error( `Failed requiring possible native bindings: ${prebuildTargets.concat( diff --git a/src/index.ts b/src/index.ts index 24d8440..3967133 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export { default as exec } from './exec'; +export { default as exec } from './exec.js'; diff --git a/tests/Exec.test.ts b/tests/Exec.test.ts index fd3c253..74ace74 100644 --- a/tests/Exec.test.ts +++ b/tests/Exec.test.ts @@ -1,10 +1,10 @@ -import child_process from 'child_process'; -import { exec } from '@'; +import child_process from 'node:child_process'; +import { exec } from '#index.js'; describe('execvp', () => { test('execvp should provide environment variables', async () => { // Setting envs to check - const output = child_process.execFileSync('./tests/callExecvpe.ts'); + const output = child_process.execFileSync('./tests/callExecvpe.mjs'); const jsonOut = JSON.parse(output.toString()); expect(jsonOut['TEST1']).toBe('value1'); expect(jsonOut['TEST2']).toBe('value2'); diff --git a/tests/callExecvpe.ts b/tests/callExecvpe.mjs similarity index 87% rename from tests/callExecvpe.ts rename to tests/callExecvpe.mjs index c5fda55..3ea0ca3 100755 --- a/tests/callExecvpe.ts +++ b/tests/callExecvpe.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env ts-node -import { exec } from '@'; +import { exec } from '#index.js'; // This executes `printEnv.js` while setting environment variables // eslint-disable-next-line no-console console.log( diff --git a/tests/setupAfterEnv.ts b/tests/setupAfterEnv.ts index 8ea8279..dcbfa6c 100644 --- a/tests/setupAfterEnv.ts +++ b/tests/setupAfterEnv.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; // Default timeout per test // some tests may take longer in which case you should specify the timeout // explicitly for each test by using the third parameter of test function diff --git a/tsconfig.json b/tsconfig.json index a120436..72708d8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,14 +12,15 @@ "esModuleInterop": true, "allowSyntheticDefaultImports": true, "resolveJsonModule": true, - "moduleResolution": "node", - "module": "CommonJS", + "isolatedModules": true, + "moduleResolution": "NodeNext", + "module": "ESNext", "target": "ES2022", "baseUrl": "./src", "paths": { - "@": ["index"], - "@/*": ["*"] + "#*": ["*"] }, + "skipLibCheck": true, "noEmit": true }, "include": [ @@ -28,10 +29,5 @@ "./tests/**/*", "./scripts/**/*", "./benches/**/*" - ], - "ts-node": { - "require": ["tsconfig-paths/register"], - "transpileOnly": true, - "swc": true - } + ] }