Skip to content

Commit f86f751

Browse files
authored
Merge pull request #32382 from storybookjs/jeppe/fix-node-24-warning
Core: Fix Node 24 deprecation warning
2 parents 98c4d9a + 88d8246 commit f86f751

File tree

5 files changed

+78
-54
lines changed

5 files changed

+78
-54
lines changed

code/addons/themes/src/postinstall.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import { spawn } from 'child_process';
22

33
const PACKAGE_MANAGER_TO_COMMAND = {
4-
npm: ['npx'],
5-
pnpm: ['pnpm', 'dlx'],
6-
yarn1: ['npx'],
7-
yarn2: ['yarn', 'dlx'],
8-
bun: ['bunx'],
4+
npm: 'npx',
5+
pnpm: 'pnpm dlx',
6+
yarn1: 'npx',
7+
yarn2: 'yarn dlx',
8+
bun: 'bunx',
99
};
1010

1111
const selectPackageManagerCommand = (packageManager: string) =>
1212
PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];
1313

14-
const spawnPackageManagerScript = async (packageManager: string, args: string[]) => {
15-
const [command, ...baseArgs] = selectPackageManagerCommand(packageManager);
14+
export default async function postinstall({ packageManager = 'npm' }) {
15+
const command = selectPackageManagerCommand(packageManager);
1616

17-
await spawn(command, [...baseArgs, ...args], {
17+
await spawn(`${command} @storybook/auto-config themes`, {
1818
stdio: 'inherit',
1919
cwd: process.cwd(),
2020
shell: true,
2121
});
22-
};
23-
24-
export default async function postinstall({ packageManager = 'npm' }) {
25-
await spawnPackageManagerScript(packageManager, ['@storybook/auto-config', 'themes']);
2622
}

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

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
4343
it('ALL EXIST: when all package managers are ok, but only a `package-lock.json` file is found', () => {
4444
spawnSyncMock.mockImplementation((command) => {
4545
// Yarn is ok
46-
if (command === 'yarn') {
46+
if (command === 'yarn --version') {
4747
return {
4848
status: 0,
4949
output: '1.22.4',
5050
};
5151
}
5252
// NPM is ok
53-
if (command === 'npm') {
53+
if (command === 'npm --version') {
5454
return {
5555
status: 0,
5656
output: '6.5.12',
5757
};
5858
}
5959
// PNPM is ok
60-
if (command === 'pnpm') {
60+
if (command === 'pnpm --version') {
6161
return {
6262
status: 0,
6363
output: '7.9.5',
@@ -70,7 +70,12 @@ describe('CLASS: JsPackageManagerFactory', () => {
7070
});
7171

7272
// There is only a package-lock.json
73-
findUpSyncMock.mockImplementation(() => '/Users/johndoe/Documents/package-lock.json');
73+
findUpSyncMock.mockImplementation((filename) => {
74+
if (typeof filename === 'string' && filename === 'package-lock.json') {
75+
return '/Users/johndoe/Documents/package-lock.json';
76+
}
77+
return undefined;
78+
});
7479

7580
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(NPMProxy);
7681
});
@@ -91,21 +96,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
9196
it('ALL EXIST: when all package managers are ok, but only a `pnpm-lock.yaml` file is found', () => {
9297
spawnSyncMock.mockImplementation((command) => {
9398
// Yarn is ok
94-
if (command === 'yarn') {
99+
if (command === 'yarn --version') {
95100
return {
96101
status: 0,
97102
output: '1.22.4',
98103
};
99104
}
100105
// NPM is ok
101-
if (command === 'npm') {
106+
if (command === 'npm --version') {
102107
return {
103108
status: 0,
104109
output: '6.5.12',
105110
};
106111
}
107112
// PNPM is ok
108-
if (command === 'pnpm') {
113+
if (command === 'pnpm --version') {
109114
return {
110115
status: 0,
111116
output: '7.9.5',
@@ -114,11 +119,16 @@ describe('CLASS: JsPackageManagerFactory', () => {
114119
// Unknown package manager is ko
115120
return {
116121
status: 1,
117-
} as any as any;
122+
} as any;
118123
});
119124

120125
// There is only a pnpm-lock.yaml
121-
findUpSyncMock.mockImplementation(() => '/Users/johndoe/Documents/pnpm-lock.yaml');
126+
findUpSyncMock.mockImplementation((filename) => {
127+
if (typeof filename === 'string' && filename === 'pnpm-lock.yaml') {
128+
return '/Users/johndoe/Documents/pnpm-lock.yaml';
129+
}
130+
return undefined;
131+
});
122132

123133
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(PNPMProxy);
124134
});
@@ -131,21 +141,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
131141

132142
spawnSyncMock.mockImplementation((command) => {
133143
// Yarn is ok
134-
if (command === 'yarn') {
144+
if (command === 'yarn --version') {
135145
return {
136146
status: 0,
137147
output: '1.22.4',
138148
};
139149
}
140150
// NPM is ok
141-
if (command === 'npm') {
151+
if (command === 'npm --version') {
142152
return {
143153
status: 0,
144154
output: '6.5.12',
145155
};
146156
}
147157
// PNPM is ok
148-
if (command === 'pnpm') {
158+
if (command === 'pnpm --version') {
149159
return {
150160
status: 0,
151161
output: '7.9.5',
@@ -176,20 +186,20 @@ describe('CLASS: JsPackageManagerFactory', () => {
176186
it('when Yarn command is ok and a yarn.lock file is found', () => {
177187
spawnSyncMock.mockImplementation((command) => {
178188
// Yarn is ok
179-
if (command === 'yarn') {
189+
if (command === 'yarn --version') {
180190
return {
181191
status: 0,
182192
output: '1.22.4',
183193
};
184194
}
185195
// NPM is ko
186-
if (command === 'npm') {
196+
if (command === 'npm --version') {
187197
return {
188198
status: 1,
189199
};
190200
}
191201
// PNPM is ko
192-
if (command === 'pnpm') {
202+
if (command === 'pnpm --version') {
193203
return {
194204
status: 1,
195205
};
@@ -200,30 +210,35 @@ describe('CLASS: JsPackageManagerFactory', () => {
200210
} as any;
201211
});
202212

203-
// there is no lockfile
204-
findUpSyncMock.mockReturnValue('yarn.lock');
213+
// there is a yarn.lock file
214+
findUpSyncMock.mockImplementation((filename) => {
215+
if (typeof filename === 'string' && filename === 'yarn.lock') {
216+
return '/Users/johndoe/Documents/yarn.lock';
217+
}
218+
return undefined;
219+
});
205220

206221
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(Yarn1Proxy);
207222
});
208223

209224
it('when Yarn command is ok, Yarn version is <2, NPM and PNPM are ok, there is a `yarn.lock` file', () => {
210225
spawnSyncMock.mockImplementation((command) => {
211226
// Yarn is ok
212-
if (command === 'yarn') {
227+
if (command === 'yarn --version') {
213228
return {
214229
status: 0,
215230
output: '1.22.4',
216231
};
217232
}
218233
// NPM is ok
219-
if (command === 'npm') {
234+
if (command === 'npm --version') {
220235
return {
221236
status: 0,
222237
output: '6.5.12',
223238
};
224239
}
225240
// PNPM is ok
226-
if (command === 'pnpm') {
241+
if (command === 'pnpm --version') {
227242
return {
228243
status: 0,
229244
output: '7.9.5',
@@ -236,7 +251,12 @@ describe('CLASS: JsPackageManagerFactory', () => {
236251
});
237252

238253
// There is a yarn.lock
239-
findUpSyncMock.mockImplementation(() => '/Users/johndoe/Documents/yarn.lock');
254+
findUpSyncMock.mockImplementation((filename) => {
255+
if (typeof filename === 'string' && filename === 'yarn.lock') {
256+
return '/Users/johndoe/Documents/yarn.lock';
257+
}
258+
return undefined;
259+
});
240260

241261
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(Yarn1Proxy);
242262
});
@@ -249,21 +269,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
249269

250270
spawnSyncMock.mockImplementation((command) => {
251271
// Yarn is ok
252-
if (command === 'yarn') {
272+
if (command === 'yarn --version') {
253273
return {
254274
status: 0,
255275
output: '1.22.4',
256276
};
257277
}
258278
// NPM is ok
259-
if (command === 'npm') {
279+
if (command === 'npm --version') {
260280
return {
261281
status: 0,
262282
output: '6.5.12',
263283
};
264284
}
265285
// PNPM is ok
266-
if (command === 'pnpm') {
286+
if (command === 'pnpm --version') {
267287
return {
268288
status: 0,
269289
output: '7.9.5',
@@ -294,20 +314,20 @@ describe('CLASS: JsPackageManagerFactory', () => {
294314
it('ONLY YARN 2: when Yarn command is ok, Yarn version is >=2, NPM is ko, PNPM is ko, and a yarn.lock file is found', () => {
295315
spawnSyncMock.mockImplementation((command) => {
296316
// Yarn is ok
297-
if (command === 'yarn') {
317+
if (command === 'yarn --version') {
298318
return {
299319
status: 0,
300320
output: '2.0.0-rc.33',
301321
};
302322
}
303323
// NPM is ko
304-
if (command === 'npm') {
324+
if (command === 'npm --version') {
305325
return {
306326
status: 1,
307327
};
308328
}
309329
// PNPM is ko
310-
if (command === 'pnpm') {
330+
if (command === 'pnpm --version') {
311331
return {
312332
status: 1,
313333
};
@@ -318,36 +338,41 @@ describe('CLASS: JsPackageManagerFactory', () => {
318338
} as any;
319339
});
320340

321-
findUpSyncMock.mockImplementation(() => 'yarn.lock');
341+
findUpSyncMock.mockImplementation((filename) => {
342+
if (typeof filename === 'string' && filename === 'yarn.lock') {
343+
return '/Users/johndoe/Documents/yarn.lock';
344+
}
345+
return undefined;
346+
});
322347

323348
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(Yarn2Proxy);
324349
});
325350

326351
it('when Yarn command is ok, Yarn version is >=2, NPM and PNPM are ok, there is a `yarn.lock` file', () => {
327352
spawnSyncMock.mockImplementation((command) => {
328353
// Yarn is ok
329-
if (command === 'yarn') {
354+
if (command === 'yarn --version') {
330355
return {
331356
status: 0,
332357
output: '2.0.0-rc.33',
333358
};
334359
}
335360
// NPM is ok
336-
if (command === 'npm') {
361+
if (command === 'npm --version') {
337362
return {
338363
status: 0,
339364
output: '6.5.12',
340365
};
341366
}
342367
// PNPM is ok
343-
if (command === 'pnpm') {
368+
if (command === 'pnpm --version') {
344369
return {
345370
status: 0,
346371
output: '7.9.5',
347372
};
348373
}
349374

350-
if (command === 'bun') {
375+
if (command === 'bun --version') {
351376
return {
352377
status: 0,
353378
output: '1.0.0',
@@ -359,8 +384,13 @@ describe('CLASS: JsPackageManagerFactory', () => {
359384
} as any;
360385
});
361386

362-
// There is a yarn.lock
363-
findUpSyncMock.mockImplementation(() => '/Users/johndoe/Documents/bun.lockb');
387+
// There is a bun.lockb
388+
findUpSyncMock.mockImplementation((filename) => {
389+
if (typeof filename === 'string' && filename === 'bun.lockb') {
390+
return '/Users/johndoe/Documents/bun.lockb';
391+
}
392+
return undefined;
393+
});
364394

365395
expect(JsPackageManagerFactory.getPackageManager()).toBeInstanceOf(BUNProxy);
366396
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class JsPackageManagerFactory {
195195
}
196196

197197
function hasNPM(cwd?: string) {
198-
const npmVersionCommand = spawnSync('npm', ['--version'], {
198+
const npmVersionCommand = spawnSync('npm --version', {
199199
cwd,
200200
shell: true,
201201
env: {
@@ -207,7 +207,7 @@ function hasNPM(cwd?: string) {
207207
}
208208

209209
function hasBun(cwd?: string) {
210-
const pnpmVersionCommand = spawnSync('bun', ['--version'], {
210+
const pnpmVersionCommand = spawnSync('bun --version', {
211211
cwd,
212212
shell: true,
213213
env: {
@@ -219,7 +219,7 @@ function hasBun(cwd?: string) {
219219
}
220220

221221
function hasPNPM(cwd?: string) {
222-
const pnpmVersionCommand = spawnSync('pnpm', ['--version'], {
222+
const pnpmVersionCommand = spawnSync('pnpm --version', {
223223
cwd,
224224
shell: true,
225225
env: {
@@ -231,7 +231,7 @@ function hasPNPM(cwd?: string) {
231231
}
232232

233233
function getYarnVersion(cwd?: string): 1 | 2 | undefined {
234-
const yarnVersionCommand = spawnSync('yarn', ['--version'], {
234+
const yarnVersionCommand = spawnSync('yarn --version', {
235235
cwd,
236236
shell: true,
237237
env: {

code/lib/cli-storybook/src/upgrade.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ const formatPackage = (pkg: Package) => `${pkg.package}@${pkg.version}`;
7676
const warnPackages = (pkgs: Package[]) => pkgs.map((pkg) => `- ${formatPackage(pkg)}`).join('\n');
7777

7878
export const checkVersionConsistency = () => {
79-
const lines = spawnSync('npm', ['ls'], { stdio: 'pipe', shell: true })
80-
.output.toString()
81-
.split('\n');
79+
const lines = spawnSync('npm ls', { stdio: 'pipe', shell: true }).output.toString().split('\n');
8280
const storybookPackages = lines
8381
.map(getStorybookVersion)
8482
.filter((item): item is NonNullable<typeof item> => !!item)

code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"lint:prettier": "prettier --write",
4646
"local-registry": "yarn --cwd ../scripts local-registry",
4747
"publish-sandboxes": "yarn --cwd ../scripts publish",
48-
"storybook:ui": "NODE_OPTIONS=\"--max_old_space_size=4096\" core/dist/bin/dispatcher.js dev --port 6006 --config-dir ./.storybook",
48+
"storybook:ui": "NODE_OPTIONS=\"--max_old_space_size=4096 --trace-deprecation\" core/dist/bin/dispatcher.js dev --port 6006 --config-dir ./.storybook",
4949
"storybook:ui:build": "NODE_OPTIONS=\"--max_old_space_size=4096\" core/dist/bin/dispatcher.js build --config-dir ./.storybook --webpack-stats-json",
5050
"storybook:ui:chromatic": "../scripts/node_modules/.bin/chromatic --build-script-name storybook:ui:build --storybook-base-dir ./ --exit-zero-on-changes --exit-once-uploaded",
5151
"storybook:vitest": "yarn test:watch --project storybook-ui",

0 commit comments

Comments
 (0)