Skip to content

Commit 5df8b2f

Browse files
Merge pull request #32984 from storybookjs/valentin/cli-init-rework-design-adjustments
CLI: Implement design feedback
2 parents 5667637 + a2d573b commit 5df8b2f

36 files changed

+216
-320
lines changed

code/addons/themes/src/postinstall.ts

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

33
const PACKAGE_MANAGER_TO_COMMAND = {
44
npm: 'npx',
@@ -12,11 +12,11 @@ const selectPackageManagerCommand = (packageManager: string) =>
1212
PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];
1313

1414
export default async function postinstall({ packageManager = 'npm' }) {
15-
const command = selectPackageManagerCommand(packageManager);
15+
const commandString = selectPackageManagerCommand(packageManager);
16+
const [command, ...commandArgs] = commandString.split(' ');
1617

17-
await spawn(`${command} @storybook/auto-config themes`, {
18+
spawnSync(command, [...commandArgs, '@storybook/auto-config', 'themes'], {
1819
stdio: 'inherit',
1920
cwd: process.cwd(),
20-
shell: true,
2121
});
2222
}

code/addons/vitest/src/postinstall.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default async function postInstall(options: PostinstallOptions) {
4646
);
4747

4848
const vitestVersionSpecifier = await packageManager.getInstalledVersion('vitest');
49+
logger.debug(`Vitest version specifier: ${vitestVersionSpecifier}`);
4950
const isVitest3_2To4 = vitestVersionSpecifier
5051
? satisfies(vitestVersionSpecifier, '>=3.2.0 <4.0.0')
5152
: false;
@@ -328,21 +329,22 @@ export default async function postInstall(options: PostinstallOptions) {
328329
'storybook',
329330
'automigrate',
330331
'addon-a11y-addon-test',
331-
'--loglevel=silent',
332+
'--loglevel',
333+
'silent',
332334
'--yes',
333335
'--skip-doctor',
334336
];
335337

336338
if (options.packageManager) {
337-
command.push(`--package-manager=${options.packageManager}`);
339+
command.push('--package-manager', options.packageManager);
338340
}
339341

340342
if (options.skipInstall) {
341343
command.push('--skip-install');
342344
}
343345

344346
if (options.configDir !== '.storybook') {
345-
command.push(`--config-dir="${options.configDir}"`);
347+
command.push('--config-dir', options.configDir);
346348
}
347349

348350
await prompt.executeTask(

code/addons/vitest/src/vitest-plugin/global-setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const startStorybookIfNotRunning = async () => {
4747
storybookProcess = spawn(storybookScript, [], {
4848
stdio: process.env.DEBUG === 'storybook' ? 'pipe' : 'ignore',
4949
cwd: process.cwd(),
50-
shell: true,
5150
});
5251

5352
storybookProcess.on('error', (error) => {

code/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@
265265
"bundle-require": "^5.1.0",
266266
"camelcase": "^8.0.0",
267267
"chai": "^5.1.1",
268-
"cli-table3": "^0.6.1",
269268
"commander": "^14.0.1",
270269
"comment-parser": "^1.4.1",
271270
"copy-to-clipboard": "^3.3.1",

code/core/src/bin/dispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function run() {
6161
if (targetCliPackageJson.version === versions[targetCli.pkg]) {
6262
command = [
6363
'node',
64-
`"${join(resolvePackageDir(targetCli.pkg), 'dist/bin/index.js')}"`,
64+
join(resolvePackageDir(targetCli.pkg), 'dist/bin/index.js'),
6565
...targetCli.args,
6666
];
6767
}
@@ -70,7 +70,7 @@ async function run() {
7070
}
7171
command ??= ['npx', '--yes', `${targetCli.pkg}@${versions[targetCli.pkg]}`, ...targetCli.args];
7272

73-
const child = spawn(command[0], command.slice(1), { stdio: 'inherit', shell: true });
73+
const child = spawn(command[0], command.slice(1), { stdio: 'inherit' });
7474
child.on('exit', (code) => {
7575
process.exit(code);
7676
});

code/core/src/builder-manager/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const starter: StarterFunction = async function* starterGeneratorFn({
141141
router,
142142
}) {
143143
if (!options.quiet) {
144-
logger.info('Starting manager..');
144+
logger.info('Starting...');
145145
}
146146

147147
const {

code/core/src/cli/AddonVitestService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ describe('AddonVitestService', () => {
390390
});
391391
expect(prompt.executeTaskWithSpinner).toHaveBeenCalledWith(expect.any(Function), {
392392
id: 'playwright-installation',
393-
intro: 'Installing Playwright browser binaries',
393+
intro: 'Installing Playwright browser binaries (Press "c" to abort)',
394394
error: expect.stringContaining('An error occurred'),
395395
success: 'Playwright browser binaries installed successfully',
396396
abortable: true,

code/core/src/cli/AddonVitestService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class AddonVitestService {
126126
: await (async () => {
127127
logger.log(dedent`
128128
Playwright browser binaries are necessary for @storybook/addon-vitest. The download can take some time. If you don't want to wait, you can skip the installation and run the following command manually later:
129-
${CLI_COLORS.cta(playwrightCommand.join(' '))}
129+
${CLI_COLORS.cta(`npx ${playwrightCommand.join(' ')}`)}
130130
`);
131131
return prompt.confirm({
132132
message: 'Do you want to install Playwright with Chromium now?',
@@ -139,12 +139,12 @@ export class AddonVitestService {
139139
(signal) =>
140140
packageManager.runPackageCommand({
141141
args: playwrightCommand,
142-
stdio: 'ignore',
142+
stdio: ['inherit', 'pipe', 'pipe'],
143143
signal,
144144
}),
145145
{
146146
id: 'playwright-installation',
147-
intro: 'Installing Playwright browser binaries',
147+
intro: 'Installing Playwright browser binaries (Press "c" to abort)',
148148
error: `An error occurred while installing Playwright browser binaries. Please run the following command later: npx ${playwrightCommand.join(' ')}`,
149149
success: 'Playwright browser binaries installed successfully',
150150
abortable: true,

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
22

33
import { JsPackageManager } from './JsPackageManager';
44

5+
const mockVersions = vi.hoisted(() => ({
6+
'@storybook/react': '8.3.0',
7+
}));
8+
59
vi.mock('../versions', () => ({
6-
default: {
7-
'@storybook/react': '8.3.0',
8-
},
10+
default: mockVersions,
911
}));
1012

1113
describe('JsPackageManager', () => {
1214
let jsPackageManager: JsPackageManager;
13-
let mockLatestVersion: ReturnType<typeof vi.fn>;
15+
let mockLatestVersion: ReturnType<typeof vi.spyOn>;
1416

1517
beforeEach(() => {
16-
mockLatestVersion = vi.fn();
17-
1818
// @ts-expect-error Ignore abstract class error
1919
jsPackageManager = new JsPackageManager();
20-
jsPackageManager.latestVersion = mockLatestVersion;
20+
// @ts-expect-error latestVersion is a method that exists on the instance
21+
mockLatestVersion = vi.spyOn(jsPackageManager, 'latestVersion');
2122

2223
vi.clearAllMocks();
2324
});

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { type ExecaChildProcess } from 'execa';
99
// eslint-disable-next-line depend/ban-dependencies
1010
import { globSync } from 'glob';
1111
import picocolors from 'picocolors';
12-
import { gt, satisfies } from 'semver';
12+
import { coerce, gt, satisfies } from 'semver';
1313
import invariant from 'tiny-invariant';
1414

1515
import { HandledError } from '../utils/HandledError';
@@ -635,10 +635,13 @@ export abstract class JsPackageManager {
635635

636636
const version = Object.entries(installations.dependencies)[0]?.[1]?.[0].version || null;
637637

638+
const coercedVersion = coerce(version, { includePrerelease: true })?.toString() ?? version;
639+
640+
logger.debug(`Installed version for ${packageName}: ${coercedVersion}`);
638641
// Cache the result
639-
JsPackageManager.installedVersionCache.set(cacheKey, version);
642+
JsPackageManager.installedVersionCache.set(cacheKey, coercedVersion);
640643

641-
return version;
644+
return coercedVersion;
642645
} catch (e) {
643646
JsPackageManager.installedVersionCache.set(cacheKey, null);
644647
return null;

0 commit comments

Comments
 (0)