@storybook/angular 0.0.0-pr-23609-sha-f47ef339
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +8 -0
- package/README.md +322 -0
- package/dist/builders/build-storybook/index.js +72 -0
- package/dist/builders/build-storybook/index.spec.d.ts +1 -0
- package/dist/builders/build-storybook/index.spec.js +216 -0
- package/dist/builders/build-storybook/schema.json +167 -0
- package/dist/builders/builders.json +14 -0
- package/dist/builders/start-storybook/index.js +93 -0
- package/dist/builders/start-storybook/index.spec.d.ts +1 -0
- package/dist/builders/start-storybook/index.spec.js +215 -0
- package/dist/builders/start-storybook/schema.json +198 -0
- package/dist/builders/utils/error-handler.d.ts +2 -0
- package/dist/builders/utils/error-handler.js +38 -0
- package/dist/builders/utils/run-compodoc.d.ts +6 -0
- package/dist/builders/utils/run-compodoc.js +58 -0
- package/dist/builders/utils/run-compodoc.spec.d.ts +1 -0
- package/dist/builders/utils/run-compodoc.spec.js +86 -0
- package/dist/builders/utils/standalone-options.d.ts +15 -0
- package/dist/builders/utils/standalone-options.js +2 -0
- package/dist/client/angular-beta/AbstractRenderer.d.ts +53 -0
- package/dist/client/angular-beta/AbstractRenderer.js +180 -0
- package/dist/client/angular-beta/CanvasRenderer.d.ts +13 -0
- package/dist/client/angular-beta/CanvasRenderer.js +16 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.d.ts +17 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.js +132 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.d.ts +1 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +403 -0
- package/dist/client/angular-beta/DocsRenderer.d.ts +13 -0
- package/dist/client/angular-beta/DocsRenderer.js +40 -0
- package/dist/client/angular-beta/RendererFactory.d.ts +11 -0
- package/dist/client/angular-beta/RendererFactory.js +56 -0
- package/dist/client/angular-beta/RendererFactory.test.d.ts +1 -0
- package/dist/client/angular-beta/RendererFactory.test.js +164 -0
- package/dist/client/angular-beta/StorybookModule.d.ts +8 -0
- package/dist/client/angular-beta/StorybookModule.js +29 -0
- package/dist/client/angular-beta/StorybookModule.test.d.ts +1 -0
- package/dist/client/angular-beta/StorybookModule.test.js +311 -0
- package/dist/client/angular-beta/StorybookProvider.d.ts +5 -0
- package/dist/client/angular-beta/StorybookProvider.js +26 -0
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +16 -0
- package/dist/client/angular-beta/StorybookWrapperComponent.js +140 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.d.ts +26 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.js +67 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +2 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.js +20 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.d.ts +29 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +100 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +374 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +6 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +41 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +23 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +32 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.js +162 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +142 -0
- package/dist/client/config.d.ts +6 -0
- package/dist/client/config.js +10 -0
- package/dist/client/decorateStory.d.ts +4 -0
- package/dist/client/decorateStory.js +49 -0
- package/dist/client/decorateStory.test.d.ts +1 -0
- package/dist/client/decorateStory.test.js +304 -0
- package/dist/client/decorators.d.ts +14 -0
- package/dist/client/decorators.js +70 -0
- package/dist/client/decorators.test.d.ts +1 -0
- package/dist/client/decorators.test.js +146 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.d.ts +111 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.js +207 -0
- package/dist/client/docs/__testfixtures__/doc-button/tsconfig.json +7 -0
- package/dist/client/docs/angular-properties.test.d.ts +1 -0
- package/dist/client/docs/angular-properties.test.js +62 -0
- package/dist/client/docs/compodoc.d.ts +12 -0
- package/dist/client/docs/compodoc.js +258 -0
- package/dist/client/docs/compodoc.test.d.ts +1 -0
- package/dist/client/docs/compodoc.test.js +131 -0
- package/dist/client/docs/config.d.ts +4 -0
- package/dist/client/docs/config.js +19 -0
- package/dist/client/docs/index.d.ts +1 -0
- package/dist/client/docs/index.js +17 -0
- package/dist/client/docs/sourceDecorator.d.ts +9 -0
- package/dist/client/docs/sourceDecorator.js +51 -0
- package/dist/client/docs/types.d.ts +102 -0
- package/dist/client/docs/types.js +2 -0
- package/dist/client/globals.d.ts +23 -0
- package/dist/client/globals.js +40 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +30 -0
- package/dist/client/preview-prod.d.ts +1 -0
- package/dist/client/preview-prod.js +4 -0
- package/dist/client/public-api.d.ts +15 -0
- package/dist/client/public-api.js +36 -0
- package/dist/client/public-types.d.ts +37 -0
- package/dist/client/public-types.js +2 -0
- package/dist/client/render.d.ts +7 -0
- package/dist/client/render.js +19 -0
- package/dist/client/types.d.ts +46 -0
- package/dist/client/types.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +29 -0
- package/dist/index.mjs +13 -0
- package/dist/preset.d.ts +6 -0
- package/dist/preset.js +36 -0
- package/dist/preset.mjs +30 -0
- package/dist/renderer.d.ts +6 -0
- package/dist/renderer.js +15 -0
- package/dist/renderer.mjs +6 -0
- package/dist/server/__mocks-ng-workspace__/empty-projects-entry/angular.json +4 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/some-config/angular.json +19 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/some-config/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/angular.json +64 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/angular.json +28 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/tsconfig.lib.json +20 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/nx.json +3 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/tsconfig.app.json +8 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/tsconfig.json +14 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/nx.json +3 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/tsconfig.app.json +8 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/tsconfig.json +14 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/workspace.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/angular.json +18 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/without-architect-build/angular.json +5 -0
- package/dist/server/__mocks-ng-workspace__/without-architect-build-options/angular.json +11 -0
- package/dist/server/__mocks-ng-workspace__/without-compatible-projects/angular.json +7 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/angular.json +3 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/tsconfig.lib.json +20 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/tsconfig.json +13 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/angular.json +16 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.d.ts +1 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.js +5 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/tsconfig.app.json +9 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/tsconfig.json +13 -0
- package/dist/server/__tests__/angular.json +96 -0
- package/dist/server/angular-cli-webpack.d.ts +1 -0
- package/dist/server/angular-cli-webpack.js +99 -0
- package/dist/server/framework-preset-angular-cli.d.ts +4 -0
- package/dist/server/framework-preset-angular-cli.js +85 -0
- package/dist/server/framework-preset-angular-docs.d.ts +2 -0
- package/dist/server/framework-preset-angular-docs.js +10 -0
- package/dist/server/framework-preset-angular-ivy.d.ts +10 -0
- package/dist/server/framework-preset-angular-ivy.js +103 -0
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.d.ts +25 -0
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +48 -0
- package/dist/server/preset-options.d.ts +13 -0
- package/dist/server/preset-options.js +2 -0
- package/dist/server/utils/filter-out-styling-rules.d.ts +2 -0
- package/dist/server/utils/filter-out-styling-rules.js +17 -0
- package/dist/server/utils/module-is-available.d.ts +1 -0
- package/dist/server/utils/module-is-available.js +13 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/jest.config.js +31 -0
- package/package.json +126 -0
- package/preset.js +1 -0
- package/renderer.d.ts +1 -0
- package/renderer.js +1 -0
- package/src/server/angular-cli-webpack.d.ts +7 -0
- package/src/server/angular-cli-webpack.js +127 -0
- package/src/server/plugins/storybook-normalize-angular-entry-plugin.js +54 -0
- package/src/typings.d.ts +21 -0
- package/template/cli/.eslintrc.json +5 -0
- package/template/cli/Button.stories.ts +51 -0
- package/template/cli/Header.stories.ts +37 -0
- package/template/cli/Page.stories.ts +46 -0
- package/template/cli/User.ts +2 -0
- package/template/cli/button.component.ts +55 -0
- package/template/cli/header.component.ts +75 -0
- package/template/cli/page.component.ts +77 -0
- package/template/components/button.component.ts +54 -0
- package/template/components/button.css +30 -0
- package/template/components/form.component.ts +37 -0
- package/template/components/html.component.ts +22 -0
- package/template/components/index.js +8 -0
- package/template/components/pre.component.ts +29 -0
- package/template/stories/angular-mdx.stories.mdx +25 -0
- package/template/stories/argTypes/doc-button/doc-button.component.html +7 -0
- package/template/stories/argTypes/doc-button/doc-button.component.scss +3 -0
- package/template/stories/argTypes/doc-button/doc-button.component.ts +232 -0
- package/template/stories/argTypes/doc-button/doc-button.stories.ts +24 -0
- package/template/stories/argTypes/doc-directive/doc-directive.directive.ts +24 -0
- package/template/stories/argTypes/doc-directive/doc-directive.stories.ts +14 -0
- package/template/stories/argTypes/doc-injectable/doc-injectable.service.ts +27 -0
- package/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts +17 -0
- package/template/stories/argTypes/doc-pipe/doc-pipe.pipe.ts +18 -0
- package/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts +17 -0
- package/template/stories/basics/README.stories.mdx +7 -0
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts +27 -0
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva.component.ts +57 -0
- package/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts +19 -0
- package/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.ts +19 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-class-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.stories.ts +8 -0
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.ts +37 -0
- package/template/stories/basics/component-with-enums/enums.component.html +8 -0
- package/template/stories/basics/component-with-enums/enums.component.stories.ts +24 -0
- package/template/stories/basics/component-with-enums/enums.component.ts +53 -0
- package/template/stories/basics/component-with-inheritance/base-button.component.ts +10 -0
- package/template/stories/basics/component-with-inheritance/base-button.stories.ts +12 -0
- package/template/stories/basics/component-with-inheritance/icon-button.component.ts +11 -0
- package/template/stories/basics/component-with-inheritance/icon-button.stories.ts +13 -0
- package/template/stories/basics/component-with-ng-content/ng-content-about-parent.stories.ts +58 -0
- package/template/stories/basics/component-with-ng-content/ng-content-simple.stories.ts +29 -0
- package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts +40 -0
- package/template/stories/basics/component-with-on-push/on-push-box.component.ts +21 -0
- package/template/stories/basics/component-with-on-push/on-push.stories.ts +21 -0
- package/template/stories/basics/component-with-pipe/custom-pipes.stories.ts +31 -0
- package/template/stories/basics/component-with-pipe/custom.pipe.ts +10 -0
- package/template/stories/basics/component-with-pipe/with-pipe.component.ts +10 -0
- package/template/stories/basics/component-with-provider/di.component.html +7 -0
- package/template/stories/basics/component-with-provider/di.component.stories.ts +26 -0
- package/template/stories/basics/component-with-provider/di.component.ts +28 -0
- package/template/stories/basics/component-with-style/styled.component.css +3 -0
- package/template/stories/basics/component-with-style/styled.component.html +5 -0
- package/template/stories/basics/component-with-style/styled.component.scss +5 -0
- package/template/stories/basics/component-with-style/styled.component.stories.ts +10 -0
- package/template/stories/basics/component-with-style/styled.component.ts +8 -0
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +73 -0
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +71 -0
- package/template/stories/basics/component-without-selector/without-selector.component.ts +30 -0
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +30 -0
- package/template/stories/basics/ng-module/angular-src/chip-color.token.ts +3 -0
- package/template/stories/basics/ng-module/angular-src/chip-text.pipe.ts +29 -0
- package/template/stories/basics/ng-module/angular-src/chip.component.ts +60 -0
- package/template/stories/basics/ng-module/angular-src/chips-group.component.ts +49 -0
- package/template/stories/basics/ng-module/angular-src/chips.module.ts +31 -0
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
- package/template/stories/basics/ng-module/import-module-for-root.stories.ts +50 -0
- package/template/stories/basics/ng-module/import-module.stories.ts +35 -0
- package/template/stories/button.component.ts +26 -0
- package/template/stories/core/README.stories.mdx +7 -0
- package/template/stories/core/applicationConfig/with-browser-animations.stories.ts +40 -0
- package/template/stories/core/applicationConfig/with-noop-browser-animations.stories.ts +35 -0
- package/template/stories/core/decorators/componentWrapperDecorator/child.component.ts +20 -0
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +99 -0
- package/template/stories/core/decorators/componentWrapperDecorator/parent.component.ts +18 -0
- package/template/stories/core/decorators/theme-decorator/decorators.stories.ts +20 -0
- package/template/stories/core/moduleMetadata/angular-src/custom.pipe.ts +10 -0
- package/template/stories/core/moduleMetadata/angular-src/dummy.service.ts +14 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +13 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +7 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +39 -0
- package/template/stories/core/moduleMetadata/angular-src/service.component.ts +24 -0
- package/template/stories/core/moduleMetadata/angular-src/token.component.ts +31 -0
- package/template/stories/core/moduleMetadata/in-export-default.stories.ts +38 -0
- package/template/stories/core/moduleMetadata/in-stories.stories.ts +46 -0
- package/template/stories/core/moduleMetadata/merge-default-and-story.stories.ts +35 -0
- package/template/stories/core/parameters/bootstrap-options.stories.ts +18 -0
- package/template/stories/core/styles/story-styles.stories.ts +50 -0
- package/template/stories/others/app-initializer-use-factory/app-initializer-use-factory.stories.ts +34 -0
- package/template/stories/others/issues/12009-unknown-component.stories.ts +14 -0
- package/template/stories/others/ngx-translate/README.stories.mdx +65 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
import { PresetOptions } from './preset-options';
|
|
3
|
+
/**
|
|
4
|
+
* Run ngcc for converting modules to ivy format before starting storybook
|
|
5
|
+
* This step is needed in order to support Ivy in storybook
|
|
6
|
+
*
|
|
7
|
+
* Information about Ivy can be found here https://angular.io/guide/ivy
|
|
8
|
+
*/
|
|
9
|
+
export declare const runNgcc: () => Promise<void>;
|
|
10
|
+
export declare const webpack: (webpackConfig: Configuration, options: PresetOptions) => Promise<Configuration>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.webpack = exports.runNgcc = void 0;
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
const fs_1 = __importDefault(require("fs"));
|
|
32
|
+
/**
|
|
33
|
+
* Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23
|
|
34
|
+
* This uses a dynamic import to load a module which may be ESM.
|
|
35
|
+
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
|
|
36
|
+
* will currently, unconditionally downlevel dynamic import into a require call.
|
|
37
|
+
* require calls cannot load ESM code and will result in a runtime error. To workaround
|
|
38
|
+
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
|
|
39
|
+
* Once TypeScript provides support for keeping the dynamic import this workaround can
|
|
40
|
+
* be dropped.
|
|
41
|
+
*
|
|
42
|
+
* @param modulePath The path of the module to load.
|
|
43
|
+
* @returns A Promise that resolves to the dynamically imported module.
|
|
44
|
+
*/
|
|
45
|
+
function loadEsmModule(modulePath) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
47
|
+
return new Function('modulePath', `return import(modulePath);`)(modulePath);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run ngcc for converting modules to ivy format before starting storybook
|
|
51
|
+
* This step is needed in order to support Ivy in storybook
|
|
52
|
+
*
|
|
53
|
+
* Information about Ivy can be found here https://angular.io/guide/ivy
|
|
54
|
+
*/
|
|
55
|
+
const runNgcc = async () => {
|
|
56
|
+
let ngcc;
|
|
57
|
+
try {
|
|
58
|
+
// eslint-disable-next-line global-require
|
|
59
|
+
ngcc = require('@angular/compiler-cli/ngcc');
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
ngcc = await loadEsmModule('@angular/compiler-cli/ngcc');
|
|
63
|
+
}
|
|
64
|
+
ngcc.process({
|
|
65
|
+
// should be async: true but does not work due to
|
|
66
|
+
// https://github.com/storybookjs/storybook/pull/11157/files#r615413803
|
|
67
|
+
async: false,
|
|
68
|
+
basePath: path.join(process.cwd(), 'node_modules'),
|
|
69
|
+
createNewEntryPointFormats: true,
|
|
70
|
+
compileAllFormats: false, // --first-only
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.runNgcc = runNgcc;
|
|
74
|
+
const webpack = async (webpackConfig, options) => {
|
|
75
|
+
const packageJsonPath = require.resolve('@angular/core/package.json');
|
|
76
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
77
|
+
const VERSION = packageJson.version;
|
|
78
|
+
const framework = await options.presets.apply('framework');
|
|
79
|
+
const angularOptions = (typeof framework === 'object' ? framework.options : {});
|
|
80
|
+
const angularMajorVersion = VERSION.split('.')[0];
|
|
81
|
+
const isAngular16OrNewer = parseInt(angularMajorVersion, 10) >= 16;
|
|
82
|
+
// Default to true, if undefined
|
|
83
|
+
if (angularOptions.enableIvy === false) {
|
|
84
|
+
return webpackConfig;
|
|
85
|
+
}
|
|
86
|
+
let extraMainFields = [];
|
|
87
|
+
if (angularOptions.enableNgcc !== false && !isAngular16OrNewer) {
|
|
88
|
+
// TODO: Drop if Angular 14 and 15 are not supported anymore
|
|
89
|
+
(0, exports.runNgcc)();
|
|
90
|
+
extraMainFields = ['es2015_ivy_ngcc', 'module_ivy_ngcc', 'main_ivy_ngcc'];
|
|
91
|
+
}
|
|
92
|
+
if (!isAngular16OrNewer) {
|
|
93
|
+
extraMainFields.push('es2015');
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...webpackConfig,
|
|
97
|
+
resolve: {
|
|
98
|
+
...webpackConfig.resolve,
|
|
99
|
+
mainFields: [...extraMainFields, 'browser', 'module', 'main'],
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
exports.webpack = webpack;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js
|
|
3
|
+
* transforms the original webpackOptions.entry point array into a structure like this:
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* {
|
|
7
|
+
* main: {
|
|
8
|
+
* import: [...]
|
|
9
|
+
* },
|
|
10
|
+
*
|
|
11
|
+
* styles: {
|
|
12
|
+
* import: [...]
|
|
13
|
+
* },
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded.
|
|
18
|
+
* To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js).
|
|
19
|
+
*/
|
|
20
|
+
export default class StorybookNormalizeAngularEntryPlugin {
|
|
21
|
+
constructor(options: any);
|
|
22
|
+
options: any;
|
|
23
|
+
apply(compiler: any): void;
|
|
24
|
+
compilation: any;
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const PLUGIN_NAME = 'storybook-normalize-angular-entry-plugin';
|
|
4
|
+
/**
|
|
5
|
+
* Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js
|
|
6
|
+
* transforms the original webpackOptions.entry point array into a structure like this:
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* {
|
|
10
|
+
* main: {
|
|
11
|
+
* import: [...]
|
|
12
|
+
* },
|
|
13
|
+
*
|
|
14
|
+
* styles: {
|
|
15
|
+
* import: [...]
|
|
16
|
+
* },
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded.
|
|
21
|
+
* To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js).
|
|
22
|
+
*/
|
|
23
|
+
class StorybookNormalizeAngularEntryPlugin {
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
apply(compiler) {
|
|
28
|
+
compiler.hooks.environment.tap(PLUGIN_NAME, () => {
|
|
29
|
+
const webpackOptions = compiler.options;
|
|
30
|
+
const entry = typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;
|
|
31
|
+
webpackOptions.entry = async () => {
|
|
32
|
+
const entryResult = await entry;
|
|
33
|
+
if (entryResult.main && entryResult.styles) {
|
|
34
|
+
return {
|
|
35
|
+
main: {
|
|
36
|
+
import: Array.from(new Set([...entryResult.main.import, ...entryResult.styles.import])),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return entry;
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
44
|
+
this.compilation = compilation;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = StorybookNormalizeAngularEntryPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Options as CoreOptions } from '@storybook/types';
|
|
2
|
+
import { BuilderContext } from '@angular-devkit/architect';
|
|
3
|
+
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
4
|
+
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
|
+
export type PresetOptions = CoreOptions & {
|
|
6
|
+
angularBrowserTarget?: string | null;
|
|
7
|
+
angularBuilderOptions?: {
|
|
8
|
+
styles?: StyleElement[];
|
|
9
|
+
stylePreprocessorOptions?: StylePreprocessorOptions;
|
|
10
|
+
};
|
|
11
|
+
angularBuilderContext?: BuilderContext | null;
|
|
12
|
+
tsConfig?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterOutStylingRules = void 0;
|
|
4
|
+
const isStylingRule = (rule) => {
|
|
5
|
+
const { test } = rule;
|
|
6
|
+
if (!test) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (!(test instanceof RegExp)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return test.test('.css') || test.test('.scss') || test.test('.sass');
|
|
13
|
+
};
|
|
14
|
+
const filterOutStylingRules = (config) => {
|
|
15
|
+
return config.module.rules.filter((rule) => !isStylingRule(rule));
|
|
16
|
+
};
|
|
17
|
+
exports.filterOutStylingRules = filterOutStylingRules;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const moduleIsAvailable: (moduleName: string) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moduleIsAvailable = void 0;
|
|
4
|
+
const moduleIsAvailable = (moduleName) => {
|
|
5
|
+
try {
|
|
6
|
+
require.resolve(moduleName);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.moduleIsAvailable = moduleIsAvailable;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StorybookConfig as StorybookConfigBase, TypescriptOptions as TypescriptOptionsReact } from '@storybook/core-webpack';
|
|
2
|
+
import { StorybookConfigWebpack, BuilderOptions, TypescriptOptions as TypescriptOptionsBuilder } from '@storybook/builder-webpack5';
|
|
3
|
+
type FrameworkName = '@storybook/angular';
|
|
4
|
+
type BuilderName = '@storybook/builder-webpack5';
|
|
5
|
+
export type FrameworkOptions = AngularOptions & {
|
|
6
|
+
builder?: BuilderOptions;
|
|
7
|
+
};
|
|
8
|
+
type StorybookConfigFramework = {
|
|
9
|
+
framework: FrameworkName | {
|
|
10
|
+
name: FrameworkName;
|
|
11
|
+
options: FrameworkOptions;
|
|
12
|
+
};
|
|
13
|
+
core?: StorybookConfigBase['core'] & {
|
|
14
|
+
builder?: BuilderName | {
|
|
15
|
+
name: BuilderName;
|
|
16
|
+
options: BuilderOptions;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
typescript?: Partial<TypescriptOptionsBuilder & TypescriptOptionsReact> & StorybookConfigBase['typescript'];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The interface for Storybook configuration in `main.ts` files.
|
|
23
|
+
*/
|
|
24
|
+
export type StorybookConfig = Omit<StorybookConfigBase, keyof StorybookConfigWebpack | keyof StorybookConfigFramework> & StorybookConfigWebpack & StorybookConfigFramework;
|
|
25
|
+
export interface AngularOptions {
|
|
26
|
+
enableIvy?: boolean;
|
|
27
|
+
enableNgcc?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
package/dist/types.js
ADDED
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
|
|
5
|
+
preset: 'jest-preset-angular/presets/defaults-esm',
|
|
6
|
+
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
|
|
7
|
+
transformIgnorePatterns: ['/node_modules/(?!@angular|rxjs|nanoid|uuid)'],
|
|
8
|
+
snapshotFormat: {
|
|
9
|
+
escapeString: true,
|
|
10
|
+
printBasicPrototype: true,
|
|
11
|
+
},
|
|
12
|
+
coverageDirectory: './coverage/testapp',
|
|
13
|
+
transform: {
|
|
14
|
+
'^.+\\.(ts|mjs|js|html)$': [
|
|
15
|
+
'jest-preset-angular',
|
|
16
|
+
{
|
|
17
|
+
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
18
|
+
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
snapshotSerializers: [
|
|
23
|
+
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
24
|
+
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
25
|
+
'jest-preset-angular/build/serializers/html-comment',
|
|
26
|
+
],
|
|
27
|
+
testMatch: [
|
|
28
|
+
'<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
|
|
29
|
+
'<rootDir>/src/**/?(*.)+(spec|test).[jt]s?(x)',
|
|
30
|
+
],
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storybook/angular",
|
|
3
|
+
"version": "0.0.0-pr-23609-sha-f47ef339",
|
|
4
|
+
"description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"storybook",
|
|
7
|
+
"angular"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/storybookjs/storybook/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/storybookjs/storybook.git",
|
|
16
|
+
"directory": "code/frameworks/angular"
|
|
17
|
+
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "opencollective",
|
|
20
|
+
"url": "https://opencollective.com/storybook"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"module": "dist/index.mjs",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/**/*",
|
|
28
|
+
"template/**/*",
|
|
29
|
+
"README.md",
|
|
30
|
+
"*.js",
|
|
31
|
+
"*.mjs",
|
|
32
|
+
"*.d.ts"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"check": "../../../scripts/node_modules/.bin/tsc",
|
|
36
|
+
"prep": "../../../scripts/prepare/tsc.ts"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@storybook/builder-webpack5": "0.0.0-pr-23609-sha-f47ef339",
|
|
40
|
+
"@storybook/cli": "0.0.0-pr-23609-sha-f47ef339",
|
|
41
|
+
"@storybook/client-logger": "0.0.0-pr-23609-sha-f47ef339",
|
|
42
|
+
"@storybook/core-common": "0.0.0-pr-23609-sha-f47ef339",
|
|
43
|
+
"@storybook/core-events": "0.0.0-pr-23609-sha-f47ef339",
|
|
44
|
+
"@storybook/core-server": "0.0.0-pr-23609-sha-f47ef339",
|
|
45
|
+
"@storybook/core-webpack": "0.0.0-pr-23609-sha-f47ef339",
|
|
46
|
+
"@storybook/docs-tools": "0.0.0-pr-23609-sha-f47ef339",
|
|
47
|
+
"@storybook/global": "^5.0.0",
|
|
48
|
+
"@storybook/manager-api": "0.0.0-pr-23609-sha-f47ef339",
|
|
49
|
+
"@storybook/node-logger": "0.0.0-pr-23609-sha-f47ef339",
|
|
50
|
+
"@storybook/preview-api": "0.0.0-pr-23609-sha-f47ef339",
|
|
51
|
+
"@storybook/telemetry": "0.0.0-pr-23609-sha-f47ef339",
|
|
52
|
+
"@storybook/types": "0.0.0-pr-23609-sha-f47ef339",
|
|
53
|
+
"@types/node": "^16.0.0",
|
|
54
|
+
"@types/react": "^16.14.34",
|
|
55
|
+
"@types/react-dom": "^16.9.14",
|
|
56
|
+
"@types/semver": "^7.3.4",
|
|
57
|
+
"@types/webpack-env": "^1.18.0",
|
|
58
|
+
"find-up": "^5.0.0",
|
|
59
|
+
"read-pkg-up": "^7.0.1",
|
|
60
|
+
"semver": "^7.3.7",
|
|
61
|
+
"telejson": "^7.0.3",
|
|
62
|
+
"ts-dedent": "^2.0.0",
|
|
63
|
+
"tsconfig-paths-webpack-plugin": "^4.0.1",
|
|
64
|
+
"util-deprecate": "^1.0.2",
|
|
65
|
+
"webpack": "5"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@angular-devkit/architect": "^0.1600.0-rc.4",
|
|
69
|
+
"@angular-devkit/build-angular": "^16.0.0-rc.4",
|
|
70
|
+
"@angular-devkit/core": "^16.0.0-rc.4",
|
|
71
|
+
"@angular/animations": "^16.0.0-rc.4",
|
|
72
|
+
"@angular/cli": "^16.0.0-rc.4",
|
|
73
|
+
"@angular/common": "^16.0.0-rc.4",
|
|
74
|
+
"@angular/compiler": "^16.0.0-rc.4",
|
|
75
|
+
"@angular/compiler-cli": "^16.0.0-rc.4",
|
|
76
|
+
"@angular/core": "^16.0.0-rc.4",
|
|
77
|
+
"@angular/forms": "^16.0.0-rc.4",
|
|
78
|
+
"@angular/platform-browser": "^16.0.0-rc.4",
|
|
79
|
+
"@angular/platform-browser-dynamic": "^16.0.0-rc.4",
|
|
80
|
+
"@types/cross-spawn": "^6.0.2",
|
|
81
|
+
"@types/tmp": "^0.2.3",
|
|
82
|
+
"cross-spawn": "^7.0.3",
|
|
83
|
+
"jest": "^29.3.1",
|
|
84
|
+
"jest-preset-angular": "^13.0.1",
|
|
85
|
+
"jest-specific-snapshot": "^8.0.0",
|
|
86
|
+
"tmp": "^0.2.1",
|
|
87
|
+
"typescript": "^5.0.4",
|
|
88
|
+
"webpack": "5",
|
|
89
|
+
"zone.js": "^0.13.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"@angular-devkit/architect": ">=0.1400.0 < 0.1700.0",
|
|
93
|
+
"@angular-devkit/build-angular": ">=14.1.0 < 17.0.0",
|
|
94
|
+
"@angular-devkit/core": ">=14.1.0 < 17.0.0",
|
|
95
|
+
"@angular/cli": ">=14.1.0 < 17.0.0",
|
|
96
|
+
"@angular/common": ">=14.1.0 < 17.0.0",
|
|
97
|
+
"@angular/compiler": ">=14.1.0 < 17.0.0",
|
|
98
|
+
"@angular/compiler-cli": ">=14.1.0 < 17.0.0",
|
|
99
|
+
"@angular/core": ">=14.1.0 < 17.0.0",
|
|
100
|
+
"@angular/forms": ">=14.1.0 < 17.0.0",
|
|
101
|
+
"@angular/platform-browser": ">=14.1.0 < 17.0.0",
|
|
102
|
+
"@angular/platform-browser-dynamic": ">=14.1.0 < 17.0.0",
|
|
103
|
+
"@babel/core": "*",
|
|
104
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
105
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
106
|
+
"rxjs": "^6.0.0 || ^7.4.0",
|
|
107
|
+
"typescript": "^4.0.0 || ^5.0.0",
|
|
108
|
+
"zone.js": "^0.8.29 || >= 0.9.0 < 1.0.0"
|
|
109
|
+
},
|
|
110
|
+
"peerDependenciesMeta": {
|
|
111
|
+
"@angular/cli": {
|
|
112
|
+
"optional": true
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"engines": {
|
|
116
|
+
"node": ">=16.0.0"
|
|
117
|
+
},
|
|
118
|
+
"publishConfig": {
|
|
119
|
+
"access": "public"
|
|
120
|
+
},
|
|
121
|
+
"builders": "dist/builders/builders.json",
|
|
122
|
+
"bundler": {
|
|
123
|
+
"tsConfig": "tsconfig.build.json"
|
|
124
|
+
},
|
|
125
|
+
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
|
|
126
|
+
}
|
package/preset.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/preset');
|
package/renderer.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/renderer.d';
|
package/renderer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/renderer');
|
|
@@ -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
|
+
}
|
package/src/typings.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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: import('@storybook/types').StorybookConfig['features'];
|
|
16
|
+
|
|
17
|
+
declare var IS_STORYBOOK: any;
|
|
18
|
+
declare var LOGLEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' | undefined;
|
|
19
|
+
declare var STORIES: any;
|
|
20
|
+
declare var STORYBOOK_ENV: 'angular';
|
|
21
|
+
declare var STORYBOOK_HOOKS_CONTEXT: any;
|