@storybook/angular 7.0.0-alpha.52 → 7.0.0-alpha.54

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.
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocsRenderer = void 0;
4
- const addons_1 = require("@storybook/addons");
4
+ const preview_api_1 = require("@storybook/preview-api");
5
5
  const core_events_1 = require("@storybook/core-events");
6
6
  const AbstractRenderer_1 = require("./AbstractRenderer");
7
7
  class DocsRenderer extends AbstractRenderer_1.AbstractRenderer {
8
8
  async render(options) {
9
- const channel = addons_1.addons.getChannel();
9
+ const channel = preview_api_1.addons.getChannel();
10
10
  /**
11
11
  * Destroy and recreate the PlatformBrowserDynamic of angular
12
12
  * For several stories to be rendered in the same docs we should
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decorateStory = void 0;
4
- const store_1 = require("@storybook/store");
4
+ const preview_api_1 = require("@storybook/preview-api");
5
5
  const ComputesTemplateFromComponent_1 = require("./angular-beta/ComputesTemplateFromComponent");
6
6
  function decorateStory(mainStoryFn, decorators) {
7
7
  const returnDecorators = [cleanArgsDecorator, ...decorators].reduce((previousStoryFn, decorator) => (context) => {
8
8
  const decoratedStory = decorator((update) => {
9
9
  return previousStoryFn({
10
10
  ...context,
11
- ...(0, store_1.sanitizeStoryContextUpdate)(update),
11
+ ...(0, preview_api_1.sanitizeStoryContextUpdate)(update),
12
12
  });
13
13
  }, context);
14
14
  return decoratedStory;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sourceDecorator = exports.skipSourceRender = void 0;
4
- const addons_1 = require("@storybook/addons");
4
+ const preview_api_1 = require("@storybook/preview-api");
5
5
  const docs_tools_1 = require("@storybook/docs-tools");
6
6
  const renderer_1 = require("../../renderer");
7
7
  const skipSourceRender = (context) => {
@@ -25,11 +25,11 @@ const sourceDecorator = (storyFn, context) => {
25
25
  if ((0, exports.skipSourceRender)(context)) {
26
26
  return story;
27
27
  }
28
- const channel = addons_1.addons.getChannel();
28
+ const channel = preview_api_1.addons.getChannel();
29
29
  const { props, template, userDefinedTemplate } = story;
30
30
  const { component, argTypes } = context;
31
31
  let toEmit;
32
- (0, addons_1.useEffect)(() => {
32
+ (0, preview_api_1.useEffect)(() => {
33
33
  if (toEmit) {
34
34
  channel.emit(docs_tools_1.SNIPPET_RENDERED, context.id, toEmit, 'angular');
35
35
  }
@@ -3,6 +3,7 @@ const { generateI18nBrowserWebpackConfigFromContext, } = require('@angular-devki
3
3
  const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
4
4
  const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
5
5
  const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');
6
+ const { default: StorybookNormalizeAngularEntryPlugin, } = require('./plugins/storybook-normalize-angular-entry-plugin');
6
7
  /**
7
8
  * Extract webpack config from angular-cli 13.x.x
8
9
  * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
@@ -48,7 +49,11 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
48
49
  ...baseConfig.module,
49
50
  rules: [...cliConfig.module.rules, ...rulesExcludingStyles],
50
51
  };
51
- const plugins = [...(cliConfig.plugins ?? []), ...baseConfig.plugins];
52
+ const plugins = [
53
+ ...(cliConfig.plugins ?? []),
54
+ ...baseConfig.plugins,
55
+ new StorybookNormalizeAngularEntryPlugin(),
56
+ ];
52
57
  const resolve = {
53
58
  ...baseConfig.resolve,
54
59
  modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])),
@@ -33,8 +33,8 @@ const find_up_1 = require("find-up");
33
33
  const semver_1 = __importDefault(require("semver"));
34
34
  const ts_dedent_1 = require("ts-dedent");
35
35
  const core_1 = require("@angular-devkit/core");
36
+ const angular_cli_webpack_1 = require("./angular-cli-webpack");
36
37
  const module_is_available_1 = require("./utils/module-is-available");
37
- const angular_cli_webpack_13_x_x_1 = require("./angular-cli-webpack-13.x.x");
38
38
  const angular_read_workspace_1 = require("./angular-read-workspace");
39
39
  async function webpackFinal(baseConfig, options) {
40
40
  if (!(0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular')) {
@@ -53,7 +53,7 @@ async function webpackFinal(baseConfig, options) {
53
53
  const builderContext = getBuilderContext(_options);
54
54
  const builderOptions = await getBuilderOptions(_options, builderContext);
55
55
  const legacyDefaultOptions = await getLegacyDefaultBuildOptions(_options);
56
- return (0, angular_cli_webpack_13_x_x_1.getWebpackConfig)(_baseConfig, {
56
+ return (0, angular_cli_webpack_1.getWebpackConfig)(_baseConfig, {
57
57
  builderOptions: {
58
58
  watch: options.configType === 'DEVELOPMENT',
59
59
  ...legacyDefaultOptions,
@@ -679,8 +679,8 @@ const newWebpackConfiguration = (transformer = (c) => c) => {
679
679
  modules: ['node_modules'],
680
680
  mainFields: ['browser', 'main'],
681
681
  alias: {
682
- '@storybook/addons': '/Users/joe/storybook/lib/addons',
683
- '@storybook/api': '/Users/joe/storybook/lib/api',
682
+ '@storybook/preview-api': '/Users/joe/storybook/lib/addons',
683
+ '@storybook/manager-api': '/Users/joe/storybook/lib/api',
684
684
  '@storybook/channels': '/Users/joe/storybook/lib/channels',
685
685
  '@storybook/channel-postmessage': '/Users/joe/storybook/lib/channel-postmessage',
686
686
  '@storybook/components': '/Users/joe/storybook/ui/components',
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js
3
+ * transforms the original webpackOptions.entry point array into a structure like this:
4
+ *
5
+ * ```js
6
+ * {
7
+ * main: {
8
+ * import: [...]
9
+ * },
10
+ *
11
+ * styles: {
12
+ * import: [...]
13
+ * },
14
+ * }
15
+ * ```
16
+ *
17
+ * Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded.
18
+ * To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js).
19
+ */
20
+ export default class StorybookNormalizeAngularEntryPlugin {
21
+ constructor(options: any);
22
+ options: any;
23
+ apply(compiler: any): void;
24
+ compilation: any;
25
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PLUGIN_NAME = 'storybook-normalize-angular-entry-plugin';
4
+ /**
5
+ * Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js
6
+ * transforms the original webpackOptions.entry point array into a structure like this:
7
+ *
8
+ * ```js
9
+ * {
10
+ * main: {
11
+ * import: [...]
12
+ * },
13
+ *
14
+ * styles: {
15
+ * import: [...]
16
+ * },
17
+ * }
18
+ * ```
19
+ *
20
+ * Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded.
21
+ * To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js).
22
+ */
23
+ class StorybookNormalizeAngularEntryPlugin {
24
+ constructor(options) {
25
+ this.options = options;
26
+ }
27
+ apply(compiler) {
28
+ const webpackOptions = compiler.options;
29
+ const entry = typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;
30
+ webpackOptions.entry = async () => {
31
+ const entryResult = await entry;
32
+ if (entryResult.main && entryResult.styles) {
33
+ return {
34
+ main: {
35
+ import: Array.from(new Set([...entryResult.main.import, ...entryResult.styles.import])),
36
+ },
37
+ };
38
+ }
39
+ return entry;
40
+ };
41
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
42
+ this.compilation = compilation;
43
+ });
44
+ }
45
+ }
46
+ exports.default = StorybookNormalizeAngularEntryPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "7.0.0-alpha.52",
3
+ "version": "7.0.0-alpha.54",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -34,20 +34,19 @@
34
34
  "prep": "rimraf dist && ../../../scripts/node_modules/.bin/tsc --project tsconfig.build.json && echo \"Preventing passing flags to tsc\""
35
35
  },
