@storybook/angular 6.4.0-rc.0 → 6.4.0-rc.1

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 (27) hide show
  1. package/dist/ts3.4/builders/build-storybook/index.d.ts +1 -1
  2. package/dist/ts3.4/builders/start-storybook/index.d.ts +1 -1
  3. package/dist/ts3.4/server/angular-cli-webpack-12.2.x.d.ts +1 -0
  4. package/dist/ts3.4/server/angular-cli-webpack-13.x.x.d.ts +1 -0
  5. package/dist/ts3.4/server/angular-cli-webpack-older.d.ts +72 -0
  6. package/dist/ts3.4/server/framework-preset-angular-cli.d.ts +2 -72
  7. package/dist/ts3.4/server/framework-preset-angular-ivy.d.ts +3 -3
  8. package/dist/ts3.4/server/options.d.ts +9 -1
  9. package/dist/ts3.9/builders/build-storybook/index.d.ts +1 -1
  10. package/dist/ts3.9/builders/build-storybook/index.js +2 -1
  11. package/dist/ts3.9/builders/build-storybook/schema.json +0 -7
  12. package/dist/ts3.9/builders/start-storybook/index.d.ts +1 -1
  13. package/dist/ts3.9/builders/start-storybook/index.js +2 -1
  14. package/dist/ts3.9/builders/start-storybook/schema.json +1 -16
  15. package/dist/ts3.9/server/angular-cli-webpack-12.2.x.d.ts +1 -0
  16. package/dist/ts3.9/server/angular-cli-webpack-12.2.x.js +93 -0
  17. package/dist/ts3.9/server/angular-cli-webpack-13.x.x.d.ts +1 -0
  18. package/dist/ts3.9/server/angular-cli-webpack-13.x.x.js +93 -0
  19. package/dist/ts3.9/server/angular-cli-webpack-older.d.ts +72 -0
  20. package/dist/ts3.9/server/angular-cli-webpack-older.js +156 -0
  21. package/dist/ts3.9/server/framework-preset-angular-cli.d.ts +2 -72
  22. package/dist/ts3.9/server/framework-preset-angular-cli.js +123 -89
  23. package/dist/ts3.9/server/framework-preset-angular-ivy.d.ts +3 -3
  24. package/dist/ts3.9/server/framework-preset-angular-ivy.js +45 -10
  25. package/dist/ts3.9/server/options.d.ts +9 -1
  26. package/package.json +11 -9
  27. package/standalone.d.ts +4 -0
@@ -6,7 +6,7 @@ export declare type StorybookBuilderOptions = JsonObject & {
6
6
  tsConfig?: string;
7
7
  compodoc: boolean;
8
8
  compodocArgs: string[];
9
- } & Pick<CLIOptions, 'staticDir' | 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'docs'>;
9
+ } & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'docs'>;
10
10
  export declare type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
11
11
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<StorybookBuilderOptions>;
12
12
  export default _default;
@@ -6,7 +6,7 @@ export declare type StorybookBuilderOptions = JsonObject & {
6
6
  tsConfig?: string;
7
7
  compodoc: boolean;
8
8
  compodocArgs: string[];
9
- } & Pick<CLIOptions, 'port' | 'host' | 'staticDir' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'docs'>;
9
+ } & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'docs'>;
10
10
  export declare type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
11
11
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<StorybookBuilderOptions>;
12
12
  export default _default;
@@ -0,0 +1 @@
1
+ export function getWebpackConfig(baseConfig: any, { builderOptions, builderContext }: any): Promise<any>;
@@ -0,0 +1 @@
1
+ export function getWebpackConfig(baseConfig: any, { builderOptions, builderContext }: any): Promise<any>;
@@ -0,0 +1,72 @@
1
+ import webpack from 'webpack';
2
+ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
3
+ import { PresetOptions } from './options';
4
+ /**
5
+ * Old way currently support version lower than 12.2.x
6
+ */
7
+ export declare function getWebpackConfig(baseConfig: webpack.Configuration, options: PresetOptions): Promise<webpack.Configuration | {
8
+ entry: any[];
9
+ module: {
10
+ rules: webpack.RuleSetRule[];
11
+ noParse?: RegExp | RegExp[] | ((content: string) => boolean);
12
+ unknownContextRequest?: string;
13
+ unknownContextRecursive?: boolean;
14
+ unknownContextRegExp?: RegExp;
15
+ unknownContextCritical?: boolean;
16
+ exprContextRequest?: string;
17
+ exprContextRegExp?: RegExp;
18
+ exprContextRecursive?: boolean;
19
+ exprContextCritical?: boolean;
20
+ wrappedContextRegExp?: RegExp;
21
+ wrappedContextRecursive?: boolean;
22
+ wrappedContextCritical?: boolean;
23
+ strictExportPresence?: boolean;
24
+ };
25
+ plugins: webpack.Plugin[];
26
+ resolve: {
27
+ modules: string[];
28
+ plugins: TsconfigPathsPlugin[];
29
+ descriptionFiles?: string[];
30
+ mainFields?: string[] | string[][];
31
+ aliasFields?: string[] | string[][];
32
+ mainFiles?: string[];
33
+ extensions?: string[];
34
+ enforceExtension?: boolean;
35
+ alias?: {
36
+ [key: string]: string;
37
+ };
38
+ unsafeCache?: boolean | {};
39
+ cachePredicate?(data: {
40
+ path: string;
41
+ request: string;
42
+ }): boolean;
43
+ symlinks?: boolean;
44
+ cacheWithContext?: boolean;
45
+ roots?: string[];
46
+ };
47
+ resolveLoader: webpack.ResolveLoader;
48
+ mode?: "development" | "production" | "none";
49
+ name?: string;
50
+ context?: string;
51
+ devtool?: webpack.Options.Devtool;
52
+ output?: webpack.Output;
53
+ externals?: string | RegExp | webpack.ExternalsObjectElement | webpack.ExternalsFunctionElement | webpack.ExternalsElement[];
54
+ target?: "node" | "web" | "webworker" | "async-node" | "node-webkit" | "atom" | "electron" | "electron-renderer" | "electron-preload" | "electron-main" | ((compiler?: any) => void);
55
+ bail?: boolean;
56
+ profile?: boolean;
57
+ cache?: boolean | object;
58
+ watch?: boolean;
59
+ watchOptions?: webpack.ICompiler.WatchOptions;
60
+ node?: false | webpack.Node;
61
+ amd?: {
62
+ [moduleName: string]: boolean;
63
+ };
64
+ recordsPath?: string;
65
+ recordsInputPath?: string;
66
+ recordsOutputPath?: string;
67
+ stats?: webpack.Stats.ToStringOptions;
68
+ performance?: false | webpack.Options.Performance;
69
+ parallelism?: number;
70
+ optimization?: webpack.Options.Optimization;
71
+ devServer?: import("webpack-dev-server").Configuration;
72
+ }>;
@@ -1,73 +1,3 @@
1
1
  import webpack from 'webpack';
