Skip to content

Commit d90af45

Browse files
author
Benjamin E. Coe
authored
feat!: yargs is now ESM first
BREAKING CHANGE: command names are not derived from modules passed to `command`. BREAKING CHANGE: Supported Node.js versions are now ^20.19.0 || ^22.12.0 || >=23. BREAKING CHANGE: singleton usage of yargs yargs.foo, yargs().argv, has been removed.
1 parent ef28c98 commit d90af45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2719
-2901
lines changed

.eslintrc.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66
"rules": {
77
"@typescript-eslint/no-var-requires": "off",
88
"@typescript-eslint/no-unused-vars": "off",
9-
"@typescript-eslint/no-explicit-any": "off"
9+
"@typescript-eslint/no-explicit-any": "off",
10+
"@typescript-eslint/no-unsafe-function-type": "off",
11+
"@typescript-eslint/no-empty-object-type": "off"
1012
}
1113
}
12-
]
14+
],
15+
"parser": "@babel/eslint-parser",
16+
"parserOptions": {
17+
"requireConfigFile": false,
18+
"babelOptions": {
19+
"babelrc": false,
20+
"configFile": false,
21+
"presets": ["@babel/preset-typescript"]
22+
}
23+
}
1324
}

.github/workflows/ci.yaml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
node: [16, 18, 20]
16+
node: [20, 22, 23]
1717
steps:
1818
- uses: actions/checkout@v1
1919
- uses: actions/setup-node@v1
@@ -29,31 +29,17 @@ jobs:
2929
- uses: actions/checkout@v2
3030
- uses: actions/setup-node@v1
3131
with:
32-
node-version: 20
32+
node-version: 23
3333
- run: npm install -g npm@8
3434
- run: npm install
3535
- run: npm test
36-
esm:
37-
runs-on: ubuntu-latest
38-
strategy:
39-
matrix:
40-
node: [20]
41-
steps:
42-
- uses: actions/checkout@v1
43-
- uses: actions/setup-node@v1
44-
with:
45-
node-version: ${{ matrix.node }}
46-
- run: npm install -g npm@8
47-
- run: node --version
48-
- run: npm install --engine-strict
49-
- run: npm run test:esm
5036
deno:
5137
runs-on: ubuntu-latest
5238
steps:
5339
- uses: actions/checkout@v2
5440
- uses: actions/setup-node@v1
5541
with:
56-
node-version: 20
42+
node-version: 22
5743
- run: npm install -g npm@8
5844
- run: npm install
5945
- run: npm run compile
@@ -69,7 +55,7 @@ jobs:
6955
- uses: actions/checkout@v1
7056
- uses: actions/setup-node@v1
7157
with:
72-
node-version: 20
58+
node-version: 22
7359
- run: npm install -g npm@8
7460
- run: npm install
7561
- run: npm test

.github/workflows/release-please.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v2
2121
- uses: actions/setup-node@v1
2222
with:
23-
node-version: 20
23+
node-version: 22
2424
- run: npm install npm@latest -g
2525
- run: npm install
2626
- run: npm run compile
@@ -38,7 +38,7 @@ jobs:
3838
if: ${{ steps.release.outputs.release_created }}
3939
- uses: actions/setup-node@v1
4040
with:
41-
node-version: 14
41+
node-version: 22
4242
registry-url: 'https://external-dot-oss-automation.appspot.com/'
4343
if: ${{ steps.release.outputs.release_created }}
4444
- run: npm install

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ package-lock.json
99
example.*
1010
.DS_Store
1111
.npmrc
12+
test-docs.cjs
13+
test-docs.mjs

.nycrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"html",
99
"text"
1010
],
11-
"lines": 99,
11+
"lines": 100,
1212
"branches": "96",
1313
"statements": "100"
1414
}

CHANGELOG.md

Lines changed: 1525 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ npm i yargs@next
5959

6060
```javascript
6161
#!/usr/bin/env node
62-
const yargs = require('yargs/yargs')
63-
const { hideBin } = require('yargs/helpers')
62+
import yargs from 'yargs';
63+
import { hideBin } from 'yargs/helpers';
6464
const argv = yargs(hideBin(process.argv)).parse()
6565

6666
if (argv.ships > 3 && argv.distance < 53.5) {
@@ -84,8 +84,8 @@ Retreat from the xupptumblers!
8484

8585
```javascript
8686
#!/usr/bin/env node
87-
const yargs = require('yargs/yargs')
88-
const { hideBin } = require('yargs/helpers')
87+
import yargs from 'yargs';
88+
import { hideBin } from 'yargs/helpers';
8989

9090
yargs(hideBin(process.argv))
9191
.command('serve [port]', 'start the server', (yargs) => {
@@ -143,22 +143,6 @@ yargs(Deno.args)
143143

144144
> Note: If you use version tags in url then you also have to add `-deno` flag on the end, like `@17.7.2-deno`
145145
146-
### ESM
147-
148-
As of `v16`,`yargs` supports ESM imports:
149-
150-
```js
151-
import yargs from 'yargs'
152-
import { hideBin } from 'yargs/helpers'
153-
154-
yargs(hideBin(process.argv))
155-
.command('curl <url>', 'fetch the contents of the URL', () => {}, (argv) => {
156-
console.info(argv)
157-
})
158-
.demandCommand(1)
159-
.parse()
160-
```
161-
162146
### Usage in Browser
163147

164148
See examples of using yargs in the browser in [docs](/docs/browser.md).
@@ -184,7 +168,6 @@ Having problems? want to contribute? join our [community slack](http://devtoolsc
184168
* [Composing Your App Using Commands](/docs/advanced.md#commands)
185169
* [Building Configurable CLI Apps](/docs/advanced.md#configuration)
186170
* [Customizing Yargs' Parser](/docs/advanced.md#customizing)
187-
* [Bundling yargs](/docs/bundling.md)
188171
* [Contributing](/contributing.md)
189172

190173
## Supported Node.js Versions

docs/CHANGELOG-historical.md

Lines changed: 0 additions & 1525 deletions
This file was deleted.

0 commit comments

Comments
 (0)