From 1b8ba86edb978991b9884170e09a35c42909287d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvard=20M=C3=B8rstad?= Date: Thu, 2 Mar 2023 12:39:35 +0100 Subject: [PATCH 1/2] added support for esm-only usage --- .gitignore | 1 + api/index.d.ts | 6 ------ package.json | 22 +++++++++++----------- tsconfig.node.json => tsconfig.cjs.json | 3 +-- tsconfig.mjs.json | 11 +++++++++++ 5 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 api/index.d.ts rename tsconfig.node.json => tsconfig.cjs.json (73%) create mode 100644 tsconfig.mjs.json diff --git a/.gitignore b/.gitignore index f132de3eb..0cc3653c2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ yarn-error.log .vscode .DS_Store src/version.ts +dist diff --git a/api/index.d.ts b/api/index.d.ts deleted file mode 100644 index ade5a81b7..000000000 --- a/api/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* -allows TypeScript to see `@cucumber/cucumber/api` where it doesn't yet support -subpath exports, see - */ - -export * from '../lib/api' diff --git a/package.json b/package.json index f48c701ca..2c3c0e67a 100644 --- a/package.json +++ b/package.json @@ -179,26 +179,26 @@ "url": "https://github.com/cucumber/cucumber-js/issues" }, "directories": { - "lib": "./lib" + "lib": "./dist" }, "main": "./lib/index.js", "exports": { ".": { - "import": "./lib/wrapper.mjs", - "require": "./lib/index.js", - "types": "./lib/index.d.ts" + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js", + "types": "./dist/esm/index.d.ts" }, "./api": { - "import": "./lib/api/wrapper.mjs", - "require": "./lib/api/index.js", - "types": "./lib/api/index.d.ts" + "import": "./dist/esm/api/index.js", + "require": "./dist/cjs/api/index.js", + "types": "./dist/esm/api/index.d.ts" }, "./lib/*": { - "require": "./lib/*.js" + "require": "./dist/cjs/*.js" }, "./package.json": "./package.json" }, - "types": "./lib/index.d.ts", + "types": "./dist/esm/index.d.ts", "engines": { "node": "14 || 16 || >=18" }, @@ -308,7 +308,7 @@ "ansi-regex": "^5.0.1" }, "scripts": { - "build-local": "genversion --es6 src/version.ts && tsc --build tsconfig.node.json && shx cp src/importer.js lib/ && shx cp src/wrapper.mjs lib/ && shx cp src/api/wrapper.mjs lib/api/", + "build-local": "genversion --es6 src/version.ts && tsc --build tsconfig.cjs.json && tsc --build tsconfig.mjs.json && shx cp src/importer.js lib/ && shx cp src/wrapper.mjs lib/ && shx cp src/api/wrapper.mjs lib/api/", "cck-test": "mocha 'compatibility/**/*_spec.ts'", "docs:ci": "api-extractor run --verbose", "docs:local": "api-extractor run --verbose --local && api-documenter markdown --input-folder ./tmp/api-extractor --output-folder ./docs/api", @@ -339,6 +339,6 @@ "files": [ "api/", "bin/", - "lib/" + "dist/" ] } diff --git a/tsconfig.node.json b/tsconfig.cjs.json similarity index 73% rename from tsconfig.node.json rename to tsconfig.cjs.json index 12e7ba66d..6fb4e5b0c 100644 --- a/tsconfig.node.json +++ b/tsconfig.cjs.json @@ -1,8 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "declaration": true, - "outDir": "lib" + "outDir": "dist/cjs", }, "include": ["src/**/*.ts"], "exclude": ["**/*_spec.ts"] diff --git a/tsconfig.mjs.json b/tsconfig.mjs.json new file mode 100644 index 000000000..5377a524b --- /dev/null +++ b/tsconfig.mjs.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "dist/esm", + "module": "ESNext", + "moduleResolution": "node" + }, + "include": ["src/**/*.ts"], + "exclude": ["**/*_spec.ts"] +} From c37abb15e16b8dd6475faa77fb026817c2e85775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvard=20M=C3=B8rstad?= Date: Thu, 2 Mar 2023 15:14:25 +0100 Subject: [PATCH 2/2] Added esm runner --- bin/cucumber-js | 2 +- bin/cucumber-js-es | 5 +++++ package.json | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100755 bin/cucumber-js-es diff --git a/bin/cucumber-js b/bin/cucumber-js index 2460cb264..ec46b09af 100755 --- a/bin/cucumber-js +++ b/bin/cucumber-js @@ -1,3 +1,3 @@ #!/usr/bin/env node -require('../lib/cli/run.js').default(); +require('../dist/cjs/cli/run.js').default(); diff --git a/bin/cucumber-js-es b/bin/cucumber-js-es new file mode 100755 index 000000000..783be0931 --- /dev/null +++ b/bin/cucumber-js-es @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import run from '../dist/esm/cli/run.js' + +run() diff --git a/package.json b/package.json index 2c3c0e67a..7b0ed19de 100644 --- a/package.json +++ b/package.json @@ -181,7 +181,8 @@ "directories": { "lib": "./dist" }, - "main": "./lib/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", "exports": { ".": { "import": "./dist/esm/index.js", @@ -333,7 +334,8 @@ "update-dependencies": "npx npm-check-updates --upgrade" }, "bin": { - "cucumber-js": "bin/cucumber.js" + "cucumber-js": "bin/cucumber.js", + "cucumber-js-es": "bin/cucumber.js" }, "license": "MIT", "files": [