Skip to content

Commit

Permalink
feat: support configFile for run function
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Nov 14, 2024
1 parent 8e0a6c4 commit 31b83d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
7 changes: 5 additions & 2 deletions packages/solutions/app-tools/src/new/getConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
),
),
);
19 changes: 11 additions & 8 deletions packages/solutions/app-tools/src/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
} from './types';

export * from '../defineConfig';
export { initAppContext };

export type AppToolsOptions = {
/**
Expand All @@ -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: {
Expand Down
6 changes: 4 additions & 2 deletions packages/solutions/app-tools/src/new/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getIsAutoLoadPlugins } from './utils';

export interface RunOptions {
cwd?: string;
configFile?: string;
packageJsonConfig?: string;
internalPlugins?: {
cli?: InternalPlugins;
Expand All @@ -24,6 +25,7 @@ export async function run({
internalPlugins,
forceAutoLoadPlugins,
packageJsonConfig,
configFile,
}: RunOptions) {
const command = process.argv[2];

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 31b83d0

Please sign in to comment.