Skip to content

Commit

Permalink
feature(resolve): improves support for package entry points (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij authored Dec 20, 2020
1 parent e7dfee9 commit 85eb04d
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 37 deletions.
10 changes: 5 additions & 5 deletions .dependency-cruiser.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "./src/schema/configuration.schema.json",
"extends": "./configs/recommended-strict",
"forbidden": [
{
Expand Down Expand Up @@ -223,11 +224,10 @@
// "babelConfig": {
// "fileName": "./babel.config.json"
// },
// "enhancedResolveOptions": {
// "cachedInputFileSystem": {
// "cacheDuration": 1800000
// }
// },
"enhancedResolveOptions": {
"exportsFields": ["exports"],
"conditionNames": ["require"]
},
"exoticRequireStrings": ["tryRequire"],
"reporterOptions": {
"archi": {
Expand Down
52 changes: 46 additions & 6 deletions doc/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1086,17 +1086,55 @@ E.g.:
### enhancedResolveOptions
> Likely you will not need to use these.
Under the hood dependency-cruiser uses webpack's
[enhanced-resolve](https://github.com/webpack/enhanced-resolve).
to resolve dependencies to disk. You can influence how dependency-cruiser uses
it directly by passing resolver options in a
[webpack config](#webpackconfig-use-the-resolution-options-of-a-webpack-configuration)
for most things. The only exception is the way enhanced-resolve accesses
the file system - the amount of which we want to have a slightly tighter control
over as with the wrong settings a lot can go wrong. There's one thing you
might still want the ability to change though, in a limited number of
for most things. If you do need to influence how dependency-cruiser does
its resolution, but don't (want to) have a webpack config, you can use the
`enhancedResolveOptions` section to set them.
#### `exportsFields`
List of strings to consider as 'exports' fields in package.json. Use ['exports']
when you use packages that use such a field and your environment supports it
(e.g. node ^12.19 || >=14.7 or recent versions of webpack).
If you have an `exportsFields` attribute in your webpack config, that one will
have precedence over the one specified here.
#### `conditionNames`
List of conditions to check for in the exports field. e.g. use `['imports']` if
you're only interested in exposed es6 modules, `['require']` for commonjs, or all
conditions at once `(['import', 'require', 'node', 'default']`) if anything goes
for you. Only works when the 'exportsFields' array is non-empty.
If you have an `conditionNames` attribute in your webpack config, that one will
have precedence over the one specified here.
#### `extensions`
List of extensions to scan for when resolving. Typically you want to leave this
alone as dependency-cruiser figures out what extensions to scan based on
1. what is available in your environment
2. in the order your environment (nodejs, typescript) applies the resolution itself.
However, if you want it to scan less you can specify so with the extensions
attribute. E.g. when you're 100% sure you _only_ have typescript & json and
nothing else you can pass `['.ts', '.json']` - which can lead to performance gains
on systems with slow i/o (like ms-windows), especially when your tsconfig
contains paths/ aliasses.
#### cachedInputFileSystem - `cacheDuration`
> Likely you will not need to use this
We want to have a slightly tighter control over the way enhanced-resolve
accesses the file system as with the wrong settings a lot can go wrong. There's
one thing you might still want the ability to change though, in a limited number of
circumstances and that is the time enhanced resolve's files systems retains
resolutions in memory.
Expand Down Expand Up @@ -1129,3 +1167,5 @@ E.g. to set the cache duration to 1337ms, you can use this:
```
The cache duration is limited from 0ms (~ don't use a cache) to 1800000ms (0.5h).
The cacheDuration used here overrides any that might be set in webpack configs.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
"build:clean": "make clean",
"check": "npm-run-all build lint depcruise test:cover",
"check:full": "npm-run-all check test:glob test:yarn-pnp",
"depcruise": "node ./bin/dependency-cruise.js src bin test configs types tools --config --webpack-config webpack.conf.js",
"depcruise:explain": "node ./bin/dependency-cruise.js src bin test configs types tools --output-type err-long --config --webpack-config webpack.conf.js --progress none",
"depcruise": "node ./bin/dependency-cruise.js src bin test configs types tools --config",
"depcruise:explain": "node ./bin/dependency-cruise.js src bin test configs types tools --output-type err-long --config --progress none",
"depcruise:graph:dev": "node ./bin/dependency-cruise.js bin src --prefix vscode://file/$(pwd)/ --config --output-type dot --progress cli-feedback | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
"depcruise:graph:doc": "npm-run-all depcruise:graph:doc:json --parallel depcruise:graph:doc:fmt-* depcruise:graph:doc:samples",
"depcruise:graph:doc:json": "node ./bin/dependency-cruise.js bin src test --config --webpack-config webpack.conf.js --output-type json --output-to tmp_graph_deps.json --progress",
"depcruise:graph:doc:json": "node ./bin/dependency-cruise.js bin src test --config --output-type json --output-to tmp_graph_deps.json --progress",
"depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.js -T dot -f - tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-dependency-graph.html",
"depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.js -T archi -f - tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-archi-graph.html",
"depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.js -T ddot -f - tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-dir-graph.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-dir-graph.html",
Expand All @@ -82,7 +82,7 @@
"depcruise:graph:dot": "node ./bin/dependency-cruise.js bin src --config --output-type dot | dot -T svg > tmp_deps.svg",
"depcruise:graph:fdp": "node ./bin/dependency-cruise.js bin src --config --output-type dot | fdp -GK=0.1 -Gsplines=true -T svg > tmp_deps.svg",
"depcruise:graph:osage": "node ./bin/dependency-cruise.js bin src --config --output-type dot | osage -Gpack=32 -GpackMode=array2 -T svg > tmp_deps.svg",
"depcruise:report": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config --webpack-config webpack.conf.js --output-to dependency-violations.html",
"depcruise:report": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config ƒ--output-to dependency-violations.html",
"lint": "npm-run-all --parallel --aggregate-output lint:eslint lint:prettier:check lint:types",
"lint:eslint": "eslint bin/dependency-cruise.js src test configs tools/**/*.js tools/schema/**/*.mjs --cache --cache-location .cache/eslint/",
"lint:eslint:fix": "eslint --fix bin src test configs tools/**/*.js tools/schema/**/*.mjs --cache --cache-location .cache/eslint/",
Expand Down
28 changes: 27 additions & 1 deletion src/cli/init-config/config.js.template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,33 @@ module.exports = {
a hack.
*/
// exoticRequireStrings: [],
// exoticRequireStrings: [],
/* options to pass on to enhanced-resolve, the package dependency-cruiser
uses to resolve module references to disk. You can set most of these
options in a webpack.conf.js - this section is here for those
projects that don't have a separate webpack config file.

Note: settings in webpack.conf.js override the ones specified here.
*/
enhancedResolveOptions:{
/* List of strings to consider as 'exports' fields in package.json. Use
['exports'] when you use packages that use such a field and your environment
supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack).

If you have an `exportsFields` attribute in your webpack config, that one
will have precedence over the one specified here.
*/
exportsFields: ["exports"],
/* List of conditions to check for in the exports field. e.g. use ['imports']
if you're only interested in exposed es6 modules, ['require'] for commonjs,
or all conditions at once `(['import', 'require', 'node', 'default']`)
if anything goes for you. Only works when the 'exportsFields' array is
non-empty.

If you have an 'conditionNames' attribute in your webpack config, that one will
have precedence over the one specified here.
*/
conditionNames: ["import", "require", "node", "default"]
},
reporterOptions: {
dot: {
/* pattern of modules that can be consolidated in the detailed
Expand Down
6 changes: 3 additions & 3 deletions src/cli/init-config/config.js.template.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 85eb04d

Please sign in to comment.