|
6 | 6 |
|
7 | 7 | import {suite} from 'uvu'; |
8 | 8 | import * as assert from 'uvu/assert'; |
| 9 | +import {dedent} from 'ts-dedent'; |
9 | 10 | import {rigTest} from './util/rig-test.js'; |
10 | 11 | import {IS_WINDOWS} from '../util/windows.js'; |
| 12 | +import {injectYarnBerryToRig} from './util/yarn-berry.js'; |
11 | 13 | import {NODE_MAJOR_VERSION} from './util/node-version.js'; |
12 | 14 | import {checkScriptOutput} from './util/check-script-output.js'; |
13 | 15 |
|
@@ -880,6 +882,109 @@ test( |
880 | 882 | }), |
881 | 883 | ); |
882 | 884 |
|
| 885 | +test( |
| 886 | + 'commands can be run locally in yarn berry', |
| 887 | + rigTest(async ({rig}) => { |
| 888 | + await injectYarnBerryToRig(rig); |
| 889 | + |
| 890 | + const rootCmd = await rig.newCommand(); |
| 891 | + const innerCmd = await rig.newCommand(); |
| 892 | + |
| 893 | + const originalLock = await rig.read('yarn.lock'); |
| 894 | + |
| 895 | + await rig.write({ |
| 896 | + 'package.json': { |
| 897 | + private: true, |
| 898 | + workspaces: ['packages/*'], |
| 899 | + scripts: { |
| 900 | + cmd: 'yarn run -B wireit', |
| 901 | + }, |
| 902 | + wireit: { |
| 903 | + cmd: { |
| 904 | + command: rootCmd.command, |
| 905 | + }, |
| 906 | + }, |
| 907 | + devDependencies: { |
| 908 | + wireit: '*', |
| 909 | + }, |
| 910 | + resolutions: { |
| 911 | + wireit: `portal:${process.cwd()}`, |
| 912 | + }, |
| 913 | + }, |
| 914 | + |
| 915 | + 'packages/inner/package.json': { |
| 916 | + scripts: { |
| 917 | + cmd: 'yarn run -TB wireit', |
| 918 | + }, |
| 919 | + wireit: { |
| 920 | + cmd: { |
| 921 | + command: innerCmd.command, |
| 922 | + }, |
| 923 | + }, |
| 924 | + }, |
| 925 | + |
| 926 | + // On a real system, `yarn` should do this automatically; however, in this |
| 927 | + // test rig, a stale copy (`originalLock`) remains, even if we manually |
| 928 | + // run `yarn`. Therefore, we manually update the lockfile here to include |
| 929 | + // the inner package. |
| 930 | + 'yarn.lock': |
| 931 | + originalLock + |
| 932 | + dedent` |
| 933 | +
|
| 934 | + "inner-d81e84@workspace:packages/inner": |
| 935 | + version: 0.0.0-use.local |
| 936 | + resolution: "inner-d81e84@workspace:packages/inner" |
| 937 | + languageName: unknown |
| 938 | + linkType: soft |
| 939 | +
|
| 940 | + "wireit@portal:${process.cwd()}::locator=root-workspace-0b6124%40workspace%3A.": |
| 941 | + version: 0.0.0-use.local |
| 942 | + resolution: "wireit@portal:${process.cwd()}::locator=root-workspace-0b6124%40workspace%3A." |
| 943 | + dependencies: |
| 944 | + braces: "npm:^3.0.2" |
| 945 | + chokidar: "npm:^3.5.3" |
| 946 | + dedent: "npm:^1.5.1" |
| 947 | + fast-glob: "npm:^3.2.11" |
| 948 | + jsonc-parser: "npm:^3.0.0" |
| 949 | + proper-lockfile: "npm:^4.1.2" |
| 950 | + ts-dedent: "npm:^2.2.0" |
| 951 | + bin: |
| 952 | + wireit: bin/wireit.js |
| 953 | + languageName: node |
| 954 | + linkType: soft |
| 955 | + `, |
| 956 | + }); |
| 957 | + |
| 958 | + // this is what should modify the lockfile, so we don't have to do it |
| 959 | + // manually |
| 960 | + rig.exec('yarn'); |
| 961 | + |
| 962 | + // logging: can be deleted once this works |
| 963 | + // |
| 964 | + // since the `.bin` is already set up by the test rig, IDK if we should need to |
| 965 | + // modify the lockfile to include wireit. however, it's saying |
| 966 | + // |
| 967 | + // Usage Error: Couldn't find a script name "wireit" in the top-level (used by inner-d81e84@workspace:packages/inner). |
| 968 | + // |
| 969 | + // so i'm trying to make it work |
| 970 | + rig.exec('ls -la node_modules/.bin'); |
| 971 | + rig.read('yarn.lock').then(console.log); |
| 972 | + |
| 973 | + { |
| 974 | + const exec = rig.exec('yarn run cmd', {cwd: 'packages/inner'}); |
| 975 | + ( |
| 976 | + await Promise.race([ |
| 977 | + innerCmd.nextInvocation(), |
| 978 | + rootCmd.nextInvocation(), |
| 979 | + ]) |
| 980 | + ).exit(0); |
| 981 | + assert.equal((await exec.exit).code, 0); |
| 982 | + assert.equal(innerCmd.numInvocations, 1); |
| 983 | + assert.equal(rootCmd.numInvocations, 0); |
| 984 | + } |
| 985 | + }), |
| 986 | +); |
| 987 | + |
883 | 988 | test( |
884 | 989 | 'commands run under pnpm workspaces', |
885 | 990 | rigTest(async ({rig}) => { |
|
0 commit comments