@storybook/angular 7.0.19 → 7.0.21

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.
@@ -6,22 +6,20 @@ import { AssetPattern, StyleElement } from '@angular-devkit/build-angular/src/bu
6
6
  export type StorybookBuilderOptions = JsonObject & {
7
7
  browserTarget?: string | null;
8
8
  tsConfig?: string;
9
- docs: boolean;
10
9
  compodoc: boolean;
11
10
  compodocArgs: string[];
12
11
  styles?: StyleElement[];
13
12
  stylePreprocessorOptions?: StylePreprocessorOptions;
14
13
  assets?: AssetPattern[];
15
- } & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'disableTelemetry'>;
14
+ } & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'disableTelemetry' | 'open' | 'docs'>;
16
15
  export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
17
16
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<JsonObject & {
18
17
  browserTarget?: string;
19
18
  tsConfig?: string;
20
- docs: boolean;
21
19
  compodoc: boolean;
22
20
  compodocArgs: string[];
23
21
  styles?: StyleElement[];
24
22
  stylePreprocessorOptions?: StylePreprocessorOptions;
25
23
  assets?: AssetPattern[];
26
- } & Pick<CLIOptions, "host" | "disableTelemetry" | "configDir" | "quiet" | "port" | "https" | "sslCa" | "sslCert" | "sslKey" | "smokeTest" | "ci">>;
24
+ } & Pick<CLIOptions, "docs" | "host" | "disableTelemetry" | "configDir" | "quiet" | "port" | "https" | "sslCa" | "sslCert" | "sslKey" | "smokeTest" | "open" | "ci">>;
27
25
  export default _default;
@@ -14,7 +14,10 @@ const error_handler_1 = require("../utils/error-handler");
14
14
  const commandBuilder = (options, context) => {
15
15
  const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
16
16
  const runCompodoc$ = options.compodoc
17
- ? (0, run_compodoc_1.runCompodoc)({ compodocArgs: options.compodocArgs, tsconfig: tsConfig }, context).pipe((0, operators_1.mapTo)({ tsConfig }))
17
+ ? (0, run_compodoc_1.runCompodoc)({
18
+ compodocArgs: [...options.compodocArgs, ...(options.quiet ? ['--silent'] : [])],
19
+ tsconfig: tsConfig,
20
+ }, context).pipe((0, operators_1.mapTo)({ tsConfig }))
18
21
  : (0, rxjs_1.of)({});
19
22
  return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
20
23
  }), (0, operators_1.map)(({ tsConfig }) => {
@@ -27,7 +30,7 @@ const commandBuilder = (options, context) => {
27
30
  });
28
31
  // eslint-disable-next-line no-param-reassign
29
32
  options.port = parseInt(`${options.port}`, 10);
30
- const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docs, host, https, port, quiet, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, assets, } = options;
33
+ const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docs, host, https, port, quiet, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, assets, open, } = options;
31
34
  const standaloneOptions = {
32
35
  packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
33
36
  ci,
@@ -50,6 +53,7 @@ const commandBuilder = (options, context) => {
50
53
  ...(assets ? { assets } : {}),
51
54
  },
52
55
  tsConfig,
56
+ open,
53
57
  };
54
58
  return standaloneOptions;
