Skip to content

feat: add run --global option #4502

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
- name: 'Build the standard bundle'
if: steps.cache-build.outputs.cache-hit != 'true'
run: |
node ./scripts/run-yarn.js build:cli
node ./scripts/run-yarn.js run --global build:cli
shell: bash
#endregion

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ jobs:
- name: 'Build bundle & plugins'
run: |
node --version
node ./scripts/run-yarn.js build:pnp:hook
node ./scripts/run-yarn.js build:cli
node ./scripts/run-yarn.js run --global build:pnp:hook
node ./scripts/run-yarn.js run --global build:cli
mv ./packages/yarnpkg-cli/bundles/yarn.js ./packages/yarnpkg-cli/bundles/yarn-min.js
node ./scripts/run-yarn.js build:cli --no-minify
node ./scripts/run-yarn.js run --global build:cli --no-minify
shell: bash

- uses: actions/upload-artifact@v2
Expand All @@ -174,7 +174,7 @@ jobs:

- name: 'Build vscode-zipfs'
run: |
node ./scripts/run-yarn.js package:vscode-zipfs
node ./scripts/run-yarn.js run --global package:vscode-zipfs
if: |
success() || failure()

Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:

- name: 'Run the integration tests'
run: |
node ./scripts/run-yarn.js test:integration --runInBand
node ./scripts/run-yarn.js run --global test:integration --runInBand
shell: bash

- name: 'Run the unit tests'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: 'Build the standard bundle'
run: |
set -ex
node ./scripts/run-yarn.js build:cli
node ./scripts/run-yarn.js run --global build:cli

- name: 'Build the dist directory'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/plugin-compat-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:

