dependency-cruiser 16.0.0 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2023 Sander Verweij
3
+ Copyright (c) 2016-2024 Sander Verweij
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "16.0.0",
3
+ "version": "16.1.0",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -98,76 +98,12 @@
98
98
  "package.json",
99
99
  "README.md"
100
100
  ],
101
- "scripts": {
102
- "build": "make build",
103
- "build:clean": "make clean",
104
- "check": "npm-run-all build lint depcruise test:cover",
105
- "check:full": "npm-run-all check test:glob",
106
- "depcruise": "node ./bin/dependency-cruise.mjs src bin test configs types tools --ignore-known",
107
- "depcruise:all": "node ./bin/dependency-cruise.mjs src bin test configs types tools",
108
- "depcruise:baseline": "node ./bin/depcruise-baseline.mjs src bin test configs types tools",
109
- "depcruise:explain": "node ./bin/dependency-cruise.mjs src bin test configs types tools --output-type err-long --progress none",
110
- "depcruise:graph:doc": "npm-run-all depcruise:graph:doc:json --parallel depcruise:graph:doc:fmt-* depcruise:graph:doc:samples",
111
- "depcruise:graph:doc:json": "node ./bin/dependency-cruise.mjs bin src test --output-type json --output-to node_modules/.cache/tmp_graph_deps.json --progress",
112
- "depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.mjs -T dot -f - node_modules/.cache/tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dependency-graph.html",
113
- "depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.mjs -T archi -f - node_modules/.cache/tmp_graph_deps.json | dot -T svg -Gordering=in -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-archi-graph.html",
114
- "depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.mjs -T ddot -f - node_modules/.cache/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.mjs > docs/dependency-cruiser-dir-graph.html",
115
- "depcruise:graph:doc:fmt-schema": "cd tools/schema && node ../../bin/dependency-cruise.mjs . --output-type dot | dot -T svg | tee ../overview.svg | node ../../bin/wrap-stream-in-html.mjs > ../../docs/schema-overview.html && cd -",
116
- "depcruise:graph:doc:fmt-types": "cd types && node ../bin/dependency-cruise.mjs . --output-type dot | dot -T svg | tee overview.svg | ../bin/wrap-stream-in-html.mjs > overview.html && cd -",
117
- "depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
118
- "depcruise:graph:mermaid": "node ./bin/dependency-cruise.mjs bin src --include-only ^src/ --collapse 2 --output-type mermaid",
119
- "depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.mjs bin src test types tools --config configs/.dependency-cruiser-unlimited.mjs --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
120
- "depcruise:graph:view": "node ./bin/dependency-cruise.mjs bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.mjs --output-type dot --progress cli-feedback --highlight \"$(watskeburt main)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
121
- "depcruise:graph:view:diff": "node ./bin/dependency-cruise.mjs bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.mjs --output-type dot --progress cli-feedback --reaches \"$(watskeburt main)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
122
- "depcruise:report": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.mjs --output-to dependency-violations.html",
123
- "depcruise:report:view": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.mjs --output-to - | browser",
124
- "depcruise:focus": "node ./bin/dependency-cruise.mjs src bin test configs types tools --progress --no-cache --output-type text --focus",
125
- "depcruise:reaches": "node ./bin/dependency-cruise.mjs src bin test configs types tools --progress --no-cache --config configs/.dependency-cruiser-unlimited.mjs --output-type text --reaches",
126
- "format": "prettier --log-level warn --write \"src/**/*.js\" \"configs/**/*.js\" \"tools/**/*.mjs\" \"bin/*\" \"types/*.d.mts\" \"test/**/*.spec.{cjs,js}\" \"test/**/*.{spec,utl}.mjs\"",
127
- "format:check": "prettier --log-level warn --check \"src/**/*.js\" \"configs/**/*.js\" \"tools/**/*.mjs\" \"bin/*\" \"types/*.d.mts\" \"test/**/*.spec.{cjs,js}\" \"test/**/*.{spec,utl}.mjs\"",
128
- "lint": "npm-run-all --parallel --aggregate-output lint:eslint format:check lint:types",
129
- "lint:eslint": "eslint bin/dependency-cruise.mjs bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
130
- "lint:eslint:fix": "eslint --fix bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
131
- "lint:eslint:clear-caches": "rm -rf node_modules/.cache/eslint/",
132
- "lint:fix": "npm-run-all lint:eslint:fix format lint:types:fix",
133
- "lint:types": "npm-run-all lint:types:tsc lint:types:lint",
134
- "lint:types:tsc": "tsc --project types/tsconfig.json",
135
- "lint:types:lint": "eslint --no-ignore --config types/.eslintrc.json types/*.d.mts",
136
- "lint:types:fix": "eslint --no-ignore --config types/.eslintrc.json --fix types/*.d.mts",
137
- "prepare": "husky install",
138
- "scm:push": "run-p --aggregate-output scm:push:*",
139
- "scm:push:bitbucket-mirror": "run-p --aggregate-output scm:push:bitbucket-mirror:*",
140
- "scm:push:bitbucket-mirror:commits": "git push bitbucket-mirror",
141
- "scm:push:bitbucket-mirror:tags": "git push --tags bitbucket-mirror",
142
- "scm:push:github": "run-p --aggregate-output scm:push:github:*",
143
- "scm:push:github:commits": "git push",
144
- "scm:push:github:tags": "git push --tags",
145
- "scm:push:gitlab-mirror": "run-p --aggregate-output scm:push:gitlab-mirror:*",
146
- "scm:push:gitlab-mirror:commits": "git push gitlab-mirror",
147
- "scm:push:gitlab-mirror:tags": "git push --tags gitlab-mirror",
148
- "scm:stage": "git add .",
149
- "test": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha",
150
- "test:i": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[I]\\]\"",
151
- "test:u": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[U]\\]\"",
152
- "test:e": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[E]\\]\"",
153
- "test:cover": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings c8 mocha",
154
- "test:glob": "set -f && test \"`bin/dependency-cruise.mjs --no-config test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
155
- "test:load": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
156
- "test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
157
- "test:load:cached": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --cache node_modules/.cache/dependency-cruiser/load-cached --no-progress\"",
158
- "test:load:cached:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --cache node_modules/.cache/dependency-cruiser/load-cached --no-progress\"",
159
- "update-dependencies": "npm-run-all upem:update upem:install build:clean build lint:eslint:clear-caches lint:fix depcruise test:cover",
160
- "upem-outdated": "npm outdated --json --long | upem --dry-run",
161
- "upem:install": "npm install",
162
- "upem:update": "npm outdated --json --long | upem | pbcopy && pbpaste",
163
- "version": "npm-run-all build depcruise:graph:doc scm:stage"
164
- },
165
101
  "dependencies": {
166
- "acorn": "8.11.2",
102
+ "acorn": "8.11.3",
167
103
  "acorn-jsx": "5.3.2",
168
104
  "acorn-jsx-walk": "2.0.0",
169
105
  "acorn-loose": "8.4.0",
170
- "acorn-walk": "8.3.1",
106
+ "acorn-walk": "8.3.2",
171
107
  "ajv": "8.12.0",
172
108
  "chalk": "5.3.0",
173
109
  "commander": "11.1.0",
@@ -187,48 +123,9 @@
187
123
  "semver-try-require": "6.2.3",
188
124
  "teamcity-service-messages": "0.1.14",
189
125
  "tsconfig-paths-webpack-plugin": "4.1.0",
190
- "watskeburt": "2.0.4",
126
+ "watskeburt": "2.0.5",
191
127
  "wrap-ansi": "9.0.0"
192
128
  },
