@storybook/core-server 6.4.0-beta.25 → 6.4.0-beta.29

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 (55) hide show
  1. package/dist/cjs/build-dev.js +1 -0
  2. package/dist/cjs/build-static.js +22 -1
  3. package/dist/cjs/cli/utils.js +21 -3
  4. package/dist/cjs/dev-server.js +4 -1
  5. package/dist/cjs/utils/StoryIndexGenerator.js +12 -6
  6. package/dist/cjs/utils/__mockdata__/src/NoMeta.stories.js +10 -0
  7. package/dist/cjs/utils/copy-all-static-files.js +33 -0
  8. package/dist/cjs/utils/get-server-channel.js +47 -0
  9. package/dist/cjs/utils/server-address.js +10 -2
  10. package/dist/cjs/utils/server-statics.js +35 -4
  11. package/dist/cjs/utils/stories-json.js +5 -11
  12. package/dist/esm/build-dev.js +2 -1
  13. package/dist/esm/build-static.js +22 -2
  14. package/dist/esm/cli/utils.js +22 -3
  15. package/dist/esm/dev-server.js +3 -1
  16. package/dist/esm/utils/StoryIndexGenerator.js +11 -6
  17. package/dist/esm/utils/__mockdata__/src/NoMeta.stories.js +3 -0
  18. package/dist/esm/utils/copy-all-static-files.js +27 -0
  19. package/dist/esm/utils/get-server-channel.js +30 -0
  20. package/dist/esm/utils/server-address.js +5 -0
  21. package/dist/esm/utils/server-statics.js +33 -4
  22. package/dist/esm/utils/stories-json.js +4 -9
  23. package/dist/modern/build-dev.js +2 -1
  24. package/dist/modern/build-static.js +22 -2
  25. package/dist/modern/cli/utils.js +22 -3
  26. package/dist/modern/dev-server.js +3 -1
  27. package/dist/modern/utils/StoryIndexGenerator.js +11 -6
  28. package/dist/modern/utils/__mockdata__/src/NoMeta.stories.js +3 -0
  29. package/dist/modern/utils/copy-all-static-files.js +27 -0
  30. package/dist/modern/utils/get-server-channel.js +30 -0
  31. package/dist/modern/utils/server-address.js +5 -0
  32. package/dist/modern/utils/server-statics.js +33 -4
  33. package/dist/modern/utils/stories-json.js +4 -9
  34. package/dist/ts3.4/cli/prod.d.ts +2 -15
  35. package/dist/ts3.4/cli/utils.d.ts +3 -5
  36. package/dist/ts3.4/utils/__mockdata__/src/NoMeta.stories.d.ts +1 -0
  37. package/dist/ts3.4/utils/copy-all-static-files.d.ts +1 -0
  38. package/dist/ts3.4/utils/get-server-channel.d.ts +9 -0
  39. package/dist/ts3.4/utils/server-address.d.ts +3 -0
  40. package/dist/ts3.4/utils/server-statics.d.ts +2 -3
  41. package/dist/ts3.4/utils/stories-json.d.ts +3 -2
  42. package/dist/ts3.9/cli/prod.d.ts +2 -15
  43. package/dist/ts3.9/cli/utils.d.ts +3 -5
  44. package/dist/ts3.9/utils/__mockdata__/src/NoMeta.stories.d.ts +1 -0
  45. package/dist/ts3.9/utils/copy-all-static-files.d.ts +1 -0
  46. package/dist/ts3.9/utils/get-server-channel.d.ts +9 -0
  47. package/dist/ts3.9/utils/server-address.d.ts +3 -0
  48. package/dist/ts3.9/utils/server-statics.d.ts +2 -3
  49. package/dist/ts3.9/utils/stories-json.d.ts +3 -2
  50. package/package.json +17 -13
  51. package/dist/cjs/utils/use-events-as-sse.js +0 -65
  52. package/dist/esm/utils/use-events-as-sse.js +0 -58
  53. package/dist/modern/utils/use-events-as-sse.js +0 -58
  54. package/dist/ts3.4/utils/use-events-as-sse.d.ts +0 -4
  55. package/dist/ts3.9/utils/use-events-as-sse.d.ts +0 -4
