@storybook/core-webpack 7.0.0-alpha.21 → 7.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ import { StorybookConfig as StorybookConfig$1, Options, NormalizedStoriesSpecifier } from '@storybook/core-common';
2
+ export { BuilderResult, Options, Preset, TypescriptOptions } from '@storybook/core-common';
3
+
4
+ declare type RulesConfig = any;
5
+ declare type ModuleConfig = {
6
+ rules?: RulesConfig[];
7
+ };
8
+ declare type ResolveConfig = {
9
+ extensions?: string[];
10
+ mainFields?: (string | string[])[] | undefined;
11
+ alias?: any;
12
+ };
13
+ interface WebpackConfiguration {
14
+ plugins?: any[];
15
+ module?: ModuleConfig;
16
+ resolve?: ResolveConfig;
17
+ optimization?: any;
18
+ devtool?: false | string;
19
+ }
20
+ declare type StorybookConfig<TWebpackConfiguration = WebpackConfiguration> = StorybookConfig$1 & {
21
+ /**
22
+ * Modify or return a custom Webpack config after the Storybook's default configuration
23
+ * has run (mostly used by addons).
24
+ */
25
+ webpack?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
26
+ /**
27
+ * Modify or return a custom Webpack config after every addon has run.
28
+ */
29
+ webpackFinal?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
30
+ };
31
+
32
+ declare const loadCustomWebpackConfig: (configDir: string) => any;
33
+
34
+ declare const checkWebpackVersion: (webpack: {
35
+ version?: string;
36
+ }, specifier: string, caption: string) => void;
37
+
38
+ declare function mergeConfigs(config: WebpackConfiguration, customConfig: WebpackConfiguration): WebpackConfiguration;
39
+
40
+ declare function webpackIncludeRegexp(specifier: NormalizedStoriesSpecifier): RegExp;
41
+ declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
42
+ declare function toImportFn(stories: NormalizedStoriesSpecifier[], { needPipelinedImport }?: {
43
+ needPipelinedImport?: boolean;
44
+ }): string;
45
+
46
+ declare const toRequireContext: (specifier: NormalizedStoriesSpecifier) => {
47
+ path: string;
48
+ recursive: boolean;
49
+ match: RegExp;
50
+ };
51
+ declare const toRequireContextString: (specifier: NormalizedStoriesSpecifier) => string;
52
+
53
+ export { ModuleConfig, ResolveConfig, RulesConfig, StorybookConfig, WebpackConfiguration, checkWebpackVersion, loadCustomWebpackConfig, mergeConfigs, toImportFn, toImportFnPart, toRequireContext, toRequireContextString, webpackIncludeRegexp };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";var h=Object.create;var n=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var S=(e,o)=>{for(var i in o)n(e,i,{get:o[i],enumerable:!0})},l=(e,o,i,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of R(o))!y.call(e,t)&&t!==i&&n(e,t,{get:()=>o[t],enumerable:!(r=v(o,t))||r.enumerable});return e};var $=(e,o,i)=>(i=e!=null?h(k(e)):{},l(o||!e||!e.__esModule?n(i,"default",{value:e,enumerable:!0}):i,e)),w=e=>l(n({},"__esModule",{value:!0}),e);var O={};S(O,{checkWebpackVersion:()=>F,loadCustomWebpackConfig:()=>P,mergeConfigs:()=>T,toImportFn:()=>j,toImportFnPart:()=>d,toRequireContext:()=>b,toRequireContextString:()=>A,webpackIncludeRegexp:()=>g});module.exports=w(O);var u=$(require("path")),a=require("@storybook/core-common"),z=["webpack.config","webpackfile"],P=e=>(0,a.serverRequire)(z.map(o=>u.default.resolve(e,o)));var p=require("@storybook/node-logger"),m=require("ts-dedent"),F=(e,o,i)=>{if(!e.version){p.logger.info("Skipping webpack version check, no version available");return}e.version!==o&&p.logger.warn(m.dedent`
2
+ Unexpected webpack version in ${i}:
3
+ - Received '${e.version}'
4
+ - Expected '${o}'
5
+
6
+ If you're using Webpack 5 in SB6.2 and upgrading, consider: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build
7
+
8
+ For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
9
+ `)};function I(e=[],o=[]){return[...e,...o]}function M(e=[],o=[]){return[...e,...o]}function E({extensions:e=[]},{extensions:o=[]}){return[...e,...o]}function N({alias:e={}},{alias:o={}}){return{...e,...o}}function q(e,o){return{...e,...o,rules:M(e.rules||[],o.rules||[])}}function W({resolve:e={}},{resolve:o={}}){return{...e,...o,alias:N(e,o),extensions:E(e,o)}}function G({optimization:e={}},{optimization:o={}}){return{...e,...o}}function T(e,o){return{...o,...e,devtool:o.devtool||e.devtool,plugins:I(e.plugins,o.plugins),module:q(e.module||{},o.module||{}),resolve:W(e,o),optimization:G(e,o)}}var s=require("ts-dedent"),f=require("@storybook/core-common");function c(){let e=Promise.resolve();return async o=>{await e;let i=o();return e=e.then(async()=>{await i}),i}}function g(e){let{directory:o,files:i}=e,r=o.replace(/^(\.+\/)+/,"/"),t=[".",".."].includes(o)?i:`${r}/${i}`,C=(0,f.globToRegexp)(t);return new RegExp(C.source.replace(/^\^/,""))}function d(e){let{directory:o,importPathMatcher:i}=e;return s.dedent`
10
+ async (path) => {
11
+ if (!${i}.exec(path)) {
12
+ return;
13
+ }
14
+
15
+ const pathRemainder = path.substring(${o.length+1});
16
+ return import(
17
+ /* webpackChunkName: "[request]" */
18
+ /* webpackInclude: ${g(e)} */
19
+ '${o}/' + pathRemainder
20
+ );
21
+ }
22
+
23
+ `}function j(e,{needPipelinedImport:o}={}){let i="const pipeline = (x) => x();";return o&&(i=`
24
+ const importPipeline = ${c};
25
+ const pipeline = importPipeline();
26
+ `),s.dedent`
27
+ ${i}
28
+
29
+ const importers = [
30
+ ${e.map(d).join(`,
31
+ `)}
32
+ ];
33
+
34
+ export async function importFn(path) {
35
+ for (let i = 0; i < importers.length; i++) {
36
+ const moduleExports = await pipeline(() => importers[i](path));
37
+ if (moduleExports) {
38
+ return moduleExports;
39
+ }
40
+ }
41
+ }
42
+ `}var x=require("@storybook/core-common"),b=e=>{let{directory:o,files:i}=e,r=(0,x.globToRegexp)(`./${i}`);return{path:o,recursive:i.includes("**")||i.split("/").length>1,match:r}},A=e=>{let{path:o,recursive:i,match:r}=b(e);return`require.context('${o}', ${i}, ${r})`};0&&(module.exports={checkWebpackVersion,loadCustomWebpackConfig,mergeConfigs,toImportFn,toImportFnPart,toRequireContext,toRequireContextString,webpackIncludeRegexp});
package/dist/index.mjs ADDED
@@ -0,0 +1,42 @@
1
+ import u from"path";import{serverRequire as c}from"@storybook/core-common";var m=["webpack.config","webpackfile"],P=o=>c(m.map(e=>u.resolve(o,e)));import{logger as p}from"@storybook/node-logger";import{dedent as f}from"ts-dedent";var I=(o,e,i)=>{if(!o.version){p.info("Skipping webpack version check, no version available");return}o.version!==e&&p.warn(f`
2
+ Unexpected webpack version in ${i}:
3
+ - Received '${o.version}'
4
+ - Expected '${e}'
5
+
6
+ If you're using Webpack 5 in SB6.2 and upgrading, consider: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build
7
+
8
+ For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
9
+ `)};function g(o=[],e=[]){return[...o,...e]}function d(o=[],e=[]){return[...o,...e]}function C({extensions:o=[]},{extensions:e=[]}){return[...o,...e]}function b({alias:o={}},{alias:e={}}){return{...o,...e}}function x(o,e){return{...o,...e,rules:d(o.rules||[],e.rules||[])}}function k({resolve:o={}},{resolve:e={}}){return{...o,...e,alias:b(o,e),extensions:C(o,e)}}function y({optimization:o={}},{optimization:e={}}){return{...o,...e}}function E(o,e){return{...e,...o,devtool:e.devtool||o.devtool,plugins:g(o.plugins,e.plugins),module:x(o.module||{},e.module||{}),resolve:k(o,e),optimization:y(o,e)}}import{dedent as a}from"ts-dedent";import{globToRegexp as v}from"@storybook/core-common";function s(){let o=Promise.resolve();return async e=>{await o;let i=e();return o=o.then(async()=>{await i}),i}}function R(o){let{directory:e,files:i}=o,t=e.replace(/^(\.+\/)+/,"/"),n=[".",".."].includes(e)?i:`${t}/${i}`,l=v(n);return new RegExp(l.source.replace(/^\^/,""))}function h(o){let{directory:e,importPathMatcher:i}=o;return a`
10
+ async (path) => {
11
+ if (!${i}.exec(path)) {
12
+ return;
13
+ }
14
+
15
+ const pathRemainder = path.substring(${e.length+1});
16
+ return import(
17
+ /* webpackChunkName: "[request]" */
18
+ /* webpackInclude: ${R(o)} */
19
+ '${e}/' + pathRemainder
20
+ );
21
+ }
22
+
23
+ `}function j(o,{needPipelinedImport:e}={}){let i="const pipeline = (x) => x();";return e&&(i=`
24
+ const importPipeline = ${s};
25
+ const pipeline = importPipeline();
26
+ `),a`
27
+ ${i}
28
+
29
+ const importers = [
30
+ ${o.map(h).join(`,
31
+ `)}
32
+ ];
33
+
34
+ export async function importFn(path) {
35
+ for (let i = 0; i < importers.length; i++) {
36
+ const moduleExports = await pipeline(() => importers[i](path));
37
+ if (moduleExports) {
38
+ return moduleExports;
39
+ }
40
+ }
41
+ }
42
+ `}import{globToRegexp as S}from"@storybook/core-common";var w=o=>{let{directory:e,files:i}=o,t=S(`./${i}`);return{path:e,recursive:i.includes("**")||i.split("/").length>1,match:t}},L=o=>{let{path:e,recursive:i,match:t}=w(o);return`require.context('${e}', ${i}, ${t})`};export{I as checkWebpackVersion,P as loadCustomWebpackConfig,E as mergeConfigs,j as toImportFn,h as toImportFnPart,w as toRequireContext,L as toRequireContextString,R as webpackIncludeRegexp};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/core-webpack",
3
- "version": "7.0.0-alpha.21",
3
+ "version": "7.0.0-alpha.24",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -19,9 +19,17 @@
19
19
  "url": "https://opencollective.com/storybook"
20
20
  },
21
21
  "license": "MIT",
22
- "main": "dist/cjs/index.js",
23
- "module": "dist/esm/index.js",
24
- "types": "dist/types/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "require": "./dist/index.js",
25
+ "import": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "main": "dist/index.js",
31
+ "module": "dist/index.mjs",
32
+ "types": "dist/index.d.ts",
25
33
  "files": [
26
34
  "dist/**/*",
27
35
  "types/**/*",
@@ -31,11 +39,11 @@
31
39
  ],
32
40
  "scripts": {
33
41
  "check": "tsc --noEmit",
34
- "prepare": "node ../../../scripts/prepare.js"
42
+ "prepare": "../../../scripts/prepare/bundle.ts"
35
43
  },
36
44
  "dependencies": {
37
- "@storybook/core-common": "7.0.0-alpha.21",
38
- "@storybook/node-logger": "7.0.0-alpha.21",
45
+ "@storybook/core-common": "7.0.0-alpha.24",
46
+ "@storybook/node-logger": "7.0.0-alpha.24",
39
47
  "@types/node": "^14.0.10 || ^16.0.0",
40
48
  "core-js": "^3.8.2",
41
49
  "ts-dedent": "^2.0.0"
@@ -46,5 +54,11 @@
46
54
  "publishConfig": {
47
55
  "access": "public"
48
56
  },
49
- "gitHead": "d8cdc5b21af68e69c6eefeaae0e1efadd06947ea"
57
+ "bundler": {
58
+ "entries": [
59
+ "./src/index.ts"
60
+ ],
61
+ "platform": "node"
62
+ },
63
+ "gitHead": "e3232cb426b8381afa48f42e6baa45fd9af9bc3a"
50
64
  }
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.checkWebpackVersion = void 0;
7
-
8
- var _nodeLogger = require("@storybook/node-logger");
9
-
10
- var _tsDedent = require("ts-dedent");
11
-
12
- const checkWebpackVersion = (webpack, specifier, caption) => {
13
- if (!webpack.version) {
14
- _nodeLogger.logger.info('Skipping webpack version check, no version available');
15
-
16
- return;
17
- }
18
-
19
- if (webpack.version !== specifier) {
20
- _nodeLogger.logger.warn((0, _tsDedent.dedent)`
21
- Unexpected webpack version in ${caption}:
22
- - Received '${webpack.version}'
23
- - Expected '${specifier}'
24
-
25
- If you're using Webpack 5 in SB6.2 and upgrading, consider: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build
26
-
27
- For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
28
- `);
29
- }
30
- };
31
-
32
- exports.checkWebpackVersion = checkWebpackVersion;
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.importPipeline = importPipeline;
7
-
8
- // If an import is in flight when another import arrives, block it until the first completes.
9
- // This is to avoid a situation where webpack kicks off a second compilation whilst the
10
- // first is still completing, cf: https://github.com/webpack/webpack/issues/15541#issuecomment-1143138832
11
- // Note the way this code works if N futher `import()`s occur while the first is in flight,
12
- // they will all be kicked off in the same tick and not block each other. This is by design,
13
- // Webpack can handle multiple invalidations simutaneously, just not in quick succession.
14
- function importPipeline() {
15
- let importGate = Promise.resolve();
16
- return async importFn => {
17
- await importGate;
18
- const moduleExportsPromise = importFn();
19
- importGate = importGate.then(async () => {
20
- await moduleExportsPromise;
21
- });
22
- return moduleExportsPromise;
23
- };
24
- }
package/dist/cjs/index.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _types = require("./types");
8
-
9
- Object.keys(_types).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _types[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _types[key];
16
- }
17
- });
18
- });
19
-
20
- var _loadCustomWebpackConfig = require("./load-custom-webpack-config");
21
-
22
- Object.keys(_loadCustomWebpackConfig).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _loadCustomWebpackConfig[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _loadCustomWebpackConfig[key];
29
- }
30
- });
31
- });
32
-
33
- var _checkWebpackVersion = require("./check-webpack-version");
34
-
35
- Object.keys(_checkWebpackVersion).forEach(function (key) {
36
- if (key === "default" || key === "__esModule") return;
37
- if (key in exports && exports[key] === _checkWebpackVersion[key]) return;
38
- Object.defineProperty(exports, key, {
39
- enumerable: true,
40
- get: function () {
41
- return _checkWebpackVersion[key];
42
- }
43
- });
44
- });
45
-
46
- var _mergeWebpackConfig = require("./merge-webpack-config");
47
-
48
- Object.keys(_mergeWebpackConfig).forEach(function (key) {
49
- if (key === "default" || key === "__esModule") return;
50
- if (key in exports && exports[key] === _mergeWebpackConfig[key]) return;
51
- Object.defineProperty(exports, key, {
52
- enumerable: true,
53
- get: function () {
54
- return _mergeWebpackConfig[key];
55
- }
56
- });
57
- });
58
-
59
- var _toImportFn = require("./to-importFn");
60
-
61
- Object.keys(_toImportFn).forEach(function (key) {
62
- if (key === "default" || key === "__esModule") return;
63
- if (key in exports && exports[key] === _toImportFn[key]) return;
64
- Object.defineProperty(exports, key, {
65
- enumerable: true,
66
- get: function () {
67
- return _toImportFn[key];
68
- }
69
- });
70
- });
71
-
72
- var _toRequireContext = require("./to-require-context");
73
-
74
- Object.keys(_toRequireContext).forEach(function (key) {
75
- if (key === "default" || key === "__esModule") return;
76
- if (key in exports && exports[key] === _toRequireContext[key]) return;
77
- Object.defineProperty(exports, key, {
78
- enumerable: true,
79
- get: function () {
80
- return _toRequireContext[key];
81
- }
82
- });
83
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadCustomWebpackConfig = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _coreCommon = require("@storybook/core-common");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const webpackConfigs = ['webpack.config', 'webpackfile'];
15
-
16
- const loadCustomWebpackConfig = configDir => (0, _coreCommon.serverRequire)(webpackConfigs.map(configName => _path.default.resolve(configDir, configName)));
17
-
18
- exports.loadCustomWebpackConfig = loadCustomWebpackConfig;
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeConfigs = mergeConfigs;
7
-
8
- function mergePluginsField(defaultPlugins = [], customPlugins = []) {
9
- return [...defaultPlugins, ...customPlugins];
10
- }
11
-
12
- function mergeRulesField(defaultRules = [], customRules = []) {
13
- return [...defaultRules, ...customRules];
14
- }
15
-
16
- function mergeExtensionsField({
17
- extensions: defaultExtensions = []
18
- }, {
19
- extensions: customExtensions = []
20
- }) {
21
- return [...defaultExtensions, ...customExtensions];
22
- }
23
-
24
- function mergeAliasField({
25
- alias: defaultAlias = {}
26
- }, {
27
- alias: customAlias = {}
28
- }) {
29
- return Object.assign({}, defaultAlias, customAlias);
30
- }
31
-
32
- function mergeModuleField(a, b) {
33
- return Object.assign({}, a, b, {
34
- rules: mergeRulesField(a.rules || [], b.rules || [])
35
- });
36
- }
37
-
38
- function mergeResolveField({
39
- resolve: defaultResolve = {}
40
- }, {
41
- resolve: customResolve = {}
42
- }) {
43
- return Object.assign({}, defaultResolve, customResolve, {
44
- alias: mergeAliasField(defaultResolve, customResolve),
45
- extensions: mergeExtensionsField(defaultResolve, customResolve)
46
- });
47
- }
48
-
49
- function mergeOptimizationField({
50
- optimization: defaultOptimization = {}
51
- }, {
52
- optimization: customOptimization = {}
53
- }) {
54
- return Object.assign({}, defaultOptimization, customOptimization);
55
- }
56
-
57
- function mergeConfigs(config, customConfig) {
58
- return Object.assign({}, customConfig, config, {
59
- devtool: customConfig.devtool || config.devtool,
60
- plugins: mergePluginsField(config.plugins, customConfig.plugins),
61
- module: mergeModuleField(config.module || {}, customConfig.module || {}),
62
- resolve: mergeResolveField(config, customConfig),
63
- optimization: mergeOptimizationField(config, customConfig)
64
- });
65
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toImportFn = toImportFn;
7
- exports.toImportFnPart = toImportFnPart;
8
- exports.webpackIncludeRegexp = webpackIncludeRegexp;
9
-
10
- var _tsDedent = require("ts-dedent");
11
-
12
- var _coreCommon = require("@storybook/core-common");
13
-
14
- var _importPipeline = require("./importPipeline");
15
-
16
- function webpackIncludeRegexp(specifier) {
17
- const {
18
- directory,
19
- files
20
- } = specifier; // It appears webpack passes *something* similar to the absolute path to the file
21
- // on disk (prefixed with something unknown) to the matcher.
22
- // We don't want to include the absolute path in our bundle, so we will just pull any leading
23
- // `./` or `../` off our directory and match on that.
24
- // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
25
- // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
26
-
27
- const directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
28
- const webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
29
- const webpackIncludeRegexpWithCaret = (0, _coreCommon.globToRegexp)(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
30
-
31
- return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
32
- }
33
-
34
- function toImportFnPart(specifier) {
35
- const {
36
- directory,
37
- importPathMatcher
38
- } = specifier;
39
- return (0, _tsDedent.dedent)`
40
- async (path) => {
41
- if (!${importPathMatcher}.exec(path)) {
42
- return;
43
- }
44
-
45
- const pathRemainder = path.substring(${directory.length + 1});
46
- return import(
47
- /* webpackChunkName: "[request]" */
48
- /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
49
- '${directory}/' + pathRemainder
50
- );
51
- }
52
-
53
- `;
54
- }
55
-
56
- function toImportFn(stories, {
57
- needPipelinedImport
58
- } = {}) {
59
- let pipelinedImport = `const pipeline = (x) => x();`;
60
-
61
- if (needPipelinedImport) {
62
- pipelinedImport = `
63
- const importPipeline = ${_importPipeline.importPipeline};
64
- const pipeline = importPipeline();
65
- `;
66
- }
67
-
68
- return (0, _tsDedent.dedent)`
69
- ${pipelinedImport}
70
-
71
- const importers = [
72
- ${stories.map(toImportFnPart).join(',\n')}
73
- ];
74
-
75
- export async function importFn(path) {
76
- for (let i = 0; i < importers.length; i++) {
77
- const moduleExports = await pipeline(() => importers[i](path));
78
- if (moduleExports) {
79
- return moduleExports;
80
- }
81
- }
82
- }
83
- `;
84
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toRequireContextString = exports.toRequireContext = void 0;
7
-
8
- var _coreCommon = require("@storybook/core-common");
9
-
10
- const toRequireContext = specifier => {
11
- const {
12
- directory,
13
- files
14
- } = specifier; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
15
- // For `require.context()` we want the same thing, relative to directory
16
-
17
- const match = (0, _coreCommon.globToRegexp)(`./${files}`);
18
- return {
19
- path: directory,
20
- recursive: files.includes('**') || files.split('/').length > 1,
21
- match
22
- };
23
- };
24
-
25
- exports.toRequireContext = toRequireContext;
26
-
27
- const toRequireContextString = specifier => {
28
- const {
29
- path: p,
30
- recursive: r,
31
- match: m
32
- } = toRequireContext(specifier);
33
- const result = `require.context('${p}', ${r}, ${m})`;
34
- return result;
35
- };
36
-
37
- exports.toRequireContextString = toRequireContextString;
package/dist/cjs/types.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,20 +0,0 @@
1
- import { logger } from '@storybook/node-logger';
2
- import { dedent } from 'ts-dedent';
3
- export const checkWebpackVersion = (webpack, specifier, caption) => {
4
- if (!webpack.version) {
5
- logger.info('Skipping webpack version check, no version available');
6
- return;
7
- }
8
-
9
- if (webpack.version !== specifier) {
10
- logger.warn(dedent`
11
- Unexpected webpack version in ${caption}:
12
- - Received '${webpack.version}'
13
- - Expected '${specifier}'
14
-
15
- If you're using Webpack 5 in SB6.2 and upgrading, consider: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build
16
-
17
- For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
18
- `);
19
- }
20
- };
@@ -1,17 +0,0 @@
1
- // If an import is in flight when another import arrives, block it until the first completes.
2
- // This is to avoid a situation where webpack kicks off a second compilation whilst the
3
- // first is still completing, cf: https://github.com/webpack/webpack/issues/15541#issuecomment-1143138832
4
- // Note the way this code works if N futher `import()`s occur while the first is in flight,
5
- // they will all be kicked off in the same tick and not block each other. This is by design,
6
- // Webpack can handle multiple invalidations simutaneously, just not in quick succession.
7
- export function importPipeline() {
8
- let importGate = Promise.resolve();
9
- return async importFn => {
10
- await importGate;
11
- const moduleExportsPromise = importFn();
12
- importGate = importGate.then(async () => {
13
- await moduleExportsPromise;
14
- });
15
- return moduleExportsPromise;
16
- };
17
- }
package/dist/esm/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from './types';
2
- export * from './load-custom-webpack-config';
3
- export * from './check-webpack-version';
4
- export * from './merge-webpack-config';
5
- export * from './to-importFn';
6
- export * from './to-require-context';
@@ -1,4 +0,0 @@
1
- import path from 'path';
2
- import { serverRequire } from '@storybook/core-common';
3
- const webpackConfigs = ['webpack.config', 'webpackfile'];
4
- export const loadCustomWebpackConfig = configDir => serverRequire(webpackConfigs.map(configName => path.resolve(configDir, configName)));
@@ -1,58 +0,0 @@
1
- function mergePluginsField(defaultPlugins = [], customPlugins = []) {
2
- return [...defaultPlugins, ...customPlugins];
3
- }
4
-
5
- function mergeRulesField(defaultRules = [], customRules = []) {
6
- return [...defaultRules, ...customRules];
7
- }
8
-
9
- function mergeExtensionsField({
10
- extensions: defaultExtensions = []
11
- }, {
12
- extensions: customExtensions = []
13
- }) {
14
- return [...defaultExtensions, ...customExtensions];
15
- }
16
-
17
- function mergeAliasField({
18
- alias: defaultAlias = {}
19
- }, {
20
- alias: customAlias = {}
21
- }) {
22
- return Object.assign({}, defaultAlias, customAlias);
23
- }
24
-
25
- function mergeModuleField(a, b) {
26
- return Object.assign({}, a, b, {
27
- rules: mergeRulesField(a.rules || [], b.rules || [])
28
- });
29
- }
30
-
31
- function mergeResolveField({
32
- resolve: defaultResolve = {}
33
- }, {
34
- resolve: customResolve = {}
35
- }) {
36
- return Object.assign({}, defaultResolve, customResolve, {
37
- alias: mergeAliasField(defaultResolve, customResolve),
38
- extensions: mergeExtensionsField(defaultResolve, customResolve)
39
- });
40
- }
41
-
42
- function mergeOptimizationField({
43
- optimization: defaultOptimization = {}
44
- }, {
45
- optimization: customOptimization = {}
46
- }) {
47
- return Object.assign({}, defaultOptimization, customOptimization);
48
- }
49
-
50
- export function mergeConfigs(config, customConfig) {
51
- return Object.assign({}, customConfig, config, {
52
- devtool: customConfig.devtool || config.devtool,
53
- plugins: mergePluginsField(config.plugins, customConfig.plugins),
54
- module: mergeModuleField(config.module || {}, customConfig.module || {}),
55
- resolve: mergeResolveField(config, customConfig),
56
- optimization: mergeOptimizationField(config, customConfig)
57
- });
58
- }
@@ -1,70 +0,0 @@
1
- import { dedent } from 'ts-dedent';
2
- import { globToRegexp } from '@storybook/core-common';
3
- import { importPipeline } from './importPipeline';
4
- export function webpackIncludeRegexp(specifier) {
5
- const {
6
- directory,
7
- files
8
- } = specifier; // It appears webpack passes *something* similar to the absolute path to the file
9
- // on disk (prefixed with something unknown) to the matcher.
10
- // We don't want to include the absolute path in our bundle, so we will just pull any leading
11
- // `./` or `../` off our directory and match on that.
12
- // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
13
- // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
14
-
15
- const directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
16
- const webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
17
- const webpackIncludeRegexpWithCaret = globToRegexp(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
18
-
19
- return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
20
- }
21
- export function toImportFnPart(specifier) {
22
- const {
23
- directory,
24
- importPathMatcher
25
- } = specifier;
26
- return dedent`
27
- async (path) => {
28
- if (!${importPathMatcher}.exec(path)) {
29
- return;
30
- }
31
-
32
- const pathRemainder = path.substring(${directory.length + 1});
33
- return import(
34
- /* webpackChunkName: "[request]" */
35
- /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
36
- '${directory}/' + pathRemainder
37
- );
38
- }
39
-
40
- `;
41
- }
42
- export function toImportFn(stories, {
43
- needPipelinedImport
44
- } = {}) {
45
- let pipelinedImport = `const pipeline = (x) => x();`;
46
-
47
- if (needPipelinedImport) {
48
- pipelinedImport = `
49
- const importPipeline = ${importPipeline};
50
- const pipeline = importPipeline();
51
- `;
52
- }
53
-
54
- return dedent`
55
- ${pipelinedImport}
56
-
57
- const importers = [
58
- ${stories.map(toImportFnPart).join(',\n')}
59
- ];
60
-
61
- export async function importFn(path) {
62
- for (let i = 0; i < importers.length; i++) {
63
- const moduleExports = await pipeline(() => importers[i](path));
64
- if (moduleExports) {
65
- return moduleExports;
66
- }
67
- }
68
- }
69
- `;
70
- }
@@ -1,24 +0,0 @@
1
- import { globToRegexp } from '@storybook/core-common';
2
- export const toRequireContext = specifier => {
3
- const {
4
- directory,
5
- files
6
- } = specifier; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
7
- // For `require.context()` we want the same thing, relative to directory
8
-
9
- const match = globToRegexp(`./${files}`);
10
- return {
11
- path: directory,
12
- recursive: files.includes('**') || files.split('/').length > 1,
13
- match
14
- };
15
- };
16
- export const toRequireContextString = specifier => {
17
- const {
18
- path: p,
19
- recursive: r,
20
- match: m
21
- } = toRequireContext(specifier);
22
- const result = `require.context('${p}', ${r}, ${m})`;
23
- return result;
24
- };
package/dist/esm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export declare const checkWebpackVersion: (webpack: {
2
- version?: string;
3
- }, specifier: string, caption: string) => void;
@@ -1,3 +0,0 @@
1
- declare type ModuleExports = Record<string, any>;
2
- export declare function importPipeline(): (importFn: () => Promise<ModuleExports>) => Promise<ModuleExports>;
3
- export {};
@@ -1,6 +0,0 @@
1
- export * from './types';
2
- export * from './load-custom-webpack-config';
3
- export * from './check-webpack-version';
4
- export * from './merge-webpack-config';
5
- export * from './to-importFn';
6
- export * from './to-require-context';
@@ -1 +0,0 @@
1
- export declare const loadCustomWebpackConfig: (configDir: string) => any;
@@ -1,2 +0,0 @@
1
- import type { WebpackConfiguration as Configuration } from './types';
2
- export declare function mergeConfigs(config: Configuration, customConfig: Configuration): Configuration;
@@ -1,6 +0,0 @@
1
- import type { NormalizedStoriesSpecifier } from '@storybook/core-common';
2
- export declare function webpackIncludeRegexp(specifier: NormalizedStoriesSpecifier): RegExp;
3
- export declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
4
- export declare function toImportFn(stories: NormalizedStoriesSpecifier[], { needPipelinedImport }?: {
5
- needPipelinedImport?: boolean;
6
- }): string;
@@ -1,7 +0,0 @@
1
- import type { NormalizedStoriesSpecifier } from '@storybook/core-common';
2
- export declare const toRequireContext: (specifier: NormalizedStoriesSpecifier) => {
3
- path: string;
4
- recursive: boolean;
5
- match: RegExp;
6
- };
7
- export declare const toRequireContextString: (specifier: NormalizedStoriesSpecifier) => string;
@@ -1,29 +0,0 @@
1
- import type { Options, StorybookConfig as StorybookConfigBase } from '@storybook/core-common';
2
- export type { Options, Preset, BuilderResult, TypescriptOptions } from '@storybook/core-common';
3
- export declare type RulesConfig = any;
4
- export declare type ModuleConfig = {
5
- rules?: RulesConfig[];
6
- };
7
- export declare type ResolveConfig = {
8
- extensions?: string[];
9
- mainFields?: (string | string[])[] | undefined;
10
- alias?: any;
11
- };
12
- export interface WebpackConfiguration {
13
- plugins?: any[];
14
- module?: ModuleConfig;
15
- resolve?: ResolveConfig;
16
- optimization?: any;
17
- devtool?: false | string;
18
- }
19
- export declare type StorybookConfig<TWebpackConfiguration = WebpackConfiguration> = StorybookConfigBase & {
20
- /**
21
- * Modify or return a custom Webpack config after the Storybook's default configuration
22
- * has run (mostly used by addons).
23
- */
24
- webpack?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
25
- /**
26
- * Modify or return a custom Webpack config after every addon has run.
27
- */
28
- webpackFinal?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
29
- };