Skip to content

Commit

Permalink
Merge PR dylang#482: "Get the library running again without errors"
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger authored Jan 2, 2023
1 parent 9e1ddf3 commit 311a8b8
Show file tree
Hide file tree
Showing 28 changed files with 7,179 additions and 8,664 deletions.
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

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
]
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ npm-check
<img width="796" alt="npm-check -u" src="https://cloud.githubusercontent.com/assets/51505/9569917/96947fea-4f48-11e5-9783-2d78077256f2.png">

> This is my personal fork, that I may or may not keep updated
### Features

* Tells you what's out of date.
Expand Down Expand Up @@ -176,7 +178,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
23 changes: 0 additions & 23 deletions appveyor.yml

This file was deleted.

172 changes: 166 additions & 6 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,169 @@
#!/usr/bin/env node
import meow from "meow";

var isEs2015;
try {
isEs2015 = new Function('() => {}');
} catch (e) {
isEs2015 = false;
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

0 comments on commit 311a8b8

Please sign in to comment.