@modern-js/storybook-builder 0.0.0-next-20231114083144 → 0.0.0-next-20231114141546
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 +63 -0
- package/dist/esm/core.js +0 -56
- package/dist/esm/plugin-storybook.js +70 -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,68 @@ 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;
|
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
|
+
const userConfig = finalConfig.tools.babel;
|
344
|
+
finalConfig.tools.babel = (config, utils) => {
|
345
|
+
const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
|
346
|
+
const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
|
347
|
+
const replaceOrInsert = (plugin, plugins) => {
|
348
|
+
const pluginName = getPluginName(plugin);
|
349
|
+
const append = [];
|
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
|
+
} else {
|
357
|
+
append.push(plugin);
|
358
|
+
}
|
359
|
+
}
|
360
|
+
plugins.push(...append);
|
361
|
+
};
|
362
|
+
const currentPlugins = config.plugins || [];
|
363
|
+
const currentPresets = config.presets || [];
|
364
|
+
for (const plugin of babelOptions.plugins || []) {
|
365
|
+
replaceOrInsert(plugin, currentPlugins);
|
366
|
+
}
|
367
|
+
for (const preset of babelOptions.presets || []) {
|
368
|
+
replaceOrInsert(preset, currentPresets);
|
369
|
+
}
|
370
|
+
const finalConfig2 = {
|
371
|
+
...config,
|
372
|
+
...babelOptions,
|
373
|
+
plugins: currentPlugins,
|
374
|
+
presets: currentPresets
|
375
|
+
};
|
376
|
+
if (typeof userConfig === "function") {
|
377
|
+
return userConfig(finalConfig2, utils);
|
378
|
+
} else if (typeof userConfig === "object") {
|
379
|
+
return {
|
380
|
+
...finalConfig2,
|
381
|
+
...userConfig
|
382
|
+
};
|
383
|
+
} else {
|
384
|
+
return finalConfig2;
|
385
|
+
}
|
386
|
+
};
|
387
|
+
});
|
388
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
389
|
+
chain.module.rule(CHAIN_ID.RULE.JS);
|
390
|
+
});
|
391
|
+
api.modifyWebpackConfig(async (config) => {
|
392
|
+
const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
|
393
|
+
return finalDefaultConfig;
|
394
|
+
});
|
395
|
+
}
|
333
396
|
// Annotate the CommonJS export names for ESM import in node:
|
334
397
|
0 && (module.exports = {
|
335
398
|
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,68 @@ 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;
|
360
|
+
const babelOptions = await presets.apply("babel", {}, { ...options });
|
361
|
+
(_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
|
362
|
+
const userConfig = finalConfig.tools.babel;
|
363
|
+
finalConfig.tools.babel = (config, utils) => {
|
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 or presets: ${pluginName}, 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
|
+
const currentPresets = config.presets || [];
|
385
|
+
for (const plugin of babelOptions.plugins || []) {
|
386
|
+
replaceOrInsert(plugin, currentPlugins);
|
387
|
+
}
|
388
|
+
for (const preset of babelOptions.presets || []) {
|
389
|
+
replaceOrInsert(preset, currentPresets);
|
390
|
+
}
|
391
|
+
const finalConfig2 = {
|
392
|
+
...config,
|
393
|
+
...babelOptions,
|
394
|
+
plugins: currentPlugins,
|
395
|
+
presets: currentPresets
|
396
|
+
};
|
397
|
+
if (typeof userConfig === "function") {
|
398
|
+
return userConfig(finalConfig2, utils);
|
399
|
+
} else if (typeof userConfig === "object") {
|
400
|
+
return { ...finalConfig2, ...userConfig };
|
401
|
+
} else {
|
402
|
+
return finalConfig2;
|
403
|
+
}
|
404
|
+
};
|
405
|
+
});
|
406
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
407
|
+
chain.module.rule(CHAIN_ID.RULE.JS);
|
408
|
+
});
|
409
|
+
api.modifyWebpackConfig(async (config) => {
|
410
|
+
const finalDefaultConfig = await presets.apply(
|
411
|
+
"webpackFinal",
|
412
|
+
config,
|
413
|
+
options
|
414
|
+
);
|
415
|
+
return finalDefaultConfig;
|
416
|
+
});
|
417
|
+
}
|
349
418
|
export {
|
350
419
|
finalize,
|
351
420
|
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-20231114141546",
|
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/
|
74
|
+
"@modern-js/builder-shared": "0.0.0-next-20231114141546",
|
75
|
+
"@modern-js/builder": "0.0.0-next-20231114141546",
|
76
|
+
"@modern-js/runtime": "0.0.0-next-20231114141546",
|
77
|
+
"@modern-js/utils": "0.0.0-next-20231114141546",
|
78
|
+
"@modern-js/core": "0.0.0-next-20231114141546"
|
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
|
-
"@
|
89
|
-
"@
|
86
|
+
"@modern-js/builder-webpack-provider": "0.0.0-next-20231114141546",
|
87
|
+
"@modern-js/builder-rspack-provider": "0.0.0-next-20231114141546",
|
88
|
+
"@modern-js/core": "0.0.0-next-20231114141546",
|
89
|
+
"@scripts/build": "0.0.0-next-20231114141546"
|
90
90
|
},
|
91
91
|
"publishConfig": {
|
92
92
|
"registry": "https://registry.npmjs.org/",
|