Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 8657129

Browse files
committedJul 28, 2019
BREAKING: Remove --entry, instead add directly
1 parent 151bc29 commit 8657129

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed
 

‎cli.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ if (args.help || args._.length === 0) {
3838
console.log("--no-dev Won't tell you about devDependencies that are missing or unused")
3939
console.log("--no-peer Won't tell you about peerDependencies that are missing or unused")
4040
console.log("--ignore-module, -i Won't tell you about these module names when missing or unused. Supports globbing")
41-
console.log('--entry If a package.json or module folder was set, then by default the main and bin entries in the package.json will be parsed, but you can add more the list of entries by passing them in as --entry. Supports globbing')
4241
console.log("--no-default-entries Won't parse your main and bin entries from package.json even when a package.json or module folder has been defined")
4342
console.log('--detective Requireable path containing an alternative implementation of the detective module that supports alternate syntaxes')
4443
console.log("--extensions, -e List of file extensions with detective to use when resolving require paths. Eg. 'js,jsx:detective-es6'")
@@ -73,7 +72,7 @@ function extensions (arg) {
7372

7473
check({
7574
path: args._.shift(),
76-
entries: args._.concat(args.entry || []),
75+
entries: args._,
7776
noDefaultEntries: !args['default-entries'],
7877
extensions: extensions(args.e),
7978
detective: args.detective

‎index.js

+60-20
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,83 @@ async function resolveGlobbedPath (entries, cwd) {
4242
return paths
4343
}
4444

45-
module.exports = async function (opts) {
46-
let targetPath = opts.path
47-
let pkgPath = targetPath
48-
let entries = []
49-
let pkg
45+
async function resolveModuleTarget (targetPath) {
46+
let pkgPath, pkg
5047

5148
try {
5249
pkg = await promisedReadPackage(targetPath)
50+
pkgPath = targetPath
5351
} catch (err) {
5452
if (targetPath.endsWith('/package.json') || targetPath === 'package.json') {
5553
throw new Error('Failed to read package.json: ' + err.message)
5654
}
5755

5856
if (err && err.code === 'EISDIR') {
57+
// We were given a path to a module folder
5958
pkgPath = path.join(targetPath, 'package.json')
60-
} else {
61-
// We've likely been given entries rather than a package.json or module path, try resolving that instead
62-
entries = await resolveGlobbedPath(pkgPath)
59+
pkg = await promisedReadPackage(pkgPath)
60+
}
61+
}
6362

64-
if (!entries[0]) {
65-
throw new Error('Failed to find package.json, no files found')
66-
}
63+
if (!pkg) return undefined
6764

68-
opts.noDefaultEntries = true
69-
pkgPath = await pkgUp({ cwd: path.dirname(entries[0]) })
70-
}
65+
return {
66+
pkgPath,
67+
pkg
68+
}
69+
}
70+
71+
async function resolveEntryTarget (targetPath) {
72+
// We've been given an entry path pattern as the target rather than a package.json or module folder
73+
// We'll resolve those entries and then finds us the package.json from the location of those
74+
const targetEntries = await resolveGlobbedPath(targetPath)
75+
76+
if (!targetEntries[0]) {
77+
throw new Error('Failed to find package.json, no file to resolve it from')
78+
}
79+
80+
const pkgPath = await pkgUp({ cwd: path.dirname(targetEntries[0]) })
81+
82+
if (!pkgPath) {
83+
throw new Error('Failed to find a package.json')
84+
}
7185

72-
pkg = await promisedReadPackage(pkgPath)
86+
const pkg = await promisedReadPackage(pkgPath)
87+
88+
return {
89+
pkgPath,
90+
pkg,
91+
targetEntries
7392
}
93+
}
94+
95+
module.exports = async function ({
96+
builtins,
97+
detective,
98+
entries,
99+
extensions,
100+
noDefaultEntries,
101+
path: targetPath
102+
}) {
103+
if (!targetPath) throw new Error('Requires a path to be set')
104+
105+
const {
106+
pkgPath,
107+
pkg,
108+
targetEntries
109+
} = await resolveModuleTarget(targetPath) || await resolveEntryTarget(targetPath)
110+
111+
entries = targetEntries ? [...targetEntries, ...entries] : entries
112+
extensions = getExtensions(extensions, detective)
113+
noDefaultEntries = noDefaultEntries || (targetEntries && targetEntries.length !== 0)
74114

75115
return parse({
76-
path: pkgPath,
116+
builtins,
117+
entries,
118+
extensions,
119+
noDefaultEntries,
77120
package: pkg,
78-
entries: entries.concat(opts.entries),
79-
noDefaultEntries: opts.noDefaultEntries,
80-
builtins: opts.builtins,
81-
extensions: getExtensions(opts.extensions, opts.detective)
121+
path: pkgPath
82122
})
83123
}
84124

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"check:node-versions": "installed-check --engine-check --no-version-check",
1212
"lint": "standard",
1313
"test-cli:custom-detective": "node cli.js test/ -e js:detective-cjs",
14-
"test-cli:glob": "node cli.js test/ --entry '**/*.js' --no-default-entries",
14+
"test-cli:glob": "node cli.js 'test/**/*.js' --no-default-entries",
1515
"test-cli:main-as-file": "node cli.js test/index.js",
1616
"test-cli:simple": "node cli.js test/",
1717
"test-cli": "npm-run-all --parallel test-cli:*",

0 commit comments

Comments
 (0)
This repository has been archived.