@modern-js/storybook-builder 0.0.0-next-20231114034808 → 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/plugin-storybook.js +51 -0
- package/dist/esm/plugin-storybook.js +60 -1
- package/package.json +10 -10
@@ -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,
|
@@ -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/builder-
|
87
|
-
"@modern-js/builder-
|
88
|
-
"@scripts/build": "0.0.0-next-
|
89
|
-
"@modern-js/core": "0.0.0-next-
|
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/",
|