@storybook/angular 7.0.0-alpha.35 → 7.0.0-alpha.38
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/dist/types/client/angular-beta/StorybookModule.d.ts +1 -1
- package/dist/types/client/angular-beta/StorybookModule.js +3 -30
- package/dist/types/client/decorateStory.js +1 -1
- package/dist/types/preset.js +0 -1
- package/dist/types/server/framework-preset-angular-cli.js +1 -20
- package/package.json +30 -28
- package/dist/types/server/angular-cli-webpack-12.2.x.d.ts +0 -1
- package/dist/types/server/angular-cli-webpack-12.2.x.js +0 -66
- package/dist/types/server/angular-cli-webpack-older.d.ts +0 -6
- package/dist/types/server/angular-cli-webpack-older.js +0 -110
- package/dist/types/server/angular-devkit-build-webpack.d.ts +0 -30
- package/dist/types/server/angular-devkit-build-webpack.js +0 -161
- package/dist/types/server/create-fork-ts-checker-plugin.d.ts +0 -3
- package/dist/types/server/create-fork-ts-checker-plugin.js +0 -19
- package/dist/types/server/framework-preset-angular.d.ts +0 -5
- package/dist/types/server/framework-preset-angular.js +0 -103
- package/dist/types/server/ngx-template-loader/index.d.ts +0 -1
- package/dist/types/server/ngx-template-loader/index.js +0 -46
- package/dist/types/server/ts_config.d.ts +0 -2
- package/dist/types/server/ts_config.js +0 -28
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NgModule, Type } from '@angular/core';
|
|
2
2
|
import { Subject } from 'rxjs';
|
|
3
3
|
import { ICollection, StoryFnAngularReturnType } from '../types';
|
|
4
|
-
export declare const getStorybookModuleMetadata: ({ storyFnAngular, component
|
|
4
|
+
export declare const getStorybookModuleMetadata: ({ storyFnAngular, component, targetSelector, }: {
|
|
5
5
|
storyFnAngular: StoryFnAngularReturnType;
|
|
6
6
|
component?: any;
|
|
7
7
|
targetSelector: string;
|
|
@@ -5,41 +5,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
9
|
exports.createStorybookModule = exports.getStorybookModuleMetadata = void 0;
|
|
13
10
|
const core_1 = require("@angular/core");
|
|
14
11
|
const platform_browser_1 = require("@angular/platform-browser");
|
|
15
|
-
const ts_dedent_1 = require("ts-dedent");
|
|
16
|
-
const util_deprecate_1 = __importDefault(require("util-deprecate"));
|
|
17
12
|
const StorybookProvider_1 = require("./StorybookProvider");
|
|
18
13
|
const NgModulesAnalyzer_1 = require("./utils/NgModulesAnalyzer");
|
|
19
14
|
const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
|
|
20
15
|
const StorybookWrapperComponent_1 = require("./StorybookWrapperComponent");
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
or
|
|
25
|
-
\`\`\`
|
|
26
|
-
export const Primary: StoryFn = () => ({});
|
|
27
|
-
Primary.parameters = { component: AppComponent };
|
|
28
|
-
\`\`\`
|
|
29
|
-
Read more at
|
|
30
|
-
- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-angular-story-component).
|
|
31
|
-
- https://storybook.js.org/docs/angular/writing-stories/parameters
|
|
32
|
-
`);
|
|
33
|
-
const getStorybookModuleMetadata = ({ storyFnAngular, component: annotatedComponent, targetSelector, }, storyProps$) => {
|
|
34
|
-
const { component: storyComponent, props, styles, moduleMetadata = {} } = storyFnAngular;
|
|
35
|
-
let { template } = storyFnAngular;
|
|
36
|
-
if (storyComponent) {
|
|
37
|
-
deprecatedStoryComponentWarning();
|
|
38
|
-
}
|
|
39
|
-
const component = storyComponent ?? annotatedComponent;
|
|
40
|
-
if (hasNoTemplate(template) && component) {
|
|
41
|
-
template = (0, ComputesTemplateFromComponent_1.computesTemplateFromComponent)(component, props, '');
|
|
42
|
-
}
|
|
16
|
+
const getStorybookModuleMetadata = ({ storyFnAngular, component, targetSelector, }, storyProps$) => {
|
|
17
|
+
const { props, styles, moduleMetadata = {} } = storyFnAngular;
|
|
18
|
+
const { template } = storyFnAngular;
|
|
43
19
|
/**
|
|
44
20
|
* Create a component that wraps generated template and gives it props
|
|
45
21
|
*/
|
|
@@ -76,6 +52,3 @@ const createStorybookModule = (ngModule) => {
|
|
|
76
52
|
return StorybookModule;
|
|
77
53
|
};
|
|
78
54
|
exports.createStorybookModule = createStorybookModule;
|
|
79
|
-
function hasNoTemplate(template) {
|
|
80
|
-
return template === null || template === undefined;
|
|
81
|
-
}
|
|
@@ -40,7 +40,7 @@ const cleanArgsDecorator = (storyFn, context) => {
|
|
|
40
40
|
context.args = Object.entries(argsToClean).reduce((obj, [key, arg]) => {
|
|
41
41
|
const argType = context.argTypes[key];
|
|
42
42
|
// Only keeps args with a control or an action in argTypes
|
|
43
|
-
if (argType
|
|
43
|
+
if (argType?.action || argType?.control) {
|
|
44
44
|
return { ...obj, [key]: arg };
|
|
45
45
|
}
|
|
46
46
|
return obj;
|
package/dist/types/preset.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.typescript = exports.core = exports.previewAnnotations = exports.addons = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
exports.addons = [
|
|
9
|
-
require.resolve('./server/framework-preset-angular'),
|
|
10
9
|
require.resolve('./server/framework-preset-angular-cli'),
|
|
11
10
|
require.resolve('./server/framework-preset-angular-ivy'),
|
|
12
11
|
require.resolve('./server/framework-preset-angular-docs'),
|
|
@@ -30,13 +30,11 @@ exports.webpackFinal = void 0;
|
|
|
30
30
|
const node_logger_1 = require("@storybook/node-logger");
|
|
31
31
|
const architect_1 = require("@angular-devkit/architect");
|
|
32
32
|
const find_up_1 = require("find-up");
|
|
33
|
-
const semver_1 = __importDefault(require("
|
|
33
|
+
const semver_1 = __importDefault(require("semver"));
|
|
34
34
|
const ts_dedent_1 = require("ts-dedent");
|
|
35
35
|
const core_1 = require("@angular-devkit/core");
|
|
36
36
|
const module_is_available_1 = require("./utils/module-is-available");
|
|
37
|
-
const angular_cli_webpack_12_2_x_1 = require("./angular-cli-webpack-12.2.x");
|
|
38
37
|
const angular_cli_webpack_13_x_x_1 = require("./angular-cli-webpack-13.x.x");
|
|
39
|
-
const angular_cli_webpack_older_1 = require("./angular-cli-webpack-older");
|
|
40
38
|
const angular_read_workspace_1 = require("./angular-read-workspace");
|
|
41
39
|
async function webpackFinal(baseConfig, options) {
|
|
42
40
|
if (!(0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular')) {
|
|
@@ -65,23 +63,6 @@ async function webpackFinal(baseConfig, options) {
|
|
|
65
63
|
});
|
|
66
64
|
},
|
|
67
65
|
},
|
|
68
|
-
{
|
|
69
|
-
info: '=> Loading angular-cli config for angular 12.2.x',
|
|
70
|
-
condition: semver_1.default.satisfies(angularCliVersion, '12.2.x') && options.angularBuilderContext,
|
|
71
|
-
getWebpackConfig: async (_baseConfig, _options) => {
|
|
72
|
-
const builderContext = getBuilderContext(_options);
|
|
73
|
-
const builderOptions = await getBuilderOptions(_options, builderContext);
|
|
74
|
-
return (0, angular_cli_webpack_12_2_x_1.getWebpackConfig)(_baseConfig, {
|
|
75
|
-
builderOptions,
|
|
76
|
-
builderContext,
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
info: '=> Loading angular-cli config for angular lower than 12.2.0',
|
|
82
|
-
condition: true,
|
|
83
|
-
getWebpackConfig: angular_cli_webpack_older_1.getWebpackConfig,
|
|
84
|
-
},
|
|
85
66
|
];
|
|
86
67
|
const webpackGetter = webpackGetterByVersions.find((wg) => wg.condition);
|
|
87
68
|
node_logger_1.logger.info(webpackGetter.info);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/angular",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.38",
|
|
4
4
|
"description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -34,22 +34,22 @@
|
|
|
34
34
|
"prep": "node ../../../scripts/prepare.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
38
|
-
"@storybook/api": "7.0.0-alpha.
|
|
39
|
-
"@storybook/builder-webpack5": "7.0.0-alpha.
|
|
40
|
-
"@storybook/client-logger": "7.0.0-alpha.
|
|
41
|
-
"@storybook/core-client": "7.0.0-alpha.
|
|
42
|
-
"@storybook/core-common": "7.0.0-alpha.
|
|
43
|
-
"@storybook/core-events": "7.0.0-alpha.
|
|
44
|
-
"@storybook/core-server": "7.0.0-alpha.
|
|
45
|
-
"@storybook/csf": "0.0.2--canary.
|
|
46
|
-
"@storybook/docs-tools": "7.0.0-alpha.
|
|
47
|
-
"@storybook/node-logger": "7.0.0-alpha.
|
|
48
|
-
"@storybook/
|
|
49
|
-
"@
|
|
50
|
-
"@types/node": "^14.14.20 || ^16.0.0",
|
|
37
|
+
"@storybook/addons": "7.0.0-alpha.38",
|
|
38
|
+
"@storybook/api": "7.0.0-alpha.38",
|
|
39
|
+
"@storybook/builder-webpack5": "7.0.0-alpha.38",
|
|
40
|
+
"@storybook/client-logger": "7.0.0-alpha.38",
|
|
41
|
+
"@storybook/core-client": "7.0.0-alpha.38",
|
|
42
|
+
"@storybook/core-common": "7.0.0-alpha.38",
|
|
43
|
+
"@storybook/core-events": "7.0.0-alpha.38",
|
|
44
|
+
"@storybook/core-server": "7.0.0-alpha.38",
|
|
45
|
+
"@storybook/csf": "0.0.2--canary.49.258942b.0",
|
|
46
|
+
"@storybook/docs-tools": "7.0.0-alpha.38",
|
|
47
|
+
"@storybook/node-logger": "7.0.0-alpha.38",
|
|
48
|
+
"@storybook/store": "7.0.0-alpha.38",
|
|
49
|
+
"@types/node": "^16.0.0",
|
|
51
50
|
"@types/react": "^16.14.23",
|
|
52
51
|
"@types/react-dom": "^16.9.14",
|
|
52
|
+
"@types/semver": "^7.3.4",
|
|
53
53
|
"autoprefixer": "^9.8.6",
|
|
54
54
|
"core-js": "^3.8.2",
|
|
55
55
|
"find-up": "^5.0.0",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"react-dom": "^16.14.0",
|
|
65
65
|
"read-pkg-up": "^7.0.1",
|
|
66
66
|
"sass-loader": "^12.6.0",
|
|
67
|
+
"semver": "^7.3.7",
|
|
67
68
|
"telejson": "^6.0.8",
|
|
68
69
|
"ts-dedent": "^2.0.0",
|
|
69
70
|
"ts-loader": "^9.2.8",
|
|
@@ -94,20 +95,21 @@
|
|
|
94
95
|
"jest-specific-snapshot": "^5.0.0",
|
|
95
96
|
"tmp": "^0.2.1",
|
|
96
97
|
"typescript": "~4.6.3",
|
|
97
|
-
"webpack": "5"
|
|
98
|
+
"webpack": "5",
|
|
99
|
+
"zone.js": "^0.11.0"
|
|
98
100
|
},
|
|
99
101
|
"peerDependencies": {
|
|
100
|
-
"@angular-devkit/architect": ">=0.
|
|
101
|
-
"@angular-devkit/build-angular": ">=
|
|
102
|
-
"@angular-devkit/core": "
|
|
103
|
-
"@angular/cli": ">=
|
|
104
|
-
"@angular/common": ">=
|
|
105
|
-
"@angular/compiler": ">=
|
|
106
|
-
"@angular/compiler-cli": ">=
|
|
107
|
-
"@angular/core": ">=
|
|
108
|
-
"@angular/forms": ">=
|
|
109
|
-
"@angular/platform-browser": ">=
|
|
110
|
-
"@angular/platform-browser-dynamic": ">=
|
|
102
|
+
"@angular-devkit/architect": ">=0.1300.0",
|
|
103
|
+
"@angular-devkit/build-angular": ">=13.0.0",
|
|
104
|
+
"@angular-devkit/core": ">=13.0.0",
|
|
105
|
+
"@angular/cli": ">=13.0.0",
|
|
106
|
+
"@angular/common": ">=13.0.0",
|
|
107
|
+
"@angular/compiler": ">=13.0.0",
|
|
108
|
+
"@angular/compiler-cli": ">=13.0.0",
|
|
109
|
+
"@angular/core": ">=13.0.0",
|
|
110
|
+
"@angular/forms": ">=13.0.0",
|
|
111
|
+
"@angular/platform-browser": ">=13.0.0",
|
|
112
|
+
"@angular/platform-browser-dynamic": ">=13.0.0",
|
|
111
113
|
"@babel/core": "*",
|
|
112
114
|
"@nrwl/workspace": "14.6.1",
|
|
113
115
|
"rxjs": "^6.0.0 || ^7.4.0",
|
|
@@ -129,5 +131,5 @@
|
|
|
129
131
|
"access": "public"
|
|
130
132
|
},
|
|
131
133
|
"builders": "dist/types/builders/builders.json",
|
|
132
|
-
"gitHead": "
|
|
134
|
+
"gitHead": "438114fcf62a763f0e8c07e2c34890dd987ca431"
|
|
133
135
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function getWebpackConfig(baseConfig: any, { builderOptions, builderContext }: any): Promise<any>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Private angular devkit stuff
|
|
2
|
-
const { generateI18nBrowserWebpackConfigFromContext, } = require('@angular-devkit/build-angular/src/utils/webpack-browser-config');
|
|
3
|
-
const { getCommonConfig, getStylesConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
|
|
4
|
-
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
5
|
-
const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');
|
|
6
|
-
/**
|
|
7
|
-
* Extract webpack config from angular-cli 12.2.x
|
|
8
|
-
* ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
|
|
9
|
-
* FIXME: Try another way with TypeScript on future storybook version (7 maybe 🤞)
|
|
10
|
-
*
|
|
11
|
-
* @param {*} baseConfig Previous webpack config from storybook
|
|
12
|
-
* @param {*} options { builderOptions, builderContext }
|
|
13
|
-
*/
|
|
14
|
-
exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }) => {
|
|
15
|
-
/**
|
|
16
|
-
* Get angular-cli Webpack config
|
|
17
|
-
*/
|
|
18
|
-
const { config: cliConfig } = await generateI18nBrowserWebpackConfigFromContext({
|
|
19
|
-
// Default options
|
|
20
|
-
index: 'noop-index',
|
|
21
|
-
main: 'noop-main',
|
|
22
|
-
outputPath: 'noop-out',
|
|
23
|
-
// Options provided by user
|
|
24
|
-
...builderOptions,
|
|
25
|
-
// Fixed options
|
|
26
|
-
optimization: false,
|
|
27
|
-
namedChunks: false,
|
|
28
|
-
progress: false,
|
|
29
|
-
buildOptimizer: false,
|
|
30
|
-
aot: false,
|
|
31
|
-
}, builderContext, (wco) => [getCommonConfig(wco), getStylesConfig(wco), getTypeScriptConfig(wco)]);
|
|
32
|
-
/**
|
|
33
|
-
* Merge baseConfig Webpack with angular-cli Webpack
|
|
34
|
-
*/
|
|
35
|
-
const entry = [
|
|
36
|
-
...baseConfig.entry,
|
|
37
|
-
...(cliConfig.entry.styles ?? []),
|
|
38
|
-
...(cliConfig.entry.polyfills ?? []),
|
|
39
|
-
];
|
|
40
|
-
// Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
|
|
41
|
-
// because @angular-devkit/build-angular created rules have include/exclude for global style files.
|
|
42
|
-
const rulesExcludingStyles = filterOutStylingRules(baseConfig);
|
|
43
|
-
const module = {
|
|
44
|
-
...baseConfig.module,
|
|
45
|
-
rules: [...cliConfig.module.rules, ...rulesExcludingStyles],
|
|
46
|
-
};
|
|
47
|
-
const plugins = [...(cliConfig.plugins ?? []), ...baseConfig.plugins];
|
|
48
|
-
const resolve = {
|
|
49
|
-
...baseConfig.resolve,
|
|
50
|
-
modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliConfig.resolve.modules])),
|
|
51
|
-
plugins: [
|
|
52
|
-
new TsconfigPathsPlugin({
|
|
53
|
-
configFile: builderOptions.tsConfig,
|
|
54
|
-
mainFields: ['browser', 'module', 'main'],
|
|
55
|
-
}),
|
|
56
|
-
],
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
...baseConfig,
|
|
60
|
-
entry,
|
|
61
|
-
module,
|
|
62
|
-
plugins,
|
|
63
|
-
resolve,
|
|
64
|
-
resolveLoader: cliConfig.resolveLoader,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import webpack, { Configuration } from 'webpack';
|
|
2
|
-
import type { PresetOptions } from './preset-options';
|
|
3
|
-
/**
|
|
4
|
-
* Old way currently support version lower than 12.2.x
|
|
5
|
-
*/
|
|
6
|
-
export declare function getWebpackConfig(baseConfig: webpack.Configuration, options: PresetOptions): Promise<Configuration>;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getWebpackConfig = void 0;
|
|
7
|
-
const node_logger_1 = require("@storybook/node-logger");
|
|
8
|
-
const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
|
|
9
|
-
const architect_1 = require("@angular-devkit/architect");
|
|
10
|
-
const angular_read_workspace_1 = require("./angular-read-workspace");
|
|
11
|
-
const angular_devkit_build_webpack_1 = require("./angular-devkit-build-webpack");
|
|
12
|
-
const filter_out_styling_rules_1 = require("./utils/filter-out-styling-rules");
|
|
13
|
-
/**
|
|
14
|
-
* Old way currently support version lower than 12.2.x
|
|
15
|
-
*/
|
|
16
|
-
async function getWebpackConfig(baseConfig, options) {
|
|
17
|
-
const dirToSearch = process.cwd();
|
|
18
|
-
// Read angular workspace
|
|
19
|
-
let workspaceConfig;
|
|
20
|
-
try {
|
|
21
|
-
workspaceConfig = await (0, angular_read_workspace_1.readAngularWorkspaceConfig)(dirToSearch);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
node_logger_1.logger.error(`=> Could not find angular workspace config (angular.json) on this path "${dirToSearch}"`);
|
|
25
|
-
node_logger_1.logger.info(`=> Fail to load angular-cli config. Using base config`);
|
|
26
|
-
return baseConfig;
|
|
27
|
-
}
|
|
28
|
-
// Find angular project target
|
|
29
|
-
let project;
|
|
30
|
-
let target;
|
|
31
|
-
let confName;
|
|
32
|
-
try {
|
|
33
|
-
// Default behavior when `angularBrowserTarget` are not explicitly defined to null
|
|
34
|
-
if (options.angularBrowserTarget !== null) {
|
|
35
|
-
const browserTarget = options.angularBrowserTarget
|
|
36
|
-
? (0, architect_1.targetFromTargetString)(options.angularBrowserTarget)
|
|
37
|
-
: {
|
|
38
|
-
configuration: undefined,
|
|
39
|
-
project: (0, angular_read_workspace_1.getDefaultProjectName)(workspaceConfig),
|
|
40
|
-
target: 'build',
|
|
41
|
-
};
|
|
42
|
-
const fondProject = (0, angular_read_workspace_1.findAngularProjectTarget)(workspaceConfig, browserTarget.project, browserTarget.target);
|
|
43
|
-
project = fondProject.project;
|
|
44
|
-
target = fondProject.target;
|
|
45
|
-
confName = browserTarget.configuration;
|
|
46
|
-
node_logger_1.logger.info(`=> Using angular project "${browserTarget.project}:${browserTarget.target}${confName ? `:${confName}` : ''}" for configuring Storybook`);
|
|
47
|
-
}
|
|
48
|
-
// Start storybook when only tsConfig is provided.
|
|
49
|
-
if (options.angularBrowserTarget === null && options.tsConfig) {
|
|
50
|
-
node_logger_1.logger.info(`=> Using default angular project with "tsConfig:${options.tsConfig}"`);
|
|
51
|
-
project = { root: '', extensions: {}, targets: undefined };
|
|
52
|
-
target = { builder: '', options: { tsConfig: options.tsConfig } };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
node_logger_1.logger.error(`=> Could not find angular project: ${error.message}`);
|
|
57
|
-
node_logger_1.logger.info(`=> Fail to load angular-cli config. Using base config`);
|
|
58
|
-
return baseConfig;
|
|
59
|
-
}
|
|
60
|
-
// Use angular-cli to get some webpack config
|
|
61
|
-
let angularCliWebpackConfig;
|
|
62
|
-
try {
|
|
63
|
-
angularCliWebpackConfig = await (0, angular_devkit_build_webpack_1.extractAngularCliWebpackConfig)(dirToSearch, project, target, confName);
|
|
64
|
-
node_logger_1.logger.info(`=> Using angular-cli webpack config`);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
node_logger_1.logger.error(`=> Could not get angular cli webpack config`);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
return mergeAngularCliWebpackConfig(angularCliWebpackConfig, baseConfig);
|
|
71
|
-
}
|
|
72
|
-
exports.getWebpackConfig = getWebpackConfig;
|
|
73
|
-
function mergeAngularCliWebpackConfig({ cliCommonWebpackConfig, cliStyleWebpackConfig, tsConfigPath }, baseConfig) {
|
|
74
|
-
// Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
|
|
75
|
-
// because @angular-devkit/build-angular created rules have include/exclude for global style files.
|
|
76
|
-
const rulesExcludingStyles = (0, filter_out_styling_rules_1.filterOutStylingRules)(baseConfig);
|
|
77
|
-
// styleWebpackConfig.entry adds global style files to the webpack context
|
|
78
|
-
const entry = [
|
|
79
|
-
...baseConfig.entry,
|
|
80
|
-
...Object.values(cliStyleWebpackConfig.entry).reduce((acc, item) => acc.concat(item), []),
|
|
81
|
-
];
|
|
82
|
-
const module = {
|
|
83
|
-
...baseConfig.module,
|
|
84
|
-
rules: [...cliStyleWebpackConfig.module.rules, ...rulesExcludingStyles],
|
|
85
|
-
};
|
|
86
|
-
// We use cliCommonConfig plugins to serve static assets files.
|
|
87
|
-
const plugins = [
|
|
88
|
-
...cliStyleWebpackConfig.plugins,
|
|
89
|
-
...cliCommonWebpackConfig.plugins,
|
|
90
|
-
...baseConfig.plugins,
|
|
91
|
-
];
|
|
92
|
-
const resolve = {
|
|
93
|
-
...baseConfig.resolve,
|
|
94
|
-
modules: Array.from(new Set([...baseConfig.resolve.modules, ...cliCommonWebpackConfig.resolve.modules])),
|
|
95
|
-
plugins: [
|
|
96
|
-
new tsconfig_paths_webpack_plugin_1.default({
|
|
97
|
-
configFile: tsConfigPath,
|
|
98
|
-
mainFields: ['browser', 'module', 'main'],
|
|
99
|
-
}),
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
...baseConfig,
|
|
104
|
-
entry,
|
|
105
|
-
module,
|
|
106
|
-
plugins,
|
|
107
|
-
resolve,
|
|
108
|
-
resolveLoader: cliCommonWebpackConfig.resolveLoader,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is to be watched !
|
|
3
|
-
* The code must be compatible from @angular-devkit version 6.1.0 to the latest supported
|
|
4
|
-
*
|
|
5
|
-
* It uses code block of angular cli to extract parts of webpack configuration
|
|
6
|
-
*/
|
|
7
|
-
import { Configuration } from 'webpack';
|
|
8
|
-
import { workspaces } from '@angular-devkit/core';
|
|
9
|
-
export declare type AngularCliWebpackConfig = {
|
|
10
|
-
cliCommonWebpackConfig: {
|
|
11
|
-
plugins: Configuration['plugins'];
|
|
12
|
-
resolve: {
|
|
13
|
-
modules: string[];
|
|
14
|
-
};
|
|
15
|
-
resolveLoader: Configuration['resolveLoader'];
|
|
16
|
-
};
|
|
17
|
-
cliStyleWebpackConfig: {
|
|
18
|
-
entry: Configuration['entry'];
|
|
19
|
-
module: {
|
|
20
|
-
rules: Configuration['module']['rules'];
|
|
21
|
-
};
|
|
22
|
-
plugins: Configuration['plugins'];
|
|
23
|
-
};
|
|
24
|
-
tsConfigPath: string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Uses angular cli to extract webpack configuration.
|
|
28
|
-
* The `AngularCliWebpackConfig` type lists the parts used by storybook
|
|
29
|
-
*/
|
|
30
|
-
export declare function extractAngularCliWebpackConfig(dirToSearch: string, project: workspaces.ProjectDefinition, target: workspaces.TargetDefinition, confName?: string): Promise<AngularCliWebpackConfig>;
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This file is to be watched !
|
|
4
|
-
* The code must be compatible from @angular-devkit version 6.1.0 to the latest supported
|
|
5
|
-
*
|
|
6
|
-
* It uses code block of angular cli to extract parts of webpack configuration
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.extractAngularCliWebpackConfig = void 0;
|
|
36
|
-
const path_1 = __importDefault(require("path"));
|
|
37
|
-
const core_1 = require("@angular-devkit/core");
|
|
38
|
-
const node_1 = require("@angular-devkit/core/node");
|
|
39
|
-
const module_is_available_1 = require("./utils/module-is-available");
|
|
40
|
-
const normalize_asset_patterns_1 = require("./utils/normalize-asset-patterns");
|
|
41
|
-
const normalize_optimization_1 = require("./utils/normalize-optimization");
|
|
42
|
-
const importAngularCliWebpackConfigGenerator = () => {
|
|
43
|
-
let angularWebpackConfig;
|
|
44
|
-
// First we look for webpack config according to directory structure of Angular 11
|
|
45
|
-
if ((0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular/src/webpack/configs')) {
|
|
46
|
-
// eslint-disable-next-line global-require
|
|
47
|
-
angularWebpackConfig = require('@angular-devkit/build-angular/src/webpack/configs');
|
|
48
|
-
}
|
|
49
|
-
// We fallback on directory structure of Angular 10 (and below)
|
|
50
|
-
else if ((0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs')) {
|
|
51
|
-
// eslint-disable-next-line global-require
|
|
52
|
-
angularWebpackConfig = require('@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs');
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new Error('Webpack config not found in "@angular-devkit/build-angular"');
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
getCommonConfig: angularWebpackConfig.getCommonConfig,
|
|
59
|
-
getStylesConfig: angularWebpackConfig.getStylesConfig,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const importAngularCliReadTsconfigUtil = () => {
|
|
63
|
-
// First we look for webpack config according to directory structure of Angular 11
|
|
64
|
-
if ((0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular/src/utils/read-tsconfig')) {
|
|
65
|
-
// eslint-disable-next-line global-require
|
|
66
|
-
return require('@angular-devkit/build-angular/src/utils/read-tsconfig');
|
|
67
|
-
}
|
|
68
|
-
// We fallback on directory structure of Angular 10 (and below)
|
|
69
|
-
if ((0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular/src/angular-cli-files/utilities/read-tsconfig')) {
|
|
70
|
-
// eslint-disable-next-line global-require
|
|
71
|
-
return require('@angular-devkit/build-angular/src/angular-cli-files/utilities/read-tsconfig');
|
|
72
|
-
}
|
|
73
|
-
throw new Error('ReadTsconfig not found in "@angular-devkit/build-angular"');
|
|
74
|
-
};
|
|
75
|
-
const buildWebpackConfigOptions = async (dirToSearch, project, target, confName) => {
|
|
76
|
-
let conf = {};
|
|
77
|
-
if (confName) {
|
|
78
|
-
if (!target.configurations) {
|
|
79
|
-
throw new Error('Missing "configurations" section in project target');
|
|
80
|
-
}
|
|
81
|
-
if (!target.configurations[confName]) {
|
|
82
|
-
throw new Error(`Missing required configuration in project target. Check "${confName}"`);
|
|
83
|
-
}
|
|
84
|
-
conf = target.configurations[confName];
|
|
85
|
-
}
|
|
86
|
-
const projectBuildOptions = { ...target.options, ...conf };
|
|
87
|
-
const requiredOptions = ['tsConfig'];
|
|
88
|
-
if (!requiredOptions.every((key) => !!projectBuildOptions[key])) {
|
|
89
|
-
throw new Error(`Missing required options in project target. Check "${requiredOptions.join(', ')}"`);
|
|
90
|
-
}
|
|
91
|
-
const workspaceRootNormalized = (0, core_1.normalize)(dirToSearch);
|
|
92
|
-
const projectRootNormalized = (0, core_1.resolve)(workspaceRootNormalized, (0, core_1.normalize)(project.root || ''));
|
|
93
|
-
const sourceRootNormalized = project.sourceRoot
|
|
94
|
-
? (0, core_1.resolve)(workspaceRootNormalized, (0, core_1.normalize)(project.sourceRoot))
|
|
95
|
-
: undefined;
|
|
96
|
-
const tsConfigPath = path_1.default.resolve((0, core_1.getSystemPath)(workspaceRootNormalized), projectBuildOptions.tsConfig);
|
|
97
|
-
const tsConfig = await importAngularCliReadTsconfigUtil().readTsconfig(tsConfigPath);
|
|
98
|
-
const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
|
|
99
|
-
const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
|
|
100
|
-
const buildOptions = {
|
|
101
|
-
// Default options
|
|
102
|
-
budgets: [],
|
|
103
|
-
fileReplacements: [],
|
|
104
|
-
main: '',
|
|
105
|
-
outputPath: 'dist/storybook-angular',
|
|
106
|
-
scripts: [],
|
|
107
|
-
sourceMap: {},
|
|
108
|
-
styles: [],
|
|
109
|
-
// Deleted in angular 12. Keep for compatibility with versions lower than angular 12
|
|
110
|
-
lazyModules: [],
|
|
111
|
-
// Project Options
|
|
112
|
-
...projectBuildOptions,
|
|
113
|
-
assets: (0, normalize_asset_patterns_1.normalizeAssetPatterns)(projectBuildOptions.assets || [], workspaceRootNormalized, projectRootNormalized, sourceRootNormalized),
|
|
114
|
-
optimization: (0, normalize_optimization_1.normalizeOptimization)(projectBuildOptions.optimization),
|
|
115
|
-
// Forced options
|
|
116
|
-
statsJson: false,
|
|
117
|
-
// Deleted in angular 12. Keep for compatibility with versions lower than angular 12
|
|
118
|
-
// @ts-expect-error (Converted from ts-ignore)
|
|
119
|
-
forkTypeChecker: false,
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
projectName: 'this-is-just-a-fake-name-for-getting-rid-of-the-error',
|
|
123
|
-
root: (0, core_1.getSystemPath)(workspaceRootNormalized),
|
|
124
|
-
// The dependency of `@angular-devkit/build-angular` to `@angular-devkit/core` is not exactly the same version as the one for storybook (node modules of node modules ^^)
|
|
125
|
-
logger: (0, node_1.createConsoleLogger)(),
|
|
126
|
-
projectRoot: (0, core_1.getSystemPath)(projectRootNormalized),
|
|
127
|
-
sourceRoot: sourceRootNormalized ? (0, core_1.getSystemPath)(sourceRootNormalized) : undefined,
|
|
128
|
-
buildOptions,
|
|
129
|
-
tsConfig,
|
|
130
|
-
tsConfigPath,
|
|
131
|
-
scriptTarget,
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Uses angular cli to extract webpack configuration.
|
|
136
|
-
* The `AngularCliWebpackConfig` type lists the parts used by storybook
|
|
137
|
-
*/
|
|
138
|
-
async function extractAngularCliWebpackConfig(dirToSearch, project, target, confName) {
|
|
139
|
-
const { getCommonConfig, getStylesConfig } = importAngularCliWebpackConfigGenerator();
|
|
140
|
-
const webpackConfigOptions = await buildWebpackConfigOptions(dirToSearch, project, target, confName);
|
|
141
|
-
const cliCommonConfig = getCommonConfig(webpackConfigOptions);
|
|
142
|
-
const cliStyleConfig = getStylesConfig(webpackConfigOptions);
|
|
143
|
-
return {
|
|
144
|
-
cliCommonWebpackConfig: {
|
|
145
|
-
plugins: cliCommonConfig.plugins,
|
|
146
|
-
resolve: {
|
|
147
|
-
modules: cliCommonConfig.resolve?.modules,
|
|
148
|
-
},
|
|
149
|
-
resolveLoader: cliCommonConfig.resolveLoader,
|
|
150
|
-
},
|
|
151
|
-
cliStyleWebpackConfig: {
|
|
152
|
-
entry: cliStyleConfig.entry,
|
|
153
|
-
module: {
|
|
154
|
-
rules: [...cliStyleConfig.module.rules],
|
|
155
|
-
},
|
|
156
|
-
plugins: cliStyleConfig.plugins,
|
|
157
|
-
},
|
|
158
|
-
tsConfigPath: webpackConfigOptions.tsConfigPath,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
exports.extractAngularCliWebpackConfig = extractAngularCliWebpackConfig;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/* eslint-disable func-names */
|
|
7
|
-
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
8
|
-
const node_logger_1 = require("@storybook/node-logger");
|
|
9
|
-
function default_1(tsLoaderOptions) {
|
|
10
|
-
if (tsLoaderOptions && tsLoaderOptions.configFile) {
|
|
11
|
-
return new fork_ts_checker_webpack_plugin_1.default({
|
|
12
|
-
typescript: { configFile: tsLoaderOptions.configFile },
|
|
13
|
-
async: true,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
node_logger_1.logger.info('=> Using default options for ForkTsCheckerWebpackPlugin');
|
|
17
|
-
return new fork_ts_checker_webpack_plugin_1.default();
|
|
18
|
-
}
|
|
19
|
-
exports.default = default_1;
|
|
@@ -1,103 +0,0 @@
|
|
|
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 = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const semver_1 = __importDefault(require("@storybook/semver"));
|
|
32
|
-
const webpack_1 = require("webpack");
|
|
33
|
-
const autoprefixer_1 = __importDefault(require("autoprefixer"));
|
|
34
|
-
const ts_config_1 = __importDefault(require("./ts_config"));
|
|
35
|
-
const create_fork_ts_checker_plugin_1 = __importDefault(require("./create-fork-ts-checker-plugin"));
|
|
36
|
-
async function webpack(config, { configDir, angularBuilderContext }) {
|
|
37
|
-
try {
|
|
38
|
-
// Disable all this webpack stuff if we use angular-cli >= 12
|
|
39
|
-
// Angular cli is in charge of doing all the necessary for angular. If there is any additional configuration to add, it must be done in the preset angular-cli versioned.
|
|
40
|
-
const angularCliVersion = await Promise.resolve().then(() => __importStar(require('@angular/cli'))).then((m) => semver_1.default.coerce(m.VERSION.full));
|
|
41
|
-
if ((semver_1.default.satisfies(angularCliVersion, '12.2.x') && angularBuilderContext) ||
|
|
42
|
-
semver_1.default.satisfies(angularCliVersion, '>=13.0.0')) {
|
|
43
|
-
return config;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
// do nothing, continue
|
|
48
|
-
}
|
|
49
|
-
const tsLoaderOptions = (0, ts_config_1.default)(configDir);
|
|
50
|
-
return {
|
|
51
|
-
...config,
|
|
52
|
-
module: {
|
|
53
|
-
...config.module,
|
|
54
|
-
rules: [
|
|
55
|
-
...config.module.rules,
|
|
56
|
-
{
|
|
57
|
-
test: /\.tsx?$/,
|
|
58
|
-
use: [
|
|
59
|
-
{
|
|
60
|
-
loader: require.resolve('ts-loader'),
|
|
61
|
-
options: tsLoaderOptions,
|
|
62
|
-
},
|
|
63
|
-
{ loader: path_1.default.resolve(__dirname, 'ngx-template-loader') },
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
|
|
68
|
-
parser: { system: false },
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
test: /\.html$/,
|
|
72
|
-
loader: require.resolve('raw-loader'),
|
|
73
|
-
exclude: /\.async\.html$/,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
test: /\.s(c|a)ss$/,
|
|
77
|
-
use: [
|
|
78
|
-
{ loader: require.resolve('raw-loader') },
|
|
79
|
-
{
|
|
80
|
-
loader: require.resolve('postcss-loader'),
|
|
81
|
-
options: {
|
|
82
|
-
postcssOptions: {
|
|
83
|
-
plugins: [(0, autoprefixer_1.default)()],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
{ loader: require.resolve('sass-loader') },
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
resolve: {
|
|
93
|
-
...config.resolve,
|
|
94
|
-
},
|
|
95
|
-
plugins: [
|
|
96
|
-
...config.plugins,
|
|
97
|
-
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
|
|
98
|
-
new webpack_1.ContextReplacementPlugin(/@angular(\\|\/)core(\\|\/)(fesm5|bundles)/, path_1.default.resolve(__dirname, '..')),
|
|
99
|
-
(0, create_fork_ts_checker_plugin_1.default)(tsLoaderOptions),
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
exports.webpack = webpack;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (source: string): string;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* By the time this file was added the repository for angular2-template-loader received no updates in 3 years
|
|
4
|
-
* This is just a copy of https://github.com/TheLarkInn/angular2-template-loader/blob/master/index.js in order
|
|
5
|
-
* to fix a bug that prevents Storybook from updating raw-loader > ^1.0.0
|
|
6
|
-
*
|
|
7
|
-
* As suggested in https://github.com/storybookjs/storybook/issues/7877#issuecomment-536556755 this code was
|
|
8
|
-
* modified to be compatible with newer versions of raw-loader as well as backwards compatible with raw-loader ^1.0.0
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
// using: regex, capture groups, and capture group variables.
|
|
12
|
-
const templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*([,}]))/gm;
|
|
13
|
-
const stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
|
|
14
|
-
const stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;
|
|
15
|
-
const replaceStringsWithRequires = (string) => {
|
|
16
|
-
return string.replace(stringRegex, (match, quote, url) => {
|
|
17
|
-
let newUrl = url;
|
|
18
|
-
if (url.charAt(0) !== '.') {
|
|
19
|
-
newUrl = `./${url}`;
|
|
20
|
-
}
|
|
21
|
-
const requireString = `(require('${newUrl}').default || require('${newUrl}'))`;
|
|
22
|
-
// without the length check an empty style file will throw
|
|
23
|
-
// "Expected 'styles' to be an array of strings"
|
|
24
|
-
return `${requireString}.length ? ${requireString} : ''`;
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
function default_1(source) {
|
|
28
|
-
const styleProperty = 'styles';
|
|
29
|
-
const templateProperty = 'template';
|
|
30
|
-
return source
|
|
31
|
-
.replace(templateUrlRegex, (_, templateUrlString) => {
|
|
32
|
-
// replace: templateUrl: './path/to/template.html'
|
|
33
|
-
// with: template: require('./path/to/template.html')
|
|
34
|
-
// or: templateUrl: require('./path/to/template.html')
|
|
35
|
-
// if `keepUrl` query parameter is set to true.
|
|
36
|
-
return `${templateProperty}:${replaceStringsWithRequires(templateUrlString)}`;
|
|
37
|
-
})
|
|
38
|
-
.replace(stylesRegex, (_, styleUrlsString) => {
|
|
39
|
-
// replace: stylesUrl: ['./foo.css', "./baz.css", "./index.component.css"]
|
|
40
|
-
// with: styles: [require('./foo.css'), require("./baz.css"), require("./index.component.css")]
|
|
41
|
-
// or: styleUrls: [require('./foo.css'), require("./baz.css"), require("./index.component.css")]
|
|
42
|
-
// if `keepUrl` query parameter is set to true.
|
|
43
|
-
return `${styleProperty}:${replaceStringsWithRequires(styleUrlsString)}`;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
exports.default = default_1;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const node_logger_1 = require("@storybook/node-logger");
|
|
9
|
-
function resolveTsConfig(tsConfigPath) {
|
|
10
|
-
if (fs_1.default.existsSync(tsConfigPath)) {
|
|
11
|
-
node_logger_1.logger.info('=> Found custom tsconfig.json');
|
|
12
|
-
return tsConfigPath;
|
|
13
|
-
}
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
function default_1(configDir) {
|
|
17
|
-
const tsLoaderOptions = {
|
|
18
|
-
transpileOnly: true,
|
|
19
|
-
compilerOptions: {
|
|
20
|
-
emitDecoratorMetadata: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const configFilePath = resolveTsConfig(path_1.default.resolve(configDir, 'tsconfig.json'));
|
|
24
|
-
if (configFilePath)
|
|
25
|
-
tsLoaderOptions.configFile = configFilePath;
|
|
26
|
-
return tsLoaderOptions;
|
|
27
|
-
}
|
|
28
|
-
exports.default = default_1;
|