dependency-cruiser 15.5.0 → 16.0.0-beta-1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "15.5.0",
3
+ "version": "16.0.0-beta-1",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -8,16 +8,31 @@ const typescript = await tryImport(
8
8
  meta.supportedTranspilers.typescript,
9
9
  );
10
10
 
11
- function isTypeOnly(pStatement) {
11
+ function isTypeOnlyImport(pStatement) {
12
+ return (
13
+ pStatement.importClause &&
14
+ (pStatement.importClause.isTypeOnly ||
15
+ (pStatement.importClause.namedBindings &&
16
+ pStatement.importClause.namedBindings.elements &&
17
+ pStatement.importClause.namedBindings.elements.every(
18
+ (pElement) => pElement.isTypeOnly,
19
+ )))
20
+ );
21
+ }
22
+
23
+ function isTypeOnlyExport(pStatement) {
12
24
  return (
13
- (pStatement.importClause && pStatement.importClause.isTypeOnly) ||
14
25
  // for some reason the isTypeOnly indicator is on _statement_ level
15
26
  // and not in exportClause as it is in the importClause ¯\_ (ツ)_/¯.
16
27
  // Also in the case of the omission of an alias the exportClause
17
28
  // is not there entirely. So regardless whether there is a
18
29
  // pStatement.exportClause or not, we can directly test for the
19
30
  // isTypeOnly attribute.
20
- pStatement.isTypeOnly
31
+ pStatement.isTypeOnly ||
32
+ // named reexports are per-element though
33
+ (pStatement.exportClause &&
34
+ pStatement.exportClause.elements &&
35
+ pStatement.exportClause.elements.every((pElement) => pElement.isTypeOnly))
21
36
  );
22
37
  }
23
38
 
@@ -47,7 +62,9 @@ function extractImportsAndExports(pAST) {
47
62
  module: pStatement.moduleSpecifier.text,
48
63
  moduleSystem: "es6",
49
64
  exoticallyRequired: false,
50
- ...(isTypeOnly(pStatement) ? { dependencyTypes: ["type-only"] } : {}),
65
+ ...(isTypeOnlyImport(pStatement) || isTypeOnlyExport(pStatement)
66
+ ? { dependencyTypes: ["type-only"] }
67
+ : {}),
51
68
  }));
52
69
  }
53
70
 
@@ -24,12 +24,12 @@ function mergeDependencyArray(pClosestDependencyKey, pFurtherDependencyKey) {
24
24
  return uniq(pClosestDependencyKey.concat(pFurtherDependencyKey));
25
25
  }
26
26
 
27
- function isDependencyKey(pKey) {
28
- return pKey.endsWith("ependencies");
27
+ function isInterestingKey(pKey) {
28
+ return pKey.endsWith("ependencies") || pKey === "workspaces";
29
29
  }
30
30
 
31
31
  function getDependencyKeys(pPackage) {
32
- return Object.keys(pPackage).filter(isDependencyKey);
32
+ return Object.keys(pPackage).filter(isInterestingKey);
33
33
  }
34
34
 
35
35
  function getJointUniqueDependencyKeys(pClosestPackage, pFurtherPackage) {
@@ -40,6 +40,10 @@ function getJointUniqueDependencyKeys(pClosestPackage, pFurtherPackage) {
40
40
  );
41
41
  }
42
42
 
43
+ function isAnArrayKey(pKey) {
44
+ return pKey.startsWith("bundle") || pKey === "workspaces";
45
+ }
46
+
43
47
  /**
44
48
  * returns an object with
45
49
  * - the *dependencies keys from both passed packages
@@ -63,7 +67,7 @@ export default function mergeManifests(pClosestManifest, pFurtherManifest) {
63
67
  )
64
68
  .map((pKey) => ({
65
69
  key: pKey,
66
- value: pKey.startsWith("bundle")
70
+ value: isAnArrayKey(pKey)
67
71
  ? mergeDependencyArray(
68
72
  pClosestManifest?.[pKey] ?? [],
69
73
  pFurtherManifest?.[pKey] ?? [],
@@ -154,7 +154,7 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) {
154
154
  //
155
155
  // oh and: ```picomatch.isMatch('asdf', 'asdf/**') === true``` so
156
156
  // in case it's only 'asdf' that's in the resolved module name for some reason
157
- // we're good as well.
157
+ // we're good as well.
158
158
  const lModuleFriendlyWorkspaceGlobs = pManifest.workspaces.map(
159
159
  (pWorkspace) =>
160
160
  pWorkspace.endsWith("/") ? `${pWorkspace}**` : `${pWorkspace}/**`,
@@ -185,7 +185,7 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) {
185
185
  /**
186
186
  * @param {string} pModuleName
187
187
  * @param {string} pResolvedModuleName
188
- * @param {import("../../../types/resolve-options").IResolveOptions} pResolveOptions
188
+ * @param {import("../../../types/resolve-options.mjs").IResolveOptions} pResolveOptions
189
189
  * @param {string} pBaseDirectory
190
190
  * @returns {boolean}
191
191
  */
@@ -206,7 +206,7 @@ function isLikelyTSAliased(
206
206
  /**
207
207
  * @param {string} pModuleName
208
208
  * @param {string} pResolvedModuleName
209
- * @param {import("../../../types/resolve-options").IResolveOptions} pResolveOptions
209
+ * @param {import("../../../types/resolve-options.mjs").IResolveOptions} pResolveOptions
210
210
  * @param {object} pManifest
211
211
  * @returns {string[]}
212
212
  */
@@ -216,15 +216,32 @@ export function getAliasTypes(
216
216
  pResolveOptions,
217
217
  pManifest,
218
218
  ) {
219
- if (isSubpathImport(pModuleName, pManifest)) {
220
- return ["aliased", "aliased-subpath-import"];
219
+ if (isRelativeModuleName(pModuleName)) {
220
+ return [];
221
221
  }
222
+ // the order of these ifs is deliberate. First stuff bolted on by bundlers & transpilers.
222
223
  if (isWebPackAliased(pModuleName, pResolveOptions.alias)) {
223
224
  return ["aliased", "aliased-webpack"];
224
225
  }
226
+ // The order of subpath imports and workspaces isn't _that_ important, as they
227
+ // can't be confused
228
+ // - subpath imports _must_ start with a #
229
+ // - workspaces (or, more precise: package names) are forbidden to even _contain_ a #
230
+ if (isSubpathImport(pModuleName, pManifest)) {
231
+ return ["aliased", "aliased-subpath-import"];
232
+ }
225
233
  if (isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest)) {
226
234
  return ["aliased", "aliased-workspace"];
227
235
  }
236
+ // We'd like to classify for ts config paths/ aliases earlier, but it's currently
237
+ // partly guess work (the resolver wouldn't know, so it'd mean checking
238
+ // against the tsconfig paths _again_ here which might not be conducive to
239
+ // performance).
240
+ // Putting it last is close enough for now because
241
+ // - it's not a common scenario to have _both_ tsconfig paths and one of the
242
+ // other (clearly superior) aliasing mechanisms
243
+ // - if it does happen it's even less likely to have the same names for both
244
+ // in both mechanisms
228
245
  if (
229
246
  isLikelyTSAliased(
230
247
  pModuleName,
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "15.5.0",
4
+ version: "16.0.0-beta-1",
5
5
  engines: {
6
6
  node: "^18.17||>=20",
7
7
  },