@storybook/angular 8.1.3 → 8.1.5

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,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const architect_1 = require("@angular-devkit/architect");
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
4
6
  const find_up_1 = require("find-up");
5
7
  const read_pkg_up_1 = require("read-pkg-up");
6
8
  const core_common_1 = require("@storybook/core-common");
@@ -8,55 +10,69 @@ const telemetry_1 = require("@storybook/telemetry");
8
10
  const core_server_1 = require("@storybook/core-server");
9
11
  const run_compodoc_1 = require("../utils/run-compodoc");
10
12
  const error_handler_1 = require("../utils/error-handler");
11
- const setup_1 = require("../utils/setup");
12
13
  (0, telemetry_1.addToGlobalContext)('cliVersion', core_common_1.versions.storybook);
13
- const commandBuilder = async (options, context) => {
14
- const { tsConfig, angularBuilderContext, angularBuilderOptions } = await (0, setup_1.setup)(options, context);
15
- const docTSConfig = (0, find_up_1.sync)('tsconfig.doc.json', { cwd: options.configDir });
16
- if (options.compodoc) {
17
- await (0, run_compodoc_1.runCompodoc)({ compodocArgs: options.compodocArgs, tsconfig: docTSConfig ?? tsConfig }, context);
18
- }
19
- (0, core_common_1.getEnvConfig)(options, {
20
- staticDir: 'SBCONFIG_STATIC_DIR',
21
- outputDir: 'SBCONFIG_OUTPUT_DIR',
22
- configDir: 'SBCONFIG_CONFIG_DIR',
23
- });
24
- const { configDir, docs, loglevel, test, outputDir, quiet, enableProdMode = true, webpackStatsJson, statsJson, debugWebpack, disableTelemetry, previewUrl, } = options;
25
- const standaloneOptions = {
26
- packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
27
- configDir,
28
- ...(docs ? { docs } : {}),
29
- excludeChunks: angularBuilderOptions.styles
30
- ?.filter((style) => typeof style !== 'string' && style.inject === false)
31
- .map((s) => s.bundleName),
32
- loglevel,
33
- outputDir,
34
- test,
35
- quiet,
36
- enableProdMode,
37
- disableTelemetry,
38
- angularBrowserTarget: options.browserTarget,
39
- angularBuilderContext,
40
- angularBuilderOptions,
41
- tsConfig,
42
- webpackStatsJson,
43
- statsJson,
44
- debugWebpack,
45
- previewUrl,
46
- };
47
- await runInstance({ ...standaloneOptions, mode: 'static' });
48
- return { success: true };
14
+ const commandBuilder = (options, context) => {
15
+ const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
16
+ const docTSConfig = (0, find_up_1.sync)('tsconfig.doc.json', { cwd: options.configDir });
17
+ const runCompodoc$ = options.compodoc
18
+ ? (0, run_compodoc_1.runCompodoc)({ compodocArgs: options.compodocArgs, tsconfig: docTSConfig ?? tsConfig }, context).pipe((0, operators_1.mapTo)({ tsConfig }))
19
+ : (0, rxjs_1.of)({});
20
+ return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
21
+ }), (0, operators_1.map)(({ tsConfig }) => {
22
+ (0, core_common_1.getEnvConfig)(options, {
23
+ staticDir: 'SBCONFIG_STATIC_DIR',
24
+ outputDir: 'SBCONFIG_OUTPUT_DIR',
25
+ configDir: 'SBCONFIG_CONFIG_DIR',
26
+ });
27
+ const { browserTarget, stylePreprocessorOptions, styles, configDir, docs, loglevel, test, outputDir, quiet, enableProdMode = true, webpackStatsJson, statsJson, debugWebpack, disableTelemetry, assets, previewUrl, sourceMap = false, } = options;
28
+ const standaloneOptions = {
29
+ packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
30
+ configDir,
31
+ ...(docs ? { docs } : {}),
32
+ loglevel,
33
+ outputDir,
34
+ test,
35
+ quiet,
36
+ enableProdMode,
37
+ disableTelemetry,
38
+ angularBrowserTarget: browserTarget,
39
+ angularBuilderContext: context,
40
+ angularBuilderOptions: {
41
+ ...(stylePreprocessorOptions ? { stylePreprocessorOptions } : {}),
42
+ ...(styles ? { styles } : {}),
43
+ ...(assets ? { assets } : {}),
44
+ sourceMap,
45
+ },
46
+ tsConfig,
47
+ webpackStatsJson,
48
+ statsJson,
49
+ debugWebpack,
50
+ previewUrl,
51
+ };
52
+ return standaloneOptions;
53
+ }), (0, operators_1.switchMap)((standaloneOptions) => runInstance({ ...standaloneOptions, mode: 'static' })), (0, operators_1.map)(() => {
54
+ return { success: true };
55
+ }));
56
+ return builder;
49
57
  };
