Skip to content

Commit 60f4bd2

Browse files
authored
Ignore packages inside node_modules from nohoist usage (#527)
1 parent c296a69 commit 60f4bd2

File tree

9 files changed

+53
-1
lines changed

9 files changed

+53
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
node_modules/
22

3+
# Any node_modules in test fixtures are allowed.
4+
!test/fixtures/**/node_modules/
5+
36
dist/
47

58
.eslintcache

lib/workspace.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ function expandWorkspaces(root: string, workspacePatterns: string[]): string[] {
125125
return [workspace];
126126
}
127127
// 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
128-
return globbySync(workspace, { onlyDirectories: true, cwd: root });
128+
// Ignore any node_modules that may be present due to the use of nohoist.
129+
return globbySync(workspace, {
130+
onlyDirectories: true,
131+
cwd: root,
132+
ignore: ['**/node_modules'],
133+
});
129134
});
130135
}
131136

test/fixtures/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export const FIXTURE_PATH_VALID_WITH_PACKAGES = join(
5252
FIXTURE_PATH,
5353
'valid-with-packages'
5454
);
55+
export const FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES = join(
56+
FIXTURE_PATH,
57+
'valid-nohoist-with-node-modules'
58+
);
5559
export const FIXTURE_PATH_WORKSPACE_PACKAGE_NOT_AN_ARRAY = join(
5660
FIXTURE_PATH,
5761
'workspace-packages-not-an-array'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"workspaces": {
3+
"packages": [
4+
"packages/**"
5+
],
6+
"nohoist": [
7+
"**/resolve"
8+
]
9+
}
10+
}

test/fixtures/valid-nohoist-with-node-modules/packages/package-a/node_modules/resolve/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/valid-nohoist-with-node-modules/packages/package-a/node_modules/resolve/test/resolver/malformed_package_json/package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "package-a",
3+
"dependencies": {
4+
"resolve": "^1.22.1"
5+
}
6+
}

test/fixtures/valid/node_modules/should-be-ignored/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/lib/workspace-test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FIXTURE_PATH_NO_PACKAGE_JSON,
66
FIXTURE_PATH_VALID,
77
FIXTURE_PATH_VALID_WITH_PACKAGES,
8+
FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES,
89
FIXTURE_PATH_WORKSPACE_NOT_AN_ARRAY,
910
FIXTURE_PATH_WORKSPACE_PACKAGE_NOT_AN_ARRAY,
1011
FIXTURE_PATH_NESTED_WORKSPACES,
@@ -162,6 +163,22 @@ describe('Utils | workspace', function () {
162163
].map((path) => join(FIXTURE_PATH_NESTED_WORKSPACES, path))
163164
);
164165
});
166+
167+
it('does not include packages in node_modules from nohoist usage (or crash from malformed package.json in node_modules test fixture)', function () {
168+
expect(
169+
getPackages(
170+
FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES,
171+
[],
172+
[],
173+
[],
174+
[]
175+
).map((package_) => package_.path)
176+
).toStrictEqual(
177+
['.', '/packages/package-a'].map((path) =>
178+
join(FIXTURE_PATH_VALID_NOHOIST_WITH_NODE_MODULES, path)
179+
)
180+
);
181+
});
165182
});
166183

167184
describe('#getWorkspaces', function () {

0 commit comments

Comments
 (0)