@storybook/builder-webpack5 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 CHANGED
@@ -197,7 +197,7 @@ var build = async function ({
197
197
  return _nodeLogger.logger.error(e.message);
198
198
  });
199
199
  compiler.close(function () {
200
- return fail(stats);
200
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
201
201
  });
202
202
  return;
203
203
  }
@@ -46,8 +46,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
46
46
  }, {});
47
47
 
48
48
  var _default = async function _default(options) {
49
- var configDir = options.configDir,
50
- babelOptions = options.babelOptions,
49
+ var babelOptions = options.babelOptions,
51
50
  _options$outputDir = options.outputDir,
52
51
  outputDir = _options$outputDir === void 0 ? _path.default.join('.', 'public') : _options$outputDir,
53
52
  quiet = options.quiet,
@@ -65,32 +64,35 @@ var _default = async function _default(options) {
65
64
  var headHtmlSnippet = await presets.apply('previewHead');
66
65
  var bodyHtmlSnippet = await presets.apply('previewBody');
67
66
  var template = await presets.apply('previewMainTemplate');
67
+ var coreOptions = await presets.apply('core');
68
68
  var babelLoader = (0, _babelLoaderPreview.createBabelLoader)(babelOptions, framework);
69
69
  var isProd = configType === 'PRODUCTION';
70
70
  var configs = [...(await presets.apply('config', [], options)), (0, _coreCommon.loadPreviewOrConfigFile)(options)].filter(Boolean);
71
71
  var entries = await presets.apply('entries', [], options);
72
+ var workingDir = process.cwd();
72
73
  var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories', [], options), {
73
74
  configDir: options.configDir,
74
- workingDir: process.cwd()
75
+ workingDir: workingDir
75
76
  });
76
77
  var virtualModuleMapping = {};
77
78
 
78
79
  if (features !== null && features !== void 0 && features.storyStoreV7) {
79
80
  var storiesFilename = 'storybook-stories.js';
80
81
 
81
- var storiesPath = _path.default.resolve(_path.default.join(configDir, storiesFilename));
82
+ var storiesPath = _path.default.resolve(_path.default.join(workingDir, storiesFilename));
82
83
 
83
84
  virtualModuleMapping[storiesPath] = (0, _coreCommon.toImportFn)(stories);
84
85
 
85
- var configEntryPath = _path.default.resolve(_path.default.join(configDir, 'storybook-config-entry.js'));
86
+ var configEntryPath = _path.default.resolve(_path.default.join(workingDir, 'storybook-config-entry.js'));
86
87
 
87
88
  virtualModuleMapping[configEntryPath] = (0, _coreCommon.handlebars)(await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
88
89
  storiesFilename: storiesFilename,
89
90
  configs: configs
90
- });
91
+ } // We need to double escape `\` for webpack. We may have some in windows paths
92
+ ).replace(/\\/g, '\\\\');
91
93
  entries.push(configEntryPath);
92
94
  } else {
93
- var frameworkInitEntry = _path.default.resolve(_path.default.join(configDir, 'storybook-init-framework-entry.js'));
95
+ var frameworkInitEntry = _path.default.resolve(_path.default.join(workingDir, 'storybook-init-framework-entry.js'));
94
96
 
95
97
  var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
96
98
  virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
@@ -110,14 +112,12 @@ var _default = async function _default(options) {
110
112
  if (stories.length > 0) {
111
113
  var storyTemplate = await (0, _coreCommon.readTemplate)(_path.default.join(__dirname, 'virtualModuleStory.template.js'));
112
114
 
113
- var _storiesFilename = _path.default.resolve(_path.default.join(configDir, `generated-stories-entry.js`));
115
+ var _storiesFilename = _path.default.resolve(_path.default.join(workingDir, `generated-stories-entry.js`));
114
116
 
115
117
  virtualModuleMapping[_storiesFilename] = (0, _coreCommon.interpolate)(storyTemplate, {
116
118
  frameworkImportPath: frameworkImportPath
117
119
  }) // Make sure we also replace quotes for this one
118
- .replace("'{{stories}}'", stories.map(function (s) {
119
- return s.glob;
120
- }).map(_coreCommon.toRequireContextString).join(','));
120
+ .replace("'{{stories}}'", stories.map(_coreCommon.toRequireContextString).join(','));
121
121
  entries.push(_storiesFilename);
122
122
  }
123
123
  }
@@ -158,10 +158,16 @@ var _default = async function _default(options) {
158
158
  options: templateOptions,
159
159
  version: packageJson.version,
160
160
  globals: {
161
+ CONFIG_TYPE: configType,
161
162
  LOGLEVEL: logLevel,
162
163
  FRAMEWORK_OPTIONS: frameworkOptions,
164
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
163
165
  FEATURES: features,
164
- STORIES: stories
166
+ STORIES: stories.map(function (specifier) {
167
+ return _objectSpread(_objectSpread({}, specifier), {}, {
168
+ importPathMatcher: specifier.importPathMatcher.source
169
+ });
170
+ })
165
171
  },
166
172
  headHtmlSnippet: headHtmlSnippet,
167
173
  bodyHtmlSnippet: bodyHtmlSnippet
@@ -14,27 +14,22 @@ const getProjectAnnotations = () =>
14
14
  {{/each}}
15
15
  ]);
