Skip to content
Open
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
36 changes: 36 additions & 0 deletions .yarn/versions/607ebb1b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
releases:
"@yarnpkg/core": patch

declined:
- "@yarnpkg/plugin-catalog"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-jsr"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/cli"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe(`Commands`, () => {
});

expect(manifest.resolutions).toEqual({
[`no-deps@npm:1.0.0`]: expect.stringMatching(/^patch:no-deps/),
[`no-deps@npm:1.0.0`]: expect.stringMatching(/^patch:no-deps/),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was auto-generated when running yarn test:lint --fix

Without this change, I get the following error in CI:

/home/runner/work/berry/berry/packages/acceptance-tests/pkg-tests-specs/sources/commands/patchCommit.test.ts
Error:   117:1  error  Expected indentation of 10 spaces but found 8  @stylistic/indent

});
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ describe(`Workspaces tests`, () => {
}),
);

test(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two tests that I've added here are duplicates of tests that already exist in this file, however these new tests have the enableWorkspacePatternAnalysis configuration turned on.

`it should support basic glob patterns with enableWorkspacePatternAnalysis`,
makeTemporaryMonorepoEnv({
workspaces: [
`packages/*`,
],
}, {
[`packages/foo`]: {},
[`packages/bar`]: {},
[`packages/baz`]: {},
}, async ({path, run, source}) => {
await run(`config`, `set`, `enableWorkspacePatternAnalysis`, `true`);
await expect(getWorkspaces(run)).resolves.toStrictEqual([
`.`,
`packages/bar`,
`packages/baz`,
`packages/foo`,
]);
}),
);

test(
`it should support negated glob patterns`,
makeTemporaryMonorepoEnv({
Expand All @@ -55,6 +76,27 @@ describe(`Workspaces tests`, () => {
}),
);

test(
`it should support negated glob patterns with enableWorkspacePatternAnalysis`,
makeTemporaryMonorepoEnv({
workspaces: [
`packages/*`,
`!packages/foo`,
],
}, {
[`packages/foo`]: {},
[`packages/bar`]: {},
[`packages/baz`]: {},
}, async ({path, run, source}) => {
await run(`config`, `set`, `enableWorkspacePatternAnalysis`, `true`);
await expect(getWorkspaces(run)).resolves.toStrictEqual([
`.`,
`packages/bar`,
`packages/baz`,
]);
}),
);

test(
`it should not implicitly make workspaces require-able`,
makeTemporaryEnv(
Expand Down
5 changes: 5 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
type: SettingsType.STRING,
default: `npm:`,
},
enableWorkspacePatternAnalysis: {
description: `If true, optimizes workspace pattern matching by separating static and dynamic globs for better performance when using mostly static patterns.`,
type: SettingsType.BOOLEAN,
default: false,
},
enableTransparentWorkspaces: {
description: `If false, Yarn won't automatically resolve workspace dependencies unless they use the \`workspace:\` protocol`,
type: SettingsType.BOOLEAN,
Expand Down
29 changes: 26 additions & 3 deletions packages/yarnpkg-core/sources/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,40 @@ export class Workspace {
// @ts-expect-error: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
this.anchoredLocator = structUtils.makeLocator(ident, `${WorkspaceResolver.protocol}${this.relativeCwd}`);

const patterns = this.manifest.workspaceDefinitions.map(({pattern}) => pattern);
const workspaceDefinitionPatterns = this.manifest.workspaceDefinitions.map(({pattern}) => pattern);

if (patterns.length === 0)
if (workspaceDefinitionPatterns.length === 0)
return;

const relativeCwds = await fastGlob(patterns, {
const resolvePatternsWithAnalysis = async () => {
const staticPatterns: Array<string> = [];
const dynamicPatterns: Array<string> = [];

for (const pattern of workspaceDefinitionPatterns) {
if (fastGlob.isDynamicPattern(pattern)) {
dynamicPatterns.push(pattern);
} else {
staticPatterns.push(pattern);
}
}

const globResults = dynamicPatterns.length > 0
? await resolveGlobPatterns(dynamicPatterns)
: [];

return [...staticPatterns, ...globResults];
};

const resolveGlobPatterns = (globPatterns: Array<string>) => fastGlob(globPatterns, {
cwd: npath.fromPortablePath(this.cwd),
onlyDirectories: true,
ignore: [`**/node_modules`, `**/.git`, `**/.yarn`],
});

const relativeCwds = this.project.configuration.get(`enableWorkspacePatternAnalysis`) ?
await resolvePatternsWithAnalysis() :
await resolveGlobPatterns(workspaceDefinitionPatterns);

// fast-glob returns results in arbitrary order
relativeCwds.sort();

Expand Down