Skip to content

Commit

Permalink
Ignore packages inside node_modules from nohoist usage (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Sep 23, 2022
1 parent c296a69 commit 60f4bd2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules/

# Any node_modules in test fixtures are allowed.
!test/fixtures/**/node_modules/

dist/

.eslintcache
Expand Down
7 changes: 6 additions & 1 deletion lib/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ function expandWorkspaces(root: string, workspacePatterns: string[]): string[] {
return [workspace];
}
// Use cwd instead of passing join()'d paths to globby for Windows support: https://github.com/micromatch/micromatch/blob/34f44b4f57eacbdbcc74f64252e0845cf44bbdbd/README.md?plain=1#L822
return globbySync(workspace, { onlyDirectories: true, cwd: root });
// Ignore any node_modules that may be present due to the use of nohoist.
return globbySync(workspace, {
onlyDirectories: true,
cwd: root,
ignore: ['**/node_modules'],
});
});
}

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const FIXTURE_PATH_VALID_WITH_PACKAGES = join(
FIXTURE_PATH,
'valid-with-packages'
);
export const FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES = join(
FIXTURE_PATH,
'valid-nohoist-with-node-modules'
);
export const FIXTURE_PATH_WORKSPACE_PACKAGE_NOT_AN_ARRAY = join(
FIXTURE_PATH,
'workspace-packages-not-an-array'
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/valid-nohoist-with-node-modules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"workspaces": {
"packages": [
"packages/**"
],
"nohoist": [
"**/resolve"
]
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "package-a",
"dependencies": {
"resolve": "^1.22.1"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions test/lib/workspace-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FIXTURE_PATH_NO_PACKAGE_JSON,
FIXTURE_PATH_VALID,
FIXTURE_PATH_VALID_WITH_PACKAGES,
FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES,
FIXTURE_PATH_WORKSPACE_NOT_AN_ARRAY,
FIXTURE_PATH_WORKSPACE_PACKAGE_NOT_AN_ARRAY,
FIXTURE_PATH_NESTED_WORKSPACES,
Expand Down Expand Up @@ -162,6 +163,22 @@ describe('Utils | workspace', function () {
].map((path) => join(FIXTURE_PATH_NESTED_WORKSPACES, path))
);
});

it('does not include packages in node_modules from nohoist usage (or crash from malformed package.json in node_modules test fixture)', function () {
expect(
getPackages(
FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES,
[],
[],
[],
[]
).map((package_) => package_.path)
).toStrictEqual(
['.', '/packages/package-a'].map((path) =>
join(FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES, path)
)
);
});
});

describe('#getWorkspaces', function () {
Expand Down

0 comments on commit 60f4bd2

Please sign in to comment.