Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extract): ignore entries in 'workspaces' arrays that aren't strings (instead of throwing) #955

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/extract/resolve/module-classifiers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions test/extract/resolve/module-classifiers.get-alias-types.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down