2
- import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
3
- import { Options as CoreOptions } from '@storybook/core-common';
4
- export declare type Options = CoreOptions & {
5
- angularBrowserTarget?: string;
6
- tsConfig?: string;
7
- };
8
- export declare function webpackFinal(baseConfig: webpack.Configuration, options: Options): Promise<webpack.Configuration | {
9
- entry: any[];
10
- module: {
11
- rules: webpack.RuleSetRule[];
12
- noParse?: RegExp | RegExp[] | ((content: string) => boolean);
13
- unknownContextRequest?: string;
14
- unknownContextRecursive?: boolean;
15
- unknownContextRegExp?: RegExp;
16
- unknownContextCritical?: boolean;
17
- exprContextRequest?: string;
18
- exprContextRegExp?: RegExp;
19
- exprContextRecursive?: boolean;
20
- exprContextCritical?: boolean;
21
- wrappedContextRegExp?: RegExp;
22
- wrappedContextRecursive?: boolean;
23
- wrappedContextCritical?: boolean;
24
- strictExportPresence?: boolean;
25
- };
26
- plugins: webpack.Plugin[];
27
- resolve: {
28
- modules: string[];
29
- plugins: TsconfigPathsPlugin[];
30
- descriptionFiles?: string[];
31
- mainFields?: string[] | string[][];
32
- aliasFields?: string[] | string[][];
33
- mainFiles?: string[];
34
- extensions?: string[];
35
- enforceExtension?: boolean;
36
- alias?: {
37
- [key: string]: string;
38
- };
39
- unsafeCache?: boolean | {};
40
- cachePredicate?(data: {
41
- path: string;
42
- request: string;
43
- }): boolean;
44
- symlinks?: boolean;
45
- cacheWithContext?: boolean;
46
- roots?: string[];
47
- };
48
- resolveLoader: webpack.ResolveLoader;
49
- mode?: "development" | "production" | "none";
50
- name?: string;
51
- context?: string;
52
- devtool?: webpack.Options.Devtool;
53
- output?: webpack.Output;
54
- externals?: string | RegExp | webpack.ExternalsObjectElement | webpack.ExternalsFunctionElement | webpack.ExternalsElement[];
55
- target?: "node" | "web" | "webworker" | "async-node" | "node-webkit" | "atom" | "electron" | "electron-renderer" | "electron-preload" | "electron-main" | ((compiler?: any) => void);
56
- bail?: boolean;
57
- profile?: boolean;
58
- cache?: boolean | object;
59
- watch?: boolean;
60
- watchOptions?: webpack.ICompiler.WatchOptions;
61
- node?: false | webpack.Node;
62
- amd?: {
63
- [moduleName: string]: boolean;
64
- };
65
- recordsPath?: string;
66
- recordsInputPath?: string;
67
- recordsOutputPath?: string;
68
- stats?: webpack.Stats.ToStringOptions;
69
- performance?: false | webpack.Options.Performance;
70
- parallelism?: number;
71
- optimization?: webpack.Options.Optimization;
72
- devServer?: import("webpack-dev-server").Configuration;
73
- }>;
2
+ import { PresetOptions } from './options';
3
+ export declare function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions): Promise<webpack.Configuration>;
@@ -1,10 +1,10 @@
1
1
  import { Configuration } from 'webpack';
2
- import { Options } from './framework-preset-angular-cli';
2
+ import { PresetOptions } from './options';
3
3
  /**
4
4
  * Run ngcc for converting modules to ivy format before starting storybook
5
5
  * This step is needed in order to support Ivy in storybook
6
6
  *
7
7
  * Information about Ivy can be found here https://angular.io/guide/ivy
8
8
  */
9
- export declare const runNgcc: () => void;
10
- export declare const webpack: (webpackConfig: Configuration, options: Options) => Promise<Configuration>;
9
+ export declare const runNgcc: () => Promise<void>;
10
+ export declare const webpack: (webpackConfig: Configuration, options: PresetOptions) => Promise<Configuration>;
@@ -1,3 +1,11 @@
1
- import { LoadOptions } from '@storybook/core-common';
1
+ import { LoadOptions, Options as CoreOptions } from '@storybook/core-common';
2
+ import { BuilderContext } from '@angular-devkit/architect';
3
+ import { JsonObject } from '@angular-devkit/core';
4
+ export declare type PresetOptions = CoreOptions & {
5
+ angularBrowserTarget?: string | null;
6
+ angularBuilderOptions?: JsonObject | null;
7
+ angularBuilderContext?: BuilderContext | null;
8
+ tsConfig?: string;
9
+ };
2
10
  declare const _default: LoadOptions;
3
11
  export default _default;
@@ -6,7 +6,7 @@ export declare type StorybookBuilderOptions = JsonObject & {
6
6
  tsConfig?: string;
7
7
  compodoc: boolean;
8
8
  compodocArgs: string[];
9
- } & Pick<CLIOptions, 'staticDir' | 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'docs'>;
9
+ } & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'docs'>;
10
10
  export declare type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
11
11
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<StorybookBuilderOptions>;
12
12
  export default _default;
@@ -79,7 +79,8 @@ function commandBuilder(options, context) {
79
79
  }), operators_1.map(function (_a) {
80
80
  var tsConfig = _a.tsConfig;
81
81
  var browserTarget = options.browserTarget, otherOptions = __rest(options, ["browserTarget"]);
82
- return __assign(__assign({}, otherOptions), { angularBrowserTarget: browserTarget, tsConfig: tsConfig });
82
+ var standaloneOptions = __assign(__assign({}, otherOptions), { angularBrowserTarget: browserTarget, angularBuilderContext: context, tsConfig: tsConfig });
83
+ return standaloneOptions;
83
84
  }), operators_1.switchMap(function (standaloneOptions) { return runInstance(__assign(__assign({}, standaloneOptions), { mode: 'static' })); }), operators_1.map(function () {
84
85
  return { success: true };
85
86
  }));
@@ -14,13 +14,6 @@
14
14
  "type": "string",
15
15
  "description": "The full path for the TypeScript configuration file, relative to the current workspace."
16
16
  },
17
- "staticDir": {
18
- "type": "array",
19
- "description": "Directory where to load static files from, array of strings.",
20
- "items": {
21
- "type": "string"
22
- }
23
- },
24
17
  "outputDir": {
25
18
  "type": "string",
26
19
  "description": "Directory where to store built files.",
@@ -6,7 +6,7 @@ export declare type StorybookBuilderOptions = JsonObject & {
6
6
  tsConfig?: string;
7
7
  compodoc: boolean;
8
8
  compodocArgs: string[];
9
- } & Pick<CLIOptions, 'port' | 'host' | 'staticDir' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'docs'>;
9
+ } & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'docs'>;
10
10
  export declare type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