@@ -96,6 +96,7 @@ async function buildDevStandalone(options) {
96
96
  options.configType = 'DEVELOPMENT';
97
97
  options.configDir = _path.default.resolve(options.configDir);
98
98
  options.outputDir = options.smokeTest ? (0, _coreCommon.resolvePathInStorybookCache)('public') : _path.default.resolve(options.outputDir || (0, _coreCommon.resolvePathInStorybookCache)('public'));
99
+ options.serverChannelUrl = (0, _serverAddress.getServerChannelUrl)(port, options);
99
100
  /* eslint-enable no-param-reassign */
100
101
 
101
102
  var previewBuilder = await (0, _getPreviewBuilder.getPreviewBuilder)(options.configDir);
@@ -18,6 +18,8 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
18
18
 
19
19
  var _path = _interopRequireDefault(require("path"));
20
20
 
21
+ var _tsDedent = _interopRequireDefault(require("ts-dedent"));
22
+
21
23
  var _nodeLogger = require("@storybook/node-logger");
22
24
 
23
25
  var _coreCommon = require("@storybook/core-common");
@@ -90,13 +92,32 @@ async function buildStaticStandalone(options) {
90
92
 
91
93
  await _fsExtra.default.emptyDir(options.outputDir);
92
94
  await (0, _cpy.default)(defaultFavIcon, options.outputDir);
93
- await (0, _copyAllStaticFiles.copyAllStaticFiles)(options.staticDir, options.outputDir);
94
95
  var previewBuilder = await (0, _getPreviewBuilder.getPreviewBuilder)(options.configDir);
95
96
  var managerBuilder = await (0, _getManagerBuilder.getManagerBuilder)(options.configDir);
96
97
  var presets = (0, _coreCommon.loadAllPresets)(_objectSpread({
97
98
  corePresets: [require.resolve('./presets/common-preset'), ...managerBuilder.corePresets, ...previewBuilder.corePresets, require.resolve('./presets/babel-cache-preset')],
98
99
  overridePresets: previewBuilder.overridePresets
99
100
  }, options));
101
+ var staticDirs = await presets.apply('staticDirs');
102
+
103
+ if (staticDirs && options.staticDir) {
104
+ throw new Error((0, _tsDedent.default)`
105
+ Conflict when trying to read staticDirs:
106
+ * Storybook's configuration option: 'staticDirs'
107
+ * Storybook's CLI flag: '--staticDir' or '-s'
108
+
109
+ Choose one of them, but not both.
110
+ `);
111
+ }
112
+
113
+ if (staticDirs) {
114
+ await (0, _copyAllStaticFiles.copyAllStaticFilesRelativeToMain)(staticDirs, options.outputDir, options.configDir);
115
+ }
116
+
117
+ if (options.staticDir) {
118
+ await (0, _copyAllStaticFiles.copyAllStaticFiles)(options.staticDir, options.outputDir);
119
+ }
120
+
100
121
  var features = await presets.apply('features');
101
122
 
102
123
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
@@ -32,14 +32,32 @@ function getEnvConfig(program, configEnv) {
32
32
  });
33
33
  }
34
34
 
