mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 06:41:17 +08:00
Merge pull request #15016 from storybookjs/14044-expand-webpack-instance
Presets: Expand `webpackInstance` to include entire namespace
This commit is contained in:
commit
f40b09dbdf
@ -16,12 +16,12 @@ let reject: (reason?: any) => void;
|
||||
|
||||
type WebpackBuilder = Builder<Configuration, Stats>;
|
||||
|
||||
// const webpack = (webpackReal as any) as typeof webpackType;
|
||||
export const executor = {
|
||||
get: async (options: Options) => {
|
||||
const version = ((await options.presets.apply('webpackVersion')) || '4') as string;
|
||||
const webpackInstance =
|
||||
(await options.presets.apply<typeof webpackType>('webpackInstance')) || webpackReal;
|
||||
(await options.presets.apply<{ default: typeof webpackType }>('webpackInstance'))?.default ||
|
||||
webpackReal;
|
||||
checkWebpackVersion({ version }, '4', 'builder-webpack4');
|
||||
return webpackInstance;
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import webpackReal from 'webpack';
|
||||
import * as webpackReal from 'webpack';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { loadCustomWebpackConfig } from '@storybook/core-common';
|
||||
import { createDefaultWebpackConfig } from '../preview/base-webpack.config';
|
||||
|
@ -40,7 +40,8 @@ export const executor = {
|
||||
get: async (options: Options) => {
|
||||
const version = ((await options.presets.apply('webpackVersion')) || '5') as string;
|
||||
const webpackInstance =
|
||||
(await options.presets.apply<typeof webpack>('webpackInstance')) || webpack;
|
||||
(await options.presets.apply<{ default: typeof webpack }>('webpackInstance'))?.default ||
|
||||
webpack;
|
||||
checkWebpackVersion({ version }, '5', 'builder-webpack5');
|
||||
return webpackInstance;
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import webpackReal from 'webpack';
|
||||
import * as webpackReal from 'webpack';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { loadCustomWebpackConfig, Options } from '@storybook/core-common';
|
||||
import type { Configuration } from 'webpack';
|
||||
|
@ -24,14 +24,6 @@ jest.setTimeout(10000);
|
||||
|
||||
const skipStoriesJsonPreset = [{ features: { buildStoriesJson: false } }];
|
||||
|
||||
// jest.mock('@storybook/builder-webpack5', () => {
|
||||
// const actualBuilder = jest.requireActual('@storybook/builder-webpack5');
|
||||
// // MUTATION! we couldn't mock webpack5, so we added a level of indirection instead
|
||||
// actualBuilder.executor.get = () => jest.fn();
|
||||
// actualBuilder.overridePresets = [...actualBuilder.overridePresets, skipStoriesJsonPreset];
|
||||
// return actualBuilder;
|
||||
// });
|
||||
|
||||
jest.mock('@storybook/builder-webpack4', () => {
|
||||
const value = jest.fn();
|
||||
const actualBuilder = jest.requireActual('@storybook/builder-webpack4');
|
||||
@ -172,8 +164,8 @@ describe.each([
|
||||
});
|
||||
});
|
||||
|
||||
// const progressPlugin = (config) =>
|
||||
// config.plugins.find((p) => p.constructor.name === 'ProgressPlugin');
|
||||
const progressPlugin = (config) =>
|
||||
config.plugins.find((p) => p.constructor.name === 'ProgressPlugin');
|
||||
|
||||
describe('dev cli flags', () => {
|
||||
beforeEach(() => {
|
||||
@ -183,18 +175,20 @@ describe('dev cli flags', () => {
|
||||
|
||||
const cliOptions = { ...reactOptions, ...baseOptions };
|
||||
|
||||
// it('baseline', async () => {
|
||||
// await buildDevStandalone(cliOptions);
|
||||
// const config = getConfig(previewExecutor.get, 'preview');
|
||||
// expect(progressPlugin(config)).toBeTruthy();
|
||||
// });
|
||||
// eslint-disable-next-line jest/no-disabled-tests
|
||||
it.skip('baseline', async () => {
|
||||
await buildDevStandalone(cliOptions);
|
||||
const config = getConfig(previewExecutor.get, 'preview');
|
||||
expect(progressPlugin(config)).toBeTruthy();
|
||||
});
|
||||
|
||||
// it('--quiet', async () => {
|
||||
// const options = { ...cliOptions, quiet: true };
|
||||
// await buildDevStandalone(options);
|
||||
// const config = getConfig(previewExecutor.get, 'preview');
|
||||
// expect(progressPlugin(config)).toBeFalsy();
|
||||
// });
|
||||
// eslint-disable-next-line jest/no-disabled-tests
|
||||
it.skip('--quiet', async () => {
|
||||
const options = { ...cliOptions, quiet: true };
|
||||
await buildDevStandalone(options);
|
||||
const config = getConfig(previewExecutor.get, 'preview');
|
||||
expect(progressPlugin(config)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('--webpack-stats-json calls output-stats', async () => {
|
||||
await buildDevStandalone(cliOptions);
|
||||
|
@ -6,6 +6,11 @@ export async function getManagerBuilder(configDir: Options['configDir']) {
|
||||
const mainFile = getInterpretedFile(main);
|
||||
const { core } = mainFile ? serverRequire(mainFile) : { core: null };
|
||||
|
||||
// Builder can be any string including community builders like `storybook-builder-vite`.
|
||||
// - For now, `webpack5` triggers `manager-webpack5`
|
||||
// - Everything else builds with `manager-webpack4`
|
||||
//
|
||||
// Unlike preview builders, manager building is not pluggable!
|
||||
const builderPackage =
|
||||
core?.builder === 'webpack5'
|
||||
? require.resolve('@storybook/manager-webpack5', { paths: [main] })
|
||||
|
@ -31,7 +31,8 @@ export const executor = {
|
||||
get: async (options: Options) => {
|
||||
const version = ((await options.presets.apply('webpackVersion')) || '4') as string;
|
||||
const webpackInstance =
|
||||
(await options.presets.apply<typeof webpack>('webpackInstance')) || webpack;
|
||||
(await options.presets.apply<{ default: typeof webpack }>('webpackInstance'))?.default ||
|
||||
webpack;
|
||||
checkWebpackVersion({ version }, '4', 'manager-webpack4');
|
||||
return webpackInstance;
|
||||
},
|
||||
|
@ -31,7 +31,8 @@ export const executor = {
|
||||
get: async (options: Options) => {
|
||||
const version = ((await options.presets.apply('webpackVersion')) || '5') as string;
|
||||
const webpackInstance =
|
||||
(await options.presets.apply<typeof webpack>('webpackInstance')) || webpack;
|
||||
(await options.presets.apply<{ default: typeof webpack }>('webpackInstance'))?.default ||
|
||||
webpack;
|
||||
checkWebpackVersion({ version }, '5', 'manager-webpack5');
|
||||
return webpackInstance;
|
||||
},
|
||||
@ -156,11 +157,6 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
|
||||
stats.toJson({ warnings: true }).warnings.forEach((e) => logger.warn(e.message));
|
||||
}
|
||||
|
||||
// const statsData = stats.toJson(
|
||||
// typeof statsOptions === 'string' ? statsOptions : { ...statsOptions, warnings: true }
|
||||
// );
|
||||
// statsData?.warnings?.forEach((e) => logger.warn(e));
|
||||
|
||||
succeed(stats);
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user