acrazing/dpdm

[BUG] Exclude option doesn't seem to work

Closed this issue · 2 comments

Describe the bug

Exclude doesn't seem to work.

To Reproduce

Create a folder with this structure

src 
    - index.ts
    - index.test.ts
    - package.json

It should not matter for this issue but the files look like this

index.ts

export const test = () => console.log('hi');

test()

index.test.ts

import { test } from "node:test"
import assert from "node:assert"

test("some test", (t) => {
    assert.strictEqual(1, 1)
  })
  
  test("second basic test", () => {
    assert.equal(2, 3)
  })

package.json

{
  "name": "dpdm-example",
  "version": "1.0.0",
  "author": "Foo Bar <foobar@example.com>",
  "scripts": {
    "test": "node --loader tsx --test *test.ts"
  },
  "devDependencies": {
    "tsx": "^4.7.0"
  }
}

Run
From within the src directory, run
$ npx dpdm --no-tree --detect-unused-files-from '**/*.*' index.ts --exclude node_modules --include *.ts

And note that you still see the node_modules and test files returned as unused

00) index.test.ts
01) node_modules/@esbuild/darwin-arm64/README.md
02) node_modules/@esbuild/darwin-arm64/package.json
03) node_modules/esbuild/LICENSE.md
04) node_modules/esbuild/README.md
05) node_modules/esbuild/install.js
06) node_modules/esbuild/lib/main.d.ts
07) node_modules/esbuild/lib/main.js
08) node_modules/esbuild/package.json
09) node_modules/fsevents/README.md
10) node_modules/fsevents/fsevents.d.ts
11) node_modules/fsevents/fsevents.js
12) node_modules/fsevents/fsevents.node
13) node_modules/fsevents/package.json
14) node_modules/get-tsconfig/README.md
15) node_modules/get-tsconfig/dist/index.cjs
16) node_modules/get-tsconfig/dist/index.d.cts
17) node_modules/get-tsconfig/dist/index.d.mts
18) node_modules/get-tsconfig/dist/index.mjs
19) node_modules/get-tsconfig/package.json
20) node_modules/resolve-pkg-maps/README.md
21) node_modules/resolve-pkg-maps/dist/index.cjs
22) node_modules/resolve-pkg-maps/dist/index.d.cts
23) node_modules/resolve-pkg-maps/dist/index.d.mts
24) node_modules/resolve-pkg-maps/dist/index.mjs
25) node_modules/resolve-pkg-maps/package.json
26) node_modules/tsx/README.md
27) node_modules/tsx/dist/cjs/index.cjs
28) node_modules/tsx/dist/cjs/index.mjs
29) node_modules/tsx/dist/cli.cjs
30) node_modules/tsx/dist/cli.mjs
31) node_modules/tsx/dist/client-2f0df4a6.cjs
32) node_modules/tsx/dist/client-e665d820.mjs
33) node_modules/tsx/dist/esm/index.cjs
34) node_modules/tsx/dist/esm/index.mjs
35) node_modules/tsx/dist/get-pipe-path-86e97fc9.cjs
36) node_modules/tsx/dist/get-pipe-path-b74d9893.mjs
37) node_modules/tsx/dist/index-5d1f01e6.cjs
38) node_modules/tsx/dist/index-bd1ceb03.mjs
39) node_modules/tsx/dist/loader.cjs
40) node_modules/tsx/dist/loader.mjs
41) node_modules/tsx/dist/node-features-c450ed54.cjs
42) node_modules/tsx/dist/node-features-fb266590.mjs
43) node_modules/tsx/dist/package-22dbf202.cjs
44) node_modules/tsx/dist/package-a2d7442c.mjs
45) node_modules/tsx/dist/pkgroll_create-require-b92e8e0d.mjs
46) node_modules/tsx/dist/pkgroll_create-require-c530e400.cjs
47) node_modules/tsx/dist/preflight.cjs
48) node_modules/tsx/dist/preflight.mjs
49) node_modules/tsx/dist/repl.cjs
50) node_modules/tsx/dist/repl.mjs
51) node_modules/tsx/dist/resolve-ts-path-3fca13b7.cjs
52) node_modules/tsx/dist/resolve-ts-path-eb3847f5.mjs
53) node_modules/tsx/dist/source-map.cjs
54) node_modules/tsx/dist/source-map.mjs
55) node_modules/tsx/dist/suppress-warnings.cjs
56) node_modules/tsx/dist/suppress-warnings.mjs
57) node_modules/tsx/dist/temporary-directory-04b36185.mjs
58) node_modules/tsx/dist/temporary-directory-2a027842.cjs
59) node_modules/tsx/package.json
60) package-lock.json
61) package.json

Expected behavior

node_modules and paths with test in the name are excluded from the output

It caused by --detect-unused-files-from '**/*.*', this option will match all the files in current directory. include your node_modules. If you do not need to detect unused files, this option should be ignored, or you need to specify a more precise glob pattern to limit the unused files. This option does not respect the --exclude and --include options.

Got it, thanks I didn't realize that.