193
- "devDependencies": {
194
- "@babel/core": "7.23.6",
195
- "@babel/plugin-transform-modules-commonjs": "7.23.3",
196
- "@babel/preset-typescript": "7.23.3",
197
- "@swc/core": "1.3.101",
198
- "@types/lodash": "4.14.202",
199
- "@types/node": "20.10.5",
200
- "@types/prompts": "2.4.9",
201
- "@typescript-eslint/eslint-plugin": "6.16.0",
202
- "@typescript-eslint/parser": "6.16.0",
203
- "@vue/compiler-sfc": "3.3.13",
204
- "c8": "8.0.1",
205
- "coffeescript": "2.7.0",
206
- "eslint": "8.56.0",
207
- "eslint-config-moving-meadow": "4.0.2",
208
- "eslint-config-prettier": "9.1.0",
209
- "eslint-plugin-budapestian": "6.0.0",
210
- "eslint-plugin-eslint-comments": "3.2.0",
211
- "eslint-plugin-import": "2.29.1",
212
- "eslint-plugin-mocha": "10.2.0",
213
- "eslint-plugin-node": "11.1.0",
214
- "eslint-plugin-security": "2.1.0",
215
- "eslint-plugin-unicorn": "^50.0.1",
216
- "husky": "8.0.3",
217
- "intercept-stdout": "0.1.2",
218
- "lint-staged": "15.2.0",
219
- "mocha": "10.2.0",
220
- "normalize-newline": "4.1.0",
221
- "npm-run-all": "4.1.5",
222
- "prettier": "3.1.1",
223
- "proxyquire": "2.1.3",
224
- "shx": "0.3.4",
225
- "svelte": "3.59.1",
226
- "symlink-dir": "5.2.1",
227
- "typescript": "5.3.3",
228
- "upem": "9.0.2",
229
- "vue-template-compiler": "2.7.16",
230
- "yarn": "1.22.21"
231
- },
232
129
  "overrides": {
233
130
  "semver": "^7.5.4",
234
131
  "postcss": "^8.4.31"
@@ -237,37 +134,10 @@
237
134
  "semver": "^7.5.4",
238
135
  "postcss": "^8.4.31"
239
136
  },
