Skip to content

Commit

Permalink
Merge branch 'v2-dev' into chore/network_url_by_default
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost authored Jan 31, 2025
2 parents e4cd69b + fef8727 commit 411fd85
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {

import {
Logger,
clearScreen,
colors,
isArray,
isEmptyObject,
Expand Down Expand Up @@ -161,7 +160,12 @@ export async function resolveConfig(
...vitePluginAdapters
]);

const config = await resolveConfigHook(userConfig, sortFarmJsPlugins);
const config = await resolveConfigHook(
userConfig,
configEnv,
sortFarmJsPlugins
);

// may be user push plugin when config hooks
const allPlugins = await resolvePlugins(config, defaultMode);
const farmJsPlugins = getSortedPlugins([
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function build(

logger.info(
`Build completed in ${bold(
green(`${logger.formatExecutionTime(elapsedTime)}`)
green(`${logger.formatTime(elapsedTime)}`)
)} ${persistentCacheText} Resources emitted to ${bold(
green(output.path)
)}.`
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './rust/index.js';

import {
CompilationMode,
ConfigEnv,
ResolvedUserConfig,
type UserConfig
} from '../config/index.js';
Expand Down Expand Up @@ -91,6 +92,7 @@ export async function resolveAsyncPlugins<T>(arr: T[]): Promise<T[]> {

export async function resolveConfigHook(
config: UserConfig,
configEnv: ConfigEnv,
plugins: JsPlugin[]
): Promise<UserConfig> {
let conf = config;
Expand All @@ -107,7 +109,7 @@ export async function resolveConfigHook(

for (const p of uniqueVitePlugins.values()) {
if (p.config) {
const res = await p.config(conf);
const res = await p.config(conf, configEnv);

if (res) {
conf = merge(conf, res);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/plugin/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Compiler,
ConfigEnv,
ModuleContext,
ResolvedUserConfig,
Server,
Expand Down Expand Up @@ -155,7 +156,10 @@ export interface JsPlugin {
name: string;
priority?: number;

config?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
config?: (
config: UserConfig,
configEnv: ConfigEnv
) => UserConfig | Promise<UserConfig>;

configResolved?: (config: ResolvedUserConfig) => void | Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/hmr-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class HmrEngine {
const result = await this.app.compiler.update(queue);

logger.info(
`${bold(cyan(updatedFilesStr))} updated in ${bold(green(logger.formatExecutionTime(performance.now() - start)))}`
`${bold(cyan(updatedFilesStr))} updated in ${bold(green(logger.formatTime(performance.now() - start)))}`
);

// clear update queue after update finished
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/middlewares/lazyCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function lazyCompilationMiddleware(
`${bold(green(`✓ Lazy compilation done`))} ${bold(
cyan(pathsStr)
)} in ${bold(
green(config.logger.formatExecutionTime(performance.now() - start))
green(config.logger.formatTime(performance.now() - start))
)}.`
);

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Logger implements ILogger {
this.prefix = color ? color(formattedPrefix) : formattedPrefix;
}

formatExecutionTime(duration: number): string {
formatTime(duration: number): string {
if (this.timeUnit === 's') {
return `${(duration / 1000).toFixed(3)}s`;
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class Logger implements ILogger {
loggerMessage = message.replace(timeRegex, (_, durationStr) => {
const duration = parseFloat(durationStr);

return this.formatExecutionTime(duration);
return this.formatTime(duration);
});
} else {
loggerMessage = message.message;
Expand Down Expand Up @@ -260,7 +260,7 @@ export function bootstrapLogger(options?: LoggerOptions): Logger {
}

export function bootstrap(
times: number,
time: number,
config: ResolvedUserConfig,
hasCacheDir: boolean
): void {
Expand All @@ -282,7 +282,7 @@ export function bootstrap(
`${colors.bold(colors.green(` ✓`))} ${colors.bold(
'Compile in'
)} ${colors.bold(
colors.green(config.logger.formatExecutionTime(times))
colors.green(config.logger.formatTime(time))
)} ${persistentCacheFlag}`,
'\n'
);
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/utils/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ export function tryStatSync(file: string): fs.Stats | undefined {
} catch {}
}

export function formatExecutionTime(
time: number,
format: 'ms' | 's' = 'ms'
): string {
export function formatTime(time: number, format: 'ms' | 's' = 'ms'): string {
switch (format) {
case 's':
return `${Math.floor(time) / 1000}s`;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/watcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function handlerWatcher(
const elapsedTime = Math.floor(performance.now() - start);
logger.info(
`update completed in ${bold(
green(`${logger.formatExecutionTime(elapsedTime)}ms`)
green(`${logger.formatTime(elapsedTime)}`)
)} Resources emitted to ${bold(
green(resolvedUserConfig.compilation.output.path)
)}.`
Expand Down

0 comments on commit 411fd85

Please sign in to comment.