16
16
 
17
- const fetchStoryIndex = async () => {
18
- const result = await fetch('./stories.json');
19
- return result.json();
20
- }
21
-
22
17
  const channel = createChannel({ page: 'preview' });
23
18
  addons.setChannel(channel);
24
19
 
25
- const preview = new PreviewWeb({ importFn, fetchStoryIndex });
20
+ const preview = new PreviewWeb();
26
21
 
27
22
  window.__STORYBOOK_PREVIEW__ = preview;
28
23
  window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
29
24
  window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
30
25
  window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
31
26
 
32
- preview.initialize({ getProjectAnnotations });
27
+ preview.initialize({ importFn, getProjectAnnotations });
33
28
 
34
29
  if (module.hot) {
35
30
  module.hot.accept('./{{storiesFilename}}', () => {
36
31
  // importFn has changed so we need to patch the new one in
37
- preview.onImportFnChanged({ importFn });
32
+ preview.onStoriesChanged({ importFn });
38
33
  });
39
34
 
40
35
  module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
package/dist/esm/index.js CHANGED
@@ -160,7 +160,7 @@ export var build = async function ({
160
160
  return logger.error(e.message);
161
161
  });
162
162
  compiler.close(function () {
163
- return fail(stats);
163
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
164
164
  });
165
165
  return;
166
166
  }
@@ -24,8 +24,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
24
24
  });
25
25
  }, {});
