@modern-js/plugin 3.0.3 → 3.0.5

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.
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  cli: ()=>index_js_namespaceObject.cli,
28
28
  mergeConfig: ()=>mergeConfig_js_namespaceObject.mergeConfig,
29
29
  createContext: ()=>external_context_js_namespaceObject.createContext,
30
+ createConfigOptions: ()=>create_js_namespaceObject.createConfigOptions,
30
31
  createStorybookOptions: ()=>create_js_namespaceObject.createStorybookOptions,
31
32
  createCli: ()=>index_js_namespaceObject.createCli,
32
33
  initAppContext: ()=>external_context_js_namespaceObject.initAppContext,
@@ -43,6 +44,7 @@ const create_js_namespaceObject = require("./run/create.js");
43
44
  const mergeConfig_js_namespaceObject = require("./run/utils/mergeConfig.js");
44
45
  exports.cli = __webpack_exports__.cli;
45
46
  exports.createCli = __webpack_exports__.createCli;
47
+ exports.createConfigOptions = __webpack_exports__.createConfigOptions;
46
48
  exports.createContext = __webpack_exports__.createContext;
47
49
  exports.createLoadedConfig = __webpack_exports__.createLoadedConfig;
48
50
  exports.createStorybookOptions = __webpack_exports__.createStorybookOptions;
@@ -54,6 +56,7 @@ exports.mergeConfig = __webpack_exports__.mergeConfig;
54
56
  for(var __rspack_i in __webpack_exports__)if (-1 === [
55
57
  "cli",
56
58
  "createCli",
59
+ "createConfigOptions",
57
60
  "createContext",
58
61
  "createLoadedConfig",
59
62
  "createStorybookOptions",
@@ -24,6 +24,7 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
+ createConfigOptions: ()=>createConfigOptions,
27
28
  createStorybookOptions: ()=>createStorybookOptions,
28
29
  createCli: ()=>createCli
29
30
  });
@@ -142,20 +143,21 @@ const createCli = ()=>{
142
143
  getPrevInitOptions: ()=>initOptions
143
144
  };
144
145
  };
