@storybook/core-server 6.4.0-beta.4 → 6.4.0-beta.8

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.
Files changed (73) hide show
  1. package/dist/cjs/build-static.js +6 -3
  2. package/dist/cjs/utils/StoryIndexGenerator.js +60 -37
  3. package/dist/cjs/utils/__mockdata__/E.stories.js +13 -0
  4. package/dist/cjs/utils/__mockdata__/deeply/nested/single/File.stories.js +12 -0
  5. package/dist/cjs/utils/__mockdata__/preview.js +8 -0
  6. package/dist/cjs/utils/__mockdata__/src/A.stories.js +13 -0
  7. package/dist/cjs/utils/__mockdata__/src/B.stories.js +13 -0
  8. package/dist/cjs/utils/__mockdata__/src/C.js +8 -0
  9. package/dist/cjs/utils/__mockdata__/src/D.stories.js +13 -0
  10. package/dist/cjs/utils/__mockdata__/src/nested/Button.js +8 -0
  11. package/dist/cjs/utils/__mockdata__/src/nested/Button.stories.js +13 -0
  12. package/dist/cjs/utils/__mockdata__/src/nested/Page.mdx +1 -0
  13. package/dist/cjs/utils/__mockdata__/src/nested/Page.stories.mdx +5 -0
  14. package/dist/cjs/utils/__mockdata__/src/second-nested/F.stories.js +13 -0
  15. package/dist/cjs/utils/stories-json.js +39 -9
  16. package/dist/cjs/utils/use-events-as-sse.js +65 -0
  17. package/dist/cjs/utils/watch-story-specifiers.js +56 -0
  18. package/dist/esm/build-static.js +6 -3
  19. package/dist/esm/utils/StoryIndexGenerator.js +55 -34
  20. package/dist/esm/utils/__mockdata__/E.stories.js +5 -0
  21. package/dist/esm/utils/__mockdata__/deeply/nested/single/File.stories.js +4 -0
  22. package/dist/esm/utils/__mockdata__/preview.js +1 -0
  23. package/dist/esm/utils/__mockdata__/src/A.stories.js +5 -0
  24. package/dist/esm/utils/__mockdata__/src/B.stories.js +5 -0
  25. package/dist/esm/utils/__mockdata__/src/C.js +1 -0
  26. package/dist/esm/utils/__mockdata__/src/D.stories.js +5 -0
  27. package/dist/esm/utils/__mockdata__/src/nested/Button.js +1 -0
  28. package/dist/esm/utils/__mockdata__/src/nested/Button.stories.js +5 -0
  29. package/dist/esm/utils/__mockdata__/src/nested/Page.mdx +1 -0
  30. package/dist/esm/utils/__mockdata__/src/nested/Page.stories.mdx +5 -0
  31. package/dist/esm/utils/__mockdata__/src/second-nested/F.stories.js +5 -0
  32. package/dist/esm/utils/stories-json.js +35 -9
  33. package/dist/esm/utils/use-events-as-sse.js +58 -0
  34. package/dist/esm/utils/watch-story-specifiers.js +46 -0
  35. package/dist/modern/build-static.js +6 -3
  36. package/dist/modern/utils/StoryIndexGenerator.js +55 -34
  37. package/dist/modern/utils/__mockdata__/E.stories.js +5 -0
  38. package/dist/modern/utils/__mockdata__/deeply/nested/single/File.stories.js +4 -0
  39. package/dist/modern/utils/__mockdata__/preview.js +1 -0
  40. package/dist/modern/utils/__mockdata__/src/A.stories.js +5 -0
  41. package/dist/modern/utils/__mockdata__/src/B.stories.js +5 -0
  42. package/dist/modern/utils/__mockdata__/src/C.js +1 -0
  43. package/dist/modern/utils/__mockdata__/src/D.stories.js +5 -0
  44. package/dist/modern/utils/__mockdata__/src/nested/Button.js +1 -0
  45. package/dist/modern/utils/__mockdata__/src/nested/Button.stories.js +5 -0
  46. package/dist/modern/utils/__mockdata__/src/nested/Page.mdx +1 -0
  47. package/dist/modern/utils/__mockdata__/src/nested/Page.stories.mdx +5 -0
  48. package/dist/modern/utils/__mockdata__/src/second-nested/F.stories.js +5 -0
  49. package/dist/modern/utils/stories-json.js +35 -9
  50. package/dist/modern/utils/use-events-as-sse.js +58 -0
  51. package/dist/modern/utils/watch-story-specifiers.js +46 -0
  52. package/dist/ts3.4/utils/StoryIndexGenerator.d.ts +17 -10
  53. package/dist/ts3.4/utils/__mockdata__/E.stories.d.ts +5 -0
  54. package/dist/ts3.4/utils/__mockdata__/deeply/nested/single/File.stories.d.ts +5 -0
  55. package/dist/ts3.4/utils/__mockdata__/src/B.stories.d.ts +5 -0
  56. package/dist/ts3.4/utils/__mockdata__/src/nested/Button.d.ts +1 -0
  57. package/dist/ts3.4/utils/__mockdata__/src/nested/Button.stories.d.ts +5 -0
  58. package/dist/ts3.4/utils/__mockdata__/src/second-nested/F.stories.d.ts +5 -0
  59. package/dist/ts3.4/utils/stories-json.d.ts +7 -2
  60. package/dist/ts3.4/utils/use-events-as-sse.d.ts +4 -0
  61. package/dist/ts3.4/utils/watch-story-specifiers.d.ts +3 -0
  62. package/dist/ts3.9/utils/StoryIndexGenerator.d.ts +17 -10
  63. package/dist/ts3.9/utils/__mockdata__/E.stories.d.ts +5 -0
  64. package/dist/ts3.9/utils/__mockdata__/deeply/nested/single/File.stories.d.ts +5 -0
  65. package/dist/ts3.9/utils/__mockdata__/src/B.stories.d.ts +5 -0
  66. package/dist/ts3.9/utils/__mockdata__/src/nested/Button.d.ts +1 -0
  67. package/dist/ts3.9/utils/__mockdata__/src/nested/Button.stories.d.ts +5 -0
  68. package/dist/ts3.9/utils/__mockdata__/src/second-nested/F.stories.d.ts +5 -0
  69. package/dist/ts3.9/utils/stories-json.d.ts +7 -2
  70. package/dist/ts3.9/utils/use-events-as-sse.d.ts +4 -0
  71. package/dist/ts3.9/utils/watch-story-specifiers.d.ts +3 -0
  72. package/package.json +13 -12
  73. package/typings.d.ts +1 -0
