@timber-js/app 0.1.16 → 0.1.18

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.js CHANGED
@@ -11752,7 +11752,7 @@ function listenForClientErrors(server, projectRoot) {
11752
11752
  //#endregion
11753
11753
  //#region src/plugins/entries.ts
11754
11754
  var __dirname$1 = dirname(fileURLToPath(import.meta.url));
11755
- var SRC_DIR = existsSync(resolve(__dirname$1, "..", "server", "rsc-entry", "index.ts")) ? resolve(__dirname$1, "..") : resolve(__dirname$1, "..", "src");
11755
+ var SRC_DIR$1 = existsSync(resolve(__dirname$1, "..", "server", "rsc-entry", "index.ts")) ? resolve(__dirname$1, "..") : resolve(__dirname$1, "..", "src");
11756
11756
  var VIRTUAL_IDS = {
11757
11757
  rscEntry: "virtual:timber-rsc-entry",
11758
11758
  ssrEntry: "virtual:timber-ssr-entry",
@@ -11769,9 +11769,9 @@ var VIRTUAL_IDS = {
11769
11769
  * published package via the `files` field.
11770
11770
  */
11771
11771
  var ENTRY_FILE_MAP = {
11772
- [VIRTUAL_IDS.rscEntry]: resolve(SRC_DIR, "server", "rsc-entry", "index.ts"),
11773
- [VIRTUAL_IDS.ssrEntry]: resolve(SRC_DIR, "server", "ssr-entry.ts"),
11774
- [VIRTUAL_IDS.browserEntry]: resolve(SRC_DIR, "client", "browser-entry.ts")
11772
+ [VIRTUAL_IDS.rscEntry]: resolve(SRC_DIR$1, "server", "rsc-entry", "index.ts"),
11773
+ [VIRTUAL_IDS.ssrEntry]: resolve(SRC_DIR$1, "server", "ssr-entry.ts"),
11774
+ [VIRTUAL_IDS.browserEntry]: resolve(SRC_DIR$1, "client", "browser-entry.ts")
11775
11775
  };
11776
11776
  /** The \0-prefixed resolved ID for virtual:timber-config */
11777
11777
  var RESOLVED_CONFIG_ID = `\0${VIRTUAL_IDS.config}`;
@@ -12288,6 +12288,7 @@ function generateManifestModule(tree) {
12288
12288
  //#region src/plugins/shims.ts
12289
12289
  var __dirname = dirname(fileURLToPath(import.meta.url));
12290
12290
  var PKG_ROOT = __dirname.endsWith("plugins") ? resolve(__dirname, "..", "..") : resolve(__dirname, "..");
12291
+ var SRC_DIR = resolve(PKG_ROOT, "src");
12291
12292
  var SHIMS_DIR = resolve(PKG_ROOT, "src", "shims");
12292
12293
  /**
12293
12294
  * Virtual module IDs for server-only and client-only poison pills.
@@ -12313,15 +12314,6 @@ var SHIM_MAP = {
12313
12314
  "next/font/local": "\0@timber/fonts/local"
12314
12315
  };
12315
12316
  /**
12316
- * Client-only shim overrides for the browser environment.
12317
- *
12318
- * next/navigation in the client environment resolves to navigation-client.ts
12319
- * which only re-exports client hooks — not server functions like redirect()
12320
- * and deny(). This prevents server/primitives.ts from being pulled into the
12321
- * browser bundle via tree-shaking-resistant imports.
12322
- */
12323
- var CLIENT_SHIM_OVERRIDES = { "next/navigation": resolve(SHIMS_DIR, "navigation-client.ts") };
12324
- /**
12325
12317
  * Strip .js extension from an import specifier.
12326
12318
  *
12327
12319
  * Libraries like nuqs import `next/navigation.js` with an explicit
@@ -12331,6 +12323,34 @@ function stripJsExtension(id) {
12331
12323
  return id.endsWith(".js") ? id.slice(0, -3) : id;
12332
12324
  }
12333
12325
  /**
12326
+ * Resolve a #/* subpath import to an absolute file path.
12327
+ *
12328
+ * The package.json "imports" field maps #/* → ./src/*. Vite's resolver
12329
+ * handles this via Node.js subpath imports, but in dev mode the resulting
12330
+ * module URL can differ from a relative import to the same file. This
12331
+ * causes module duplication — the same file loaded as two separate ES
12332
+ * modules with separate module-level state.
12333
+ *
12334
+ * This function resolves #/foo/bar.js to <PKG_ROOT>/src/foo/bar.ts
12335
+ * (trying .ts first, then .tsx, then .js, then the raw path).
12336
+ * Returns null if the import is not a #/ import or the file doesn't exist.
12337
+ */
12338
+ function resolveSubpathImport(id) {
12339
+ if (!id.startsWith("#/")) return null;
12340
+ const basePath = resolve(SRC_DIR, id.slice(2));
12341
+ const withoutJs = stripJsExtension(basePath);
12342
+ for (const ext of [
12343
+ ".ts",
12344
+ ".tsx",
12345
+ ".js"
12346
+ ]) {
12347
+ const candidate = withoutJs + ext;
12348
+ if (existsSync(candidate)) return candidate;
12349
+ }
12350
+ if (existsSync(basePath)) return basePath;
12351
+ return null;
12352
+ }
12353
+ /**
12334
12354
  * Create the timber-shims Vite plugin.
12335
12355
  *
12336
12356
  * Hooks: resolveId, load
@@ -12342,9 +12362,11 @@ function timberShims(_ctx) {
12342
12362
  resolveId(id) {
12343
12363
  if (id === "server-only") return SERVER_ONLY_VIRTUAL;
12344
12364
  if (id === "client-only") return CLIENT_ONLY_VIRTUAL;
12365
+ const subpathResolved = resolveSubpathImport(id);
12366
+ if (subpathResolved) return subpathResolved;
12345
12367
  const cleanId = stripJsExtension(id);
12346
12368
  if (cleanId in SHIM_MAP) {
12347
- if (this.environment?.name === "client" && cleanId in CLIENT_SHIM_OVERRIDES) return CLIENT_SHIM_OVERRIDES[cleanId];
12369
+ if (this.environment?.name === "client" && cleanId === "next/navigation") return resolve(SHIMS_DIR, "navigation-client.ts");
12348
12370
  return SHIM_MAP[cleanId];
12349
12371
  }
12350
12372
  if (cleanId === "@timber-js/app/server") {