Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Add "intents" question & auto-install test addon & improve test-addon compatibility #30202

Open
wants to merge 161 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 154 commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
bde2134
ink in core and esm in create-storybook
ndelangen Jan 7, 2025
7e4592d
ink in init
ndelangen Jan 7, 2025
9f88950
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
59d7c63
fix
ndelangen Jan 7, 2025
6462b7b
keep other package dist bundling unchanged
ndelangen Jan 7, 2025
3a19d00
fix
ndelangen Jan 7, 2025
71df9d9
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
b5f7b2e
support ink types
ndelangen Jan 7, 2025
25d7e76
use esm of CLI
ndelangen Jan 7, 2025
760ce6d
fixes for check to support for moduleresolution=bundler
ndelangen Jan 7, 2025
c44aca3
add cjs
ndelangen Jan 7, 2025
321de92
undo shim change in prepare script
ndelangen Jan 7, 2025
9683316
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
20844fc
disable parallelism as it's not letting me see the issue, and i canno…
ndelangen Jan 7, 2025
57bc122
rendering with ink embedded in vite
ndelangen Jan 7, 2025
0eec9b0
add `node` condition for chalk
ndelangen Jan 7, 2025
e84572d
fix
ndelangen Jan 7, 2025
0f42062
unit test pass?
ndelangen Jan 8, 2025
b843a68
Discard changes to .circleci/config.yml
ndelangen Jan 8, 2025
199b5bf
fix linting
ndelangen Jan 8, 2025
5da8301
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 8, 2025
0fccec9
fix linting
ndelangen Jan 8, 2025
fb51e3b
add first demo story of an ink component
ndelangen Jan 8, 2025
1a5fe81
Discard changes to code/lib/cli-storybook/test/default/cli.test.cjs
ndelangen Jan 8, 2025
7440621
cleanup
ndelangen Jan 8, 2025
21c04b7
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 9, 2025
9541d3e
cleanup
ndelangen Jan 9, 2025
1e75423
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 9, 2025
5ff6089
typings
ndelangen Jan 9, 2025
90f12d7
update the target environment so we do not need TLA plugin, which see…
ndelangen Jan 9, 2025
69d64f8
cleanup
ndelangen Jan 9, 2025
a876450
fix types
ndelangen Jan 9, 2025
94843bf
patch away the top-level-away and devtools from ink to fix https://cl…
ndelangen Jan 9, 2025
b79205f
Revert "patch away the top-level-away and devtools from ink to fix ht…
ndelangen Jan 9, 2025
49f2c44
fix dev
ndelangen Jan 9, 2025
35505ec
fix dev actually
ndelangen Jan 9, 2025
f02c1a7
centered
ndelangen Jan 9, 2025
211318f
fix firefox Intl.Segmenter in chromatic
ndelangen Jan 9, 2025
580cf60
try to fix
ndelangen Jan 9, 2025
234c8da
alt solution
ndelangen Jan 9, 2025
6555742
add debug
ndelangen Jan 9, 2025
fe1e4c7
debug
ndelangen Jan 9, 2025
098a52e
Merge changes from POC
ghengeveld Jan 10, 2025
02cffc8
conditional ink stories, do not add when running vitest
ndelangen Jan 10, 2025
c97f554
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 10, 2025
2cbdd8e
fix windows compilation problem with pathing
ndelangen Jan 10, 2025
e821aae
remove story I added fro debugging purposes
ndelangen Jan 10, 2025
660aa3c
trying to fix the include pattern
ndelangen Jan 10, 2025
18b4f8d
again
ndelangen Jan 10, 2025
82851be
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 10, 2025
f6975ff
cleanup
ndelangen Jan 10, 2025
ec64802
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 13, 2025
1cdcb1a
split the create-storybook CLI into a modern & legacy part, based on …
ndelangen Jan 13, 2025
8c9d6af
add comments
ndelangen Jan 13, 2025
b5d1593
render the app
ndelangen Jan 13, 2025
6423249
wip
ghengeveld Jan 14, 2025
cfd010a
Merge pull request #30256 from storybookjs/gert/cli-with-ink
ndelangen Jan 14, 2025
b6e2afe
version accurate
ndelangen Jan 14, 2025
b530642
scaffold reducer state
ndelangen Jan 14, 2025
cf905a2
adding more input
ndelangen Jan 14, 2025
4b9f6cf
cleanup
ndelangen Jan 14, 2025
bbdae44
add more steps details
ndelangen Jan 15, 2025
54b0998
add a run step && cleanup
ndelangen Jan 15, 2025
9983643
add node utils via context, so storybook doesn't run into it
ndelangen Jan 15, 2025
d5ca217
crude install
ndelangen Jan 15, 2025
dcd3d1f
add require for resolving to context, use ni for package manager oper…
ndelangen Jan 15, 2025
a59ea66
reduce bloat
ndelangen Jan 16, 2025
af7ec07
fix
ndelangen Jan 16, 2025
75019af
fixes & add place for metrics component
ndelangen Jan 16, 2025
d8fc245
handle steps as a straight line. each step can skip itself in a useEf…
ndelangen Jan 16, 2025
df22449
cleanup
ndelangen Jan 16, 2025
ab86684
I guess we can keep it
ndelangen Jan 16, 2025
9c70158
move Confirm component
ndelangen Jan 16, 2025
195c39f
simplify
ndelangen Jan 16, 2025
8ff6e74
figured out a way to cancel
ndelangen Jan 16, 2025
f58c72d
track errors from procedures
ndelangen Jan 16, 2025
4817715
more error handling in interllation procedure
ndelangen Jan 16, 2025
3fe3307
better error handling
ndelangen Jan 16, 2025
a4c188e
improve error handling (no meaningless error if a meaningful one was …
ndelangen Jan 16, 2025
212b99f
install with versions & improve UI
ndelangen Jan 17, 2025
4bf774d
improve UI
ndelangen Jan 17, 2025
924fb94
uppercase to indicate <enter> will select that
ndelangen Jan 20, 2025
133f948
refactor, to reduce long files
ndelangen Jan 20, 2025
3de4555
move check to context
ndelangen Jan 20, 2025
dde08df
more stories
ndelangen Jan 20, 2025
9dc465b
cleanup
ndelangen Jan 20, 2025
25e2024
cleanup
ndelangen Jan 20, 2025
d41f56d
context changes
ndelangen Jan 20, 2025
1276642
fixes
ndelangen Jan 20, 2025
10bf2e7
fixes
ndelangen Jan 20, 2025
d9f0590
fix
ndelangen Jan 20, 2025
076929d
add story
ndelangen Jan 20, 2025
03c8751
cleanup
ndelangen Jan 20, 2025
b28651c
Add telemetry
ghengeveld Jan 20, 2025
174473c
improve
ndelangen Jan 21, 2025
6443b00
Omit directory for privacy reasons
ghengeveld Jan 21, 2025
2a2f9b0
Rename files
ghengeveld Jan 21, 2025
dbdb3a1
Merge branch 'norbert/cli-with-ink' into gert/init-telemetry
ghengeveld Jan 21, 2025
2ad4e6f
Merge pull request #30313 from storybookjs/gert/init-telemetry
ghengeveld Jan 21, 2025
17eb077
fix
ndelangen Jan 21, 2025
68fd581
fix
ndelangen Jan 21, 2025
d281b9a
improve error handling
ndelangen Jan 21, 2025
3114096
cleanup
ndelangen Jan 21, 2025
23379b3
cleanup
ndelangen Jan 21, 2025
9e3968d
add completion & spinners to procedures && add telemetry as tracked task
ndelangen Jan 21, 2025
5b2bbab
have some fun, I got the user's name
ndelangen Jan 21, 2025
db1e037
improve header
ndelangen Jan 22, 2025
90f0a74
improve error handling of installation
ndelangen Jan 22, 2025
4958640
fixes
ndelangen Jan 22, 2025
89c404c
fix typo
ndelangen Jan 22, 2025
e003420
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 22, 2025
8b13cb1
Disable telemetry notification when running create-storybook because …
ghengeveld Jan 22, 2025
7a167e0
Implement checks
ghengeveld Jan 22, 2025
16a7433
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 22, 2025
958e81e
fix intents
ndelangen Jan 22, 2025
7ea83ed
no default in CLI, but set defaults in the component instead. This wa…
ndelangen Jan 23, 2025
1a6be9c
no default intents in app
ndelangen Jan 23, 2025
3159795
Implement first set of actual checks
ghengeveld Jan 23, 2025
7044963
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 23, 2025
fb670b9
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 23, 2025
e8d1fdf
add crude config generation
ndelangen Jan 24, 2025
8a58dbe
add main config generation
ndelangen Jan 24, 2025
da9991b
improve config generation
ndelangen Jan 24, 2025
1368d0d
improve messaging of configDir check
ndelangen Jan 24, 2025
e9abc33
previewConfig file generation
ndelangen Jan 24, 2025
5661454
Various prerequisite checks
ghengeveld Jan 24, 2025
2f2472c
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 24, 2025
426013c
Cleanup comments
ghengeveld Jan 24, 2025
f83bd4b
add a map for package names
ndelangen Jan 24, 2025
4302698
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 24, 2025
6266659
add detection
ndelangen Jan 27, 2025
29e75e1
I suppose we could do it like this
ndelangen Jan 27, 2025
e858811
add cwd
ndelangen Jan 27, 2025
6b9ec5d
Wrapup Vitest compatibility checks
ghengeveld Jan 27, 2025
6f059c1
Add new compatibility checks to old create-storybook CLI
ghengeveld Jan 28, 2025
a594eea
Fix installation process
ghengeveld Jan 28, 2025
8468f6f
remove unused ink
ndelangen Jan 29, 2025
88f3cbc
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 29, 2025
ef2f0e6
make intents question optional && more cleanup
ndelangen Jan 29, 2025
c3b2f8b
improve check
ndelangen Jan 29, 2025
46771c5
cleanup
ndelangen Jan 29, 2025
f4f1e3b
fix typing
ndelangen Jan 29, 2025
457a447
cleanup
ndelangen Jan 29, 2025
1c0dd49
fix
ndelangen Jan 29, 2025
9028541
do not run on CI
ndelangen Jan 29, 2025
6a6e89b
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 31, 2025
e433a08
cleanup
ndelangen Jan 31, 2025
6867b54
add intents to telemetry
ndelangen Jan 31, 2025
da37286
cleanup
ndelangen Jan 31, 2025
8e0d959
cleanup
ndelangen Jan 31, 2025
fe2dc28
cleanup
ndelangen Jan 31, 2025
5bad95b
cleanup
ndelangen Jan 31, 2025
2a2806f
prebundle create-storybook more
ndelangen Jan 31, 2025
2ff6044
remove prettier as a dependency
ndelangen Jan 31, 2025
5adcfd5
direct depend on storybook/core
ndelangen Jan 31, 2025
d43667d
fix forgotten usages of storybook/internal
ndelangen Jan 31, 2025
43029f5
Add support for extending existing Vitest workspace file
ghengeveld Jan 31, 2025
dc10757
Handle non-interactive (non TTY) mode
ghengeveld Jan 31, 2025
35656f0
add CLi flag for intents & send original intent to telemetry
ndelangen Jan 31, 2025
78a2d72
Don't default to migrating to nextjs-vite
ghengeveld Jan 31, 2025
0063c5e
Check for framework compatibility with addon-test
ghengeveld Jan 31, 2025
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
11 changes: 10 additions & 1 deletion code/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ module.exports = {
},
},
{
files: ['*.js', '*.jsx', '*.json', '*.html', '**/.storybook/*.ts', '**/.storybook/*.tsx'],
files: [
'*.js',
'*.jsx',
'*.json',
'*.html',
'**/.storybook/*.ts',
'**/.storybook/*.tsx',
'**/.storybook/**/*.ts',
'**/.storybook/**/*.tsx',
],
Comment on lines +61 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more concise glob pattern like '/.storybook//*.{ts,tsx}' instead of separate patterns

parserOptions: {
project: null,
},
Expand Down
3 changes: 2 additions & 1 deletion code/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { StorybookConfig } from '../frameworks/react-vite';

const componentsPath = join(__dirname, '../core/src/components');
const managerApiPath = join(__dirname, '../core/src/manager-api');
const imageContextPath = join(__dirname, '..//frameworks/nextjs/src/image-context.ts');
const imageContextPath = join(__dirname, '../frameworks/nextjs/src/image-context.ts');

const config: StorybookConfig = {
stories: [
Expand Down Expand Up @@ -159,6 +159,7 @@ const config: StorybookConfig = {
build: {
// disable sourcemaps in CI to not run out of memory
sourcemap: process.env.CI !== 'true',
target: ['chrome100'],
},
server: {
watch: {
Expand Down
3 changes: 1 addition & 2 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ export default async function postInstall(options: PostinstallOptions) {
args: ['playwright', 'install', 'chromium', '--with-deps'],
});

const fileExtension =
allDeps['typescript'] || (await findFile('tsconfig', ['.json'])) ? 'ts' : 'js';
const fileExtension = allDeps.typescript || (await findFile('tsconfig', ['.json'])) ? 'ts' : 'js';

const vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`);
if (existsSync(vitestSetupFile)) {
Expand Down
7 changes: 6 additions & 1 deletion code/core/scripts/prep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable local-rules/no-uncategorized-errors */
import { existsSync, mkdirSync, watch } from 'node:fs';
import { existsSync, watch } from 'node:fs';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';

Expand Down Expand Up @@ -124,6 +124,11 @@ async function run() {
platform: 'neutral',
mainFields: ['main', 'module', 'node'],
conditions: ['node', 'module', 'import', 'require'],
plugins: [],
define: {
'process.env.NODE_ENV': '"production"',
'process.env.DEV': '"false"',
},
} satisfies EsbuildContextOptions;

const browserAliases = {
Expand Down
4 changes: 3 additions & 1 deletion code/core/src/cli/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ command('build')
.option('--docs', 'Build a documentation-only site using addon-docs')
.option('--test', 'Build stories optimized for testing purposes.')
.action(async (options) => {
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const { env } = process;
env.NODE_ENV = env.NODE_ENV || 'production';

logger.setLevel(options.loglevel);
consoleLogger.log(picocolors.bold(`${pkg.name} v${pkg.version}\n`));

Expand Down
3 changes: 2 additions & 1 deletion code/core/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function printError(error: any) {
}

export const dev = async (cliOptions: CLIOptions) => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const { env } = process;
env.NODE_ENV = env.NODE_ENV || 'development';

const packageJson = await findPackage(__dirname);
invariant(packageJson, 'Failed to find the closest package.json file.');
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/core-server/utils/doTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry';
import type { CoreConfig, Options } from '@storybook/core/types';

import type Polka from 'polka';
import type { Polka } from 'polka';
import invariant from 'tiny-invariant';

import { sendTelemetryError } from '../withTelemetry';
Expand All @@ -11,7 +11,7 @@ import { summarizeIndex } from './summarizeIndex';
import { versionStatus } from './versionStatus';

export async function doTelemetry(
app: Polka.Polka,
app: Polka,
core: CoreConfig,
initializedStoryIndexGenerator: Promise<StoryIndexGenerator | undefined>,
options: Options
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/core-server/utils/getStoryIndexGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { normalizeStories } from '@storybook/core/common';
import type { DocsOptions, Options } from '@storybook/core/types';

import type Polka from 'polka';
import type { Polka } from 'polka';

import { StoryIndexGenerator } from './StoryIndexGenerator';
import type { ServerChannel } from './get-server-channel';
import { useStoriesJson } from './stories-json';

export async function getStoryIndexGenerator(
app: Polka.Polka,
app: Polka,
options: Options,
serverChannel: ServerChannel
): Promise<StoryIndexGenerator | undefined> {
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/core-server/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { writeFile } from 'node:fs/promises';

import { getStorybookMetadata } from '@storybook/core/telemetry';

import type Polka from 'polka';
import type { Polka } from 'polka';

export async function extractStorybookMetadata(outputFile: string, configDir: string) {
const storybookMetadata = await getStorybookMetadata(configDir);

await writeFile(outputFile, JSON.stringify(storybookMetadata));
}

export function useStorybookMetadata(app: Polka.Polka, configDir?: string) {
export function useStorybookMetadata(app: Polka, configDir?: string) {
app.use('/project.json', async (req, res) => {
const storybookMetadata = await getStorybookMetadata(configDir);
res.setHeader('Content-Type', 'application/json');
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/core-server/utils/server-statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { Options, StorybookConfigRaw } from '@storybook/core/types';
import { logger } from '@storybook/core/node-logger';

import picocolors from 'picocolors';
import type Polka from 'polka';
import type { Polka } from 'polka';
import sirv from 'sirv';
import { dedent } from 'ts-dedent';

export async function useStatics(app: Polka.Polka, options: Options): Promise<void> {
export async function useStatics(app: Polka, options: Options): Promise<void> {
const staticDirs = (await options.presets.apply('staticDirs')) ?? [];
const faviconPath = await options.presets.apply<string>('favicon');

Expand Down
8 changes: 4 additions & 4 deletions code/core/src/core-server/utils/stories-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { normalizeStoriesEntry } from '@storybook/core/common';
import { STORY_INDEX_INVALIDATED } from '@storybook/core/core-events';

import { debounce } from 'es-toolkit/compat';
import type Polka from 'polka';
import type { Polka, Request, Response } from 'polka';
import Watchpack from 'watchpack';

import { csfIndexer } from '../presets/common-preset';
Expand Down Expand Up @@ -58,10 +58,10 @@ const getInitializedStoryIndexGenerator = async (

describe('useStoriesJson', () => {
const use = vi.fn();
const app: Polka.Polka = { use } as any;
const app: Polka = { use } as any;
const end = vi.fn();
const write = vi.fn();
const response: Polka.Response = {
const response: Response = {
header: vi.fn(),
send: vi.fn(),
status: vi.fn(),
Expand All @@ -81,7 +81,7 @@ describe('useStoriesJson', () => {
Watchpack.mockClear();
});

const request: Polka.Request = {
const request: Request = {
headers: { accept: 'application/json' },
} as any;

Expand Down
4 changes: 2 additions & 2 deletions code/core/src/core-server/utils/stories-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { NormalizedStoriesSpecifier, StoryIndex } from '@storybook/core/typ
import { STORY_INDEX_INVALIDATED } from '@storybook/core/core-events';

import { debounce } from 'es-toolkit/compat';
import type Polka from 'polka';
import type { Polka } from 'polka';

import type { StoryIndexGenerator } from './StoryIndexGenerator';
import type { ServerChannel } from './get-server-channel';
Expand All @@ -33,7 +33,7 @@ export function useStoriesJson({
serverChannel,
normalizedStories,
}: {
app: Polka.Polka;
app: Polka;
initializedStoryIndexGenerator: Promise<StoryIndexGenerator>;
serverChannel: ServerChannel;
workingDir?: string;
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const telemetry = async (
) => {
// Don't notify on boot since it can lead to double notification in `sb init`.
// The notification will happen when the actual command runs.
if (eventType !== 'boot') {
if (eventType !== 'boot' && options.notify !== false) {
await notify();
}
const telemetryData: TelemetryData = {
Expand Down
1 change: 1 addition & 0 deletions code/core/src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface Options {
configDir?: string;
enableCrashReports?: boolean;
stripMetadata?: boolean;
notify?: boolean;
}

export interface TelemetryData {
Expand Down
1 change: 1 addition & 0 deletions code/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"moduleResolution": "bundler",
"module": "ES2022"
},
"include": ["src/**/*", "scripts/**/*", "*.d.ts"]
Expand Down
5 changes: 4 additions & 1 deletion code/lib/cli-storybook/bin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ process.once('uncaughtException', (error) => {
throw error;
});

require('../dist/bin/index.cjs');
import('../dist/bin/index.js').catch((error) => {
console.error(error);
process.exit(1);
});
11 changes: 7 additions & 4 deletions code/lib/cli-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"author": "Storybook Team",
"type": "module",
"exports": {
"./bin/index.cjs": {
"node": "./bin/index.cjs",
"require": "./bin/index.cjs"
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./bin/index.cjs": "./bin/index.cjs",
"./package.json": "./package.json"
},
"bin": "./bin/index.cjs",
Expand Down Expand Up @@ -78,7 +79,9 @@
"./src/index.ts",
"./src/bin/index.ts"
],
"platform": "node"
"formats": [
"node-esm"
]
},
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
}
4 changes: 2 additions & 2 deletions code/lib/cli-storybook/src/automigrate/fixes/mdx-to-csf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { runCodemod } from '@storybook/codemod';
// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import picocolors from 'picocolors';
import { prompt } from 'prompts';
import prompts from 'prompts';
import { dedent } from 'ts-dedent';

import { updateMainConfig } from '../helpers/mainConfigFile';
Expand Down Expand Up @@ -121,7 +121,7 @@ export const mdxToCSF: Fix<BareMdxStoriesGlobRunOptions> = {
${JSON.stringify(nextStoriesEntries, null, 2)}`);

if (!dryRun) {
const { glob: globString } = await prompt({
const { glob: globString } = await prompts.prompt({
type: 'text',
name: 'glob',
message: 'Please enter the glob for your MDX stories',
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli-storybook/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type BaseTemplates = Template & {
| 'TypeScript'})`;
};

const baseTemplates = {
export const baseTemplates = {
'cra/default-js': {
name: 'Create React App Latest (Webpack | JavaScript)',
script: `
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli-storybook/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { JsPackageManagerFactory } from 'storybook/internal/common';
import { versions } from 'storybook/internal/common';

import boxen from 'boxen';
import { initiate } from 'create-storybook';
import { downloadTemplate } from 'giget';
import picocolors from 'picocolors';
import prompts from 'prompts';
Expand Down Expand Up @@ -225,6 +224,7 @@ export const sandbox = async ({
const before = process.cwd();
process.chdir(templateDestination);
// we run doInitiate, instead of initiate, to avoid sending this init event to telemetry, because it's not a real world project
const { initiate } = await import('create-storybook');
await initiate({
dev: process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANBOX !== 'true',
...options,
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli-storybook/test/helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const CLI_PATH = path.join(__dirname, '..', 'bin', 'index.cjs');

/**
* Execute command
* @param {String[]} args - args to be passed in
* @param {Object} options - customize the behavior
*
* @param {String[]} args - Args to be passed in
* @param {Object} options - Customize the behavior
* @returns {Object}
*/
const run = (args, options = {}) => spawnSync('node', [CLI_PATH].concat(args), options);
Expand Down
5 changes: 4 additions & 1 deletion code/lib/cli/bin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ process.once('uncaughtException', (error) => {
throw error;
});

require('../dist/proxy.cjs');
import('../dist/proxy.js').catch((error) => {
console.error(error);
process.exit(1);
});
11 changes: 5 additions & 6 deletions code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./bin/index.cjs": {
"node": "./bin/index.cjs",
"require": "./bin/index.cjs"
},
"./bin/index.cjs": "./bin/index.cjs",
"./core-path": {
"types": "./dist/core-path.d.ts",
"node": "./dist/core-path.cjs",
"import": "./dist/core-path.js",
"require": "./dist/core-path.cjs"
},
Expand Down Expand Up @@ -338,7 +334,10 @@
"./src/core-path.ts",
"./src/index.ts"
],
"platform": "node"
"formats": [
"cjs",
"node-esm"
]
},
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
}
5 changes: 4 additions & 1 deletion code/lib/cli/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { spawn } from 'child_process';
const args = process.argv.slice(2);

if (['dev', 'build'].includes(args[0])) {
require('@storybook/core/cli/bin');
import('@storybook/core/cli/bin').catch((e) => {
console.error('Failed to load @storybook/core/cli/bin', e);
process.exit(1);
});
Comment on lines 7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider adding await to ensure the import completes before any other code runs

} else {
const proxiedArgs =
args[0] === 'init'
Expand Down
5 changes: 4 additions & 1 deletion code/lib/create-storybook/bin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ process.once('uncaughtException', (error) => {
throw error;
});

require('../dist/bin/index.cjs');
import('../dist/bin/index.js').catch((error) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using dynamic import() with .js extension may cause issues if the file is actually .cjs - verify the correct extension is being used

console.error(error);
process.exit(1);
});
Loading