@modern-js/storybook-builder 0.0.0-next-20240220105216 → 0.0.0-next-20240220122504
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 +11 -8
- package/dist/cjs/docgen/index.js +4 -5
- package/dist/cjs/plugin-storybook.js +51 -59
- package/dist/cjs/preset.js +0 -2
- package/dist/cjs/types.js +2 -4
- package/dist/cjs/utils.js +20 -0
- package/dist/esm/build.js +1 -1
- package/dist/esm/core.js +20 -13
- package/dist/esm/docgen/index.js +1 -2
- package/dist/esm/plugin-storybook.js +52 -57
- package/dist/esm/preset.js +0 -2
- package/dist/esm/types.js +1 -3
- package/dist/esm/utils.js +19 -0
- package/dist/types/core.d.ts +1 -1
- package/dist/types/docgen/index.d.ts +2 -1
- package/dist/types/plugin-storybook.d.ts +4 -4
- package/dist/types/preset.d.ts +2 -2
- package/dist/types/types.d.ts +9 -6
- package/dist/types/utils.d.ts +4 -0
- package/package.json +30 -16
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("@modern-js/builder-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,8 +21,7 @@ __export(core_exports, {
|
|
21
21
|
getCompiler: () => getCompiler
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(core_exports);
|
24
|
-
var
|
25
|
-
var import_shared = require("@rsbuild/shared");
|
24
|
+
var import_builder = require("@modern-js/builder");
|
26
25
|
var import_core = require("@modern-js/core");
|
27
26
|
var import_utils = require("./utils");
|
28
27
|
var import_plugin_storybook = require("./plugin-storybook");
|
@@ -33,14 +32,18 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
33
32
|
const res = await (0, import_utils.runWithErrorMsg)(() => (0, import_core.loadConfig)(cwd, builderOptions.configPath || (0, import_utils.getConfigFileName)()), "Failed to load config");
|
34
33
|
const loadedConfig = res ? res.config : {};
|
35
34
|
const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
|
36
|
-
const
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
const provider = await (0, import_utils.getProvider)(bundler, (0, import_builder.mergeBuilderConfig)(finalConfig, builderOptions.builderConfig) || {});
|
36
|
+
if (!provider) {
|
37
|
+
if (bundler) {
|
38
|
+
throw new Error(`You choose to use ${bundler}, but @modern-js/builder-${bundler}-provider not found in your project, please install it`);
|
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, {
|
40
44
|
cwd,
|
41
45
|
target: "web",
|
42
|
-
|
43
|
-
config: bundlerType === "webpack" ? await (0, import_plugin_storybook.addonBabelAdapter)(uniBuilderConfig, options) : uniBuilderConfig,
|
46
|
+
framework: "modern.js storybook",
|
44
47
|
entry: {
|
45
48
|
main: entries
|
46
49
|
}
|
package/dist/cjs/docgen/index.js
CHANGED
@@ -33,7 +33,6 @@ __export(docgen_exports, {
|
|
33
33
|
});
|
34
34
|
module.exports = __toCommonJS(docgen_exports);
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
|
-
var import_shared = require("@rsbuild/shared");
|
37
36
|
async function applyDocgenWebpack(chain, options) {
|
38
37
|
const typescriptOptions = await options.presets.apply("typescript", {});
|
39
38
|
const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions || {};
|
@@ -51,14 +50,14 @@ async function applyDocgenWebpack(chain, options) {
|
|
51
50
|
} else if (reactDocgen === "react-docgen") {
|
52
51
|
const loader = require.resolve("./loader");
|
53
52
|
const resolveOptions = chain.toConfig().resolve;
|
54
|
-
chain.module.rule(
|
53
|
+
chain.module.rule(import_utils.CHAIN_ID.RULE.JS).use("react-docgen").loader(loader).options({
|
55
54
|
resolveOptions
|
56
|
-
}).after(
|
57
|
-
const tsRuls = chain.module.rule(
|
55
|
+
}).after(import_utils.CHAIN_ID.USE.BABEL).after(import_utils.CHAIN_ID.USE.ESBUILD).after(import_utils.CHAIN_ID.USE.SWC).end();
|
56
|
+
const tsRuls = chain.module.rule(import_utils.CHAIN_ID.RULE.TS);
|
58
57
|
if (tsRuls.uses.values().length !== 0) {
|
59
58
|
tsRuls.use("react-docgen").loader(loader).options({
|
60
59
|
resolveOptions
|
61
|
-
}).after(
|
60
|
+
}).after(import_utils.CHAIN_ID.USE.TS).after(import_utils.CHAIN_ID.USE.ESBUILD).after(import_utils.CHAIN_ID.USE.SWC).end();
|
62
61
|
}
|
63
62
|
}
|
64
63
|
}
|
@@ -28,16 +28,15 @@ 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,
|
32
31
|
finalize: () => finalize,
|
33
32
|
pluginStorybook: () => pluginStorybook
|
34
33
|
});
|
35
34
|
module.exports = __toCommonJS(plugin_storybook_exports);
|
36
35
|
var import_path = require("path");
|
37
36
|
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");
|
41
40
|
var import_csf_plugin = require("@storybook/csf-plugin");
|
42
41
|
var import_minimatch = require("minimatch");
|
43
42
|
var import_utils2 = require("./utils");
|
@@ -69,7 +68,7 @@ const pluginStorybook = (cwd, options) => {
|
|
69
68
|
const absolutePattern = (0, import_path.isAbsolute)(pattern) ? pattern : (0, import_path.join)(options.configDir, pattern);
|
70
69
|
return absolutePattern;
|
71
70
|
});
|
72
|
-
api.
|
71
|
+
api.modifyBuilderConfig(async (builderConfig) => {
|
73
72
|
await prepareStorybookModules(api.context.cachePath, cwd, options, builderConfig, storyPatterns);
|
74
73
|
await applyDefines(builderConfig, options);
|
75
74
|
await applyHTML(builderConfig, options);
|
@@ -84,13 +83,13 @@ const pluginStorybook = (cwd, options) => {
|
|
84
83
|
await applyMdxLoader(config, options);
|
85
84
|
await applyCsfPlugin(config, options);
|
86
85
|
};
|
87
|
-
if (
|
86
|
+
if ("modifyWebpackConfig" in api) {
|
88
87
|
addonAdapter(api, options);
|
89
88
|
api.modifyWebpackConfig(modifyConfig);
|
90
89
|
api.modifyWebpackChain(async (chain) => {
|
91
90
|
await (0, import_docgen.applyDocgenWebpack)(chain, options);
|
92
91
|
});
|
93
|
-
} else {
|
92
|
+
} else if ("modifyRspackConfig" in api) {
|
94
93
|
api.modifyRspackConfig(async (config) => {
|
95
94
|
await modifyConfig(config);
|
96
95
|
await (0, import_docgen.applyDocgenRspack)(config, options);
|
@@ -137,9 +136,7 @@ async function prepareStorybookModules(tempDir, cwd, options, builderConfig, sto
|
|
137
136
|
builderConfig.source.alias = (0, import_utils.applyOptionsChain)({
|
138
137
|
...storybookPaths,
|
139
138
|
...mappingsAlias
|
140
|
-
}, builderConfig.source.alias
|
141
|
-
target: "web"
|
142
|
-
});
|
139
|
+
}, builderConfig.source.alias);
|
143
140
|
if ((0, import_utils2.isDev)()) {
|
144
141
|
const watcher = await watchStories(storyPatterns, cwd, write);
|
145
142
|
onClose(async () => {
|
@@ -251,7 +248,7 @@ async function applyMdxLoader(config, options) {
|
|
251
248
|
}
|
252
249
|
function applyExternals(builderConfig) {
|
253
250
|
var _builderConfig_output;
|
254
|
-
const config = (0,
|
251
|
+
const config = (0, import_builder_shared.mergeBuilderConfig)({
|
255
252
|
output: {
|
256
253
|
...builderConfig.output,
|
257
254
|
externals: (_builderConfig_output = builderConfig.output) === null || _builderConfig_output === void 0 ? void 0 : _builderConfig_output.externals
|
@@ -313,9 +310,7 @@ async function applyReact(config, options) {
|
|
313
310
|
(_source = (_config = config).source) !== null && _source !== void 0 ? _source : _config.source = {};
|
314
311
|
config.source.alias = (0, import_utils.applyOptionsChain)({
|
315
312
|
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-18"
|
316
|
-
}, config.source.alias
|
317
|
-
target: "web"
|
318
|
-
});
|
313
|
+
}, config.source.alias);
|
319
314
|
}
|
320
315
|
}
|
321
316
|
async function watchStories(patterns, cwd, writeModule) {
|
@@ -339,60 +334,57 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
339
334
|
}
|
340
335
|
function addonAdapter(api, options) {
|
341
336
|
const { presets } = options;
|
342
|
-
api.
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
}
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
if (getPluginName(plugins[i]) === pluginName) {
|
363
|
-
if (getOptions(plugin)) {
|
364
|
-
import_utils.logger.info(`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`);
|
365
|
-
plugins[i] = plugin;
|
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;
|
366
357
|
}
|
367
|
-
return;
|
368
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;
|
369
378
|
}
|
370
|
-
plugins.push(plugin);
|
371
|
-
};
|
372
|
-
const currentPlugins = config.plugins || [];
|
373
|
-
const currentPresets = config.presets || [];
|
374
|
-
for (const plugin of babelOptions.plugins || []) {
|
375
|
-
replaceOrInsert(plugin, currentPlugins);
|
376
|
-
}
|
377
|
-
for (const preset of babelOptions.presets || []) {
|
378
|
-
replaceOrInsert(preset, currentPresets);
|
379
|
-
}
|
380
|
-
const finalConfig2 = {
|
381
|
-
...babelOptions,
|
382
|
-
plugins: currentPlugins,
|
383
|
-
presets: currentPresets
|
384
379
|
};
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
};
|
391
|
-
return finalConfig;
|
380
|
+
});
|
381
|
+
api.modifyWebpackConfig(async (config) => {
|
382
|
+
const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
|
383
|
+
return finalDefaultConfig;
|
384
|
+
});
|
392
385
|
}
|
393
386
|
// Annotate the CommonJS export names for ESM import in node:
|
394
387
|
0 && (module.exports = {
|
395
|
-
addonBabelAdapter,
|
396
388
|
finalize,
|
397
389
|
pluginStorybook
|
398
390
|
});
|
package/dist/cjs/preset.js
CHANGED
package/dist/cjs/types.js
CHANGED
@@ -18,12 +18,10 @@ 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: () => defineConfig
|
21
|
+
defineConfig: () => import_cli.defineConfig
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(types_exports);
|
24
|
-
|
25
|
-
return config;
|
26
|
-
}
|
24
|
+
var import_cli = require("@modern-js/builder/cli");
|
27
25
|
// Annotate the CommonJS export names for ESM import in node:
|
28
26
|
0 && (module.exports = {
|
29
27
|
defineConfig
|
package/dist/cjs/utils.js
CHANGED
@@ -33,6 +33,7 @@ __export(utils_exports, {
|
|
33
33
|
VIRTUAL_MODULE_BASE: () => VIRTUAL_MODULE_BASE,
|
34
34
|
getAbsolutePath: () => getAbsolutePath,
|
35
35
|
getConfigFileName: () => getConfigFileName,
|
36
|
+
getProvider: () => getProvider,
|
36
37
|
isDev: () => isDev,
|
37
38
|
maybeGetAbsolutePath: () => maybeGetAbsolutePath,
|
38
39
|
requireResolve: () => requireResolve,
|
@@ -51,6 +52,24 @@ const requireResolve = (importer, path2) => {
|
|
51
52
|
const require1 = (0, import_node_module.createRequire)(importer);
|
52
53
|
require1.resolve(path2);
|
53
54
|
};
|
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
|
+
}
|
54
73
|
async function virtualModule(tempDir, cwd, virtualModuleMap) {
|
55
74
|
import_utils.fs.ensureDirSync(tempDir);
|
56
75
|
const alias = {};
|
@@ -129,6 +148,7 @@ function getConfigFileName() {
|
|
129
148
|
VIRTUAL_MODULE_BASE,
|
130
149
|
getAbsolutePath,
|
131
150
|
getConfigFileName,
|
151
|
+
getProvider,
|
132
152
|
isDev,
|
133
153
|
maybeGetAbsolutePath,
|
134
154
|
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 "@modern-js/builder-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,8 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { mergeRsbuildConfig } from "@rsbuild/shared";
|
1
|
+
import { createBuilder, mergeBuilderConfig } from "@modern-js/builder";
|
3
2
|
import { loadConfig } from "@modern-js/core";
|
4
|
-
import { getConfigFileName, runWithErrorMsg } from "./utils";
|
5
|
-
import { pluginStorybook
|
3
|
+
import { getConfigFileName, getProvider, runWithErrorMsg } from "./utils";
|
4
|
+
import { pluginStorybook } from "./plugin-storybook";
|
6
5
|
async function getCompiler(cwd, builderOptions, options) {
|
7
6
|
const { bundler } = builderOptions;
|
8
7
|
const { presets } = options;
|
@@ -13,17 +12,25 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
13
12
|
);
|
14
13
|
const loadedConfig = res ? res.config : {};
|
15
14
|
const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
|
16
|
-
const
|
17
|
-
|
18
|
-
builderOptions.builderConfig
|
19
|
-
)
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
const provider = await getProvider(
|
16
|
+
bundler,
|
17
|
+
mergeBuilderConfig(finalConfig, builderOptions.builderConfig) || {}
|
18
|
+
);
|
19
|
+
if (!provider) {
|
20
|
+
if (bundler) {
|
21
|
+
throw new Error(
|
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, {
|
23
31
|
cwd,
|
24
32
|
target: "web",
|
25
|
-
|
26
|
-
config: bundlerType === "webpack" ? await addonBabelAdapter(uniBuilderConfig, options) : uniBuilderConfig,
|
33
|
+
framework: "modern.js storybook",
|
27
34
|
entry: {
|
28
35
|
main: entries
|
29
36
|
}
|
package/dist/esm/docgen/index.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { logger } from "@modern-js/utils";
|
2
|
-
import { CHAIN_ID } from "@rsbuild/shared";
|
1
|
+
import { CHAIN_ID, logger } from "@modern-js/utils";
|
3
2
|
async function applyDocgenWebpack(chain, options) {
|
4
3
|
const typescriptOptions = await options.presets.apply(
|
5
4
|
"typescript",
|
@@ -6,6 +6,9 @@ import {
|
|
6
6
|
applyOptionsChain,
|
7
7
|
logger
|
8
8
|
} from "@modern-js/utils";
|
9
|
+
import {
|
10
|
+
mergeBuilderConfig
|
11
|
+
} from "@modern-js/builder-shared";
|
9
12
|
import {
|
10
13
|
normalizeStories,
|
11
14
|
stringifyProcessEnvs,
|
@@ -14,9 +17,6 @@ import {
|
|
14
17
|
loadPreviewOrConfigFile
|
15
18
|
} from "@storybook/core-common";
|
16
19
|
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.modifyBuilderConfig(async (builderConfig) => {
|
57
57
|
await prepareStorybookModules(
|
58
58
|
api.context.cachePath,
|
59
59
|
cwd,
|
@@ -73,13 +73,13 @@ const pluginStorybook = (cwd, options) => {
|
|
73
73
|
await applyMdxLoader(config, options);
|
74
74
|
await applyCsfPlugin(config, options);
|
75
75
|
};
|
76
|
-
if (
|
76
|
+
if ("modifyWebpackConfig" in api) {
|
77
77
|
addonAdapter(api, options);
|
78
78
|
api.modifyWebpackConfig(modifyConfig);
|
79
79
|
api.modifyWebpackChain(async (chain) => {
|
80
80
|
await applyDocgenWebpack(chain, options);
|
81
81
|
});
|
82
|
-
} else {
|
82
|
+
} else if ("modifyRspackConfig" in api) {
|
83
83
|
api.modifyRspackConfig(async (config) => {
|
84
84
|
await modifyConfig(config);
|
85
85
|
await applyDocgenRspack(config, options);
|
@@ -124,8 +124,7 @@ async function prepareStorybookModules(tempDir, cwd, options, builderConfig, sto
|
|
124
124
|
...storybookPaths,
|
125
125
|
...mappingsAlias
|
126
126
|
},
|
127
|
-
builderConfig.source.alias
|
128
|
-
{ target: "web" }
|
127
|
+
builderConfig.source.alias
|
129
128
|
);
|
130
129
|
if (isDev()) {
|
131
130
|
const watcher = await watchStories(storyPatterns, cwd, write);
|
@@ -255,7 +254,7 @@ async function applyMdxLoader(config, options) {
|
|
255
254
|
}
|
256
255
|
function applyExternals(builderConfig) {
|
257
256
|
var _a;
|
258
|
-
const config =
|
257
|
+
const config = mergeBuilderConfig(
|
259
258
|
{
|
260
259
|
output: {
|
261
260
|
...builderConfig.output,
|
@@ -332,8 +331,7 @@ async function applyReact(config, options) {
|
|
332
331
|
{
|
333
332
|
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-18"
|
334
333
|
},
|
335
|
-
config.source.alias
|
336
|
-
{ target: "web" }
|
334
|
+
config.source.alias
|
337
335
|
);
|
338
336
|
}
|
339
337
|
}
|
@@ -360,6 +358,49 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
360
358
|
}
|
361
359
|
function addonAdapter(api, options) {
|
362
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
|
+
});
|
363
404
|
api.modifyWebpackConfig(async (config) => {
|
364
405
|
const finalDefaultConfig = await presets.apply(
|
365
406
|
"webpackFinal",
|
@@ -369,53 +410,7 @@ function addonAdapter(api, options) {
|
|
369
410
|
return finalDefaultConfig;
|
370
411
|
});
|
371
412
|
}
|
372
|
-
async function addonBabelAdapter(finalConfig, options) {
|
373
|
-
var _a;
|
374
|
-
const { presets } = options;
|
375
|
-
const babelOptions = await presets.apply("babel", {}, { ...options });
|
376
|
-
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
377
|
-
const userConfig = finalConfig.tools.babel;
|
378
|
-
finalConfig.tools.babel = (config, utils) => {
|
379
|
-
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
380
|
-
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
381
|
-
const replaceOrInsert = (plugin, plugins) => {
|
382
|
-
const pluginName = getPluginName(plugin);
|
383
|
-
for (let i = 0; i < plugins.length; i++) {
|
384
|
-
if (getPluginName(plugins[i]) === pluginName) {
|
385
|
-
if (getOptions(plugin)) {
|
386
|
-
logger.info(
|
387
|
-
`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`
|
388
|
-
);
|
389
|
-
plugins[i] = plugin;
|
390
|
-
}
|
391
|
-
return;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
plugins.push(plugin);
|
395
|
-
};
|
396
|
-
const currentPlugins = config.plugins || [];
|
397
|
-
const currentPresets = config.presets || [];
|
398
|
-
for (const plugin of babelOptions.plugins || []) {
|
399
|
-
replaceOrInsert(plugin, currentPlugins);
|
400
|
-
}
|
401
|
-
for (const preset of babelOptions.presets || []) {
|
402
|
-
replaceOrInsert(preset, currentPresets);
|
403
|
-
}
|
404
|
-
const finalConfig2 = {
|
405
|
-
...babelOptions,
|
406
|
-
plugins: currentPlugins,
|
407
|
-
presets: currentPresets
|
408
|
-
};
|
409
|
-
if (userConfig) {
|
410
|
-
return applyOptionsChain(finalConfig2, userConfig, utils);
|
411
|
-
} else {
|
412
|
-
return finalConfig2;
|
413
|
-
}
|
414
|
-
};
|
415
|
-
return finalConfig;
|
416
|
-
}
|
417
413
|
export {
|
418
|
-
addonBabelAdapter,
|
419
414
|
finalize,
|
420
415
|
pluginStorybook
|
421
416
|
};
|
package/dist/esm/preset.js
CHANGED
package/dist/esm/types.js
CHANGED
package/dist/esm/utils.js
CHANGED
@@ -8,6 +8,24 @@ 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
|
+
}
|
11
29
|
async function virtualModule(tempDir, cwd, virtualModuleMap) {
|
12
30
|
fs.ensureDirSync(tempDir);
|
13
31
|
const alias = {};
|
@@ -83,6 +101,7 @@ export {
|
|
83
101
|
VIRTUAL_MODULE_BASE,
|
84
102
|
getAbsolutePath,
|
85
103
|
getConfigFileName,
|
104
|
+
getProvider,
|
86
105
|
isDev,
|
87
106
|
maybeGetAbsolutePath,
|
88
107
|
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 '@modern-js/builder-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,5 +1,6 @@
|
|
1
1
|
import type { Options } from '@storybook/types';
|
2
|
-
import
|
2
|
+
import { RspackConfig } from '@modern-js/builder-rspack-provider';
|
3
|
+
import { WebpackChain } from '@modern-js/builder-webpack-provider';
|
3
4
|
export type DocgenOptions = {
|
4
5
|
reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
|
5
6
|
reactDocgenTypescriptOptions?: any;
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import { BuilderPlugin } from '@modern-js/builder-shared';
|
1
2
|
import type { Options } from '@storybook/types';
|
2
|
-
import {
|
3
|
-
import {
|
3
|
+
import type { BuilderPluginAPI as WebpackAPI } from '@modern-js/builder-webpack-provider';
|
4
|
+
import type { BuilderPluginAPI as RspackAPI } from '@modern-js/builder-rspack-provider';
|
4
5
|
export declare function finalize(): Promise<void>;
|
5
|
-
export declare const pluginStorybook: (cwd: string, options: Options) =>
|
6
|
-
export declare function addonBabelAdapter(finalConfig: BuilderConfig, options: Options): Promise<BuilderConfig>;
|
6
|
+
export declare const pluginStorybook: (cwd: string, options: Options) => BuilderPlugin<WebpackAPI | RspackAPI>;
|
package/dist/types/preset.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Options } from '@storybook/types';
|
2
|
-
import
|
2
|
+
import { BuilderConfig } from './types';
|
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: BuilderConfig, options: Options) => BuilderConfig;
|
package/dist/types/types.d.ts
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { BuilderConfig as WebpackBuilderConfig } from '@modern-js/builder-webpack-provider';
|
2
|
+
import type { BuilderConfig as RspackBuilderConfig } from '@modern-js/builder-rspack-provider';
|
3
|
+
import { BuilderPlugin } from '@modern-js/builder-shared';
|
3
4
|
export type BundlerType = 'webpack' | 'rspack';
|
5
|
+
export type { WebpackBuilderConfig, RspackBuilderConfig };
|
6
|
+
export type AllBuilderConfig = WebpackBuilderConfig | RspackBuilderConfig;
|
4
7
|
export type BuilderOptions = {
|
5
8
|
bundler?: BundlerType;
|
6
|
-
builderConfig?:
|
9
|
+
builderConfig?: AllBuilderConfig;
|
7
10
|
configPath?: string;
|
8
11
|
};
|
9
|
-
export type BuilderConfig =
|
10
|
-
builderPlugins?:
|
12
|
+
export type BuilderConfig = AllBuilderConfig & {
|
13
|
+
builderPlugins?: BuilderPlugin[];
|
11
14
|
};
|
12
|
-
export
|
15
|
+
export { defineConfig } from '@modern-js/builder/cli';
|
package/dist/types/utils.d.ts
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
import { BuilderWebpackProvider } from '@modern-js/builder-webpack-provider';
|
2
|
+
import { BuilderRspackProvider } from '@modern-js/builder-rspack-provider';
|
3
|
+
import { AllBuilderConfig } from './types';
|
1
4
|
export declare const VIRTUAL_MODULE_BASE = ".MODERN_STORYBOOK";
|
2
5
|
export declare const STORIES_FILENAME = "storybook-stories.js";
|
3
6
|
export declare const STORYBOOK_CONFIG_ENTRY = "storybook-config-entry.js";
|
4
7
|
export declare const requireResolve: (importer: string, path: string) => void;
|
8
|
+
export declare function getProvider(bundler: 'webpack' | 'rspack' | undefined, builderConfig: AllBuilderConfig): Promise<BuilderWebpackProvider | BuilderRspackProvider | undefined>;
|
5
9
|
export declare function virtualModule(tempDir: string, cwd: string, virtualModuleMap: Record<string, string>): Promise<[Record<string, string>, (p: string, content: string) => void]>;
|
6
10
|
export declare function toImportFn(cwd: string, stories: string[]): Promise<string>;
|
7
11
|
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-20240220122504",
|
4
4
|
"description": "modern.js support for storybook",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -51,19 +51,18 @@
|
|
51
51
|
},
|
52
52
|
"license": "MIT",
|
53
53
|
"dependencies": {
|
54
|
-
"@rsbuild/shared": "0.4.3",
|
55
54
|
"@rspack/plugin-react-refresh": "0.4.5",
|
56
|
-
"@storybook/components": "~7.6.
|
57
|
-
"@storybook/core-common": "~7.6.
|
58
|
-
"@storybook/csf-plugin": "~7.6.
|
55
|
+
"@storybook/components": "~7.6.1",
|
56
|
+
"@storybook/core-common": "~7.6.1",
|
57
|
+
"@storybook/csf-plugin": "~7.6.1",
|
59
58
|
"@storybook/global": "~5.0.0",
|
60
59
|
"@storybook/mdx1-csf": "~1.0.0",
|
61
60
|
"@storybook/mdx2-csf": "~1.1.0",
|
62
|
-
"@storybook/preview": "~7.6.
|
63
|
-
"@storybook/preview-api": "~7.6.
|
61
|
+
"@storybook/preview": "~7.6.1",
|
62
|
+
"@storybook/preview-api": "~7.6.1",
|
64
63
|
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
|
65
|
-
"@storybook/router": "~7.6.
|
66
|
-
"@storybook/theming": "~7.6.
|
64
|
+
"@storybook/router": "~7.6.1",
|
65
|
+
"@storybook/theming": "~7.6.1",
|
67
66
|
"ast-types": "^0.14.2",
|
68
67
|
"minimatch": "^9.0.3",
|
69
68
|
"react-docgen": "6.0.0-alpha.3",
|
@@ -72,19 +71,34 @@
|
|
72
71
|
"serve-static": "^1.14.1",
|
73
72
|
"tinypool": "^0.8.0",
|
74
73
|
"webpack-hot-middleware": "^2.25.4",
|
75
|
-
"@modern-js/
|
76
|
-
"@modern-js/core": "0.0.0-next-
|
77
|
-
"@modern-js/
|
78
|
-
"@modern-js/
|
74
|
+
"@modern-js/builder": "0.0.0-next-20240220122504",
|
75
|
+
"@modern-js/core": "0.0.0-next-20240220122504",
|
76
|
+
"@modern-js/builder-shared": "0.0.0-next-20240220122504",
|
77
|
+
"@modern-js/runtime": "0.0.0-next-20240220122504",
|
78
|
+
"@modern-js/utils": "0.0.0-next-20240220122504"
|
79
79
|
},
|
80
80
|
"devDependencies": {
|
81
|
-
"@storybook/types": "~7.6.
|
81
|
+
"@storybook/types": "~7.6.1",
|
82
82
|
"@types/babel__core": "^7.20.1",
|
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
|
-
"@
|
86
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20240220122504",
|
87
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20240220122504",
|
88
|
+
"@scripts/build": "0.0.0-next-20240220122504",
|
89
|
+
"@modern-js/core": "0.0.0-next-20240220122504"
|
90
|
+
},
|
91
|
+
"peerDependencies": {
|
92
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20240220122504",
|
93
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20240220122504"
|
94
|
+
},
|
95
|
+
"peerDependenciesMeta": {
|
96
|
+
"@modern-js/builder-webpack-provider": {
|
97
|
+
"optional": true
|
98
|
+
},
|
99
|
+
"@modern-js/builder-rspack-provider": {
|
100
|
+
"optional": true
|
101
|
+
}
|
88
102
|
},
|
89
103
|
"publishConfig": {
|
90
104
|
"registry": "https://registry.npmjs.org/",
|