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

Get the library running again without errors [Breaking change] #482

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
29 changes: 29 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"space": 4,
"rules": {
"no-warning-comments": [
0
],
"global-require": [
0
],
"unicorn/no-array-callback-reference": [
0
],
"promise/prefer-await-to-then": [
1
],
"no-unused-expressions": [
1
],
"unicorn/no-array-reduce" : [
1
],
"no-prototype-builtins" : [
1
],
"no-promise-executor-return" : [
1
]
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Enable or disable the spinner. Useful for terminals that don't support them. Aut
The API is here in case you want to wrap this with your CI toolset.

```js
const npmCheck = require('npm-check');
import npmCheck from 'npm-check';

npmCheck(options)
.then(currentState => console.log(currentState.get('packages')));
Expand Down
174 changes: 168 additions & 6 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,171 @@
#!/usr/bin/env node
'use strict';
LinusU marked this conversation as resolved.
Show resolved Hide resolved

var isEs2015;
try {
isEs2015 = new Function('() => {}');
} catch (e) {
isEs2015 = false;
import meow from "meow";

import detectPreferredPM from "preferred-pm";
import { packageDirectorySync } from "pkg-dir";
import debug from "../lib/state/debug.js";
import updateAll from "../lib/out/update-all.js";
import interactiveUpdate from "../lib/out/interactive-update.js";
import staticOutput from "../lib/out/static-output.js";
import npmCheck from "../lib/index.js";
import createCallsiteRecord from "callsite-record";
import isCI from "is-ci";
import updateNotifier from "update-notifier";
import {readFileSync} from "fs";

const pkg = JSON.parse(readFileSync(
new URL('../package.json', import.meta.url),
{ encoding: 'utf8' },
));

updateNotifier({pkg}).notify();

/* eslint-disable indent */
const cli = meow(`
Usage
$ npm-check <path> <options>

Path
Where to check. Defaults to current directory. Use -g for checking global modules.

Options
-u, --update Interactive update.
-y, --update-all Uninteractive update. Apply all updates without prompting.
-g, --global Look at global modules.
-s, --skip-unused Skip check for unused packages.
-p, --production Skip devDependencies.
-d, --dev-only Look at devDependencies only (skip dependencies).
-i, --ignore Ignore dependencies based on succeeding glob.
-E, --save-exact Save exact version (x.y.z) instead of caret (^x.y.z) in package.json.
--specials List of depcheck specials to include in check for unused dependencies.
--no-color Force or disable color output.
--no-emoji Remove emoji support. No emoji in default in CI environments.
--debug Debug output. Throw in a gist when creating issues on github.

Examples
$ npm-check # See what can be updated, what isn't being used.
$ npm-check ../foo # Check another path.
$ npm-check -gu # Update globally installed modules by picking which ones to upgrade.
`,
{
importMeta: import.meta,
flags: {
update: {
type: 'boolean',
alias: 'u'
},
updateAll: {
type: 'boolean',
alias: 'y'
},
global: {
type: 'boolean',
alias: 'g'
},
skipUnused: {
type: 'boolean',
alias: 's'
},
production: {
type: 'boolean',
alias: 'p'
},
devOnly: {
type: 'boolean',
alias: 'd'
},
saveExact: {
type: 'boolean',
alias: 'E'
},
ignore: {
type: 'string',
alias: 'i'
},
specials: {
type: 'string'
},
color: {
type: 'boolean'
},
emoji: {
type: 'boolean',
default: !isCI
},
debug: {
type: 'boolean'
},
spinner: {
type: 'boolean',
default: !isCI
}
}
});

/* eslint-enable indent */

const options = {
cwd: cli.input[0] || packageDirectorySync() || process.cwd(),
update: cli.flags.update,
updateAll: cli.flags.updateAll,
global: cli.flags.global,
skipUnused: cli.flags.skipUnused,
ignoreDev: cli.flags.production,
devOnly: cli.flags.devOnly,
saveExact: cli.flags.saveExact,
specials: cli.flags.specials,
emoji: cli.flags.emoji,
installer: process.env.NPM_CHECK_INSTALLER || 'auto',
debug: cli.flags.debug,
spinner: cli.flags.spinner,
ignore: cli.flags.ignore
};

if (options.debug) {
debug('cli.flags', cli.flags);
debug('cli.input', cli.input);
}

Promise.resolve()
.then(() => {
return options.installer === 'auto' ?
detectPreferredInstaller(options.cwd) :
options.installer;
})
.then(installer => {
options.installer = installer;
return npmCheck(options);
})
.then(currentState => {
currentState.inspectIfDebugMode();

if (options.updateAll) {
return updateAll(currentState);
}

if (options.update) {
return interactiveUpdate(currentState);
}

return staticOutput(currentState);
})
.catch(error => {
console.error(error.message);

if (options.debug) {
console.log(createCallsiteRecord(error).renderSync());
} else {
console.log('For more detail, add `--debug` to the command');
}

process.exit(1);
});

const SUPPORTED_INSTALLERS = new Set(['npm', 'pnpm', 'ied', 'yarn']);

async function detectPreferredInstaller(cwd) {
const preferredPM = await detectPreferredPM(cwd);
return preferredPM && SUPPORTED_INSTALLERS.has(preferredPM.name) ? preferredPM.name : 'npm';
}
isEs2015 ? require('../lib/cli') : require('../lib-es5/cli');
Loading