Skip to content

Commit 43f20bf

Browse files
authoredApr 19, 2022
fix: run dep check in prod mode (#964)
Run dep check command twice - once to check all deps of a project are present and once again to only check production code for production deps in order to catch the instance when we add a production dep to the dev deps list.
1 parent 95429d6 commit 43f20bf

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed
 

‎src/cmds/dependency-check.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ export default {
3030
.positional('input', {
3131
describe: 'Files to check',
3232
type: 'string',
33-
array: true,
34-
default: userConfig.dependencyCheck.input
35-
})
36-
.option('p', {
37-
alias: 'production-only',
38-
describe: 'Check production dependencies and paths only',
39-
type: 'boolean',
40-
default: userConfig.dependencyCheck.productionOnly
33+
array: true
4134
})
4235
.option('i', {
4336
alias: 'ignore',

‎src/config/user.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ const defaults = {
111111
productionInput: [
112112
'package.json',
113113
'src/**/*.js',
114-
'src/**/*.cjs'
114+
'src/**/*.cjs',
115+
'dist/src/**/*.js',
116+
'utils/**/*.js',
117+
'utils/**/*.cjs'
115118
],
116119
ignore: [
117120
'@types/*'

‎src/dependency-check.js

+37-14
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
1313
* @typedef {import("./types").DependencyCheckOptions} DependencyCheckOptions
1414
*/
1515

16-
/**
17-
* @param {any} arr1
18-
* @param {any} arr2
19-
*/
20-
const isDefaultInput = (arr1, arr2) =>
21-
JSON.stringify(arr1) === JSON.stringify(arr2)
22-
2316
const tasks = new Listr(
2417
[
2518
{
@@ -30,17 +23,47 @@ const tasks = new Listr(
3023
*/
3124
task: async (ctx, task) => {
3225
const forwardOptions = ctx['--'] ? ctx['--'] : []
33-
const input =
34-
ctx.productionOnly &&
35-
isDefaultInput(ctx.fileConfig.dependencyCheck.input, ctx.input)
36-
? ctx.fileConfig.dependencyCheck.productionInput
37-
: ctx.input
38-
const noDev = ctx.productionOnly ? ['--no-dev'] : []
26+
const input = ctx.input.length > 0 ? ctx.input : ctx.fileConfig.dependencyCheck.input
27+
const ignore = ctx.ignore
28+
.concat(ctx.fileConfig.dependencyCheck.ignore)
29+
.reduce((acc, i) => acc.concat('-i', i), /** @type {string[]} */ ([]))
30+
31+
const args = [...input, '--missing', ...ignore]
32+
33+
if (pkg.type === 'module') {
34+
// use detective-es6 for js, regular detective for cjs
35+
args.push(
36+
'--extensions', 'cjs:detective-cjs',
37+
'--extensions', 'js:detective-es6'
38+
)
39+
}
40+
41+
await execa(
42+
'dependency-check',
43+
[...args, ...forwardOptions],
44+
merge(
45+
{
46+
localDir: path.join(__dirname, '..'),
47+
preferLocal: true
48+
}
49+
)
50+
)
51+
}
52+
},
53+
{
54+
title: 'dependency-check (production only)',
55+
/**
56+
* @param {GlobalOptions & DependencyCheckOptions} ctx
57+
* @param {Task} task
58+
*/
59+
task: async (ctx, task) => {
60+
const forwardOptions = ctx['--'] ? ctx['--'] : []
61+
const input = ctx.input.length > 0 ? ctx.input : ctx.fileConfig.dependencyCheck.productionInput
3962
const ignore = ctx.ignore
4063
.concat(ctx.fileConfig.dependencyCheck.ignore)
4164
.reduce((acc, i) => acc.concat('-i', i), /** @type {string[]} */ ([]))
4265

43-
const args = [...input, '--missing', ...noDev, ...ignore]
66+
const args = [...input, '--missing', '--no-dev', ...ignore]
4467

4568
if (pkg.type === 'module') {
4669
// use detective-es6 for js, regular detective for cjs

0 commit comments

Comments
 (0)
Please sign in to comment.