dependency-check icon indicating copy to clipboard operation
dependency-check copied to clipboard

Ignoring loader-supported extensions like .css?

Open fatso83 opened this issue 2 years ago • 5 comments

I have been using this for a few years, but after failing to get the latest 4.x version running (a few bugs and hickups) I tried using the @next version, seeing that it is supposed to come pre-configured for TS(X). This seems to work, but non-js imports supported by Vite & webpack loaders (like import 'index.css') seems to trip up the process. How can I make detective ignore these imports?

Output from failing run

2022-02-20T19:11:56.215Z dependency-check globby resolving [ 'src/index.tsx' ]
2022-02-20T19:11:56.219Z dependency-check globby resolved [ '/Users/my-user/dev/ACME-trainer-web/src/index.tsx' ]
2022-02-20T19:11:56.219Z dependency-check entry paths [ '/Users/my-user/dev/ACME-trainer-web/src/index.tsx' ]
2022-02-20T19:11:56.220Z precinct options given: { type: 'tsx', es6: undefined }
2022-02-20T19:11:56.220Z precinct module type: tsx
2022-02-20T19:11:56.220Z typescript-eslint:typescript-estree:createSourceFile Getting AST without type information in TSX mode for: /Users/my-user/dev/ACME-trainer-web/estree.tsx
2022-02-20T19:11:56.228Z dependency-check require("./index.css") is relative
2022-02-20T19:11:56.228Z dependency-check require("./i18next") is relative
2022-02-20T19:11:56.228Z dependency-check require("react") is a dependency
2022-02-20T19:11:56.228Z dependency-check require("react-dom") is a dependency
2022-02-20T19:11:56.228Z dependency-check require("./App") is relative
2022-02-20T19:11:56.228Z dependency-check require("./serviceWorker") is relative
An unexpected error in initial stage: Detective function missing for "/Users/my-user/dev/ACME-trainer-web/src/index.css"
2022-02-20T19:11:56.229Z dependency-check Error: Detective function missing for "/Users/my-user/dev/ACME-trainer-web/src/index.css"
    at getDeps (/Users/my-user/dev/ACME-trainer-web/node_modules/dependency-check/lib/resolve-dependency.js:37:27)
    at resolveDep (/Users/my-user/dev/ACME-trainer-web/node_modules/dependency-check/lib/resolve-dependency.js:84:10)
    at async Promise.all (index 0)
    at async getDeps (/Users/my-user/dev/ACME-trainer-web/node_modules/dependency-check/lib/resolve-dependency.js:67:3)
    at async Promise.all (index 0)
    at async parse (/Users/my-user/dev/ACME-trainer-web/node_modules/dependency-check/lib/parse.js:65:3)

fatso83 avatar Feb 20 '22 19:02 fatso83

Right, would need to be able to append to the noopExtensions + .css should probably be a noop to begin with. I'll give it a look 👍

voxpelli avatar Feb 22 '22 09:02 voxpelli

Seeing that noopExtensions is inside of the module, I think it would make sense to somehow expose it to the user so one could add any extension to it. In any decent sized frontend project with webpack or Vite you would see people use transformation plugins to load mp3s, mp4s, fonts, and all manner of assets that you cannot possibly cover in advance.

fatso83 avatar Feb 22 '22 10:02 fatso83

@fatso83 Yes, or maybe add an option to not fail on unknown file extensions?

voxpelli avatar Feb 22 '22 10:02 voxpelli

Released in 5.0.0-6, sorry for the long delay!

voxpelli avatar May 09 '22 11:05 voxpelli

Thinking more about it, this should be the default as well, reopening

voxpelli avatar May 24 '22 10:05 voxpelli