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
Indexing: Introduce new experimental indexer
API - NESTED PR!
#23691
Conversation
Indexer: Deprecate `storyIndexers` API, add foundation for `indexers`
…upport-new-indexer
Core: Support new indexer API
indexer
APIindexer
API - NESTED PR!
indexer
API - NESTED PR!indexer
API - NESTED PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Co-authored-by: Michael Shilman <shilman@users.noreply.github.com>
Upgraded to Storybook 7.3.0, and all my component stories now fail to indexed, crashing the storybook build. Related to this PR?
My import { StorybookConfig } from '@storybook/react-vite';
import { projectConfig } from '../src/project-config';
// Set an env variable, so we can detect Storybook inside other tools (Mainly Tailwind)
process.env.STORYBOOK = 'true';
const config: StorybookConfig = {
framework: '@storybook/react-vite',
staticDirs: [
'../public',
{
// Move the favicon.svg to the root, so it can be found by the browser
from: '../public/assets/favicon.svg',
to: '/favicon.svg',
},
],
stories: [
{
directory: '../docs',
titlePrefix: 'Docs',
files: '**/*.mdx',
},
'../src/**/*.@(story|stories).@(js|jsx|ts|tsx)',
],
addons: [
'@storybook/addon-links',
{
name: '@storybook/addon-essentials',
options: {
backgrounds: false,
},
},
'@storybook/addon-a11y',
'@storybook/addon-interactions',
'@storybook/addon-designs',
],
core: {
builder: '@storybook/builder-vite',
},
};
export default config; |
@thebuilder confirmed this is a bug. should have a fix shortly. sorry for the inconvenience! |
I'm still seeing this error on v7.3.1 |
Could you share your main.js file? @GreenGremlin |
@kasperpeulen here's our main.ts file: import type { StorybookConfig } from '@storybook/react-webpack5';
import childProcess from 'child_process';
import path from 'path';
import webpack, { type Configuration } from 'webpack';
import buildAliasesFromTsconfig from '../config/buildAliasesFromTsConfig';
// This allows us to run storybook from a single package or for the entire repo
function getStoriesGlobs() {
if (!process.env.PWD) {
throw new Error(
'process.env.PWD not set! This is typically set by node, but could have been modified after the node process was started.'
);
}
const baseUrl = path.relative(__dirname, process.env.PWD);
if (baseUrl === '..') {
return [baseUrl + '/packages/**/src/**/stories.@(ts|tsx)', baseUrl + '/packages/**/src/**/*.stories.@(ts|tsx)'];
}
return [baseUrl + '/src/**/stories.@(ts|tsx)', baseUrl + '/src/**/*.stories.@(ts|tsx)'];
}
const commitHash = childProcess.execSync('git rev-parse --short HEAD').toString().trim();
const isIntegrationBuild = process.env.IS_INTEGRATION_BUILD === 'true';
const isProductionBuild = process.env.NODE_ENV === 'production';
const isSnapshotBuild = process.env.IS_SNAPSHOT_BUILD === 'true';
const storybookConfig: StorybookConfig = {
framework: {
name: '@storybook/react-webpack5',
options: {
builder: { lazyCompilation: true },
},
},
core: {
// Our storybook setup is likely too custom for these reports to be useful.
disableTelemetry: true,
enableCrashReports: false,
},
features: {
// Bundle splitting causes percy to fail with "TypeError: Cannot read property 'message' of undefined".
// The actual error is difficult to access, but it appears to be an uncaught error in a promise in the browser.
// This error only repros on CircleCI.
storyStoreV7: !isSnapshotBuild,
},
stories: getStoriesGlobs(),
addons: [
'@storybook/addon-a11y',
'@storybook/addon-essentials',
'@storybook/addon-knobs',
'@storybook/addon-links',
'storybook-addon-designs',
],
docs: {
autodocs: true,
},
webpackFinal: (config: Configuration) => {
// Slight hack to fix "Unable to determine deployment - Unexpected hostname" error when loading stories that use
// components that load the configuration manager.
config.plugins = config.plugins?.concat(
new webpack.DefinePlugin({
__DEV__: true,
__INTEGRATION_BUILD__: isIntegrationBuild,
__SNAPSHOT_BUILD__: isSnapshotBuild,
})
);
config.resolve ??= {};
config.resolve.alias = {
...config.resolve.alias,
'@internal-test/giraffe-client': path.resolve(
__dirname,
'..',
'packages/basics/giraffe-client/src/utils/testhelpers/index'
),
'@internal-test/internal-user-utils': path.resolve(
__dirname,
'..',
'packages/basics/internal-user-utils/src/utils/testhelpers/index'
),
// jsdom is not needed in storybook so far and this empty mock prevents it for using NodeJS modules that break the storybook build
jsdom: path.resolve(__dirname, 'jsdomMock.ts'),
...buildAliasesFromTsconfig(),
};
config.resolve.extensions ??= [];
config.resolve.extensions.push('.ts', '.tsx');
config.resolve.fallback = {
fs: false,
};
// Append commitHash to JS files instead of contentHash to help serve on engdocs
// Engdocs has multiple pods, each of which creates its own set of assets.
// If the bundle names differ, it will fail to serve depending on how the request is routed
config.output ??= {};
config.output.filename = `[name].${commitHash}.js`;
config.optimization ??= {};
config.optimization.chunkIds = 'deterministic';
// Addresses OOM issues
config.optimization.minimize = false;
config.devtool = false;
config.module ??= {};
config.module.rules ??= [];
const tsRuleIndex = config.module.rules.findIndex(
rule => typeof rule === 'object' && 'test' in rule && rule.test instanceof RegExp && rule.test.test('test.ts')
);
if (tsRuleIndex === -1) {
throw new Error("No *.ts rule found in storybook's webpack config.");
}
// Replace storybook's babel-loader with esbuild-loader. Matches the config from webpack.config.base.ts
config.module.rules.splice(
tsRuleIndex,
1,
{
// Storybook includes some .mjs files.
test: /\.m?js$/,
exclude: [/node_modules/],
enforce: 'pre',
use: ['source-map-loader'],
},
{
test: /\.tsx?$/,
exclude: [/node_modules/],
use: [
{
loader: 'esbuild-loader',
options: {
target: 'es2018',
// Setting this to 'automatic' currently breaks storybook builds.
// For some reason jsx_dev_runtime.jsxDEV is undefined when jsx = 'automatic'.
jsx: undefined,
// injects filename and source location into each JSX element, great for debugging
jsxDev: !isProductionBuild,
},
},
],
}
);
return config;
},
};
export default storybookConfig; |
Changelog
This PR contains multiple changes that should be referenced like so in the changelog (replacing the entry that this PR creates):
indexer
API - Indexing: Introduce new experimentalindexer
API - NESTED PR! #23691, thanks @JReinhold!indexer
API - Core, Server, Addon-docs: Replace story indexers with new API #23660, thanks @JReinhold!Completes milestone 1 of #23457
These changes have already been reviewed separately in:
#23582
#23626
#23656
#23660
#23676
#23632
What I did
How to test
Checklist
MIGRATION.MD
Maintainers
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
["cleanup", "BREAKING CHANGE", "feature request", "bug", "build", "documentation", "maintenance", "dependencies", "other"]
🦋 Canary release
This pull request has been released as version
0.0.0-pr-23691-sha-8f3fbd86
. Install it by pinning all your Storybook dependencies to that version.More information
0.0.0-pr-23691-sha-8f3fbd86
indexer-api
8f3fbd86
1691014389
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=23691