@modern-js/storybook-builder 0.0.0-next-20240207100605 → 0.0.0-next-20240207181843
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 -7
- package/dist/cjs/plugin-storybook.js +48 -52
- 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 -12
- package/dist/esm/plugin-storybook.js +49 -52
- 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 -17
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,13 +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
|
-
|
46
|
+
framework: "modern.js storybook",
|
43
47
|
entry: {
|
44
48
|
main: entries
|
45
49
|
}
|
@@ -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,7 +83,7 @@ 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) => {
|
@@ -249,7 +248,7 @@ async function applyMdxLoader(config, options) {
|
|
249
248
|
}
|
250
249
|
function applyExternals(builderConfig) {
|
251
250
|
var _builderConfig_output;
|
252
|
-
const config = (0,
|
251
|
+
const config = (0, import_builder_shared.mergeBuilderConfig)({
|
253
252
|
output: {
|
254
253
|
...builderConfig.output,
|
255
254
|
externals: (_builderConfig_output = builderConfig.output) === null || _builderConfig_output === void 0 ? void 0 : _builderConfig_output.externals
|
@@ -335,60 +334,57 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
335
334
|
}
|
336
335
|
function addonAdapter(api, options) {
|
337
336
|
const { presets } = options;
|
338
|
-
api.
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
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;
|
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;
|
362
357
|
}
|
363
|
-
return;
|
364
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;
|
365
378
|
}
|
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
379
|
};
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
};
|
387
|
-
return finalConfig;
|
380
|
+
});
|
381
|
+
api.modifyWebpackConfig(async (config) => {
|
382
|
+
const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
|
383
|
+
return finalDefaultConfig;
|
384
|
+
});
|
388
385
|
}
|
389
386
|
// Annotate the CommonJS export names for ESM import in node:
|
390
387
|
0 && (module.exports = {
|
391
|
-
addonBabelAdapter,
|
392
388
|
finalize,
|
393
389
|
pluginStorybook
|
394
390
|
});
|
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,16 +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
|
-
|
33
|
+
framework: "modern.js storybook",
|
26
34
|
entry: {
|
27
35
|
main: entries
|
28
36
|
}
|
@@ -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,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 ("modifyWebpackConfig" in api) {
|
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 = mergeBuilderConfig(
|
258
258
|
{
|
259
259
|
output: {
|
260
260
|
...builderConfig.output,
|
@@ -358,6 +358,49 @@ 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
|
+
});
|
361
404
|
api.modifyWebpackConfig(async (config) => {
|
362
405
|
const finalDefaultConfig = await presets.apply(
|
363
406
|
"webpackFinal",
|
@@ -367,53 +410,7 @@ function addonAdapter(api, options) {
|
|
367
410
|
return finalDefaultConfig;
|
368
411
|
});
|
369
412
|
}
|
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
|
-
}
|
415
413
|
export {
|
416
|
-
addonBabelAdapter,
|
417
414
|
finalize,
|
418
415
|
pluginStorybook
|
419
416
|
};
|
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-20240207181843",
|
4
4
|
"description": "modern.js support for storybook",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -51,20 +51,18 @@
|
|
51
51
|
},
|
52
52
|
"license": "MIT",
|
53
53
|
"dependencies": {
|
54
|
-
"@rsbuild/core": "0.3.7",
|
55
|
-
"@rsbuild/shared": "0.3.7",
|
56
54
|
"@rspack/plugin-react-refresh": "0.4.5",
|
57
|
-
"@storybook/components": "~7.6.
|
58
|
-
"@storybook/core-common": "~7.6.
|
59
|
-
"@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",
|
60
58
|
"@storybook/global": "~5.0.0",
|
61
59
|
"@storybook/mdx1-csf": "~1.0.0",
|
62
60
|
"@storybook/mdx2-csf": "~1.1.0",
|
63
|
-
"@storybook/preview": "~7.6.
|
64
|
-
"@storybook/preview-api": "~7.6.
|
61
|
+
"@storybook/preview": "~7.6.1",
|
62
|
+
"@storybook/preview-api": "~7.6.1",
|
65
63
|
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
|
66
|
-
"@storybook/router": "~7.6.
|
67
|
-
"@storybook/theming": "~7.6.
|
64
|
+
"@storybook/router": "~7.6.1",
|
65
|
+
"@storybook/theming": "~7.6.1",
|
68
66
|
"ast-types": "^0.14.2",
|
69
67
|
"minimatch": "^9.0.3",
|
70
68
|
"react-docgen": "6.0.0-alpha.3",
|
@@ -73,19 +71,34 @@
|
|
73
71
|
"serve-static": "^1.14.1",
|
74
72
|
"tinypool": "^0.8.0",
|
75
73
|
"webpack-hot-middleware": "^2.25.4",
|
76
|
-
"@modern-js/
|
77
|
-
"@modern-js/
|
78
|
-
"@modern-js/
|
79
|
-
"@modern-js/
|
74
|
+
"@modern-js/builder": "0.0.0-next-20240207181843",
|
75
|
+
"@modern-js/builder-shared": "0.0.0-next-20240207181843",
|
76
|
+
"@modern-js/core": "0.0.0-next-20240207181843",
|
77
|
+
"@modern-js/runtime": "0.0.0-next-20240207181843",
|
78
|
+
"@modern-js/utils": "0.0.0-next-20240207181843"
|
80
79
|
},
|
81
80
|
"devDependencies": {
|
82
|
-
"@storybook/types": "~7.6.
|
81
|
+
"@storybook/types": "~7.6.1",
|
83
82
|
"@types/babel__core": "^7.20.1",
|
84
83
|
"@types/serve-static": "^1.13.10",
|
85
84
|
"@types/webpack-hot-middleware": "^2.25.6",
|
86
85
|
"typescript": "^5.2.2",
|
87
|
-
"@modern-js/
|
88
|
-
"@
|
86
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20240207181843",
|
87
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20240207181843",
|
88
|
+
"@modern-js/core": "0.0.0-next-20240207181843",
|
89
|
+
"@scripts/build": "0.0.0-next-20240207181843"
|
90
|
+
},
|
91
|
+
"peerDependencies": {
|
92
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20240207181843",
|
93
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20240207181843"
|
94
|
+
},
|
95
|
+
"peerDependenciesMeta": {
|
96
|
+
"@modern-js/builder-webpack-provider": {
|
97
|
+
"optional": true
|
98
|
+
},
|
99
|
+
"@modern-js/builder-rspack-provider": {
|
100
|
+
"optional": true
|
101
|
+
}
|
89
102
|
},
|
90
103
|
"publishConfig": {
|
91
104
|
"registry": "https://registry.npmjs.org/",
|