@storybook/core-webpack 7.0.0-alpha.2 → 7.0.0-alpha.20
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.
- package/dist/cjs/check-webpack-version.js +2 -4
- package/dist/cjs/importPipeline.js +24 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/merge-webpack-config.js +15 -31
- package/dist/cjs/to-importFn.js +84 -0
- package/dist/cjs/to-require-context.js +37 -0
- package/dist/esm/check-webpack-version.js +1 -1
- package/dist/esm/importPipeline.js +17 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/merge-webpack-config.js +15 -31
- package/dist/esm/to-importFn.js +70 -0
- package/dist/esm/to-require-context.js +24 -0
- package/dist/types/importPipeline.d.ts +3 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/merge-webpack-config.d.ts +1 -1
- package/dist/types/to-importFn.d.ts +6 -0
- package/dist/types/to-require-context.d.ts +7 -0
- package/dist/types/types.d.ts +18 -16
- package/package.json +9 -5
- package/LICENSE +0 -21
|
@@ -7,9 +7,7 @@ exports.checkWebpackVersion = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _nodeLogger = require("@storybook/node-logger");
|
|
9
9
|
|
|
10
|
-
var _tsDedent =
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
var _tsDedent = require("ts-dedent");
|
|
13
11
|
|
|
14
12
|
const checkWebpackVersion = (webpack, specifier, caption) => {
|
|
15
13
|
if (!webpack.version) {
|
|
@@ -19,7 +17,7 @@ const checkWebpackVersion = (webpack, specifier, caption) => {
|
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
if (webpack.version !== specifier) {
|
|
22
|
-
_nodeLogger.logger.warn((0, _tsDedent.
|
|
20
|
+
_nodeLogger.logger.warn((0, _tsDedent.dedent)`
|
|
23
21
|
Unexpected webpack version in ${caption}:
|
|
24
22
|
- Received '${webpack.version}'
|
|
25
23
|
- Expected '${specifier}'
|
|
@@ -0,0 +1,24 @@
|
|
|
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
CHANGED
|
@@ -54,4 +54,30 @@ Object.keys(_mergeWebpackConfig).forEach(function (key) {
|
|
|
54
54
|
return _mergeWebpackConfig[key];
|
|
55
55
|
}
|
|
56
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
|
+
});
|
|
57
83
|
});
|
|
@@ -5,23 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.mergeConfigs = mergeConfigs;
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
plugins: defaultPlugins = []
|
|
10
|
-
}, {
|
|
11
|
-
plugins: customPlugins = []
|
|
12
|
-
}) {
|
|
8
|
+
function mergePluginsField(defaultPlugins = [], customPlugins = []) {
|
|
13
9
|
return [...defaultPlugins, ...customPlugins];
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
function
|
|
17
|
-
rules: defaultRules = []
|
|
18
|
-
}, {
|
|
19
|
-
rules: customRules = []
|
|
20
|
-
}) {
|
|
12
|
+
function mergeRulesField(defaultRules = [], customRules = []) {
|
|
21
13
|
return [...defaultRules, ...customRules];
|
|
22
14
|
}
|
|
23
15
|
|
|
24
|
-
function
|
|
16
|
+
function mergeExtensionsField({
|
|
25
17
|
extensions: defaultExtensions = []
|
|
26
18
|
}, {
|
|
27
19
|
extensions: customExtensions = []
|
|
@@ -29,7 +21,7 @@ function extensions({
|
|
|
29
21
|
return [...defaultExtensions, ...customExtensions];
|
|
30
22
|
}
|
|
31
23
|
|
|
32
|
-
function
|
|
24
|
+
function mergeAliasField({
|
|
33
25
|
alias: defaultAlias = {}
|
|
34
26
|
}, {
|
|
35
27
|
alias: customAlias = {}
|
|
@@ -37,32 +29,24 @@ function alias({
|
|
|
37
29
|
return Object.assign({}, defaultAlias, customAlias);
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
rules: []
|
|
43
|
-
}
|
|
44
|
-
}, {
|
|
45
|
-
module: customModule = {
|
|
46
|
-
rules: []
|
|
47
|
-
}
|
|
48
|
-
}) {
|
|
49
|
-
return Object.assign({}, defaultModule, customModule, {
|
|
50
|
-
rules: rules(defaultModule, customModule)
|
|
32
|
+
function mergeModuleField(a, b) {
|
|
33
|
+
return Object.assign({}, a, b, {
|
|
34
|
+
rules: mergeRulesField(a.rules || [], b.rules || [])
|
|
51
35
|
});
|
|
52
36
|
}
|
|
53
37
|
|
|
54
|
-
function
|
|
38
|
+
function mergeResolveField({
|
|
55
39
|
resolve: defaultResolve = {}
|
|
56
40
|
}, {
|
|
57
41
|
resolve: customResolve = {}
|
|
58
42
|
}) {
|
|
59
43
|
return Object.assign({}, defaultResolve, customResolve, {
|
|
60
|
-
alias:
|
|
61
|
-
extensions:
|
|
44
|
+
alias: mergeAliasField(defaultResolve, customResolve),
|
|
45
|
+
extensions: mergeExtensionsField(defaultResolve, customResolve)
|
|
62
46
|
});
|
|
63
47
|
}
|
|
64
48
|
|
|
65
|
-
function
|
|
49
|
+
function mergeOptimizationField({
|
|
66
50
|
optimization: defaultOptimization = {}
|
|
67
51
|
}, {
|
|
68
52
|
optimization: customOptimization = {}
|
|
@@ -73,9 +57,9 @@ function optimization({
|
|
|
73
57
|
function mergeConfigs(config, customConfig) {
|
|
74
58
|
return Object.assign({}, customConfig, config, {
|
|
75
59
|
devtool: customConfig.devtool || config.devtool,
|
|
76
|
-
plugins:
|
|
77
|
-
module:
|
|
78
|
-
resolve:
|
|
79
|
-
optimization:
|
|
60
|
+
plugins: mergePluginsField(config.plugins, customConfig.plugins),
|
|
61
|
+
module: mergeModuleField(config.module || {}, customConfig.module || {}),
|
|
62
|
+
resolve: mergeResolveField(config, customConfig),
|
|
63
|
+
optimization: mergeOptimizationField(config, customConfig)
|
|
80
64
|
});
|
|
81
65
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@storybook/node-logger';
|
|
2
|
-
import dedent from 'ts-dedent';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
3
|
export const checkWebpackVersion = (webpack, specifier, caption) => {
|
|
4
4
|
if (!webpack.version) {
|
|
5
5
|
logger.info('Skipping webpack version check, no version available');
|
|
@@ -0,0 +1,17 @@
|
|
|
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
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './load-custom-webpack-config';
|
|
3
3
|
export * from './check-webpack-version';
|
|
4
|
-
export * from './merge-webpack-config';
|
|
4
|
+
export * from './merge-webpack-config';
|
|
5
|
+
export * from './to-importFn';
|
|
6
|
+
export * from './to-require-context';
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
function
|
|
2
|
-
plugins: defaultPlugins = []
|
|
3
|
-
}, {
|
|
4
|
-
plugins: customPlugins = []
|
|
5
|
-
}) {
|
|
1
|
+
function mergePluginsField(defaultPlugins = [], customPlugins = []) {
|
|
6
2
|
return [...defaultPlugins, ...customPlugins];
|
|
7
3
|
}
|
|
8
4
|
|
|
9
|
-
function
|
|
10
|
-
rules: defaultRules = []
|
|
11
|
-
}, {
|
|
12
|
-
rules: customRules = []
|
|
13
|
-
}) {
|
|
5
|
+
function mergeRulesField(defaultRules = [], customRules = []) {
|
|
14
6
|
return [...defaultRules, ...customRules];
|
|
15
7
|
}
|
|
16
8
|
|
|
17
|
-
function
|
|
9
|
+
function mergeExtensionsField({
|
|
18
10
|
extensions: defaultExtensions = []
|
|
19
11
|
}, {
|
|
20
12
|
extensions: customExtensions = []
|
|
@@ -22,7 +14,7 @@ function extensions({
|
|
|
22
14
|
return [...defaultExtensions, ...customExtensions];
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
function
|
|
17
|
+
function mergeAliasField({
|
|
26
18
|
alias: defaultAlias = {}
|
|
27
19
|
}, {
|
|
28
20
|
alias: customAlias = {}
|
|
@@ -30,32 +22,24 @@ function alias({
|
|
|
30
22
|
return Object.assign({}, defaultAlias, customAlias);
|
|
31
23
|
}
|
|
32
24
|
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
rules: []
|
|
36
|
-
}
|
|
37
|
-
}, {
|
|
38
|
-
module: customModule = {
|
|
39
|
-
rules: []
|
|
40
|
-
}
|
|
41
|
-
}) {
|
|
42
|
-
return Object.assign({}, defaultModule, customModule, {
|
|
43
|
-
rules: rules(defaultModule, customModule)
|
|
25
|
+
function mergeModuleField(a, b) {
|
|
26
|
+
return Object.assign({}, a, b, {
|
|
27
|
+
rules: mergeRulesField(a.rules || [], b.rules || [])
|
|
44
28
|
});
|
|
45
29
|
}
|
|
46
30
|
|
|
47
|
-
function
|
|
31
|
+
function mergeResolveField({
|
|
48
32
|
resolve: defaultResolve = {}
|
|
49
33
|
}, {
|
|
50
34
|
resolve: customResolve = {}
|
|
51
35
|
}) {
|
|
52
36
|
return Object.assign({}, defaultResolve, customResolve, {
|
|
53
|
-
alias:
|
|
54
|
-
extensions:
|
|
37
|
+
alias: mergeAliasField(defaultResolve, customResolve),
|
|
38
|
+
extensions: mergeExtensionsField(defaultResolve, customResolve)
|
|
55
39
|
});
|
|
56
40
|
}
|
|
57
41
|
|
|
58
|
-
function
|
|
42
|
+
function mergeOptimizationField({
|
|
59
43
|
optimization: defaultOptimization = {}
|
|
60
44
|
}, {
|
|
61
45
|
optimization: customOptimization = {}
|
|
@@ -66,9 +50,9 @@ function optimization({
|
|
|
66
50
|
export function mergeConfigs(config, customConfig) {
|
|
67
51
|
return Object.assign({}, customConfig, config, {
|
|
68
52
|
devtool: customConfig.devtool || config.devtool,
|
|
69
|
-
plugins:
|
|
70
|
-
module:
|
|
71
|
-
resolve:
|
|
72
|
-
optimization:
|
|
53
|
+
plugins: mergePluginsField(config.plugins, customConfig.plugins),
|
|
54
|
+
module: mergeModuleField(config.module || {}, customConfig.module || {}),
|
|
55
|
+
resolve: mergeResolveField(config, customConfig),
|
|
56
|
+
optimization: mergeOptimizationField(config, customConfig)
|
|
73
57
|
});
|
|
74
58
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WebpackConfiguration as Configuration } from './types';
|
|
2
2
|
export declare function mergeConfigs(config: Configuration, customConfig: Configuration): Configuration;
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import type { Options, StorybookConfig as
|
|
1
|
+
import type { Options, StorybookConfig as StorybookConfigBase } from '@storybook/core-common';
|
|
2
2
|
export type { Options, Preset, BuilderResult, TypescriptOptions } from '@storybook/core-common';
|
|
3
|
-
export
|
|
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 {
|
|
4
13
|
plugins?: any[];
|
|
5
|
-
module?:
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
resolve?: {
|
|
9
|
-
extensions?: string[];
|
|
10
|
-
mainFields?: string[] | string[][];
|
|
11
|
-
alias?: any;
|
|
12
|
-
};
|
|
14
|
+
module?: ModuleConfig;
|
|
15
|
+
resolve?: ResolveConfig;
|
|
13
16
|
optimization?: any;
|
|
14
|
-
devtool?:
|
|
17
|
+
devtool?: false | string;
|
|
15
18
|
}
|
|
16
|
-
export
|
|
19
|
+
export declare type StorybookConfig<TWebpackConfiguration = WebpackConfiguration> = StorybookConfigBase & {
|
|
17
20
|
/**
|
|
18
21
|
* Modify or return a custom Webpack config after the Storybook's default configuration
|
|
19
22
|
* has run (mostly used by addons).
|
|
20
23
|
*/
|
|
21
|
-
webpack?: (config:
|
|
24
|
+
webpack?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
|
|
22
25
|
/**
|
|
23
26
|
* Modify or return a custom Webpack config after every addon has run.
|
|
24
27
|
*/
|
|
25
|
-
webpackFinal?: (config:
|
|
26
|
-
}
|
|
27
|
-
export declare type StorybookConfig<TWebpackConfiguration extends CommonWebpackConfiguration = CommonWebpackConfiguration> = BaseStorybookConfig & StorybookWebpackConfig<TWebpackConfiguration>;
|
|
28
|
+
webpackFinal?: (config: TWebpackConfiguration, options: Options) => TWebpackConfiguration | Promise<TWebpackConfiguration>;
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/core-webpack",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.20",
|
|
4
4
|
"description": "Storybook framework-agnostic API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -30,17 +30,21 @@
|
|
|
30
30
|
"*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"
|
|
33
|
+
"check": "tsc --noEmit",
|
|
34
|
+
"prepare": "node ../../../scripts/prepare.js"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@storybook/core-common": "7.0.0-alpha.
|
|
37
|
-
"@storybook/node-logger": "7.0.0-alpha.
|
|
37
|
+
"@storybook/core-common": "7.0.0-alpha.20",
|
|
38
|
+
"@storybook/node-logger": "7.0.0-alpha.20",
|
|
38
39
|
"@types/node": "^14.0.10 || ^16.0.0",
|
|
39
40
|
"core-js": "^3.8.2",
|
|
40
41
|
"ts-dedent": "^2.0.0"
|
|
41
42
|
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "~4.6.3"
|
|
45
|
+
},
|
|
42
46
|
"publishConfig": {
|
|
43
47
|
"access": "public"
|
|
44
48
|
},
|
|
45
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a6c00d2ebed21da54b4772b4a4f7fed9258f0ab4"
|
|
46
50
|
}
|
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.
|