-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
workspace glob exclusions #15164
base: main
Are you sure you want to change the base?
workspace glob exclusions #15164
Conversation
The reason for a draft PR is that right now I have it so the order in which workspace packages are defined in the root package.json matters. For example this test is passing test("workspace entry order matters", async () => {
await Promise.all([
write(
join(packageDir, "package.json"),
JSON.stringify({
name: "foo",
workspaces: [
"packages/*",
"!packages/re-excluded-pkg",
"packages/re-excluded-pkg",
"!packages/re-excluded-pkg",
"!packages/re-included-pkg",
"packages/re-included-pkg",
],
}),
),
write(
join(packageDir, "packages", "re-excluded-pkg", "package.json"),
JSON.stringify({
name: "re-excluded-pkg",
dependencies: { },
}),
),
write(
join(packageDir, "packages", "re-included-pkg", "package.json"),
JSON.stringify({
name: "re-included-pkg",
dependencies: { },
}),
)
]);
await runBunInstall(env, packageDir);
const filesInNodeModules = await readdir(join(packageDir, "node_modules"));
expect(filesInNodeModules).not.toContain("re-excluded-pkg");
expect(filesInNodeModules).toContain("re-included-pkg");
}) However I'm now questioning if that behavior is actually confusing because {
"workspaces": [
"!packages/excluded",
"packages/*"
]
} Note that without order-based precedence or complex logic to figure out what the user is trying to do something like the following would result in {
"workspaces": [
"!packages/*",
"packages/included"
]
} I am leaning towards ignoring order and having exclusions always outweigh inclusions but felt it would be better to check first so the ux is acceptable. |
060aba1
to
48c1d69
Compare
899957d
to
2716e39
Compare
After some further research (scraping open source pnpm-workspace.json files on github) and analyzing the use of exclusions in those workspaces I've determined that my initial assumptions were correct, and that additionally most people assume that exclusions have higher precedence than inclusions, and therefore my implementation should not allow re-including workspaces after they have been excluded based on order. |
I would appreciate some input on how to best test windows paths in the workspaces array, otherwise I feel this is ready to go |
What does this PR do?
Adds the ability to exclude packages from a workspace using
!
glob syntaxImplemented by preventing excluded directories from ever being added to
workspace_names
while processing the workspace names array.This is accomplished by creating a hashmap of the excluded paths which are computed using GlobWalker before processing the rest of the entries in the workspace names array. The remaining paths are not added to
workspace_names
if they are present in the excluded path map.This should have little to no overhead when there are no workspace exclusions as the only changes to the original algorithm are
The assumptions that informed my decision to go with this implementation were
GlobWalker
to get all of the valid paths described by each exclusion so they can be stored individually risks high memory usage when many paths are excluded, it is simple to implement/understand, robust, and requires much less bespoke logic than say trying to check each workspace path to see if it matches one of the exclusion globsHow did you verify your code works?
bun-debug test bun-workspaces.test
)Still TODO