35
- var warnDLLsDeprecated = (0, _utilDeprecate.default)(function () {}, (0, _tsDedent.default)`
35
+ var warnDeprecatedFlag = function (message) {
36
+ return (0, _utilDeprecate.default)(function () {}, (0, _tsDedent.default)(message));
37
+ };
38
+
39
+ var warnDLLsDeprecated = warnDeprecatedFlag(`
36
40
  DLL-related CLI flags are deprecated, see:
37
41
 
38
42
  https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-dll-flags
39
43
  `);
44
+ var warnStaticDirDeprecated = warnDeprecatedFlag(`
45
+ --static-dir CLI flag is deprecated, see:
46
+
47
+ https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-static-dir-flag
48
+ `);
40
49
 
41
- function checkDeprecatedFlags(options) {
42
- if (!options.dll || options.uiDll || options.docsDll) {
50
+ function checkDeprecatedFlags({
51
+ dll: dll,
52
+ uiDll: uiDll,
53
+ docsDll: docsDll,
54
+ staticDir: staticDir
55
+ }) {
56
+ if (!dll || uiDll || docsDll) {
43
57
  warnDLLsDeprecated();
44
58
  }
59
+
60
+ if (staticDir) {
61
+ warnStaticDirDeprecated();
62
+ }
45
63
  }
@@ -26,6 +26,8 @@ var _serverStatics = require("./utils/server-statics");
26
26
 
27
27
  var _storiesJson = require("./utils/stories-json");
28
28
 
29
+ var _getServerChannel = require("./utils/get-server-channel");
30
+
29
31
  var _openInBrowser = require("./utils/open-in-browser");
30
32
 
31
33
  var _getPreviewBuilder = require("./utils/get-preview-builder");
@@ -58,6 +60,7 @@ async function storybookDevServer(options) {
58
60
  var startTime = process.hrtime();
59
61
  var app = (0, _express.default)();
60
62
  var server = await (0, _serverInit.getServer)(app, options);
63
+ var serverChannel = (0, _getServerChannel.getServerChannel)(server);
61
64
  app.use((0, _compression.default)({
62
65
  level: 1
63
66
  }));
@@ -76,7 +79,7 @@ async function storybookDevServer(options) {
76
79
  var features = await options.presets.apply('features');
77
80
 
78
81
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
79
- await (0, _storiesJson.useStoriesJson)(router, options);
82
+ await (0, _storiesJson.useStoriesJson)(router, serverChannel, options);
80
83
  }
81
84
 
82
85
  (0, _middleware.getMiddleware)(options.configDir)(router);
@@ -113,9 +113,10 @@ class StoryIndexGenerator {
113
113
  async extractStories(specifier, absolutePath) {
114
114
  var relativePath = _path.default.relative(this.options.workingDir, absolutePath);
115
115
 
116
+ var fileStories = {};
117
+ var entry = this.storyIndexEntries.get(specifier);
118
+
116
119
  try {
117
- var entry = this.storyIndexEntries.get(specifier);
118
- var fileStories = {};
119
120
  var importPath = (0, _slash.default)(relativePath[0] === '.' ? relativePath : `./${relativePath}`);
120
121
  var defaultTitle = (0, _store.autoTitleFromSpecifier)(importPath, specifier);
121
122
  var csf = (await (0, _csfTools.readCsfOrMdx)(absolutePath, {
@@ -132,13 +133,18 @@ class StoryIndexGenerator {
132
133
  importPath: importPath
133
134
  };
134
135
  });
135
- entry[absolutePath] = fileStories;
136
- return fileStories;
137
136
  } catch (err) {
138
- _nodeLogger.logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
137
+ if (err.name === 'NoMetaError') {
138
+ _nodeLogger.logger.info(`💡 Skipping ${relativePath}: ${err}`);
139
+ } else {
140
+ _nodeLogger.logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
139
141
 
140
- throw err;
142
+ throw err;
143
+ }
141
144
  }
145
+
146
+ entry[absolutePath] = fileStories;
147
+ return fileStories;
142
148
  }
143
149
 
144
150
  async sortStories(storiesList) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryOne = void 0;
7
+ // no default export
8
+ // e.g. https://github.com/storybookjs/storybook/issues/16421
9
+ var StoryOne = {};
10
+ exports.StoryOne = StoryOne;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.copyAllStaticFiles = copyAllStaticFiles;
7
+ exports.copyAllStaticFilesRelativeToMain = copyAllStaticFilesRelativeToMain;
7
8
 
8
9
  require("core-js/modules/es.promise.js");
9
10
 
@@ -15,6 +16,8 @@ var _path = _interopRequireDefault(require("path"));
15
16
 
16
17
  var _nodeLogger = require("@storybook/node-logger");
17
18
 
19
+ var _coreCommon = require("@storybook/core-common");
20
+
18
21
  var _serverStatics = require("./server-statics");
19
22
 
20
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -50,4 +53,34 @@ async function copyAllStaticFiles(staticDirs, outputDir) {
50
53
  }
51
54
  }));
52
55
  }
56
+ }
57
+
58
+ async function copyAllStaticFilesRelativeToMain(staticDirs, outputDir, configDir) {
59
+ staticDirs.forEach(async function (dir) {
60
+ var staticDirAndTarget = typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`;
61
+
62
+ var _await$parseStaticDir2 = await (0, _serverStatics.parseStaticDir)((0, _coreCommon.getDirectoryFromWorkingDir)({
63
+ configDir: configDir,
64
+ workingDir: process.cwd(),
65
+ directory: staticDirAndTarget
66
+ })),
67
+ from = _await$parseStaticDir2.staticPath,
68
+ to = _await$parseStaticDir2.targetEndpoint;
69
+
70
+ var targetPath = _path.default.join(outputDir, to);
71
+
72
+ var skipPaths = ['index.html', 'iframe.html'].map(function (f) {
73
+ return _path.default.join(targetPath, f);
74
+ });
75
+
76
+ _nodeLogger.logger.info((0, _chalk.default)`=> Copying static files: {cyan ${from}} at {cyan ${targetPath}}`);
77
+
78
+ await _fsExtra.default.copy(from, targetPath, {
79
+ dereference: true,
80
+ preserveTimestamps: true,
81
+ filter: function (_, dest) {
82
+ return !skipPaths.includes(dest);
83
+ }
84
+ });
85
+ });
53
86
  }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getServerChannel = getServerChannel;
