@storybook/core-webpack 7.0.0-alpha.8 → 7.0.0-beta.1

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/types';
2
+ export { BuilderResult, Options, Preset, TypescriptOptions } from '@storybook/types';
3
+
4
+ type RulesConfig = any;
5
+ type ModuleConfig = {
6
+ rules?: RulesConfig[];
7
+ };
8
+ 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
+ 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 path from"path";import{serverRequire}from"@storybook/core-common";var webpackConfigs=["webpack.config","webpackfile"],loadCustomWebpackConfig=configDir=>serverRequire(webpackConfigs.map(configName=>path.resolve(configDir,configName)));import{logger}from"@storybook/node-logger";import{dedent}from"ts-dedent";var checkWebpackVersion=(webpack,specifier,caption)=>{if(!webpack.version){logger.info("Skipping webpack version check, no version available");return}webpack.version!==specifier&&logger.warn(dedent`
2
+ Unexpected webpack version in ${caption}:
3
+ - Received '${webpack.version}'
4
+ - Expected '${specifier}'
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 mergePluginsField(defaultPlugins=[],customPlugins=[]){return[...defaultPlugins,...customPlugins]}function mergeRulesField(defaultRules=[],customRules=[]){return[...defaultRules,...customRules]}function mergeExtensionsField({extensions:defaultExtensions=[]},{extensions:customExtensions=[]}){return[...defaultExtensions,...customExtensions]}function mergeAliasField({alias:defaultAlias={}},{alias:customAlias={}}){return{...defaultAlias,...customAlias}}function mergeModuleField(a,b){return{...a,...b,rules:mergeRulesField(a.rules||[],b.rules||[])}}function mergeResolveField({resolve:defaultResolve={}},{resolve:customResolve={}}){return{...defaultResolve,...customResolve,alias:mergeAliasField(defaultResolve,customResolve),extensions:mergeExtensionsField(defaultResolve,customResolve)}}function mergeOptimizationField({optimization:defaultOptimization={}},{optimization:customOptimization={}}){return{...defaultOptimization,...customOptimization}}function mergeConfigs(config,customConfig){return{...customConfig,...config,devtool:customConfig.devtool||config.devtool,plugins:mergePluginsField(config.plugins,customConfig.plugins),module:mergeModuleField(config.module||{},customConfig.module||{}),resolve:mergeResolveField(config,customConfig),optimization:mergeOptimizationField(config,customConfig)}}import{dedent as dedent2}from"ts-dedent";import{globToRegexp}from"@storybook/core-common";function importPipeline(){let importGate=Promise.resolve();return async importFn=>{await importGate;let moduleExportsPromise=importFn();return importGate=importGate.then(async()=>{await moduleExportsPromise}),moduleExportsPromise}}function webpackIncludeRegexp(specifier){let{directory,files}=specifier,directoryWithoutLeadingDots=directory.replace(/^(\.+\/)+/,"/"),webpackIncludeGlob=[".",".."].includes(directory)?files:`${directoryWithoutLeadingDots}/${files}`,webpackIncludeRegexpWithCaret=globToRegexp(webpackIncludeGlob);return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/,""))}function toImportFnPart(specifier){let{directory,importPathMatcher}=specifier;return dedent2`
10
+ async (path) => {
11
+ if (!${importPathMatcher}.exec(path)) {
12
+ return;
13
+ }
14
+
15
+ const pathRemainder = path.substring(${directory.length+1});
16
+ return import(
17
+ /* webpackChunkName: "[request]" */
18
+ /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
19
+ '${directory}/' + pathRemainder
20
+ );
21
+ }
22
+
23
+ `}function toImportFn(stories,{needPipelinedImport}={}){let pipelinedImport="const pipeline = (x) => x();";return needPipelinedImport&&(pipelinedImport=`
24
+ const importPipeline = ${importPipeline};
25
+ const pipeline = importPipeline();
26
+ `),dedent2`
27
+ ${pipelinedImport}
28
+
29
+ const importers = [
30
+ ${stories.map(toImportFnPart).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 globToRegexp2}from"@storybook/core-common";var toRequireContext=specifier=>{let{directory,files}=specifier,match=globToRegexp2(`./${files}`);return{path:directory,recursive:files.includes("**")||files.split("/").length>1,match}},toRequireContextString=specifier=>{let{path:p,recursive:r,match:m}=toRequireContext(specifier);return`require.context('${p}', ${r}, ${m})`};export{checkWebpackVersion,loadCustomWebpackConfig,mergeConfigs,toImportFn,toImportFnPart,toRequireContext,toRequireContextString,webpackIncludeRegexp};
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ const path = require('path');
2
+ const baseConfig = require('../../jest.config.node');
3
+
4
+ module.exports = {
5
+ ...baseConfig,
6
+ displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/core-webpack",
3
- "version": "7.0.0-alpha.8",
3
+ "version": "7.0.0-beta.1",
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/**/*",
@@ -30,17 +38,28 @@
30
38
  "*.d.ts"
31
39
  ],
32
40
  "scripts": {
33
- "prepare": "node ../../scripts/prepare.js"
41
+ "check": "../../../scripts/node_modules/.bin/tsc --noEmit",
42
+ "prep": "../../../scripts/prepare/bundle.ts"
34
43
  },
35
44
  "dependencies": {
36
- "@storybook/core-common": "7.0.0-alpha.8",
37
- "@storybook/node-logger": "7.0.0-alpha.8",
38
- "@types/node": "^14.0.10 || ^16.0.0",
39
- "core-js": "^3.8.2",
45
+ "@storybook/core-common": "7.0.0-beta.1",
46
+ "@storybook/node-logger": "7.0.0-beta.1",
47
+ "@storybook/types": "7.0.0-beta.1",
48
+ "@types/node": "^16.0.0",
40
49
  "ts-dedent": "^2.0.0"
41
50
  },
51
+ "devDependencies": {
52
+ "typescript": "~4.9.3",
53
+ "webpack": "5"
54
+ },
42
55
  "publishConfig": {
43
56
  "access": "public"
44
57
  },
45
- "gitHead": "24725501c32a073cebc6bf2674a47357136fbe3a"
58
+ "bundler": {
59
+ "entries": [
60
+ "./src/index.ts"
61
+ ],
62
+ "platform": "node"
63
+ },
64
+ "gitHead": "42c08678ac06d9c2c8e7a4c31a91e0a14bf5c2cd"
46
65
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,34 +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 = _interopRequireDefault(require("ts-dedent"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const checkWebpackVersion = (webpack, specifier, caption) => {
15
- if (!webpack.version) {
16
- _nodeLogger.logger.info('Skipping webpack version check, no version available');
17
-
18
- return;
19
- }
20
-
21
- if (webpack.version !== specifier) {
22
- _nodeLogger.logger.warn((0, _tsDedent.default)`
23
- Unexpected webpack version in ${caption}:
24
- - Received '${webpack.version}'
25
- - Expected '${specifier}'
26
-
27
- 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
28
-
29
- For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
30
- `);
31
- }
32
- };
33
-
34
- 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,86 +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 = _interopRequireDefault(require("ts-dedent"));
11
-
12
- var _coreCommon = require("@storybook/core-common");
13
-
14
- var _importPipeline = require("./importPipeline");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function webpackIncludeRegexp(specifier) {
19
- const {
20
- directory,
21
- files
22
- } = specifier; // It appears webpack passes *something* similar to the absolute path to the file
23
- // on disk (prefixed with something unknown) to the matcher.
24
- // We don't want to include the absolute path in our bundle, so we will just pull any leading
25
- // `./` or `../` off our directory and match on that.
26
- // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
27
- // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
28
-
29
- const directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
30
- const webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
31
- const webpackIncludeRegexpWithCaret = (0, _coreCommon.globToRegexp)(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
32
-
33
- return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
34
- }
35
-
36
- function toImportFnPart(specifier) {
37
- const {
38
- directory,
39
- importPathMatcher
40
- } = specifier;
41
- return (0, _tsDedent.default)`
42
- async (path) => {
43
- if (!${importPathMatcher}.exec(path)) {
44
- return;
45
- }
46
-
47
- const pathRemainder = path.substring(${directory.length + 1});
48
- return import(
49
- /* webpackChunkName: "[request]" */
50
- /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
51
- '${directory}/' + pathRemainder
52
- );
53
- }
54
-
55
- `;
56
- }
57
-
58
- function toImportFn(stories, {
59
- needPipelinedImport
60
- } = {}) {
61
- let pipelinedImport = `const pipeline = (x) => x();`;
62
-
63
- if (needPipelinedImport) {
64
- pipelinedImport = `
65
- const importPipeline = ${_importPipeline.importPipeline};
66
- const pipeline = importPipeline();
67
- `;
68
- }
69
-
70
- return (0, _tsDedent.default)`
71
- ${pipelinedImport}
72
-
73
- const importers = [
74
- ${stories.map(toImportFnPart).join(',\n')}
75
- ];
76
-
77
- export async function importFn(path) {
78
- for (let i = 0; i < importers.length; i++) {
79
- const moduleExports = await pipeline(() => importers[i](path));
80
- if (moduleExports) {
81
- return moduleExports;
82
- }
83
- }
84
- }
85
- `;
86
- }
@@ -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
- };