26
26
  export default (async function (options) {
27
- var configDir = options.configDir,
28
- babelOptions = options.babelOptions,
27
+ var babelOptions = options.babelOptions,
29
28
  _options$outputDir = options.outputDir,
30
29
  outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
31
30
  quiet = options.quiet,
@@ -43,28 +42,31 @@ export default (async function (options) {
43
42
  var headHtmlSnippet = await presets.apply('previewHead');
44
43
  var bodyHtmlSnippet = await presets.apply('previewBody');
45
44
  var template = await presets.apply('previewMainTemplate');
45
+ var coreOptions = await presets.apply('core');
46
46
  var babelLoader = createBabelLoader(babelOptions, framework);
47
47
  var isProd = configType === 'PRODUCTION';
48
48
  var configs = [...(await presets.apply('config', [], options)), loadPreviewOrConfigFile(options)].filter(Boolean);
49
49
  var entries = await presets.apply('entries', [], options);
50
+ var workingDir = process.cwd();
50
51
  var stories = normalizeStories(await presets.apply('stories', [], options), {
51
52
  configDir: options.configDir,
52
- workingDir: process.cwd()
53
+ workingDir: workingDir
53
54
  });
54
55
  var virtualModuleMapping = {};
55
56
 
56
57
  if (features !== null && features !== void 0 && features.storyStoreV7) {
57
58
  var storiesFilename = 'storybook-stories.js';
58
- var storiesPath = path.resolve(path.join(configDir, storiesFilename));
59
+ var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
59
60
  virtualModuleMapping[storiesPath] = toImportFn(stories);
60
- var configEntryPath = path.resolve(path.join(configDir, 'storybook-config-entry.js'));
61
+ var configEntryPath = path.resolve(path.join(workingDir, 'storybook-config-entry.js'));
61
62
  virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(path.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
62
63
  storiesFilename: storiesFilename,
63
64
  configs: configs
64
- });
65
+ } // We need to double escape `\` for webpack. We may have some in windows paths
66
+ ).replace(/\\/g, '\\\\');
65
67
  entries.push(configEntryPath);
66
68
  } else {
67
- var frameworkInitEntry = path.resolve(path.join(configDir, 'storybook-init-framework-entry.js'));
69
+ var frameworkInitEntry = path.resolve(path.join(workingDir, 'storybook-init-framework-entry.js'));
68
70
  var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
69
71
  virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
70
72
  entries.push(frameworkInitEntry);
@@ -83,14 +85,12 @@ export default (async function (options) {
83
85
  if (stories.length > 0) {
84
86
  var storyTemplate = await readTemplate(path.join(__dirname, 'virtualModuleStory.template.js'));
85
87
 
86
- var _storiesFilename = path.resolve(path.join(configDir, `generated-stories-entry.js`));
88
+ var _storiesFilename = path.resolve(path.join(workingDir, `generated-stories-entry.js`));
87
89
 
88
90
  virtualModuleMapping[_storiesFilename] = interpolate(storyTemplate, {
89
91
  frameworkImportPath: frameworkImportPath
90
92
  }) // Make sure we also replace quotes for this one
91
- .replace("'{{stories}}'", stories.map(function (s) {
92
- return s.glob;
93
- }).map(toRequireContextString).join(','));
93
+ .replace("'{{stories}}'", stories.map(toRequireContextString).join(','));
94
94
  entries.push(_storiesFilename);
95
95
  }
96
96
  }
@@ -131,10 +131,16 @@ export default (async function (options) {
131
131
  options: templateOptions,
132
132
  version: packageJson.version,
133
133
  globals: {
134
+ CONFIG_TYPE: configType,
134
135
  LOGLEVEL: logLevel,
135
136
  FRAMEWORK_OPTIONS: frameworkOptions,
137
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
136
138
  FEATURES: features,
137
- STORIES: stories
139
+ STORIES: stories.map(function (specifier) {
140
+ return _objectSpread(_objectSpread({}, specifier), {}, {
141
+ importPathMatcher: specifier.importPathMatcher.source
142
+ });
143
+ })
138
144
  },
139
145
  headHtmlSnippet: headHtmlSnippet,
140
146
  bodyHtmlSnippet: bodyHtmlSnippet
@@ -14,27 +14,22 @@ const getProjectAnnotations = () =>
14
14
  {{/each}}
15
15
  ]);
16
16
 
17
- const fetchStoryIndex = async () => {
18
- const result = await fetch('./stories.json');
19
- return result.json();
20
- }
21
-
22
17
  const channel = createChannel({ page: 'preview' });
23
18
  addons.setChannel(channel);
24
19
 
25
- const preview = new PreviewWeb({ importFn, fetchStoryIndex });
20
+ const preview = new PreviewWeb();
26
21
 
27
22
  window.__STORYBOOK_PREVIEW__ = preview;
28
23
  window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
29
24
  window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
30
25
  window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
31
26
 
32
- preview.initialize({ getProjectAnnotations });
27
+ preview.initialize({ importFn, getProjectAnnotations });
33
28
 
34
29
  if (module.hot) {
35
30
  module.hot.accept('./{{storiesFilename}}', () => {
36
31
  // importFn has changed so we need to patch the new one in
37
- preview.onImportFnChanged({ importFn });
32
+ preview.onStoriesChanged({ importFn });
38
33
  });
39
34
 
40
35
  module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
@@ -160,7 +160,7 @@ export var build = async function ({
160
160
  return logger.error(e.message);
161
161
  });
162
162
  compiler.close(function () {
163
- return fail(stats);
163
+ return options.debugWebpack ? fail(stats) : fail(new Error('=> Webpack failed, learn more with --debug-webpack'));
164
164
  });
165
165
  return;
166
166
  }
@@ -24,8 +24,7 @@ var storybookPaths = ['addons', 'api', 'channels', 'channel-postmessage', 'compo
24
24
  });
25
25
  }, {});
