diff --git a/src/extract/resolve/module-classifiers.mjs b/src/extract/resolve/module-classifiers.mjs index 6a4c7e45a..ee600b788 100644 --- a/src/extract/resolve/module-classifiers.mjs +++ b/src/extract/resolve/module-classifiers.mjs @@ -168,8 +168,15 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) { // oh and: ```picomatch.isMatch('asdf', 'asdf/**') === true``` so // in case it's only 'asdf' that's in the resolved module name for some reason // we're good as well. + // + // workspaces is supposed to be array of strings, where each string is + // a glob pattern. However, in the field there's occasions where it's + // not a string. We'll just ignore those for now, hence the presence of + // the `typeof pWorkspace === "string"` check. const lModuleFriendlyWorkspaceGlobs = lWorkspaces.map((pWorkspace) => - pWorkspace.endsWith("/") ? `${pWorkspace}**` : `${pWorkspace}/**`, + typeof pWorkspace === "string" && pWorkspace.endsWith("/") + ? `${pWorkspace}**` + : `${pWorkspace}/**`, ); if (picomatch.isMatch(pResolvedModuleName, lModuleFriendlyWorkspaceGlobs)) { return true; diff --git a/test/extract/resolve/module-classifiers.get-alias-types.spec.mjs b/test/extract/resolve/module-classifiers.get-alias-types.spec.mjs index 52ca0157d..2dbef29c8 100644 --- a/test/extract/resolve/module-classifiers.get-alias-types.spec.mjs +++ b/test/extract/resolve/module-classifiers.get-alias-types.spec.mjs @@ -293,6 +293,44 @@ describe("[I] extract/resolve/module-classifiers - getAliasTypes", () => { ); }); + it("doesn't run aliased and aliased-workspace for when workspaces is an array, but the entry isn't a string", () => { + const lManifest = { + name: "test", + version: "1.0.0", + dependencies: {}, + workspaces: [{ "packages/*": "packages/*" }], + }; + const lResolveOptions = {}; + deepEqual( + getAliasTypes( + "some-workspaced-local-package", + "packages/a-package/index.js", + lResolveOptions, + lManifest, + ), + [], + ); + }); + + it("skips over entries in the workspaces array that aren't string, but still uses the rest", () => { + const lManifest = { + name: "test", + version: "1.0.0", + dependencies: {}, + workspaces: [{ "packages/*": "packages/*" }, "packages/*"], + }; + const lResolveOptions = {}; + deepEqual( + getAliasTypes( + "some-workspaced-local-package", + "packages/a-package/index.js", + lResolveOptions, + lManifest, + ), + ["aliased", "aliased-workspace"], + ); + }); + it("classifies as a webpack alias if it could be both a webpack alias _and_ a workspace alias", () => { const lManifest = { name: "test",