240
- "upem": {
241
- "policies": [
242
- {
243
- "package": "interpret",
244
- "policy": "wanted",
245
- "because": "we want to keep interpret ~similar to what webpack-cli uses (which is ^3.1.1 since 2022-11-15). See https://github.com/webpack/webpack-cli/blame/master/packages/webpack-cli/package.json"
246
- },
247
- {
248
- "package": "rechoir",
249
- "policy": "wanted",
250
- "because": "we want to keep rechoir ~similar to what webpack-cli uses (which is ^0.8.0 since 2022-11-15). See https://github.com/webpack/webpack-cli/blame/master/packages/webpack-cli/package.json"
251
- },
252
- {
253
- "package": "svelte",
254
- "policy": "pin",
255
- "because": "upgrading to supporting svelte 4 will require a non-trivial amount of labour (which we are going to invest, but not right now)"
256
- }
257
- ]
258
- },
259
137
  "engines": {
260
138
  "node": "^18.17||>=20"
261
139
  },
262
- "supportedTranspilers": {
263
- "babel": ">=7.0.0 <8.0.0",
264
- "coffee-script": ">=1.0.0 <2.0.0",
265
- "coffeescript": ">=1.0.0 <3.0.0",
266
- "livescript": ">=1.0.0 <2.0.0",
267
- "svelte": ">=3.0.0 <4.0.0",
268
- "swc": ">=1.0.0 <2.0.0",
269
- "typescript": ">=2.0.0 <6.0.0",
270
- "vue-template-compiler": ">=2.0.0 <3.0.0",
271
- "@vue/compiler-sfc": ">=3.0.0 <4.0.0"
140
+ "scripts": {
141
+ "test": "echo for test, build and static analysis scripts: see the github repository"
272
142
  }
273
143
  }
