@modern-js/storybook-builder 0.0.0-next-20231114034808 → 0.0.0-next-20231114083144
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/cjs/core.js +57 -3
- package/dist/esm/core.js +56 -0
- package/package.json +10 -10
package/dist/cjs/core.js
CHANGED
@@ -23,16 +23,18 @@ __export(core_exports, {
|
|
23
23
|
module.exports = __toCommonJS(core_exports);
|
24
24
|
var import_builder = require("@modern-js/builder");
|
25
25
|
var import_core = require("@modern-js/core");
|
26
|
-
var import_utils = require("
|
26
|
+
var import_utils = require("@modern-js/utils");
|
27
|
+
var import_utils2 = require("./utils");
|
27
28
|
var import_plugin_storybook = require("./plugin-storybook");
|
28
29
|
async function getCompiler(cwd, builderOptions, options) {
|
29
30
|
const bundler = builderOptions.bundler || "webpack";
|
30
31
|
const { presets } = options;
|
31
32
|
const entries = await presets.apply("entries", []);
|
32
|
-
const res = await (0,
|
33
|
+
const res = await (0, import_utils2.runWithErrorMsg)(() => (0, import_core.loadConfig)(cwd, builderOptions.configPath || (0, import_utils2.getConfigFileName)()), "Failed to load config");
|
33
34
|
const loadedConfig = res ? res.config : {};
|
34
35
|
const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
|
35
|
-
|
36
|
+
await addonAdapter(finalConfig, options);
|
37
|
+
const provider = await (0, import_utils2.getProvider)(bundler, finalConfig);
|
36
38
|
if (!provider) {
|
37
39
|
throw new Error(`@modern-js/builder-${bundler}-provider not found `);
|
38
40
|
}
|
@@ -50,6 +52,58 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
50
52
|
]);
|
51
53
|
return builder.createCompiler();
|
52
54
|
}
|
55
|
+
async function addonAdapter(finalConfig, options) {
|
56
|
+
var _finalConfig, _finalConfig1;
|
57
|
+
const { presets } = options;
|
58
|
+
const babelOptions = await presets.apply("babel", {}, {
|
59
|
+
...options
|
60
|
+
});
|
61
|
+
var _tools;
|
62
|
+
(_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
|
63
|
+
finalConfig.tools.babel = (config) => {
|
64
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
65
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
66
|
+
const replaceOrInsert = (plugin, plugins) => {
|
67
|
+
const pluginName = getPluginName(plugin);
|
68
|
+
const append = [];
|
69
|
+
for (let i = 0; i < plugins.length; i++) {
|
70
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
71
|
+
if (getOptions(plugin)) {
|
72
|
+
import_utils.logger.info("Detected duplicated babel plugin, overrides with the new one");
|
73
|
+
plugins[i] = plugin;
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
append.push(plugin);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
plugins.push(...append);
|
80
|
+
};
|
81
|
+
const currentPlugins = config.plugins || [];
|
82
|
+
for (const plugin of babelOptions.plugins || []) {
|
83
|
+
replaceOrInsert(plugin, currentPlugins);
|
84
|
+
}
|
85
|
+
return {
|
86
|
+
...config,
|
87
|
+
...babelOptions,
|
88
|
+
plugins: currentPlugins,
|
89
|
+
presets: config.presets,
|
90
|
+
overrides: [
|
91
|
+
...config.overrides || [],
|
92
|
+
...babelOptions.overrides || []
|
93
|
+
]
|
94
|
+
};
|
95
|
+
};
|
96
|
+
var _tools1;
|
97
|
+
(_tools1 = (_finalConfig1 = finalConfig).tools) !== null && _tools1 !== void 0 ? _tools1 : _finalConfig1.tools = {};
|
98
|
+
finalConfig.tools.webpack = (0, import_utils.applyOptionsChain)(
|
99
|
+
// @ts-expect-error tools.webpack not present in rspack config, but it's OK, we only
|
100
|
+
finalConfig.tools.webpack,
|
101
|
+
async (defaultConfig) => {
|
102
|
+
const finalDefaultConfig = await presets.apply("webpackFinal", defaultConfig, options);
|
103
|
+
return finalDefaultConfig;
|
104
|
+
}
|
105
|
+
);
|
106
|
+
}
|
53
107
|
// Annotate the CommonJS export names for ESM import in node:
|
54
108
|
0 && (module.exports = {
|
55
109
|
getCompiler
|
package/dist/esm/core.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { createBuilder } from "@modern-js/builder";
|
2
2
|
import { loadConfig } from "@modern-js/core";
|
3
|
+
import { applyOptionsChain, logger } from "@modern-js/utils";
|
3
4
|
import { getConfigFileName, getProvider, runWithErrorMsg } from "./utils";
|
4
5
|
import { pluginStorybook } from "./plugin-storybook";
|
5
6
|
async function getCompiler(cwd, builderOptions, options) {
|
@@ -12,6 +13,7 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
12
13
|
);
|
13
14
|
const loadedConfig = res ? res.config : {};
|
14
15
|
const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
|
16
|
+
await addonAdapter(finalConfig, options);
|
15
17
|
const provider = await getProvider(bundler, finalConfig);
|
16
18
|
if (!provider) {
|
17
19
|
throw new Error(`@modern-js/builder-${bundler}-provider not found `);
|
@@ -30,6 +32,60 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
30
32
|
]);
|
31
33
|
return builder.createCompiler();
|
32
34
|
}
|
35
|
+
async function addonAdapter(finalConfig, options) {
|
36
|
+
var _a, _b;
|
37
|
+
const { presets } = options;
|
38
|
+
const babelOptions = await presets.apply("babel", {}, { ...options });
|
39
|
+
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
40
|
+
finalConfig.tools.babel = (config) => {
|
41
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
42
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
43
|
+
const replaceOrInsert = (plugin, plugins) => {
|
44
|
+
const pluginName = getPluginName(plugin);
|
45
|
+
const append = [];
|
46
|
+
for (let i = 0; i < plugins.length; i++) {
|
47
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
48
|
+
if (getOptions(plugin)) {
|
49
|
+
logger.info(
|
50
|
+
"Detected duplicated babel plugin, overrides with the new one"
|
51
|
+
);
|
52
|
+
plugins[i] = plugin;
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
append.push(plugin);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
plugins.push(...append);
|
59
|
+
};
|
60
|
+
const currentPlugins = config.plugins || [];
|
61
|
+
for (const plugin of babelOptions.plugins || []) {
|
62
|
+
replaceOrInsert(plugin, currentPlugins);
|
63
|
+
}
|
64
|
+
return {
|
65
|
+
...config,
|
66
|
+
...babelOptions,
|
67
|
+
plugins: currentPlugins,
|
68
|
+
presets: config.presets,
|
69
|
+
overrides: [
|
70
|
+
...config.overrides || [],
|
71
|
+
...babelOptions.overrides || []
|
72
|
+
]
|
73
|
+
};
|
74
|
+
};
|
75
|
+
(_b = finalConfig.tools) != null ? _b : finalConfig.tools = {};
|
76
|
+
finalConfig.tools.webpack = applyOptionsChain(
|
77
|
+
// @ts-expect-error tools.webpack not present in rspack config, but it's OK, we only
|
78
|
+
finalConfig.tools.webpack,
|
79
|
+
async (defaultConfig) => {
|
80
|
+
const finalDefaultConfig = await presets.apply(
|
81
|
+
"webpackFinal",
|
82
|
+
defaultConfig,
|
83
|
+
options
|
84
|
+
);
|
85
|
+
return finalDefaultConfig;
|
86
|
+
}
|
87
|
+
);
|
88
|
+
}
|
33
89
|
export {
|
34
90
|
getCompiler
|
35
91
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@modern-js/storybook-builder",
|
3
|
-
"version": "0.0.0-next-
|
3
|
+
"version": "0.0.0-next-20231114083144",
|
4
4
|
"description": "modern.js support for storybook",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -71,11 +71,11 @@
|
|
71
71
|
"serve-static": "^1.14.1",
|
72
72
|
"tinypool": "^0.8.0",
|
73
73
|
"webpack-hot-middleware": "^2.25.4",
|
74
|
-
"@modern-js/builder": "0.0.0-next-
|
75
|
-
"@modern-js/
|
76
|
-
"@modern-js/
|
77
|
-
"@modern-js/
|
78
|
-
"@modern-js/utils": "0.0.0-next-
|
74
|
+
"@modern-js/builder": "0.0.0-next-20231114083144",
|
75
|
+
"@modern-js/core": "0.0.0-next-20231114083144",
|
76
|
+
"@modern-js/builder-shared": "0.0.0-next-20231114083144",
|
77
|
+
"@modern-js/runtime": "0.0.0-next-20231114083144",
|
78
|
+
"@modern-js/utils": "0.0.0-next-20231114083144"
|
79
79
|
},
|
80
80
|
"devDependencies": {
|
81
81
|
"@storybook/types": "^7.5.1",
|
@@ -83,10 +83,10 @@
|
|
83
83
|
"@types/serve-static": "^1.13.10",
|
84
84
|
"@types/webpack-hot-middleware": "^2.25.6",
|
85
85
|
"typescript": "^5.2.2",
|
86
|
-
"@modern-js/
|
87
|
-
"@modern-js/builder-webpack-provider": "0.0.0-next-
|
88
|
-
"@scripts/build": "0.0.0-next-
|
89
|
-
"@modern-js/
|
86
|
+
"@modern-js/core": "0.0.0-next-20231114083144",
|
87
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20231114083144",
|
88
|
+
"@scripts/build": "0.0.0-next-20231114083144",
|
89
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20231114083144"
|
90
90
|
},
|
91
91
|
"publishConfig": {
|
92
92
|
"registry": "https://registry.npmjs.org/",
|