50
58
  exports.default = (0, architect_1.createBuilder)(commandBuilder);
51
- async function runInstance(options) {
52
- try {
53
- await (0, core_server_1.withTelemetry)('build', {
54
- cliOptions: options,
55
- presetOptions: { ...options, corePresets: [], overridePresets: [] },
56
- printError: error_handler_1.printErrorDetails,
57
- }, () => (0, core_server_1.buildStaticStandalone)(options));
58
- }
59
- catch (error) {
60
- throw new Error((0, error_handler_1.errorSummary)(error));
59
+ async function setup(options, context) {
60
+ let browserOptions;
61
+ let browserTarget;
62
+ if (options.browserTarget) {
63
+ browserTarget = (0, architect_1.targetFromTargetString)(options.browserTarget);
64
+ browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
61
65
  }
66
+ return {
67
+ tsConfig: options.tsConfig ??
68
+ (0, find_up_1.sync)('tsconfig.json', { cwd: options.configDir }) ??
69
+ browserOptions.tsConfig,
70
+ };
71
+ }
72
+ function runInstance(options) {
73
+ return (0, rxjs_1.from)((0, core_server_1.withTelemetry)('build', {
74
+ cliOptions: options,
75
+ presetOptions: { ...options, corePresets: [], overridePresets: [] },
76
+ printError: error_handler_1.printErrorDetails,
77
+ }, () => (0, core_server_1.buildStaticStandalone)(options))).pipe((0, operators_1.catchError)((error) => (0, rxjs_1.throwError)((0, error_handler_1.errorSummary)(error))));
62
78
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const architect_1 = require("@angular-devkit/architect");
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
4
6
  const find_up_1 = require("find-up");
5
7
  const read_pkg_up_1 = require("read-pkg-up");
6
8
  const core_common_1 = require("@storybook/core-common");
@@ -8,70 +10,90 @@ const telemetry_1 = require("@storybook/telemetry");
8
10
  const core_server_1 = require("@storybook/core-server");
9
11
  const run_compodoc_1 = require("../utils/run-compodoc");
10
12
  const error_handler_1 = require("../utils/error-handler");
11
- const setup_1 = require("../utils/setup");
12
13
  (0, telemetry_1.addToGlobalContext)('cliVersion', core_common_1.versions.storybook);
13
- const commandBuilder = async (options, context) => {
14
- const { tsConfig, angularBuilderContext, angularBuilderOptions } = await (0, setup_1.setup)(options, context);
15
- const docTSConfig = (0, find_up_1.sync)('tsconfig.doc.json', { cwd: options.configDir });
16
- if (options.compodoc) {
17
- await (0, run_compodoc_1.runCompodoc)({
18
- compodocArgs: [...options.compodocArgs, ...(options.quiet ? ['--silent'] : [])],
19
- tsconfig: docTSConfig ?? tsConfig,
20
- }, context);
21
- }
22
- (0, core_common_1.getEnvConfig)(options, {
23
- port: 'SBCONFIG_PORT',
24
- host: 'SBCONFIG_HOSTNAME',
25
- staticDir: 'SBCONFIG_STATIC_DIR',
26
- configDir: 'SBCONFIG_CONFIG_DIR',
27
- ci: 'CI',
28
- });
29
- options.port = parseInt(`${options.port}`, 10);
30
- const { browserTarget, ci, configDir, docs, host, https, port, quiet, enableProdMode = false, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, initialPath, open, debugWebpack, loglevel, webpackStatsJson, statsJson, previewUrl, } = options;
31
- const standaloneOptions = {
32
- packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
33
- ci,
34
- configDir,
35
- ...(docs ? { docs } : {}),
36
- excludeChunks: angularBuilderOptions.styles
37
- ?.filter((style) => typeof style !== 'string' && style.inject === false)
38
- .map((s) => s.bundleName),
39
- host,
40
- https,
41
- port,
42
- quiet,
43
- enableProdMode,
44
- smokeTest,
45
- sslCa,
46
- sslCert,
47
- sslKey,
48
- disableTelemetry,
49
- angularBrowserTarget: browserTarget,
50
- angularBuilderContext,
51
- angularBuilderOptions,
52
- tsConfig,
53
- initialPath,
54
- open,
55
- debugWebpack,
56
- webpackStatsJson,
57
- statsJson,
58
- loglevel,
59
- previewUrl,
60
- };
61
- const devPort = await runInstance(standaloneOptions);
62
- return { success: true, info: { port: devPort } };
14
+ const commandBuilder = (options, context) => {
15
+ const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
16
+ const docTSConfig = (0, find_up_1.sync)('tsconfig.doc.json', { cwd: options.configDir });
17
+ const runCompodoc$ = options.compodoc
18
+ ? (0, run_compodoc_1.runCompodoc)({
19
+ compodocArgs: [...options.compodocArgs, ...(options.quiet ? ['--silent'] : [])],
20
+ tsconfig: docTSConfig ?? tsConfig,
21
+ }, context).pipe((0, operators_1.mapTo)({ tsConfig }))
22
+ : (0, rxjs_1.of)({});
23
+ return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
24
+ }), (0, operators_1.map)(({ tsConfig }) => {
25
+ (0, core_common_1.getEnvConfig)(options, {
26
+ port: 'SBCONFIG_PORT',
27
+ host: 'SBCONFIG_HOSTNAME',
28
+ staticDir: 'SBCONFIG_STATIC_DIR',
29
+ configDir: 'SBCONFIG_CONFIG_DIR',
30
+ ci: 'CI',
31
+ });
32
+ options.port = parseInt(`${options.port}`, 10);
33
+ const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docs, host, https, port, quiet, enableProdMode = false, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, assets, initialPath, open, debugWebpack, loglevel, webpackStatsJson, statsJson, previewUrl, sourceMap = false, } = options;
34
+ const standaloneOptions = {
35
+ packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
36
+ ci,
37
+ configDir,
38
+ ...(docs ? { docs } : {}),
39
+ host,
40
+ https,
41
+ port,
42
+ quiet,
43
+ enableProdMode,
44
+ smokeTest,
45
+ sslCa,
46
+ sslCert,
47
+ sslKey,
48
+ disableTelemetry,
49
+ angularBrowserTarget: browserTarget,
50
+ angularBuilderContext: context,
51
+ angularBuilderOptions: {
52
+ ...(stylePreprocessorOptions ? { stylePreprocessorOptions } : {}),
53
+ ...(styles ? { styles } : {}),
54
+ ...(assets ? { assets } : {}),
55
+ sourceMap,
56
+ },
57
+ tsConfig,
58
+ initialPath,
59
+ open,
60
+ debugWebpack,
61
+ webpackStatsJson,
62
+ statsJson,
63
+ loglevel,
64
+ previewUrl,
65
+ };
66
+ return standaloneOptions;
67
+ }), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)((port) => {
68
+ return { success: true, info: { port } };
69
+ }));
70
+ return builder;
63
71
  };
