m-izadmehr / deadfile Goto Github PK
View Code? Open in Web Editor NEWSimple util to find unused files in any JavaScript project (ES5, ES6, React, Vue, ...)
Home Page: https://m-izadmehr.github.io/deadfile/
Simple util to find unused files in any JavaScript project (ES5, ES6, React, Vue, ...)
Home Page: https://m-izadmehr.github.io/deadfile/
Hey,
First of all thanks for this awesome lib! It's really good =)
I wonder if we could add babel.js module-resolver support - in order to support absolute imports.
For example I have this setup in my project:
import FadeIn from "components/Loading/FadeIn";
Thanks to module-resolver I don't have to do ../../../components/Loading/FadeIn
, since it simplifies that by allowing me to directly target components
folder.
But due to module-resolver, deadfile doesn't recognise that the component is being imported:
Any ideas? I'm willing to contribute to this project. ๐
(develop *+$% u=)$ deadfile ./src/root.jsx
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Dead File! โ
โ โ
โ Simply find the unused files in your javascript project. โ
โ Press --help for help. โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ 3152 total assets found in base directory.
โ 16 imported assets found. /path/to/the/project/src/state/routes.jsx Killed
Tried two times. Every time I had to kill the process after 4-6 minutes.
Weirdly, I couldn't also terminate the process using Ctrl+c
so I killed it from the outside.
Both times the process was consuming 175-200% of CPU according to htop
.
System: Linux Ubuntu 18.04
This tools awesome to check all my unused files, but i have some import file that used package.json
let say i have this structure folder
assets (dir)
welcome.png
splash_screen.png
package.json
index.js (file)
where package.json
inside assets
folder has json :
{
"name": "@images"
}
and my index.js
contain some code like this :
const WelcomeImage = require('@images/welcome.png')
this way, deadfile checking welcome.png
is not imported
is there some way to solve this issue @M-Izadmehr ?
I'm currently investigating running this as part of a CI process in GHA.
The visualisation is great for manual investigations, but in this case, I just need to pipe machine readable output to a script that iterates over unused files and deletes them.
I've been writing and reading the JSON output as a stop-gap for sending JSON to stdout, but it seems that the process which launches the visualisation server causes the CI to hang and never resolve.
It would be great to expose a CLI argument to switch this feature off, and also optionally, to pipe the JSON output to stdout.
Thanks!
Very nice project, thank you.
It would be great to be able to use a config file. For instance the list of excluded paths can be pretty long, it could be nicer to place that info in a config file rather than a script?
folder list
I want to include src/main/app and exclude src/test
npx deadfile src/main/app/application.tsx --exclude src/main/java src/main/resources dist storybook-static static bin src/test browser-tests build src/stories
Actual Result
files in src/test are not excluded
Should introduce a debug mode when running the scan, I got a huge project with .js & .ts files, it calculates the amount of assets & files, then just gets stuck & uncancellable.
Is it compliant with typescript files?
Super project! Thank you.
I've got a use case where my project is a library that exports much of it's functionality for 3rd parties to use. I want to know what files are not getting exported. It seems like this could have an option to run in library mode that tells you not just what isn't imported, but also what isn't exported.
I think we are one step away from adding a monorepo support.
I've checked the source code and it seems to me that we only need to add support for multiple --dir
options.
Hello,
I have a large project and for performance I'am using lazy() to load my views
const Home = lazy(() => import('@/views/home'))
however this files are not being considered when runing the tool and they appear as unused.
Is there a work around to make this work right now or is not possible?
Thanks for your attention
To speed up process while working on #5 I realized that this tool may be useful also to be used as node module rather than CLI only.
I spotted a couple of issues that may be worth working on
UsedAssets
is async, there is not way to know when Deadfile
has finished his work, maybe extend EventEmitter
and send events may be a solution?I'd like to use it like
const instance = new Deadfile(opts);
instance.on('end', (results) => {
console.log(results) // console.log(instance.results)
// do your own stuff with results of deadfile
});
Hi, was linked this utility and it looks great! ๐คฉ
One feature I'd really love is to be able to ignore files based on my .gitignore. Currently, these files pollute the output of this utility and there's no simple way to ignore them.
I tried e.g. npx deadfile ./src/App.tsx --exclude $(cat .gitignore)
but that fails due to my .gitignore containing wildcards. Maybe e.g. parse-gitignore could be a simple way of acheving this?
Launching deadfile will fail due to missing find-babel-config
package as it's been added to devDependencies
instead of dependencies
/cc @leorossi
master
branch failed. ๐จI recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iโm sure you can fix this ๐ช.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here are some links that can help you:
If those donโt help, or if this issue is reporting something you think isnโt right, you can always ask the humans behind semantic-release.
An npm token must be created and set in the NPM_TOKEN
environment variable on your CI environment.
Please make sure to create an npm token and to set it in the NPM_TOKEN
environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/
.
Good luck with your project โจ
Your semantic-release bot ๐ฆ๐
This library looks great! We have a large typescript/javascript repo and are hoping to find some dead code.
Would it be possible to add a license to this repository so that we know under what circumstances we can use and modify the code?
(MIT / ISC preferred -- but of course it's up to your preferences)
The project I'd like to use deadfile
with doesn't use a module resolver plugin. As a result moduleResolverConfig
ends up being null
which results in https://github.com/M-Izadmehr/deadfile/blob/master/src/handlers/fileResolver.js#L26 throwing an exception. I'd like to add a null-check to checkBabelModuleResolver
so that I can use it with my project. I can submit a PR to address this issue.
main.scss
@import "dropdowns";
actual file name: _dropdowns.scss
I'm using create-react-app and have a file like this in the root of my project:
{
"compilerOptions": {
"baseUrl": "src"
}
}
So all of my imports look like
import { abc } from 'components/XYZ'
for a file in src/components/XYZ.js
Right now when I run deadfile it shows every single file as being dead.
eg:
673 total files found!
670 dead files found!
...
Is it possible to configure it so I can tell it the baseUrl
is src
?
Kudos on the lib btw, it looks really nicely put together!
detect React.Lazy import as unusedfile
I just tried on my project and unfortunately it returned an error. Any idea what's causing the issue?
$ deadfile ./src/index.js
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Dead File! โ
โ โ
โ Simply find the unused files in your javascript project. โ
โ Press --help for help. โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ 1221 total assets found in base directory.
โ 76 imported assets found.
/usr/local/lib/node_modules/deadfile/node_modules/table/dist/validateTableData.js:88
throw _iteratorError;
^
Error: Table data must not contain control characters.
at validateTableData (/usr/local/lib/node_modules/deadfile/node_modules/table/dist/validateTableData.js:60:19)
at table (/usr/local/lib/node_modules/deadfile/node_modules/table/dist/table.js:96:34)
at logger (/usr/local/lib/node_modules/deadfile/src/cli/Logger.js:38:18)
at DeadFile.reporting (/usr/local/lib/node_modules/deadfile/src/index.js:84:5)
at DeadFile.checkDiff (/usr/local/lib/node_modules/deadfile/src/index.js:78:12)
at DeadFile.setUsedAssets (/usr/local/lib/node_modules/deadfile/src/index.js:47:10)
at /usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:75:12
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
After installation either globally or locally none of the deadfile commands works even version commands.
Hey there,
in our project we use module-resolver
with directory aliases, the config looks like this:
[
"module-resolver",
{
"root": [
"."
],
"alias": {
"~": "./src",
"lib": "./src/lib",
"components": "./src/components",
"state": "./src/state",
"config": "./src/config",
"RootParams": "./src/lib/Shared/ScreenManager/RootParams"
}
}
]
but when running deadfile we get the following error:
err: Error: Can't resolve './src' in '/Users/workstation/Development/example/mobile'
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:209:21
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1) {
details: "resolve './src' in '/Users/workstation/Development/example/mobile'\n" +
' using description file: /Users/workstation/Development/example/mobile/package.json (relative path: .)\n' +
' using description file: /Users/workstation/Development/example/mobile/package.json (relative path: ./src)\n' +
' no extension\n' +
' /Users/workstation/Development/example/mobile/src is not a file\n' +
' .js\n' +
" /Users/workstation/Development/example/mobile/src.js doesn't exist\n" +
' .jsx\n' +
" /Users/workstation/Development/example/mobile/src.jsx doesn't exist\n" +
' .ts\n' +
" /Users/workstation/Development/example/mobile/src.ts doesn't exist\n" +
' tsx\n' +
" /Users/workstation/Development/example/mobile/srctsx doesn't exist\n" +
' .vue\n' +
" /Users/workstation/Development/example/mobile/src.vue doesn't exist\n" +
' as directory\n' +
' existing directory\n' +
' using path: /Users/workstation/Development/example/mobile/src/index\n' +
' using description file: /Users/workstation/Development/example/mobile/package.json (relative path: ./src/index)\n' +
' no extension\n' +
" /Users/workstation/Development/example/mobile/src/index doesn't exist\n" +
' .js\n' +
" /Users/workstation/Development/example/mobile/src/index.js doesn't exist\n" +
' .jsx\n' +
" /Users/workstation/Development/example/mobile/src/index.jsx doesn't exist\n" +
' .ts\n' +
" /Users/workstation/Development/example/mobile/src/index.ts doesn't exist\n" +
' tsx\n' +
" /Users/workstation/Development/example/mobile/src/indextsx doesn't exist\n" +
' .vue\n' +
" /Users/workstation/Development/example/mobile/src/index.vue doesn't exist",
missing: [
'/Users/workstation/Development/example/mobile/src',
'/Users/workstation/Development/example/mobile/src.js',
'/Users/workstation/Development/example/mobile/src.jsx',
'/Users/workstation/Development/example/mobile/src.ts',
'/Users/workstation/Development/example/mobile/srctsx',
'/Users/workstation/Development/example/mobile/src.vue',
'/Users/workstation/Development/example/mobile/src/index',
'/Users/workstation/Development/example/mobile/src/index.js',
'/Users/workstation/Development/example/mobile/src/index.jsx',
'/Users/workstation/Development/example/mobile/src/index.ts',
'/Users/workstation/Development/example/mobile/src/indextsx',
'/Users/workstation/Development/example/mobile/src/index.vue'
]
}
Looks like the problem is enhanced-resolver doesn't understand that /src refers to a directory (and not a file), and is trying to find a specific file in there.
Any ideas?
Thanks
same error keeps repeating ... I cant get any results
deadfile ./src/App.js
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Dead File! โ
โ โ
โ Simply find the unused files in your javascript project. โ
โ Press --help for help. โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ 614 total assets found in base directory.
โ Counting imported assetserr: TypeError: Cannot read property '1' of undefined
at checkBabelModuleResolver (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:26:38)
at resolve (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:53:15)
at UsedAssets.updateSources (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:99:38)
at UsedAssets.checkImports (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:142:21)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:79:24)
at Object.skipThrough (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:186:39)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.base.Program.base.BlockStatement (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:198:7)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.full (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:80:7)
err: TypeError: Cannot read property '1' of undefined
at checkBabelModuleResolver (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:26:38)
at resolve (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:53:15)
at UsedAssets.updateSources (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:99:38)
at UsedAssets.checkImports (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:142:21)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:79:24)
at Object.skipThrough (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:186:39)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.base.Program.base.BlockStatement (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:198:7)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.full (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:80:7)
err: TypeError: Cannot read property '1' of undefined
at checkBabelModuleResolver (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:26:38)
at resolve (/usr/local/lib/node_modules/deadfile/src/handlers/fileResolver.js:53:15)
at UsedAssets.updateSources (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:99:38)
at UsedAssets.checkImports (/usr/local/lib/node_modules/deadfile/src/handlers/UsedAssets.js:142:21)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:79:24)
at Object.skipThrough (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:186:39)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.base.Program.base.BlockStatement (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:198:7)
at c (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:78:24)
at Object.full (/usr/local/lib/node_modules/deadfile/node_modules/acorn-walk/dist/walk.js:80:7)
This line contains "tsx" without dot, is this intentional or a typo?
deadfile/src/models/Parsables.js
Line 1 in fd24e01
After running deadcode
we get a big page which we should able to filter and sort using name, size etc
Hey.
Does anyone know what entry point should I set for a react gatsby application?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.