11
11
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<StorybookBuilderOptions>;
12
12
  export default _default;
@@ -79,7 +79,8 @@ function commandBuilder(options, context) {
79
79
  }), operators_1.map(function (_a) {
80
80
  var tsConfig = _a.tsConfig;
81
81
  var browserTarget = options.browserTarget, otherOptions = __rest(options, ["browserTarget"]);
82
- return __assign(__assign({}, otherOptions), { angularBrowserTarget: browserTarget, tsConfig: tsConfig });
82
+ var standaloneOptions = __assign(__assign({}, otherOptions), { angularBrowserTarget: browserTarget, angularBuilderContext: context, tsConfig: tsConfig });
83
+ return standaloneOptions;
83
84
  }), operators_1.switchMap(function (standaloneOptions) { return runInstance(standaloneOptions); }), operators_1.map(function () {
84
85
  return { success: true };
85
86
  }));
@@ -24,13 +24,6 @@
24
24
  "description": "Host to listen on.",
25
25
  "default": "localhost"
26
26
  },
27
- "staticDir": {
28
- "type": "array",
29
- "description": "Directory where to load static files from, array of strings.",
30
- "items": {
31
- "type": "string"
32
- }
33
- },
34
27
  "configDir": {
35
28
  "type": "string",
36
29
  "description": "Directory where to load Storybook configurations from.",
@@ -87,13 +80,5 @@
87
80
  }
88
81
  }
89
82
  },
90
- "additionalProperties": false,
91
- "oneOf": [
92
- {
93
- "required": ["browserTarget"]
94
- },
95
- {
96
- "required": ["tsConfig"]
97
- }
98
- ]
83
+ "additionalProperties": false
99
84
  }
