diff --git a/packages/solutions/app-tools/src/new/getConfigFile.ts b/packages/solutions/app-tools/src/new/getConfigFile.ts index 7ce753f52dc8..2a7819d09cd7 100644 --- a/packages/solutions/app-tools/src/new/getConfigFile.ts +++ b/packages/solutions/app-tools/src/new/getConfigFile.ts @@ -2,9 +2,12 @@ import path from 'path'; import { CONFIG_FILE_EXTENSIONS, findExists } from '@modern-js/utils'; import { DEFAULT_CONFIG_FILE } from './constants'; -export const getConfigFile = () => +export const getConfigFile = (configFile?: string) => findExists( CONFIG_FILE_EXTENSIONS.map(extension => - path.resolve(process.cwd(), `${DEFAULT_CONFIG_FILE}${extension}`), + path.resolve( + process.cwd(), + `${configFile || DEFAULT_CONFIG_FILE}${extension}`, + ), ), ); diff --git a/packages/solutions/app-tools/src/new/index.ts b/packages/solutions/app-tools/src/new/index.ts index 5c9b9051c98e..06a1cd53094c 100644 --- a/packages/solutions/app-tools/src/new/index.ts +++ b/packages/solutions/app-tools/src/new/index.ts @@ -29,6 +29,7 @@ import type { } from './types'; export * from '../defineConfig'; +export { initAppContext }; export type AppToolsOptions = { /** @@ -38,20 +39,22 @@ export type AppToolsOptions = { bundler?: 'rspack' | 'webpack' | 'experimental-rspack'; }; -export const appTools = ( - options: AppToolsOptions = { - // default webpack to be compatible with original projects - bundler: 'webpack', - }, -): Plugin< +export type AppToolsPlugin = Plugin< AppTools<'shared'>, InternalContext< AppToolsUserConfig<'shared'>, AppToolsNormalizedConfig, AppToolsExtendAPIName<'shared'> > -> => ({ - name: '@modern-js/plugin-app-tools', +>; + +export const appTools = ( + options: AppToolsOptions = { + // default webpack to be compatible with original projects + bundler: 'webpack', + }, +): AppToolsPlugin => ({ + name: '@modern-js/app-tools', usePlugins: [compatPlugin(), oldAppTools(options) as any], post: ['@modern-js/app-tools-old'], registryHooks: { diff --git a/packages/solutions/app-tools/src/new/run.ts b/packages/solutions/app-tools/src/new/run.ts index e8ba9c517d18..a3dfe8f001d5 100644 --- a/packages/solutions/app-tools/src/new/run.ts +++ b/packages/solutions/app-tools/src/new/run.ts @@ -10,6 +10,7 @@ import { getIsAutoLoadPlugins } from './utils'; export interface RunOptions { cwd?: string; + configFile?: string; packageJsonConfig?: string; internalPlugins?: { cli?: InternalPlugins; @@ -24,6 +25,7 @@ export async function run({ internalPlugins, forceAutoLoadPlugins, packageJsonConfig, + configFile, }: RunOptions) { const command = process.argv[2]; @@ -58,7 +60,7 @@ export async function run({ const appDirectory = await initAppDir(cwd); const autoLoadPlugins = await getIsAutoLoadPlugins( appDirectory, - customConfigFile || getConfigFile(), + customConfigFile || getConfigFile(configFile), ); const plugins = await loadInternalPlugins( appDirectory, @@ -71,7 +73,7 @@ export async function run({ await CLIPluginRun({ cwd, initialLog: `Modern.js Framework v${version}`, - configFile: customConfigFile || getConfigFile(), + configFile: customConfigFile || getConfigFile(configFile), packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME, internalPlugins: plugins, handleSetupResult,