26
26
  export default (async function (options) {
27
- var configDir = options.configDir,
28
- babelOptions = options.babelOptions,
27
+ var babelOptions = options.babelOptions,
29
28
  _options$outputDir = options.outputDir,
30
29
  outputDir = _options$outputDir === void 0 ? path.join('.', 'public') : _options$outputDir,
31
30
  quiet = options.quiet,
@@ -43,28 +42,31 @@ export default (async function (options) {
43
42
  var headHtmlSnippet = await presets.apply('previewHead');
44
43
  var bodyHtmlSnippet = await presets.apply('previewBody');
45
44
  var template = await presets.apply('previewMainTemplate');
45
+ var coreOptions = await presets.apply('core');
46
46
  var babelLoader = createBabelLoader(babelOptions, framework);
47
47
  var isProd = configType === 'PRODUCTION';
48
48
  var configs = [...(await presets.apply('config', [], options)), loadPreviewOrConfigFile(options)].filter(Boolean);
49
49
  var entries = await presets.apply('entries', [], options);
50
+ var workingDir = process.cwd();
50
51
  var stories = normalizeStories(await presets.apply('stories', [], options), {
51
52
  configDir: options.configDir,
52
- workingDir: process.cwd()
53
+ workingDir: workingDir
53
54
  });
54
55
  var virtualModuleMapping = {};
55
56
 
56
57
  if (features !== null && features !== void 0 && features.storyStoreV7) {
57
58
  var storiesFilename = 'storybook-stories.js';
58
- var storiesPath = path.resolve(path.join(configDir, storiesFilename));
59
+ var storiesPath = path.resolve(path.join(workingDir, storiesFilename));
59
60
  virtualModuleMapping[storiesPath] = toImportFn(stories);
60
- var configEntryPath = path.resolve(path.join(configDir, 'storybook-config-entry.js'));
61
+ var configEntryPath = path.resolve(path.join(workingDir, 'storybook-config-entry.js'));
61
62
  virtualModuleMapping[configEntryPath] = handlebars(await readTemplate(path.join(__dirname, 'virtualModuleModernEntry.js.handlebars')), {
62
63
  storiesFilename: storiesFilename,
63
64
  configs: configs
64
- });
65
+ } // We need to double escape `\` for webpack. We may have some in windows paths
66
+ ).replace(/\\/g, '\\\\');
65
67
  entries.push(configEntryPath);
66
68
  } else {
67
- var frameworkInitEntry = path.resolve(path.join(configDir, 'storybook-init-framework-entry.js'));
69
+ var frameworkInitEntry = path.resolve(path.join(workingDir, 'storybook-init-framework-entry.js'));
68
70
  var frameworkImportPath = frameworkPath || `@storybook/${framework}`;
69
71
  virtualModuleMapping[frameworkInitEntry] = `import '${frameworkImportPath}';`;
70
72
  entries.push(frameworkInitEntry);
@@ -83,14 +85,12 @@ export default (async function (options) {
83
85
  if (stories.length > 0) {
84
86
  var storyTemplate = await readTemplate(path.join(__dirname, 'virtualModuleStory.template.js'));
85
87
 
86
- var _storiesFilename = path.resolve(path.join(configDir, `generated-stories-entry.js`));
88
+ var _storiesFilename = path.resolve(path.join(workingDir, `generated-stories-entry.js`));
87
89
 
88
90
  virtualModuleMapping[_storiesFilename] = interpolate(storyTemplate, {
89
91
  frameworkImportPath: frameworkImportPath
90
92
  }) // Make sure we also replace quotes for this one
91
- .replace("'{{stories}}'", stories.map(function (s) {
92
- return s.glob;
93
- }).map(toRequireContextString).join(','));
93
+ .replace("'{{stories}}'", stories.map(toRequireContextString).join(','));
94
94
  entries.push(_storiesFilename);
95
95
  }
96
96
  }
@@ -131,10 +131,16 @@ export default (async function (options) {
131
131
  options: templateOptions,
132
132
  version: packageJson.version,
133
133
  globals: {
134
+ CONFIG_TYPE: configType,
134
135
  LOGLEVEL: logLevel,
135
136
  FRAMEWORK_OPTIONS: frameworkOptions,
137
+ CHANNEL_OPTIONS: coreOptions === null || coreOptions === void 0 ? void 0 : coreOptions.channelOptions,
136
138
  FEATURES: features,
137
- STORIES: stories
139
+ STORIES: stories.map(function (specifier) {
140
+ return _objectSpread(_objectSpread({}, specifier), {}, {
141
+ importPathMatcher: specifier.importPathMatcher.source
142
+ });
143
+ })
138
144
  },
139
145
  headHtmlSnippet: headHtmlSnippet,
140
146
  bodyHtmlSnippet: bodyHtmlSnippet
@@ -14,27 +14,22 @@ const getProjectAnnotations = () =>
14
14
  {{/each}}
15
15
  ]);
16
16
 
17
- const fetchStoryIndex = async () => {
18
- const result = await fetch('./stories.json');
19
- return result.json();
20
- }
21
-
22
17
  const channel = createChannel({ page: 'preview' });
23
18
  addons.setChannel(channel);
24
19
 
25
- const preview = new PreviewWeb({ importFn, fetchStoryIndex });
20
+ const preview = new PreviewWeb();
26
21
 
27
22
  window.__STORYBOOK_PREVIEW__ = preview;
28
23
  window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
29
24
  window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
30
25
  window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
31
26
 
32
- preview.initialize({ getProjectAnnotations });
27
+ preview.initialize({ importFn, getProjectAnnotations });
33
28
 
34
29
  if (module.hot) {
35
30
  module.hot.accept('./{{storiesFilename}}', () => {
36
31
  // importFn has changed so we need to patch the new one in
37
- preview.onImportFnChanged({ importFn });
32
+ preview.onStoriesChanged({ importFn });
38
33
  });
39
34
 
40
35
  module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-webpack5",
3
- "version": "6.4.0-beta.2",
3
+ "version": "6.4.0-beta.20",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -60,21 +60,21 @@
60
60
  "@babel/preset-env": "^7.12.11",
61
61
  "@babel/preset-react": "^7.12.10",
62
62
  "@babel/preset-typescript": "^7.12.7",
63
- "@storybook/addons": "6.4.0-beta.2",
64
- "@storybook/api": "6.4.0-beta.2",
65
- "@storybook/channel-postmessage": "6.4.0-beta.2",
66
- "@storybook/channels": "6.4.0-beta.2",
67
- "@storybook/client-api": "6.4.0-beta.2",
68
- "@storybook/client-logger": "6.4.0-beta.2",
69
- "@storybook/components": "6.4.0-beta.2",
70
- "@storybook/core-common": "6.4.0-beta.2",
71
- "@storybook/core-events": "6.4.0-beta.2",
72
- "@storybook/node-logger": "6.4.0-beta.2",
73
- "@storybook/preview-web": "6.4.0-beta.2",
74
- "@storybook/router": "6.4.0-beta.2",
63
+ "@storybook/addons": "6.4.0-beta.20",
64
+ "@storybook/api": "6.4.0-beta.20",
65
+ "@storybook/channel-postmessage": "6.4.0-beta.20",
66
+ "@storybook/channels": "6.4.0-beta.20",
67
+ "@storybook/client-api": "6.4.0-beta.20",
68
+ "@storybook/client-logger": "6.4.0-beta.20",
69
+ "@storybook/components": "6.4.0-beta.20",
70
+ "@storybook/core-common": "6.4.0-beta.20",
71
+ "@storybook/core-events": "6.4.0-beta.20",
72
+ "@storybook/node-logger": "6.4.0-beta.20",
73
+ "@storybook/preview-web": "6.4.0-beta.20",
74
+ "@storybook/router": "6.4.0-beta.20",
75
75
  "@storybook/semver": "^7.3.2",
76
- "@storybook/store": "6.4.0-beta.2",
77
- "@storybook/theming": "6.4.0-beta.2",
76
+ "@storybook/store": "6.4.0-beta.20",
77
+ "@storybook/theming": "6.4.0-beta.20",
78
78
  "@types/node": "^14.0.10",
79
79
  "babel-loader": "^8.0.0",
80
80
  "babel-plugin-macros": "^3.0.1",
@@ -117,6 +117,6 @@
117
117
  "publishConfig": {
118
118
  "access": "public"
119
119
  },
120
- "gitHead": "3358e1e90c4e46dfd28e7ab822d5d20579463186",
120
+ "gitHead": "1a9315fd39f7e4abcdf3eb839dc29aedce346e01",
121
121
  "sbmodern": "dist/modern/index.js"
122
122
  }