@@ -0,0 +1 @@
1
+ export function getWebpackConfig(baseConfig: any, { builderOptions, builderContext }: any): Promise<any>;
@@ -0,0 +1,93 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
49
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
50
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
51
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
52
+ r[k] = a[j];
53
+ return r;
54
+ };
55
+ // Private angular devkit stuff
56
+ var generateI18nBrowserWebpackConfigFromContext = require('@angular-devkit/build-angular/src/utils/webpack-browser-config').generateI18nBrowserWebpackConfigFromContext;
57
+ var _a = require('@angular-devkit/build-angular/src/webpack/configs'), getCommonConfig = _a.getCommonConfig, getStylesConfig = _a.getStylesConfig, getTypeScriptConfig = _a.getTypeScriptConfig;
58
+ var filterOutStylingRules = require('./utils/filter-out-styling-rules').filterOutStylingRules;
59
+ /**
60
+ * Extract webpack config from angular-cli 12.2.x
61
+ * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
62
+ * FIXME: Try another way with TypeScript on future storybook version (7 maybe 🤞)
63
+ *
64
+ * @param {*} baseConfig Previous webpack config from storybook
65
+ * @param {*} options { builderOptions, builderContext }
66
+ */
67
+ exports.getWebpackConfig = function (baseConfig, _a) {
68
+ var builderOptions = _a.builderOptions, builderContext = _a.builderContext;
69
+ return __awaiter(void 0, void 0, void 0, function () {
70
+ var cliConfig, entry, rulesExcludingStyles, module, plugins, resolve;
71
+ var _b, _c, _d;
72
+ return __generator(this, function (_e) {
73
+ switch (_e.label) {
74
+ case 0: return [4 /*yield*/, generateI18nBrowserWebpackConfigFromContext(__assign(__assign({
75
+ // Default options
76
+ index: 'noop-index', main: 'noop-main', outputPath: 'noop-out' }, builderOptions), {
77
+ // Fixed options
78
+ optimization: false, namedChunks: false, progress: false, buildOptimizer: false, aot: false }), builderContext, function (wco) { return [getCommonConfig(wco), getStylesConfig(wco), getTypeScriptConfig(wco)]; })];
79
+ case 1:
80
+ cliConfig = (_e.sent()).config;
81
+ entry = __spreadArrays(baseConfig.entry, ((_b = cliConfig.entry.styles) !== null && _b !== void 0 ? _b : []), ((_c = cliConfig.entry.polyfills) !== null && _c !== void 0 ? _c : []));
82
+ rulesExcludingStyles = filterOutStylingRules(baseConfig);
83
+ module = __assign(__assign({}, baseConfig.module), { rules: __spreadArrays(cliConfig.module.rules, rulesExcludingStyles) });
84
+ plugins = __spreadArrays(((_d = cliConfig.plugins) !== null && _d !== void 0 ? _d : []), baseConfig.plugins);
85
+ resolve = __assign(__assign({}, baseConfig.resolve), { modules: Array.from(new Set(__spreadArrays(baseConfig.resolve.modules, cliConfig.resolve.modules))) });
86
+ return [2 /*return*/, __assign(__assign({}, baseConfig), { entry: entry,
87
+ module: module,
88
+ plugins: plugins,
89
+ resolve: resolve, resolveLoader: cliConfig.resolveLoader })];
90
+ }
91
+ });
92
+ });
93
+ };
@@ -0,0 +1 @@
1
+ export function getWebpackConfig(baseConfig: any, { builderOptions, builderContext }: any): Promise<any>;
@@ -0,0 +1,93 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
49
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
50
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
51
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
52
+ r[k] = a[j];
53
+ return r;
54
+ };
55
+ // Private angular devkit stuff
56
+ var generateI18nBrowserWebpackConfigFromContext = require('@angular-devkit/build-angular/src/utils/webpack-browser-config').generateI18nBrowserWebpackConfigFromContext;
57
+ var _a = require('@angular-devkit/build-angular/src/webpack/configs'), getCommonConfig = _a.getCommonConfig, getStylesConfig = _a.getStylesConfig, getTypescriptWorkerPlugin = _a.getTypescriptWorkerPlugin;
58
+ var filterOutStylingRules = require('./utils/filter-out-styling-rules').filterOutStylingRules;
59
+ /**
60
+ * Extract webpack config from angular-cli 13.x.x
61
+ * ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
62
+ * FIXME: Try another way with TypeScript on future storybook version (7 maybe 🤞)
63
+ *
64
+ * @param {*} baseConfig Previous webpack config from storybook
65
+ * @param {*} options { builderOptions, builderContext }
66
+ */
67
+ exports.getWebpackConfig = function (baseConfig, _a) {
68
+ var builderOptions = _a.builderOptions, builderContext = _a.builderContext;
69
+ return __awaiter(void 0, void 0, void 0, function () {
70
+ var cliConfig, entry, rulesExcludingStyles, module, plugins, resolve;
71
+ var _b, _c, _d;
72
+ return __generator(this, function (_e) {
73
+ switch (_e.label) {
74
+ case 0: return [4 /*yield*/, generateI18nBrowserWebpackConfigFromContext(__assign(__assign({
75
+ // Default options
76
+ index: 'noop-index', main: 'noop-main', outputPath: 'noop-out' }, builderOptions), {
77
+ // Fixed options
78
+ optimization: false, namedChunks: false, progress: false, buildOptimizer: false, aot: false }), builderContext, function (wco) { return [getCommonConfig(wco), getStylesConfig(wco), getTypescriptWorkerPlugin(wco)]; })];
79
+ case 1:
80
+ cliConfig = (_e.sent()).config;
81
+ entry = __spreadArrays(baseConfig.entry, ((_b = cliConfig.entry.styles) !== null && _b !== void 0 ? _b : []), ((_c = cliConfig.entry.polyfills) !== null && _c !== void 0 ? _c : []));
82
+ rulesExcludingStyles = filterOutStylingRules(baseConfig);
83
+ module = __assign(__assign({}, baseConfig.module), { rules: __spreadArrays(cliConfig.module.rules, rulesExcludingStyles) });
84
+ plugins = __spreadArrays(((_d = cliConfig.plugins) !== null && _d !== void 0 ? _d : []), baseConfig.plugins);
85
+ resolve = __assign(__assign({}, baseConfig.resolve), { modules: Array.from(new Set(__spreadArrays(baseConfig.resolve.modules, cliConfig.resolve.modules))) });
86
+ return [2 /*return*/, __assign(__assign({}, baseConfig), { entry: entry,
87
+ module: module,
88
+ plugins: plugins,
89
+ resolve: resolve, resolveLoader: cliConfig.resolveLoader })];
90
+ }
91
+ });
92
+ });
93
+ };
@@ -0,0 +1,72 @@
1
+ import webpack from 'webpack';
2
+ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
3
+ import { PresetOptions } from './options';
4
+ /**
5
+ * Old way currently support version lower than 12.2.x
6
+ */
7
+ export declare function getWebpackConfig(baseConfig: webpack.Configuration, options: PresetOptions): Promise<webpack.Configuration | {
8
+ entry: any[];
9
+ module: {
10
+ rules: webpack.RuleSetRule[];
11
+ noParse?: RegExp | RegExp[] | ((content: string) => boolean);
12
+ unknownContextRequest?: string;
13
+ unknownContextRecursive?: boolean;
14
+ unknownContextRegExp?: RegExp;
15
+ unknownContextCritical?: boolean;
16
+ exprContextRequest?: string;
17
+ exprContextRegExp?: RegExp;
18
+ exprContextRecursive?: boolean;
19
+ exprContextCritical?: boolean;
20
+ wrappedContextRegExp?: RegExp;
21
+ wrappedContextRecursive?: boolean;
22
+ wrappedContextCritical?: boolean;
23
+ strictExportPresence?: boolean;
24
+ };
25
+ plugins: webpack.Plugin[];
26
+ resolve: {
27
+ modules: string[];
28
+ plugins: TsconfigPathsPlugin[];
29
+ descriptionFiles?: string[];
30
+ mainFields?: string[] | string[][];
31
+ aliasFields?: string[] | string[][];
32
+ mainFiles?: string[];
33
+ extensions?: string[];
34
+ enforceExtension?: boolean;
35
+ alias?: {
36
+ [key: string]: string;
37
+ };
38
+ unsafeCache?: boolean | {};
39
+ cachePredicate?(data: {
40
+ path: string;
41
+ request: string;
42
+ }): boolean;
43
+ symlinks?: boolean;
44
+ cacheWithContext?: boolean;
45
+ roots?: string[];
46
+ };
47
+ resolveLoader: webpack.ResolveLoader;
48
+ mode?: "development" | "production" | "none";
49
+ name?: string;
50
+ context?: string;
51
+ devtool?: webpack.Options.Devtool;
52
+ output?: webpack.Output;
53
+ externals?: string | RegExp | webpack.ExternalsObjectElement | webpack.ExternalsFunctionElement | webpack.ExternalsElement[];
54
+ target?: "node" | "web" | "webworker" | "async-node" | "node-webkit" | "atom" | "electron" | "electron-renderer" | "electron-preload" | "electron-main" | ((compiler?: any) => void);
55
+ bail?: boolean;
56
+ profile?: boolean;
57
+ cache?: boolean | object;
58
+ watch?: boolean;
59
+ watchOptions?: webpack.ICompiler.WatchOptions;
60
+ node?: false | webpack.Node;
61
+ amd?: {
62
+ [moduleName: string]: boolean;
63
+ };
64
+ recordsPath?: string;
65
+ recordsInputPath?: string;
66
+ recordsOutputPath?: string;
67
+ stats?: webpack.Stats.ToStringOptions;
68
+ performance?: false | webpack.Options.Performance;
69
+ parallelism?: number;
70
+ optimization?: webpack.Options.Optimization;
71
+ devServer?: import("webpack-dev-server").Configuration;
72
+ }>;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
50
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
51
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
52
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
53
+ r[k] = a[j];
54
+ return r;
55
+ };
56
+ var __importDefault = (this && this.__importDefault) || function (mod) {
57
+ return (mod && mod.__esModule) ? mod : { "default": mod };
58
+ };
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ exports.getWebpackConfig = void 0;
61
+ var node_logger_1 = require("@storybook/node-logger");
62
+ var tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
63
+ var architect_1 = require("@angular-devkit/architect");
64
+ var angular_read_workspace_1 = require("./angular-read-workspace");
65
+ var angular_devkit_build_webpack_1 = require("./angular-devkit-build-webpack");
66
+ var filter_out_styling_rules_1 = require("./utils/filter-out-styling-rules");
67
+ /**
68
+ * Old way currently support version lower than 12.2.x
69
+ */
70
+ function getWebpackConfig(baseConfig, options) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var dirToSearch, workspaceConfig, error_1, project, target, confName, browserTarget, fondProject, angularCliWebpackConfig, error_2;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0:
76
+ dirToSearch = process.cwd();
77
+ _a.label = 1;
78
+ case 1:
79
+ _a.trys.push([1, 3, , 4]);
80
+ return [4 /*yield*/, angular_read_workspace_1.readAngularWorkspaceConfig(dirToSearch)];
81
+ case 2:
82
+ workspaceConfig = _a.sent();
83
+ return [3 /*break*/, 4];
84
+ case 3:
85
+ error_1 = _a.sent();
86
+ node_logger_1.logger.error("=> Could not find angular workspace config (angular.json) on this path \"" + dirToSearch + "\"");
87
+ node_logger_1.logger.info("=> Fail to load angular-cli config. Using base config");
88
+ return [2 /*return*/, baseConfig];
89
+ case 4:
90
+ try {
91
+ // Default behavior when `angularBrowserTarget` are not explicitly defined to null
92
+ if (options.angularBrowserTarget !== null) {
93
+ browserTarget = options.angularBrowserTarget
94
+ ? architect_1.targetFromTargetString(options.angularBrowserTarget)
95
+ : {
96
+ configuration: undefined,
97
+ project: angular_read_workspace_1.getDefaultProjectName(workspaceConfig),
98
+ target: 'build',
99
+ };
100
+ fondProject = angular_read_workspace_1.findAngularProjectTarget(workspaceConfig, browserTarget.project, browserTarget.target);
101
+ project = fondProject.project;
102
+ target = fondProject.target;
103
+ confName = browserTarget.configuration;
104
+ node_logger_1.logger.info("=> Using angular project \"" + browserTarget.project + ":" + browserTarget.target + (confName ? ":" + confName : '') + "\" for configuring Storybook");
105
+ }
106
+ // Start storybook when only tsConfig is provided.
107
+ if (options.angularBrowserTarget === null && options.tsConfig) {
108
+ node_logger_1.logger.info("=> Using default angular project with \"tsConfig:" + options.tsConfig + "\"");
109
+ project = { root: '', extensions: {}, targets: undefined };
110
+ target = { builder: '', options: { tsConfig: options.tsConfig } };
111
+ }
112
+ }
113
+ catch (error) {
114
+ node_logger_1.logger.error("=> Could not find angular project: " + error.message);
115
+ node_logger_1.logger.info("=> Fail to load angular-cli config. Using base config");
116
+ return [2 /*return*/, baseConfig];
117
+ }
118
+ _a.label = 5;
119
+ case 5:
120
+ _a.trys.push([5, 7, , 8]);
121
+ return [4 /*yield*/, angular_devkit_build_webpack_1.extractAngularCliWebpackConfig(dirToSearch, project, target, confName)];
122
+ case 6:
123
+ angularCliWebpackConfig = _a.sent();
124
+ node_logger_1.logger.info("=> Using angular-cli webpack config");
125
+ return [3 /*break*/, 8];
126
+ case 7:
127
+ error_2 = _a.sent();
128
+ node_logger_1.logger.error("=> Could not get angular cli webpack config");
129
+ throw error_2;
130
+ case 8: return [2 /*return*/, mergeAngularCliWebpackConfig(angularCliWebpackConfig, baseConfig)];
131
+ }
132
+ });
133
+ });
134
+ }
135
+ exports.getWebpackConfig = getWebpackConfig;
136
+ function mergeAngularCliWebpackConfig(_a, baseConfig) {
137
+ var cliCommonWebpackConfig = _a.cliCommonWebpackConfig, cliStyleWebpackConfig = _a.cliStyleWebpackConfig, tsConfigPath = _a.tsConfigPath;
138
+ // Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
139
+ // because @angular-devkit/build-angular created rules have include/exclude for global style files.
140
+ var rulesExcludingStyles = filter_out_styling_rules_1.filterOutStylingRules(baseConfig);
141
+ // styleWebpackConfig.entry adds global style files to the webpack context
142
+ var entry = __spreadArrays(baseConfig.entry, Object.values(cliStyleWebpackConfig.entry).reduce(function (acc, item) { return acc.concat(item); }, []));
143
+ var module = __assign(__assign({}, baseConfig.module), { rules: __spreadArrays(cliStyleWebpackConfig.module.rules, rulesExcludingStyles) });
144
+ // We use cliCommonConfig plugins to serve static assets files.
145
+ var plugins = __spreadArrays(cliStyleWebpackConfig.plugins, cliCommonWebpackConfig.plugins, baseConfig.plugins);
146
+ var resolve = __assign(__assign({}, baseConfig.resolve), { modules: Array.from(new Set(__spreadArrays(baseConfig.resolve.modules, cliCommonWebpackConfig.resolve.modules))), plugins: [
147
+ new tsconfig_paths_webpack_plugin_1.default({
148
+ configFile: tsConfigPath,
149
+ mainFields: ['browser', 'module', 'main'],
150
+ }),
151
+ ] });
152
+ return __assign(__assign({}, baseConfig), { entry: entry,
153
+ module: module,
154
+ plugins: plugins,
155
+ resolve: resolve, resolveLoader: cliCommonWebpackConfig.resolveLoader });
156
+ }
@@ -1,73 +1,3 @@
1
1
  import webpack from 'webpack';
