Webpack-tools: Work in progress

This commit is contained in:
Michael Shilman 2022-05-01 17:57:29 +08:00
parent af8b4828d7
commit e7a93c6f78
57 changed files with 395 additions and 148 deletions

View File

@ -56,6 +56,7 @@
"@storybook/store": "6.5.0-beta.1",
"@storybook/theming": "6.5.0-beta.1",
"@storybook/ui": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.0.10 || ^16.0.0",
"@types/webpack": "^4.41.26",
"autoprefixer": "^9.8.6",

View File

@ -5,7 +5,10 @@ import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import { logger } from '@storybook/node-logger';
import type { Builder, Options } from '@storybook/core-common';
import { useProgressReporting, checkWebpackVersion } from '@storybook/core-common';
import { useProgressReporting } from '@storybook/core-common';
import { checkWebpackVersion } from '@storybook/webpack-tools';
export * from './types';
let compilation: ReturnType<typeof webpackDevMiddleware>;
let reject: (reason?: any) => void;

View File

@ -1,8 +1,8 @@
import * as webpackReal from 'webpack';
import { logger } from '@storybook/node-logger';
import type { CoreConfig, Options } from '@storybook/core-common';
import { loadCustomWebpackConfig } from '@storybook/core-common';
import type { Configuration } from 'webpack';
import type { CoreConfig, Options } from '@storybook/core-common';
import { loadCustomWebpackConfig } from '@storybook/webpack-tools';
import { createDefaultWebpackConfig } from '../preview/base-webpack.config';
export async function webpack(config: Configuration, options: Options) {

View File

@ -1,9 +1,10 @@
import autoprefixer from 'autoprefixer';
import findUp from 'find-up';
import path from 'path';
import { logger } from '@storybook/node-logger';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { logger } from '@storybook/node-logger';
import type { LoadedPreset, Options } from '@storybook/core-common';
const warnImplicitPostcssPlugins = deprecate(

View File

@ -0,0 +1,51 @@
import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import type { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
import type { Configuration, Stats } from 'webpack';
import type {
Options,
TypescriptOptions as BaseTypescriptOptions,
BuilderResult as BaseBuilderResult,
} from '@storybook/core-common';
/**
* Options for TypeScript usage within Storybook.
*/
export interface TypescriptOptions extends BaseTypescriptOptions {
/**
* Configures `fork-ts-checker-webpack-plugin`
*/
checkOptions?: ForkTsCheckerWebpackPlugin['options'];
/**
* Sets the type of Docgen when working with React and TypeScript
*
* @default `'react-docgen-typescript'`
*/
reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
/**
* Configures `react-docgen-typescript-plugin`
*
* @default
* @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
*/
reactDocgenTypescriptOptions: PluginOptions;
}
export interface StorybookWebpackConfig {
/**
* Modify or return a custom Webpack config after the Storybook's default configuration
* has run (mostly used by addons).
*/
webpack?: (config: Configuration, options: Options) => Configuration | Promise<Configuration>;
/**
* Modify or return a custom Webpack config after every addon has run.
*/
webpackFinal?: (
config: Configuration,
options: Options
) => Configuration | Promise<Configuration>;
}
export interface BuilderResult extends BaseBuilderResult {
stats?: Stats;
}

View File

@ -55,6 +55,7 @@
"@storybook/semver": "^7.3.2",
"@storybook/store": "6.5.0-beta.1",
"@storybook/theming": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.0.10 || ^16.0.0",
"babel-loader": "^8.0.0",
"babel-plugin-named-exports-order": "^0.0.2",
@ -62,7 +63,7 @@
"case-sensitive-paths-webpack-plugin": "^2.3.0",
"core-js": "^3.8.2",
"css-loader": "^5.0.1",
"fork-ts-checker-webpack-plugin": "^6.0.4",
"fork-ts-checker-webpack-plugin": "^7.2.8",
"glob": "^7.1.6",
"glob-promise": "^3.4.0",
"html-webpack-plugin": "^5.0.0",

View File

@ -2,8 +2,11 @@ import webpack, { Stats, Configuration, ProgressPlugin, StatsOptions } from 'web
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import { logger } from '@storybook/node-logger';
import { useProgressReporting, checkWebpackVersion } from '@storybook/core-common';
import { useProgressReporting } from '@storybook/core-common';
import type { Builder, Options } from '@storybook/core-common';
import { checkWebpackVersion } from '@storybook/webpack-tools';
export * from './types';
let compilation: ReturnType<typeof webpackDevMiddleware>;
let reject: (reason?: any) => void;

View File

@ -1,9 +1,10 @@
import * as webpackReal from 'webpack';
import { logger } from '@storybook/node-logger';
import { loadCustomWebpackConfig, Options, CoreConfig } from '@storybook/core-common';
import type { Options, CoreConfig } from '@storybook/core-common';
import type { Configuration } from 'webpack';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { loadCustomWebpackConfig } from '@storybook/webpack-tools';
import { createDefaultWebpackConfig } from '../preview/base-webpack.config';
export async function webpack(config: Configuration, options: Options) {

View File

@ -0,0 +1,51 @@
import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import type { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
import type { Configuration, Stats } from 'webpack';
import type {
Options,
TypescriptOptions as BaseTypescriptOptions,
BuilderResult as BaseBuilderResult,
} from '@storybook/core-common';
/**
* Options for TypeScript usage within Storybook.
*/
export interface TypescriptOptions extends BaseTypescriptOptions {
/**
* Configures `fork-ts-checker-webpack-plugin`
*/
checkOptions?: ForkTsCheckerWebpackPlugin['options'];
/**
* Sets the type of Docgen when working with React and TypeScript
*
* @default `'react-docgen-typescript'`
*/
reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
/**
* Configures `react-docgen-typescript-plugin`
*
* @default
* @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
*/
reactDocgenTypescriptOptions: PluginOptions;
}
export interface StorybookWebpackConfig {
/**
* Modify or return a custom Webpack config after the Storybook's default configuration
* has run (mostly used by addons).
*/
webpack?: (config: Configuration, options: Options) => Configuration | Promise<Configuration>;
/**
* Modify or return a custom Webpack config after every addon has run.
*/
webpackFinal?: (
config: Configuration,
options: Options
) => Configuration | Promise<Configuration>;
}
export interface BuilderResult extends BaseBuilderResult {
stats?: Stats;
}

View File

@ -5,14 +5,14 @@
"keywords": [
"storybook"
],
"homepage": "https://github.com/storybookjs/storybook/tree/main/lib/core",
"homepage": "https://github.com/storybookjs/storybook/tree/main/lib/core-common",
"bugs": {
"url": "https://github.com/storybookjs/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybookjs/storybook.git",
"directory": "lib/core"
"directory": "lib/core-common"
},
"funding": {
"type": "opencollective",
@ -74,7 +74,6 @@
"express": "^4.17.1",
"file-system-cache": "^1.0.5",
"find-up": "^5.0.0",
"fork-ts-checker-webpack-plugin": "^6.0.4",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"handlebars": "^4.7.7",
@ -88,11 +87,9 @@
"slash": "^3.0.0",
"telejson": "^5.3.3",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2",
"webpack": "4"
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@storybook/react-docgen-typescript-plugin": "1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0",
"@types/compression": "^1.7.0",
"@types/interpret": "^1.1.1",
"@types/mock-fs": "^4.13.0",

View File

@ -1,7 +1,6 @@
export * from './presets';
export * from './utils/babel';
export * from './utils/check-webpack-version';
export * from './utils/check-addon-order';
export * from './utils/envs';
export * from './utils/es6Transpiler';
@ -10,11 +9,9 @@ export * from './utils/interpret-files';
export * from './utils/interpret-require';
export * from './utils/load-custom-babel-config';
export * from './utils/load-custom-presets';
export * from './utils/load-custom-webpack-config';
export * from './utils/load-manager-or-addons-file';
export * from './utils/load-preview-or-config-file';
export * from './utils/log-config';
export * from './utils/merge-webpack-config';
export * from './utils/paths';
export * from './utils/progress-reporting';
export * from './utils/resolve-path-in-sb-cache';

View File

@ -1,7 +1,4 @@
import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import type { Options as TelejsonOptions } from 'telejson';
import type { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
import type { Configuration, Stats } from 'webpack';
import type { TransformOptions } from '@babel/core';
import { Router } from 'express';
import { Server } from 'http';
@ -11,16 +8,6 @@ import { FileSystemCache } from './utils/file-cache';
* This file contains internal WIP types they MUST NOT be exported outside this package for now!
*/
export interface TypescriptConfig {
check: boolean;
reactDocgen: false | string;
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: boolean;
shouldRemoveUndefinedFromOptional: boolean;
propFilter: (prop: any) => boolean;
};
}
export type BuilderName = 'webpack4' | 'webpack5' | string;
export type BuilderConfigObject = {
@ -68,25 +55,15 @@ interface DirectoryMapping {
export interface Presets {
apply(
extension: 'typescript',
config: TypescriptConfig,
config: TypescriptOptions,
args?: Options
): Promise<TypescriptConfig>;
): Promise<TypescriptOptions>;
apply(extension: 'babel', config: {}, args: any): Promise<TransformOptions>;
apply(extension: 'entries', config: [], args: any): Promise<unknown>;
apply(extension: 'stories', config: [], args: any): Promise<StoriesEntry[]>;
apply(
extension: 'webpack',
config: {},
args: { babelOptions?: TransformOptions } & any
): Promise<Configuration>;
apply(extension: 'managerEntries', config: [], args: any): Promise<string[]>;
apply(extension: 'refs', config: [], args: any): Promise<unknown>;
apply(extension: 'core', config: {}, args: any): Promise<CoreConfig>;
apply(
extension: 'managerWebpack',
config: {},
args: Options & { babelOptions?: TransformOptions } & ManagerWebpackOptions
): Promise<Configuration>;
apply<T extends unknown>(extension: string, config?: T, args?: unknown): Promise<T>;
}
@ -131,7 +108,6 @@ export interface ReleaseNotesData {
}
export interface BuilderResult {
stats?: Stats;
totalTime?: ReturnType<typeof process.hrtime>;
}
@ -242,23 +218,6 @@ export interface TypescriptOptions {
* @default `false`
*/
check: boolean;
/**
* Configures `fork-ts-checker-webpack-plugin`
*/
checkOptions?: ForkTsCheckerWebpackPlugin['options'];
/**
* Sets the type of Docgen when working with React and TypeScript
*
* @default `'react-docgen-typescript'`
*/
reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
/**
* Configures `react-docgen-typescript-plugin`
*
* @default
* @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
*/
reactDocgenTypescriptOptions: PluginOptions;
}
interface StoriesSpecifier {
@ -406,7 +365,7 @@ export interface StorybookConfig {
/**
* References external Storybooks
*/
refs?: StorybookRefs | ((config: Configuration, options: Options) => StorybookRefs);
refs?: StorybookRefs | ((config: any, options: Options) => StorybookRefs);
/**
* Modify or return babel config.
@ -424,20 +383,6 @@ export interface StorybookConfig {
options: Options
) => TransformOptions | Promise<TransformOptions>;
/**
* Modify or return a custom Webpack config after the Storybook's default configuration
* has run (mostly used by addons).
*/
webpack?: (config: Configuration, options: Options) => Configuration | Promise<Configuration>;
/**
* Modify or return a custom Webpack config after every addon has run.
*/
webpackFinal?: (
config: Configuration,
options: Options
) => Configuration | Promise<Configuration>;
/**
* Add additional scripts to run in the preview a la `.storybook/preview.js`
*

View File

@ -2,8 +2,9 @@ import webpack, { ProgressPlugin } from 'webpack';
import type { Stats, Configuration } from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import { logger } from '@storybook/node-logger';
import { useProgressReporting, checkWebpackVersion } from '@storybook/core-common';
import { useProgressReporting } from '@storybook/core-common';
import type { Builder, Options } from '@storybook/core-common';
import { checkWebpackVersion } from '@storybook/webpack-tools';
import findUp from 'find-up';
import fs from 'fs-extra';

View File

@ -2,8 +2,9 @@ import webpack, { ProgressPlugin } from 'webpack';
import type { Stats, Configuration } from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import { logger } from '@storybook/node-logger';
import { useProgressReporting, checkWebpackVersion } from '@storybook/core-common';
import { useProgressReporting } from '@storybook/core-common';
import type { Builder, Options } from '@storybook/core-common';
import { checkWebpackVersion } from '@storybook/webpack-tools';
import findUp from 'find-up';
import fs from 'fs-extra';

View File

@ -0,0 +1,9 @@
# Storybook Core-Common
Common utilities used across `@storybook/core-server` (manager UI configuration) and `@storybook/builder-webpack{4,5}` (preview configuration).
This is a lot of code extracted for convenience, not because it made sense.
Supporting multiple version of webpack and this duplicating a large portion of code that was never meant to be generic caused this.
At some point we'll refactor this, it's likely a lot of this code is dead or barely used.

View File

@ -0,0 +1,54 @@
{
"name": "@storybook/webpack-tools",
"version": "6.5.0-beta.1",
"description": "Storybook framework-agnostic API",
"keywords": [
"storybook"
],
"homepage": "https://github.com/storybookjs/storybook/tree/main/lib/webpack-tools",
"bugs": {
"url": "https://github.com/storybookjs/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybookjs/storybook.git",
"directory": "lib/webpack-tools"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/ts3.9/index.d.ts",
"typesVersions": {
"<3.8": {
"dist/ts3.9/*": [
"dist/ts3.4/*"
]
}
},
"files": [
"dist/**/*",
"types/**/*",
"templates/**/*",
"*.js",
"*.d.ts"
],
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/node-logger": "6.5.0-beta.1",
"@types/node": "^14.0.10 || ^16.0.0",
"core-js": "^3.8.2",
"ts-dedent": "^2.0.0"
},
"publishConfig": {
"access": "public"
},
"gitHead": "b2e85f3599c043815b18bbfc5ca563bf1c6e4add",
"sbmodern": "dist/modern/index.js"
}

View File

@ -0,0 +1,4 @@
export * from './types';
export * from './load-custom-webpack-config';
export * from './check-webpack-version';
export * from './merge-webpack-config';

View File

@ -1,5 +1,5 @@
import path from 'path';
import { serverRequire } from './interpret-require';
import { serverRequire } from '@storybook/core-common';
const webpackConfigs = ['webpack.config', 'webpackfile'];

View File

@ -1,4 +1,4 @@
import type { Configuration } from 'webpack';
import type { WebpackConfiguration as Configuration } from './types';
function plugins(
{ plugins: defaultPlugins = [] }: Configuration,

View File

@ -0,0 +1,79 @@
import type {
Options,
TypescriptOptions as BaseTypescriptOptions,
BuilderResult as BaseBuilderResult,
StorybookConfig as BaseStorybookConfig,
} from '@storybook/core-common';
export type { Options, Preset } from '@storybook/core-common';
export interface ForkTsCheckerWebpackPluginOptions {}
export interface ReactDocgenTypescriptOptions {}
export interface WebpackConfiguration {
plugins?: any[];
module?: {
rules?: any[];
};
resolve?: {
extensions?: string[];
mainFields?: string[];
alias?: any;
};
optimization?: any;
devtool?: string;
}
export interface WebpackStats {}
/**
* Options for TypeScript usage within Storybook.
*/
export interface TypescriptOptions<
TForkTsCheckerWebpackPluginOptions extends ForkTsCheckerWebpackPluginOptions = ForkTsCheckerWebpackPluginOptions,
TReactDocgenTypescriptOptions extends ReactDocgenTypescriptOptions = ReactDocgenTypescriptOptions
> extends BaseTypescriptOptions {
/**
* Configures `fork-ts-checker-webpack-plugin`
*/
checkOptions?: TForkTsCheckerWebpackPluginOptions;
/**
* Sets the type of Docgen when working with React and TypeScript
*
* @default `'react-docgen-typescript'`
*/
reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
/**
* Configures `react-docgen-typescript-plugin`
*
* @default
* @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
*/
reactDocgenTypescriptOptions: TReactDocgenTypescriptOptions;
}
export interface StorybookWebpackConfig<
TConfiguration extends WebpackConfiguration = WebpackConfiguration
> {
/**
* Modify or return a custom Webpack config after the Storybook's default configuration
* has run (mostly used by addons).
*/
webpack?: (config: TConfiguration, options: Options) => TConfiguration | Promise<TConfiguration>;
/**
* Modify or return a custom Webpack config after every addon has run.
*/
webpackFinal?: (
config: TConfiguration,
options: Options
) => TConfiguration | Promise<TConfiguration>;
}
export type StorybookConfig<TConfiguration extends WebpackConfiguration = WebpackConfiguration> =
StorybookWebpackConfig<TConfiguration> & BaseStorybookConfig;
export interface BuilderResult<TStats extends WebpackStats> extends BaseBuilderResult {
stats?: TStats;
}

View File

@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
],
"exclude": [
"src/**.test.ts"
]
}

View File

@ -154,6 +154,9 @@
"@storybook/web-components": {
"implicitDependencies": []
},
"@storybook/webpack-tools": {
"implicitDependencies": []
},
"angular-cli": {
"implicitDependencies": []
},

View File

@ -205,6 +205,7 @@
"@storybook/ui": "workspace:*",
"@storybook/vue": "workspace:*",
"@storybook/web-components": "workspace:*",
"@storybook/webpack-tools": "workspace:*",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.2",

View File

@ -39,17 +39,13 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"core-js": "^3.8.2",
"html-loader": "^1.3.2",
"react": "16.14.0",
"react-dom": "16.14.0",
"regenerator-runtime": "^0.13.7",
"webpack": ">=4.0.0 <6.0.0"
},
"devDependencies": {
"webpack": "4"
"regenerator-runtime": "^0.13.7"
},
"peerDependencies": {
"@babel/core": "*"

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = (config) => {
config.module.rules.push({

View File

@ -40,18 +40,15 @@
},
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.12.12",
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/renderer-preact": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"core-js": "^3.8.2",
"react": "16.14.0",
"react-dom": "16.14.0",
"regenerator-runtime": "^0.13.7",
"webpack": ">=4.0.0 <6.0.0"
"regenerator-runtime": "^0.13.7"
},
"devDependencies": {
"preact": "^10.5.13",
"webpack": "4"
"preact": "^10.5.13"
},
"peerDependencies": {
"@babel/core": "*",

View File

@ -1,5 +1,5 @@
import path from 'path';
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const babelDefault: StorybookConfig['babelDefault'] = (config) => {
return {

View File

@ -43,24 +43,22 @@
"@babel/preset-flow": "^7.12.1",
"@babel/preset-react": "^7.12.10",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/docs-tools": "6.5.0-beta.1",
"@storybook/node-logger": "6.5.0-beta.1",
"@storybook/react-docgen-typescript-plugin": "1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0",
"@storybook/renderer-react": "6.5.0-beta.1",
"@storybook/semver": "^7.3.2",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-react-docgen": "^4.2.1",
"core-js": "^3.8.2",
"fs-extra": "^9.0.1",
"react-refresh": "^0.11.0",
"regenerator-runtime": "^0.13.7",
"webpack": ">=4.43.0 <6.0.0"
"regenerator-runtime": "^0.13.7"
},
"devDependencies": {
"@types/util-deprecate": "^1.0.0",
"webpack": "4"
"@types/util-deprecate": "^1.0.0"
},
"peerDependencies": {
"@babel/core": "^7.11.5",

View File

@ -1,5 +1,5 @@
import { logger } from '@storybook/node-logger';
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
import { isReactScriptsInstalled } from './cra-config';
type Preset = string | { name: string };

View File

@ -1,5 +1,5 @@
import ReactDocgenTypescriptPlugin from '@storybook/react-docgen-typescript-plugin';
import type { TypescriptConfig } from '@storybook/core-common';
import type { TypescriptConfig } from '@storybook/webpack-tools';
import * as preset from './framework-preset-react-docs';
describe('framework-preset-react-docgen', () => {

View File

@ -1,11 +1,11 @@
import type { StorybookConfig, TypescriptConfig } from '@storybook/core-common';
import type { StorybookConfig, TypescriptOptions } from '@storybook/webpack-tools';
import ReactDocgenTypescriptPlugin from '@storybook/react-docgen-typescript-plugin';
import { hasDocsOrControls } from '@storybook/docs-tools';
export const babel: StorybookConfig['babel'] = async (config, options) => {
if (!hasDocsOrControls(options)) return config;
const typescriptOptions = await options.presets.apply<TypescriptConfig>('typescript', {} as any);
const typescriptOptions = await options.presets.apply<TypescriptOptions>('typescript', {} as any);
const { reactDocgen } = typescriptOptions;
@ -34,7 +34,7 @@ export const babel: StorybookConfig['babel'] = async (config, options) => {
export const webpackFinal: StorybookConfig['webpackFinal'] = async (config, options) => {
if (!hasDocsOrControls(options)) return config;
const typescriptOptions = await options.presets.apply<TypescriptConfig>('typescript', {} as any);
const typescriptOptions = await options.presets.apply<TypescriptOptions>('typescript', {} as any);
const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions;

View File

@ -1,6 +1,6 @@
import { readJSON } from 'fs-extra';
import { IgnorePlugin } from 'webpack';
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
// this is a hack to allow importing react-dom/client even when it's not available
// this should be removed once we drop support for react-dom < 18

View File

@ -1,6 +1,6 @@
import type { Configuration } from 'webpack';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import type { Options } from '@storybook/core-common';
import type { Options } from '@storybook/webpack-tools';
import * as preset from './framework-preset-react';
const mockApply = jest.fn();

View File

@ -3,7 +3,7 @@ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import { logger } from '@storybook/node-logger';
import type { StorybookConfig, Options, Preset } from '@storybook/core-common';
import type { StorybookConfig, Options, Preset } from '@storybook/webpack-tools';
import type { ReactOptions } from './types';
const useFastRefresh = async (options: Options) => {

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const addons: StorybookConfig['addons'] = [
require.resolve('./framework-preset-react'),

View File

@ -1,4 +1,4 @@
import type { StorybookConfig as BaseConfig } from '@storybook/core-common';
import type { StorybookConfig as BaseConfig } from '@storybook/webpack-tools';
export interface ReactOptions {
fastRefresh?: boolean;
@ -16,7 +16,7 @@ export interface ReactOptions {
/**
* The interface for Storybook configuration in `main.ts` files.
*/
export interface StorybookConfig extends BaseConfig {
export interface ReactConfig {
framework:
| string
| {
@ -24,3 +24,5 @@ export interface StorybookConfig extends BaseConfig {
options: ReactOptions;
};
}
export type StorybookConfig = BaseConfig & ReactConfig;

View File

@ -39,9 +39,9 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/core-server": "6.5.0-beta.1",
"@storybook/renderer-server": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"core-js": "^3.8.2",
"global": "^4.4.0",

View File

@ -1,5 +1,5 @@
import path from 'path';
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = (config) => {
config.module.rules.push({

View File

@ -40,22 +40,20 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/node-logger": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"core-js": "^3.8.2",
"loader-utils": "^2.0.0",
"react": "16.14.0",
"react-dom": "16.14.0",
"regenerator-runtime": "^0.13.7",
"sveltedoc-parser": "4.1.0",
"ts-dedent": "^2.0.0",
"webpack": ">=4.0.0 <6.0.0"
"ts-dedent": "^2.0.0"
},
"devDependencies": {
"@types/loader-utils": "^2.0.0",
"svelte": "^3.31.2",
"svelte-loader": "^3.0.0",
"webpack": "4"
"svelte-loader": "^3.0.0"
},
"peerDependencies": {
"@babel/core": "*",

View File

@ -1,5 +1,5 @@
import path from 'path';
import { StorybookConfig } from '@storybook/core-common';
import { StorybookConfig } from '@storybook/webpack-tools';
export const webpackFinal: StorybookConfig['webpackFinal'] = async (config, options) => {
const svelteOptions = await options.presets.apply('svelteOptions', {} as any, options);

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = async (config, options) => {
const { preprocess = undefined, loader = {} } = await options.presets.apply(

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const addons: StorybookConfig['addons'] = [
require.resolve('./framework-preset-svelte'),

View File

@ -39,8 +39,8 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/docs-tools": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"core-js": "^3.8.2",
"react": "16.14.0",

View File

@ -1,4 +1,4 @@
import { StorybookConfig } from '@storybook/core-common';
import { StorybookConfig } from '@storybook/webpack-tools';
import { hasDocsOrControls } from '@storybook/docs-tools';
export const webpackFinal: StorybookConfig['webpackFinal'] = (config, options) => {

View File

@ -1,10 +1,10 @@
/* eslint-disable no-param-reassign */
import { VueLoaderPlugin } from 'vue-loader';
import type { TypescriptConfig, StorybookConfig } from '@storybook/core-common';
import type { TypescriptOptions, StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = async (config, { presets }) => {
const typescriptOptions = await presets.apply<TypescriptConfig>('typescript', {} as any);
const typescriptOptions = await presets.apply<TypescriptOptions>('typescript', {} as any);
config.plugins.push(new VueLoaderPlugin());
config.module.rules.push({

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const addons: StorybookConfig['addons'] = [
require.resolve('./framework-preset-vue'),

View File

@ -40,8 +40,8 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/docs-tools": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"core-js": "^3.8.2",
"react": "16.14.0",

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
import { hasDocsOrControls } from '@storybook/docs-tools';
export const webpackFinal: StorybookConfig['webpackFinal'] = (config, options) => {

View File

@ -1,6 +1,6 @@
import { VueLoaderPlugin } from 'vue-loader';
import { DefinePlugin } from 'webpack';
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = (config) => {
return {

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const addons: StorybookConfig['addons'] = [
require.resolve('./framework-preset-vue3'),

View File

@ -44,7 +44,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/preset-env": "^7.12.11",
"@storybook/core-common": "6.5.0-beta.1",
"@storybook/webpack-tools": "6.5.0-beta.1",
"@types/node": "^14.14.20 || ^16.0.0",
"babel-plugin-bundled-import-meta": "^0.3.1",
"core-js": "^3.8.2",

View File

@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/webpack-tools';
export const webpack: StorybookConfig['webpack'] = (config, options) => {
const babelrcOptions = options.features?.babelModeV7 ? null : { babelrc: false };

View File

@ -117,6 +117,10 @@
"root": "app/web-components",
"type": "library"
},
"@storybook/webpack-tools": {
"root": "lib/webpack-tools",
"type": "library"
},
"angular-cli": {
"root": "examples/angular-cli",
"type": "library"

View File

@ -7333,6 +7333,7 @@ __metadata:
"@storybook/store": 6.5.0-beta.1
"@storybook/theming": 6.5.0-beta.1
"@storybook/ui": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/case-sensitive-paths-webpack-plugin": ^2.1.4
"@types/node": ^14.0.10 || ^16.0.0
"@types/terser-webpack-plugin": ^4.2.0
@ -7397,6 +7398,7 @@ __metadata:
"@storybook/semver": ^7.3.2
"@storybook/store": 6.5.0-beta.1
"@storybook/theming": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/case-sensitive-paths-webpack-plugin": ^2.1.4
"@types/node": ^14.0.10 || ^16.0.0
"@types/terser-webpack-plugin": ^5.0.2
@ -7409,7 +7411,7 @@ __metadata:
case-sensitive-paths-webpack-plugin: ^2.3.0
core-js: ^3.8.2
css-loader: ^5.0.1
fork-ts-checker-webpack-plugin: ^6.0.4
fork-ts-checker-webpack-plugin: ^7.2.8
glob: ^7.1.6
glob-promise: ^3.4.0
html-webpack-plugin: ^5.0.0
@ -7698,7 +7700,6 @@ __metadata:
"@babel/preset-typescript": ^7.12.7
"@babel/register": ^7.12.1
"@storybook/node-logger": 6.5.0-beta.1
"@storybook/react-docgen-typescript-plugin": 1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0
"@storybook/semver": ^7.3.2
"@types/compression": ^1.7.0
"@types/interpret": ^1.1.1
@ -7714,7 +7715,6 @@ __metadata:
express: ^4.17.1
file-system-cache: ^1.0.5
find-up: ^5.0.0
fork-ts-checker-webpack-plugin: ^6.0.4
fs-extra: ^9.0.1
glob: ^7.1.6
handlebars: ^4.7.7
@ -7730,7 +7730,6 @@ __metadata:
telejson: ^5.3.3
ts-dedent: ^2.0.0
util-deprecate: ^1.0.2
webpack: 4
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
@ -8335,14 +8334,13 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/preset-html-webpack@workspace:presets/html-webpack"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
core-js: ^3.8.2
html-loader: ^1.3.2
react: 16.14.0
react-dom: 16.14.0
regenerator-runtime: ^0.13.7
webpack: 4
peerDependencies:
"@babel/core": "*"
languageName: unknown
@ -8353,15 +8351,13 @@ __metadata:
resolution: "@storybook/preset-preact-webpack@workspace:presets/preact-webpack"
dependencies:
"@babel/plugin-transform-react-jsx": ^7.12.12
"@storybook/core-common": 6.5.0-beta.1
"@storybook/renderer-preact": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
core-js: ^3.8.2
preact: ^10.5.13
react: 16.14.0
react-dom: 16.14.0
regenerator-runtime: ^0.13.7
webpack: 4
peerDependencies:
"@babel/core": "*"
preact: ^8.0.0||^10.0.0
@ -8375,12 +8371,12 @@ __metadata:
"@babel/preset-flow": ^7.12.1
"@babel/preset-react": ^7.12.10
"@pmmmwh/react-refresh-webpack-plugin": ^0.5.3
"@storybook/core-common": 6.5.0-beta.1
"@storybook/docs-tools": 6.5.0-beta.1
"@storybook/node-logger": 6.5.0-beta.1
"@storybook/react-docgen-typescript-plugin": 1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0
"@storybook/renderer-react": 6.5.0-beta.1
"@storybook/semver": ^7.3.2
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
"@types/util-deprecate": ^1.0.0
babel-plugin-add-react-displayname: ^0.0.5
@ -8389,7 +8385,6 @@ __metadata:
fs-extra: ^9.0.1
react-refresh: ^0.11.0
regenerator-runtime: ^0.13.7
webpack: 4
peerDependencies:
"@babel/core": ^7.11.5
jest-specific-snapshot: ^4.0.0
@ -8427,9 +8422,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/preset-server-webpack@workspace:presets/server-webpack"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/core-server": 6.5.0-beta.1
"@storybook/renderer-server": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
core-js: ^3.8.2
fs-extra: ^9.0.1
@ -8448,8 +8443,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/preset-svelte-webpack@workspace:presets/svelte-webpack"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/node-logger": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/loader-utils": ^2.0.0
core-js: ^3.8.2
loader-utils: ^2.0.0
@ -8460,7 +8455,6 @@ __metadata:
svelte-loader: ^3.0.0
sveltedoc-parser: 4.1.0
ts-dedent: ^2.0.0
webpack: 4
peerDependencies:
"@babel/core": "*"
svelte: ^3.1.0
@ -8472,8 +8466,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/preset-vue-webpack@workspace:presets/vue-webpack"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/docs-tools": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
core-js: ^3.8.2
react: 16.14.0
@ -8500,8 +8494,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/preset-vue3-webpack@workspace:presets/vue3-webpack"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/docs-tools": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
"@vue/compiler-sfc": 3.0.0
core-js: ^3.8.2
@ -8529,7 +8523,7 @@ __metadata:
"@babel/plugin-syntax-dynamic-import": ^7.8.3
"@babel/plugin-syntax-import-meta": ^7.10.4
"@babel/preset-env": ^7.12.11
"@storybook/core-common": 6.5.0-beta.1
"@storybook/webpack-tools": 6.5.0-beta.1
"@types/node": ^14.14.20 || ^16.0.0
babel-plugin-bundled-import-meta: ^0.3.1
core-js: ^3.8.2
@ -8908,6 +8902,7 @@ __metadata:
"@storybook/ui": "workspace:*"
"@storybook/vue": "workspace:*"
"@storybook/web-components": "workspace:*"
"@storybook/webpack-tools": "workspace:*"
"@testing-library/dom": ^7.29.4
"@testing-library/jest-dom": ^5.11.9
"@testing-library/react": ^11.2.2
@ -9387,6 +9382,18 @@ __metadata:
languageName: unknown
linkType: soft
"@storybook/webpack-tools@6.5.0-beta.1, @storybook/webpack-tools@workspace:*, @storybook/webpack-tools@workspace:lib/webpack-tools":
version: 0.0.0-use.local
resolution: "@storybook/webpack-tools@workspace:lib/webpack-tools"
dependencies:
"@storybook/core-common": 6.5.0-beta.1
"@storybook/node-logger": 6.5.0-beta.1
"@types/node": ^14.0.10 || ^16.0.0
core-js: ^3.8.2
ts-dedent: ^2.0.0
languageName: unknown
linkType: soft
"@stroncium/procfs@npm:^1.2.1":
version: 1.2.1
resolution: "@stroncium/procfs@npm:1.2.1"
@ -23694,6 +23701,32 @@ __metadata:
languageName: node
linkType: hard
"fork-ts-checker-webpack-plugin@npm:^7.2.8":
version: 7.2.8
resolution: "fork-ts-checker-webpack-plugin@npm:7.2.8"
dependencies:
"@babel/code-frame": ^7.16.7
chalk: ^4.1.2
chokidar: ^3.5.3
cosmiconfig: ^7.0.1
deepmerge: ^4.2.2
fs-extra: ^10.0.0
memfs: ^3.4.1
minimatch: ^3.0.4
schema-utils: ^3.1.1
semver: ^7.3.5
tapable: ^2.2.1
peerDependencies:
typescript: ">3.6.0"
vue-template-compiler: "*"
webpack: ^5.11.0
peerDependenciesMeta:
vue-template-compiler:
optional: true
checksum: a142888a4eb5846ec7f837b039a866121476f002a86fa981ae91c6bcf57986f3d330bcfe07eb38a4c97002c3332a3069a40f602ffa3f3f393b14cbfa24737d31
languageName: node
linkType: hard
"form-data@npm:^2.5.0":
version: 2.5.1
resolution: "form-data@npm:2.5.1"
@ -31919,7 +31952,7 @@ __metadata:
languageName: node
linkType: hard
"memfs@npm:^3.1.2, memfs@npm:^3.2.2":
"memfs@npm:^3.1.2, memfs@npm:^3.2.2, memfs@npm:^3.4.1":
version: 3.4.1
resolution: "memfs@npm:3.4.1"
dependencies:
@ -43415,7 +43448,7 @@ __metadata:
languageName: node
linkType: hard
"tapable@npm:^2.0.0, tapable@npm:^2.1.1, tapable@npm:^2.2.0":
"tapable@npm:^2.0.0, tapable@npm:^2.1.1, tapable@npm:^2.2.0, tapable@npm:^2.2.1":
version: 2.2.1
resolution: "tapable@npm:2.2.1"
checksum: bc40e6efe1e554d075469cedaba69a30eeb373552aaf41caeaaa45bf56ffacc2674261b106245bd566b35d8f3329b52d838e851ee0a852120acae26e622925c9