diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 79750cf2ba..e5fb76329c 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -718,6 +718,12 @@ module.exports = { 'import/no-commonjs': 'off', }, }, + { + files: 'resources/with-ts-node-esm.js', + parserOptions: { + sourceType: 'module', + }, + }, { files: '**/*.jsx', parserOptions: { diff --git a/.mocharc.yml b/.mocharc.yml index 923173c1c4..1a8c7a3aee 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -4,4 +4,4 @@ check-leaks: true extension: - ts node-option: - - 'loader=ts-node/esm/transpile-only' + - 'import=./resources/with-ts-node-esm.js' diff --git a/package.json b/package.json index 7399802238..6074610732 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,10 @@ }, "scripts": { "preversion": "bash -c '. ./resources/checkgit.sh && npm ci --ignore-scripts'", - "version": "node --loader ts-node/esm resources/gen-version.ts && npm test && git add src/version.ts", + "version": "node --import ./resources/with-ts-node-esm.js resources/gen-version.ts && npm test && git add src/version.ts", "fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts", - "changelog": "node --loader ts-node/esm resources/gen-changelog.ts", - "benchmark": "node --loader ts-node/esm resources/benchmark.ts", + "changelog": "node --import ./resources/with-ts-node-esm.js resources/gen-changelog.ts", + "benchmark": "node --import ./resources/with-ts-node-esm.js resources/benchmark.ts", "test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations", "lint": "eslint --cache --max-warnings 0 --rulesdir resources/eslint-internal-rules/ .", "check": "tsc --pretty", @@ -47,10 +47,10 @@ "check:integrations": "mocha --full-trace resources/integration-test.ts", "serve": "docusaurus serve --dir websiteDist/ --config website/docusaurus.config.cjs", "start": "npm run build:website && npm run serve", - "build:website": "node --loader ts-node/esm resources/build-docusaurus.ts", - "build:npm": "node --loader ts-node/esm resources/build-npm.ts", - "build:deno": "node --loader ts-node/esm resources/build-deno.ts", - "diff:npm": "node --loader ts-node/esm resources/diff-npm-package.ts", + "build:website": "node --import ./resources/with-ts-node-esm.js resources/build-docusaurus.ts", + "build:npm": "node --import ./resources/with-ts-node-esm.js resources/build-npm.ts", + "build:deno": "node --import ./resources/with-ts-node-esm.js resources/build-deno.ts", + "diff:npm": "node --import ./resources/with-ts-node-esm.js resources/diff-npm-package.ts", "gitpublish:npm": "bash ./resources/gitpublish.sh npm npmDist", "gitpublish:deno": "bash ./resources/gitpublish.sh deno denoDist", "prepare": "husky" diff --git a/resources/with-ts-node-esm.js b/resources/with-ts-node-esm.js new file mode 100644 index 0000000000..7eea215607 --- /dev/null +++ b/resources/with-ts-node-esm.js @@ -0,0 +1,5 @@ +// eslint-disable-next-line n/no-unsupported-features/node-builtins +import { register } from 'node:module'; +import { pathToFileURL } from 'node:url'; + +register('ts-node/esm/transpile-only', pathToFileURL('./'));