2
- import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
3
- import { Options as CoreOptions } from '@storybook/core-common';
4
- export declare type Options = CoreOptions & {
5
- angularBrowserTarget?: string;
6
- tsConfig?: string;
7
- };
8
- export declare function webpackFinal(baseConfig: webpack.Configuration, options: Options): Promise<webpack.Configuration | {
9
- entry: any[];
10
- module: {
11
- rules: webpack.RuleSetRule[];
12
- noParse?: RegExp | RegExp[] | ((content: string) => boolean);
13
- unknownContextRequest?: string;
14
- unknownContextRecursive?: boolean;
15
- unknownContextRegExp?: RegExp;
16
- unknownContextCritical?: boolean;
17
- exprContextRequest?: string;
18
- exprContextRegExp?: RegExp;
19
- exprContextRecursive?: boolean;
20
- exprContextCritical?: boolean;
21
- wrappedContextRegExp?: RegExp;
22
- wrappedContextRecursive?: boolean;
23
- wrappedContextCritical?: boolean;
24
- strictExportPresence?: boolean;
25
- };
26
- plugins: webpack.Plugin[];
27
- resolve: {
28
- modules: string[];
29
- plugins: TsconfigPathsPlugin[];
30
- descriptionFiles?: string[];
31
- mainFields?: string[] | string[][];
32
- aliasFields?: string[] | string[][];
33
- mainFiles?: string[];
34
- extensions?: string[];
35
- enforceExtension?: boolean;
36
- alias?: {
37
- [key: string]: string;
38
- };
39
- unsafeCache?: boolean | {};
40
- cachePredicate?(data: {
41
- path: string;
42
- request: string;
43
- }): boolean;
44
- symlinks?: boolean;
45
- cacheWithContext?: boolean;
46
- roots?: string[];
47
- };
48
- resolveLoader: webpack.ResolveLoader;
49
- mode?: "development" | "production" | "none";
50
- name?: string;
51
- context?: string;
52
- devtool?: webpack.Options.Devtool;
53
- output?: webpack.Output;
54
- externals?: string | RegExp | webpack.ExternalsObjectElement | webpack.ExternalsFunctionElement | webpack.ExternalsElement[];
55
- target?: "node" | "web" | "webworker" | "async-node" | "node-webkit" | "atom" | "electron" | "electron-renderer" | "electron-preload" | "electron-main" | ((compiler?: any) => void);
56
- bail?: boolean;
57
- profile?: boolean;
58
- cache?: boolean | object;
59
- watch?: boolean;
60
- watchOptions?: webpack.ICompiler.WatchOptions;
61
- node?: false | webpack.Node;
62
- amd?: {
63
- [moduleName: string]: boolean;
64
- };
65
- recordsPath?: string;
66
- recordsInputPath?: string;
67
- recordsOutputPath?: string;
68
- stats?: webpack.Stats.ToStringOptions;
69
- performance?: false | webpack.Options.Performance;
70
- parallelism?: number;
71
- optimization?: webpack.Options.Optimization;
72
- devServer?: import("webpack-dev-server").Configuration;
73
- }>;
2
+ import { PresetOptions } from './options';
3
+ export declare function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions): Promise<webpack.Configuration>;
@@ -10,6 +10,25 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
13
32
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,114 +65,129 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
65
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
66
  }