64
72
  exports.default = (0, architect_1.createBuilder)(commandBuilder);
65
- async function runInstance(options) {
66
- try {
67
- const { port } = await (0, core_server_1.withTelemetry)('dev', {
73
+ async function setup(options, context) {
74
+ let browserOptions;
75
+ let browserTarget;
76
+ if (options.browserTarget) {
77
+ browserTarget = (0, architect_1.targetFromTargetString)(options.browserTarget);
78
+ browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
79
+ }
80
+ return {
81
+ tsConfig: options.tsConfig ??
82
+ (0, find_up_1.sync)('tsconfig.json', { cwd: options.configDir }) ??
83
+ browserOptions.tsConfig,
84
+ };
85
+ }
86
+ function runInstance(options) {
87
+ return new rxjs_1.Observable((observer) => {
88
+ // This Observable intentionally never complete, leaving the process running ;)
89
+ (0, core_server_1.withTelemetry)('dev', {
68
90
  cliOptions: options,
69
91
  presetOptions: { ...options, corePresets: [], overridePresets: [] },
70
92
  printError: error_handler_1.printErrorDetails,
71
- }, () => (0, core_server_1.buildDevStandalone)(options));
72
- return port;
73
- }
74
- catch (error) {
75
- throw new Error((0, error_handler_1.errorSummary)(error));
76
- }
93
+ }, () => (0, core_server_1.buildDevStandalone)(options))
94
+ .then(({ port }) => observer.next(port))
95
+ .catch((error) => {
96
+ observer.error((0, error_handler_1.errorSummary)(error));
97
+ });
98
+ });
77
99
  }
@@ -1,5 +1,6 @@
1
1
  import { BuilderContext } from '@angular-devkit/architect';
2
+ import { Observable } from 'rxjs';
2
3
  export declare const runCompodoc: ({ compodocArgs, tsconfig }: {
3
4
  compodocArgs: string[];
4
5
  tsconfig: string;
5
- }, context: BuilderContext) => Promise<void>;
6
+ }, context: BuilderContext) => Observable<void>;
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.runCompodoc = void 0;
27
+ const rxjs_1 = require("rxjs");
27
28
  const path = __importStar(require("path"));
