diff --git a/src/node-file-trace.ts b/src/node-file-trace.ts index 879acc99..dc036056 100644 --- a/src/node-file-trace.ts +++ b/src/node-file-trace.ts @@ -256,11 +256,13 @@ export class Job { if (!reasonEntry) { reasonEntry = { - type: reasonType, + type: [reasonType], ignored: false, parents: new Set() }; this.reasons.set(path, reasonEntry) + } else if (!reasonEntry.type.includes(reasonType)) { + reasonEntry.type.push(reasonType) } if (parent && this.ignoreFn(path, parent)) { if (!this.fileList.has(path) && reasonEntry) { diff --git a/src/types.ts b/src/types.ts index e398a8e0..da9201a8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -54,7 +54,7 @@ export interface NodeFileTraceOptions { export type NodeFileTraceReasonType = 'initial' | 'resolve' | 'dependency' | 'asset' | 'sharedlib'; export interface NodeFileTraceReasons extends Map; }> {} diff --git a/test/unit.test.js b/test/unit.test.js index 95556c1f..f550eced 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -59,7 +59,7 @@ for (const { testName, isRoot } of unitTests) { } if (testName === 'multi-input') { - inputFileNames.push('input-2.js', 'input-3.js') + inputFileNames.push('input-2.js', 'input-3.js', 'input-4.js'); } const { fileList, reasons } = await nodeFileTrace( @@ -107,6 +107,7 @@ for (const { testName, isRoot } of unitTests) { const normalizeInputRoot = file => isRoot ? join('./', unitPath, file) : join('test/unit', testName, file) + const getReasonType = file => reasons.get(normalizeInputRoot(file)).type expect([...collectFiles(normalizeInputRoot('input.js'))].map(normalizeFilesRoot).sort()).toEqual([ "package.json", @@ -129,6 +130,25 @@ for (const { testName, isRoot } of unitTests) { "test/unit/multi-input/asset.txt", "test/unit/multi-input/child-3.js", ]) + + expect([...collectFiles(normalizeInputRoot('input-4.js'))].map(normalizeFilesRoot).sort()).toEqual([ + "package.json", + "test/unit/multi-input/child-4.js", + "test/unit/multi-input/style.module.css", + ]) + + expect(getReasonType('input.js')).toEqual(['initial', 'dependency']) + expect(getReasonType('input-2.js')).toEqual(['initial', 'dependency']) + expect(getReasonType('input-3.js')).toEqual(['initial', 'dependency']) + expect(getReasonType('input-4.js')).toEqual(['initial', 'dependency']) + expect(getReasonType('child-1.js')).toEqual(['dependency']) + expect(getReasonType('child-2.js')).toEqual(['dependency']) + expect(getReasonType('child-3.js')).toEqual(['dependency']) + expect(getReasonType('child-4.js')).toEqual(['dependency']) + expect(getReasonType('asset.txt')).toEqual(['asset']) + expect(getReasonType('asset-2.txt')).toEqual(['asset']) + expect(getReasonType('style.module.css')).toEqual(['dependency', 'asset']) + } let expected; diff --git a/test/unit/multi-input/child-4.js b/test/unit/multi-input/child-4.js new file mode 100644 index 00000000..03e7a2be --- /dev/null +++ b/test/unit/multi-input/child-4.js @@ -0,0 +1,4 @@ +const fs = require('fs') +const { join } = require('path') + +fs.readFileSync(join(__dirname, 'style.module.css')) diff --git a/test/unit/multi-input/input-4.js b/test/unit/multi-input/input-4.js new file mode 100644 index 00000000..154735dd --- /dev/null +++ b/test/unit/multi-input/input-4.js @@ -0,0 +1,3 @@ +import style from './style.module.css'; + +import child4 from './child-4'; \ No newline at end of file diff --git a/test/unit/multi-input/output.js b/test/unit/multi-input/output.js index a668c1ba..5ecf027a 100644 --- a/test/unit/multi-input/output.js +++ b/test/unit/multi-input/output.js @@ -5,7 +5,10 @@ "test/unit/multi-input/child-1.js", "test/unit/multi-input/child-2.js", "test/unit/multi-input/child-3.js", + "test/unit/multi-input/child-4.js", "test/unit/multi-input/input-2.js", "test/unit/multi-input/input-3.js", - "test/unit/multi-input/input.js" + "test/unit/multi-input/input-4.js", + "test/unit/multi-input/input.js", + "test/unit/multi-input/style.module.css" ] \ No newline at end of file diff --git a/test/unit/multi-input/style.module.css b/test/unit/multi-input/style.module.css new file mode 100644 index 00000000..0eeff3d4 --- /dev/null +++ b/test/unit/multi-input/style.module.css @@ -0,0 +1 @@ +body { color: green; } \ No newline at end of file