48
67
  };
49
- var __spreadArrays = (this && this.__spreadArrays) || function () {
50
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
51
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
52
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
53
- r[k] = a[j];
54
- return r;
55
- };
56
68
  var __importDefault = (this && this.__importDefault) || function (mod) {
57
69
  return (mod && mod.__esModule) ? mod : { "default": mod };
58
70
  };
59
71
  Object.defineProperty(exports, "__esModule", { value: true });
60
72
  exports.webpackFinal = void 0;
61
73
  var node_logger_1 = require("@storybook/node-logger");
62
- var tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
63
74
  var architect_1 = require("@angular-devkit/architect");
64
- var angular_read_workspace_1 = require("./angular-read-workspace");
65
- var angular_devkit_build_webpack_1 = require("./angular-devkit-build-webpack");
75
+ var find_up_1 = require("find-up");
76
+ var semver_1 = __importDefault(require("@storybook/semver"));
77
+ var core_1 = require("@angular-devkit/core");
66
78
  var module_is_available_1 = require("./utils/module-is-available");
67
- var filter_out_styling_rules_1 = require("./utils/filter-out-styling-rules");
79
+ var angular_cli_webpack_12_2_x_1 = require("./angular-cli-webpack-12.2.x");
80
+ var angular_cli_webpack_13_x_x_1 = require("./angular-cli-webpack-13.x.x");
81
+ var angular_cli_webpack_older_1 = require("./angular-cli-webpack-older");
68
82
  function webpackFinal(baseConfig, options) {
83
+ var _a;
69
84
  return __awaiter(this, void 0, void 0, function () {
70
- var dirToSearch, workspaceConfig, error_1, project, target, confName, browserTarget, fondProject, angularCliWebpackConfig, error_2;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
85
+ var packageJson, angularCliVersion, webpackGetterByVersions, webpackGetter;
86
+ var _this = this;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
73
89
  case 0:
74
- dirToSearch = process.cwd();
75
90
  if (!module_is_available_1.moduleIsAvailable('@angular-devkit/build-angular')) {
76
91
  node_logger_1.logger.info('=> Using base config because "@angular-devkit/build-angular" is not installed');
77
92
  return [2 /*return*/, baseConfig];
78
93
  }
79
- node_logger_1.logger.info('=> Loading angular-cli config');
80
- _a.label = 1;
94
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(find_up_1.sync('package.json', { cwd: options.configDir }))); })];
81
95
  case 1:
82
- _a.trys.push([1, 3, , 4]);
83
- return [4 /*yield*/, angular_read_workspace_1.readAngularWorkspaceConfig(dirToSearch)];
84
- case 2:
85
- workspaceConfig = _a.sent();
86
- return [3 /*break*/, 4];
87
- case 3:
88
- error_1 = _a.sent();
89
- node_logger_1.logger.error("=> Could not find angular workspace config (angular.json) on this path \"" + dirToSearch + "\"");
90
- node_logger_1.logger.info("=> Fail to load angular-cli config. Using base config");
91
- return [2 /*return*/, baseConfig];
92
- case 4:
93
- try {
94
- // Default behavior when `angularBrowserTarget` are not explicitly defined to null
95
- if (options.angularBrowserTarget !== null) {
96
- browserTarget = options.angularBrowserTarget
97
- ? architect_1.targetFromTargetString(options.angularBrowserTarget)
98
- : {
99
- configuration: undefined,
100
- project: angular_read_workspace_1.getDefaultProjectName(workspaceConfig),
101
- target: 'build',
102
- };
103
- fondProject = angular_read_workspace_1.findAngularProjectTarget(workspaceConfig, browserTarget.project, browserTarget.target);
104
- project = fondProject.project;
105
- target = fondProject.target;
106
- confName = browserTarget.configuration;
107
- node_logger_1.logger.info("=> Using angular project \"" + browserTarget.project + ":" + browserTarget.target + (confName ? ":" + confName : '') + "\" for configuring Storybook");
108
- }
109
- // Start storybook when only tsConfig is provided.
110
- if (options.angularBrowserTarget === null && options.tsConfig) {
111
- node_logger_1.logger.info("=> Using default angular project with \"tsConfig:" + options.tsConfig + "\"");
112
- project = { root: '', extensions: {}, targets: undefined };
113
- target = { builder: '', options: { tsConfig: options.tsConfig } };
114
- }
115
- }
116
- catch (error) {
117
- node_logger_1.logger.error("=> Could not find angular project: " + error.message);
118
- node_logger_1.logger.info("=> Fail to load angular-cli config. Using base config");
119
- return [2 /*return*/, baseConfig];
120
- }
121
- _a.label = 5;
122
- case 5:
123
- _a.trys.push([5, 7, , 8]);
124
- return [4 /*yield*/, angular_devkit_build_webpack_1.extractAngularCliWebpackConfig(dirToSearch, project, target, confName)];
125
- case 6:
126
- angularCliWebpackConfig = _a.sent();
127
- node_logger_1.logger.info("=> Using angular-cli webpack config");
128
- return [3 /*break*/, 8];
129
- case 7:
130
- error_2 = _a.sent();
131
- node_logger_1.logger.error("=> Could not get angular cli webpack config");
132
- throw error_2;
133
- case 8: return [2 /*return*/, mergeAngularCliWebpackConfig(angularCliWebpackConfig, baseConfig)];
96
+ packageJson = _b.sent();
97
+ angularCliVersion = (_a = semver_1.default.coerce(packageJson.devDependencies['@angular/cli'])) === null || _a === void 0 ? void 0 : _a.version;
98
+ webpackGetterByVersions = [
99
+ {
100
+ info: '=> Loading angular-cli config for angular >= 13.0.0',
101
+ condition: semver_1.default.satisfies(angularCliVersion, '>=13.0.0'),
102
+ getWebpackConfig: function (_baseConfig, _options) { return __awaiter(_this, void 0, void 0, function () {
103
+ var builderContext, builderOptions;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ builderContext = getBuilderContext(_options);
108
+ return [4 /*yield*/, getBuilderOptions(_options, builderContext)];
109
+ case 1:
110
+ builderOptions = _a.sent();
111
+ return [2 /*return*/, angular_cli_webpack_13_x_x_1.getWebpackConfig(_baseConfig, {
112
+ builderOptions: builderOptions,
113
+ builderContext: builderContext,
114
+ })];
115
+ }
116
+ });
117
+ }); },
118
+ },
119
+ {
120
+ info: '=> Loading angular-cli config for angular 12.2.x',
121
+ condition: semver_1.default.satisfies(angularCliVersion, '12.2.x') && options.angularBuilderContext,
122
+ getWebpackConfig: function (_baseConfig, _options) { return __awaiter(_this, void 0, void 0, function () {
123
+ var builderContext, builderOptions;
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0:
127
+ builderContext = getBuilderContext(_options);
128
+ return [4 /*yield*/, getBuilderOptions(_options, builderContext)];
129
+ case 1:
130
+ builderOptions = _a.sent();
131
+ return [2 /*return*/, angular_cli_webpack_12_2_x_1.getWebpackConfig(_baseConfig, {
132
+ builderOptions: builderOptions,
133
+ builderContext: builderContext,
134
+ })];
135
+ }
136
+ });
137
+ }); },
138
+ },
139
+ {
140
+ info: '=> Loading angular-cli config for angular lower than 12.2.0',
141
+ condition: true,
142
+ getWebpackConfig: angular_cli_webpack_older_1.getWebpackConfig,
143
+ },
144
+ ];
145
+ webpackGetter = webpackGetterByVersions.find(function (wg) { return wg.condition; });
146
+ node_logger_1.logger.info(webpackGetter.info);
147
+ return [2 /*return*/, Promise.resolve(webpackGetter.getWebpackConfig(baseConfig, options))];
134
148
  }
