@modern-js/storybook-builder 0.0.0-next-20231114141546 → 0.0.0-next-20231115182236

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.
@@ -89,7 +89,6 @@ const pluginStorybook = (cwd, options) => {
89
89
  await applyCsfPlugin(config, options);
90
90
  };
91
91
  if ("modifyWebpackConfig" in api) {
92
- addonAdapter(api, options);
93
92
  api.modifyWebpackConfig(modifyConfig);
94
93
  api.modifyWebpackChain(async (chain) => {
95
94
  await (0, import_docgen.applyDocgenWebpack)(chain, options);
@@ -331,68 +330,6 @@ async function watchStories(patterns, cwd, writeModule) {
331
330
  ]);
332
331
  return watcher;
333
332
  }
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
- }
396
333
  // Annotate the CommonJS export names for ESM import in node:
397
334
  0 && (module.exports = {
398
335
  finalize,
@@ -1,11 +1,5 @@
1
1
  import { isAbsolute, join, resolve } from "path";
2
- import {
3
- slash,
4
- watch,
5
- globby,
6
- applyOptionsChain,
7
- logger
8
- } from "@modern-js/utils";
2
+ import { slash, watch, globby, applyOptionsChain } from "@modern-js/utils";
9
3
  import {
10
4
  mergeBuilderConfig
11
5
  } from "@modern-js/builder-shared";
@@ -79,7 +73,6 @@ const pluginStorybook = (cwd, options) => {
79
73
  await applyCsfPlugin(config, options);
80
74
  };
81
75
  if ("modifyWebpackConfig" in api) {
82
- addonAdapter(api, options);
83
76
  api.modifyWebpackConfig(modifyConfig);
84
77
  api.modifyWebpackChain(async (chain) => {
85
78
  await applyDocgenWebpack(chain, options);
@@ -353,68 +346,6 @@ async function watchStories(patterns, cwd, writeModule) {
353
346
  );
354
347
  return watcher;
355
348
  }
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
- }
418
349
  export {
419
350
  finalize,
420
351
  pluginStorybook
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/storybook-builder",
3
- "version": "0.0.0-next-20231114141546",
3
+ "version": "0.0.0-next-20231115182236",
4
4
  "description": "modern.js support for storybook",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,19 +17,19 @@
17
17
  ],
18
18
  "exports": {
19
19
  ".": {
20
- "jsnext:source": "./src/index.ts",
21
20
  "types": "./dist/types/index.d.ts",
21
+ "jsnext:source": "./src/index.ts",
22
22
  "default": "./dist/cjs/index.js"
23
23
  },
24
24
  "./preset": "./dist/esm/preset.js",
25
25
  "./addons": {
26
- "jsnext:source": "./src/addons/preset/preview.ts",
27
26
  "types": "./dist/types/addons/preset/preview.d.ts",
27
+ "jsnext:source": "./src/addons/preset/preview.ts",
28
28
  "default": "./dist/esm/addons/preset/preview.js"
29
29
  },
30
30
  "./types": {
31
- "jsnext:source": "./src/types.ts",
32
31
  "types": "./dist/types/types.d.ts",
32
+ "jsnext:source": "./src/types.ts",
33
33
  "default": "./dist/cjs/types.js"
34
34
  },
35
35
  "./templates/preview.ejs": "./templates/preview.ejs",
@@ -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-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"
74
+ "@modern-js/builder": "0.0.0-next-20231115182236",
75
+ "@modern-js/builder-shared": "0.0.0-next-20231115182236",
76
+ "@modern-js/core": "0.0.0-next-20231115182236",
77
+ "@modern-js/runtime": "0.0.0-next-20231115182236",
78
+ "@modern-js/utils": "0.0.0-next-20231115182236"
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-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"
86
+ "@modern-js/builder-rspack-provider": "0.0.0-next-20231115182236",
87
+ "@modern-js/builder-webpack-provider": "0.0.0-next-20231115182236",
88
+ "@modern-js/core": "0.0.0-next-20231115182236",
89
+ "@scripts/build": "0.0.0-next-20231115182236"
90
90
  },
91
91
  "publishConfig": {
92
92
  "registry": "https://registry.npmjs.org/",
@@ -27,13 +27,13 @@ window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore
27
27
 
28
28
  preview.initialize({ importFn, getProjectAnnotations });
29
29
 
30
- if (import.meta.webpackHot) {
31
- import.meta.webpackHot.accept('./{{storiesFilename}}', () => {
30
+ if (module.hot) {
31
+ module.hot.accept('./{{storiesFilename}}', () => {
32
32
  // importFn has changed so we need to patch the new one in
33
33
  preview.onStoriesChanged({ importFn });
34
34
  });
35
35
 
36
- import.meta.webpackHot.accept([
36
+ module.hot.accept([
37
37
  {{#each previewAnnotations}}'{{this}}',
38
38
  {{/each}}
39
39
  ], () => {