@storybook/core-server 7.0.0-alpha.10 → 7.0.0-alpha.13
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/build-dev.js +5 -7
- package/dist/cjs/build-static.js +52 -73
- package/dist/cjs/dev-server.js +2 -1
- package/dist/cjs/index.js +0 -14
- package/dist/cjs/presets/common-preset.js +7 -7
- package/dist/cjs/utils/StoryIndexGenerator.js +154 -67
- package/dist/cjs/utils/__mockdata__/duplicate/A.stories.js +14 -0
- package/dist/cjs/utils/__mockdata__/duplicate/SecondA.stories.js +14 -0
- package/dist/cjs/utils/__mockdata__/{src → errors}/NoMeta.stories.js +0 -0
- package/dist/cjs/utils/copy-all-static-files.js +1 -1
- package/dist/cjs/utils/get-builders.js +1 -1
- package/dist/cjs/utils/metadata.js +2 -4
- package/dist/cjs/utils/open-in-browser.js +2 -2
- package/dist/cjs/utils/output-startup-information.js +2 -2
- package/dist/cjs/utils/server-statics.js +3 -3
- package/dist/cjs/utils/stories-json.js +2 -2
- package/dist/cjs/utils/update-check.js +2 -2
- package/dist/esm/build-dev.js +5 -7
- package/dist/esm/build-static.js +51 -67
- package/dist/esm/dev-server.js +2 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/presets/common-preset.js +4 -4
- package/dist/esm/utils/StoryIndexGenerator.js +153 -65
- package/dist/esm/utils/__mockdata__/duplicate/A.stories.js +6 -0
- package/dist/esm/utils/__mockdata__/duplicate/SecondA.stories.js +6 -0
- package/dist/esm/utils/__mockdata__/{src → errors}/NoMeta.stories.js +0 -0
- package/dist/esm/utils/copy-all-static-files.js +1 -1
- package/dist/esm/utils/get-builders.js +1 -1
- package/dist/esm/utils/metadata.js +2 -2
- package/dist/esm/utils/open-in-browser.js +1 -1
- package/dist/esm/utils/output-startup-information.js +1 -1
- package/dist/esm/utils/server-statics.js +1 -1
- package/dist/esm/utils/stories-json.js +2 -2
- package/dist/esm/utils/update-check.js +1 -1
- package/dist/types/dev-server.d.ts +3 -3
- package/dist/types/index.d.ts +1 -2
- package/dist/types/presets/common-preset.d.ts +1 -1
- package/dist/types/utils/StoryIndexGenerator.d.ts +29 -7
- package/dist/types/utils/__mockdata__/{src → errors}/NoMeta.stories.d.ts +0 -0
- package/dist/types/utils/get-builders.d.ts +1 -1
- package/package.json +15 -16
package/dist/cjs/build-dev.js
CHANGED
|
@@ -106,7 +106,7 @@ async function buildDevStandalone(options) {
|
|
|
106
106
|
|
|
107
107
|
_nodeLogger.logger.info('=> Loading presets');
|
|
108
108
|
|
|
109
|
-
var presets = (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
109
|
+
var presets = await (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
110
110
|
corePresets: corePresets,
|
|
111
111
|
overridePresets: []
|
|
112
112
|
}, options));
|
|
@@ -118,7 +118,7 @@ async function buildDevStandalone(options) {
|
|
|
118
118
|
previewBuilder = _await$getBuilders2[0],
|
|
119
119
|
managerBuilder = _await$getBuilders2[1];
|
|
120
120
|
|
|
121
|
-
presets = (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
121
|
+
presets = await (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
122
122
|
corePresets: [require.resolve('./presets/common-preset'), ...managerBuilder.corePresets, ...previewBuilder.corePresets, ...corePresets, require.resolve('./presets/babel-cache-preset')],
|
|
123
123
|
overridePresets: previewBuilder.overridePresets
|
|
124
124
|
}, options));
|
|
@@ -143,14 +143,12 @@ async function buildDevStandalone(options) {
|
|
|
143
143
|
|
|
144
144
|
if (options.webpackStatsJson) {
|
|
145
145
|
var target = options.webpackStatsJson === true ? options.outputDir : options.webpackStatsJson;
|
|
146
|
-
await (0, _outputStats.outputStats)(target, previewStats
|
|
146
|
+
await (0, _outputStats.outputStats)(target, previewStats);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
if (options.smokeTest) {
|
|
150
|
-
var warnings = [];
|
|
151
|
-
|
|
152
|
-
warnings.push(...(managerStats && managerStats.toJson().warnings || [])); // @ts-ignore
|
|
153
|
-
|
|
150
|
+
var warnings = [];
|
|
151
|
+
warnings.push(...(managerStats && managerStats.toJson().warnings || []));
|
|
154
152
|
warnings.push(...(managerStats && previewStats.toJson().warnings || []));
|
|
155
153
|
var problems = warnings.filter(function (warning) {
|
|
156
154
|
return !warning.message.includes(`export 'useInsertionEffect'`);
|
package/dist/cjs/build-static.js
CHANGED
|
@@ -11,11 +11,11 @@ require("core-js/modules/es.promise.js");
|
|
|
11
11
|
|
|
12
12
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
13
13
|
|
|
14
|
-
var _fsExtra =
|
|
14
|
+
var _fsExtra = require("fs-extra");
|
|
15
15
|
|
|
16
|
-
var _path =
|
|
16
|
+
var _path = require("path");
|
|
17
17
|
|
|
18
|
-
var _tsDedent =
|
|
18
|
+
var _tsDedent = require("ts-dedent");
|
|
19
19
|
|
|
20
20
|
var _global = _interopRequireDefault(require("global"));
|
|
21
21
|
|
|
@@ -57,10 +57,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
57
57
|
|
|
58
58
|
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; }
|
|
59
59
|
|
|
60
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
61
|
-
|
|
62
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
63
|
-
|
|
64
60
|
async function buildStaticStandalone(options) {
|
|
65
61
|
var _options$staticDir;
|
|
66
62
|
|
|
@@ -75,25 +71,18 @@ async function buildStaticStandalone(options) {
|
|
|
75
71
|
throw new Error("Won't copy root directory. Check your staticDirs!");
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
options.outputDir = _path.
|
|
79
|
-
options.configDir = _path.
|
|
74
|
+
options.outputDir = (0, _path.isAbsolute)(options.outputDir) ? options.outputDir : (0, _path.join)(process.cwd(), options.outputDir);
|
|
75
|
+
options.configDir = (0, _path.resolve)(options.configDir);
|
|
80
76
|
/* eslint-enable no-param-reassign */
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
_nodeLogger.logger.info((0, _chalk.default)`=> Cleaning outputDir: {cyan ${options.outputDir}}`);
|
|
78
|
+
_nodeLogger.logger.info((0, _chalk.default)`=> Cleaning outputDir: {cyan ${options.outputDir.replace(process.cwd(), '')}}`);
|
|
85
79
|
|
|
86
80
|
if (options.outputDir === '/') {
|
|
87
81
|
throw new Error("Won't remove directory '/'. Check your outputDir!");
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
await _fsExtra.
|
|
91
|
-
await
|
|
92
|
-
|
|
93
|
-
var _await$import = await Promise.resolve().then(function () {
|
|
94
|
-
return _interopRequireWildcard(require('@storybook/manager-webpack5/prebuilt-manager'));
|
|
95
|
-
}),
|
|
96
|
-
getPrebuiltDir = _await$import.getPrebuiltDir;
|
|
84
|
+
await (0, _fsExtra.emptyDir)(options.outputDir);
|
|
85
|
+
await (0, _fsExtra.ensureDir)(options.outputDir);
|
|
97
86
|
|
|
98
87
|
var _loadMainConfig = (0, _coreCommon.loadMainConfig)(options),
|
|
99
88
|
framework = _loadMainConfig.framework;
|
|
@@ -109,7 +98,7 @@ async function buildStaticStandalone(options) {
|
|
|
109
98
|
|
|
110
99
|
_nodeLogger.logger.info('=> Loading presets');
|
|
111
100
|
|
|
112
|
-
var presets = (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
101
|
+
var presets = await (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
113
102
|
corePresets: [require.resolve('./presets/common-preset'), ...corePresets],
|
|
114
103
|
overridePresets: []
|
|
115
104
|
}, options));
|
|
@@ -121,14 +110,27 @@ async function buildStaticStandalone(options) {
|
|
|
121
110
|
previewBuilder = _await$getBuilders2[0],
|
|
122
111
|
managerBuilder = _await$getBuilders2[1];
|
|
123
112
|
|
|
124
|
-
presets = (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
113
|
+
presets = await (0, _coreCommon.loadAllPresets)(_objectSpread({
|
|
125
114
|
corePresets: [require.resolve('./presets/common-preset'), ...(managerBuilder.corePresets || []), ...(previewBuilder.corePresets || []), ...corePresets, require.resolve('./presets/babel-cache-preset')],
|
|
126
115
|
overridePresets: previewBuilder.overridePresets || []
|
|
127
116
|
}, options));
|
|
128
|
-
|
|
117
|
+
|
|
118
|
+
var _await$Promise$all = await Promise.all([presets.apply('features'), presets.apply('core'), presets.apply('staticDirs'), presets.apply('storyIndexers', []), presets.apply('stories'), presets.apply('docs', {})]),
|
|
119
|
+
_await$Promise$all2 = _slicedToArray(_await$Promise$all, 6),
|
|
120
|
+
features = _await$Promise$all2[0],
|
|
121
|
+
core = _await$Promise$all2[1],
|
|
122
|
+
staticDirs = _await$Promise$all2[2],
|
|
123
|
+
storyIndexers = _await$Promise$all2[3],
|
|
124
|
+
stories = _await$Promise$all2[4],
|
|
125
|
+
docsOptions = _await$Promise$all2[5];
|
|
126
|
+
|
|
127
|
+
var fullOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
128
|
+
presets: presets,
|
|
129
|
+
features: features
|
|
130
|
+
});
|
|
129
131
|
|
|
130
132
|
if (staticDirs && options.staticDir) {
|
|
131
|
-
throw new Error((0, _tsDedent.
|
|
133
|
+
throw new Error((0, _tsDedent.dedent)`
|
|
132
134
|
Conflict when trying to read staticDirs:
|
|
133
135
|
* Storybook's configuration option: 'staticDirs'
|
|
134
136
|
* Storybook's CLI flag: '--staticDir' or '-s'
|
|
@@ -137,17 +139,23 @@ async function buildStaticStandalone(options) {
|
|
|
137
139
|
`);
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
var effects = [];
|
|
143
|
+
_global.default.FEATURES = features;
|
|
144
|
+
await managerBuilder.build({
|
|
145
|
+
startTime: process.hrtime(),
|
|
146
|
+
options: fullOptions
|
|
147
|
+
});
|
|
148
|
+
|
|
140
149
|
if (staticDirs) {
|
|
141
|
-
|
|
150
|
+
effects.push((0, _copyAllStaticFiles.copyAllStaticFilesRelativeToMain)(staticDirs, options.outputDir, options.configDir));
|
|
142
151
|
}
|
|
143
152
|
|
|
144
153
|
if (options.staticDir) {
|
|
145
|
-
|
|
154
|
+
effects.push((0, _copyAllStaticFiles.copyAllStaticFiles)(options.staticDir, options.outputDir));
|
|
146
155
|
}
|
|
147
156
|
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
var extractTasks = [];
|
|
157
|
+
var coreServerPublicDir = (0, _path.join)((0, _path.dirname)(require.resolve('@storybook/core-server/package.json')), 'public');
|
|
158
|
+
effects.push((0, _fsExtra.copy)(coreServerPublicDir, options.outputDir));
|
|
151
159
|
var initializedStoryIndexGenerator = Promise.resolve(undefined);
|
|
152
160
|
|
|
153
161
|
if ((features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) && !options.ignorePreview) {
|
|
@@ -156,24 +164,22 @@ async function buildStaticStandalone(options) {
|
|
|
156
164
|
configDir: options.configDir,
|
|
157
165
|
workingDir: workingDir
|
|
158
166
|
};
|
|
159
|
-
var normalizedStories = (0, _coreCommon.normalizeStories)(
|
|
160
|
-
var storyIndexers = await presets.apply('storyIndexers', []);
|
|
167
|
+
var normalizedStories = (0, _coreCommon.normalizeStories)(stories, directories);
|
|
161
168
|
var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, _objectSpread(_objectSpread({}, directories), {}, {
|
|
162
169
|
storyIndexers: storyIndexers,
|
|
170
|
+
docs: docsOptions,
|
|
163
171
|
storiesV2Compatibility: !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7),
|
|
164
172
|
storyStoreV7: !!(features !== null && features !== void 0 && features.storyStoreV7)
|
|
165
173
|
}));
|
|
166
174
|
initializedStoryIndexGenerator = generator.initialize().then(function () {
|
|
167
175
|
return generator;
|
|
168
176
|
});
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
effects.push((0, _storiesJson.extractStoriesJson)((0, _path.join)(options.outputDir, 'stories.json'), initializedStoryIndexGenerator, _storiesJson.convertToIndexV3));
|
|
178
|
+
effects.push((0, _storiesJson.extractStoriesJson)((0, _path.join)(options.outputDir, 'index.json'), initializedStoryIndexGenerator));
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
var core = await presets.apply('core');
|
|
174
|
-
|
|
175
181
|
if (!(core !== null && core !== void 0 && core.disableTelemetry)) {
|
|
176
|
-
initializedStoryIndexGenerator.then(async function (generator) {
|
|
182
|
+
effects.push(initializedStoryIndexGenerator.then(async function (generator) {
|
|
177
183
|
if (!generator) {
|
|
178
184
|
return;
|
|
179
185
|
}
|
|
@@ -185,60 +191,33 @@ async function buildStaticStandalone(options) {
|
|
|
185
191
|
version: storyIndex.v
|
|
186
192
|
}
|
|
187
193
|
} : undefined;
|
|
188
|
-
(0, _telemetry.telemetry)('build', payload, {
|
|
194
|
+
await (0, _telemetry.telemetry)('build', payload, {
|
|
189
195
|
configDir: options.configDir
|
|
190
196
|
});
|
|
191
|
-
});
|
|
197
|
+
}));
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
if (!(core !== null && core !== void 0 && core.disableProjectJson)) {
|
|
195
|
-
|
|
201
|
+
effects.push((0, _metadata.extractStorybookMetadata)((0, _path.join)(options.outputDir, 'project.json'), options.configDir));
|
|
196
202
|
}
|
|
197
203
|
|
|
198
|
-
var fullOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
199
|
-
presets: presets,
|
|
200
|
-
features: features
|
|
201
|
-
});
|
|
202
|
-
|
|
203
204
|
if (options.debugWebpack) {
|
|
204
205
|
(0, _coreCommon.logConfig)('Preview webpack config', await previewBuilder.getConfig(fullOptions));
|
|
205
|
-
(0, _coreCommon.logConfig)('Manager webpack config', await managerBuilder.getConfig(fullOptions));
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
var prebuiltDir = await getPrebuiltDir(fullOptions);
|
|
209
|
-
var startTime = process.hrtime(); // When using the prebuilt manager, we straight up copy it into the outputDir instead of building it
|
|
210
|
-
|
|
211
|
-
var manager = prebuiltDir ? _fsExtra.default.copy(prebuiltDir, options.outputDir, {
|
|
212
|
-
dereference: true
|
|
213
|
-
}).then(function () {}) : managerBuilder.build({
|
|
214
|
-
startTime: startTime,
|
|
215
|
-
options: fullOptions
|
|
216
|
-
});
|
|
217
|
-
|
|
218
208
|
if (options.ignorePreview) {
|
|
219
209
|
_nodeLogger.logger.info(`=> Not building preview`);
|
|
220
210
|
}
|
|
221
211
|
|
|
222
|
-
|
|
223
|
-
startTime:
|
|
212
|
+
await Promise.all([...(options.ignorePreview ? [] : [previewBuilder.build({
|
|
213
|
+
startTime: process.hrtime(),
|
|
224
214
|
options: fullOptions
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}),
|
|
231
|
-
await (managerBuilder === null || managerBuilder === void 0 ? void 0 : managerBuilder.bail());
|
|
232
|
-
throw err;
|
|
233
|
-
}), ...extractTasks]),
|
|
234
|
-
_await$Promise$all2 = _slicedToArray(_await$Promise$all, 2),
|
|
235
|
-
managerStats = _await$Promise$all2[0],
|
|
236
|
-
previewStats = _await$Promise$all2[1];
|
|
237
|
-
|
|
238
|
-
if (options.webpackStatsJson) {
|
|
239
|
-
var target = options.webpackStatsJson === true ? options.outputDir : options.webpackStatsJson;
|
|
240
|
-
await (0, _outputStats.outputStats)(target, previewStats, managerStats);
|
|
241
|
-
}
|
|
215
|
+
}).then(async function (previewStats) {
|
|
216
|
+
if (options.webpackStatsJson) {
|
|
217
|
+
var target = options.webpackStatsJson === true ? options.outputDir : options.webpackStatsJson;
|
|
218
|
+
await (0, _outputStats.outputStats)(target, previewStats);
|
|
219
|
+
}
|
|
220
|
+
})]), ...effects]);
|
|
242
221
|
|
|
243
222
|
_nodeLogger.logger.info(`=> Output directory: ${options.outputDir}`);
|
|
244
223
|
}
|
package/dist/cjs/dev-server.js
CHANGED
|
@@ -87,8 +87,10 @@ async function storybookDevServer(options) {
|
|
|
87
87
|
};
|
|
88
88
|
var normalizedStories = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), directories);
|
|
89
89
|
var storyIndexers = await options.presets.apply('storyIndexers', []);
|
|
90
|
+
var docsOptions = await options.presets.apply('docs', {});
|
|
90
91
|
var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, _objectSpread(_objectSpread({}, directories), {}, {
|
|
91
92
|
storyIndexers: storyIndexers,
|
|
93
|
+
docs: docsOptions,
|
|
92
94
|
workingDir: workingDir,
|
|
93
95
|
storiesV2Compatibility: !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7),
|
|
94
96
|
storyStoreV7: features === null || features === void 0 ? void 0 : features.storyStoreV7
|
|
@@ -191,7 +193,6 @@ async function storybookDevServer(options) {
|
|
|
191
193
|
|
|
192
194
|
if (options.debugWebpack) {
|
|
193
195
|
(0, _coreCommon.logConfig)('Preview webpack config', await previewBuilder.getConfig(options));
|
|
194
|
-
(0, _coreCommon.logConfig)('Manager webpack config', await managerBuilder.getConfig(options));
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
var preview = options.ignorePreview ? Promise.resolve() : previewBuilder.start({
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,23 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
getPreviewHeadTemplate: true,
|
|
8
|
-
getManagerHeadTemplate: true,
|
|
9
|
-
getManagerMainTemplate: true,
|
|
10
8
|
getPreviewBodyTemplate: true,
|
|
11
9
|
getPreviewMainTemplate: true
|
|
12
10
|
};
|
|
13
|
-
Object.defineProperty(exports, "getManagerHeadTemplate", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _coreCommon.getManagerHeadTemplate;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "getManagerMainTemplate", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _coreCommon.getManagerMainTemplate;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
11
|
Object.defineProperty(exports, "getPreviewBodyTemplate", {
|
|
26
12
|
enumerable: true,
|
|
27
13
|
get: function () {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.typescript = exports.storyIndexers = exports.previewMainTemplate = exports.previewHead = exports.previewEntries = exports.previewBody = exports.
|
|
6
|
+
exports.typescript = exports.title = exports.storyIndexers = exports.previewMainTemplate = exports.previewHead = exports.previewEntries = exports.previewBody = exports.logLevel = exports.features = exports.env = exports.core = exports.config = exports.babel = void 0;
|
|
7
7
|
|
|
8
8
|
require("core-js/modules/es.promise.js");
|
|
9
9
|
|
|
@@ -28,6 +28,12 @@ var babel = async function (_, options) {
|
|
|
28
28
|
|
|
29
29
|
exports.babel = babel;
|
|
30
30
|
|
|
31
|
+
var title = function (previous, options) {
|
|
32
|
+
return previous || options.packageJson.name || false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.title = title;
|
|
36
|
+
|
|
31
37
|
var logLevel = function (previous, options) {
|
|
32
38
|
return previous || options.loglevel || 'info';
|
|
33
39
|
};
|
|
@@ -68,12 +74,6 @@ var previewMainTemplate = function () {
|
|
|
68
74
|
|
|
69
75
|
exports.previewMainTemplate = previewMainTemplate;
|
|
70
76
|
|
|
71
|
-
var managerMainTemplate = function () {
|
|
72
|
-
return (0, _coreCommon.getManagerMainTemplate)();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
exports.managerMainTemplate = managerMainTemplate;
|
|
76
|
-
|
|
77
77
|
var previewEntries = function (entries = []) {
|
|
78
78
|
entries.push(require.resolve('@storybook/core-client/dist/esm/globals/globals'));
|
|
79
79
|
return entries;
|
|
@@ -56,6 +56,25 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
56
56
|
var makeAbsolute = function (otherImport, normalizedPath, workingDir) {
|
|
57
57
|
return otherImport.startsWith('.') ? (0, _slash.default)(_path.default.resolve(workingDir, (0, _coreCommon.normalizeStoryPath)(_path.default.join(_path.default.dirname(normalizedPath), otherImport)))) : otherImport;
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* The StoryIndexGenerator extracts stories and docs entries for each file matching
|
|
61
|
+
* (one or more) stories "specifiers", as defined in main.js.
|
|
62
|
+
*
|
|
63
|
+
* The output is a set of entries (see above for the types).
|
|
64
|
+
*
|
|
65
|
+
* Each file is treated as a stories or a (modern) docs file.
|
|
66
|
+
*
|
|
67
|
+
* A stories file is indexed by an indexer (passed in), which produces a list of stories.
|
|
68
|
+
* - If the stories have the `parameters.docsOnly` setting, they are disregarded.
|
|
69
|
+
* - If the indexer is a "docs template" indexer, OR docsPage is enabled,
|
|
70
|
+
* a templated docs entry is added pointing to the story file.
|
|
71
|
+
*
|
|
72
|
+
* A (modern) docs file is indexed, a standalone docs entry is added.
|
|
73
|
+
*
|
|
74
|
+
* The entries are "uniq"-ed and sorted. Stories entries are preferred to docs entries and
|
|
75
|
+
* standalone docs entries are preferred to templates (with warnings).
|
|
76
|
+
*/
|
|
77
|
+
|
|
59
78
|
|
|
60
79
|
class StoryIndexGenerator {
|
|
61
80
|
// An internal cache mapping specifiers to a set of path=><set of stories>
|
|
@@ -103,14 +122,15 @@ class StoryIndexGenerator {
|
|
|
103
122
|
*/
|
|
104
123
|
|
|
105
124
|
|
|
106
|
-
async updateExtracted(updater) {
|
|
125
|
+
async updateExtracted(updater, overwrite = false) {
|
|
107
126
|
var _this2 = this;
|
|
108
127
|
|
|
109
128
|
await Promise.all(this.specifiers.map(async function (specifier) {
|
|
110
129
|
var entry = _this2.specifierToCache.get(specifier);
|
|
111
130
|
|
|
112
131
|
return Promise.all(Object.keys(entry).map(async function (absolutePath) {
|
|
113
|
-
|
|
132
|
+
if (entry[absolutePath] && !overwrite) return;
|
|
133
|
+
entry[absolutePath] = await updater(specifier, absolutePath, entry[absolutePath]);
|
|
114
134
|
}));
|
|
115
135
|
}));
|
|
116
136
|
}
|
|
@@ -129,9 +149,13 @@ class StoryIndexGenerator {
|
|
|
129
149
|
await this.updateExtracted(async function (specifier, absolutePath) {
|
|
130
150
|
return _this3.isDocsMdx(absolutePath) ? false : _this3.extractStories(specifier, absolutePath);
|
|
131
151
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
152
|
+
|
|
153
|
+
if (this.options.docs.enabled) {
|
|
154
|
+
await this.updateExtracted(async function (specifier, absolutePath) {
|
|
155
|
+
return _this3.extractDocs(specifier, absolutePath);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
135
159
|
return this.specifiers.flatMap(function (specifier) {
|
|
136
160
|
var cache = _this3.specifierToCache.get(specifier);
|
|
137
161
|
|
|
@@ -172,6 +196,79 @@ class StoryIndexGenerator {
|
|
|
172
196
|
return dependencies;
|
|
173
197
|
}
|
|
174
198
|
|
|
199
|
+
async extractStories(specifier, absolutePath) {
|
|
200
|
+
var relativePath = _path.default.relative(this.options.workingDir, absolutePath);
|
|
201
|
+
|
|
202
|
+
var entries = [];
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
var importPath = (0, _slash.default)((0, _coreCommon.normalizeStoryPath)(relativePath));
|
|
206
|
+
|
|
207
|
+
var makeTitle = function (userTitle) {
|
|
208
|
+
return (0, _store.userOrAutoTitleFromSpecifier)(importPath, specifier, userTitle);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
var storyIndexer = this.options.storyIndexers.find(function (indexer) {
|
|
212
|
+
return indexer.test.exec(absolutePath);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (!storyIndexer) {
|
|
216
|
+
throw new Error(`No matching story indexer found for ${absolutePath}`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var csf = await storyIndexer.indexer(absolutePath, {
|
|
220
|
+
makeTitle: makeTitle
|
|
221
|
+
});
|
|
222
|
+
csf.stories.forEach(function ({
|
|
223
|
+
id: id,
|
|
224
|
+
name: name,
|
|
225
|
+
parameters: parameters
|
|
226
|
+
}) {
|
|
227
|
+
if (!(parameters !== null && parameters !== void 0 && parameters.docsOnly)) {
|
|
228
|
+
entries.push({
|
|
229
|
+
id: id,
|
|
230
|
+
title: csf.meta.title,
|
|
231
|
+
name: name,
|
|
232
|
+
importPath: importPath,
|
|
233
|
+
type: 'story'
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (this.options.docs.enabled) {
|
|
239
|
+
// We always add a template for *.stories.mdx, but only if docs page is enabled for
|
|
240
|
+
// regular CSF files
|
|
241
|
+
if (storyIndexer.addDocsTemplate || this.options.docs.docsPage) {
|
|
242
|
+
var name = this.options.docs.defaultName;
|
|
243
|
+
var id = (0, _csf.toId)(csf.meta.title, name);
|
|
244
|
+
entries.unshift({
|
|
245
|
+
id: id,
|
|
246
|
+
title: csf.meta.title,
|
|
247
|
+
name: name,
|
|
248
|
+
importPath: importPath,
|
|
249
|
+
type: 'docs',
|
|
250
|
+
storiesImports: [],
|
|
251
|
+
standalone: false
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (err) {
|
|
256
|
+
if (err.name === 'NoMetaError') {
|
|
257
|
+
_nodeLogger.logger.info(`💡 Skipping ${relativePath}: ${err}`);
|
|
258
|
+
} else {
|
|
259
|
+
_nodeLogger.logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
|
|
260
|
+
|
|
261
|
+
throw err;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
entries: entries,
|
|
267
|
+
type: 'stories',
|
|
268
|
+
dependents: []
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
175
272
|
async extractDocs(specifier, absolutePath) {
|
|
176
273
|
var _this4 = this;
|
|
177
274
|
|
|
@@ -193,9 +290,10 @@ class StoryIndexGenerator {
|
|
|
193
290
|
var _await$require = await require('@storybook/docs-mdx'),
|
|
194
291
|
analyze = _await$require.analyze;
|
|
195
292
|
|
|
196
|
-
var content = await _fsExtra.default.readFile(absolutePath, 'utf8');
|
|
293
|
+
var content = await _fsExtra.default.readFile(absolutePath, 'utf8');
|
|
294
|
+
var result = analyze(content); // Templates are not indexed
|
|
197
295
|
|
|
198
|
-
|
|
296
|
+
if (result.isTemplate) return false;
|
|
199
297
|
var absoluteImports = result.imports.map(function (p) {
|
|
200
298
|
return makeAbsolute(p, normalizedPath, _this4.options.workingDir);
|
|
201
299
|
}); // Go through the cache and collect all of the cache entries that this docs file depends on.
|
|
@@ -225,8 +323,8 @@ class StoryIndexGenerator {
|
|
|
225
323
|
dependencies.forEach(function (dep) {
|
|
226
324
|
dep.dependents.push(absolutePath);
|
|
227
325
|
});
|
|
228
|
-
var title = (0, _store.userOrAutoTitleFromSpecifier)(importPath, specifier, result.title
|
|
229
|
-
var name =
|
|
326
|
+
var title = ofTitle || (0, _store.userOrAutoTitleFromSpecifier)(importPath, specifier, result.title);
|
|
327
|
+
var name = result.name || this.options.docs.defaultName;
|
|
230
328
|
var id = (0, _csf.toId)(title, name);
|
|
231
329
|
var docsEntry = {
|
|
232
330
|
id: id,
|
|
@@ -236,7 +334,8 @@ class StoryIndexGenerator {
|
|
|
236
334
|
storiesImports: dependencies.map(function (dep) {
|
|
237
335
|
return dep.entries[0].importPath;
|
|
238
336
|
}),
|
|
239
|
-
type: 'docs'
|
|
337
|
+
type: 'docs',
|
|
338
|
+
standalone: true
|
|
240
339
|
};
|
|
241
340
|
return docsEntry;
|
|
242
341
|
} catch (err) {
|
|
@@ -246,74 +345,62 @@ class StoryIndexGenerator {
|
|
|
246
345
|
}
|
|
247
346
|
}
|
|
248
347
|
|
|
249
|
-
|
|
250
|
-
var
|
|
251
|
-
return indexer.test.exec(filePath);
|
|
252
|
-
});
|
|
348
|
+
chooseDuplicate(firstEntry, secondEntry) {
|
|
349
|
+
var firstIsBetter = true;
|
|
253
350
|
|
|
254
|
-
if (
|
|
255
|
-
|
|
351
|
+
if (secondEntry.type === 'story') {
|
|
352
|
+
firstIsBetter = false;
|
|
353
|
+
} else if (secondEntry.standalone && firstEntry.type === 'docs' && !firstEntry.standalone) {
|
|
354
|
+
firstIsBetter = false;
|
|
256
355
|
}
|
|
257
356
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
async extractStories(specifier, absolutePath) {
|
|
262
|
-
var relativePath = _path.default.relative(this.options.workingDir, absolutePath);
|
|
263
|
-
|
|
264
|
-
var entries = [];
|
|
357
|
+
var betterEntry = firstIsBetter ? firstEntry : secondEntry;
|
|
358
|
+
var worseEntry = firstIsBetter ? secondEntry : firstEntry;
|
|
359
|
+
var changeDocsName = 'Use `<Meta of={} name="Other Name">` to distinguish them.'; // This shouldn't be possible, but double check and use for typing
|
|
265
360
|
|
|
266
|
-
|
|
267
|
-
var importPath = (0, _slash.default)((0, _coreCommon.normalizeStoryPath)(relativePath));
|
|
361
|
+
if (worseEntry.type === 'story') throw new Error(`Duplicate stories with id: ${firstEntry.id}`);
|
|
268
362
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
};
|
|
363
|
+
if (betterEntry.type === 'story') {
|
|
364
|
+
var worseDescriptor = worseEntry.standalone ? `component docs page` : `automatically generated docs page`;
|
|
272
365
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
csf.stories.forEach(function ({
|
|
277
|
-
id: id,
|
|
278
|
-
name: name,
|
|
279
|
-
parameters: parameters
|
|
280
|
-
}) {
|
|
281
|
-
var base = {
|
|
282
|
-
id: id,
|
|
283
|
-
title: csf.meta.title,
|
|
284
|
-
name: name,
|
|
285
|
-
importPath: importPath
|
|
286
|
-
};
|
|
287
|
-
var entry = parameters !== null && parameters !== void 0 && parameters.docsOnly ? _objectSpread(_objectSpread({}, base), {}, {
|
|
288
|
-
type: 'docs',
|
|
289
|
-
storiesImports: [],
|
|
290
|
-
legacy: true
|
|
291
|
-
}) : _objectSpread(_objectSpread({}, base), {}, {
|
|
292
|
-
type: 'story'
|
|
293
|
-
});
|
|
294
|
-
entries.push(entry);
|
|
295
|
-
});
|
|
296
|
-
} catch (err) {
|
|
297
|
-
if (err.name === 'NoMetaError') {
|
|
298
|
-
_nodeLogger.logger.info(`💡 Skipping ${relativePath}: ${err}`);
|
|
366
|
+
if (betterEntry.name === this.options.docs.defaultName) {
|
|
367
|
+
_nodeLogger.logger.warn(`🚨 You have a story for ${betterEntry.title} with the same name as your default docs entry name (${betterEntry.name}), so the docs page is being dropped. Consider changing the story name.`);
|
|
299
368
|
} else {
|
|
300
|
-
_nodeLogger.logger.warn(`🚨
|
|
301
|
-
|
|
302
|
-
throw err;
|
|
369
|
+
_nodeLogger.logger.warn(`🚨 You have a story for ${betterEntry.title} with the same name as your ${worseDescriptor} (${worseEntry.name}), so the docs page is being dropped. ${changeDocsName}`);
|
|
303
370
|
}
|
|
371
|
+
} else if (betterEntry.standalone) {
|
|
372
|
+
// Both entries are standalone but pointing at the same place
|
|
373
|
+
if (worseEntry.standalone) {
|
|
374
|
+
_nodeLogger.logger.warn(`🚨 You have two component docs pages with the same name ${betterEntry.title}:${betterEntry.name}. ${changeDocsName}`);
|
|
375
|
+
} // If one entry is standalone (i.e. .mdx of={}) we are OK with it overriding a template
|
|
376
|
+
// - docs page templates, this is totally fine and expected
|
|
377
|
+
// - not sure if it is even possible to have a .mdx of={} pointing at a stories.mdx file
|
|
378
|
+
|
|
379
|
+
} else {
|
|
380
|
+
// If both entries are templates (e.g. you have two CSF files with the same title), then
|
|
381
|
+
// we need to merge the entries. We'll use the the first one's name and importPath,
|
|
382
|
+
// but ensure we include both as storiesImports so they are both loaded before rendering
|
|
383
|
+
// the story (for the <Stories> block & friends)
|
|
384
|
+
return _objectSpread(_objectSpread({}, betterEntry), {}, {
|
|
385
|
+
storiesImports: [...betterEntry.storiesImports, worseEntry.importPath, ...worseEntry.storiesImports]
|
|
386
|
+
});
|
|
304
387
|
}
|
|
305
388
|
|
|
306
|
-
return
|
|
307
|
-
entries: entries,
|
|
308
|
-
type: 'stories',
|
|
309
|
-
dependents: []
|
|
310
|
-
};
|
|
389
|
+
return betterEntry;
|
|
311
390
|
}
|
|
312
391
|
|
|
313
392
|
async sortStories(storiesList) {
|
|
393
|
+
var _this5 = this;
|
|
394
|
+
|
|
314
395
|
var entries = {};
|
|
315
396
|
storiesList.forEach(function (entry) {
|
|
316
|
-
entries[entry.id]
|
|
397
|
+
var existing = entries[entry.id];
|
|
398
|
+
|
|
399
|
+
if (existing) {
|
|
400
|
+
entries[entry.id] = _this5.chooseDuplicate(existing, entry);
|
|
401
|
+
} else {
|
|
402
|
+
entries[entry.id] = entry;
|
|
403
|
+
}
|
|
317
404
|
});
|
|
318
405
|
var sortableStories = Object.values(entries); // Skip sorting if we're in v6 mode because we don't have
|
|
319
406
|
// all the info we need here
|
|
@@ -371,7 +458,7 @@ class StoryIndexGenerator {
|
|
|
371
458
|
}
|
|
372
459
|
|
|
373
460
|
invalidate(specifier, importPath, removed) {
|
|
374
|
-
var
|
|
461
|
+
var _this6 = this;
|
|
375
462
|
|
|
376
463
|
var absolutePath = (0, _slash.default)(_path.default.resolve(this.options.workingDir, importPath));
|
|
377
464
|
var cache = this.specifierToCache.get(specifier);
|
|
@@ -402,7 +489,7 @@ class StoryIndexGenerator {
|
|
|
402
489
|
if (removed) {
|
|
403
490
|
if (cacheEntry && cacheEntry.type === 'docs') {
|
|
404
491
|
var absoluteImports = cacheEntry.storiesImports.map(function (p) {
|
|
405
|
-
return _path.default.resolve(
|
|
492
|
+
return _path.default.resolve(_this6.options.workingDir, p);
|
|
406
493
|
});
|
|
407
494
|
var dependencies = this.findDependencies(absoluteImports);
|
|
408
495
|
dependencies.forEach(function (dep) {
|
|
@@ -419,10 +506,10 @@ class StoryIndexGenerator {
|
|
|
419
506
|
}
|
|
420
507
|
|
|
421
508
|
async getStorySortParameter() {
|
|
422
|
-
var
|
|
509
|
+
var _this7 = this;
|
|
423
510
|
|
|
424
511
|
var previewFile = ['js', 'jsx', 'ts', 'tsx'].map(function (ext) {
|
|
425
|
-
return _path.default.join(
|
|
512
|
+
return _path.default.join(_this7.options.configDir, `preview.${ext}`);
|
|
426
513
|
}).find(function (fname) {
|
|
427
514
|
return _fsExtra.default.existsSync(fname);
|
|
428
515
|
});
|