135
149
  });
136
150
  });
137
151
  }
138
152
  exports.webpackFinal = webpackFinal;
139
- function mergeAngularCliWebpackConfig(_a, baseConfig) {
140
- var cliCommonWebpackConfig = _a.cliCommonWebpackConfig, cliStyleWebpackConfig = _a.cliStyleWebpackConfig, tsConfigPath = _a.tsConfigPath;
141
- // Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
142
- // because @angular-devkit/build-angular created rules have include/exclude for global style files.
143
- var rulesExcludingStyles = filter_out_styling_rules_1.filterOutStylingRules(baseConfig);
144
- // styleWebpackConfig.entry adds global style files to the webpack context
145
- var entry = __spreadArrays(baseConfig.entry, Object.values(cliStyleWebpackConfig.entry).reduce(function (acc, item) { return acc.concat(item); }, []));
146
- var module = __assign(__assign({}, baseConfig.module), { rules: __spreadArrays(cliStyleWebpackConfig.module.rules, rulesExcludingStyles) });
147
- // We use cliCommonConfig plugins to serve static assets files.
148
- var plugins = __spreadArrays(cliStyleWebpackConfig.plugins, cliCommonWebpackConfig.plugins, baseConfig.plugins);
149
- var resolve = __assign(__assign({}, baseConfig.resolve), { modules: Array.from(new Set(__spreadArrays(baseConfig.resolve.modules, cliCommonWebpackConfig.resolve.modules))), plugins: [
150
- new tsconfig_paths_webpack_plugin_1.default({
151
- configFile: tsConfigPath,
152
- mainFields: ['browser', 'module', 'main'],
153
- }),
154
- ] });
155
- return __assign(__assign({}, baseConfig), { entry: entry,
156
- module: module,
157
- plugins: plugins,
158
- resolve: resolve, resolveLoader: cliCommonWebpackConfig.resolveLoader });
153
+ /**
154
+ * Get Builder Context
155
+ * If storybook is not start by angular builder create dumb BuilderContext
156
+ */
157
+ function getBuilderContext(options) {
158
+ var _a;
159
+ return ((_a = options.angularBuilderContext) !== null && _a !== void 0 ? _a : {
160
+ target: { project: 'noop-project', builder: '', options: {} },
161
+ workspaceRoot: process.cwd(),
162
+ getProjectMetadata: function () { return ({}); },
163
+ getTargetOptions: function () { return ({}); },
164
+ logger: new core_1.logging.Logger('Storybook'),
165
+ });
166
+ }
167
+ /**
168
+ * Get builder options
169
+ * Merge target options from browser target and from storybook options
170
+ */
171
+ function getBuilderOptions(options, builderContext) {
172
+ var _a, _b, _c, _d;
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ var browserTargetOptions, browserTarget, builderOptions;
175
+ return __generator(this, function (_e) {
176
+ switch (_e.label) {
177
+ case 0:
178
+ browserTargetOptions = {};
179
+ if (!options.angularBrowserTarget) return [3 /*break*/, 2];
180
+ browserTarget = architect_1.targetFromTargetString(options.angularBrowserTarget);
181
+ node_logger_1.logger.info("=> Using angular browser target options from \"" + browserTarget.project + ":" + browserTarget.target + (browserTarget.configuration ? ":" + browserTarget.configuration : '') + "\"");
182
+ return [4 /*yield*/, builderContext.getTargetOptions(browserTarget)];
183
+ case 1:
184
+ browserTargetOptions = _e.sent();
185
+ _e.label = 2;
186
+ case 2:
187
+ builderOptions = __assign(__assign(__assign({}, browserTargetOptions), options.angularBuilderOptions), { tsConfig: (_d = (_c = (_a = options.tsConfig) !== null && _a !== void 0 ? _a : (_b = options.angularBuilderOptions) === null || _b === void 0 ? void 0 : _b.tsConfig) !== null && _c !== void 0 ? _c : browserTargetOptions.tsConfig) !== null && _d !== void 0 ? _d : find_up_1.sync('tsconfig.json', { cwd: options.configDir }) });
188
+ node_logger_1.logger.info("=> Using angular project with \"tsConfig:" + builderOptions.tsConfig + "\"");
189
+ return [2 /*return*/, builderOptions];
190
+ }
191
+ });
192
+ });
159
193
  }
@@ -1,10 +1,10 @@
1
1
  import { Configuration } from 'webpack';
2
- import { Options } from './framework-preset-angular-cli';
2
+ import { PresetOptions } from './options';
3
3
  /**
4
4
  * Run ngcc for converting modules to ivy format before starting storybook
5
5
  * This step is needed in order to support Ivy in storybook
6
6
  *
7
7
  * Information about Ivy can be found here https://angular.io/guide/ivy
8
8
  */
