forked from dylang/npm-check
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR dylang#482: "Get the library running again without errors"
- Loading branch information
1 parent
9e1ddf3
commit 311a8b8
Showing
28 changed files
with
7,179 additions
and
8,664 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Oops, something went wrong.