From ce78e616096f90f08bc3ca22990f52324743ccb5 Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 24 Aug 2021 18:53:50 +1200 Subject: [PATCH 1/3] FIrst try at exports in package.json --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 737c757aa..43c8d947c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit", "test-all": "npm run test && npm run lint && npm run typescript-lint && npm run typescript-checkJS && npm run test-esm" }, - "main": "./index.js", "files": [ "index.js", "lib/*.js", @@ -36,6 +35,14 @@ "package-support.json" ], "type": "commonjs", + "main": "./index.js", + "exports": { + ".": { + "require": "./index.js", + "import": "./esm.mjs" + }, + "./esm.mjs": "./esm.mjs" + }, "dependencies": {}, "devDependencies": { "@types/jest": "^26.0.23", From 0fd4fbcda2dfd83a9adad42ec8c90a49f436ee94 Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 24 Aug 2021 21:02:26 +1200 Subject: [PATCH 2/3] Set required version for conditional export in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43c8d947c..51c805be5 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ ] }, "engines": { - "node": ">= 12" + "node": "^12.20.0 || >=14" }, "support": true } From 0fc29d5087c3aa264ef732e40b0ad9da3380897b Mon Sep 17 00:00:00 2001 From: John Gee Date: Wed, 25 Aug 2021 18:57:00 +1200 Subject: [PATCH 3/3] Update README with export support --- Readme.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index 4cc640b94..95d8c7839 100644 --- a/Readme.md +++ b/Readme.md @@ -65,30 +65,26 @@ Commander exports a global object which is convenient for quick programs. This is used in the examples in this README for brevity. ```js +// CommonJS (.cjs) const { program } = require('commander'); -program.version('0.0.1'); ``` For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use. ```js +// CommonJS (.cjs) const { Command } = require('commander'); const program = new Command(); -program.version('0.0.1'); ``` -For named imports in ECMAScript modules, import from `commander/esm.mjs`. - ```js -// index.mjs -import { Command } from 'commander/esm.mjs'; +// ECMAScript (.mjs) +import { Command } from 'commander'; const program = new Command(); ``` -And in TypeScript: - ```ts -// index.ts +// TypeScript (.ts) import { Command } from 'commander'; const program = new Command(); ``` @@ -994,8 +990,8 @@ More samples can be found in the [examples](https://github.com/tj/commander.js/t ## Support -The current version of Commander is fully supported on Long Term Support versions of node, and requires at least node v12. -(For older versions of node, use an older version of Commander. Commander version 2.x has the widest support.) +The current version of Commander is fully supported on Long Term Support versions of Node.js, and requires at least v12.20.0. +(For older versions of Node.js, use an older version of Commander. Commander version 2.x has the widest support.) The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.