- name: 'Run the plugin-compat tests'
run: |
node ./scripts/run-yarn.js test:plugin-compat
node ./scripts/run-yarn.js run --global test:plugin-compat
40 changes: 40 additions & 0 deletions .yarn/versions/c5422023.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
releases:
"@yarnpkg/plugin-essentials": major

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@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/cli"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/fslib"
- "@yarnpkg/json-proxy"
- "@yarnpkg/libzip"
- "@yarnpkg/nm"
- "@yarnpkg/parsers"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
- "@yarnpkg/shell"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:
- Some legacy layers have been sunset:
- Plugins cannot access the Clipanion 2 APIs anymore (upgrade to [Clipanion 3](https://github.com/arcanis/clipanion))
- Plugins cannot access the internal copy of Yup anymore (use [Typanion](https://github.com/arcanis/typanion) instead)
- Scripts containing a colon are no longer implicitly global. The `--global` option should be used instead.

### **API Changes**

Expand Down
2 changes: 1 addition & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ gen_enforced_field(WorkspaceCwd, 'scripts.update-local', '<any value>') :-
inline_compile('@yarnpkg/eslint-config').
inline_compile('@yarnpkg/libui').

gen_enforced_field(WorkspaceCwd, 'scripts.prepack', 'run build:compile "$(pwd)"') :-
gen_enforced_field(WorkspaceCwd, 'scripts.prepack', 'run --global build:compile "$(pwd)"') :-
workspace(WorkspaceCwd),
% This package is built using Rollup, so we allow it to configure its build scripts itself
\+ workspace_ident(WorkspaceCwd, '@yarnpkg/pnp'),
Expand Down
2 changes: 1 addition & 1 deletion packages/acceptance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"pkg-tests-core": "workspace:^"
},
"scripts": {
"test:integration": "run test:unit --config \"$(pwd)/jest.config.js\""
"test:integration": "run --global test:unit --config \"$(pwd)/jest.config.js\""
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe(`Commands`, () => {
await setupWorkspaces(path);
await run(`install`);

await expect(run(`workspaces`, `foreach`, `--topological`, `run`, `test:colon`)).resolves.toMatchSnapshot();
await expect(run(`workspaces`, `foreach`, `--topological`, `run`, `--global`, `test:colon`)).resolves.toMatchSnapshot();
},
),
);
Expand All @@ -411,7 +411,7 @@ describe(`Commands`, () => {
await setupWorkspaces(path);
await run(`install`);

await expect(run(`test:foo`)).resolves.toMatchSnapshot();
await expect(run(`run`, `--global`, `test:foo`)).resolves.toMatchSnapshot();
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe(`Node_Modules`, () => {

await run(`install`);

expect((await run(`run`, `ws:cwd`)).stdout.trim()).toEqual(npath.fromPortablePath(`${path}/packages/workspace`));
expect((await run(`run`, `--global`, `ws:cwd`)).stdout.trim()).toEqual(npath.fromPortablePath(`${path}/packages/workspace`));
},
),
);
Expand Down
10 changes: 5 additions & 5 deletions packages/acceptance-tests/pkg-tests-specs/sources/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ describe(`Scripts tests`, () => {

await run(`install`);

await expect(run(`run`, `test:script`)).resolves.toMatchObject({
await expect(run(`run`, `--global`, `test:script`)).resolves.toMatchObject({
stdout: `${npath.fromPortablePath(path)}\n`,
});

await expect(run(`run`, `test:script`, {
await expect(run(`run`, `--global`, `test:script`, {
cwd: `${path}/packages`,
})).resolves.toMatchObject({
stdout: `${npath.fromPortablePath(`${path}/packages`)}\n`,
Expand All @@ -107,11 +107,11 @@ describe(`Scripts tests`, () => {

await run(`install`);

await expect(run(`run`, `test:script`)).resolves.toMatchObject({
await expect(run(`run`, `--global`, `test:script`)).resolves.toMatchObject({
stdout: `${npath.fromPortablePath(path)}\n`,
});

await expect(run(`run`, `test:script`, {
await expect(run(`run`, `--global`, `test:script`, {
cwd: `${path}/packages`,
})).resolves.toMatchObject({
stdout: `${npath.fromPortablePath(path)}\n`,
Expand All @@ -134,7 +134,7 @@ describe(`Scripts tests`, () => {

await run(`install`);

await expect(run(`run`, `ws:foo2`)).resolves.toMatchObject({
await expect(run(`run`, `--global`, `ws:foo2`)).resolves.toMatchObject({
stdout: `1\n`,
});
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-pnp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\"",
"prepack": "run --global build:compile \"$(pwd)\"",
"release": "yarn npm publish"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\"",
"test:plugin-compat": "run test:unit --config \"$(pwd)/jest.config.js\"",
"prepack": "run --global build:compile \"$(pwd)\"",
"test:plugin-compat": "run --global test:unit --config \"$(pwd)/jest.config.js\"",
"debug:patch": "node -r @yarnpkg/monorepo/scripts/setup-ts-execution extra/debugPatch \"$INIT_CWD\""
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-constraints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dlx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-essentials/sources/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export default class RunCommand extends BaseCommand {
description: `Forwarded to the underlying Node process when executing a binary`,
});

global = Option.Boolean(`--global`, false, {
description: `Check all workspaces for ones that declare the script uniquely`,
});

// The v1 used to print the Yarn version header when using "yarn run", which
// was messing with the output of things like `--version` & co. We don't do
// this anymore, but many workflows use `yarn run --silent` to make sure that
Expand Down Expand Up @@ -123,13 +127,13 @@ export default class RunCommand extends BaseCommand {

// When it fails, we try to check whether it's a global script (ie we look
// into all the workspaces to find one that exports this script). We only do
// this if the script name contains a colon character (":"), and we skip
// this if the `--global` option is passed, and we skip
// this logic if multiple workspaces share the same script name.
//
// We also disable this logic for packages coming from third-parties (ie
// not workspaces). No particular reason except maybe security concerns.

if (!this.topLevel && !this.binariesOnly && workspace && this.scriptName.includes(`:`)) {
if (!this.topLevel && !this.binariesOnly && workspace && this.global) {
const candidateWorkspaces = await Promise.all(project.workspaces.map(async workspace => {
return workspace.manifest.scripts.has(this.scriptName) ? workspace : null;
}));
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-exec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"@yarnpkg/plugin-git": "workspace:^"
},
"scripts": {
"test": "run test:unit packages/plugin-github",
"test": "run --global test:unit packages/plugin-github",
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-interactive-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-npm-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-patch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pnp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pnpm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
"prepack": "run --global build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
Expand Down
Loading