From 648a0dfb6f3b7b80ac294d407628d9efd5c08b40 Mon Sep 17 00:00:00 2001 From: Glenn Gore Date: Wed, 25 Nov 2026 08:12:04 -0800 Subject: [PATCH] chore(extension): clear Vite and Node deprecation warnings in the build and tests - Vite configs use import.meta.dirname instead of __dirname, which Vite 8 flags as unsupported by the native config loader it plans to make the default. - The test harness installs its .tsx resolve/load hooks with module.registerHooks (synchronous, in-thread) instead of module.register, deprecated as DEP0205 on Node 26. The hooks were already effectively synchronous (esbuild.transformSync); the file read becomes readFileSync. Signed-off-by: Glenn Gore --- packages/extension/tests/harness/hooks.mjs | 13 ++++++------- packages/extension/tests/harness/register.mjs | 8 ++++++-- packages/extension/vite.config.background.ts | 2 +- packages/extension/vite.config.content.ts | 2 +- packages/extension/vite.config.manager.ts | 2 +- packages/extension/vite.config.ts | 12 ++++++------ 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/extension/tests/harness/hooks.mjs b/packages/extension/tests/harness/hooks.mjs index 5b0e7f19..058aa451 100644 --- a/packages/extension/tests/harness/hooks.mjs +++ b/packages/extension/tests/harness/hooks.mjs @@ -39,17 +39,16 @@ // the agent (`tests/harness/dom.mjs`), rather than this file inventing a module // graph the real build never has. -import { existsSync } from "node:fs"; -import { readFile } from "node:fs/promises"; +import { existsSync, readFileSync } from "node:fs"; import { fileURLToPath, pathToFileURL } from "node:url"; import { createRequire } from "node:module"; -// Required rather than imported: esbuild is CJS, and the sync transform is what -// keeps this hook simple — no service to start on a loader thread. +// Required rather than imported: esbuild is CJS, and its sync transform is what +// lets these be synchronous `registerHooks` hooks — no service to start. const esbuild = createRequire(import.meta.url)("esbuild"); /** `./x.js` → `./x.tsx` → `./x.ts`, when the `.js` is not on disk. */ -export async function resolve(specifier, context, nextResolve) { +export function resolve(specifier, context, nextResolve) { if (specifier.endsWith(".js") && (specifier.startsWith(".") || specifier.startsWith("/"))) { const base = context.parentURL ?? pathToFileURL(`${process.cwd()}/`).href; const asJs = new URL(specifier, base); @@ -69,12 +68,12 @@ export async function resolve(specifier, context, nextResolve) { return nextResolve(specifier, context); } -export async function load(url, context, nextLoad) { +export function load(url, context, nextLoad) { const isTsx = url.endsWith(".tsx"); const isTs = url.endsWith(".ts") && !url.includes("/node_modules/"); if (!isTsx && !isTs) return nextLoad(url, context); const path = fileURLToPath(url); - const source = await readFile(path, "utf8"); + const source = readFileSync(path, "utf8"); const { code } = esbuild.transformSync(source, { loader: isTsx ? "tsx" : "ts", // The automatic runtime, matching `tsconfig.base.json`'s `jsx: react-jsx`, diff --git a/packages/extension/tests/harness/register.mjs b/packages/extension/tests/harness/register.mjs index ea502a8f..bca5a1dc 100644 --- a/packages/extension/tests/harness/register.mjs +++ b/packages/extension/tests/harness/register.mjs @@ -1,3 +1,7 @@ // Installs the `.tsx` hooks. Passed to `node --import` by the test script. -import { register } from "node:module"; -register("./hooks.mjs", import.meta.url); +// `registerHooks` runs the hooks synchronously on this thread; the older +// `module.register` (off-thread, async hooks) is deprecated as of Node 26 +// (DEP0205). +import { registerHooks } from "node:module"; +import { resolve, load } from "./hooks.mjs"; +registerHooks({ resolve, load }); diff --git a/packages/extension/vite.config.background.ts b/packages/extension/vite.config.background.ts index d220266a..bd168616 100644 --- a/packages/extension/vite.config.background.ts +++ b/packages/extension/vite.config.background.ts @@ -21,7 +21,7 @@ export default defineConfig({ // top-level-await plugin's destructuring to vite's default targets. target: "es2022", rollupOptions: { - input: { background: resolve(__dirname, "src/background.ts") }, + input: { background: resolve(import.meta.dirname, "src/background.ts") }, output: { entryFileNames: "background.js", codeSplitting: false, diff --git a/packages/extension/vite.config.content.ts b/packages/extension/vite.config.content.ts index d938575b..f4cc7eec 100644 --- a/packages/extension/vite.config.content.ts +++ b/packages/extension/vite.config.content.ts @@ -21,7 +21,7 @@ export default defineConfig({ emptyOutDir: false, target: "es2022", rollupOptions: { - input: { content: resolve(__dirname, "src/content.ts") }, + input: { content: resolve(import.meta.dirname, "src/content.ts") }, output: { entryFileNames: "content.js", format: "iife", diff --git a/packages/extension/vite.config.manager.ts b/packages/extension/vite.config.manager.ts index 75e55e8b..288f3930 100644 --- a/packages/extension/vite.config.manager.ts +++ b/packages/extension/vite.config.manager.ts @@ -38,7 +38,7 @@ export default defineConfig({ // top-level-await plugin's destructuring to vite's default targets. target: "es2022", rollupOptions: { - input: { manager: resolve(__dirname, "manager.html") }, + input: { manager: resolve(import.meta.dirname, "manager.html") }, output: { entryFileNames: "manager.js", // Named so the guard can address it, and so a stray second chunk is diff --git a/packages/extension/vite.config.ts b/packages/extension/vite.config.ts index 203ec85e..38bf90b9 100644 --- a/packages/extension/vite.config.ts +++ b/packages/extension/vite.config.ts @@ -26,7 +26,7 @@ function emitManifest() { writeBundle() { const manifest = buildManifest({ includeKey: true }); writeFileSync( - resolve(__dirname, "dist/manifest.json"), + resolve(import.meta.dirname, "dist/manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`, ); }, @@ -62,11 +62,11 @@ export default defineConfig({ modulePreload: false, rollupOptions: { input: { - popup: resolve(__dirname, "popup.html"), - options: resolve(__dirname, "options.html"), - confirm: resolve(__dirname, "confirm.html"), - offscreen: resolve(__dirname, "offscreen.html"), - provider: resolve(__dirname, "src/provider.ts"), + popup: resolve(import.meta.dirname, "popup.html"), + options: resolve(import.meta.dirname, "options.html"), + confirm: resolve(import.meta.dirname, "confirm.html"), + offscreen: resolve(import.meta.dirname, "offscreen.html"), + provider: resolve(import.meta.dirname, "src/provider.ts"), }, output: { // Fixed names for the files the manifest references by path.