55
59
  }), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)((port) => {
@@ -56,6 +56,11 @@
56
56
  "description": "CI mode (skip interactive prompts, don't open browser).",
57
57
  "default": false
58
58
  },
59
+ "open": {
60
+ "type": "boolean",
61
+ "description": "Whether to open Storybook automatically in the browser.",
62
+ "default": true
63
+ },
59
64
  "quiet": {
60
65
  "type": "boolean",
61
66
  "description": "Suppress verbose build output.",
@@ -1,9 +1,31 @@
1
+ /* eslint-disable global-require */
1
2
  // Private angular devkit stuff
2
3
  const { generateI18nBrowserWebpackConfigFromContext, } = require('@angular-devkit/build-angular/src/utils/webpack-browser-config');
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
6
  const { default: StorybookNormalizeAngularEntryPlugin, } = require('./plugins/storybook-normalize-angular-entry-plugin');
7
+ const getAngularWebpackUtils = () => {
8
+ try {
9
+ // Angular < 16.1.0
10
+ const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
11
+ return {
12
+ getCommonConfig,
13
+ getStylesConfig,
14
+ getDevServerConfig,
15
+ getTypeScriptConfig,
16
+ };
17
+ }
18
+ catch (e) {
19
+ // Angular > 16.1.0
20
+ const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/tools/webpack/configs');
21
+ return {
22
+ getCommonConfig,
23
+ getStylesConfig,
24
+ getDevServerConfig,
25
+ getTypeScriptConfig,
26
+ };
27
+ }
28
+ };
7
29
  /**
8
30
  * Extract webpack config from angular-cli 13.x.x
9
31
  * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
@@ -16,6 +38,7 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
16
38
  /**
17
39
  * Get angular-cli Webpack config
18
40
  */
41
+ const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig } = getAngularWebpackUtils();
19
42
  const { config: cliConfig } = await generateI18nBrowserWebpackConfigFromContext({
20
43
  // Default options
21
44
  index: 'noop-index',
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.webpack = exports.runNgcc = void 0;
27
- const core_1 = require("@angular/core");
28
27
  const path = __importStar(require("path"));
29
28
  /**
30
29
  * Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23
@@ -69,9 +68,10 @@ const runNgcc = async () => {
69
68
  };
70
69
  exports.runNgcc = runNgcc;
71
70
  const webpack = async (webpackConfig, options) => {
71
+ const { VERSION } = await loadEsmModule('@angular/core');
72
72
  const framework = await options.presets.apply('framework');
73
73
  const angularOptions = (typeof framework === 'object' ? framework.options : {});
74
- const isAngular16OrNewer = parseInt(core_1.VERSION.major, 10) >= 16;
74
+ const isAngular16OrNewer = parseInt(VERSION.major, 10) >= 16;
75
75
  // Default to true, if undefined
76
76
  if (angularOptions.enableIvy === false) {
77
77
  return webpackConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "7.0.19",
3
+ "version": "7.0.21",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -36,21 +36,21 @@
36
36
  "prep": "../../../scripts/prepare/tsc.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@storybook/builder-webpack5": "7.0.19",
40
- "@storybook/cli": "7.0.19",
41
- "@storybook/client-logger": "7.0.19",
42
- "@storybook/core-client": "7.0.19",
43
- "@storybook/core-common": "7.0.19",
44
- "@storybook/core-events": "7.0.19",
45
- "@storybook/core-server": "7.0.19",
46
- "@storybook/core-webpack": "7.0.19",
47
- "@storybook/docs-tools": "7.0.19",
39
+ "@storybook/builder-webpack5": "7.0.21",
40
+ "@storybook/cli": "7.0.21",
41
+ "@storybook/client-logger": "7.0.21",
42
+ "@storybook/core-client": "7.0.21",
43
+ "@storybook/core-common": "7.0.21",
44
+ "@storybook/core-events": "7.0.21",
45
+ "@storybook/core-server": "7.0.21",
46
+ "@storybook/core-webpack": "7.0.21",
47
+ "@storybook/docs-tools": "7.0.21",
48
48
  "@storybook/global": "^5.0.0",
49
- "@storybook/manager-api": "7.0.19",
50
- "@storybook/node-logger": "7.0.19",
51
- "@storybook/preview-api": "7.0.19",
52
- "@storybook/telemetry": "7.0.19",
53
- "@storybook/types": "7.0.19",
49
+ "@storybook/manager-api": "7.0.21",
50
+ "@storybook/node-logger": "7.0.21",
51
+ "@storybook/preview-api": "7.0.21",
52
+ "@storybook/telemetry": "7.0.21",
53
+ "@storybook/types": "7.0.21",
54
54
  "@types/node": "^16.0.0",
55
55
  "@types/react": "^16.14.34",
56
56
  "@types/react-dom": "^16.9.14",
@@ -124,5 +124,5 @@
124
124
  "bundler": {
125
125
  "tsConfig": "tsconfig.build.json"
126
126
  },
127
- "gitHead": "245bae01c81d87eeadf74886167507fcea16369c"
128
- }
127
+ "gitHead": "9fb2573aa274f3f69d3358050e8df9c903e8245f"
128
+ }
@@ -0,0 +1,7 @@
1
+ import { JsonObject } from '@angular-devkit/core';
2
+ import { BuilderContext } from '@angular-devkit/architect';
3
+
4
+ export declare function getWebpackConfig(
5
+ baseConfig: any,
6
+ options: { builderOptions: JsonObject; builderContext: BuilderContext }
7
+ ): any;
@@ -0,0 +1,127 @@
1
+ /* eslint-disable global-require */
2
+ // Private angular devkit stuff
3
+ const {
4
+ generateI18nBrowserWebpackConfigFromContext,
5
+ } = require('@angular-devkit/build-angular/src/utils/webpack-browser-config');
6
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
7
+ const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');
8
+ const {
9
+ default: StorybookNormalizeAngularEntryPlugin,
10
+ } = require('./plugins/storybook-normalize-angular-entry-plugin');
11
+
12
+ const getAngularWebpackUtils = () => {
13
+ try {
14
+ // Angular < 16.1.0
15
+ const {
16
+ getCommonConfig,
17
+ getStylesConfig,
18
+ getDevServerConfig,
19
+ getTypeScriptConfig,
20
+ } = require('@angular-devkit/build-angular/src/webpack/configs');
21
+
22
+ return {
23
+ getCommonConfig,
24
+ getStylesConfig,
25
+ getDevServerConfig,
26
+ getTypeScriptConfig,
27
+ };
28
+ } catch (e) {
29
+ // Angular > 16.1.0
30
+ const {
31
+ getCommonConfig,
32
+ getStylesConfig,
33
+ getDevServerConfig,
34
+ getTypeScriptConfig,
35
+ } = require('@angular-devkit/build-angular/src/tools/webpack/configs');
36
+
37
+ return {
38
+ getCommonConfig,
39
+ getStylesConfig,
40
+ getDevServerConfig,
41
+ getTypeScriptConfig,
42
+ };
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Extract webpack config from angular-cli 13.x.x
48
+ * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
49
+ * FIXME: Try another way with TypeScript on future storybook version (7 maybe 🤞)
50
+ *
51
+ * @param {*} baseConfig Previous webpack config from storybook
52
+ * @param {*} options { builderOptions, builderContext }
53
+ */
54
+ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }) => {
55
+ /**
56
+ * Get angular-cli Webpack config
57
+ */
58
+ const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig } =
59
+ getAngularWebpackUtils();
60
+ const { config: cliConfig } = await generateI18nBrowserWebpackConfigFromContext(
61
+ {
62
+ // Default options
63
+ index: 'noop-index',
64
+ main: 'noop-main',
65
+ outputPath: 'noop-out',
66
+
67
+ // Options provided by user
68
+ ...builderOptions,
69
+
70
+ // Fixed options
71
+ optimization: false,
72
+ namedChunks: false,
73
+ progress: false,
74
+ buildOptimizer: false,
75
+ aot: false,
76
+ },
77
+ builderContext,
78
+ (wco) => [
79
+ getCommonConfig(wco),
80
+ getStylesConfig(wco),
81
+ getTypeScriptConfig ? getTypeScriptConfig(wco) : getDevServerConfig(wco),
82
+ ]
83
+ );
84
+
85
+ /**
86
+ * Merge baseConfig Webpack with angular-cli Webpack
87
+ */
88
+ const entry = [
89
+ ...baseConfig.entry,
90
+ ...(cliConfig.entry.styles ?? []),
91
+ ...(cliConfig.entry.polyfills ?? []),
92
+ ];
93
+
94
+ // Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
95
+ // because @angular-devkit/build-angular created rules have include/exclude for global style files.
96
+ const rulesExcludingStyles = filterOutStylingRules(baseConfig);
97
+ const module = {
98
+ ...baseConfig.module,
99
+ rules: [...cliConfig.module.rules, ...rulesExcludingStyles],
100
+ };
101
+
102
+ const plugins = [
103
+ ...(cliConfig.plugins ?? []),
104
+ ...baseConfig.plugins,
105
+ new StorybookNormalizeAngularEntryPlugin(),
106
+ ];
107
+
108
+ const resolve = {
109
+ ...baseConfig.resolve,
110
+ modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])),
111
+ plugins: [
112
+ new TsconfigPathsPlugin({
113
+ configFile: builderOptions.tsConfig,
114
+ mainFields: ['browser', 'module', 'main'],
115
+ }),
116
+ ],
117
+ };
118
+
119
+ return {
120
+ ...baseConfig,
121
+ entry,
122
+ module,
123
+ plugins,
124
+ resolve,
125
+ resolveLoader: cliConfig.resolveLoader,
126
+ };
127
+ };
@@ -0,0 +1,54 @@
1
+ const PLUGIN_NAME = 'storybook-normalize-angular-entry-plugin';
2
+
3
+ /**
4
+ * Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js
5
+ * transforms the original webpackOptions.entry point array into a structure like this:
6
+ *
7
+ * ```js
8
+ * {
9
+ * main: {
10
+ * import: [...]
11
+ * },
12
+ *
13
+ * styles: {
14
+ * import: [...]
15
+ * },
16
+ * }
17
+ * ```
18
+ *
19
+ * Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded.
20
+ * To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js).
21
+ */
22
+ export default class StorybookNormalizeAngularEntryPlugin {
23
+ constructor(options) {
24
+ this.options = options;
25
+ }
26
+
27
+ apply(compiler) {
28
+ compiler.hooks.environment.tap(PLUGIN_NAME, () => {
29
+ const webpackOptions = compiler.options;
30
+ const entry =
31
+ typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;
32
+
33
+ webpackOptions.entry = async () => {
34
+ const entryResult = await entry;
35
+
36
+ if (entryResult.main && entryResult.styles) {
37
+ return {
38
+ main: {
39
+ import: Array.from(
40
+ new Set([...entryResult.main.import, ...entryResult.styles.import])
41
+ ),
42
+ },
43
+ };
44
+ }
45
+
46
+ return entry;
47
+ };
48
+ });
49
+
50
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
51
+ this.compilation = compilation;
52
+ });
53
+ }
54
+ }
@@ -0,0 +1,26 @@
1
+ /* eslint-disable no-underscore-dangle, @typescript-eslint/naming-convention */
2
+
3
+ // will be provided by the webpack define plugin
4
+ declare var NODE_ENV: string | undefined;
5
+
6
+ declare var __STORYBOOK_ADDONS_CHANNEL__: any;
7
+ declare var __STORYBOOK_ADDONS_PREVIEW: any;
8
+ declare var __STORYBOOK_COMPODOC_JSON__: any;
9
+ declare var __STORYBOOK_CLIENT_API__: any;
10
+ declare var __STORYBOOK_PREVIEW__: any;
11
+ declare var __STORYBOOK_STORY_STORE__: any;
12
+ declare var CHANNEL_OPTIONS: any;
13
+ declare var DOCS_OPTIONS: any;
14
+
15
+ declare var FEATURES:
16
+ | {
17
+ storyStoreV7?: boolean;
18
+ argTypeTargetsV7?: boolean;
19
+ }
20
+ | undefined;
21
+
22
+ declare var IS_STORYBOOK: any;
23
+ declare var LOGLEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' | undefined;
24
+ declare var STORIES: any;
25
+ declare var STORYBOOK_ENV: 'angular';
26
+ declare var STORYBOOK_HOOKS_CONTEXT: any;