Skip to content

Commit 0013362

Browse files
authored
feat: adjust cli plugin type (#6665)
1 parent a488346 commit 0013362

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.changeset/smart-lamps-shout.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/app-tools': patch
3+
'@modern-js/plugin-v2': patch
4+
---
5+
6+
feat: adjust cli plugin type
7+
8+
feat: 调整 CLI 插件类型定义

packages/solutions/app-tools/src/run/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ export async function run({
5959
customConfigFile = cliParams['config-file'];
6060
}
6161

62+
// set NODE_ENV value because configFile may use
63+
if (!process.env.NODE_ENV) {
64+
if (['build', 'serve', 'deploy', 'analyze'].includes(command)) {
65+
process.env.NODE_ENV = 'production';
66+
} else if (command === 'test') {
67+
process.env.NODE_ENV = 'test';
68+
} else {
69+
process.env.NODE_ENV = 'development';
70+
}
71+
}
72+
6273
const appDirectory = await initAppDir(cwd);
6374
const finalConfigFile = customConfigFile || getConfigFile(configFile);
6475
const autoLoadPlugins = await isAutoLoadPlugins(

packages/solutions/app-tools/src/types/new.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export interface AppToolsExtendHooks
145145
addRuntimeExports: AsyncHook<AddRuntimeExportsFn>;
146146
}
147147

148-
export type AppToolsExtendContext<B extends Bundler = 'webpack'> = {
148+
export interface AppToolsExtendContext<B extends Bundler = 'webpack'> {
149149
metaName: string;
150150
internalDirectory: string;
151151
sharedDirectory: string;
@@ -180,7 +180,7 @@ export type AppToolsExtendContext<B extends Bundler = 'webpack'> = {
180180
* @deprecated compat old plugin, default is app tools
181181
*/
182182
toolsType?: string;
183-
};
183+
}
184184

185185
export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<
186186
AppTools<B>

packages/toolkit/plugin-v2/src/types/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type Plugin<PluginAPI = {}, Context = {}> = {
2929
* This function is called once when the plugin is initialized.
3030
* @param api provides the context info, utility functions and lifecycle hooks.
3131
*/
32-
setup: (api: PluginAPI) => MaybePromise<void>;
32+
setup?: (api: PluginAPI) => MaybePromise<void>;
3333
/**
3434
* Declare the names of pre-plugins, which will be executed before the current plugin.
3535
*/

0 commit comments

Comments
 (0)