@@ -100,11 +100,14 @@ async function buildStaticStandalone(options) {
100
100
  var features = await presets.apply('features');
101
101
 
102
102
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
103
- var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories'), {
103
+ var directories = {
104
104
  configDir: options.configDir,
105
105
  workingDir: process.cwd()
106
- });
107
- await (0, _storiesJson.extractStoriesJson)(_path.default.join(options.outputDir, 'stories.json'), stories, options.configDir, !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7));
106
+ };
107
+ var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories'), directories);
108
+ await (0, _storiesJson.extractStoriesJson)(_path.default.join(options.outputDir, 'stories.json'), stories, _objectSpread(_objectSpread({}, directories), {}, {
109
+ storiesV2Compatibility: !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7)
110
+ }));
108
111
  }
109
112
 
110
113
  var fullOptions = _objectSpread(_objectSpread({}, options), {}, {
@@ -57,11 +57,14 @@ function sortExtractedStories(stories, storySortParameter, fileNameOrder) {
57
57
  class StoryIndexGenerator {
58
58
  // An internal cache mapping specifiers to a set of path=><set of stories>
59
59
  // Later, we'll combine each of these subsets together to form the full index
60
- constructor(specifiers, configDir, storiesV2Compatibility) {
60
+ // Cache the last value of `getStoryIndex`. We invalidate (by unsetting) when:
61
+ // - any file changes, including deletions
62
+ // - the preview changes [not yet implemented]
63
+ constructor(specifiers, options) {
61
64
  this.specifiers = specifiers;
62
- this.configDir = configDir;
63
- this.storiesV2Compatibility = storiesV2Compatibility;
65
+ this.options = options;
64
66
  this.storyIndexEntries = void 0;
67
+ this.lastIndex = void 0;
65
68
  this.storyIndexEntries = new Map();
66
69
  }
67
70
 
@@ -71,9 +74,22 @@ class StoryIndexGenerator {
71
74
  // Find all matching paths for each specifier
72
75
  await Promise.all(this.specifiers.map(async function (specifier) {
73
76
  var pathToSubIndex = {};
74
- var files = await (0, _globby.default)(_path.default.join(_this.configDir, specifier.glob));
75
- files.forEach(function (fileName) {
76
- pathToSubIndex[fileName] = false;
77
+
78
+ var fullGlob = _path.default.join(_this.options.workingDir, specifier.directory, specifier.files);
79
+
80
+ var files = await (0, _globby.default)(fullGlob);
81
+ files.forEach(function (absolutePath) {
82
+ var ext = _path.default.extname(absolutePath);
83
+
84
+ var relativePath = _path.default.relative(_this.options.workingDir, absolutePath);
85
+
86
+ if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
87
+ _nodeLogger.logger.info(`Skipping ${ext} file ${relativePath}`);
88
+
89
+ return;
90
+ }
91
+
92
+ pathToSubIndex[absolutePath] = false;
77
93
  });
78
94
 
79
95
  _this.storyIndexEntries.set(specifier, pathToSubIndex);
@@ -85,25 +101,17 @@ class StoryIndexGenerator {
85
101
  async ensureExtracted() {
86
102
  var _this2 = this;
87
103
 
88
- await Promise.all(this.specifiers.map(async function (specifier) {
104
+ return (await Promise.all(this.specifiers.map(async function (specifier) {
89
105
  var entry = _this2.storyIndexEntries.get(specifier);
90
106
 
91
- await Promise.all(Object.keys(entry).map(async function (fileName) {
92
- if (!entry[fileName]) await _this2.extractStories(specifier, fileName);
107
+ return Promise.all(Object.keys(entry).map(async function (absolutePath) {
108
+ return entry[absolutePath] || _this2.extractStories(specifier, absolutePath);
93
109
  }));
94
- }));
110
+ }))).flat();
95
111
  }
96
112
 
97
113
  async extractStories(specifier, absolutePath) {
98
- var ext = _path.default.extname(absolutePath);
99
-
100
- var relativePath = _path.default.relative(this.configDir, absolutePath);
101
-
102
- if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
103
- _nodeLogger.logger.info(`Skipping ${ext} file ${relativePath}`);
104
-
105
- return;
106
- }
114
+ var relativePath = _path.default.relative(this.options.workingDir, absolutePath);
107
115
 
108
116
  try {
109
117
  var entry = this.storyIndexEntries.get(specifier);
@@ -125,32 +133,32 @@ class StoryIndexGenerator {
125
133
  };
126
134
  });
127
135
  entry[absolutePath] = fileStories;
136
+ return fileStories;
128
137
  } catch (err) {
129
138
  _nodeLogger.logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
130
139
 
131
- _nodeLogger.logger.warn(`🚨 ${err.stack}`);
132
-
133
140
  throw err;
134
141
  }
135
142
  }
136
143
 
137
- async getIndex() {
138
- var _this3 = this;
139
-
140
- // Extract any entries that are currently missing
141
- await this.ensureExtracted();
142
- var stories = {}; // Check each entry and compose into stories, extracting if needed
143
-
144
- this.specifiers.map(async function (specifier) {
145
- Object.values(_this3.storyIndexEntries.get(specifier)).map(function (subStories) {
146
- return Object.assign(stories, subStories);
147
- });
144
+ async sortStories(storiesList) {
145
+ var stories = {};
146
+ storiesList.forEach(function (subStories) {
147
+ Object.assign(stories, subStories);
148
148
  });
149
149
  var storySortParameter = await this.getStorySortParameter();
150
- var sorted = sortExtractedStories(stories, storySortParameter, this.storyFileNames());
150
+ return sortExtractedStories(stories, storySortParameter, this.storyFileNames());
151
+ }
152
+
153
+ async getIndex() {
154
+ if (this.lastIndex) return this.lastIndex; // Extract any entries that are currently missing
155
+ // Pull out each file's stories into a list of stories, to be composed and sorted
156
+
157
+ var storiesList = await this.ensureExtracted();
158
+ var sorted = await this.sortStories(storiesList);
151
159
  var compat = sorted;
152
160
 
153
- if (this.storiesV2Compatibility) {
161
+ if (this.options.storiesV2Compatibility) {
154
162
  var titleToStoryCount = Object.values(sorted).reduce(function (acc, story) {
155
163
  acc[story.title] = (acc[story.title] || 0) + 1;
156
164
  return acc;
@@ -174,17 +182,32 @@ class StoryIndexGenerator {
174
182
  }, {});
175
183
  }
176
184
 
177
- return {
185
+ this.lastIndex = {
178
186
  v: 3,
179
187
  stories: compat
180
188
  };
189
+ return this.lastIndex;
190
+ }
191
+
192
+ invalidate(specifier, importPath, removed) {
193
+ var absolutePath = _path.default.resolve(this.options.workingDir, importPath);
194
+
195
+ var pathToEntries = this.storyIndexEntries.get(specifier);
196
+
197
+ if (removed) {
198
+ delete pathToEntries[absolutePath];
199
+ } else {
200
+ pathToEntries[absolutePath] = false;
201
+ }
202
+
203
+ this.lastIndex = null;
181
204
  }
182
205
 
183
206
  async getStorySortParameter() {
184
- var _this4 = this;
207
+ var _this3 = this;
185
208
 
186
209
  var previewFile = ['js', 'jsx', 'ts', 'tsx'].map(function (ext) {
187
- return _path.default.join(_this4.configDir, `preview.${ext}`);
210
+ return _path.default.join(_this3.options.configDir, `preview.${ext}`);
188
211
  }).find(function (fname) {
189
212
  return _fsExtra.default.existsSync(fname);
190
213
  });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var _default = {
8
+ component: {}
9
+ };
10
+ exports.default = _default;
11
+ var StoryOne = {};
12
+ exports.StoryOne = StoryOne;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parameters = void 0;
7
+ var parameters = {};
8
+ exports.parameters = parameters;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.C = void 0;
7
+ var C = {};
8
+ exports.C = C;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Button = void 0;
7
+ var Button = {};
8
+ exports.Button = Button;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -0,0 +1 @@
1
+ <h1>Some MDX</h1>
@@ -0,0 +1,5 @@
1
+ import { Meta, Story } from '@storybook/addon-docs';
2
+
3
+ <Meta component={{}} />;
4
+
5
+ <Story name="StoryOne" />
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = exports.default = void 0;
7
+ var component = {};
8
+ var _default = {
9
+ component: component
10
+ };
11
+ exports.default = _default;
12
+ var StoryOne = {};
13
+ exports.StoryOne = StoryOne;
@@ -10,35 +10,65 @@ require("core-js/modules/es.promise.js");
10
10
 
11
11
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
12
12
 
13
+ var _events = _interopRequireDefault(require("events"));
14
+
13
15
  var _coreCommon = require("@storybook/core-common");
14
16
 
15
17
  var _StoryIndexGenerator = require("./StoryIndexGenerator");
16
18
 
19
+ var _watchStorySpecifiers = require("./watch-story-specifiers");
20
+
21
+ var _useEventsAsSse = require("./use-events-as-sse");
22
+
17
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
24
 
19
- async function extractStoriesJson(outputFile, normalizedStories, configDir, v2compatibility) {
20
- var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, configDir, v2compatibility);
25
+ var INVALIDATE = 'INVALIDATE';
26
+
27
+ async function extractStoriesJson(outputFile, normalizedStories, options) {
28
+ var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, options);
21
29
  await generator.initialize();
22
30
  var index = await generator.getIndex();
23
31
  await _fsExtra.default.writeJson(outputFile, index);
24
32
  }
25
33
 
26
- async function useStoriesJson(router, options) {
27
- var normalized = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), {
34
+ async function useStoriesJson(router, options, workingDir = process.cwd()) {
35
+ var normalizedStories = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), {
28
36
  configDir: options.configDir,
29
- workingDir: process.cwd()
37
+ workingDir: workingDir
30
38
  });
31
39
  var features = await options.presets.apply('features');
32
- router.use('/stories.json', async function (_req, res) {
33
- var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalized, options.configDir, !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7));
40
+ var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, {
41
+ configDir: options.configDir,
42
+ workingDir: workingDir,
43
+ storiesV2Compatibility: !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7)
44
+ }); // Wait until someone actually requests `stories.json` before we start generating/watching.
45
+ // This is mainly for testing purposes.
46
+
47
+ var started = false;
48
+ var invalidationEmitter = new _events.default();
49
+
50
+ async function ensureStarted() {
51
+ if (started) return;
52
+ started = true;
53
+ (0, _watchStorySpecifiers.watchStorySpecifiers)(normalizedStories, function (specifier, path, removed) {
54
+ generator.invalidate(specifier, path, removed);
55
+ invalidationEmitter.emit(INVALIDATE);
56
+ });
34
57
  await generator.initialize();
58
+ }
59
+
60
+ var eventsAsSSE = (0, _useEventsAsSse.useEventsAsSSE)(invalidationEmitter, [INVALIDATE]);
61
+ router.use('/stories.json', async function (req, res) {
62
+ await ensureStarted();
63
+ if (eventsAsSSE(req, res)) return;
35
64
 
36
65
  try {
37
66
  var index = await generator.getIndex();
38
67
  res.header('Content-Type', 'application/json');
39
- return res.send(JSON.stringify(index));
68
+ res.send(JSON.stringify(index));
40
69
  } catch (err) {
41
- return res.status(500).send(err.message);
70
+ res.status(500);
71
+ res.send(err.message);
42
72
  }
43
73
  });
44
74
  }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useEventsAsSSE = useEventsAsSSE;
7
+ var PING_INTERVAL = 1000;
8
+ var PING = 'PING';
9
+
10
+ function useEventsAsSSE(emitter, events) {
11
+ return function (req, res) {
12
+ if (req.headers.accept !== 'text/event-stream') {
13
+ return false;
14
+ }
15
+
16
+ var closed = false;
17
+
18
+ function sendEvent(event, data) {
19
+ if (closed || res.writableEnded) return;
20
+
21
+ if (data) {
22
+ res.write(`event:${event}\ndata:${JSON.stringify(data)}\n\n`);
23
+ } else {
24
+ res.write(`event:${event}\ndata:\n\n`);
25
+ }
26
+
27
+ res.flush();
28
+ }
29
+
30
+ var watchers = events.reduce(function (acc, event) {
31
+ acc[event] = function (data) {
32
+ return sendEvent(event, data);
33
+ };
34
+
35
+ return acc;
36
+ }, {});
37
+ var interval;
38
+
39
+ var close = function () {
40
+ events.forEach(function (eventName) {
41
+ emitter.off(eventName, watchers[eventName]);
42
+ });
43
+ clearTimeout(interval);
44
+ closed = true;
45
+ res.end();
46
+ };
47
+
48
+ res.on('close', close);
49
+ if (closed || res.writableEnded) return true;
50
+ res.setHeader('Cache-Control', 'no-cache');
51
+ res.setHeader('Content-Type', 'text/event-stream');
52
+ res.setHeader('Connection', 'keep-alive');
53
+ res.flushHeaders();
54
+ events.forEach(function (eventName) {
55
+ emitter.on(eventName, watchers[eventName]);
56
+ }); // Send a PING event every 1s to avoid Chrome timing out the request
57
+
58
+ var ping = function () {
59
+ return sendEvent(PING);
60
+ };
61
+
62
+ interval = setInterval(ping, PING_INTERVAL);
63
+ return true;
64
+ };
65
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.watchStorySpecifiers = watchStorySpecifiers;
7
+
8
+ var _watchpack = _interopRequireDefault(require("watchpack"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function watchStorySpecifiers(specifiers, onInvalidate) {
13
+ // See https://www.npmjs.com/package/watchpack for full options.
14
+ // If you want less traffic, consider using aggregation with some interval
15
+ var wp = new _watchpack.default({
16
+ // poll: true, // Slow!!! Enable only in special cases
17
+ followSymlinks: false,
18
+ ignored: ['**/.git', 'node_modules']
19
+ });
20
+ wp.watch({
21
+ directories: specifiers.map(function (ns) {
22
+ return ns.directory;
23
+ })
24
+ });
25
+
26
+ function onChangeOrRemove(watchpackPath, removed) {
27
+ // Watchpack passes paths either with no leading './' - e.g. `src/Foo.stories.js`,
28
+ // or with a leading `../` (etc), e.g. `../src/Foo.stories.js`.
29
+ // We want to deal in importPaths relative to the working dir, or absolute paths.
30
+ var importPath = watchpackPath.startsWith('.') ? watchpackPath : `./${watchpackPath}`;
31
+ var specifier = specifiers.find(function (ns) {
32
+ return ns.importPathMatcher.exec(importPath);
33
+ });
34
+
35
+ if (specifier) {
36
+ onInvalidate(specifier, importPath, removed);
37
+ }
38
+ }
39
+
40
+ wp.on('change', function (path, mtime, explanation) {
41
+ // When a file is renamed (including being moved out of the watched dir)
42
+ // we see first an event with explanation=rename and no mtime for the old name.
43
+ // then an event with explanation=rename with an mtime for the new name.
44
+ // In theory we could try and track both events together and move the exports
45
+ // but that seems dangerous (what if the contents changed?) and frankly not worth it
46
+ // (at this stage at least)
47
+ var removed = !mtime;
48
+ onChangeOrRemove(path, removed);
49
+ });
50
+ wp.on('remove', function (path, explanation) {
51
+ onChangeOrRemove(path, true);
52
+ });
53
+ return function () {
54
+ return wp.close();
55
+ };
56
+ }
@@ -72,11 +72,14 @@ export async function buildStaticStandalone(options) {
72
72
  var features = await presets.apply('features');
73
73
 
74
74
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
75
- var stories = normalizeStories(await presets.apply('stories'), {
75
+ var directories = {
76
76
  configDir: options.configDir,
77
77
  workingDir: process.cwd()
78
- });
79
- await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories, options.configDir, !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7));
78
+ };
79
+ var stories = normalizeStories(await presets.apply('stories'), directories);
80
+ await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories, _objectSpread(_objectSpread({}, directories), {}, {
81
+ storiesV2Compatibility: !(features !== null && features !== void 0 && features.breakingChangesV7) && !(features !== null && features !== void 0 && features.storyStoreV7)
82
+ }));
80
83
  }
81
84
 
82
85
  var fullOptions = _objectSpread(_objectSpread({}, options), {}, {