Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude imports not used at module load time #368

Closed
1226085293 opened this issue Apr 12, 2023 · 1 comment
Closed

Exclude imports not used at module load time #368

1226085293 opened this issue Apr 12, 2023 · 1 comment

Comments

@1226085293
Copy link

1226085293 commented Apr 12, 2023

example

a.ts

import b from "./b";

class a {
    test(): b {
        return new b();
    }
}

export default a;

b.ts

import a from "./a";

class b {
    test(): a {
        return new a();
    }
}

export default b;

There is no circular reference error at runtime, can exclude such imports?

.madgerc

{
	"detectiveOptions": {
		"ts": {
			"mixedImports": true,
			"skipTypeImports": true,
			"skipAsyncImports": true
		},
		"es6": {
			"skipTypeImports": true
		}
	}
}

tsconfig.json

{
	"compilerOptions": {
		"target": "es6",
		"lib": ["es2015", "es2017", "ES2020", "ES2022", "dom"],
		"module": "commonjs",
		"sourceMap": true,
		"noEmit": true,
		"strict": true,
		"noImplicitAny": false,
		"downlevelIteration": true,
		"esModuleInterop": true,
		"experimentalDecorators": true,
		"allowSyntheticDefaultImports": true,
		"isolatedModules": true
	}
}
@fdc-viktor-luft
Copy link
Collaborator

Madge is based on the implementation of dependency-tree, which uses "detective" packages to analyze the code. For simplicity most of them are just checking the imports. Not the actual code, see e.g. here: https://github.com/dependents/detective-typescript/blob/main/test/test.js

This means that this is not possible to detect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants