diff --git a/build-id/README.md b/build-id/README.md new file mode 100644 index 00000000000..4840135a27b --- /dev/null +++ b/build-id/README.md @@ -0,0 +1,3 @@ +# Fresh build id + +Don't use this package directly. It's considered internal for Fresh. diff --git a/build-id/deno.json b/build-id/deno.json new file mode 100644 index 00000000000..1023500d74d --- /dev/null +++ b/build-id/deno.json @@ -0,0 +1,11 @@ +{ + "name": "@fresh/build-id", + "version": "1.0.0", + "license": "MIT", + "exports": { + ".": "./mod.ts" + }, + "imports": { + "@std/encoding": "jsr:@std/encoding@^1.0.10" + } +} diff --git a/src/runtime/build_id.ts b/build-id/mod.ts similarity index 100% rename from src/runtime/build_id.ts rename to build-id/mod.ts diff --git a/deno.json b/deno.json index 6ff43ab6a87..4d883cfe3c8 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,7 @@ { "nodeModulesDir": "auto", "workspace": [ + "./build-id", "./examples", "./init", "./plugin-tailwindcss", @@ -19,8 +20,7 @@ "./dev": "./src/dev/mod.ts", "./compat": "./src/compat.ts", "./internal": "./src/internals.ts", - "./internal-dev": "./src/internals_dev.ts", - "./build-id": "./src/runtime/build_id.ts" + "./internal-dev": "./src/internals_dev.ts" }, "tasks": { "test": "deno test -A --parallel", @@ -57,6 +57,7 @@ "imports": { "@deno/doc": "jsr:@deno/doc@^0.172.0", "@deno/esbuild-plugin": "jsr:@deno/esbuild-plugin@^1.1.5", + "@fresh/build-id": "jsr:@fresh/build-id@^1.0.0", "@std/cli": "jsr:@std/cli@^1.0.19", "@std/collections": "jsr:@std/collections@^1.1.2", "@std/http": "jsr:@std/http@^1.0.15", diff --git a/deno.lock b/deno.lock index c846fe40dc7..6047f0f9aee 100644 --- a/deno.lock +++ b/deno.lock @@ -90,6 +90,8 @@ "npm:tailwindcss@^4.1.10": "4.1.11", "npm:ts-morph@26": "26.0.0", "npm:vite-plugin-inspect@^11.3.2": "11.3.2_vite@7.0.6__@types+node@22.15.15__picomatch@4.0.3_@types+node@22.15.15", + "npm:vite@*": "7.0.6_@types+node@22.15.15_picomatch@4.0.3", + "npm:vite@7.0.6": "7.0.6_@types+node@22.15.15_picomatch@4.0.3", "npm:vite@^7.0.6": "7.0.6_@types+node@22.15.15_picomatch@4.0.3" }, "jsr": { @@ -2855,6 +2857,7 @@ "jsr:@astral/astral@~0.5.3", "jsr:@deno/doc@0.172", "jsr:@deno/esbuild-plugin@^1.1.5", + "jsr:@fresh/build-id@1", "jsr:@fresh/core@^2.0.0-alpha.37", "jsr:@marvinh-test/fresh-island@^0.0.1", "jsr:@std/async@^1.0.13", @@ -2892,6 +2895,11 @@ "npm:ts-morph@26" ], "members": { + "build-id": { + "dependencies": [ + "jsr:@std/encoding@^1.0.10" + ] + }, "plugin-tailwindcss-v3": { "dependencies": [ "npm:autoprefixer@^10.4.21", diff --git a/plugin-vite/src/plugins/build_id.ts b/plugin-vite/src/plugins/build_id.ts index c5ae2effd47..00bbb496b5f 100644 --- a/plugin-vite/src/plugins/build_id.ts +++ b/plugin-vite/src/plugins/build_id.ts @@ -3,6 +3,8 @@ import type { Plugin } from "vite"; export function buildIdPlugin(): Plugin { let buildId = ""; + const regex = /^(jsr:)?@fresh\/build-id(@.*)?$/; + return { name: "fresh:build-id", async config(_, env) { @@ -20,7 +22,7 @@ export function buildIdPlugin(): Plugin { return true; }, resolveId(id) { - if (id === "fresh/build-id") { + if (regex.test(id)) { return `\0fresh/build-id`; } }, diff --git a/src/app.ts b/src/app.ts index 03653ca8fc9..30d0253721c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ import { trace } from "@opentelemetry/api"; -import { DENO_DEPLOYMENT_ID } from "fresh/build-id"; +import { DENO_DEPLOYMENT_ID } from "@fresh/build-id"; import * as colors from "@std/fmt/colors"; import { type MaybeLazyMiddleware, diff --git a/src/build_cache.ts b/src/build_cache.ts index 957d1c1ad13..3b88e60a8b1 100644 --- a/src/build_cache.ts +++ b/src/build_cache.ts @@ -4,7 +4,7 @@ import { fsItemsToCommands, type FsRouteFile } from "./fs_routes.ts"; import type { ServerIslandRegistry } from "./context.ts"; import type { AnyComponent } from "preact"; import { UniqueNamer } from "./utils.ts"; -import { setBuildId } from "fresh/build-id"; +import { setBuildId } from "@fresh/build-id"; export interface FileSnapshot { name: string; diff --git a/src/context_test.tsx b/src/context_test.tsx index 6e4c717d700..de94d900e6a 100644 --- a/src/context_test.tsx +++ b/src/context_test.tsx @@ -3,7 +3,7 @@ import { Context } from "./context.ts"; import { App } from "fresh"; import { asset } from "fresh/runtime"; import { FakeServer } from "./test_utils.ts"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import { parseHtml } from "../tests/test_utils.tsx"; Deno.test("FreshReqContext.prototype.redirect", () => { diff --git a/src/dev/builder.ts b/src/dev/builder.ts index ac20e850a1f..abbb0dbe041 100644 --- a/src/dev/builder.ts +++ b/src/dev/builder.ts @@ -17,7 +17,7 @@ import { type FsRoute, MemoryBuildCache, } from "./dev_build_cache.ts"; -import { BUILD_ID } from "../runtime/build_id.ts"; +import { BUILD_ID } from "@fresh/build-id"; import { updateCheck } from "./update_check.ts"; import { devErrorOverlay } from "./middlewares/error_overlay/middleware.tsx"; import { automaticWorkspaceFolders } from "./middlewares/automatic_workspace_folders.ts"; diff --git a/src/dev/builder_test.ts b/src/dev/builder_test.ts index e0edd0fb1c0..d2c1f69cf55 100644 --- a/src/dev/builder_test.ts +++ b/src/dev/builder_test.ts @@ -3,7 +3,7 @@ import * as path from "@std/path"; import { Builder, specToName } from "./builder.ts"; import { App } from "../app.ts"; import { DEV_ERROR_OVERLAY_URL } from "../constants.ts"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import { withTmpDir, writeFiles } from "../test_utils.ts"; import { getStdOutput, diff --git a/src/dev/esbuild.ts b/src/dev/esbuild.ts index eec6289d821..d6c6d1d21dc 100644 --- a/src/dev/esbuild.ts +++ b/src/dev/esbuild.ts @@ -166,14 +166,14 @@ function buildIdPlugin(buildId: string): EsbuildPlugin { return { name: "fresh-build-id", setup(build) { - build.onResolve({ filter: /^fresh\/build-id$/ }, (args) => { + build.onResolve({ filter: /^(jsr:)?@fresh\/build-id(@.*)?$/ }, (args) => { return { path: args.path, namespace: "fresh-internal", }; }); build.onLoad({ - filter: /^fresh\/build-id$/, + filter: /^(jsr:)?@fresh\/build-id$/, namespace: "fresh-internal", }, () => { return { diff --git a/src/dev/file_transformer.ts b/src/dev/file_transformer.ts index 3f821fecb0c..d4a93f1403a 100644 --- a/src/dev/file_transformer.ts +++ b/src/dev/file_transformer.ts @@ -1,6 +1,6 @@ import { globToRegExp, isGlob } from "@std/path"; import type { FsAdapter } from "../fs.ts"; -import { BUILD_ID } from "../runtime/build_id.ts"; +import { BUILD_ID } from "@fresh/build-id"; import { assetInternal } from "../runtime/shared_internal.tsx"; export type TransformMode = "development" | "production"; diff --git a/src/middlewares/static_files.ts b/src/middlewares/static_files.ts index 370b9c29b20..a26a83a838a 100644 --- a/src/middlewares/static_files.ts +++ b/src/middlewares/static_files.ts @@ -1,6 +1,6 @@ import type { Middleware } from "./mod.ts"; import { ASSET_CACHE_BUST_KEY } from "../runtime/shared_internal.tsx"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import { tracer } from "../otel.ts"; import { getBuildCache } from "../context.ts"; diff --git a/src/middlewares/static_files_test.ts b/src/middlewares/static_files_test.ts index eec3d60c82e..09a70983f94 100644 --- a/src/middlewares/static_files_test.ts +++ b/src/middlewares/static_files_test.ts @@ -3,7 +3,7 @@ import { serveMiddleware } from "../test_utils.ts"; import type { BuildCache, StaticFile } from "../build_cache.ts"; import { expect } from "@std/expect"; import { ASSET_CACHE_BUST_KEY } from "../runtime/shared_internal.tsx"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import type { Command } from "../commands.ts"; import type { ServerIslandRegistry } from "../context.ts"; import { getContentType } from "../dev/dev_build_cache.ts"; diff --git a/src/runtime/client/preact_hooks_client.ts b/src/runtime/client/preact_hooks_client.ts index 9684385ad00..fb15bf501fe 100644 --- a/src/runtime/client/preact_hooks_client.ts +++ b/src/runtime/client/preact_hooks_client.ts @@ -1,6 +1,6 @@ import { options } from "preact"; import { assetHashingHook, CLIENT_NAV_ATTR } from "../shared_internal.tsx"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; const oldVNodeHook = options.vnode; options.vnode = (vnode) => { diff --git a/src/runtime/server/preact_hooks.tsx b/src/runtime/server/preact_hooks.tsx index ab01760ca1c..4a560ccbafd 100644 --- a/src/runtime/server/preact_hooks.tsx +++ b/src/runtime/server/preact_hooks.tsx @@ -23,7 +23,7 @@ import { setActiveUrl, } from "../shared_internal.tsx"; import type { BuildCache } from "../../build_cache.ts"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import { DEV_ERROR_OVERLAY_URL, PARTIAL_SEARCH_PARAM, diff --git a/src/runtime/shared.ts b/src/runtime/shared.ts index f316a834268..9ed43fbfb7f 100644 --- a/src/runtime/shared.ts +++ b/src/runtime/shared.ts @@ -1,5 +1,5 @@ import type { ComponentChildren, VNode } from "preact"; -import { BUILD_ID } from "fresh/build-id"; +import { BUILD_ID } from "@fresh/build-id"; import { assetInternal, assetSrcSetInternal } from "./shared_internal.tsx"; /**