@storybook/angular 7.0.20 → 7.0.22
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/server/angular-cli-webpack.js +24 -1
- package/dist/server/framework-preset-angular-ivy.js +2 -2
- package/package.json +16 -16
- 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 +26 -0
|
@@ -1,9 +1,31 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
1
2
|
// Private angular devkit stuff
|
|
2
3
|
const { generateI18nBrowserWebpackConfigFromContext, } = require('@angular-devkit/build-angular/src/utils/webpack-browser-config');
|
|
3
|
-
const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
|
|
4
4
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
5
5
|
const { filterOutStylingRules } = require('./utils/filter-out-styling-rules');
|
|
6
6
|
const { default: StorybookNormalizeAngularEntryPlugin, } = require('./plugins/storybook-normalize-angular-entry-plugin');
|
|
7
|
+
const getAngularWebpackUtils = () => {
|
|
8
|
+
try {
|
|
9
|
+
// Angular < 16.1.0
|
|
10
|
+
const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/webpack/configs');
|
|
11
|
+
return {
|
|
12
|
+
getCommonConfig,
|
|
13
|
+
getStylesConfig,
|
|
14
|
+
getDevServerConfig,
|
|
15
|
+
getTypeScriptConfig,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
// Angular > 16.1.0
|
|
20
|
+
const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig, } = require('@angular-devkit/build-angular/src/tools/webpack/configs');
|
|
21
|
+
return {
|
|
22
|
+
getCommonConfig,
|
|
23
|
+
getStylesConfig,
|
|
24
|
+
getDevServerConfig,
|
|
25
|
+
getTypeScriptConfig,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
7
29
|
/**
|
|
8
30
|
* Extract webpack config from angular-cli 13.x.x
|
|
9
31
|
* ⚠️ This file is in JavaScript to not use TypeScript. Because current storybook TypeScript version is not compatible with Angular CLI.
|
|
@@ -16,6 +38,7 @@ exports.getWebpackConfig = async (baseConfig, { builderOptions, builderContext }
|
|
|
16
38
|
/**
|
|
17
39
|
* Get angular-cli Webpack config
|
|
18
40
|
*/
|
|
41
|
+
const { getCommonConfig, getStylesConfig, getDevServerConfig, getTypeScriptConfig } = getAngularWebpackUtils();
|
|
19
42
|
const { config: cliConfig } = await generateI18nBrowserWebpackConfigFromContext({
|
|
20
43
|
// Default options
|
|
21
44
|
index: 'noop-index',
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.webpack = exports.runNgcc = void 0;
|
|
27
|
-
const core_1 = require("@angular/core");
|
|
28
27
|
const path = __importStar(require("path"));
|
|
29
28
|
/**
|
|
30
29
|
* Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23
|
|
@@ -69,9 +68,10 @@ const runNgcc = async () => {
|
|
|
69
68
|
};
|
|
70
69
|
exports.runNgcc = runNgcc;
|
|
71
70
|
const webpack = async (webpackConfig, options) => {
|
|
71
|
+
const { VERSION } = await loadEsmModule('@angular/core');
|
|
72
72
|
const framework = await options.presets.apply('framework');
|
|
73
73
|
const angularOptions = (typeof framework === 'object' ? framework.options : {});
|
|
74
|
-
const isAngular16OrNewer = parseInt(
|
|
74
|
+
const isAngular16OrNewer = parseInt(VERSION.major, 10) >= 16;
|
|
75
75
|
// Default to true, if undefined
|
|
76
76
|
if (angularOptions.enableIvy === false) {
|
|
77
77
|
return webpackConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/angular",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.22",
|
|
4
4
|
"description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"prep": "../../../scripts/prepare/tsc.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@storybook/builder-webpack5": "7.0.
|
|
40
|
-
"@storybook/cli": "7.0.
|
|
41
|
-
"@storybook/client-logger": "7.0.
|
|
42
|
-
"@storybook/core-client": "7.0.
|
|
43
|
-
"@storybook/core-common": "7.0.
|
|
44
|
-
"@storybook/core-events": "7.0.
|
|
45
|
-
"@storybook/core-server": "7.0.
|
|
46
|
-
"@storybook/core-webpack": "7.0.
|
|
47
|
-
"@storybook/docs-tools": "7.0.
|
|
39
|
+
"@storybook/builder-webpack5": "7.0.22",
|
|
40
|
+
"@storybook/cli": "7.0.22",
|
|
41
|
+
"@storybook/client-logger": "7.0.22",
|
|
42
|
+
"@storybook/core-client": "7.0.22",
|
|
43
|
+
"@storybook/core-common": "7.0.22",
|
|
44
|
+
"@storybook/core-events": "7.0.22",
|
|
45
|
+
"@storybook/core-server": "7.0.22",
|
|
46
|
+
"@storybook/core-webpack": "7.0.22",
|
|
47
|
+
"@storybook/docs-tools": "7.0.22",
|
|
48
48
|
"@storybook/global": "^5.0.0",
|
|
49
|
-
"@storybook/manager-api": "7.0.
|
|
50
|
-
"@storybook/node-logger": "7.0.
|
|
51
|
-
"@storybook/preview-api": "7.0.
|
|
52
|
-
"@storybook/telemetry": "7.0.
|
|
53
|
-
"@storybook/types": "7.0.
|
|
49
|
+
"@storybook/manager-api": "7.0.22",
|
|
50
|
+
"@storybook/node-logger": "7.0.22",
|
|
51
|
+
"@storybook/preview-api": "7.0.22",
|
|
52
|
+
"@storybook/telemetry": "7.0.22",
|
|
53
|
+
"@storybook/types": "7.0.22",
|
|
54
54
|
"@types/node": "^16.0.0",
|
|
55
55
|
"@types/react": "^16.14.34",
|
|
56
56
|
"@types/react-dom": "^16.9.14",
|
|
@@ -125,4 +125,4 @@
|
|
|
125
125
|
"tsConfig": "tsconfig.build.json"
|
|
126
126
|
},
|
|
127
127
|
"gitHead": "9fb2573aa274f3f69d3358050e8df9c903e8245f"
|
|
128
|
-
}
|
|
128
|
+
}
|
|
@@ -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,26 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle, @typescript-eslint/naming-convention */
|
|
2
|
+
|
|
3
|
+
// will be provided by the webpack define plugin
|
|
4
|
+
declare var NODE_ENV: string | undefined;
|
|
5
|
+
|
|
6
|
+
declare var __STORYBOOK_ADDONS_CHANNEL__: any;
|
|
7
|
+
declare var __STORYBOOK_ADDONS_PREVIEW: any;
|
|
8
|
+
declare var __STORYBOOK_COMPODOC_JSON__: any;
|
|
9
|
+
declare var __STORYBOOK_CLIENT_API__: any;
|
|
10
|
+
declare var __STORYBOOK_PREVIEW__: any;
|
|
11
|
+
declare var __STORYBOOK_STORY_STORE__: any;
|
|
12
|
+
declare var CHANNEL_OPTIONS: any;
|
|
13
|
+
declare var DOCS_OPTIONS: any;
|
|
14
|
+
|
|
15
|
+
declare var FEATURES:
|
|
16
|
+
| {
|
|
17
|
+
storyStoreV7?: boolean;
|
|
18
|
+
argTypeTargetsV7?: boolean;
|
|
19
|
+
}
|
|
20
|
+
| undefined;
|
|
21
|
+
|
|
22
|
+
declare var IS_STORYBOOK: any;
|
|
23
|
+
declare var LOGLEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' | undefined;
|
|
24
|
+
declare var STORIES: any;
|
|
25
|
+
declare var STORYBOOK_ENV: 'angular';
|
|
26
|
+
declare var STORYBOOK_HOOKS_CONTEXT: any;
|