Skip to content

Commit

Permalink
Require Node.js 14 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 6, 2022
1 parent 73d003e commit 60d5b9a
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
10 changes: 3 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
- 6
- 4
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
25 changes: 15 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const filterObj = require('filter-obj');
const packageJson = require('package-json');
import process from 'node:process';
import meow from 'meow';
import filterObject from 'filter-obj';
import packageJson from 'package-json';

const cli = meow(`
Usage
Expand All @@ -13,15 +13,20 @@ const cli = meow(`
{
"name": "ava",
"version": "0.18.0",
...
}
`);
`, {
importMeta: import.meta,
});

if (!cli.input[0]) {
const [packageName, version] = cli.input;

if (!packageName) {
console.error('Specify a package name');
process.exit(1);
}

packageJson(cli.input[0], {version: cli.input[1]})
.then(pkg => filterObj(pkg, key => key[0] !== '_' && key !== 'directories'))
.then(x => console.log(JSON.stringify(x, null, ' ')));
let package_ = await packageJson(packageName, {version});
package_ = filterObject(package_, key => key[0] !== '_' && key !== 'directories');

console.log(JSON.stringify(package_, undefined, ' '));
22 changes: 5 additions & 17 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
92 changes: 47 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
{
"name": "package-json-cli",
"version": "2.0.0",
"description": "Get the package.json of a package from the npm registry",
"license": "MIT",
"repository": "sindresorhus/package-json-cli",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bin": {
"package-json": "cli.js"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"npm",
"registry",
"package",
"pkg",
"package.json",
"json",
"module",
"scope",
"scoped"
],
"dependencies": {
"filter-obj": "^1.1.0",
"meow": "^3.7.0",
"package-json": "^4.0.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.6.0",
"xo": "*"
}
"name": "package-json-cli",
"version": "2.0.0",
"description": "Get the package.json of a package from the npm registry",
"license": "MIT",
"repository": "sindresorhus/package-json-cli",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"bin": {
"package-json": "cli.js"
},
"engines": {
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"npm",
"registry",
"package",
"pkg",
"package.json",
"json",
"module",
"scope",
"scoped"
],
"dependencies": {
"filter-obj": "^3.0.0",
"meow": "^10.1.2",
"package-json": "^8.0.0"
},
"devDependencies": {
"ava": "^4.3.0",
"execa": "^6.1.0",
"xo": "^0.49.0"
}
}
14 changes: 3 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

> Get the package.json of a package from the npm registry

## Install

```
$ npm install --global package-json-cli
```sh
npm install --global package-json-cli
```


## Usage

```
Expand All @@ -23,7 +21,7 @@ $ package-json --help
{
"name": "ava",
"version": "0.18.0"
...
}
```

Expand All @@ -33,13 +31,7 @@ The `version` can be in any format supported by the [semver](https://github.com/
- `1.2` - get the latest `1.2.x`
- `^1.2.3` - get the latest `1.x.x` but at least `1.2.3`


## Related

- [package-json](https://github.com/sindresorhus/package-json) - API for this module
- [latest-version-cli](https://github.com/sindresorhus/latest-version-cli) - Get the latest version of an npm package


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import execa from 'execa';
import {execa} from 'execa';

test(async t => {
const stdout = await execa.stdout('./cli.js', ['ava']);
test('main', async t => {
const {stdout} = await execa('./cli.js', ['ava']);
t.is(JSON.parse(stdout).name, 'ava');
});

0 comments on commit 60d5b9a

Please sign in to comment.