9
- export declare const runNgcc: () => void;
10
- export declare const webpack: (webpackConfig: Configuration, options: Options) => Promise<Configuration>;
9
+ export declare const runNgcc: () => Promise<void>;
10
+ export declare const webpack: (webpackConfig: Configuration, options: PresetOptions) => Promise<Configuration>;
@@ -67,24 +67,59 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
67
67
  };
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
69
  exports.webpack = exports.runNgcc = void 0;
70
- var ngcc_1 = require("@angular/compiler-cli/ngcc");
71
70
  var path = __importStar(require("path"));
71
+ /**
72
+ * Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23
73
+ * This uses a dynamic import to load a module which may be ESM.
74
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
75
+ * will currently, unconditionally downlevel dynamic import into a require call.
76
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
77
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
78
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
79
+ * be dropped.
80
+ *
81
+ * @param modulePath The path of the module to load.
82
+ * @returns A Promise that resolves to the dynamically imported module.
83
+ */
84
+ function loadEsmModule(modulePath) {
85
+ // eslint-disable-next-line no-new-func
86
+ return new Function('modulePath', "return import(modulePath);")(modulePath);
87
+ }
72
88
  /**
73
89
  * Run ngcc for converting modules to ivy format before starting storybook
74
90
  * This step is needed in order to support Ivy in storybook
75
91
  *
76
92
  * Information about Ivy can be found here https://angular.io/guide/ivy
77
93
  */
78
- exports.runNgcc = function () {
79
- ngcc_1.process({
80
- // should be async: true but does not work due to
81
- // https://github.com/storybookjs/storybook/pull/11157/files#r615413803
82
- async: false,
83
- basePath: path.join(process.cwd(), 'node_modules'),
84
- createNewEntryPointFormats: true,
85
- compileAllFormats: false,
94
+ exports.runNgcc = function () { return __awaiter(void 0, void 0, void 0, function () {
95
+ var ngcc, error_1;
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0:
99
+ _a.trys.push([0, 2, , 4]);
100
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('@angular/compiler-cli/ngcc')); })];
101
+ case 1:
102
+ ngcc = _a.sent();
103
+ return [3 /*break*/, 4];
104
+ case 2:
105
+ error_1 = _a.sent();
106
+ return [4 /*yield*/, loadEsmModule('@angular/compiler-cli/ngcc')];
107
+ case 3:
108
+ ngcc = _a.sent();
109
+ return [3 /*break*/, 4];
110
+ case 4:
111
+ ngcc.process({
112
+ // should be async: true but does not work due to
113
+ // https://github.com/storybookjs/storybook/pull/11157/files#r615413803
114
+ async: false,
115
+ basePath: path.join(process.cwd(), 'node_modules'),
116
+ createNewEntryPointFormats: true,
117
+ compileAllFormats: false,
118
+ });
119
+ return [2 /*return*/];
120
+ }
86
121
  });
87
- };
122
+ }); };
88
123
  exports.webpack = function (webpackConfig, options) { return __awaiter(void 0, void 0, void 0, function () {
89
124
  var angularOptions;
90
125
  return __generator(this, function (_a) {
@@ -1,3 +1,11 @@
1
- import { LoadOptions } from '@storybook/core-common';
1
+ import { LoadOptions, Options as CoreOptions } from '@storybook/core-common';
2
+ import { BuilderContext } from '@angular-devkit/architect';
3
+ import { JsonObject } from '@angular-devkit/core';
4
+ export declare type PresetOptions = CoreOptions & {
5
+ angularBrowserTarget?: string | null;
6
+ angularBuilderOptions?: JsonObject | null;
7
+ angularBuilderContext?: BuilderContext | null;
8
+ tsConfig?: string;
9
+ };
2
10
  declare const _default: LoadOptions;
3
11
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "6.4.0-rc.0",
3
+ "version": "6.4.0-rc.1",
4
4
  "description": "Storybook for Angular: Develop Angular Components in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook"
@@ -45,17 +45,19 @@
45
45
  "prepare": "node ../../scripts/prepare.js"
46
46
  },
47
47
  "dependencies": {
48
- "@storybook/addons": "6.4.0-rc.0",
49
- "@storybook/api": "6.4.0-rc.0",
50
- "@storybook/core": "6.4.0-rc.0",
51
- "@storybook/core-common": "6.4.0-rc.0",
52
- "@storybook/core-events": "6.4.0-rc.0",
48
+ "@storybook/addons": "6.4.0-rc.1",
49
+ "@storybook/api": "6.4.0-rc.1",
50
+ "@storybook/core": "6.4.0-rc.1",
51
+ "@storybook/core-common": "6.4.0-rc.1",
52
+ "@storybook/core-events": "6.4.0-rc.1",
53
53
  "@storybook/csf": "0.0.2--canary.87bc651.0",
54
- "@storybook/node-logger": "6.4.0-rc.0",
55
- "@storybook/store": "6.4.0-rc.0",
54
+ "@storybook/node-logger": "6.4.0-rc.1",
55
+ "@storybook/semver": "^7.3.2",
56
+ "@storybook/store": "6.4.0-rc.1",
56
57
  "@types/webpack-env": "^1.16.0",
57
58
  "autoprefixer": "^9.8.6",
58
59
  "core-js": "^3.8.2",
60
+ "find-up": "^5.0.0",
59
61
  "fork-ts-checker-webpack-plugin": "^4.1.6",
60
62
  "global": "^4.4.0",
61
63
  "postcss": "^7.0.36",
@@ -131,5 +133,5 @@
131
133
  "access": "public"
132
134
  },
133
135
  "builders": "dist/ts3.9/builders/builders.json",
134
- "gitHead": "812e75b32c7fe222b872961a83c05cc8ece36a36"
136
+ "gitHead": "0d79fcc7dd9f8d949c2644aefb54e77a3f932db4"
135
137
  }
package/standalone.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { CLIOptions, LoadOptions, BuilderOptions } from '@storybook/core-common';
2
+ import { BuilderContext } from '@angular-devkit/architect';
3
+ import { JsonObject } from '@angular-devkit/core';
2
4
 
3
5
  export type StandaloneOptions = Partial<
4
6
  CLIOptions &
@@ -6,6 +8,8 @@ export type StandaloneOptions = Partial<
6
8
  BuilderOptions & {
7
9
  mode?: 'static' | 'dev';
8
10
  angularBrowserTarget?: string | null;
11
+ angularBuilderOptions?: JsonObject;
12
+ angularBuilderContext?: BuilderContext | null;
9
13
  tsConfig?: string;
10
14
  }
11
15
  >;