145
- const createStorybookOptions = async (options)=>{
146
+ const createConfigOptions = async (options)=>{
146
147
  const pluginManager = (0, external_manager_js_namespaceObject.createPluginManager)();
147
148
  pluginManager.clear();
148
- const { configFile, cwd, metaName = 'modern-js' } = options;
149
+ const { configFile, cwd, metaName = 'modern-js', command } = options;
149
150
  const appDirectory = await (0, initAppDir_js_namespaceObject.initAppDir)(cwd);
150
- const loaded = await (0, createLoadedConfig_js_namespaceObject.createLoadedConfig)(appDirectory, configFile);
151
+ const loaded = await (0, createLoadedConfig_js_namespaceObject.createLoadedConfig)(appDirectory, configFile, options.config);
152
+ loaded.config = options.modifyModernConfig ? await options.modifyModernConfig(loaded.config || {}) : loaded.config;
151
153
  pluginManager.addPlugins(loaded.config.plugins || []);
152
154
  const plugins = await pluginManager.getPlugins();
153
155
  const context = await (0, external_context_js_namespaceObject.createContext)({
154
156
  appContext: (0, external_context_js_namespaceObject.initAppContext)({
155
157
  packageName: loaded.packageName,
156
158
  configFile: loaded.configFile,
157
- command: 'storybook',
158
159
  appDirectory,
160
+ command,
159
161
  plugins,
160
162
  metaName
161
163
  }),
@@ -171,15 +173,24 @@ const createStorybookOptions = async (options)=>{
171
173
  const extraConfigs = await context.hooks.config.call();
172
174
  const normalizedConfig = await (0, createResolvedConfig_js_namespaceObject.createResolveConfig)(loaded, extraConfigs);
173
175
  const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
176
+ const finalConfig = resolved || normalizedConfig;
177
+ context.normalizedConfig = finalConfig;
178
+ await pluginAPI.updateAppContext(context);
174
179
  return {
175
- config: resolved || normalizedConfig,
180
+ config: finalConfig,
176
181
  getAppContext: ()=>pluginAPI.getAppContext()
177
182
  };
178
183
  };
184
+ const createStorybookOptions = (options)=>createConfigOptions({
185
+ ...options,
186
+ command: 'storybook'
187
+ });
179
188
  exports.createCli = __webpack_exports__.createCli;
189
+ exports.createConfigOptions = __webpack_exports__.createConfigOptions;
180
190
  exports.createStorybookOptions = __webpack_exports__.createStorybookOptions;
181
191
  for(var __rspack_i in __webpack_exports__)if (-1 === [
182
192
  "createCli",
193
+ "createConfigOptions",
183
194
  "createStorybookOptions"
184
195
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
185
196
  Object.defineProperty(exports, '__esModule', {
@@ -2,6 +2,6 @@ import { initPluginAPI } from "./api.mjs";
2
2
  import { createContext, initAppContext } from "./context.mjs";
3
3
  import { initHooks } from "./hooks.mjs";
4
4
  import { cli, createCli, createLoadedConfig, initAppDir } from "./run/index.mjs";
5
- import { createStorybookOptions } from "./run/create.mjs";
5
+ import { createConfigOptions, createStorybookOptions } from "./run/create.mjs";
6
6
  import { mergeConfig } from "./run/utils/mergeConfig.mjs";
7
- export { cli, createCli, createContext, createLoadedConfig, createStorybookOptions, initAppContext, initAppDir, initHooks, initPluginAPI, mergeConfig };
7
+ export { cli, createCli, createConfigOptions, createContext, createLoadedConfig, createStorybookOptions, initAppContext, initAppDir, initHooks, initPluginAPI, mergeConfig };
@@ -113,20 +113,21 @@ const createCli = ()=>{
113
113
  getPrevInitOptions: ()=>initOptions
114
114
  };
115
115
  };
116
- const createStorybookOptions = async (options)=>{
116
+ const createConfigOptions = async (options)=>{
117
117
  const pluginManager = createPluginManager();
118
118
  pluginManager.clear();
119
- const { configFile, cwd, metaName = 'modern-js' } = options;
119
+ const { configFile, cwd, metaName = 'modern-js', command } = options;
120
120
  const appDirectory = await initAppDir(cwd);
121
- const loaded = await createLoadedConfig(appDirectory, configFile);
121
+ const loaded = await createLoadedConfig(appDirectory, configFile, options.config);
122
+ loaded.config = options.modifyModernConfig ? await options.modifyModernConfig(loaded.config || {}) : loaded.config;
122
123
  pluginManager.addPlugins(loaded.config.plugins || []);
123
124
  const plugins = await pluginManager.getPlugins();
124
125
  const context = await createContext({
125
126
  appContext: initAppContext({
126
127
  packageName: loaded.packageName,
127
128
  configFile: loaded.configFile,
128
- command: 'storybook',
129
129
  appDirectory,
130
+ command,
130
131
  plugins,
131
132
  metaName
132
133
  }),
@@ -142,9 +143,16 @@ const createStorybookOptions = async (options)=>{
142
143
  const extraConfigs = await context.hooks.config.call();
143
144
  const normalizedConfig = await createResolveConfig(loaded, extraConfigs);
144
145
  const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
146
+ const finalConfig = resolved || normalizedConfig;
147
+ context.normalizedConfig = finalConfig;
148
+ await pluginAPI.updateAppContext(context);
145
149
  return {
146
- config: resolved || normalizedConfig,
150
+ config: finalConfig,
147
151
  getAppContext: ()=>pluginAPI.getAppContext()
148
152
  };
149
153
  };
150
- export { createCli, createStorybookOptions };
154
+ const createStorybookOptions = (options)=>createConfigOptions({
155
+ ...options,
156
+ command: 'storybook'
157
+ });
158
+ export { createCli, createConfigOptions, createStorybookOptions };
@@ -3,6 +3,6 @@ import { initPluginAPI } from "./api.mjs";
3
3
  import { createContext, initAppContext } from "./context.mjs";
4
4
  import { initHooks } from "./hooks.mjs";
5
5
  import { cli, createCli, createLoadedConfig, initAppDir } from "./run/index.mjs";
6
- import { createStorybookOptions } from "./run/create.mjs";
6
+ import { createConfigOptions, createStorybookOptions } from "./run/create.mjs";
7
7
  import { mergeConfig } from "./run/utils/mergeConfig.mjs";
8
- export { cli, createCli, createContext, createLoadedConfig, createStorybookOptions, initAppContext, initAppDir, initHooks, initPluginAPI, mergeConfig };
8
+ export { cli, createCli, createConfigOptions, createContext, createLoadedConfig, createStorybookOptions, initAppContext, initAppDir, initHooks, initPluginAPI, mergeConfig };
@@ -114,20 +114,21 @@ const createCli = ()=>{
114
114
  getPrevInitOptions: ()=>initOptions
115
115
  };
116
116
  };
117
- const createStorybookOptions = async (options)=>{
117
+ const createConfigOptions = async (options)=>{
118
118
  const pluginManager = createPluginManager();
119
119
  pluginManager.clear();
120
- const { configFile, cwd, metaName = 'modern-js' } = options;
120
+ const { configFile, cwd, metaName = 'modern-js', command } = options;
121
121
  const appDirectory = await initAppDir(cwd);
122
- const loaded = await createLoadedConfig(appDirectory, configFile);
122
+ const loaded = await createLoadedConfig(appDirectory, configFile, options.config);
123
+ loaded.config = options.modifyModernConfig ? await options.modifyModernConfig(loaded.config || {}) : loaded.config;
123
124
  pluginManager.addPlugins(loaded.config.plugins || []);
124
125
  const plugins = await pluginManager.getPlugins();
125
126
  const context = await createContext({
126
127
  appContext: initAppContext({
127
128
  packageName: loaded.packageName,
128
129
  configFile: loaded.configFile,
129
- command: 'storybook',
130
130
  appDirectory,
131
+ command,
131
132
  plugins,
132
133
  metaName
133
134
  }),
@@ -143,9 +144,16 @@ const createStorybookOptions = async (options)=>{
143
144
  const extraConfigs = await context.hooks.config.call();
144
145
  const normalizedConfig = await createResolveConfig(loaded, extraConfigs);
145
146
  const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
147
+ const finalConfig = resolved || normalizedConfig;
148
+ context.normalizedConfig = finalConfig;
149
+ await pluginAPI.updateAppContext(context);
146
150
  return {
147
- config: resolved || normalizedConfig,
151
+ config: finalConfig,
148
152
  getAppContext: ()=>pluginAPI.getAppContext()
149
153
  };
150
154
  };
151
- export { createCli, createStorybookOptions };
155
+ const createStorybookOptions = (options)=>createConfigOptions({
156
+ ...options,
157
+ command: 'storybook'
158
+ });
159
+ export { createCli, createConfigOptions, createStorybookOptions };
@@ -2,5 +2,5 @@ export { initPluginAPI } from './api';
2
2
  export { initAppContext, createContext } from './context';
3
3
  export { initHooks, type Hooks, type OnAfterBuildFn, type OnAfterCreateCompilerFn, type OnBeforeBuildFn, type OnBeforeCreateCompilerFn, type OnDevCompileDoneFn, type AddCommandFn, type AddWatchFilesFn, type ConfigFn, type ModifyBundlerChainFn, type ModifyConfigFn, type ModifyHtmlPartialsFn, type ModifyResolvedConfigFn, type ModifyRsbuildConfigFn, type ModifyRspackConfigFn, type OnAfterDeployFn, type OnBeforeDeployFn, type OnBeforeDevFn, type OnAfterDevFn, type OnBeforeExitFn, type OnBeforeRestartFn, type OnFileChangedFn, type OnPrepareFn, type InternalRuntimePluginsFn, type InternalServerPluginsFn, type ModifyServerRoutesFn, type RuntimePluginConfig, type ServerPluginConfig, } from './hooks';
4
4
  export { cli, createLoadedConfig, initAppDir, createCli } from './run';
5
- export { createStorybookOptions } from './run/create';
5
+ export { createConfigOptions, createStorybookOptions } from './run/create';
6
6
  export { mergeConfig } from './run/utils/mergeConfig';
@@ -9,7 +9,15 @@ export declare const createCli: <Extends extends CLIPluginExtends>() => {
9
9
  getPrevInitOptions: () => CLIRunOptions<Extends>;
10
10
  };
11
11
  type UselessOptions = 'handleSetupResult' | 'command' | 'internalPlugins';
12
- export declare const createStorybookOptions: <Extends extends CLIPluginExtends>(options: Omit<CLIRunOptions<Extends>, UselessOptions>) => Promise<{
12
+ type CreateConfigOption<Extends extends CLIPluginExtends> = Omit<CLIRunOptions<Extends>, UselessOptions> & {
13
+ command: string;
14
+ modifyModernConfig?: (config: Extends['config']) => Extends['config'] | Promise<Extends['config']>;
15
+ };
16
+ export declare const createConfigOptions: <Extends extends CLIPluginExtends>(options: CreateConfigOption<Extends>) => Promise<{
17
+ config: Awaited<Extends["normalizedConfig"]> | NonNullable<Awaited<import("../../types/utils").UnwrapPromise<Extends["normalizedConfig"]>>>;
18
+ getAppContext: () => Readonly<import("../../types/cli/context").AppContext<Extends> & Extends["extendContext"]>;
19
+ }>;
20
+ export declare const createStorybookOptions: <Extends extends CLIPluginExtends>(options: Omit<CreateConfigOption<Extends>, "command">) => Promise<{
13
21
  config: Awaited<Extends["normalizedConfig"]> | NonNullable<Awaited<import("../../types/utils").UnwrapPromise<Extends["normalizedConfig"]>>>;
14
22
  getAppContext: () => Readonly<import("../../types/cli/context").AppContext<Extends> & Extends["extendContext"]>;
15
23
  }>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.0.3",
18
+ "version": "3.0.5",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -85,16 +85,16 @@
85
85
  "@rsbuild/core": "2.0.0-beta.4",
86
86
  "@swc/helpers": "^0.5.17",
87
87
  "jiti": "^2.6.1",
88
- "@modern-js/runtime-utils": "3.0.3",
89
- "@modern-js/types": "3.0.3",
90
- "@modern-js/utils": "3.0.3"
88
+ "@modern-js/runtime-utils": "3.0.5",
89
+ "@modern-js/types": "3.0.5",
90
+ "@modern-js/utils": "3.0.5"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@rslib/core": "0.19.6",
94
94
  "@types/node": "^20",
95
95
  "@types/react": "^19.2.14",
96
96
  "typescript": "^5",
97
- "@modern-js/builder": "3.0.3",
97
+ "@modern-js/builder": "3.0.5",
98
98
  "@modern-js/rslib": "2.68.10"
99
99
  },
100
100
  "sideEffects": false,