@modern-js/storybook-builder 0.0.0-next-20240131181000 → 0.0.0-next-20240207100605
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/build.js +1 -1
- package/dist/cjs/core.js +7 -11
- package/dist/cjs/plugin-storybook.js +52 -48
- package/dist/cjs/types.js +4 -2
- package/dist/cjs/utils.js +0 -20
- package/dist/esm/build.js +1 -1
- package/dist/esm/core.js +12 -20
- package/dist/esm/plugin-storybook.js +52 -49
- package/dist/esm/types.js +3 -1
- package/dist/esm/utils.js +0 -19
- package/dist/types/core.d.ts +1 -1
- package/dist/types/docgen/index.d.ts +1 -2
- package/dist/types/plugin-storybook.d.ts +4 -4
- package/dist/types/preset.d.ts +2 -2
- package/dist/types/types.d.ts +6 -9
- package/dist/types/utils.d.ts +0 -4
- package/package.json +17 -30
package/dist/cjs/build.js
CHANGED
@@ -35,7 +35,7 @@ __export(build_exports, {
|
|
35
35
|
});
|
36
36
|
module.exports = __toCommonJS(build_exports);
|
37
37
|
var import_path = require("path");
|
38
|
-
var import_webpack_dev_middleware = __toESM(require("@
|
38
|
+
var import_webpack_dev_middleware = __toESM(require("@rsbuild/shared/webpack-dev-middleware"));
|
39
39
|
var import_webpack_hot_middleware = __toESM(require("webpack-hot-middleware"));
|
40
40
|
var import_serve_static = __toESM(require("serve-static"));
|
41
41
|
var import_utils = require("@modern-js/utils");
|
package/dist/cjs/core.js
CHANGED
@@ -21,7 +21,8 @@ __export(core_exports, {
|
|
21
21
|
getCompiler: () => getCompiler
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(core_exports);
|
24
|
-
var
|
24
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
25
|
+
var import_shared = require("@rsbuild/shared");
|
25
26
|
var import_core = require("@modern-js/core");
|
26
27
|
var import_utils = require("./utils");
|
27
28
|
var import_plugin_storybook = require("./plugin-storybook");
|
@@ -32,18 +33,13 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
32
33
|
const res = await (0, import_utils.runWithErrorMsg)(() => (0, import_core.loadConfig)(cwd, builderOptions.configPath || (0, import_utils.getConfigFileName)()), "Failed to load config");
|
33
34
|
const loadedConfig = res ? res.config : {};
|
34
35
|
const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
} else {
|
40
|
-
throw new Error(`Please install one provider first, try install @modern-js/builder-rspack-provider or @modern-js/builder-webpack-provider first`);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
const builder = await (0, import_builder.createBuilder)(provider, {
|
36
|
+
const uniBuilderConfig = builderOptions.builderConfig ? (0, import_shared.mergeRsbuildConfig)(finalConfig, builderOptions.builderConfig) : finalConfig || {};
|
37
|
+
const bundlerType = bundler || "webpack";
|
38
|
+
const builder = await (0, import_uni_builder.createUniBuilder)({
|
39
|
+
bundlerType,
|
44
40
|
cwd,
|
45
41
|
target: "web",
|
46
|
-
|
42
|
+
config: bundlerType === "webpack" ? await (0, import_plugin_storybook.addonBabelAdapter)(uniBuilderConfig, options) : uniBuilderConfig,
|
47
43
|
entry: {
|
48
44
|
main: entries
|
49
45
|
}
|
@@ -28,15 +28,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var plugin_storybook_exports = {};
|
30
30
|
__export(plugin_storybook_exports, {
|
31
|
+
addonBabelAdapter: () => addonBabelAdapter,
|
31
32
|
finalize: () => finalize,
|
32
33
|
pluginStorybook: () => pluginStorybook
|
33
34
|
});
|
34
35
|
module.exports = __toCommonJS(plugin_storybook_exports);
|
35
36
|
var import_path = require("path");
|
36
37
|
var import_utils = require("@modern-js/utils");
|
37
|
-
var import_builder_shared = require("@modern-js/builder-shared");
|
38
38
|
var import_core_common = require("@storybook/core-common");
|
39
39
|
var import_globals = require("@storybook/preview/globals");
|
40
|
+
var import_shared = require("@rsbuild/shared");
|
40
41
|
var import_csf_plugin = require("@storybook/csf-plugin");
|
41
42
|
var import_minimatch = require("minimatch");
|
42
43
|
var import_utils2 = require("./utils");
|
@@ -68,7 +69,7 @@ const pluginStorybook = (cwd, options) => {
|
|
68
69
|
const absolutePattern = (0, import_path.isAbsolute)(pattern) ? pattern : (0, import_path.join)(options.configDir, pattern);
|
69
70
|
return absolutePattern;
|
70
71
|
});
|
71
|
-
api.
|
72
|
+
api.modifyRsbuildConfig(async (builderConfig) => {
|
72
73
|
await prepareStorybookModules(api.context.cachePath, cwd, options, builderConfig, storyPatterns);
|
73
74
|
await applyDefines(builderConfig, options);
|
74
75
|
await applyHTML(builderConfig, options);
|
@@ -83,7 +84,7 @@ const pluginStorybook = (cwd, options) => {
|
|
83
84
|
await applyMdxLoader(config, options);
|
84
85
|
await applyCsfPlugin(config, options);
|
85
86
|
};
|
86
|
-
if ("
|
87
|
+
if (api.context.bundlerType === "webpack") {
|
87
88
|
addonAdapter(api, options);
|
88
89
|
api.modifyWebpackConfig(modifyConfig);
|
89
90
|
api.modifyWebpackChain(async (chain) => {
|
@@ -248,7 +249,7 @@ async function applyMdxLoader(config, options) {
|
|
248
249
|
}
|
249
250
|
function applyExternals(builderConfig) {
|
250
251
|
var _builderConfig_output;
|
251
|
-
const config = (0,
|
252
|
+
const config = (0, import_shared.mergeRsbuildConfig)({
|
252
253
|
output: {
|
253
254
|
...builderConfig.output,
|
254
255
|
externals: (_builderConfig_output = builderConfig.output) === null || _builderConfig_output === void 0 ? void 0 : _builderConfig_output.externals
|
@@ -334,57 +335,60 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
334
335
|
}
|
335
336
|
function addonAdapter(api, options) {
|
336
337
|
const { presets } = options;
|
337
|
-
api.modifyBuilderConfig(async (finalConfig) => {
|
338
|
-
var _finalConfig;
|
339
|
-
const babelOptions = await presets.apply("babel", {}, {
|
340
|
-
...options
|
341
|
-
});
|
342
|
-
var _tools;
|
343
|
-
(_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
|
344
|
-
const userConfig = finalConfig.tools.babel;
|
345
|
-
finalConfig.tools.babel = (config, utils) => {
|
346
|
-
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
347
|
-
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
348
|
-
const replaceOrInsert = (plugin, plugins) => {
|
349
|
-
const pluginName = getPluginName(plugin);
|
350
|
-
for (let i = 0; i < plugins.length; i++) {
|
351
|
-
if (getPluginName(plugins[i]) === pluginName) {
|
352
|
-
if (getOptions(plugin)) {
|
353
|
-
import_utils.logger.info(`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`);
|
354
|
-
plugins[i] = plugin;
|
355
|
-
}
|
356
|
-
return;
|
357
|
-
}
|
358
|
-
}
|
359
|
-
plugins.push(plugin);
|
360
|
-
};
|
361
|
-
const currentPlugins = config.plugins || [];
|
362
|
-
const currentPresets = config.presets || [];
|
363
|
-
for (const plugin of babelOptions.plugins || []) {
|
364
|
-
replaceOrInsert(plugin, currentPlugins);
|
365
|
-
}
|
366
|
-
for (const preset of babelOptions.presets || []) {
|
367
|
-
replaceOrInsert(preset, currentPresets);
|
368
|
-
}
|
369
|
-
const finalConfig2 = {
|
370
|
-
...babelOptions,
|
371
|
-
plugins: currentPlugins,
|
372
|
-
presets: currentPresets
|
373
|
-
};
|
374
|
-
if (userConfig) {
|
375
|
-
return (0, import_utils.applyOptionsChain)(finalConfig2, userConfig, utils);
|
376
|
-
} else {
|
377
|
-
return finalConfig2;
|
378
|
-
}
|
379
|
-
};
|
380
|
-
});
|
381
338
|
api.modifyWebpackConfig(async (config) => {
|
382
339
|
const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
|
383
340
|
return finalDefaultConfig;
|
384
341
|
});
|
385
342
|
}
|
343
|
+
async function addonBabelAdapter(finalConfig, options) {
|
344
|
+
var _finalConfig;
|
345
|
+
const { presets } = options;
|
346
|
+
const babelOptions = await presets.apply("babel", {}, {
|
347
|
+
...options
|
348
|
+
});
|
349
|
+
var _tools;
|
350
|
+
(_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
|
351
|
+
const userConfig = finalConfig.tools.babel;
|
352
|
+
finalConfig.tools.babel = (config, utils) => {
|
353
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
354
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
355
|
+
const replaceOrInsert = (plugin, plugins) => {
|
356
|
+
const pluginName = getPluginName(plugin);
|
357
|
+
for (let i = 0; i < plugins.length; i++) {
|
358
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
359
|
+
if (getOptions(plugin)) {
|
360
|
+
import_utils.logger.info(`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`);
|
361
|
+
plugins[i] = plugin;
|
362
|
+
}
|
363
|
+
return;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
plugins.push(plugin);
|
367
|
+
};
|
368
|
+
const currentPlugins = config.plugins || [];
|
369
|
+
const currentPresets = config.presets || [];
|
370
|
+
for (const plugin of babelOptions.plugins || []) {
|
371
|
+
replaceOrInsert(plugin, currentPlugins);
|
372
|
+
}
|
373
|
+
for (const preset of babelOptions.presets || []) {
|
374
|
+
replaceOrInsert(preset, currentPresets);
|
375
|
+
}
|
376
|
+
const finalConfig2 = {
|
377
|
+
...babelOptions,
|
378
|
+
plugins: currentPlugins,
|
379
|
+
presets: currentPresets
|
380
|
+
};
|
381
|
+
if (userConfig) {
|
382
|
+
return (0, import_utils.applyOptionsChain)(finalConfig2, userConfig, utils);
|
383
|
+
} else {
|
384
|
+
return finalConfig2;
|
385
|
+
}
|
386
|
+
};
|
387
|
+
return finalConfig;
|
388
|
+
}
|
386
389
|
// Annotate the CommonJS export names for ESM import in node:
|
387
390
|
0 && (module.exports = {
|
391
|
+
addonBabelAdapter,
|
388
392
|
finalize,
|
389
393
|
pluginStorybook
|
390
394
|
});
|
package/dist/cjs/types.js
CHANGED
@@ -18,10 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
19
|
var types_exports = {};
|
20
20
|
__export(types_exports, {
|
21
|
-
defineConfig: () =>
|
21
|
+
defineConfig: () => defineConfig
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(types_exports);
|
24
|
-
|
24
|
+
function defineConfig(config) {
|
25
|
+
return config;
|
26
|
+
}
|
25
27
|
// Annotate the CommonJS export names for ESM import in node:
|
26
28
|
0 && (module.exports = {
|
27
29
|
defineConfig
|
package/dist/cjs/utils.js
CHANGED
@@ -33,7 +33,6 @@ __export(utils_exports, {
|
|
33
33
|
VIRTUAL_MODULE_BASE: () => VIRTUAL_MODULE_BASE,
|
34
34
|
getAbsolutePath: () => getAbsolutePath,
|
35
35
|
getConfigFileName: () => getConfigFileName,
|
36
|
-
getProvider: () => getProvider,
|
37
36
|
isDev: () => isDev,
|
38
37
|
maybeGetAbsolutePath: () => maybeGetAbsolutePath,
|
39
38
|
requireResolve: () => requireResolve,
|
@@ -52,24 +51,6 @@ const requireResolve = (importer, path2) => {
|
|
52
51
|
const require1 = (0, import_node_module.createRequire)(importer);
|
53
52
|
require1.resolve(path2);
|
54
53
|
};
|
55
|
-
async function getProvider(bundler, builderConfig) {
|
56
|
-
try {
|
57
|
-
if (bundler === "webpack") {
|
58
|
-
const { builderWebpackProvider } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-webpack-provider")));
|
59
|
-
return builderWebpackProvider({
|
60
|
-
builderConfig
|
61
|
-
});
|
62
|
-
} else if (bundler === "rspack") {
|
63
|
-
const { builderRspackProvider } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-rspack-provider")));
|
64
|
-
return builderRspackProvider({
|
65
|
-
builderConfig
|
66
|
-
});
|
67
|
-
} else {
|
68
|
-
return await getProvider("webpack", builderConfig) || await getProvider("rspack", builderConfig);
|
69
|
-
}
|
70
|
-
} catch (e) {
|
71
|
-
}
|
72
|
-
}
|
73
54
|
async function virtualModule(tempDir, cwd, virtualModuleMap) {
|
74
55
|
import_utils.fs.ensureDirSync(tempDir);
|
75
56
|
const alias = {};
|
@@ -148,7 +129,6 @@ function getConfigFileName() {
|
|
148
129
|
VIRTUAL_MODULE_BASE,
|
149
130
|
getAbsolutePath,
|
150
131
|
getConfigFileName,
|
151
|
-
getProvider,
|
152
132
|
isDev,
|
153
133
|
maybeGetAbsolutePath,
|
154
134
|
requireResolve,
|
package/dist/esm/build.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { dirname, join, parse } from "path";
|
2
|
-
import webpackDevMiddleware from "@
|
2
|
+
import webpackDevMiddleware from "@rsbuild/shared/webpack-dev-middleware";
|
3
3
|
import webpackHotMiddleware from "webpack-hot-middleware";
|
4
4
|
import serveStatic from "serve-static";
|
5
5
|
import { fs } from "@modern-js/utils";
|
package/dist/esm/core.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { createUniBuilder } from "@modern-js/uni-builder";
|
2
|
+
import { mergeRsbuildConfig } from "@rsbuild/shared";
|
2
3
|
import { loadConfig } from "@modern-js/core";
|
3
|
-
import { getConfigFileName,
|
4
|
-
import { pluginStorybook } from "./plugin-storybook";
|
4
|
+
import { getConfigFileName, runWithErrorMsg } from "./utils";
|
5
|
+
import { pluginStorybook, addonBabelAdapter } from "./plugin-storybook";
|
5
6
|
async function getCompiler(cwd, builderOptions, options) {
|
6
7
|
const { bundler } = builderOptions;
|
7
8
|
const { presets } = options;
|
@@ -12,25 +13,16 @@ 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;
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
);
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
`You choose to use ${bundler}, but @modern-js/builder-${bundler}-provider not found in your project, please install it`
|
23
|
-
);
|
24
|
-
} else {
|
25
|
-
throw new Error(
|
26
|
-
`Please install one provider first, try install @modern-js/builder-rspack-provider or @modern-js/builder-webpack-provider first`
|
27
|
-
);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
const builder = await createBuilder(provider, {
|
16
|
+
const uniBuilderConfig = builderOptions.builderConfig ? mergeRsbuildConfig(
|
17
|
+
finalConfig,
|
18
|
+
builderOptions.builderConfig
|
19
|
+
) : finalConfig || {};
|
20
|
+
const bundlerType = bundler || "webpack";
|
21
|
+
const builder = await createUniBuilder({
|
22
|
+
bundlerType,
|
31
23
|
cwd,
|
32
24
|
target: "web",
|
33
|
-
|
25
|
+
config: bundlerType === "webpack" ? await addonBabelAdapter(uniBuilderConfig, options) : uniBuilderConfig,
|
34
26
|
entry: {
|
35
27
|
main: entries
|
36
28
|
}
|
@@ -6,9 +6,6 @@ import {
|
|
6
6
|
applyOptionsChain,
|
7
7
|
logger
|
8
8
|
} from "@modern-js/utils";
|
9
|
-
import {
|
10
|
-
mergeBuilderConfig
|
11
|
-
} from "@modern-js/builder-shared";
|
12
9
|
import {
|
13
10
|
normalizeStories,
|
14
11
|
stringifyProcessEnvs,
|
@@ -17,6 +14,9 @@ import {
|
|
17
14
|
loadPreviewOrConfigFile
|
18
15
|
} from "@storybook/core-common";
|
19
16
|
import { globalsNameReferenceMap } from "@storybook/preview/globals";
|
17
|
+
import {
|
18
|
+
mergeRsbuildConfig
|
19
|
+
} from "@rsbuild/shared";
|
20
20
|
import { unplugin as csfPlugin } from "@storybook/csf-plugin";
|
21
21
|
import { minimatch } from "minimatch";
|
22
22
|
import {
|
@@ -53,7 +53,7 @@ const pluginStorybook = (cwd, options) => {
|
|
53
53
|
const absolutePattern = isAbsolute(pattern) ? pattern : join(options.configDir, pattern);
|
54
54
|
return absolutePattern;
|
55
55
|
});
|
56
|
-
api.
|
56
|
+
api.modifyRsbuildConfig(async (builderConfig) => {
|
57
57
|
await prepareStorybookModules(
|
58
58
|
api.context.cachePath,
|
59
59
|
cwd,
|
@@ -73,7 +73,7 @@ const pluginStorybook = (cwd, options) => {
|
|
73
73
|
await applyMdxLoader(config, options);
|
74
74
|
await applyCsfPlugin(config, options);
|
75
75
|
};
|
76
|
-
if ("
|
76
|
+
if (api.context.bundlerType === "webpack") {
|
77
77
|
addonAdapter(api, options);
|
78
78
|
api.modifyWebpackConfig(modifyConfig);
|
79
79
|
api.modifyWebpackChain(async (chain) => {
|
@@ -254,7 +254,7 @@ async function applyMdxLoader(config, options) {
|
|
254
254
|
}
|
255
255
|
function applyExternals(builderConfig) {
|
256
256
|
var _a;
|
257
|
-
const config =
|
257
|
+
const config = mergeRsbuildConfig(
|
258
258
|
{
|
259
259
|
output: {
|
260
260
|
...builderConfig.output,
|
@@ -358,49 +358,6 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
358
358
|
}
|
359
359
|
function addonAdapter(api, options) {
|
360
360
|
const { presets } = options;
|
361
|
-
api.modifyBuilderConfig(async (finalConfig) => {
|
362
|
-
var _a;
|
363
|
-
const babelOptions = await presets.apply("babel", {}, { ...options });
|
364
|
-
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
365
|
-
const userConfig = finalConfig.tools.babel;
|
366
|
-
finalConfig.tools.babel = (config, utils) => {
|
367
|
-
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
368
|
-
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
369
|
-
const replaceOrInsert = (plugin, plugins) => {
|
370
|
-
const pluginName = getPluginName(plugin);
|
371
|
-
for (let i = 0; i < plugins.length; i++) {
|
372
|
-
if (getPluginName(plugins[i]) === pluginName) {
|
373
|
-
if (getOptions(plugin)) {
|
374
|
-
logger.info(
|
375
|
-
`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`
|
376
|
-
);
|
377
|
-
plugins[i] = plugin;
|
378
|
-
}
|
379
|
-
return;
|
380
|
-
}
|
381
|
-
}
|
382
|
-
plugins.push(plugin);
|
383
|
-
};
|
384
|
-
const currentPlugins = config.plugins || [];
|
385
|
-
const currentPresets = config.presets || [];
|
386
|
-
for (const plugin of babelOptions.plugins || []) {
|
387
|
-
replaceOrInsert(plugin, currentPlugins);
|
388
|
-
}
|
389
|
-
for (const preset of babelOptions.presets || []) {
|
390
|
-
replaceOrInsert(preset, currentPresets);
|
391
|
-
}
|
392
|
-
const finalConfig2 = {
|
393
|
-
...babelOptions,
|
394
|
-
plugins: currentPlugins,
|
395
|
-
presets: currentPresets
|
396
|
-
};
|
397
|
-
if (userConfig) {
|
398
|
-
return applyOptionsChain(finalConfig2, userConfig, utils);
|
399
|
-
} else {
|
400
|
-
return finalConfig2;
|
401
|
-
}
|
402
|
-
};
|
403
|
-
});
|
404
361
|
api.modifyWebpackConfig(async (config) => {
|
405
362
|
const finalDefaultConfig = await presets.apply(
|
406
363
|
"webpackFinal",
|
@@ -410,7 +367,53 @@ function addonAdapter(api, options) {
|
|
410
367
|
return finalDefaultConfig;
|
411
368
|
});
|
412
369
|
}
|
370
|
+
async function addonBabelAdapter(finalConfig, options) {
|
371
|
+
var _a;
|
372
|
+
const { presets } = options;
|
373
|
+
const babelOptions = await presets.apply("babel", {}, { ...options });
|
374
|
+
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
375
|
+
const userConfig = finalConfig.tools.babel;
|
376
|
+
finalConfig.tools.babel = (config, utils) => {
|
377
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
378
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
379
|
+
const replaceOrInsert = (plugin, plugins) => {
|
380
|
+
const pluginName = getPluginName(plugin);
|
381
|
+
for (let i = 0; i < plugins.length; i++) {
|
382
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
383
|
+
if (getOptions(plugin)) {
|
384
|
+
logger.info(
|
385
|
+
`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`
|
386
|
+
);
|
387
|
+
plugins[i] = plugin;
|
388
|
+
}
|
389
|
+
return;
|
390
|
+
}
|
391
|
+
}
|
392
|
+
plugins.push(plugin);
|
393
|
+
};
|
394
|
+
const currentPlugins = config.plugins || [];
|
395
|
+
const currentPresets = config.presets || [];
|
396
|
+
for (const plugin of babelOptions.plugins || []) {
|
397
|
+
replaceOrInsert(plugin, currentPlugins);
|
398
|
+
}
|
399
|
+
for (const preset of babelOptions.presets || []) {
|
400
|
+
replaceOrInsert(preset, currentPresets);
|
401
|
+
}
|
402
|
+
const finalConfig2 = {
|
403
|
+
...babelOptions,
|
404
|
+
plugins: currentPlugins,
|
405
|
+
presets: currentPresets
|
406
|
+
};
|
407
|
+
if (userConfig) {
|
408
|
+
return applyOptionsChain(finalConfig2, userConfig, utils);
|
409
|
+
} else {
|
410
|
+
return finalConfig2;
|
411
|
+
}
|
412
|
+
};
|
413
|
+
return finalConfig;
|
414
|
+
}
|
413
415
|
export {
|
416
|
+
addonBabelAdapter,
|
414
417
|
finalize,
|
415
418
|
pluginStorybook
|
416
419
|
};
|
package/dist/esm/types.js
CHANGED
package/dist/esm/utils.js
CHANGED
@@ -8,24 +8,6 @@ const requireResolve = (importer, path2) => {
|
|
8
8
|
const require2 = createRequire(importer);
|
9
9
|
require2.resolve(path2);
|
10
10
|
};
|
11
|
-
async function getProvider(bundler, builderConfig) {
|
12
|
-
try {
|
13
|
-
if (bundler === "webpack") {
|
14
|
-
const { builderWebpackProvider } = await import("@modern-js/builder-webpack-provider");
|
15
|
-
return builderWebpackProvider({
|
16
|
-
builderConfig
|
17
|
-
});
|
18
|
-
} else if (bundler === "rspack") {
|
19
|
-
const { builderRspackProvider } = await import("@modern-js/builder-rspack-provider");
|
20
|
-
return builderRspackProvider({
|
21
|
-
builderConfig
|
22
|
-
});
|
23
|
-
} else {
|
24
|
-
return await getProvider("webpack", builderConfig) || await getProvider("rspack", builderConfig);
|
25
|
-
}
|
26
|
-
} catch (e) {
|
27
|
-
}
|
28
|
-
}
|
29
11
|
async function virtualModule(tempDir, cwd, virtualModuleMap) {
|
30
12
|
fs.ensureDirSync(tempDir);
|
31
13
|
const alias = {};
|
@@ -101,7 +83,6 @@ export {
|
|
101
83
|
VIRTUAL_MODULE_BASE,
|
102
84
|
getAbsolutePath,
|
103
85
|
getConfigFileName,
|
104
|
-
getProvider,
|
105
86
|
isDev,
|
106
87
|
maybeGetAbsolutePath,
|
107
88
|
requireResolve,
|
package/dist/types/core.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { Options } from '@storybook/types';
|
2
|
-
import type { Compiler } from '@
|
2
|
+
import type { Compiler } from '@rsbuild/shared/webpack-dev-middleware';
|
3
3
|
import type { BuilderOptions } from './types';
|
4
4
|
export declare function getCompiler(cwd: string, builderOptions: BuilderOptions, options: Options): Promise<Compiler>;
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { Options } from '@storybook/types';
|
2
|
-
import { RspackConfig } from '@
|
3
|
-
import { WebpackChain } from '@modern-js/builder-webpack-provider';
|
2
|
+
import type { RspackConfig, WebpackChain } from '@rsbuild/shared';
|
4
3
|
export type DocgenOptions = {
|
5
4
|
reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
|
6
5
|
reactDocgenTypescriptOptions?: any;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { BuilderPlugin } from '@modern-js/builder-shared';
|
2
1
|
import type { Options } from '@storybook/types';
|
3
|
-
import
|
4
|
-
import
|
2
|
+
import { type RsbuildPlugin } from '@rsbuild/shared';
|
3
|
+
import { BuilderConfig } from './types';
|
5
4
|
export declare function finalize(): Promise<void>;
|
6
|
-
export declare const pluginStorybook: (cwd: string, options: Options) =>
|
5
|
+
export declare const pluginStorybook: (cwd: string, options: Options) => RsbuildPlugin;
|
6
|
+
export declare function addonBabelAdapter(finalConfig: BuilderConfig, options: Options): Promise<BuilderConfig>;
|
package/dist/types/preset.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Options } from '@storybook/types';
|
2
|
-
import {
|
2
|
+
import type { UniBuilderConfig } from '@modern-js/uni-builder';
|
3
3
|
export declare const previewMainTemplate: () => string;
|
4
4
|
export declare const entries: (_: unknown, options: Options) => Promise<string[]>;
|
5
|
-
export declare const modern: (builderConfig:
|
5
|
+
export declare const modern: (builderConfig: UniBuilderConfig, options: Options) => UniBuilderConfig;
|
package/dist/types/types.d.ts
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import { BuilderPlugin } from '@modern-js/builder-shared';
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/shared';
|
2
|
+
import type { UniBuilderConfig } from '@modern-js/uni-builder';
|
4
3
|
export type BundlerType = 'webpack' | 'rspack';
|
5
|
-
export type { WebpackBuilderConfig, RspackBuilderConfig };
|
6
|
-
export type AllBuilderConfig = WebpackBuilderConfig | RspackBuilderConfig;
|
7
4
|
export type BuilderOptions = {
|
8
5
|
bundler?: BundlerType;
|
9
|
-
builderConfig?:
|
6
|
+
builderConfig?: UniBuilderConfig;
|
10
7
|
configPath?: string;
|
11
8
|
};
|
12
|
-
export type BuilderConfig =
|
13
|
-
builderPlugins?:
|
9
|
+
export type BuilderConfig = UniBuilderConfig & {
|
10
|
+
builderPlugins?: RsbuildPlugin[];
|
14
11
|
};
|
15
|
-
export
|
12
|
+
export declare function defineConfig(config: UniBuilderConfig): UniBuilderConfig;
|
package/dist/types/utils.d.ts
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
import { BuilderWebpackProvider } from '@modern-js/builder-webpack-provider';
|
2
|
-
import { BuilderRspackProvider } from '@modern-js/builder-rspack-provider';
|
3
|
-
import { AllBuilderConfig } from './types';
|
4
1
|
export declare const VIRTUAL_MODULE_BASE = ".MODERN_STORYBOOK";
|
5
2
|
export declare const STORIES_FILENAME = "storybook-stories.js";
|
6
3
|
export declare const STORYBOOK_CONFIG_ENTRY = "storybook-config-entry.js";
|
7
4
|
export declare const requireResolve: (importer: string, path: string) => void;
|
8
|
-
export declare function getProvider(bundler: 'webpack' | 'rspack' | undefined, builderConfig: AllBuilderConfig): Promise<BuilderWebpackProvider | BuilderRspackProvider | undefined>;
|
9
5
|
export declare function virtualModule(tempDir: string, cwd: string, virtualModuleMap: Record<string, string>): Promise<[Record<string, string>, (p: string, content: string) => void]>;
|
10
6
|
export declare function toImportFn(cwd: string, stories: string[]): Promise<string>;
|
11
7
|
export declare function getAbsolutePath<I extends string>(input: I): I;
|
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-20240207100605",
|
4
4
|
"description": "modern.js support for storybook",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -51,18 +51,20 @@
|
|
51
51
|
},
|
52
52
|
"license": "MIT",
|
53
53
|
"dependencies": {
|
54
|
+
"@rsbuild/core": "0.3.7",
|
55
|
+
"@rsbuild/shared": "0.3.7",
|
54
56
|
"@rspack/plugin-react-refresh": "0.4.5",
|
55
|
-
"@storybook/components": "~7.6.
|
56
|
-
"@storybook/core-common": "~7.6.
|
57
|
-
"@storybook/csf-plugin": "~7.6.
|
57
|
+
"@storybook/components": "~7.6.12",
|
58
|
+
"@storybook/core-common": "~7.6.12",
|
59
|
+
"@storybook/csf-plugin": "~7.6.12",
|
58
60
|
"@storybook/global": "~5.0.0",
|
59
61
|
"@storybook/mdx1-csf": "~1.0.0",
|
60
62
|
"@storybook/mdx2-csf": "~1.1.0",
|
61
|
-
"@storybook/preview": "~7.6.
|
62
|
-
"@storybook/preview-api": "~7.6.
|
63
|
+
"@storybook/preview": "~7.6.12",
|
64
|
+
"@storybook/preview-api": "~7.6.12",
|
63
65
|
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
|
64
|
-
"@storybook/router": "~7.6.
|
65
|
-
"@storybook/theming": "~7.6.
|
66
|
+
"@storybook/router": "~7.6.12",
|
67
|
+
"@storybook/theming": "~7.6.12",
|
66
68
|
"ast-types": "^0.14.2",
|
67
69
|
"minimatch": "^9.0.3",
|
68
70
|
"react-docgen": "6.0.0-alpha.3",
|
@@ -71,34 +73,19 @@
|
|
71
73
|
"serve-static": "^1.14.1",
|
72
74
|
"tinypool": "^0.8.0",
|
73
75
|
"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-20240131181000"
|
76
|
+
"@modern-js/uni-builder": "0.0.0-next-20240207100605",
|
77
|
+
"@modern-js/core": "0.0.0-next-20240207100605",
|
78
|
+
"@modern-js/runtime": "0.0.0-next-20240207100605",
|
79
|
+
"@modern-js/utils": "0.0.0-next-20240207100605"
|
79
80
|
},
|
80
81
|
"devDependencies": {
|
81
|
-
"@storybook/types": "~7.6.
|
82
|
+
"@storybook/types": "~7.6.12",
|
82
83
|
"@types/babel__core": "^7.20.1",
|
83
84
|
"@types/serve-static": "^1.13.10",
|
84
85
|
"@types/webpack-hot-middleware": "^2.25.6",
|
85
86
|
"typescript": "^5.2.2",
|
86
|
-
"@modern-js/
|
87
|
-
"@
|
88
|
-
"@modern-js/core": "0.0.0-next-20240131181000",
|
89
|
-
"@scripts/build": "0.0.0-next-20240131181000"
|
90
|
-
},
|
91
|
-
"peerDependencies": {
|
92
|
-
"@modern-js/builder-webpack-provider": "0.0.0-next-20240131181000",
|
93
|
-
"@modern-js/builder-rspack-provider": "0.0.0-next-20240131181000"
|
94
|
-
},
|
95
|
-
"peerDependenciesMeta": {
|
96
|
-
"@modern-js/builder-webpack-provider": {
|
97
|
-
"optional": true
|
98
|
-
},
|
99
|
-
"@modern-js/builder-rspack-provider": {
|
100
|
-
"optional": true
|
101
|
-
}
|
87
|
+
"@modern-js/core": "0.0.0-next-20240207100605",
|
88
|
+
"@scripts/build": "0.0.0-next-20240207100605"
|
102
89
|
},
|
103
90
|
"publishConfig": {
|
104
91
|
"registry": "https://registry.npmjs.org/",
|