dependency-cruiser 16.2.3 → 16.2.4-beta-2

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": "16.2.3",
3
+ "version": "16.2.4-beta-2",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -122,6 +122,16 @@ function isWebPackAliased(pModuleName, pAliasObject) {
122
122
  );
123
123
  }
124
124
 
125
+ function getWorkspacesArray(pManifestWorkspacesField) {
126
+ if (Array.isArray(pManifestWorkspacesField)) {
127
+ return pManifestWorkspacesField;
128
+ }
129
+ if (pManifestWorkspacesField?.packages) {
130
+ return pManifestWorkspacesField.packages;
131
+ }
132
+ return [];
133
+ }
134
+
125
135
  /**
126
136
  * @param {string} pModuleName
127
137
  * @param {string} pResolvedModuleName
@@ -131,7 +141,11 @@ function isWebPackAliased(pModuleName, pAliasObject) {
131
141
  // eslint-disable-next-line max-lines-per-function
132
142
  function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) {
133
143
  // reference: https://docs.npmjs.com/cli/v10/using-npm/workspaces
134
- if (pManifest?.workspaces) {
144
+ // for yarn the workspaces field might be either an array or
145
+ // an object. To prevent the code from borking we check whether it's an array
146
+ // see https://github.com/sverweij/dependency-cruiser/issues/919
147
+ const lWorkspaces = getWorkspacesArray(pManifest?.workspaces);
148
+ if (lWorkspaces.length >= 0) {
135
149
  // workspaces are an array of globs that match the (sub) workspace
136
150
  // folder itself only.
137
151
  //
@@ -154,9 +168,8 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) {
154
168
  // oh and: ```picomatch.isMatch('asdf', 'asdf/**') === true``` so
155
169
  // in case it's only 'asdf' that's in the resolved module name for some reason
156
170
  // we're good as well.
157
- const lModuleFriendlyWorkspaceGlobs = pManifest.workspaces.map(
158
- (pWorkspace) =>
159
- pWorkspace.endsWith("/") ? `${pWorkspace}**` : `${pWorkspace}/**`,
171
+ const lModuleFriendlyWorkspaceGlobs = lWorkspaces.map((pWorkspace) =>
172
+ pWorkspace.endsWith("/") ? `${pWorkspace}**` : `${pWorkspace}/**`,
160
173
  );
161
174
  if (picomatch.isMatch(pResolvedModuleName, lModuleFriendlyWorkspaceGlobs)) {
162
175
  return true;
package/src/meta.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "16.2.3",
4
+ version: "16.2.4-beta-2",
5
5
  engines: {
6
6
  node: "^18.17||>=20",
7
7
  },