28
29
  const core_common_1 = require("@storybook/core-common");
29
30
  const hasTsConfigArg = (args) => args.indexOf('-p') !== -1;
@@ -33,21 +34,25 @@ const hasOutputArg = (args) => args.indexOf('-d') !== -1 || args.indexOf('--outp
33
34
  const toRelativePath = (pathToTsConfig) => {
34
35
  return path.isAbsolute(pathToTsConfig) ? path.relative('.', pathToTsConfig) : pathToTsConfig;
35
36
  };
36
- const runCompodoc = async ({ compodocArgs, tsconfig }, context) => {
37
- const tsConfigPath = toRelativePath(tsconfig);
38
- const finalCompodocArgs = [
39
- ...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
40
- ...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot || '.'}`]),
41
- ...compodocArgs,
42
- ];
43
- const packageManager = core_common_1.JsPackageManagerFactory.getPackageManager();
44
- try {
45
- const stdout = packageManager.runPackageCommandSync('compodoc', finalCompodocArgs, context.workspaceRoot, 'inherit');
46
- context.logger.info(stdout);
47
- }
48
- catch (e) {
49
- context.logger.error(e);
50
- throw e;
51
- }
37
+ const runCompodoc = ({ compodocArgs, tsconfig }, context) => {
38
+ return new rxjs_1.Observable((observer) => {
39
+ const tsConfigPath = toRelativePath(tsconfig);
40
+ const finalCompodocArgs = [
41
+ ...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
42
+ ...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot || '.'}`]),
43
+ ...compodocArgs,
44
+ ];
45
+ const packageManager = core_common_1.JsPackageManagerFactory.getPackageManager();
46
+ try {
47
+ const stdout = packageManager.runPackageCommandSync('compodoc', finalCompodocArgs, context.workspaceRoot, 'inherit');
48
+ context.logger.info(stdout);
49
+ observer.next();
50
+ observer.complete();
51
+ }
52
+ catch (e) {
53
+ context.logger.error(e);
54
+ observer.error();
55
+ }
56
+ });
52
57
  };