36
36
  "dependencies": {
37
- "@storybook/addons": "7.0.0-alpha.52",
38
- "@storybook/api": "7.0.0-alpha.52",
39
- "@storybook/builder-webpack5": "7.0.0-alpha.52",
40
- "@storybook/client-logger": "7.0.0-alpha.52",
41
- "@storybook/core-client": "7.0.0-alpha.52",
42
- "@storybook/core-common": "7.0.0-alpha.52",
43
- "@storybook/core-events": "7.0.0-alpha.52",
44
- "@storybook/core-server": "7.0.0-alpha.52",
45
- "@storybook/core-webpack": "7.0.0-alpha.52",
46
- "@storybook/docs-tools": "7.0.0-alpha.52",
47
- "@storybook/node-logger": "7.0.0-alpha.52",
48
- "@storybook/store": "7.0.0-alpha.52",
49
- "@storybook/types": "7.0.0-alpha.52",
50
- "@types/node": "^16.0.0 || ^18.0.0",
37
+ "@storybook/builder-webpack5": "7.0.0-alpha.54",
38
+ "@storybook/client-logger": "7.0.0-alpha.54",
39
+ "@storybook/core-client": "7.0.0-alpha.54",
40
+ "@storybook/core-common": "7.0.0-alpha.54",
41
+ "@storybook/core-events": "7.0.0-alpha.54",
42
+ "@storybook/core-server": "7.0.0-alpha.54",
43
+ "@storybook/core-webpack": "7.0.0-alpha.54",
44
+ "@storybook/docs-tools": "7.0.0-alpha.54",
45
+ "@storybook/manager-api": "7.0.0-alpha.54",
46
+ "@storybook/node-logger": "7.0.0-alpha.54",
47
+ "@storybook/preview-api": "7.0.0-alpha.54",
48
+ "@storybook/types": "7.0.0-alpha.54",
49
+ "@types/node": "^16.0.0",
51
50
  "@types/react": "^16.14.34",
52
51
  "@types/react-dom": "^16.9.14",
53
52
  "@types/semver": "^7.3.4",
@@ -123,5 +122,5 @@
123
122
  "access": "public"
124
123
  },
125
124
  "builders": "dist/builders/builders.json",
126
- "gitHead": "d2494e3f51ce0f55bcb1ef693a6477c669fbe666"
125
+ "gitHead": "91177d4e27daec556a24ae6223c3cbe17a998d9b"
127
126
  }