7
+ exports.ServerChannel = void 0;
8
+
9
+ var _ws = _interopRequireWildcard(require("ws"));
10
+
11
+ var _telejson = require("telejson");
12
+
13
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
14
+
15
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
16
+
17
+ class ServerChannel {
18
+ constructor(server) {
19
+ this.webSocketServer = void 0;
20
+ this.webSocketServer = new _ws.WebSocketServer({
21
+ server: server
22
+ });
23
+ }
24
+
25
+ emit(type, args = []) {
26
+ var event = {
27
+ type: type,
28
+ args: args
29
+ };
30
+ var data = (0, _telejson.stringify)(event, {
31
+ maxDepth: 15,
32
+ allowFunction: true
33
+ });
34
+ Array.from(this.webSocketServer.clients).filter(function (c) {
35
+ return c.readyState === _ws.default.OPEN;
36
+ }).forEach(function (client) {
37
+ return client.send(data);
38
+ });
39
+ }
40
+
41
+ }
42
+
43
+ exports.ServerChannel = ServerChannel;
44
+
45
+ function getServerChannel(server) {
46
+ return new ServerChannel(server);
47
+ }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getServerAddresses = getServerAddresses;
7
- exports.getServerPort = void 0;
7
+ exports.getServerChannelUrl = exports.getServerPort = void 0;
8
8
 
9
9
  var _ip = _interopRequireDefault(require("ip"));
10
10
 
@@ -29,4 +29,12 @@ var getServerPort = function (port) {
29
29
  });
30
30
  };
31
31
 
32
- exports.getServerPort = getServerPort;
32
+ exports.getServerPort = getServerPort;
33
+
34
+ var getServerChannelUrl = function (port, {
35
+ https: https
36
+ }) {
37
+ return `${https ? 'wss' : 'ws'}://localhost:${port}/`;
38
+ };
39
+
40
+ exports.getServerChannelUrl = getServerChannelUrl;
@@ -12,6 +12,8 @@ require("core-js/modules/es.promise.js");
12
12
 
13
13
  var _nodeLogger = require("@storybook/node-logger");
14
14
 
15
+ var _coreCommon = require("@storybook/core-common");
16
+
15
17
  var _chalk = _interopRequireDefault(require("chalk"));
16
18
 
17
19
  var _express = _interopRequireDefault(require("express"));