53
58
  exports.runCompodoc = runCompodoc;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // eslint-disable-next-line import/no-extraneous-dependencies
4
4
  const vitest_1 = require("vitest");
5
+ const operators_1 = require("rxjs/operators");
5
6
  const run_compodoc_1 = require("./run-compodoc");
6
7
  const mockRunScript = vitest_1.vi.fn();
7
8
  vitest_1.vi.mock('@storybook/core-common', () => ({
@@ -29,38 +30,48 @@ const builderContextLoggerMock = {
29
30
  logger: builderContextLoggerMock,
30
31
  };
31
32
  (0, vitest_1.it)('should run compodoc with tsconfig from context', async () => {
32
- await (0, run_compodoc_1.runCompodoc)({
33
+ (0, run_compodoc_1.runCompodoc)({
33
34
  compodocArgs: [],
34
35
  tsconfig: 'path/to/tsconfig.json',
35
- }, builderContextMock);
36
+ }, builderContextMock)
37
+ .pipe((0, operators_1.take)(1))
38
+ .subscribe();
36
39
  (0, vitest_1.expect)(mockRunScript).toHaveBeenCalledWith('compodoc', ['-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], 'path/to/project', 'inherit');
37
40
  });
38
41
  (0, vitest_1.it)('should run compodoc with tsconfig from compodocArgs', async () => {
39
- await (0, run_compodoc_1.runCompodoc)({
42
+ (0, run_compodoc_1.runCompodoc)({
40
43
  compodocArgs: ['-p', 'path/to/tsconfig.stories.json'],
41
44
  tsconfig: 'path/to/tsconfig.json',
42
- }, builderContextMock);
45
+ }, builderContextMock)
46
+ .pipe((0, operators_1.take)(1))
47
+ .subscribe();
43
48
  (0, vitest_1.expect)(mockRunScript).toHaveBeenCalledWith('compodoc', ['-d', 'path/to/project', '-p', 'path/to/tsconfig.stories.json'], 'path/to/project', 'inherit');
44
49
  });
45
50
  (0, vitest_1.it)('should run compodoc with default output folder.', async () => {
46
- await (0, run_compodoc_1.runCompodoc)({
51
+ (0, run_compodoc_1.runCompodoc)({
47
52
  compodocArgs: [],
48
53
  tsconfig: 'path/to/tsconfig.json',
49
- }, builderContextMock);
54
+ }, builderContextMock)
55
+ .pipe((0, operators_1.take)(1))
56
+ .subscribe();
50
57
  (0, vitest_1.expect)(mockRunScript).toHaveBeenCalledWith('compodoc', ['-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], 'path/to/project', 'inherit');
51
58
  });
52
59
  (0, vitest_1.it)('should run with custom output folder specified with --output compodocArgs', async () => {
53
- await (0, run_compodoc_1.runCompodoc)({
60
+ (0, run_compodoc_1.runCompodoc)({
54
61
  compodocArgs: ['--output', 'path/to/customFolder'],
55
62
  tsconfig: 'path/to/tsconfig.json',
56
- }, builderContextMock);
63
+ }, builderContextMock)
64
+ .pipe((0, operators_1.take)(1))
65
+ .subscribe();
57
66
  (0, vitest_1.expect)(mockRunScript).toHaveBeenCalledWith('compodoc', ['-p', 'path/to/tsconfig.json', '--output', 'path/to/customFolder'], 'path/to/project', 'inherit');
58
67
  });
59
68
  (0, vitest_1.it)('should run with custom output folder specified with -d compodocArgs', async () => {
60
- await (0, run_compodoc_1.runCompodoc)({
69
+ (0, run_compodoc_1.runCompodoc)({
61
70
  compodocArgs: ['-d', 'path/to/customFolder'],
62
71
  tsconfig: 'path/to/tsconfig.json',
63
- }, builderContextMock);
72
+ }, builderContextMock)
73
+ .pipe((0, operators_1.take)(1))
74
+ .subscribe();
64
75
  (0, vitest_1.expect)(mockRunScript).toHaveBeenCalledWith('compodoc', ['-p', 'path/to/tsconfig.json', '-d', 'path/to/customFolder'], 'path/to/project', 'inherit');
65
76
  });
66
77
  });
@@ -1,12 +1,16 @@
1
1
  import { BuilderContext } from '@angular-devkit/architect';
2
+ import { AssetPattern, SourceMapUnion, StyleElement, StylePreprocessorOptions } from '@angular-devkit/build-angular/src/builders/browser/schema';
2
3
  import { LoadOptions, CLIOptions, BuilderOptions } from '@storybook/types';
3
- import { AngularBuilderOptions } from '../../server/framework-preset-angular-cli';
4
4
  export type StandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
5
5
  mode?: 'static' | 'dev';
6
6
  enableProdMode: boolean;
7
7
  angularBrowserTarget?: string | null;
8
- angularBuilderOptions?: AngularBuilderOptions;
8
+ angularBuilderOptions?: Record<string, any> & {
9
+ styles?: StyleElement[];
10
+ stylePreprocessorOptions?: StylePreprocessorOptions;
11
+ assets?: AssetPattern[];
12
+ sourceMap?: SourceMapUnion;
13
+ };
9
14
  angularBuilderContext?: BuilderContext | null;
10
15
  tsConfig?: string;
11
- excludeChunks?: string[];
12
16
  };
@@ -46,13 +46,9 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
46
46
  outputPath: 'noop-out',
47
47
  // Options provided by user
48
48
  ...builderOptions,
49
- styles: builderOptions.styles?.map((style) => typeof style === 'string'
50
- ? {
51
- input: style,
52
- inject: true,
53
- bundleName: style.split('/').pop(),
54
- }
55
- : style),
49
+ styles: builderOptions.styles
50
+ ?.map((style) => (typeof style === 'string' ? style : style.input))
51
+ .filter((style) => typeof style === 'string' || style.inject !== false),
56
52
  // Fixed options
57
53
  optimization: false,
58
54
  namedChunks: false,
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webpackFinal = void 0;
4
4
  const node_logger_1 = require("@storybook/node-logger");
5
5
  const server_errors_1 = require("@storybook/core-events/server-errors");
6
+ const architect_1 = require("@angular-devkit/architect");
7
+ const find_up_1 = require("find-up");
8
+ const core_1 = require("@angular-devkit/core");
6
9
  const angular_cli_webpack_1 = require("./angular-cli-webpack");
7
10
  const module_is_available_1 = require("./utils/module-is-available");
8
11
  async function webpackFinal(baseConfig, options) {
@@ -11,15 +14,58 @@ async function webpackFinal(baseConfig, options) {
11
14
  return baseConfig;
12
15
  }
13
16
  checkForLegacyBuildOptions(options);
17
+ const builderContext = getBuilderContext(options);
18
+ const builderOptions = await getBuilderOptions(options, builderContext);
14
19
  return (0, angular_cli_webpack_1.getWebpackConfig)(baseConfig, {
15
20
  builderOptions: {
16
21
  watch: options.configType === 'DEVELOPMENT',
17
- ...options.angularBuilderOptions,
22
+ ...builderOptions,
18
23
  },
19
- builderContext: options.angularBuilderContext,
24
+ builderContext,
20
25
  });
21
26
  }
22
27
  exports.webpackFinal = webpackFinal;
28
+ /**
29
+ * Get Builder Context
30
+ * If storybook is not start by angular builder create dumb BuilderContext
31
+ */
32
+ function getBuilderContext(options) {
33
+ return (options.angularBuilderContext ??
34
+ {
35
+ target: { project: 'noop-project', builder: '', options: {} },
36
+ workspaceRoot: process.cwd(),
37
+ getProjectMetadata: () => ({}),
38
+ getTargetOptions: () => ({}),
39
+ logger: new core_1.logging.Logger('Storybook'),
40
+ });
41
+ }
42
+ /**
43
+ * Get builder options
44
+ * Merge target options from browser target and from storybook options
45
+ */
46
+ async function getBuilderOptions(options, builderContext) {
47
+ /**
48
+ * Get Browser Target options
49
+ */
50
+ let browserTargetOptions = {};
51
+ if (options.angularBrowserTarget) {
52
+ const browserTarget = (0, architect_1.targetFromTargetString)(options.angularBrowserTarget);
53
+ node_logger_1.logger.info(`=> Using angular browser target options from "${browserTarget.project}:${browserTarget.target}${browserTarget.configuration ? `:${browserTarget.configuration}` : ''}"`);
54
+ browserTargetOptions = await builderContext.getTargetOptions(browserTarget);
55
+ }
56
+ /**
57
+ * Merge target options from browser target options and from storybook options
58
+ */
59
+ const builderOptions = {
60
+ ...browserTargetOptions,
61
+ ...options.angularBuilderOptions,
62
+ tsConfig: options.tsConfig ??
63
+ (0, find_up_1.sync)('tsconfig.json', { cwd: options.configDir }) ??
64
+ browserTargetOptions.tsConfig,
65
+ };
66
+ node_logger_1.logger.info(`=> Using angular project with "tsConfig:${builderOptions.tsConfig}"`);
67
+ return builderOptions;
68
+ }
23
69
  /**
24
70
  * Checks if using legacy configuration that doesn't use builder and logs message referring to migration docs.
25
71
  */
@@ -1,9 +1,13 @@
1
1
  import { Options as CoreOptions } from '@storybook/types';
2
2
  import { BuilderContext } from '@angular-devkit/architect';
3
- import { JsonObject } from '@angular-devkit/core';
3
+ import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
4
+ import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
4
5
  export type PresetOptions = CoreOptions & {
5
6
  angularBrowserTarget?: string | null;
6
- angularBuilderOptions?: JsonObject;
7
+ angularBuilderOptions?: {
8
+ styles?: StyleElement[];
9
+ stylePreprocessorOptions?: StylePreprocessorOptions;
10
+ };
7
11
  angularBuilderContext?: BuilderContext | null;
8
12
  tsConfig?: string;
9
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "8.1.3",
3
+ "version": "8.1.5",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -37,18 +37,18 @@
37
37
  "prep": "rimraf dist && node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/tsc.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@storybook/builder-webpack5": "8.1.3",
41
- "@storybook/client-logger": "8.1.3",
42
- "@storybook/core-common": "8.1.3",
43
- "@storybook/core-events": "8.1.3",
44
- "@storybook/core-server": "8.1.3",
45
- "@storybook/core-webpack": "8.1.3",
46
- "@storybook/docs-tools": "8.1.3",
40
+ "@storybook/builder-webpack5": "8.1.5",
41
+ "@storybook/client-logger": "8.1.5",
42
+ "@storybook/core-common": "8.1.5",
43
+ "@storybook/core-events": "8.1.5",
44
+ "@storybook/core-server": "8.1.5",
45
+ "@storybook/core-webpack": "8.1.5",
46
+ "@storybook/docs-tools": "8.1.5",
47
47
  "@storybook/global": "^5.0.0",
48
- "@storybook/node-logger": "8.1.3",
49
- "@storybook/preview-api": "8.1.3",
50
- "@storybook/telemetry": "8.1.3",
51
- "@storybook/types": "8.1.3",
48
+ "@storybook/node-logger": "8.1.5",
49
+ "@storybook/preview-api": "8.1.5",
50
+ "@storybook/telemetry": "8.1.5",
51
+ "@storybook/types": "8.1.5",
52
52
  "@types/node": "^18.0.0",
53
53
  "@types/react": "^18.0.37",
54
54
  "@types/react-dom": "^18.0.11",
@@ -1,26 +0,0 @@
1
- import { BuilderContext } from '@angular-devkit/architect';
2
- import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
3
- import { AssetPattern, SourceMapUnion, StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
4
- type AngularBuilderOptions = {
5
- stylePreprocessorOptions?: StylePreprocessorOptions;
6
- styles?: StyleElement[];
7
- assets?: AssetPattern[];
8
- sourceMap?: SourceMapUnion;
9
- };
10
- type Options = AngularBuilderOptions & {
11
- browserTarget?: string | null;
12
- tsConfig?: string;
13
- configDir?: string;
14
- };
15
- export declare function setup(options: Options, context: BuilderContext): Promise<{
16
- tsConfig: string;
17
- angularBuilderContext: BuilderContext;
18
- angularBuilderOptions: {
19
- tsConfig: string;
20
- stylePreprocessorOptions?: StylePreprocessorOptions | undefined;
21
- styles?: StyleElement[] | undefined;
22
- assets?: AssetPattern[] | undefined;
23
- sourceMap?: SourceMapUnion | undefined;
24
- };
25
- }>;
26
- export {};
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setup = void 0;
4
- const architect_1 = require("@angular-devkit/architect");
5
- const core_1 = require("@angular-devkit/core");
6
- const find_up_1 = require("find-up");
7
- const node_logger_1 = require("@storybook/node-logger");
8
- async function setup(options, context) {
9
- let browserOptions;
10
- let browserTarget;
11
- if (options.browserTarget) {
12
- browserTarget = (0, architect_1.targetFromTargetString)(options.browserTarget);
13
- browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
14
- }
15
- const tsConfig = options.tsConfig ??
16
- (0, find_up_1.sync)('tsconfig.json', { cwd: options.configDir }) ??
17
- browserOptions.tsConfig;
18
- const angularBuilderContext = getBuilderContext(context);
19
- const angularBuilderOptions = await getBuilderOptions(options.browserTarget, {
20
- ...(options.stylePreprocessorOptions
21
- ? { stylePreprocessorOptions: options.stylePreprocessorOptions }
22
- : {}),
23
- ...(options.styles ? { styles: options.styles } : {}),
24
- ...(options.assets ? { assets: options.assets } : {}),
25
- sourceMap: options.sourceMap ?? false,
26
- }, tsConfig, options.configDir, angularBuilderContext);
27
- return {
28
- tsConfig,
29
- angularBuilderContext,
30
- angularBuilderOptions,
31
- };
32
- }
33
- exports.setup = setup;
34
- /**
35
- * Get Builder Context
36
- * If storybook is not start by angular builder create dumb BuilderContext
37
- */
38
- function getBuilderContext(builderContext) {
39
- return (builderContext ??
40
- {
41
- target: { project: 'noop-project', builder: '', options: {} },
42
- workspaceRoot: process.cwd(),
43
- getProjectMetadata: () => ({}),
44
- getTargetOptions: () => ({}),
45
- logger: new core_1.logging.Logger('Storybook'),
46
- });
47
- }
48
- /**
49
- * Get builder options
50
- * Merge target options from browser target and from storybook options
51
- */
52
- async function getBuilderOptions(angularBrowserTarget, angularBuilderOptions, tsConfig, configDir, builderContext) {
53
- /**
54
- * Get Browser Target options
55
- */
56
- let browserTargetOptions = {};
57
- if (angularBrowserTarget) {
58
- const browserTarget = (0, architect_1.targetFromTargetString)(angularBrowserTarget);
59
- browserTargetOptions = await builderContext.getTargetOptions(browserTarget);
60
- }
61
- /**
62
- * Merge target options from browser target options and from storybook options
63
- */
64
- const builderOptions = {
65
- ...browserTargetOptions,
66
- ...angularBuilderOptions,
67
- tsConfig: tsConfig ?? (0, find_up_1.sync)('tsconfig.json', { cwd: configDir }) ?? browserTargetOptions.tsConfig,
68
- };
69
- node_logger_1.logger.info(`=> Using angular project with "tsConfig:${builderOptions.tsConfig}"`);
70
- return builderOptions;
71
- }