Skip to content

Commit

Permalink
chore: add wrapConsoleTimeAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 28, 2023
1 parent 72dcd49 commit 4417a49
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,21 @@ const writeFileSafe = async (file: string, contents: string): Promise<void> => {
await fse.writeFile(file, contents);
};

const getRouteManifestModuleExports = async (
function wrapConsoleTimeAsync<F extends (...args: any[]) => any>(f: F) {
const wrapper = async function (this: any, ...args: any[]) {
const id = Math.random().toString(36).slice(2).padStart(12, "0");
const label = `${f.name}:${id}`;
globalThis.console.time(label);
try {
return await f.apply(this, args);
} finally {
globalThis.console.timeEnd(label);
}
}
return wrapper as F;
}

let getRouteManifestModuleExports = async (
viteChildCompiler: Vite.ViteDevServer | null,
pluginConfig: ResolvedRemixVitePluginConfig
): Promise<Record<string, string[]>> => {
Expand All @@ -222,7 +236,9 @@ const getRouteManifestModuleExports = async (
return Object.fromEntries(entries);
};

const getRouteModuleExports = async (
getRouteManifestModuleExports = wrapConsoleTimeAsync(getRouteManifestModuleExports);

let getRouteModuleExports = async (
viteChildCompiler: Vite.ViteDevServer | null,
pluginConfig: ResolvedRemixVitePluginConfig,
routeFile: string
Expand All @@ -247,6 +263,8 @@ const getRouteModuleExports = async (
return exportNames;
};

getRouteModuleExports = wrapConsoleTimeAsync(getRouteModuleExports);

const showUnstableWarning = () => {
console.warn(
colors.yellow(
Expand Down

0 comments on commit 4417a49

Please sign in to comment.