Skip to content
Merged
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
7 changes: 6 additions & 1 deletion code/core/src/cli/AddonVitestService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('AddonVitestService', () => {
getAllDependencies: vi.fn(),
getInstalledVersion: vi.fn(),
runPackageCommand: vi.fn(),
getPackageCommand: vi.fn(),
} as Partial<JsPackageManager> as JsPackageManager;

service = new AddonVitestService(mockPackageManager);
Expand Down Expand Up @@ -366,6 +367,10 @@ describe('AddonVitestService', () => {
// Mock the logger methods used in installPlaywright
vi.mocked(logger.log).mockImplementation(() => {});
vi.mocked(logger.warn).mockImplementation(() => {});
// Mock getPackageCommand to return a string
vi.mocked(mockPackageManager.getPackageCommand).mockReturnValue(
'npx playwright install chromium --with-deps'
);
});

it('should install Playwright successfully', async () => {
Expand All @@ -381,7 +386,7 @@ describe('AddonVitestService', () => {
});
expect(prompt.executeTaskWithSpinner).toHaveBeenCalledWith(expect.any(Function), {
id: 'playwright-installation',
intro: 'Installing Playwright browser binaries (Press "c" to abort)',
intro: 'Installing Playwright browser binaries (press "c" to abort)',
error: expect.stringContaining('An error occurred'),
success: 'Playwright browser binaries installed successfully',
abortable: true,
Expand Down
7 changes: 4 additions & 3 deletions code/core/src/cli/AddonVitestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ export class AddonVitestService {
const errors: string[] = [];

const playwrightCommand = ['playwright', 'install', 'chromium', '--with-deps'];
const playwrightCommandString = this.packageManager.getPackageCommand(playwrightCommand);

try {
const shouldBeInstalled = options.yes
? true
: await (async () => {
logger.log(dedent`
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:
${CLI_COLORS.cta(`npx ${playwrightCommand.join(' ')}`)}
${CLI_COLORS.cta(playwrightCommandString)}
`);
return prompt.confirm({
message: 'Do you want to install Playwright with Chromium now?',
Expand All @@ -143,8 +144,8 @@ export class AddonVitestService {
}),
{
id: 'playwright-installation',
intro: 'Installing Playwright browser binaries (Press "c" to abort)',
error: `An error occurred while installing Playwright browser binaries. Please run the following command later: npx ${playwrightCommand.join(' ')}`,
intro: 'Installing Playwright browser binaries (press "c" to abort)',
error: `An error occurred while installing Playwright browser binaries. Please run the following command later: ${playwrightCommandString}`,
success: 'Playwright browser binaries installed successfully',
abortable: true,
}
Expand Down
4 changes: 4 additions & 0 deletions code/core/src/common/js-package-manager/BUNProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export class BUNProxy extends JsPackageManager {
return `bunx ${pkg}${specifier ? `@${specifier}` : ''} ${args.join(' ')}`;
}

getPackageCommand(args: string[]): string {
return `bunx ${args.join(' ')}`;
}

public async getModulePackageJSON(packageName: string): Promise<PackageJson | null> {
const wantedPath = join('node_modules', packageName, 'package.json');
const packageJsonPath = find.up(wantedPath, {
Expand Down
5 changes: 4 additions & 1 deletion code/core/src/common/js-package-manager/JsPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ export abstract class JsPackageManager {
this.primaryPackageJson = this.#getPrimaryPackageJson();
}

/** Runs arbitrary package scripts. */
/** Runs arbitrary package scripts (as a string for display). */
abstract getRunCommand(command: string): string;

/** Returns the command to run the binary of a local package */
abstract getPackageCommand(args: string[]): string;

/** Get the package.json file for a given module. */
abstract getModulePackageJSON(packageName: string, cwd?: string): Promise<PackageJson | null>;

Expand Down
4 changes: 4 additions & 0 deletions code/core/src/common/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class NPMProxy extends JsPackageManager {
return this.installArgs;
}

public getPackageCommand(args: string[]): string {
return `npx ${args.join(' ')}`;
}

public runPackageCommand(
options: Omit<ExecuteCommandOptions, 'command'> & { args: string[] }
): ExecaChildProcess {
Expand Down
4 changes: 4 additions & 0 deletions code/core/src/common/js-package-manager/PNPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class PNPMProxy extends JsPackageManager {
return this.installArgs;
}

getPackageCommand(args: string[]): string {
return `pnpm exec ${args.join(' ')}`;
}

public runPackageCommand({
args,
...options
Expand Down
5 changes: 5 additions & 0 deletions code/core/src/common/js-package-manager/Yarn1Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class Yarn1Proxy extends JsPackageManager {
return `yarn ${command}`;
}

getPackageCommand(args: string[]): string {
const [command, ...rest] = args;
return `yarn exec ${command} -- ${rest.join(' ')}`;
}

public runPackageCommand({
args,
...options
Expand Down
4 changes: 4 additions & 0 deletions code/core/src/common/js-package-manager/Yarn2Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class Yarn2Proxy extends JsPackageManager {
return `yarn ${command}`;
}

getPackageCommand(args: string[]): string {
return `yarn exec ${args.join(' ')}`;
}

public runPackageCommand({
args,
...options
Expand Down
3 changes: 2 additions & 1 deletion code/core/src/node-logger/logger/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const CLI_COLORS = {
success: picocolors.green,
error: picocolors.red,
warning: picocolors.yellow,
info: process.platform === 'win32' ? picocolors.cyan : picocolors.blue,
// Improve contrast on dark terminals by using cyan for info on all platforms
info: picocolors.cyan,
debug: picocolors.gray,
// Only color a link if it is the primary call to action, otherwise links shouldn't be colored
cta: picocolors.cyan,
Expand Down
5 changes: 1 addition & 4 deletions code/core/src/telemetry/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export const notify = async () => {
if (!(await cache.get(TELEMETRY_KEY_NOTIFY_DATE, null))) {
cache.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now());
logger.info(
dedent`
Attention: Storybook collects completely anonymous telemetry regarding usage. This information is used to shape Storybook's roadmap and prioritize features. You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://storybook.js.org/telemetry
`
"Storybook collects completely anonymous usage telemetry. We use it to shape Storybook's roadmap and prioritize features. You can learn more, including how to opt out, at https://storybook.js.org/telemetry"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export class UserPreferencesCommand {
let installType: InstallType = 'recommended';

const recommendedLabel = isTestFeatureAvailable
? `Recommended: Includes component development, docs and testing features.`
: `Recommended: Includes component development and docs`;
? `Recommended: Component development, docs, and testing features.`
: `Recommended: Component development and docs`;

if (!skipPrompt) {
installType = await prompt.select({
Expand Down
Loading