@@ -42,14 +44,43 @@ var defaultFavIcon = require.resolve('../public/favicon.ico');
42
44
 
43
45
  async function useStatics(router, options) {
44
46
  var hasCustomFavicon = false;
47
+ var staticDirs = await options.presets.apply('staticDirs', []);
48
+
49
+ if (staticDirs && options.staticDir) {
50
+ throw new Error((0, _tsDedent.default)`
51
+ Conflict when trying to read staticDirs:
52
+ * Storybook's configuration option: 'staticDirs'
53
+ * Storybook's CLI flag: '--staticDir' or '-s'
54
+
55
+ Choose one of them, but not both.
56
+ `);
57
+ }
58
+
59
+ staticDirs.forEach(async function (dir) {
60
+ var staticDirAndTarget = typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`;
61
+
62
+ var _await$parseStaticDir = await parseStaticDir((0, _coreCommon.getDirectoryFromWorkingDir)({
63
+ configDir: options.configDir,
64
+ workingDir: process.cwd(),
65
+ directory: staticDirAndTarget
66
+ })),
67
+ from = _await$parseStaticDir.staticPath,
68
+ to = _await$parseStaticDir.targetEndpoint;
69
+
70
+ _nodeLogger.logger.info((0, _chalk.default)`=> Serving static files from {cyan ${from}} at {cyan ${to}}`);
71
+
72
+ router.use(to, _express.default.static(from, {
73
+ index: false
74
+ }));
75
+ });
45
76
 
46
77
  if (options.staticDir && options.staticDir.length > 0) {
47
78
  await Promise.all(options.staticDir.map(async function (dir) {
48
79
  try {
49
- var _await$parseStaticDir = await parseStaticDir(dir),
50
- staticDir = _await$parseStaticDir.staticDir,
51
- staticPath = _await$parseStaticDir.staticPath,
52
- targetEndpoint = _await$parseStaticDir.targetEndpoint;
80
+ var _await$parseStaticDir2 = await parseStaticDir(dir),
81
+ staticDir = _await$parseStaticDir2.staticDir,
82
+ staticPath = _await$parseStaticDir2.staticPath,
83
+ targetEndpoint = _await$parseStaticDir2.targetEndpoint;
53
84
 
54
85
  _nodeLogger.logger.info((0, _chalk.default)`=> Serving static files from {cyan ${staticDir}} at {cyan ${targetEndpoint}}`);
55
86
 
@@ -11,22 +11,19 @@ require("core-js/modules/es.promise.js");
11
11
 
12
12
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
13
 
14
- var _events = _interopRequireDefault(require("events"));
15
-
16
14
  var _coreCommon = require("@storybook/core-common");
17
15
 
16
+ var _coreEvents = _interopRequireDefault(require("@storybook/core-events"));
17
+
18
18
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
19
19
 
20
20
  var _StoryIndexGenerator = require("./StoryIndexGenerator");
21
21
 
22
22
  var _watchStorySpecifiers = require("./watch-story-specifiers");
23
23
 
24
- var _useEventsAsSse = require("./use-events-as-sse");
25
-
26
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
25
 
28
- var INVALIDATE = 'INVALIDATE';
29
- var DEBOUNCE = 50;
26
+ var DEBOUNCE = 100;
30
27
  exports.DEBOUNCE = DEBOUNCE;
31
28
 
32
29
  async function extractStoriesJson(outputFile, normalizedStories, options) {
@@ -36,7 +33,7 @@ async function extractStoriesJson(outputFile, normalizedStories, options) {
36
33
  await _fsExtra.default.writeJson(outputFile, index);
37
34
  }
38
35
 
39
- async function useStoriesJson(router, options, workingDir = process.cwd()) {
36
+ async function useStoriesJson(router, serverChannel, options, workingDir = process.cwd()) {
40
37
  var normalizedStories = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), {
41
38
  configDir: options.configDir,
42
39
  workingDir: workingDir
@@ -50,9 +47,8 @@ async function useStoriesJson(router, options, workingDir = process.cwd()) {
50
47
  // This is mainly for testing purposes.
51
48
 
52
49
  var started = false;
53
- var invalidationEmitter = new _events.default();
54
50
  var maybeInvalidate = (0, _debounce.default)(function () {
55
- return invalidationEmitter.emit(INVALIDATE);
51
+ return serverChannel.emit(_coreEvents.default.STORY_INDEX_INVALIDATED);
56
52
  }, DEBOUNCE, {
57
53
  leading: true
58
54
  });
@@ -69,10 +65,8 @@ async function useStoriesJson(router, options, workingDir = process.cwd()) {
69
65
  await generator.initialize();
70
66
  }
71
67
 
72
- var eventsAsSSE = (0, _useEventsAsSse.useEventsAsSSE)(invalidationEmitter, [INVALIDATE]);
73
68
  router.use('/stories.json', async function (req, res) {
74
69
  await ensureStarted();
75
- if (eventsAsSSE(req, res)) return;
76
70
 
77
71
  try {
78
72
  var index = await generator.getIndex();
@@ -29,7 +29,7 @@ import { getReleaseNotesData, getReleaseNotesFailedState } from './utils/release
29
29
  import { outputStats } from './utils/output-stats';
30
30
  import { outputStartupInformation } from './utils/output-startup-information';
31
31
  import { updateCheck } from './utils/update-check';
32
- import { getServerPort } from './utils/server-address';
32
+ import { getServerPort, getServerChannelUrl } from './utils/server-address';
33
33
  import { getPreviewBuilder } from './utils/get-preview-builder';
34
34
  import { getManagerBuilder } from './utils/get-manager-builder';
35
35
  export async function buildDevStandalone(options) {
@@ -70,6 +70,7 @@ export async function buildDevStandalone(options) {
70
70
  options.configType = 'DEVELOPMENT';
71
71
  options.configDir = path.resolve(options.configDir);
72
72
  options.outputDir = options.smokeTest ? resolvePathInStorybookCache('public') : path.resolve(options.outputDir || resolvePathInStorybookCache('public'));
73
+ options.serverChannelUrl = getServerChannelUrl(port, options);
73
74
  /* eslint-enable no-param-reassign */
74
75
 
75
76
  var previewBuilder = await getPreviewBuilder(options.configDir);
@@ -26,11 +26,12 @@ import chalk from 'chalk';
26
26
  import cpy from 'cpy';
27
27
  import fs from 'fs-extra';
28
28
  import path from 'path';
29
+ import dedent from 'ts-dedent';
29
30
  import { logger } from '@storybook/node-logger';
30
31
  import { loadAllPresets, cache, normalizeStories, logConfig } from '@storybook/core-common';
31
32
  import { getProdCli } from './cli';
32
33
  import { outputStats } from './utils/output-stats';
33
- import { copyAllStaticFiles } from './utils/copy-all-static-files';
34
+ import { copyAllStaticFiles, copyAllStaticFilesRelativeToMain } from './utils/copy-all-static-files';
34
35
  import { getPreviewBuilder } from './utils/get-preview-builder';
35
36
  import { getManagerBuilder } from './utils/get-manager-builder';
36
37
  import { extractStoriesJson } from './utils/stories-json';
@@ -62,13 +63,32 @@ export async function buildStaticStandalone(options) {
62
63
 
63
64
  await fs.emptyDir(options.outputDir);
64
65
  await cpy(defaultFavIcon, options.outputDir);
65
- await copyAllStaticFiles(options.staticDir, options.outputDir);
66
66
  var previewBuilder = await getPreviewBuilder(options.configDir);
67
67
  var managerBuilder = await getManagerBuilder(options.configDir);
68
68
  var presets = loadAllPresets(_objectSpread({
69
69
  corePresets: [require.resolve('./presets/common-preset'), ...managerBuilder.corePresets, ...previewBuilder.corePresets, require.resolve('./presets/babel-cache-preset')],
70
70
  overridePresets: previewBuilder.overridePresets
71
71
  }, options));
72
+ var staticDirs = await presets.apply('staticDirs');
73
+
74
+ if (staticDirs && options.staticDir) {
75
+ throw new Error(dedent`
76
+ Conflict when trying to read staticDirs:
77
+ * Storybook's configuration option: 'staticDirs'
78
+ * Storybook's CLI flag: '--staticDir' or '-s'
79
+
80
+ Choose one of them, but not both.
81
+ `);
82
+ }
83
+
84
+ if (staticDirs) {
85
+ await copyAllStaticFilesRelativeToMain(staticDirs, options.outputDir, options.configDir);
86
+ }
87
+
88
+ if (options.staticDir) {
89
+ await copyAllStaticFiles(options.staticDir, options.outputDir);
90
+ }
91
+
72
92
  var features = await presets.apply('features');
73
93
 
74
94
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
@@ -17,13 +17,32 @@ export function getEnvConfig(program, configEnv) {
17
17
  }
18
18
  });
19
19
  }
20
- var warnDLLsDeprecated = deprecate(function () {}, dedent`
20
+
21
+ var warnDeprecatedFlag = function (message) {
22
+ return deprecate(function () {}, dedent(message));
23
+ };
24
+
25
+ var warnDLLsDeprecated = warnDeprecatedFlag(`
21
26
  DLL-related CLI flags are deprecated, see:
22
27
 
23
28
  https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-dll-flags
24
29
  `);
25
- export function checkDeprecatedFlags(options) {
26
- if (!options.dll || options.uiDll || options.docsDll) {
30
+ var warnStaticDirDeprecated = warnDeprecatedFlag(`
31
+ --static-dir CLI flag is deprecated, see:
32
+
33
+ https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-static-dir-flag
34
+ `);
35
+ export function checkDeprecatedFlags({
36
+ dll: dll,
37
+ uiDll: uiDll,
38
+ docsDll: docsDll,
39
+ staticDir: staticDir
40
+ }) {
41
+ if (!dll || uiDll || docsDll) {
27
42
  warnDLLsDeprecated();
28
43
  }
44
+
45
+ if (staticDir) {
46
+ warnStaticDirDeprecated();
47
+ }
29
48
  }
@@ -20,6 +20,7 @@ import { getServerAddresses } from './utils/server-address';
20
20
  import { getServer } from './utils/server-init';
21
21
  import { useStatics } from './utils/server-statics';
22
22
  import { useStoriesJson } from './utils/stories-json';
23
+ import { getServerChannel } from './utils/get-server-channel';
23
24
  import { openInBrowser } from './utils/open-in-browser';
24
25
  import { getPreviewBuilder } from './utils/get-preview-builder';
25
26
  import { getManagerBuilder } from './utils/get-manager-builder'; // @ts-ignore
@@ -29,6 +30,7 @@ export async function storybookDevServer(options) {
29
30
  var startTime = process.hrtime();
30
31
  var app = express();
31
32
  var server = await getServer(app, options);
33
+ var serverChannel = getServerChannel(server);
32
34
  app.use(compression({
33
35
  level: 1
34
36
  }));
@@ -47,7 +49,7 @@ export async function storybookDevServer(options) {
47
49
  var features = await options.presets.apply('features');
48
50
 
49
51
  if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
50
- await useStoriesJson(router, options);
52
+ await useStoriesJson(router, serverChannel, options);
51
53
  }
52
54
 
53
55
  getMiddleware(options.configDir)(router);
@@ -91,10 +91,10 @@ export class StoryIndexGenerator {
91
91
 
92
92
  async extractStories(specifier, absolutePath) {
93
93
  var relativePath = path.relative(this.options.workingDir, absolutePath);
94
+ var fileStories = {};
95
+ var entry = this.storyIndexEntries.get(specifier);
94
96
 
95
97
  try {
96
- var entry = this.storyIndexEntries.get(specifier);
97
- var fileStories = {};
98
98
  var importPath = slash(relativePath[0] === '.' ? relativePath : `./${relativePath}`);
99
99
  var defaultTitle = autoTitleFromSpecifier(importPath, specifier);
100
100
  var csf = (await readCsfOrMdx(absolutePath, {
@@ -111,12 +111,17 @@ export class StoryIndexGenerator {
111
111
  importPath: importPath
112
112
  };
113
113
  });
114
- entry[absolutePath] = fileStories;
115
- return fileStories;
116
114
  } catch (err) {
117
- logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
118
- throw err;
115
+ if (err.name === 'NoMetaError') {
116
+ logger.info(`💡 Skipping ${relativePath}: ${err}`);
117
+ } else {
118
+ logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
119
+ throw err;
120
+ }
119
121
  }
122
+
123
+ entry[absolutePath] = fileStories;
124
+ return fileStories;
120
125
  }
121
126
 
122
127
  async sortStories(storiesList) {
@@ -0,0 +1,3 @@
1
+ // no default export
2
+ // e.g. https://github.com/storybookjs/storybook/issues/16421
3
+ export var StoryOne = {};
@@ -3,6 +3,7 @@ import chalk from 'chalk';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
5
  import { logger } from '@storybook/node-logger';
6
+ import { getDirectoryFromWorkingDir } from '@storybook/core-common';
6
7
  import { parseStaticDir } from './server-statics';
7
8
  export async function copyAllStaticFiles(staticDirs, outputDir) {
8
9
  if (staticDirs && staticDirs.length > 0) {
@@ -32,4 +33,30 @@ export async function copyAllStaticFiles(staticDirs, outputDir) {
32
33
  }
33
34
  }));
34
35
  }
36
+ }
37
+ export async function copyAllStaticFilesRelativeToMain(staticDirs, outputDir, configDir) {
38
+ staticDirs.forEach(async function (dir) {
39
+ var staticDirAndTarget = typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`;
40
+
41
+ var _await$parseStaticDir2 = await parseStaticDir(getDirectoryFromWorkingDir({
42
+ configDir: configDir,
43
+ workingDir: process.cwd(),
44
+ directory: staticDirAndTarget
45
+ })),
46
+ from = _await$parseStaticDir2.staticPath,
47
+ to = _await$parseStaticDir2.targetEndpoint;
48
+
49
+ var targetPath = path.join(outputDir, to);
50
+ var skipPaths = ['index.html', 'iframe.html'].map(function (f) {
51
+ return path.join(targetPath, f);
52
+ });
53
+ logger.info(chalk`=> Copying static files: {cyan ${from}} at {cyan ${targetPath}}`);
54
+ await fs.copy(from, targetPath, {
55
+ dereference: true,
56
+ preserveTimestamps: true,
57
+ filter: function (_, dest) {
58
+ return !skipPaths.includes(dest);
59
+ }
60
+ });
61
+ });
35
62
  }
@@ -0,0 +1,30 @@
1
+ import WebSocket, { WebSocketServer } from 'ws';
2
+ import { stringify } from 'telejson';
3
+ export class ServerChannel {
4
+ constructor(server) {
5
+ this.webSocketServer = void 0;
6
+ this.webSocketServer = new WebSocketServer({
7
+ server: server
8
+ });
9
+ }
10
+
11
+ emit(type, args = []) {
12
+ var event = {
13
+ type: type,
14
+ args: args
15
+ };
16
+ var data = stringify(event, {
17
+ maxDepth: 15,
18
+ allowFunction: true
19
+ });
20
+ Array.from(this.webSocketServer.clients).filter(function (c) {
21
+ return c.readyState === WebSocket.OPEN;
22
+ }).forEach(function (client) {
23
+ return client.send(data);
24
+ });
25
+ }
26
+
27
+ }
28
+ export function getServerChannel(server) {
29
+ return new ServerChannel(server);
30
+ }
@@ -12,4 +12,9 @@ export var getServerPort = function (port) {
12
12
  logger.error(error);
13
13
  process.exit(-1);
14
14
  });
15
+ };
16
+ export var getServerChannelUrl = function (port, {
17
+ https: https
18
+ }) {
19
+ return `${https ? 'wss' : 'ws'}://localhost:${port}/`;
15
20
  };