@pracht/vite-plugin 0.7.3 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { i as scanPagesDirectory, n as generatePagesManifestSource, o as createRouteLoaderHints } from "./pages-router-BsVlzz-e.mjs";
1
+ import { i as scanPagesDirectory, n as generatePagesManifestSource, o as createRouteLoaderHints } from "./pages-router-CStJY2Zp.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { preactSsrPrecompile } from "@pracht/preact-ssr-precompile";
4
4
  import preact from "@preact/preset-vite";
5
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
5
6
  import { dirname, extname, join, resolve } from "node:path";
6
7
  import { loadEnv, parseAst } from "vite";
7
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
8
8
  import { CAPABILITY_SETTLED_EVENT, CAPABILITY_TRANSPORT_HEADER, CONFIRMATION_HEADER } from "@pracht/capabilities";
9
9
  import { extractCapabilityProjection, extractCapabilityRegistrations } from "@pracht/capabilities/static";
10
10
  import { createNodeServerEntryModule } from "@pracht/adapter-node";
@@ -1221,17 +1221,19 @@ function createEnvSafetyPlugin(envSafety) {
1221
1221
  //#endregion
1222
1222
  //#region src/hot-update-reload.ts
1223
1223
  /**
1224
- * True when `file` participates in server rendering but has no counterpart in
1225
- * the client module graph, meaning client HMR can never deliver its change.
1224
+ * True when `file` participates in server rendering but has no runtime
1225
+ * counterpart in the client module graph, meaning client HMR can never deliver
1226
+ * its change. File-only asset entries created by content scanners are watchers,
1227
+ * not browser modules, so they do not make an update client-reachable.
1226
1228
  */
1227
1229
  function isServerOnlyModuleFile(server, file) {
1228
1230
  const environments = server.environments;
1229
1231
  const client = environments?.client;
1230
1232
  if (!client) return false;
1231
- if (hasModules(client, file)) return false;
1233
+ if (hasRuntimeModules(client, file)) return false;
1232
1234
  for (const [name, environment] of Object.entries(environments ?? {})) {
1233
1235
  if (name === "client" || !environment) continue;
1234
- if (hasModules(environment, file)) return true;
1236
+ if (hasRuntimeModules(environment, file)) return true;
1235
1237
  }
1236
1238
  return false;
1237
1239
  }
@@ -1241,8 +1243,9 @@ function sendServerOnlyFullReload(server, file) {
1241
1243
  server.environments?.client?.hot?.send({ type: "full-reload" });
1242
1244
  return true;
1243
1245
  }
1244
- function hasModules(environment, file) {
1245
- return (environment.moduleGraph.getModulesByFile(file)?.size ?? 0) > 0;
1246
+ function hasRuntimeModules(environment, file) {
1247
+ for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) if (module.type !== "asset") return true;
1248
+ return false;
1246
1249
  }
1247
1250
  //#endregion
1248
1251
  //#region src/plugin-assets.ts
@@ -1934,12 +1937,14 @@ function createPrachtServerModuleSource(options = {}, buildOptions = {}) {
1934
1937
  function createPrachtDevModuleSource(options = {}, buildOptions = {}) {
1935
1938
  const resolved = resolveOptions(options);
1936
1939
  return [
1937
- "import { resolveApp } from \"@pracht/core/server\";",
1940
+ "import { resolveApp, resolveApiRoutes } from \"@pracht/core/server\";",
1938
1941
  resolved.pagesDir ? generatePagesAppInlineSource(resolved, buildOptions.root) : `import { app } from ${JSON.stringify(resolved.appFile)};`,
1939
1942
  "",
1940
1943
  createPrachtRegistryModuleSource(resolved),
1941
1944
  "",
1942
1945
  "export const resolvedApp = resolveApp(app);",
1946
+ `export const apiRoutes = resolveApiRoutes(Object.keys(apiModules), ${JSON.stringify(resolved.apiDir)});`,
1947
+ `export const buildTarget = ${JSON.stringify(resolved.adapter?.id ?? "node")};`,
1943
1948
  ""
1944
1949
  ].join("\n");
1945
1950
  }
@@ -2523,7 +2528,7 @@ function pracht(options = {}) {
2523
2528
  root = config.root;
2524
2529
  isBuild = config.command === "build";
2525
2530
  routeFileDirs = computeRouteFileDirs(root, resolved);
2526
- capabilityModulePaths = new Set(resolveCapabilityModulePaths(resolved, root).map((path) => toPosixPath(path)));
2531
+ capabilityModulePaths = new Set(resolveCapabilityModulePaths(resolved, root).map(canonicalFilePath));
2527
2532
  },
2528
2533
  resolveId(id, importer, resolveIdOptions) {
2529
2534
  if (isIslandsClientModule(id)) return PRACHT_ISLANDS_CLIENT_MODULE_ID;
@@ -2548,8 +2553,8 @@ function pracht(options = {}) {
2548
2553
  return null;
2549
2554
  },
2550
2555
  transform(code, id) {
2551
- const appFileAbs = resolveConfigPath(root, resolved.appFile);
2552
- if (toPosixPath(id.split("?")[0]) !== appFileAbs) return null;
2556
+ const appFileAbs = canonicalFilePath(resolveConfigPath(root, resolved.appFile));
2557
+ if (canonicalFilePath(id.split("?")[0]) !== appFileAbs) return null;
2553
2558
  const transformed = rewriteManifestCoreImports(code.replace(/\(\)\s*=>\s*import\(\s*(['"])([^'"]+)\1\s*\)/g, "$1$2$1"));
2554
2559
  if (transformed === code) return null;
2555
2560
  return {
@@ -2760,7 +2765,7 @@ const ROUTE_FILE_EXTENSIONS = new Set([
2760
2765
  ".tsrx"
2761
2766
  ]);
2762
2767
  function computeRouteFileDirs(root, resolved) {
2763
- return (resolved.pagesDir ? [resolved.pagesDir] : [resolved.routesDir, resolved.shellsDir]).map((dir) => resolveConfigPath(root, dir)).map(withTrailingSep);
2768
+ return (resolved.pagesDir ? [resolved.pagesDir] : [resolved.routesDir, resolved.shellsDir]).map((dir) => canonicalFilePath(resolveConfigPath(root, dir))).map(withTrailingSep);
2764
2769
  }
2765
2770
  /**
2766
2771
  * Whether `id` is one of the capability modules the manifest registers.
@@ -2774,7 +2779,20 @@ function isCapabilityModule(id, capabilityModulePaths) {
2774
2779
  const queryStart = id.indexOf("?");
2775
2780
  const path = queryStart === -1 ? id : id.slice(0, queryStart);
2776
2781
  if (path.startsWith("\0") || path.startsWith("virtual:")) return false;
2777
- return capabilityModulePaths.has(toPosixPath(path));
2782
+ return capabilityModulePaths.has(canonicalFilePath(path));
2783
+ }
2784
+ /**
2785
+ * Match Vite's canonical module ids even when the manifest path crosses a
2786
+ * symlink (including macOS' /var -> /private/var alias). Missing paths keep
2787
+ * their lexical identity so the projection code can raise its precise missing
2788
+ * capability error later.
2789
+ */
2790
+ function canonicalFilePath(path) {
2791
+ try {
2792
+ return toPosixPath(realpathSync.native(path));
2793
+ } catch {
2794
+ return toPosixPath(path);
2795
+ }
2778
2796
  }
2779
2797
  function isRouteOrShellFile(id, dirs) {
2780
2798
  if (dirs.length === 0) return false;
@@ -1,2 +1,2 @@
1
- import { a as sortRoutes, i as scanPagesDirectory, n as generatePagesManifestSource, r as generateRoutesFile, t as filePathToRoutePath } from "./pages-router-BsVlzz-e.mjs";
1
+ import { a as sortRoutes, i as scanPagesDirectory, n as generatePagesManifestSource, r as generateRoutesFile, t as filePathToRoutePath } from "./pages-router-CStJY2Zp.mjs";
2
2
  export { filePathToRoutePath, generatePagesManifestSource, generateRoutesFile, scanPagesDirectory, sortRoutes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pracht/vite-plugin",
3
- "version": "0.7.3",
3
+ "version": "0.7.6",
4
4
  "description": "Vite plugin for Pracht apps with virtual modules, dev SSR, prerendering, route inspection, and multi-adapter builds.",
5
5
  "keywords": [
6
6
  "pracht",
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@preact/preset-vite": "^2.10.5",
46
46
  "@prefresh/vite": "^2.0.0",
47
- "@pracht/adapter-node": "0.3.6",
48
- "@pracht/capabilities": "0.1.1",
49
- "@pracht/core": "0.11.3",
50
- "@pracht/preact-ssr-precompile": "0.1.2"
47
+ "@pracht/adapter-node": "0.3.8",
48
+ "@pracht/core": "0.12.0",
49
+ "@pracht/preact-ssr-precompile": "0.1.2",
50
+ "@pracht/capabilities": "0.1.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "vite": "^8.0.0"
@@ -1,5 +1,5 @@
1
- import { basename, extname, join, relative } from "node:path";
2
1
  import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
+ import { basename, extname, join, relative } from "node:path";
3
3
  //#region src/route-loader-hints.ts
4
4
  const ROUTE_EXTENSIONS = new Set([
5
5
  ".tsx",