chore: update to vite's hook filter (#3333)
Fixes https://github.com/denoland/fresh/issues/3331
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
"jsr:@std/assert@^1.0.14": "1.0.14",
|
||||
"jsr:@std/async@1": "1.0.14",
|
||||
"jsr:@std/async@^1.0.13": "1.0.14",
|
||||
"jsr:@std/bytes@^1.0.2": "1.0.6",
|
||||
"jsr:@std/bytes@^1.0.5": "1.0.6",
|
||||
"jsr:@std/bytes@^1.0.6": "1.0.6",
|
||||
"jsr:@std/cli@^1.0.19": "1.0.21",
|
||||
"jsr:@std/cli@^1.0.21": "1.0.21",
|
||||
@@ -41,7 +41,7 @@
|
||||
"jsr:@std/http@^1.0.15": "1.0.20",
|
||||
"jsr:@std/internal@^1.0.10": "1.0.10",
|
||||
"jsr:@std/internal@^1.0.9": "1.0.10",
|
||||
"jsr:@std/io@0.225": "0.225.0",
|
||||
"jsr:@std/io@0.225": "0.225.2",
|
||||
"jsr:@std/io@0.225.0": "0.225.0",
|
||||
"jsr:@std/json@^1.0.2": "1.0.2",
|
||||
"jsr:@std/jsonc@1": "1.0.2",
|
||||
@@ -58,7 +58,7 @@
|
||||
"jsr:@std/toml@^1.0.3": "1.0.8",
|
||||
"jsr:@std/uuid@^1.0.7": "1.0.9",
|
||||
"jsr:@std/yaml@^1.0.5": "1.0.9",
|
||||
"jsr:@zip-js/zip-js@^2.7.52": "2.7.72",
|
||||
"jsr:@zip-js/zip-js@^2.7.52": "2.7.73",
|
||||
"npm:@babel/core@^7.28.0": "7.28.3",
|
||||
"npm:@babel/preset-react@^7.27.1": "7.27.1_@babel+core@7.28.3",
|
||||
"npm:@mjackson/node-fetch-server@0.7": "0.7.0",
|
||||
@@ -98,10 +98,8 @@
|
||||
"npm:tailwindcss@^4.1.10": "4.1.12",
|
||||
"npm:ts-morph@26": "26.0.0",
|
||||
"npm:vite-plugin-inspect@^11.3.2": "11.3.3_vite@7.1.4__@types+node@24.3.0__picomatch@4.0.3_@types+node@24.3.0_@types+node@24.2.0",
|
||||
"npm:vite@*": "7.1.3_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0",
|
||||
"npm:vite@7.1.3": "7.1.3_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0",
|
||||
"npm:vite@*": "7.1.4_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0",
|
||||
"npm:vite@7.1.4": "7.1.4_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0",
|
||||
"npm:vite@^7.1.3": "7.1.4_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0",
|
||||
"npm:vite@^7.1.4": "7.1.4_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0"
|
||||
},
|
||||
"jsr": {
|
||||
@@ -247,9 +245,12 @@
|
||||
"integrity": "e3be62ce42cab0e177c27698e5d9800122f67b766a0bea6ca4867886cbde8cf7"
|
||||
},
|
||||
"@std/io@0.225.0": {
|
||||
"integrity": "c1db7c5e5a231629b32d64b9a53139445b2ca640d828c26bf23e1c55f8c079b3",
|
||||
"integrity": "c1db7c5e5a231629b32d64b9a53139445b2ca640d828c26bf23e1c55f8c079b3"
|
||||
},
|
||||
"@std/io@0.225.2": {
|
||||
"integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7",
|
||||
"dependencies": [
|
||||
"jsr:@std/bytes@^1.0.2"
|
||||
"jsr:@std/bytes@^1.0.5"
|
||||
]
|
||||
},
|
||||
"@std/json@1.0.2": {
|
||||
@@ -318,8 +319,8 @@
|
||||
"@zip-js/zip-js@2.7.62": {
|
||||
"integrity": "11cbe0746fa1e52e6e0a601c89ba97365f16e38a07f139b9d9914f988aec9081"
|
||||
},
|
||||
"@zip-js/zip-js@2.7.72": {
|
||||
"integrity": "b72877f90aaefa1f1bd265d51f354bb58b6dd0d0e2799c865584acf49eae9115"
|
||||
"@zip-js/zip-js@2.7.73": {
|
||||
"integrity": "14c123f0e534377a6f47c5ba5293bb6c0f3e72e78c6a687108011605420a4867"
|
||||
}
|
||||
},
|
||||
"npm": {
|
||||
@@ -2611,16 +2612,6 @@
|
||||
"reusify@1.1.0": {
|
||||
"integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw=="
|
||||
},
|
||||
"rollup-plugin-visualizer@6.0.3": {
|
||||
"integrity": "sha512-ZU41GwrkDcCpVoffviuM9Clwjy5fcUxlz0oMoTXTYsK+tcIFzbdacnrr2n8TXcHxbGKKXtOdjxM2HUS4HjkwIw==",
|
||||
"dependencies": [
|
||||
"open@8.4.2",
|
||||
"picomatch@4.0.3",
|
||||
"source-map",
|
||||
"yargs"
|
||||
],
|
||||
"bin": true
|
||||
},
|
||||
"rollup-plugin-visualizer@6.0.3_rollup@4.50.0": {
|
||||
"integrity": "sha512-ZU41GwrkDcCpVoffviuM9Clwjy5fcUxlz0oMoTXTYsK+tcIFzbdacnrr2n8TXcHxbGKKXtOdjxM2HUS4HjkwIw==",
|
||||
"dependencies": [
|
||||
@@ -2942,44 +2933,6 @@
|
||||
"vite-dev-rpc@1.1.0_vite@7.1.4__@types+node@24.3.0__picomatch@4.0.3_@types+node@24.3.0_@types+node@24.2.0"
|
||||
]
|
||||
},
|
||||
"vite@7.1.3_@types+node@24.3.0_picomatch@4.0.3": {
|
||||
"integrity": "sha512-OOUi5zjkDxYrKhTV3V7iKsoS37VUM7v40+HuwEmcrsf11Cdx9y3DIr2Px6liIcZFwt3XSRpQvFpL3WVy7ApkGw==",
|
||||
"dependencies": [
|
||||
"@types/node@24.3.0",
|
||||
"esbuild",
|
||||
"fdir",
|
||||
"picomatch@4.0.3",
|
||||
"postcss",
|
||||
"rollup",
|
||||
"tinyglobby"
|
||||
],
|
||||
"optionalDependencies": [
|
||||
"fsevents"
|
||||
],
|
||||
"optionalPeers": [
|
||||
"@types/node@24.3.0"
|
||||
],
|
||||
"bin": true
|
||||
},
|
||||
"vite@7.1.3_@types+node@24.3.0_picomatch@4.0.3_@types+node@24.2.0": {
|
||||
"integrity": "sha512-OOUi5zjkDxYrKhTV3V7iKsoS37VUM7v40+HuwEmcrsf11Cdx9y3DIr2Px6liIcZFwt3XSRpQvFpL3WVy7ApkGw==",
|
||||
"dependencies": [
|
||||
"@types/node@24.2.0",
|
||||
"esbuild",
|
||||
"fdir",
|
||||
"picomatch@4.0.3",
|
||||
"postcss",
|
||||
"rollup",
|
||||
"tinyglobby"
|
||||
],
|
||||
"optionalDependencies": [
|
||||
"fsevents"
|
||||
],
|
||||
"optionalPeers": [
|
||||
"@types/node@24.2.0"
|
||||
],
|
||||
"bin": true
|
||||
},
|
||||
"vite@7.1.4_@types+node@24.3.0_picomatch@4.0.3": {
|
||||
"integrity": "sha512-X5QFK4SGynAeeIt+A7ZWnApdUyHYm+pzv/8/A57LqSGcI88U6R6ipOs3uCesdc6yl7nl+zNO0t8LmqAdXcQihw==",
|
||||
"dependencies": [
|
||||
@@ -3232,7 +3185,7 @@
|
||||
"dependencies": [
|
||||
"npm:@tailwindcss/vite@^4.1.12",
|
||||
"npm:vite-plugin-inspect@^11.3.2",
|
||||
"npm:vite@^7.1.3"
|
||||
"npm:vite@^7.1.4"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,18 @@ export function buildIdPlugin(): Plugin {
|
||||
return `\0fresh/build-id`;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id !== `\0fresh/build-id`) return;
|
||||
|
||||
load: {
|
||||
filter: {
|
||||
id: /\0fresh\/build-id/,
|
||||
},
|
||||
handler() {
|
||||
return `export let BUILD_ID = ${JSON.stringify(buildId)};
|
||||
export const DENO_DEPLOYMENT_ID = undefined;
|
||||
export function setBuildId(id) {
|
||||
BUILD_ID = id;
|
||||
}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,23 @@ export function clientEntryPlugin(options: ResolvedFreshViteConfig): Plugin {
|
||||
configResolved(config) {
|
||||
clientEntry = pathWithRoot(options.clientEntry, config.root);
|
||||
},
|
||||
resolveId(id) {
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: /(fresh:client-entry|fresh:client-entry-user)/,
|
||||
},
|
||||
handler(id) {
|
||||
if (id === modName) {
|
||||
return `\0${modName}`;
|
||||
} else if (id === modNameUser) {
|
||||
return clientEntry;
|
||||
}
|
||||
},
|
||||
async load(id) {
|
||||
if (id !== `\0${modName}`) return;
|
||||
|
||||
},
|
||||
load: {
|
||||
filter: {
|
||||
id: /\0fresh:client-entry/,
|
||||
},
|
||||
async handler() {
|
||||
let exists = false;
|
||||
try {
|
||||
const stat = await Deno.stat(clientEntry);
|
||||
@@ -53,5 +60,6 @@ if (import.meta.hot) {
|
||||
}
|
||||
`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,19 +48,28 @@ export function clientSnapshot(options: ResolvedFreshViteConfig): Plugin {
|
||||
islands.add(filePath);
|
||||
}
|
||||
},
|
||||
resolveId(id) {
|
||||
configureServer(devServer) {
|
||||
server = devServer;
|
||||
},
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: /fresh:client-snapshot/,
|
||||
},
|
||||
handler(id) {
|
||||
if (id === modName) {
|
||||
return `\0${modName}`;
|
||||
}
|
||||
},
|
||||
configureServer(devServer) {
|
||||
server = devServer;
|
||||
},
|
||||
load(id) {
|
||||
if (id !== `\0${modName}`) return;
|
||||
|
||||
load: {
|
||||
filter: {
|
||||
id: /\0fresh:client-snapshot/,
|
||||
},
|
||||
handler() {
|
||||
const imports = Array.from(islands.keys()).map((file, i) => {
|
||||
return `export const mod_${i} = await import(${JSON.stringify(file)});`;
|
||||
return `export const mod_${i} = await import(${
|
||||
JSON.stringify(file)
|
||||
});`;
|
||||
}).join("\n");
|
||||
|
||||
if (isDev && server !== undefined) {
|
||||
@@ -80,5 +89,6 @@ if (import.meta.hot) {
|
||||
}
|
||||
`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as path from "@std/path";
|
||||
import * as babel from "@babel/core";
|
||||
import babelReact from "@babel/preset-react";
|
||||
import { httpAbsolute } from "./patches/http_absolute.ts";
|
||||
import { JS_REG } from "../utils.ts";
|
||||
import { JS_REG, JSX_REG } from "../utils.ts";
|
||||
|
||||
interface DenoState {
|
||||
type: RequestedModuleType;
|
||||
@@ -210,10 +210,14 @@ export function deno(): Plugin {
|
||||
code,
|
||||
};
|
||||
},
|
||||
async transform(_, id, options) {
|
||||
transform: {
|
||||
filter: {
|
||||
id: JSX_REG,
|
||||
},
|
||||
async handler(_, id, options) {
|
||||
// This transform is a hack to be able to re-use Deno's precompile
|
||||
// jsx transform.
|
||||
if (!options?.ssr || !id.endsWith(".tsx") || id.endsWith(".jsx")) {
|
||||
if (!options?.ssr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -222,6 +226,11 @@ export function deno(): Plugin {
|
||||
const { specifier } = parseDenoSpecifier(id);
|
||||
actualId = specifier;
|
||||
}
|
||||
actualId = actualId.replace("?commonjs-es-import", "");
|
||||
|
||||
if (actualId.startsWith("\0")) {
|
||||
actualId = actualId.slice(1);
|
||||
}
|
||||
if (path.isAbsolute(actualId)) {
|
||||
actualId = path.toFileUrl(actualId).href;
|
||||
}
|
||||
@@ -245,6 +254,7 @@ export function deno(): Plugin {
|
||||
code,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,11 @@ export function patches(): Plugin {
|
||||
applyToEnvironment() {
|
||||
return true;
|
||||
},
|
||||
transform(code, id, options) {
|
||||
if (!JS_REG.test(id)) return;
|
||||
|
||||
transform: {
|
||||
filter: {
|
||||
id: JS_REG,
|
||||
},
|
||||
handler(code, id, options) {
|
||||
const presets = [];
|
||||
if (!options?.ssr && JSX_REG.test(id)) {
|
||||
presets.push([babelReact, {
|
||||
@@ -59,5 +61,6 @@ export function patches(): Plugin {
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,14 +39,21 @@ export function serverEntryPlugin(
|
||||
config.root,
|
||||
);
|
||||
},
|
||||
resolveId(id) {
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: /fresh:server_entry/,
|
||||
},
|
||||
handler(id) {
|
||||
if (id === modName) {
|
||||
return `\0${modName}`;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id !== `\0${modName}`) return;
|
||||
|
||||
},
|
||||
load: {
|
||||
filter: {
|
||||
id: /\0fresh:server_entry/,
|
||||
},
|
||||
handler() {
|
||||
let code = generateServerEntry({
|
||||
root: isDev ? path.relative(serverOutDir, root) : "..",
|
||||
serverEntry: path.toFileUrl(serverEntry).href,
|
||||
@@ -72,6 +79,7 @@ if (import.meta.hot) import.meta.hot.accept();`;
|
||||
|
||||
return code;
|
||||
},
|
||||
},
|
||||
async writeBundle(_options, bundle) {
|
||||
const manifest = bundle[".vite/manifest.json"];
|
||||
|
||||
|
||||
@@ -111,14 +111,22 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
||||
viteServer.ws.send("fresh:reload");
|
||||
});
|
||||
},
|
||||
resolveId(id) {
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: /fresh:server-snapshot/,
|
||||
},
|
||||
handler(id) {
|
||||
if (id === modName) {
|
||||
return `\0${modName}`;
|
||||
}
|
||||
},
|
||||
async load(id) {
|
||||
if (id !== `\0${modName}`) return;
|
||||
},
|
||||
load: {
|
||||
filter: {
|
||||
id: /\0fresh:server-snapshot/,
|
||||
},
|
||||
|
||||
async handler() {
|
||||
const result = await crawlFsItem({
|
||||
islandDir: options.islandsDir,
|
||||
routeDir: options.routeDir,
|
||||
@@ -303,10 +311,14 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
||||
|
||||
return code;
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "fresh:island-resolver",
|
||||
resolveId(id) {
|
||||
if (id.startsWith("fresh-island::")) {
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: /^fresh-island::.*/,
|
||||
},
|
||||
handler(id) {
|
||||
let name = id.slice("fresh-island::".length);
|
||||
|
||||
if (JS_REG.test(name)) {
|
||||
@@ -315,7 +327,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
||||
|
||||
const spec = islandSpecByName.get(name);
|
||||
if (spec !== undefined) return spec;
|
||||
}
|
||||
},
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -51,11 +51,15 @@ export function checkImports(pluginOptions: CheckImportOptions): Plugin {
|
||||
configResolved(config) {
|
||||
root = pathWithRoot(config.root);
|
||||
},
|
||||
async resolveId(id, importer, options) {
|
||||
resolveId: {
|
||||
filter: {
|
||||
id: [
|
||||
/^(?!\0|[\\/]@fs[\\/]|fresh-island::|fresh:)/,
|
||||
/[\\/]node_modules[\\/]/,
|
||||
],
|
||||
},
|
||||
async handler(id, importer, options) {
|
||||
if (
|
||||
id.startsWith("\0") || id.startsWith("/@fs/") ||
|
||||
id.startsWith("fresh-island::") || id.startsWith("fresh:") ||
|
||||
id.includes("node_modules") ||
|
||||
importer &&
|
||||
(importer.startsWith("\0") || importer.includes("node_modules") ||
|
||||
importer.includes("deno::"))
|
||||
@@ -103,7 +107,9 @@ export function checkImports(pluginOptions: CheckImportOptions): Plugin {
|
||||
|
||||
if (ancestors && ancestors.length > 0) {
|
||||
// deno-lint-ignore no-console
|
||||
console.log(`The specifier ${cl.cyan(`"${id}"`)} was imported in:`);
|
||||
console.log(
|
||||
`The specifier ${cl.cyan(`"${id}"`)} was imported in:`,
|
||||
);
|
||||
ancestors.forEach((spec) => {
|
||||
if (path.isAbsolute(spec)) {
|
||||
spec = path.relative(root, spec);
|
||||
@@ -137,6 +143,7 @@ export function checkImports(pluginOptions: CheckImportOptions): Plugin {
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
},
|
||||
"imports": {
|
||||
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
|
||||
"vite": "npm:vite@^7.1.3",
|
||||
"vite": "npm:vite@^7.1.4",
|
||||
"vite-plugin-inspect": "npm:vite-plugin-inspect@^11.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user