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

declined:
- "@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-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/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ exports[`Commands workspace <workspace-name> <sub-command> runs a given command
}
`;

exports[`Commands workspace <workspace-name> <sub-command> should preserve INIT_CWD to the original value 1`] = `
{
"code": 0,
"stderr": "",
"stdout": "docs",
}
`;

exports[`Commands workspace <workspace-name> <sub-command> when the given workspace doesnt exist lists all possible workspaces 1`] = `
{
"code": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe(`Commands`, () => {
);

test(
`should preserve INIT_CWD to the original value`,
`should run set INIT_CWD to each individual workspace cwd`,
makeTemporaryEnv(
{
private: true,
Expand All @@ -81,20 +81,11 @@ describe(`Commands`, () => {
async ({path, run}) => {
await setupWorkspaces(path);

let code;
let stdout;
let stderr;
await run(`install`);

try {
await run(`install`);
({code, stdout, stderr} = await run(`workspace`, `component-a`, `run`, `printInitCwd`, {cwd: ppath.join(path, `docs`)}));
} catch (error) {
({code, stdout, stderr} = error);
}

stdout = ppath.relative(path, npath.toPortablePath(stdout.trim()));

await expect({code, stdout, stderr}).toMatchSnapshot();
await expect(run(`workspace`, `component-a`, `run`, `printInitCwd`, {cwd: ppath.join(path, `docs`)})).resolves.toMatchObject({
stdout: `${npath.join(npath.fromPortablePath(path), `components/component-a`)}\n`,
});
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,23 @@ exports[`Commands workspace foreach should run scripts in parallel but following
}
`;

exports[`Commands workspace foreach should run set INIT_CWD to each individual workspace cwd even with global scripts 1`] = `
{
"code": 0,
"stderr": "",
"stdout": "
packages/workspace-a
packages/workspace-b
packages/workspace-c
packages/workspace-c/packages/workspace-d
packages/workspace-c/packages/workspace-d/packages/workspace-e
packages/workspace-c/packages/workspace-f
packages/workspace-c/packages/workspace-g
Done
",
}
`;

exports[`Commands workspace foreach should start all the processes at once when --jobs is unlimited 1`] = `
{
"code": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ describe(`Commands`, () => {
),
);

test(
`should run set INIT_CWD to each individual workspace cwd even with global scripts`,
makeTemporaryEnv(
{
private: true,
workspaces: [`packages/*`],
scripts: {
[`test:foo`]: `yarn workspaces foreach --all run test:bar`,
[`test:bar`]: `node -p 'require("path").relative(process.cwd(), process.argv[1]).replace(/\\\\/g, "/")' "$INIT_CWD"`,
},
},
async ({path, run}) => {
await setupWorkspaces(path);
await run(`install`);

await expect(run(`test:foo`)).resolves.toMatchSnapshot();
},
),
);

test(
`should handle global scripts getting downgraded to a normal script`,
makeTemporaryEnv(
Expand Down
10 changes: 4 additions & 6 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ export async function detectPackageManager(location: PortablePath): Promise<Pack
case `yarn`: {
const packageManager = Number(major) === 1 ? PackageManager.Yarn1 : PackageManager.Yarn2;
return {packageManagerField: true, packageManager, reason};
} break;

}
case `npm`: {
return {packageManagerField: true, packageManager: PackageManager.Npm, reason};
} break;

}
case `pnpm`: {
return {packageManagerField: true, packageManager: PackageManager.Pnpm, reason};
} break;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why, but my IDE constantly removes those statements by itself. It's technically correct, but really annoying to have those unrelated changes every time I update the file.

Copy link
Member

@merceyz merceyz Nov 3, 2023

Choose a reason for hiding this comment

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

A global eslint config or a different extension perhaps?

}
}
}
}
Expand Down Expand Up @@ -140,7 +138,7 @@ export async function makeScriptEnv({project, locator, binFolder, ignoreCorepack
]);

if (project) {
scriptEnv.INIT_CWD = npath.cwd();
scriptEnv.INIT_CWD = npath.fromPortablePath(project.configuration.startingCwd);
scriptEnv.PROJECT_CWD = npath.fromPortablePath(project.cwd);
}

Expand Down