@modern-js/storybook-builder 0.0.0-next-20231114083144 → 0.0.0-next-20231114124526
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 +3 -57
- package/dist/cjs/plugin-storybook.js +51 -0
- package/dist/esm/core.js +0 -56
- package/dist/esm/plugin-storybook.js +60 -1
- package/package.json +10 -10
package/dist/cjs/core.js
CHANGED
@@ -23,18 +23,16 @@ __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("
|
27
|
-
var import_utils2 = require("./utils");
|
26
|
+
var import_utils = require("./utils");
|
28
27
|
var import_plugin_storybook = require("./plugin-storybook");
|
29
28
|
async function getCompiler(cwd, builderOptions, options) {
|
30
29
|
const bundler = builderOptions.bundler || "webpack";
|
31
30
|
const { presets } = options;
|
32
31
|
const entries = await presets.apply("entries", []);
|
33
|
-
const res = await (0,
|
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
|
-
await
|
37
|
-
const provider = await (0, import_utils2.getProvider)(bundler, finalConfig);
|
35
|
+
const provider = await (0, import_utils.getProvider)(bundler, finalConfig);
|
38
36
|
if (!provider) {
|
39
37
|
throw new Error(`@modern-js/builder-${bundler}-provider not found `);
|
40
38
|
}
|
@@ -52,58 +50,6 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
52
50
|
]);
|
53
51
|
return builder.createCompiler();
|
54
52
|
}
|
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
|
-
}
|
107
53
|
// Annotate the CommonJS export names for ESM import in node:
|
108
54
|
0 && (module.exports = {
|
109
55
|
getCompiler
|
@@ -89,6 +89,7 @@ const pluginStorybook = (cwd, options) => {
|
|
89
89
|
await applyCsfPlugin(config, options);
|
90
90
|
};
|
91
91
|
if ("modifyWebpackConfig" in api) {
|
92
|
+
addonAdapter(api, options);
|
92
93
|
api.modifyWebpackConfig(modifyConfig);
|
93
94
|
api.modifyWebpackChain(async (chain) => {
|
94
95
|
await (0, import_docgen.applyDocgenWebpack)(chain, options);
|
@@ -330,6 +331,56 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
330
331
|
]);
|
331
332
|
return watcher;
|
332
333
|
}
|
334
|
+
async function addonAdapter(api, options) {
|
335
|
+
const { presets } = options;
|
336
|
+
api.modifyBuilderConfig(async (finalConfig) => {
|
337
|
+
var _finalConfig, _finalConfig_tools;
|
338
|
+
const babelOptions = await presets.apply("babel", {}, {
|
339
|
+
...options
|
340
|
+
});
|
341
|
+
var _tools;
|
342
|
+
(_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
|
343
|
+
var _babel;
|
344
|
+
(_babel = (_finalConfig_tools = finalConfig.tools).babel) !== null && _babel !== void 0 ? _babel : _finalConfig_tools.babel = {};
|
345
|
+
finalConfig.tools.babel = (config) => {
|
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
|
+
const append = [];
|
351
|
+
for (let i = 0; i < plugins.length; i++) {
|
352
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
353
|
+
if (getOptions(plugin)) {
|
354
|
+
import_utils.logger.info("Detected duplicated babel plugin, overrides with the new one");
|
355
|
+
plugins[i] = plugin;
|
356
|
+
}
|
357
|
+
} else {
|
358
|
+
append.push(plugin);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
plugins.push(...append);
|
362
|
+
};
|
363
|
+
const currentPlugins = config.plugins || [];
|
364
|
+
for (const plugin of babelOptions.plugins || []) {
|
365
|
+
replaceOrInsert(plugin, currentPlugins);
|
366
|
+
}
|
367
|
+
return {
|
368
|
+
...config,
|
369
|
+
...babelOptions,
|
370
|
+
plugins: currentPlugins,
|
371
|
+
presets: config.presets,
|
372
|
+
overrides: [
|
373
|
+
...config.overrides || [],
|
374
|
+
...babelOptions.overrides || []
|
375
|
+
]
|
376
|
+
};
|
377
|
+
};
|
378
|
+
});
|
379
|
+
api.modifyWebpackConfig(async (config) => {
|
380
|
+
const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
|
381
|
+
return finalDefaultConfig;
|
382
|
+
});
|
383
|
+
}
|
333
384
|
// Annotate the CommonJS export names for ESM import in node:
|
334
385
|
0 && (module.exports = {
|
335
386
|
finalize,
|
package/dist/esm/core.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { createBuilder } from "@modern-js/builder";
|
2
2
|
import { loadConfig } from "@modern-js/core";
|
3
|
-
import { applyOptionsChain, logger } from "@modern-js/utils";
|
4
3
|
import { getConfigFileName, getProvider, runWithErrorMsg } from "./utils";
|
5
4
|
import { pluginStorybook } from "./plugin-storybook";
|
6
5
|
async function getCompiler(cwd, builderOptions, options) {
|
@@ -13,7 +12,6 @@ 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
|
-
await addonAdapter(finalConfig, options);
|
17
15
|
const provider = await getProvider(bundler, finalConfig);
|
18
16
|
if (!provider) {
|
19
17
|
throw new Error(`@modern-js/builder-${bundler}-provider not found `);
|
@@ -32,60 +30,6 @@ async function getCompiler(cwd, builderOptions, options) {
|
|
32
30
|
]);
|
33
31
|
return builder.createCompiler();
|
34
32
|
}
|
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
|
-
}
|
89
33
|
export {
|
90
34
|
getCompiler
|
91
35
|
};
|
@@ -1,5 +1,11 @@
|
|
1
1
|
import { isAbsolute, join, resolve } from "path";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
slash,
|
4
|
+
watch,
|
5
|
+
globby,
|
6
|
+
applyOptionsChain,
|
7
|
+
logger
|
8
|
+
} from "@modern-js/utils";
|
3
9
|
import {
|
4
10
|
mergeBuilderConfig
|
5
11
|
} from "@modern-js/builder-shared";
|
@@ -73,6 +79,7 @@ const pluginStorybook = (cwd, options) => {
|
|
73
79
|
await applyCsfPlugin(config, options);
|
74
80
|
};
|
75
81
|
if ("modifyWebpackConfig" in api) {
|
82
|
+
addonAdapter(api, options);
|
76
83
|
api.modifyWebpackConfig(modifyConfig);
|
77
84
|
api.modifyWebpackChain(async (chain) => {
|
78
85
|
await applyDocgenWebpack(chain, options);
|
@@ -346,6 +353,58 @@ async function watchStories(patterns, cwd, writeModule) {
|
|
346
353
|
);
|
347
354
|
return watcher;
|
348
355
|
}
|
356
|
+
async function addonAdapter(api, options) {
|
357
|
+
const { presets } = options;
|
358
|
+
api.modifyBuilderConfig(async (finalConfig) => {
|
359
|
+
var _a, _b, _c;
|
360
|
+
const babelOptions = await presets.apply("babel", {}, { ...options });
|
361
|
+
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
362
|
+
(_c = (_b = finalConfig.tools).babel) != null ? _c : _b.babel = {};
|
363
|
+
finalConfig.tools.babel = (config) => {
|
364
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
365
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
366
|
+
const replaceOrInsert = (plugin, plugins) => {
|
367
|
+
const pluginName = getPluginName(plugin);
|
368
|
+
const append = [];
|
369
|
+
for (let i = 0; i < plugins.length; i++) {
|
370
|
+
if (getPluginName(plugins[i]) === pluginName) {
|
371
|
+
if (getOptions(plugin)) {
|
372
|
+
logger.info(
|
373
|
+
"Detected duplicated babel plugin, overrides with the new one"
|
374
|
+
);
|
375
|
+
plugins[i] = plugin;
|
376
|
+
}
|
377
|
+
} else {
|
378
|
+
append.push(plugin);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
plugins.push(...append);
|
382
|
+
};
|
383
|
+
const currentPlugins = config.plugins || [];
|
384
|
+
for (const plugin of babelOptions.plugins || []) {
|
385
|
+
replaceOrInsert(plugin, currentPlugins);
|
386
|
+
}
|
387
|
+
return {
|
388
|
+
...config,
|
389
|
+
...babelOptions,
|
390
|
+
plugins: currentPlugins,
|
391
|
+
presets: config.presets,
|
392
|
+
overrides: [
|
393
|
+
...config.overrides || [],
|
394
|
+
...babelOptions.overrides || []
|
395
|
+
]
|
396
|
+
};
|
397
|
+
};
|
398
|
+
});
|
399
|
+
api.modifyWebpackConfig(async (config) => {
|
400
|
+
const finalDefaultConfig = await presets.apply(
|
401
|
+
"webpackFinal",
|
402
|
+
config,
|
403
|
+
options
|
404
|
+
);
|
405
|
+
return finalDefaultConfig;
|
406
|
+
});
|
407
|
+
}
|
349
408
|
export {
|
350
409
|
finalize,
|
351
410
|
pluginStorybook
|
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-20231114124526",
|
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-20231114124526",
|
75
|
+
"@modern-js/builder-shared": "0.0.0-next-20231114124526",
|
76
|
+
"@modern-js/runtime": "0.0.0-next-20231114124526",
|
77
|
+
"@modern-js/core": "0.0.0-next-20231114124526",
|
78
|
+
"@modern-js/utils": "0.0.0-next-20231114124526"
|
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-
|
88
|
-
"@scripts/build": "0.0.0-next-
|
89
|
-
"@modern-js/
|
86
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20231114124526",
|
87
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20231114124526",
|
88
|
+
"@scripts/build": "0.0.0-next-20231114124526",
|
89
|
+
"@modern-js/core": "0.0.0-next-20231114124526"
|
90
90
|
},
|
91
91
|
"publishConfig": {
|
92
92
|
"registry": "https://registry.npmjs.org/",
|