package/src/cli/index.mjs CHANGED
@@ -138,16 +138,27 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) {
138
138
  *
139
139
  * @param {string[]} pFileDirectoryArray
140
140
  * @param {import("../../types/options.mjs").ICruiseOptions} lCruiseOptions
141
+ * @param {{stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream}=} pStreams
141
142
  * @returns {number}
142
143
  */
143
- export default async function executeCli(pFileDirectoryArray, pCruiseOptions) {
144
+ // eslint-disable-next-line complexity
145
+ export default async function executeCli(
146
+ pFileDirectoryArray,
147
+ pCruiseOptions,
148
+ pStreams,
149
+ ) {
150
+ const lStreams = {
151
+ stdout: process.stdout,
152
+ stderr: process.stderr,
153
+ ...(pStreams || {}),
154
+ };
144
155
  let lCruiseOptions = pCruiseOptions || {};
145
156
  let lExitCode = 0;
146
157
 
147
158
  try {
148
159
  /* c8 ignore start */
149
160
  if (isInstalledGlobally) {
150
- process.stderr.write(
161
+ lStreams.stderr.write(
151
162
  `\n ${chalk.yellow(
152
163
  "WARNING",
153
164
  )}: You're running a globally installed dependency-cruiser.\n\n` +
@@ -164,15 +175,15 @@ export default async function executeCli(pFileDirectoryArray, pCruiseOptions) {
164
175
  const { default: formatMetaInfo } = await import(
165
176
  "./format-meta-info.mjs"
166
177
  );
167
- process.stdout.write(await formatMetaInfo());
178
+ lStreams.stdout.write(await formatMetaInfo());
168
179
  } else if (lCruiseOptions.init) {
169
180
  const { default: initConfig } = await import("./init-config/index.mjs");
170
- initConfig(lCruiseOptions.init);
181
+ initConfig(lCruiseOptions.init, null, lStreams);
171
182
  } else {
172
183
  lExitCode = await runCruise(pFileDirectoryArray, lCruiseOptions);
173
184
  }
174
185
  } catch (pError) {
175
- process.stderr.write(`\n ${chalk.red("ERROR")}: ${pError.message}\n`);
186
+ lStreams.stderr.write(`\n ${chalk.red("ERROR")}: ${pError.message}\n`);
176
187
  bus.emit("end");
177
188
  lExitCode = 1;
178
189
  }
@@ -330,7 +330,7 @@ module.exports = {
330
330
  If you have a 'conditionNames' attribute in your webpack config, that one will
331
331
  have precedence over the one specified here.
332
332
  */
333
- conditionNames: ["import", "require", "node", "default"],
333
+ conditionNames: ["import", "require", "node", "default", "types"],
334
334
  /*
335
335
  The extensions, by default are the same as the ones dependency-cruiser
336
336
  can access (run \`npx depcruise --info\` to see which ones that are in
@@ -75,8 +75,14 @@ function manifestIsUpdatable(pNormalizedInitConfig) {
75
75
  /**
76
76
  * @param {boolean|import("./types").OneShotConfigIDType} pInit
77
77
  * @param {string=} pConfigFileName
78
+ * @param {{stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream}=} pStreams
78
79
  */
79
- export default function initConfig(pInit, pConfigFileName) {
80
+ export default function initConfig(pInit, pConfigFileName, pStreams) {
81
+ const lStreams = {
82
+ stdout: process.stdout,
83
+ stderr: process.stderr,
84
+ ...pStreams,
85
+ };
80
86
  /* c8 ignore start */
81
87
  if (pInit === true) {
82
88
  getUserInput()
@@ -84,19 +90,33 @@ export default function initConfig(pInit, pConfigFileName) {
84
90
  .then(buildConfig)
85
91
  .then(writeConfig)
86
92
  .catch((pError) => {
87
- process.stderr.write(`\n ERROR: ${pError.message}\n`);
93
+ lStreams.stderr.write(`\n ERROR: ${pError.message}\n`);
88
94
  });
89
95
  /* c8 ignore stop */
90
96
  } else if (pInit !== false) {
91
97
  const lNormalizedInitConfig = normalizeInitOptions(getOneShotConfig(pInit));
92
98
  const lConfigFileName = pConfigFileName || getDefaultConfigFileName();
93
99
 
94
- if (!fileExists(lConfigFileName)) {
95
- writeConfig(buildConfig(lNormalizedInitConfig), lConfigFileName);
96
- }
97
-
98
100
  if (manifestIsUpdatable(lNormalizedInitConfig)) {
99
- writeRunScriptsToManifest(lNormalizedInitConfig);
101
+ // if we're going to update the manifest, no need to complain about
102
+ // a .dependency-cruiser that might already exist, because writing
103
+ // run scripts to the manifest could still work AOK.
104
+ if (!fileExists(lConfigFileName)) {
105
+ writeConfig(
106
+ buildConfig(lNormalizedInitConfig),
107
+ lConfigFileName,
108
+ lStreams.stdout,
109
+ );
110
+ }
111
+ writeRunScriptsToManifest(lNormalizedInitConfig, {
112
+ outStream: lStreams.stdout,
113
+ });
114
+ } else {
115
+ writeConfig(
116
+ buildConfig(lNormalizedInitConfig),
117
+ lConfigFileName,
118
+ lStreams.stdout,
119
+ );
100
120
  }
101
121
  }
102
122
  }
@@ -12,6 +12,7 @@ import {
12
12
  * @returns {void} Nothing
13
13
  * @param {string} pConfig - dependency-cruiser configuration
14
14
  * @param {import("fs").PathOrFileDescriptor} pFileName - name of the file to write to
15
+ * @param {NodeJS.WritableStream} pOutStream - the stream to write user feedback to
15
16
  * @throws {Error} An error object with the root cause of the problem
16
17
  * as a description:
17
18
  * - file already exists
@@ -20,22 +21,23 @@ import {
20
21
  */
21
22
  export default function writeConfig(
22
23
  pConfig,
23
- pFileName = getDefaultConfigFileName()
24
+ pFileName = getDefaultConfigFileName(),
25
+ pOutStream = process.stdout,
24
26
  ) {
25
27
  if (fileExists(pFileName)) {
26
28
  throw new Error(`A '${pFileName}' already exists here - leaving it be.\n`);
27
29
  } else {
28
30
  try {
29
31
  writeFileSync(pFileName, pConfig);
30
- process.stdout.write(
32
+ pOutStream.write(
31
33
  `\n ${chalk.green(
32
- figures.tick
33
- )} Successfully created '${pFileName}'\n\n`
34
+ figures.tick,
35
+ )} Successfully created '${pFileName}'\n\n`,
34
36
  );
35
37
  /* c8 ignore start */
36
38
  } catch (pError) {
37
39
  throw new Error(
38
- `ERROR: Writing to '${pFileName}' didn't work. ${pError}\n`
40
+ `ERROR: Writing to '${pFileName}' didn't work. ${pError}\n`,
39
41
  );
40
42
  }
41
43
  /* c8 ignore stop */
@@ -131,21 +131,30 @@ function getSuccessMessage(pDestinationManifestFileName) {
131
131
  );
132
132
  }
133
133
 
134
- export function writeRunScriptsToManifest(
135
- pNormalizedInitOptions,
136
- pManifest = readManifest(),
137
- pDestinationManifestFileName = PACKAGE_MANIFEST,
138
- ) {
134
+ /**
135
+ *
136
+ * @param {any} pNormalizedInitOptions
137
+ * @param {{manifest?: string, destinationManifestFileName?: string, outStream?: NodeJS.WritableStream}} pOptions
138
+ */
139
+ export function writeRunScriptsToManifest(pNormalizedInitOptions, pOptions) {
140
+ const lOptions = {
141
+ manifest: readManifest(),
142
+ destinationManifestFileName: PACKAGE_MANIFEST,
143
+ outStream: process.stdout,
144
+ ...pOptions,
145
+ };
139
146
  const lUpdatedManifest = addRunScriptsToManifest(
140
- pManifest,
147
+ lOptions.manifest,
141
148
  compileRunScripts(pNormalizedInitOptions),
142
149
  );
143
150
 
144
151
  writeFileSync(
145
- pDestinationManifestFileName,
152
+ lOptions.destinationManifestFileName,
146
153
  JSON.stringify(lUpdatedManifest, null, " "),
147
154
  "utf8",
148
155
  );
149
156
 
150
- process.stdout.write(getSuccessMessage(pDestinationManifestFileName));
157
+ lOptions.outStream.write(
158
+ getSuccessMessage(lOptions.destinationManifestFileName),
159
+ );
151
160
  }
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "16.0.0",
4
+ version: "16.1.0",
5
5
  engines: {
6
6
  node: "^18.17||>=20",
7
7
  },