Skip to content

Commit e3f53ba

Browse files
author
Your Name
committed
Fix: use yarn dlx for remote package execution in Yarn2Proxy
When `useRemotePkg` is true, `Yarn2Proxy.runPackageCommand` now uses `yarn dlx` instead of `yarn exec`. `yarn exec` only runs locally installed binaries, causing exit code 127 when attempting to download and run a remote package (e.g. `storybook@10.2.7`) during addon postinstall on Yarn 2+. Fixes #33844
1 parent 6b05884 commit e3f53ba

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

code/core/src/common/js-package-manager/Yarn2Proxy.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ describe('Yarn 2 Proxy', () => {
6767
})
6868
);
6969
});
70+
71+
it('should use `yarn dlx` when useRemotePkg is true', async () => {
72+
const executeCommandSpy = mockedExecuteCommand.mockResolvedValue({
73+
stdout: '',
74+
} as any);
75+
76+
await yarn2Proxy.runPackageCommand({
77+
args: ['storybook@latest', 'automigrate'],
78+
useRemotePkg: true,
79+
});
80+
81+
expect(executeCommandSpy).toHaveBeenLastCalledWith(
82+
expect.objectContaining({
83+
command: 'yarn',
84+
args: ['dlx', 'storybook@latest', 'automigrate'],
85+
})
86+
);
87+
});
7088
});
7189

7290
describe('addDependencies', () => {

code/core/src/common/js-package-manager/Yarn2Proxy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ export class Yarn2Proxy extends JsPackageManager {
100100

101101
public runPackageCommand({
102102
args,
103+
useRemotePkg = false,
103104
...options
104-
}: Omit<ExecuteCommandOptions, 'command'> & { args: string[] }): ResultPromise {
105+
}: Omit<ExecuteCommandOptions, 'command'> & {
106+
args: string[];
107+
useRemotePkg?: boolean;
108+
}): ResultPromise {
105109
return executeCommand({
106110
command: 'yarn',
107-
args: ['exec', ...args],
111+
args: [useRemotePkg ? 'dlx' : 'exec', ...args],
108112
...options,
109113
});
110114
}

0 commit comments

Comments
 (0)