Skip to content
Closed
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
16 changes: 16 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 10.0.0-beta.3

- CLI: Add addon-console automigration - [#32083](https://github.com/storybookjs/storybook/pull/32083), thanks @Sidnioulz!
- CLI: Capture the version specifier used in `create-storybook` - [#32344](https://github.com/storybookjs/storybook/pull/32344), thanks @shilman!
- CLI: Init not running `dev` when it should fixed - [#32457](https://github.com/storybookjs/storybook/pull/32457), thanks @ndelangen!
- CSF: Support `satisfies x as y` syntax - [#32169](https://github.com/storybookjs/storybook/pull/32169), thanks @diagramatics!
- Core: Fix Node 24 deprecation warning - [#32382](https://github.com/storybookjs/storybook/pull/32382), thanks @JReinhold!
- Core: Switch from `mlly` to `exsolve` - [#32383](https://github.com/storybookjs/storybook/pull/32383), thanks @mrginglymus!
- Instrumenter: Fix userEvent.type performance regression - [#32439](https://github.com/storybookjs/storybook/pull/32439), thanks @ndelangen!
- Modernize: Replace `fs-extra` with native APIs - [#32296](https://github.com/storybookjs/storybook/pull/32296), thanks @y-hsgw!
- React Native Web: Fix RNW peer dependency version - [#32438](https://github.com/storybookjs/storybook/pull/32438), thanks @dannyhw!
- React: Preserve `@ts-expect-error` in preview - [#32442](https://github.com/storybookjs/storybook/pull/32442), thanks @mrginglymus!
- Replace: Use `empathic` over `find-up` - [#31338](https://github.com/storybookjs/storybook/pull/31338), thanks @beeequeue!
- Replace: Use `empathic` over `find-up` - [#32472](https://github.com/storybookjs/storybook/pull/32472), thanks @ndelangen!
- Telemetry: Record known CLI integrations - [#32448](https://github.com/storybookjs/storybook/pull/32448), thanks @shilman!

## 10.0.0-beta.2

- Build: Fix dts bundling external detection - [#32366](https://github.com/storybookjs/storybook/pull/32366), thanks @mrginglymus!
Expand Down
2 changes: 1 addition & 1 deletion code/addons/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"@vitest/browser": "^3.2.4",
"@vitest/runner": "^3.2.4",
"boxen": "^8.0.1",
"empathic": "^2.0.0",
"es-toolkit": "^1.36.0",
"execa": "^8.0.1",
"find-up": "^7.0.0",
"istanbul-lib-report": "^3.0.1",
"micromatch": "^4.0.8",
"pathe": "^1.1.2",
Expand Down
6 changes: 3 additions & 3 deletions code/addons/vitest/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
import { getProjectRoot, resolvePathInStorybookCache } from 'storybook/internal/common';
import type { StoryId, StoryIndex, StoryIndexEntry } from 'storybook/internal/types';

import { findUp } from 'find-up';
import * as find from 'empathic/find';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logic: This import should use find-up instead of empathic/find since PR #32470 reverted the empathic changes. The current import will cause runtime errors.

Suggested change
import * as find from 'empathic/find';
import { findUp } from 'find-up';

import path, { dirname, join, normalize } from 'pathe';
import slash from 'slash';

Expand Down Expand Up @@ -64,12 +64,12 @@ export class VitestManager {
: { enabled: false }
) as CoverageOptions;

const vitestWorkspaceConfig = await findUp(
const vitestWorkspaceConfig = find.any(
[
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`),
],
{ stopAt: getProjectRoot() }
{ last: getProjectRoot() }
);
Comment on lines +67 to 73

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logic: This API usage is incorrect - should use findUp() with stopAt parameter instead of find.any() with last parameter to match the reverted state.

Suggested change
const vitestWorkspaceConfig = find.any(
[
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`),
],
{ stopAt: getProjectRoot() }
{ last: getProjectRoot() }
);
const vitestWorkspaceConfig = await findUp(
[
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`),
],
{ stopAt: getProjectRoot() }
);


const projectName = 'storybook:' + process.env.STORYBOOK_CONFIG_DIR;
Expand Down
26 changes: 12 additions & 14 deletions code/addons/vitest/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { experimental_loadStorybook } from 'storybook/internal/core-server';
import { readConfig, writeConfig } from 'storybook/internal/csf-tools';
import { logger } from 'storybook/internal/node-logger';

import * as find from 'empathic/find';
import * as pkg from 'empathic/package';
// eslint-disable-next-line depend/ban-dependencies
import { execa } from 'execa';
import { findUp } from 'find-up';
import { dirname, relative, resolve } from 'pathe';
import prompts from 'prompts';
import { coerce, satisfies } from 'semver';
Expand Down Expand Up @@ -60,10 +61,10 @@ const logErrors = (...args: Parameters<typeof printError>) => {
printError(...args);
};

const findFile = async (basename: string, extensions = EXTENSIONS) =>
findUp(
const findFile = (basename: string, extensions = EXTENSIONS) =>
find.any(
extensions.map((ext) => basename + ext),
{ stopAt: getProjectRoot() }
{ last: getProjectRoot() }
);

export default async function postInstall(options: PostinstallOptions) {
Expand Down Expand Up @@ -320,7 +321,7 @@ export default async function postInstall(options: PostinstallOptions) {
}

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

const vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`);
if (existsSync(vitestSetupFile)) {
Expand Down Expand Up @@ -367,11 +368,11 @@ export default async function postInstall(options: PostinstallOptions) {
);

const vitestWorkspaceFile =
(await findFile('vitest.workspace', ['.ts', '.js', '.json'])) ||
(await findFile('vitest.projects', ['.ts', '.js', '.json']));
const viteConfigFile = await findFile('vite.config');
const vitestConfigFile = await findFile('vitest.config');
const vitestShimFile = await findFile('vitest.shims.d');
findFile('vitest.workspace', ['.ts', '.js', '.json']) ||
findFile('vitest.projects', ['.ts', '.js', '.json']);
const viteConfigFile = findFile('vite.config');
const vitestConfigFile = findFile('vitest.config');
const vitestShimFile = findFile('vitest.shims.d');
const rootConfig = vitestConfigFile || viteConfigFile;

const browserConfig = `{
Expand Down Expand Up @@ -576,10 +577,7 @@ async function getPackageNameFromPath(input: string): Promise<string> {
return path;
}

const packageJsonPath = await findUp('package.json', {
cwd: path,
});

const packageJsonPath = pkg.up({ cwd: path });
if (!packageJsonPath) {
throw new Error(`Could not find package.json in path: ${path}`);
}
Expand Down
3 changes: 1 addition & 2 deletions code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
"ts-dedent": "^2.0.0"
},
"devDependencies": {
"@types/find-cache-dir": "^3.2.1",
"@types/node": "^22.0.0",
"empathic": "^2.0.0",
"es-module-lexer": "^1.5.0",
"find-cache-dir": "^3.0.0",
"glob": "^10.0.0",
"knitwork": "^1.1.0",
"magic-string": "^0.30.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';

import * as pkg from 'empathic/package';
import { init, parse } from 'es-module-lexer';
import findCacheDirectory from 'find-cache-dir';
import MagicString from 'magic-string';
import type { Alias, Plugin } from 'vite';

Expand Down Expand Up @@ -52,10 +52,7 @@ export async function externalGlobalsPlugin(externals: Record<string, string>):
}
const newAlias = mergeAlias([], config.resolve?.alias) as Alias[];

const cachePath = findCacheDirectory({
name: 'sb-vite-plugin-externals',
create: true,
}) as string;
const cachePath = pkg.cache('sb-vite-plugin-externals', { create: true })!;
await Promise.all(
(Object.keys(externals) as Array<keyof typeof externals>).map(async (externalKey) => {
const externalCachePath = join(cachePath, `${externalKey}.js`);
Expand Down
6 changes: 1 addition & 5 deletions code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@
"@types/detect-port": "^1.3.0",
"@types/diff": "^5.0.9",
"@types/ejs": "^3.1.1",
"@types/find-cache-dir": "^5.0.0",
"@types/js-yaml": "^4.0.5",
"@types/node": "^22.0.0",
"@types/npmlog": "^7.0.0",
Expand Down Expand Up @@ -305,14 +304,12 @@
"diff": "^5.2.0",
"downshift": "^9.0.4",
"ejs": "^3.1.10",
"empathic": "^2.0.0",
"es-toolkit": "^1.36.0",
"esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0 || ^0.25.0",
"execa": "^8.0.1",
"exsolve": "^1.0.7",
"fd-package-json": "^1.2.0",
"fetch-retry": "^6.0.0",
"find-cache-dir": "^5.0.0",
"find-up": "^7.0.0",
"flush-promises": "^1.0.2",
"fuse.js": "^3.6.1",
"get-npm-tarball-url": "^2.0.3",
Expand Down Expand Up @@ -348,7 +345,6 @@
"react-textarea-autosize": "^8.3.0",
"react-transition-group": "^4.4.5",
"require-from-string": "^2.0.2",
"resolve-from": "^5.0.0",
"resolve.exports": "^2.0.3",
"sirv": "^2.0.4",
"slash": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/cli/detect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vi.mock(import('fs'), async (importOriginal) => {
});

vi.mock('storybook/internal/node-logger');
vi.mock('find-up');
vi.mock('empathic/find');

const MOCK_FRAMEWORK_FILES: {
name: string;
Expand Down
8 changes: 4 additions & 4 deletions code/core/src/cli/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { JsPackageManager, PackageJsonWithMaybeDeps } from 'storybook/inter
import { HandledError, commandLog, getProjectRoot } from 'storybook/internal/common';
import { logger } from 'storybook/internal/node-logger';

import { findUpSync } from 'find-up';
import * as find from 'empathic/find';
import prompts from 'prompts';
import semver from 'semver';

Expand Down Expand Up @@ -112,8 +112,8 @@ export function detectFrameworkPreset(
* @returns CoreBuilder
*/
export async function detectBuilder(packageManager: JsPackageManager, projectType: ProjectType) {
const viteConfig = findUpSync(viteConfigFiles, { stopAt: getProjectRoot() });
const webpackConfig = findUpSync(webpackConfigFiles, { stopAt: getProjectRoot() });
const viteConfig = find.any(viteConfigFiles, { last: getProjectRoot() });
const webpackConfig = find.any(webpackConfigFiles, { last: getProjectRoot() });
const dependencies = packageManager.getAllDependencies();

if (viteConfig || (dependencies.vite && dependencies.webpack === undefined)) {
Expand Down Expand Up @@ -171,7 +171,7 @@ export function isStorybookInstantiated(configDir = resolve(process.cwd(), '.sto
}

export async function detectPnp() {
return !!findUpSync(['.pnp.js', '.pnp.cjs']);
return !!find.any(['.pnp.js', '.pnp.cjs']);
}

export async function detectLanguage(packageManager: JsPackageManager) {
Expand Down
24 changes: 12 additions & 12 deletions code/core/src/cli/eslintPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile, writeFile } from 'node:fs/promises';

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { findUp } from 'find-up';
import * as find from 'empathic/find';
import { dedent } from 'ts-dedent';

import type { PackageJsonWithDepsAndDevDeps } from '../common';
Expand All @@ -14,8 +14,8 @@ import {
normalizeExtends,
} from './eslintPlugin';

vi.mock('find-up', () => ({
findUp: vi.fn(),
vi.mock('empathic/find', () => ({
up: vi.fn(),
}));

vi.mock(import('node:fs/promises'), async (importOriginal) => {
Expand All @@ -38,32 +38,32 @@ describe('extractEslintInfo', () => {
} satisfies Partial<JsPackageManager>;

beforeEach(() => {
vi.mocked(findUp).mockClear();
vi.mocked(find).up.mockClear();
mockPackageManager.getAllDependencies.mockClear();
});

it('should find ESLint config file with supported extension', async () => {
vi.mocked(findUp).mockImplementation(async (fileName) => {
vi.mocked(find).up.mockImplementation((fileName) => {
return String(fileName) === '.eslintrc.js' ? String(fileName) : undefined;
});

const result = await findEslintFile(process.cwd());
const result = findEslintFile(process.cwd());
expect(result).toBe('.eslintrc.js');
});

it('should return undefined if no ESLint config file is found', async () => {
vi.mocked(findUp).mockImplementation(async () => undefined);
vi.mocked(find).up.mockImplementation(() => undefined);

const result = await findEslintFile(process.cwd());
const result = findEslintFile(process.cwd());
expect(result).toBeUndefined();
});

it('should throw error for unsupported ESLint config file extensions', async () => {
vi.mocked(findUp).mockImplementation(async () => {
vi.mocked(find).up.mockImplementation(() => {
return '.eslintrc.yaml';
});

await expect(findEslintFile(process.cwd())).rejects.toThrowError(
expect(() => findEslintFile(process.cwd())).toThrowError(
'Unsupported ESLint config extension: .yaml'
);
});
Expand All @@ -72,7 +72,7 @@ describe('extractEslintInfo', () => {
mockPackageManager.getAllDependencies.mockReturnValue({});
mockPackageManager.primaryPackageJson.packageJson = { dependencies: {}, devDependencies: {} };

vi.mocked(findUp).mockImplementation(async () => undefined);
vi.mocked(find).up.mockImplementation(() => undefined);

const result = await extractEslintInfo(mockPackageManager as any);

Expand All @@ -96,7 +96,7 @@ describe('extractEslintInfo', () => {
operationDir: '/some/path',
};

vi.mocked(findUp).mockImplementation(async (fileName) =>
vi.mocked(find).up.mockImplementation((fileName) =>
String(fileName) === '.eslintrc.js' ? String(fileName) : undefined
);

Expand Down
10 changes: 5 additions & 5 deletions code/core/src/cli/eslintPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger, prompt } from 'storybook/internal/node-logger';

import commentJson from 'comment-json';
import detectIndent from 'detect-indent';
import { findUp } from 'find-up';
import * as find from 'empathic/find';
import picocolors from 'picocolors';
import { dedent } from 'ts-dedent';

Expand All @@ -15,13 +15,13 @@ import { babelParse, recast, types as t, traverse } from '../babel';
export const SUPPORTED_ESLINT_EXTENSIONS = ['ts', 'mts', 'cts', 'mjs', 'js', 'cjs', 'json'];
const UNSUPPORTED_ESLINT_EXTENSIONS = ['yaml', 'yml'];

export const findEslintFile = async (instanceDir: string) => {
export const findEslintFile = (instanceDir: string) => {
const filePrefixes = ['eslint.config', '.eslintrc'];

// Check for unsupported files
for (const prefix of filePrefixes) {
for (const ext of UNSUPPORTED_ESLINT_EXTENSIONS) {
const file = await findUp(`${prefix}.${ext}`, { cwd: instanceDir, stopAt: getProjectRoot() });
const file = find.up(`${prefix}.${ext}`, { cwd: instanceDir, last: getProjectRoot() });
if (file) {
throw new Error(`Unsupported ESLint config extension: .${ext}`);
}
Expand All @@ -31,7 +31,7 @@ export const findEslintFile = async (instanceDir: string) => {
// Find supported ESLint config files
for (const prefix of filePrefixes) {
for (const ext of SUPPORTED_ESLINT_EXTENSIONS) {
const file = await findUp(`${prefix}.${ext}`, { cwd: instanceDir, stopAt: getProjectRoot() });
const file = find.up(`${prefix}.${ext}`, { cwd: instanceDir, last: getProjectRoot() });
if (file) {
return file;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ export async function extractEslintInfo(packageManager: JsPackageManager): Promi
let eslintConfigFile: string | undefined = undefined;

try {
eslintConfigFile = await findEslintFile(packageManager.instanceDir);
eslintConfigFile = findEslintFile(packageManager.instanceDir);
} catch (err) {
if (err instanceof Error && err.message.includes('Unsupported ESLint')) {
unsupportedExtension = String(err);
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/cli/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ vi.mock('node:fs/promises', async (importOriginal) => {
};
});

vi.mock('find-up', () => ({
sync: vi.fn(),
vi.mock('empathic/find', () => ({
up: vi.fn(),
}));

vi.mock('path', async (importOriginal) => {
Expand Down
6 changes: 2 additions & 4 deletions code/core/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { join, resolve } from 'node:path';
import {
type JsPackageManager,
type PackageJson,
type PackageJsonWithDepsAndDevDeps,
frameworkToRenderer,
getProjectRoot,
} from 'storybook/internal/common';
import { versions as storybookMonorepoPackages } from 'storybook/internal/common';
import { logger } from 'storybook/internal/node-logger';
import type { SupportedFrameworks, SupportedRenderers } from 'storybook/internal/types';

import { findUpSync } from 'find-up';
import * as find from 'empathic/find';
import picocolors from 'picocolors';
import { coerce, satisfies } from 'semver';
import stripJsonComments from 'strip-json-comments';
Expand Down Expand Up @@ -261,7 +259,7 @@ export async function adjustTemplate(templatePath: string, templateData: Record<
}

export async function isNxProject() {
return findUpSync('nx.json', { stopAt: getProjectRoot() });
return find.up('nx.json', { last: getProjectRoot() });
}

export function coerceSemver(version: string) {
Expand Down
Loading