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

Conditional exports to simplify ECMAScript import #1589

Merged
merged 3 commits into from Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions Readme.md
Expand Up @@ -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();
```
Expand Down Expand Up @@ -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.

Expand Down
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -63,7 +70,7 @@
]
},
"engines": {
"node": ">= 12"
"node": "^12.20.0 || >=14"
},
"support": true
}