@storybook/core-common 6.4.0-beta.2 → 6.4.0-beta.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/index.js +26 -0
- package/dist/cjs/presets.js +41 -9
- package/dist/cjs/utils/check-addon-order.js +54 -0
- package/dist/cjs/utils/findDistEsm.js +22 -0
- package/dist/cjs/utils/glob-to-regexp.js +32 -0
- package/dist/cjs/utils/normalize-stories.js +82 -65
- package/dist/cjs/utils/progress-reporting.js +1 -0
- package/dist/cjs/utils/to-importFn.js +11 -14
- package/dist/cjs/utils/to-require-context.js +16 -78
- package/dist/esm/index.js +2 -0
- package/dist/esm/presets.js +41 -10
- package/dist/esm/utils/check-addon-order.js +45 -0
- package/dist/esm/utils/findDistEsm.js +8 -0
- package/dist/esm/utils/glob-to-regexp.js +24 -0
- package/dist/esm/utils/normalize-stories.js +77 -62
- package/dist/esm/utils/progress-reporting.js +1 -0
- package/dist/esm/utils/to-importFn.js +11 -13
- package/dist/esm/utils/to-require-context.js +15 -72
- package/dist/modern/index.js +2 -0
- package/dist/modern/presets.js +41 -10
- package/dist/modern/utils/check-addon-order.js +45 -0
- package/dist/modern/utils/findDistEsm.js +8 -0
- package/dist/modern/utils/glob-to-regexp.js +24 -0
- package/dist/modern/utils/normalize-stories.js +77 -62
- package/dist/modern/utils/progress-reporting.js +1 -0
- package/dist/modern/utils/to-importFn.js +11 -13
- package/dist/modern/utils/to-require-context.js +15 -72
- package/dist/ts3.4/index.d.ts +2 -0
- package/dist/ts3.4/types.d.ts +43 -9
- package/dist/ts3.4/utils/check-addon-order.d.ts +16 -0
- package/dist/ts3.4/utils/findDistEsm.d.ts +1 -0
- package/dist/ts3.4/utils/glob-to-regexp.d.ts +1 -0
- package/dist/ts3.4/utils/normalize-stories.d.ts +1 -7
- package/dist/ts3.4/utils/to-importFn.d.ts +1 -1
- package/dist/ts3.4/utils/to-require-context.d.ts +7 -2
- package/dist/ts3.9/index.d.ts +2 -0
- package/dist/ts3.9/types.d.ts +43 -9
- package/dist/ts3.9/utils/check-addon-order.d.ts +16 -0
- package/dist/ts3.9/utils/findDistEsm.d.ts +1 -0
- package/dist/ts3.9/utils/glob-to-regexp.d.ts +1 -0
- package/dist/ts3.9/utils/normalize-stories.d.ts +1 -7
- package/dist/ts3.9/utils/to-importFn.d.ts +1 -1
- package/dist/ts3.9/utils/to-require-context.d.ts +7 -2
- package/package.json +6 -3
- package/typings.d.ts +9 -0
package/dist/cjs/index.js
CHANGED
|
@@ -43,6 +43,19 @@ Object.keys(_checkWebpackVersion).forEach(function (key) {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
var _checkAddonOrder = require("./utils/check-addon-order");
|
|
47
|
+
|
|
48
|
+
Object.keys(_checkAddonOrder).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _checkAddonOrder[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _checkAddonOrder[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
46
59
|
var _envs = require("./utils/envs");
|
|
47
60
|
|
|
48
61
|
Object.keys(_envs).forEach(function (key) {
|
|
@@ -342,6 +355,19 @@ Object.keys(_readTemplate).forEach(function (key) {
|
|
|
342
355
|
});
|
|
343
356
|
});
|
|
344
357
|
|
|
358
|
+
var _findDistEsm = require("./utils/findDistEsm");
|
|
359
|
+
|
|
360
|
+
Object.keys(_findDistEsm).forEach(function (key) {
|
|
361
|
+
if (key === "default" || key === "__esModule") return;
|
|
362
|
+
if (key in exports && exports[key] === _findDistEsm[key]) return;
|
|
363
|
+
Object.defineProperty(exports, key, {
|
|
364
|
+
enumerable: true,
|
|
365
|
+
get: function () {
|
|
366
|
+
return _findDistEsm[key];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
345
371
|
var _types = require("./types");
|
|
346
372
|
|
|
347
373
|
Object.keys(_types).forEach(function (key) {
|
package/dist/cjs/presets.js
CHANGED
|
@@ -21,6 +21,8 @@ var _resolveFrom = _interopRequireDefault(require("resolve-from"));
|
|
|
21
21
|
|
|
22
22
|
var _loadCustomPresets = require("./utils/load-custom-presets");
|
|
23
23
|
|
|
24
|
+
var _interpretRequire = require("./utils/interpret-require");
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
@@ -48,13 +50,15 @@ function filterPresetsConfig(presetsConfig) {
|
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
function resolvePresetFunction(input, presetOptions, storybookOptions) {
|
|
53
|
+
function resolvePresetFunction(input, presetOptions, framework, storybookOptions) {
|
|
54
|
+
var prepend = [framework].filter(Boolean);
|
|
55
|
+
|
|
52
56
|
if (isFunction(input)) {
|
|
53
|
-
return input(_objectSpread(_objectSpread({}, storybookOptions), presetOptions));
|
|
57
|
+
return [...prepend, ...input(_objectSpread(_objectSpread({}, storybookOptions), presetOptions))];
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
if (Array.isArray(input)) {
|
|
57
|
-
return input;
|
|
61
|
+
return [...prepend, ...input];
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
return [];
|
|
@@ -197,11 +201,12 @@ function loadPreset(input, level, storybookOptions) {
|
|
|
197
201
|
var _contents = contents,
|
|
198
202
|
addonsInput = _contents.addons,
|
|
199
203
|
presetsInput = _contents.presets,
|
|
200
|
-
|
|
204
|
+
framework = _contents.framework,
|
|
205
|
+
rest = _objectWithoutProperties(_contents, ["addons", "presets", "framework"]);
|
|
201
206
|
|
|
202
|
-
var _subPresets = resolvePresetFunction(presetsInput, presetOptions, storybookOptions);
|
|
207
|
+
var _subPresets = resolvePresetFunction(presetsInput, presetOptions, framework, storybookOptions);
|
|
203
208
|
|
|
204
|
-
var subAddons = resolvePresetFunction(addonsInput, presetOptions, storybookOptions);
|
|
209
|
+
var subAddons = resolvePresetFunction(addonsInput, presetOptions, framework, storybookOptions);
|
|
205
210
|
return [...loadPresets([..._subPresets], level + 1, storybookOptions), ...loadPresets([...subAddons.map(map(storybookOptions))].filter(Boolean), level + 1, storybookOptions), {
|
|
206
211
|
name: name,
|
|
207
212
|
preset: rest,
|
|
@@ -239,8 +244,8 @@ function loadPresets(presets, level, storybookOptions) {
|
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
function applyPresets(presets, extension, config, args, storybookOptions) {
|
|
242
|
-
var presetResult = new Promise(function (
|
|
243
|
-
return
|
|
247
|
+
var presetResult = new Promise(function (res) {
|
|
248
|
+
return res(config);
|
|
244
249
|
});
|
|
245
250
|
|
|
246
251
|
if (!presets.length) {
|
|
@@ -297,6 +302,32 @@ function getPresets(presets, storybookOptions) {
|
|
|
297
302
|
}
|
|
298
303
|
};
|
|
299
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Get the `framework` provided in main.js and also do error checking up front
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
var getFrameworkPackage = function (configDir) {
|
|
311
|
+
var main = (0, _interpretRequire.serverRequire)((0, _path.resolve)(configDir, 'main'));
|
|
312
|
+
if (!main) return null;
|
|
313
|
+
var frameworkPackage = main.framework,
|
|
314
|
+
_main$features = main.features,
|
|
315
|
+
features = _main$features === void 0 ? {} : _main$features;
|
|
316
|
+
|
|
317
|
+
if (features.breakingChangesV7 && !frameworkPackage) {
|
|
318
|
+
throw new Error((0, _tsDedent.default)`
|
|
319
|
+
Expected 'framework' in your main.js, didn't find one.
|
|
320
|
+
|
|
321
|
+
You can fix this automatically by running:
|
|
322
|
+
|
|
323
|
+
npx sb@next automigrate
|
|
324
|
+
|
|
325
|
+
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mainjs-framework-field
|
|
326
|
+
`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return frameworkPackage;
|
|
330
|
+
};
|
|
300
331
|
|
|
301
332
|
function loadAllPresets(options) {
|
|
302
333
|
var _options$corePresets = options.corePresets,
|
|
@@ -307,7 +338,8 @@ function loadAllPresets(options) {
|
|
|
307
338
|
overridePresets = _options$overridePres === void 0 ? [] : _options$overridePres,
|
|
308
339
|
restOptions = _objectWithoutProperties(options, ["corePresets", "frameworkPresets", "overridePresets"]);
|
|
309
340
|
|
|
310
|
-
var
|
|
341
|
+
var frameworkPackage = getFrameworkPackage(options.configDir);
|
|
342
|
+
var presetsConfig = [...corePresets, ...(frameworkPackage ? [] : frameworkPresets), ...(0, _loadCustomPresets.loadCustomPresets)(options), ...overridePresets]; // Remove `@storybook/preset-typescript` and add a warning if in use.
|
|
311
343
|
|
|
312
344
|
var filteredPresetConfig = filterPresetsConfig(presetsConfig);
|
|
313
345
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkAddonOrder = void 0;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.promise.js");
|
|
9
|
+
|
|
10
|
+
var _require = require('@storybook/node-logger'),
|
|
11
|
+
logger = _require.logger;
|
|
12
|
+
|
|
13
|
+
var predicateFor = function (addon) {
|
|
14
|
+
return function (entry) {
|
|
15
|
+
var name = entry.name || entry;
|
|
16
|
+
return name && name.includes(addon);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var isCorrectOrder = function (addons, before, after) {
|
|
21
|
+
var essentialsIndex = addons.findIndex(predicateFor('@storybook/addon-essentials'));
|
|
22
|
+
var beforeIndex = addons.findIndex(predicateFor(before.name));
|
|
23
|
+
var afterIndex = addons.findIndex(predicateFor(after.name));
|
|
24
|
+
if (beforeIndex === -1 && before.inEssentials) beforeIndex = essentialsIndex;
|
|
25
|
+
if (afterIndex === -1 && after.inEssentials) afterIndex = essentialsIndex;
|
|
26
|
+
return beforeIndex !== -1 && afterIndex !== -1 && beforeIndex <= afterIndex;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var checkAddonOrder = async function ({
|
|
30
|
+
before: before,
|
|
31
|
+
after: after,
|
|
32
|
+
configFile: configFile,
|
|
33
|
+
getConfig: getConfig
|
|
34
|
+
}) {
|
|
35
|
+
try {
|
|
36
|
+
var config = await getConfig(configFile);
|
|
37
|
+
|
|
38
|
+
if (!(config !== null && config !== void 0 && config.addons)) {
|
|
39
|
+
logger.warn(`Unable to find 'addons' config in main Storybook config`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!isCorrectOrder(config.addons, before, after)) {
|
|
44
|
+
var orEssentials = " (or '@storybook/addon-essentials')";
|
|
45
|
+
var beforeText = `'${before.name}'${before.inEssentials ? orEssentials : ''}`;
|
|
46
|
+
var afterText = `'${after.name}'${after.inEssentials ? orEssentials : ''}`;
|
|
47
|
+
logger.warn(`Expected ${beforeText} to be listed before ${afterText} in main Storybook config.`);
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
logger.warn(`Unable to load config file: ${configFile}`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.checkAddonOrder = checkAddonOrder;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findDistEsm = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _findUp = require("find-up");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
var findDistEsm = function (cwd, relativePath) {
|
|
15
|
+
var packageDir = _path.default.dirname((0, _findUp.sync)('package.json', {
|
|
16
|
+
cwd: cwd
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
return _path.default.join(packageDir, 'dist', 'esm', relativePath);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.findDistEsm = findDistEsm;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.globToRegex = globToRegex;
|
|
7
|
+
|
|
8
|
+
var _micromatch = require("micromatch");
|
|
9
|
+
|
|
10
|
+
function globToRegex(glob) {
|
|
11
|
+
var regex = (0, _micromatch.makeRe)(glob, {
|
|
12
|
+
fastpaths: false,
|
|
13
|
+
noglobstar: false,
|
|
14
|
+
bash: false
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (!regex.source.startsWith('^')) {
|
|
18
|
+
throw new Error(`Invalid glob: >> ${glob} >> ${regex}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!glob.startsWith('./')) {
|
|
22
|
+
return regex;
|
|
23
|
+
} // makeRe is sort of funny. If you pass it a directory starting with `./` it
|
|
24
|
+
// creates a matcher that expects files with no prefix (e.g. `src/file.js`)
|
|
25
|
+
// but if you pass it a directory that starts with `../` it expects files that
|
|
26
|
+
// start with `../`. Let's make it consistent.
|
|
27
|
+
// Globs starting `**` require special treatment due to the regex they
|
|
28
|
+
// produce, specifically a negative look-ahead
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return new RegExp(['^\\.', glob.startsWith('./**') ? '' : '[\\\\/]', regex.source.substring(1)].join(''));
|
|
32
|
+
}
|
|
@@ -3,12 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normalizeStories = exports.
|
|
6
|
+
exports.normalizeStories = exports.normalizeStoriesEntry = void 0;
|
|
7
7
|
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
|
|
12
|
+
var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
|
|
13
|
+
|
|
14
|
+
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
|
15
|
+
|
|
16
|
+
var _micromatch = require("micromatch");
|
|
17
|
+
|
|
18
|
+
var _slash = _interopRequireDefault(require("slash"));
|
|
19
|
+
|
|
20
|
+
var _globToRegexp = require("./glob-to-regexp");
|
|
21
|
+
|
|
12
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
23
|
|
|
14
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -17,11 +27,24 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
17
27
|
|
|
18
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
29
|
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
|
|
30
|
+
var DEFAULT_TITLE_PREFIX = '';
|
|
31
|
+
var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
|
|
32
|
+
|
|
33
|
+
var fixBadGlob = (0, _utilDeprecate.default)(function (match) {
|
|
34
|
+
return match.input.replace(match[1], `@${match[1]}`);
|
|
35
|
+
}, (0, _tsDedent.default)`
|
|
36
|
+
You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
|
|
37
|
+
`);
|
|
23
38
|
|
|
24
|
-
var
|
|
39
|
+
var detectBadGlob = function (val) {
|
|
40
|
+
var match = val.match(/\.(\([^)]+\))/);
|
|
41
|
+
|
|
42
|
+
if (match) {
|
|
43
|
+
return fixBadGlob(match);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return val;
|
|
47
|
+
};
|
|
25
48
|
|
|
26
49
|
var isDirectory = function (configDir, entry) {
|
|
27
50
|
try {
|
|
@@ -31,87 +54,81 @@ var isDirectory = function (configDir, entry) {
|
|
|
31
54
|
}
|
|
32
55
|
};
|
|
33
56
|
|
|
34
|
-
var normalizeStoriesEntry = function (entry,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
57
|
+
var normalizeStoriesEntry = function (entry, {
|
|
58
|
+
configDir: configDir,
|
|
59
|
+
workingDir: workingDir
|
|
60
|
+
}) {
|
|
61
|
+
var specifierWithoutMatcher;
|
|
39
62
|
|
|
40
63
|
if (typeof entry === 'string') {
|
|
41
|
-
if (!entry.includes('
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (match) {
|
|
49
|
-
directory = match.groups.directory;
|
|
50
|
-
files = match.groups.files;
|
|
51
|
-
titlePrefix = DEFAULT_TITLE_PREFIX;
|
|
64
|
+
if (!entry.includes('*')) {
|
|
65
|
+
if (isDirectory(configDir, entry)) {
|
|
66
|
+
specifierWithoutMatcher = {
|
|
67
|
+
titlePrefix: DEFAULT_TITLE_PREFIX,
|
|
68
|
+
directory: entry,
|
|
69
|
+
files: DEFAULT_FILES
|
|
70
|
+
};
|
|
52
71
|
} else {
|
|
53
|
-
|
|
72
|
+
specifierWithoutMatcher = {
|
|
73
|
+
titlePrefix: DEFAULT_TITLE_PREFIX,
|
|
74
|
+
directory: _path.default.dirname(entry),
|
|
75
|
+
files: _path.default.basename(entry)
|
|
76
|
+
};
|
|
54
77
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
files = entry.files || DEFAULT_FILES;
|
|
59
|
-
titlePrefix = entry.titlePrefix || DEFAULT_TITLE_PREFIX;
|
|
60
|
-
}
|
|
78
|
+
} else {
|
|
79
|
+
var fixedEntry = detectBadGlob(entry);
|
|
80
|
+
var globResult = (0, _micromatch.scan)(fixedEntry);
|
|
61
81
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
specifier: undefined
|
|
66
|
-
};
|
|
67
|
-
}
|
|
82
|
+
var _directory = globResult.isGlob ? globResult.prefix + globResult.base : _path.default.dirname(fixedEntry);
|
|
83
|
+
|
|
84
|
+
var filesFallback = _directory !== '.' ? fixedEntry.substr(_directory.length + 1) : fixedEntry;
|
|
68
85
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
var _files = globResult.isGlob ? globResult.glob : filesFallback;
|
|
87
|
+
|
|
88
|
+
specifierWithoutMatcher = {
|
|
89
|
+
titlePrefix: DEFAULT_TITLE_PREFIX,
|
|
90
|
+
directory: _directory,
|
|
91
|
+
files: _files
|
|
92
|
+
};
|
|
75
93
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
94
|
+
} else {
|
|
95
|
+
specifierWithoutMatcher = _objectSpread({
|
|
96
|
+
titlePrefix: DEFAULT_TITLE_PREFIX,
|
|
97
|
+
files: DEFAULT_FILES
|
|
98
|
+
}, entry);
|
|
99
|
+
} // We are going to be doing everything with node importPaths which use
|
|
100
|
+
// URL format, i.e. `/` as a separator, so let's make sure we've normalized
|
|
78
101
|
|
|
79
|
-
exports.normalizeStoriesEntry = normalizeStoriesEntry;
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* current working directory. This function rewrites the specifier.directory relative to the current working
|
|
84
|
-
* directory.
|
|
85
|
-
*/
|
|
86
|
-
var normalizeDirectory = function (entry, {
|
|
87
|
-
configDir: configDir,
|
|
88
|
-
workingDir: workingDir
|
|
89
|
-
}) {
|
|
90
|
-
if (!entry.specifier) return entry;
|
|
91
|
-
var directory = entry.specifier.directory;
|
|
103
|
+
var files = (0, _slash.default)(specifierWithoutMatcher.files); // At this stage `directory` is relative to `main.js` (the config dir)
|
|
104
|
+
// We want to work relative to the working dir, so we transform it here.
|
|
92
105
|
|
|
93
|
-
var
|
|
106
|
+
var _specifierWithoutMatc = specifierWithoutMatcher,
|
|
107
|
+
directoryRelativeToConfig = _specifierWithoutMatc.directory;
|
|
94
108
|
|
|
95
|
-
var
|
|
96
|
-
// but we want `./src`to match webpack's file names
|
|
109
|
+
var absoluteDirectory = _path.default.resolve(configDir, directoryRelativeToConfig);
|
|
97
110
|
|
|
111
|
+
var directory = (0, _slash.default)(_path.default.relative(workingDir, absoluteDirectory)); // relative('/foo', '/foo/src') => 'src'
|
|
112
|
+
// but we want `./src` to match importPaths
|
|
98
113
|
|
|
99
|
-
if (!
|
|
100
|
-
|
|
114
|
+
if (!directory.startsWith('.')) {
|
|
115
|
+
directory = `./${directory}`;
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
|
|
119
|
+
|
|
120
|
+
var importPathMatcher = (0, _globToRegexp.globToRegex)(`${directory}/${files}`);
|
|
121
|
+
return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
|
|
122
|
+
directory: directory,
|
|
123
|
+
importPathMatcher: importPathMatcher
|
|
107
124
|
});
|
|
108
125
|
};
|
|
109
126
|
|
|
110
|
-
exports.
|
|
127
|
+
exports.normalizeStoriesEntry = normalizeStoriesEntry;
|
|
111
128
|
|
|
112
129
|
var normalizeStories = function (entries, options) {
|
|
113
130
|
return entries.map(function (entry) {
|
|
114
|
-
return
|
|
131
|
+
return normalizeStoriesEntry(entry, options);
|
|
115
132
|
});
|
|
116
133
|
};
|
|
117
134
|
|
|
@@ -35,6 +35,7 @@ var useProgressReporting = async function (router, startTime, options) {
|
|
|
35
35
|
reportProgress = function (progress) {
|
|
36
36
|
if (closed || response.writableEnded) return;
|
|
37
37
|
response.write(`data: ${JSON.stringify(progress)}\n\n`);
|
|
38
|
+
response.flush();
|
|
38
39
|
if (progress.value === 1) close();
|
|
39
40
|
};
|
|
40
41
|
});
|
|
@@ -8,30 +8,27 @@ exports.toImportFn = toImportFn;
|
|
|
8
8
|
|
|
9
9
|
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
|
10
10
|
|
|
11
|
-
var _ = require("..");
|
|
12
|
-
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
12
|
|
|
15
|
-
function toImportFnPart(
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
function toImportFnPart(specifier) {
|
|
14
|
+
var directory = specifier.directory,
|
|
15
|
+
importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
|
|
16
|
+
// on disk (prefixed with something unknown) to the matcher.
|
|
17
|
+
// We don't want to include the absolute path in our bundle, so we will just pull the
|
|
18
|
+
// '^' and any leading '.' off the regexp and match on that.
|
|
19
|
+
// It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
|
|
19
20
|
|
|
20
|
-
var webpackIncludeRegex = new RegExp(
|
|
21
|
+
var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
|
|
21
22
|
return (0, _tsDedent.default)`
|
|
22
23
|
async (path) => {
|
|
23
|
-
|
|
24
|
-
if (pathBase !== '${base}/') {
|
|
24
|
+
if (!${importPathMatcher}.exec(path)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const pathRemainder = path.substring(${
|
|
29
|
-
if (!${regex}.exec(pathRemainder)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
28
|
+
const pathRemainder = path.substring(${directory.length + 1});
|
|
32
29
|
return import(
|
|
33
30
|
/* webpackInclude: ${webpackIncludeRegex} */
|
|
34
|
-
'${
|
|
31
|
+
'${directory}/' + pathRemainder
|
|
35
32
|
);
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -5,92 +5,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.toRequireContextString = exports.toRequireContext = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, (0, _tsDedent.default)`
|
|
22
|
-
You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
|
|
23
|
-
`);
|
|
24
|
-
|
|
25
|
-
var detectBadGlob = function (val) {
|
|
26
|
-
var match = val.match(/\.(\([^)]+\))/);
|
|
27
|
-
|
|
28
|
-
if (match) {
|
|
29
|
-
return fixBadGlob(match);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return val;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var isObject = function (val) {
|
|
36
|
-
return val != null && typeof val === 'object' && Array.isArray(val) === false;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var toRequireContext = function (input) {
|
|
40
|
-
var fixedInput = detectBadGlob(input);
|
|
41
|
-
|
|
42
|
-
switch (true) {
|
|
43
|
-
case typeof input === 'string':
|
|
44
|
-
{
|
|
45
|
-
var globResult = (0, _micromatch.scan)(fixedInput);
|
|
46
|
-
var base = globResult.isGlob ? globResult.prefix + globResult.base : _path.default.dirname(fixedInput);
|
|
47
|
-
var globFallback = base !== '.' ? fixedInput.substr(base.length + 1) : fixedInput;
|
|
48
|
-
var glob = globResult.isGlob ? globResult.glob : globFallback;
|
|
49
|
-
var regex = (0, _micromatch.makeRe)(glob, {
|
|
50
|
-
fastpaths: false,
|
|
51
|
-
noglobstar: false,
|
|
52
|
-
bash: false
|
|
53
|
-
});
|
|
54
|
-
var source = regex.source;
|
|
55
|
-
|
|
56
|
-
if (source.startsWith('^')) {
|
|
57
|
-
// webpack's require.context matches against paths starting `./`
|
|
58
|
-
// Globs starting `**` require special treatment due to the regex they
|
|
59
|
-
// produce, specifically a negative look-ahead
|
|
60
|
-
var match = ['^\\.', glob.startsWith('**') ? '' : '\\/', source.substring(1)].join('');
|
|
61
|
-
var recursive = glob.includes('**') || glob.split('/').length > 1;
|
|
62
|
-
return {
|
|
63
|
-
path: base,
|
|
64
|
-
recursive: recursive,
|
|
65
|
-
match: match,
|
|
66
|
-
regex: regex
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
throw new Error(`Invalid glob: >> ${input} >> ${regex}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
case isObject(input):
|
|
74
|
-
{
|
|
75
|
-
return input;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
default:
|
|
79
|
-
{
|
|
80
|
-
throw new Error('the provided input cannot be transformed into a require.context');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
8
|
+
var _globToRegexp = require("./glob-to-regexp");
|
|
9
|
+
|
|
10
|
+
var toRequireContext = function (specifier) {
|
|
11
|
+
var directory = specifier.directory,
|
|
12
|
+
files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
|
|
13
|
+
// For `require.context()` we want the same thing, relative to directory
|
|
14
|
+
|
|
15
|
+
var match = (0, _globToRegexp.globToRegex)(`./${files}`);
|
|
16
|
+
return {
|
|
17
|
+
path: directory,
|
|
18
|
+
recursive: !!files.match(/^\*{1,2}\//),
|
|
19
|
+
match: match
|
|
20
|
+
};
|
|
83
21
|
};
|
|
84
22
|
|
|
85
23
|
exports.toRequireContext = toRequireContext;
|
|
86
24
|
|
|
87
|
-
var toRequireContextString = function (
|
|
88
|
-
var _toRequireContext = toRequireContext(
|
|
25
|
+
var toRequireContextString = function (specifier) {
|
|
26
|
+
var _toRequireContext = toRequireContext(specifier),
|
|
89
27
|
p = _toRequireContext.path,
|
|
90
28
|
r = _toRequireContext.recursive,
|
|
91
29
|
m = _toRequireContext.match;
|
|
92
30
|
|
|
93
|
-
var result = `require.context('${p}', ${r},
|
|
31
|
+
var result = `require.context('${p}', ${r}, ${m})`;
|
|
94
32
|
return result;
|
|
95
33
|
};
|
|
96
34
|
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './presets';
|
|
2
2
|
export * from './utils/babel';
|
|
3
3
|
export * from './utils/check-webpack-version';
|
|
4
|
+
export * from './utils/check-addon-order';
|
|
4
5
|
export * from './utils/envs';
|
|
5
6
|
export * from './utils/es6Transpiler';
|
|
6
7
|
export * from './utils/handlebars';
|
|
@@ -24,4 +25,5 @@ export * from './utils/to-require-context';
|
|
|
24
25
|
export * from './utils/normalize-stories';
|
|
25
26
|
export * from './utils/to-importFn';
|
|
26
27
|
export * from './utils/readTemplate';
|
|
28
|
+
export * from './utils/findDistEsm';
|
|
27
29
|
export * from './types';
|