@lovable.dev/vite-tanstack-config 2.19.3 → 2.19.4

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.
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let node_fs_promises = require("node:fs/promises");
3
2
  let node_path = require("node:path");
3
+ let node_fs_promises = require("node:fs/promises");
4
4
  //#region src/dev-server-bridge/error-collector.ts
5
5
  const DEFAULT_ENDPOINT = "/__lovable/error-collector";
6
6
  const DEFAULT_OUTPUT_FILE = "/tmp/runtime-errors.log";
@@ -1,5 +1,5 @@
1
- import { appendFile, mkdir, writeFile } from "node:fs/promises";
2
1
  import { dirname, resolve } from "node:path";
2
+ import { appendFile, mkdir, writeFile } from "node:fs/promises";
3
3
  //#region src/dev-server-bridge/error-collector.ts
4
4
  const DEFAULT_ENDPOINT = "/__lovable/error-collector";
5
5
  const DEFAULT_OUTPUT_FILE = "/tmp/runtime-errors.log";
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
+ let node_path = require("node:path");
24
25
  let node_url = require("node:url");
25
26
  let vite = require("vite");
26
27
  let node_https = require("node:https");
@@ -152,7 +153,7 @@ function bundledDevCssUrlShim() {
152
153
  //#endregion
153
154
  //#region package.json
154
155
  var name = "@lovable.dev/vite-tanstack-config";
155
- var version = "2.19.3";
156
+ var version = "2.19.4";
156
157
  //#endregion
157
158
  //#region src/logging.ts
158
159
  const PACKAGE_NAME = "@lovable.dev/vite-tanstack-config";
@@ -745,7 +746,7 @@ function stripRedundantNodejsCompatFlag() {
745
746
  order: "post",
746
747
  handler: async () => {
747
748
  const { readFile, writeFile } = await import("node:fs/promises");
748
- const configPath = (await import("node:path")).join(root, SANDBOX_WRANGLER_CONFIG_PATH);
749
+ const configPath = (0, node_path.join)(root, SANDBOX_WRANGLER_CONFIG_PATH);
749
750
  let parsed;
750
751
  try {
751
752
  parsed = JSON.parse(await readFile(configPath, "utf8"));
@@ -768,14 +769,16 @@ function stripRedundantNodejsCompatFlag() {
768
769
  };
769
770
  }
770
771
  const NITRO_SERVER_ENTRY = "index.mjs";
772
+ const NITRO_DEFAULT_OUTPUT_DIR = ".output";
773
+ const VITE_DEFAULT_OUTPUT_DIR = "dist";
771
774
  const NITRO_WRANGLER_CONFIG = "wrangler.json";
772
775
  const DEFAULT_SERVER_ENTRY_NAME = "server";
773
776
  const PRERENDER_PREVIEW_HOST = "127.0.0.1";
774
777
  const TSS_PRERENDERING_ENV = "TSS_PRERENDERING";
775
778
  const SHIM_MARKER = "// Generated by @lovable.dev/vite-tanstack-config for the prerender preview server.";
776
- function prerenderShimSource(vars) {
779
+ function prerenderShimSource(vars, entrySpecifier) {
777
780
  return `${SHIM_MARKER}
778
- import server from "./${NITRO_SERVER_ENTRY}";
781
+ import server from "${entrySpecifier}";
779
782
 
780
783
  const env = ${JSON.stringify(vars)};
781
784
  const ctx = { waitUntil() {}, passThroughOnException() {}, props: {} };
@@ -790,16 +793,54 @@ export default {
790
793
  };
791
794
  `;
792
795
  }
793
- function prerenderPreviewShim(state) {
796
+ function captureNitroServerDir(nitroOpts) {
797
+ const output = {};
798
+ const hooks = nitroOpts.hooks ?? {};
799
+ const userCompiled = hooks.compiled;
800
+ nitroOpts.hooks = {
801
+ ...hooks,
802
+ compiled: async (nitro) => {
803
+ const serverDir = nitro?.options?.output?.serverDir;
804
+ if (typeof serverDir === "string") output.serverDir = serverDir;
805
+ if (typeof userCompiled === "function") await userCompiled(nitro);
806
+ }
807
+ };
808
+ return output;
809
+ }
810
+ function previewServerOutputDir(viteConfig) {
811
+ const ssrOutDir = viteConfig?.environments?.ssr?.build?.outDir;
812
+ if (typeof ssrOutDir === "string") return ssrOutDir;
813
+ const rootOutDir = viteConfig?.build?.outDir;
814
+ return (0, node_path.join)(typeof rootOutDir === "string" ? rootOutDir : VITE_DEFAULT_OUTPUT_DIR, "server");
815
+ }
816
+ function pinnedNitroServerDir(nitroOpts) {
817
+ const output = nitroOpts.output;
818
+ const dir = typeof output?.dir === "string" ? output.dir : void 0;
819
+ const serverDir = typeof output?.serverDir === "string" ? output.serverDir : void 0;
820
+ const resolved = serverDir ? serverDir.replace(/\{\{\s*output\.dir\s*\}\}/g, dir ?? NITRO_DEFAULT_OUTPUT_DIR) : dir && (0, node_path.join)(dir, "server");
821
+ return resolved && !resolved.includes("{{") ? resolved : void 0;
822
+ }
823
+ function prerenderShimDirs(viteConfig, nitroOpts) {
824
+ const shimDir = previewServerOutputDir(viteConfig);
825
+ const candidates = [
826
+ pinnedNitroServerDir(nitroOpts),
827
+ (0, node_path.join)(NITRO_DEFAULT_OUTPUT_DIR, "server"),
828
+ shimDir
829
+ ];
830
+ return {
831
+ shimDir,
832
+ entryDirs: [...new Set(candidates.filter((dir) => !!dir))],
833
+ nitroOutput: captureNitroServerDir(nitroOpts)
834
+ };
835
+ }
836
+ function prerenderPreviewShim(state, dirs) {
794
837
  let root = process.cwd();
795
- let serverOutDir = SERVER_OUTPUT_DIR;
796
838
  let serverEntryName = DEFAULT_SERVER_ENTRY_NAME;
797
839
  return {
798
840
  name: "lovable-prerender-preview-shim",
799
841
  apply: "build",
800
842
  config(userConfig) {
801
843
  const ssrBuild = userConfig.environments?.ssr?.build;
802
- if (ssrBuild?.outDir) serverOutDir = ssrBuild.outDir;
803
844
  const input = ssrBuild?.rolldownOptions?.input ?? ssrBuild?.rollupOptions?.input;
804
845
  if (typeof input === "string") serverEntryName = input;
805
846
  },
@@ -809,8 +850,7 @@ function prerenderPreviewShim(state) {
809
850
  buildApp: {
810
851
  order: "post",
811
852
  handler: async () => {
812
- const { access, readFile, writeFile } = await import("node:fs/promises");
813
- const nodePath = await import("node:path");
853
+ const { access, mkdir, readFile, writeFile } = await import("node:fs/promises");
814
854
  const exists = async (candidate) => {
815
855
  try {
816
856
  await access(candidate);
@@ -819,28 +859,41 @@ function prerenderPreviewShim(state) {
819
859
  return false;
820
860
  }
821
861
  };
822
- const outDir = nodePath.resolve(root, serverOutDir);
823
- if (!await exists(nodePath.join(outDir, NITRO_SERVER_ENTRY))) {
824
- logWarning(`Cannot prerender: nitro's ${NITRO_SERVER_ENTRY} is not in ${serverOutDir}, so the preview shim was not written and every prerendered route will fall back to SSR.`);
862
+ const found = [dirs.nitroOutput.serverDir, ...dirs.entryDirs].filter((dir) => !!dir);
863
+ const candidates = [...new Set(found)];
864
+ let entryDir;
865
+ for (const candidate of candidates) {
866
+ const resolved = (0, node_path.resolve)(root, candidate);
867
+ if (await exists((0, node_path.join)(resolved, NITRO_SERVER_ENTRY))) {
868
+ entryDir = resolved;
869
+ break;
870
+ }
871
+ }
872
+ if (!entryDir) {
873
+ logWarning(`Cannot prerender: nitro's ${NITRO_SERVER_ENTRY} is in none of ${candidates.join(", ")}, so the preview shim was not written and every prerendered route will fall back to SSR.`);
825
874
  return;
826
875
  }
827
- const basename = nodePath.basename(serverEntryName, nodePath.extname(serverEntryName));
828
- if (!basename || basename === "index") {
829
- logWarning(`Cannot prerender: the server entry "${serverEntryName}" would need a shim at ${SERVER_OUTPUT_DIR}/index.js, which outranks nitro's own entry when publishing. Rename the entry to anything but \`index\`.`);
876
+ const entryName = (0, node_path.basename)(serverEntryName, (0, node_path.extname)(serverEntryName));
877
+ const wouldOutrankNitroEntry = entryName === "index" && dirs.shimDir === SERVER_OUTPUT_DIR;
878
+ if (!entryName || wouldOutrankNitroEntry) {
879
+ logWarning(`Cannot prerender: the server entry "${serverEntryName}" would need a shim at ${dirs.shimDir}/index.js, which outranks nitro's own entry when publishing. Rename the entry to anything but \`index\`.`);
830
880
  return;
831
881
  }
832
- const target = nodePath.join(outDir, `${basename}.js`);
882
+ const shimDir = (0, node_path.resolve)(root, dirs.shimDir);
883
+ const target = (0, node_path.join)(shimDir, `${entryName}.js`);
833
884
  const occupant = await readFile(target, "utf8").catch(() => void 0);
834
885
  if (occupant !== void 0 && !occupant.startsWith(SHIM_MARKER)) {
835
- logWarning(`Cannot prerender: ${basename}.js already exists in ${serverOutDir} and was not written by this plugin.`);
886
+ logWarning(`Cannot prerender: ${entryName}.js already exists in ${dirs.shimDir} and was not written by this plugin.`);
836
887
  return;
837
888
  }
838
889
  let vars = {};
839
890
  try {
840
- const candidate = JSON.parse(await readFile(nodePath.join(outDir, NITRO_WRANGLER_CONFIG), "utf8"))?.vars;
891
+ const candidate = JSON.parse(await readFile((0, node_path.join)(entryDir, NITRO_WRANGLER_CONFIG), "utf8"))?.vars;
841
892
  if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) vars = candidate;
842
893
  } catch {}
843
- await writeFile(target, prerenderShimSource(vars));
894
+ const specifier = (0, node_path.relative)(shimDir, (0, node_path.join)(entryDir, NITRO_SERVER_ENTRY)).split(node_path.sep).join("/");
895
+ await mkdir(shimDir, { recursive: true });
896
+ await writeFile(target, prerenderShimSource(vars, specifier.startsWith(".") ? specifier : `./${specifier}`));
844
897
  state.file = target;
845
898
  }
846
899
  }
@@ -1101,10 +1154,11 @@ function defineConfig(configOrOptions = {}) {
1101
1154
  };
1102
1155
  }
1103
1156
  } else if (!nitroOpts.preset && !await nitroSupportsDefaultPreset()) logWarning("The installed `nitro` predates the `defaultPreset` option (3.0.260603-beta), so the Cloudflare fallback is ignored and a zero-config build may target Node instead. Upgrade nitro to >=3.0.260603-beta, or set an explicit `nitro: { preset: \"cloudflare-module\" }`.");
1157
+ const shimDirs = prerenderEnabled ? prerenderShimDirs(options.vite, nitroOpts) : void 0;
1104
1158
  internalPlugins.push(nitro(nitroOpts));
1105
- if (prerenderEnabled) {
1159
+ if (shimDirs) {
1106
1160
  const shimState = {};
1107
- internalPlugins.push(prerenderPreviewShim(shimState), prerenderPreviewShimCleanup(shimState));
1161
+ internalPlugins.push(prerenderPreviewShim(shimState, shimDirs), prerenderPreviewShimCleanup(shimState));
1108
1162
  }
1109
1163
  if (isSandbox) internalPlugins.push(stripRedundantNodejsCompatFlag());
1110
1164
  }
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { basename, extname, join, relative, resolve, sep } from "node:path";
1
2
  import { fileURLToPath } from "node:url";
2
3
  import { loadEnv, mergeConfig } from "vite";
3
4
  import https from "node:https";
@@ -128,7 +129,7 @@ function bundledDevCssUrlShim() {
128
129
  //#endregion
129
130
  //#region package.json
130
131
  var name = "@lovable.dev/vite-tanstack-config";
131
- var version = "2.19.3";
132
+ var version = "2.19.4";
132
133
  //#endregion
133
134
  //#region src/logging.ts
134
135
  const PACKAGE_NAME = "@lovable.dev/vite-tanstack-config";
@@ -721,7 +722,7 @@ function stripRedundantNodejsCompatFlag() {
721
722
  order: "post",
722
723
  handler: async () => {
723
724
  const { readFile, writeFile } = await import("node:fs/promises");
724
- const configPath = (await import("node:path")).join(root, SANDBOX_WRANGLER_CONFIG_PATH);
725
+ const configPath = join(root, SANDBOX_WRANGLER_CONFIG_PATH);
725
726
  let parsed;
726
727
  try {
727
728
  parsed = JSON.parse(await readFile(configPath, "utf8"));
@@ -744,14 +745,16 @@ function stripRedundantNodejsCompatFlag() {
744
745
  };
745
746
  }
746
747
  const NITRO_SERVER_ENTRY = "index.mjs";
748
+ const NITRO_DEFAULT_OUTPUT_DIR = ".output";
749
+ const VITE_DEFAULT_OUTPUT_DIR = "dist";
747
750
  const NITRO_WRANGLER_CONFIG = "wrangler.json";
748
751
  const DEFAULT_SERVER_ENTRY_NAME = "server";
749
752
  const PRERENDER_PREVIEW_HOST = "127.0.0.1";
750
753
  const TSS_PRERENDERING_ENV = "TSS_PRERENDERING";
751
754
  const SHIM_MARKER = "// Generated by @lovable.dev/vite-tanstack-config for the prerender preview server.";
752
- function prerenderShimSource(vars) {
755
+ function prerenderShimSource(vars, entrySpecifier) {
753
756
  return `${SHIM_MARKER}
754
- import server from "./${NITRO_SERVER_ENTRY}";
757
+ import server from "${entrySpecifier}";
755
758
 
756
759
  const env = ${JSON.stringify(vars)};
757
760
  const ctx = { waitUntil() {}, passThroughOnException() {}, props: {} };
@@ -766,16 +769,54 @@ export default {
766
769
  };
767
770
  `;
768
771
  }
769
- function prerenderPreviewShim(state) {
772
+ function captureNitroServerDir(nitroOpts) {
773
+ const output = {};
774
+ const hooks = nitroOpts.hooks ?? {};
775
+ const userCompiled = hooks.compiled;
776
+ nitroOpts.hooks = {
777
+ ...hooks,
778
+ compiled: async (nitro) => {
779
+ const serverDir = nitro?.options?.output?.serverDir;
780
+ if (typeof serverDir === "string") output.serverDir = serverDir;
781
+ if (typeof userCompiled === "function") await userCompiled(nitro);
782
+ }
783
+ };
784
+ return output;
785
+ }
786
+ function previewServerOutputDir(viteConfig) {
787
+ const ssrOutDir = viteConfig?.environments?.ssr?.build?.outDir;
788
+ if (typeof ssrOutDir === "string") return ssrOutDir;
789
+ const rootOutDir = viteConfig?.build?.outDir;
790
+ return join(typeof rootOutDir === "string" ? rootOutDir : VITE_DEFAULT_OUTPUT_DIR, "server");
791
+ }
792
+ function pinnedNitroServerDir(nitroOpts) {
793
+ const output = nitroOpts.output;
794
+ const dir = typeof output?.dir === "string" ? output.dir : void 0;
795
+ const serverDir = typeof output?.serverDir === "string" ? output.serverDir : void 0;
796
+ const resolved = serverDir ? serverDir.replace(/\{\{\s*output\.dir\s*\}\}/g, dir ?? NITRO_DEFAULT_OUTPUT_DIR) : dir && join(dir, "server");
797
+ return resolved && !resolved.includes("{{") ? resolved : void 0;
798
+ }
799
+ function prerenderShimDirs(viteConfig, nitroOpts) {
800
+ const shimDir = previewServerOutputDir(viteConfig);
801
+ const candidates = [
802
+ pinnedNitroServerDir(nitroOpts),
803
+ join(NITRO_DEFAULT_OUTPUT_DIR, "server"),
804
+ shimDir
805
+ ];
806
+ return {
807
+ shimDir,
808
+ entryDirs: [...new Set(candidates.filter((dir) => !!dir))],
809
+ nitroOutput: captureNitroServerDir(nitroOpts)
810
+ };
811
+ }
812
+ function prerenderPreviewShim(state, dirs) {
770
813
  let root = process.cwd();
771
- let serverOutDir = SERVER_OUTPUT_DIR;
772
814
  let serverEntryName = DEFAULT_SERVER_ENTRY_NAME;
773
815
  return {
774
816
  name: "lovable-prerender-preview-shim",
775
817
  apply: "build",
776
818
  config(userConfig) {
777
819
  const ssrBuild = userConfig.environments?.ssr?.build;
778
- if (ssrBuild?.outDir) serverOutDir = ssrBuild.outDir;
779
820
  const input = ssrBuild?.rolldownOptions?.input ?? ssrBuild?.rollupOptions?.input;
780
821
  if (typeof input === "string") serverEntryName = input;
781
822
  },
@@ -785,8 +826,7 @@ function prerenderPreviewShim(state) {
785
826
  buildApp: {
786
827
  order: "post",
787
828
  handler: async () => {
788
- const { access, readFile, writeFile } = await import("node:fs/promises");
789
- const nodePath = await import("node:path");
829
+ const { access, mkdir, readFile, writeFile } = await import("node:fs/promises");
790
830
  const exists = async (candidate) => {
791
831
  try {
792
832
  await access(candidate);
@@ -795,28 +835,41 @@ function prerenderPreviewShim(state) {
795
835
  return false;
796
836
  }
797
837
  };
798
- const outDir = nodePath.resolve(root, serverOutDir);
799
- if (!await exists(nodePath.join(outDir, NITRO_SERVER_ENTRY))) {
800
- logWarning(`Cannot prerender: nitro's ${NITRO_SERVER_ENTRY} is not in ${serverOutDir}, so the preview shim was not written and every prerendered route will fall back to SSR.`);
838
+ const found = [dirs.nitroOutput.serverDir, ...dirs.entryDirs].filter((dir) => !!dir);
839
+ const candidates = [...new Set(found)];
840
+ let entryDir;
841
+ for (const candidate of candidates) {
842
+ const resolved = resolve(root, candidate);
843
+ if (await exists(join(resolved, NITRO_SERVER_ENTRY))) {
844
+ entryDir = resolved;
845
+ break;
846
+ }
847
+ }
848
+ if (!entryDir) {
849
+ logWarning(`Cannot prerender: nitro's ${NITRO_SERVER_ENTRY} is in none of ${candidates.join(", ")}, so the preview shim was not written and every prerendered route will fall back to SSR.`);
801
850
  return;
802
851
  }
803
- const basename = nodePath.basename(serverEntryName, nodePath.extname(serverEntryName));
804
- if (!basename || basename === "index") {
805
- logWarning(`Cannot prerender: the server entry "${serverEntryName}" would need a shim at ${SERVER_OUTPUT_DIR}/index.js, which outranks nitro's own entry when publishing. Rename the entry to anything but \`index\`.`);
852
+ const entryName = basename(serverEntryName, extname(serverEntryName));
853
+ const wouldOutrankNitroEntry = entryName === "index" && dirs.shimDir === SERVER_OUTPUT_DIR;
854
+ if (!entryName || wouldOutrankNitroEntry) {
855
+ logWarning(`Cannot prerender: the server entry "${serverEntryName}" would need a shim at ${dirs.shimDir}/index.js, which outranks nitro's own entry when publishing. Rename the entry to anything but \`index\`.`);
806
856
  return;
807
857
  }
808
- const target = nodePath.join(outDir, `${basename}.js`);
858
+ const shimDir = resolve(root, dirs.shimDir);
859
+ const target = join(shimDir, `${entryName}.js`);
809
860
  const occupant = await readFile(target, "utf8").catch(() => void 0);
810
861
  if (occupant !== void 0 && !occupant.startsWith(SHIM_MARKER)) {
811
- logWarning(`Cannot prerender: ${basename}.js already exists in ${serverOutDir} and was not written by this plugin.`);
862
+ logWarning(`Cannot prerender: ${entryName}.js already exists in ${dirs.shimDir} and was not written by this plugin.`);
812
863
  return;
813
864
  }
814
865
  let vars = {};
815
866
  try {
816
- const candidate = JSON.parse(await readFile(nodePath.join(outDir, NITRO_WRANGLER_CONFIG), "utf8"))?.vars;
867
+ const candidate = JSON.parse(await readFile(join(entryDir, NITRO_WRANGLER_CONFIG), "utf8"))?.vars;
817
868
  if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) vars = candidate;
818
869
  } catch {}
819
- await writeFile(target, prerenderShimSource(vars));
870
+ const specifier = relative(shimDir, join(entryDir, NITRO_SERVER_ENTRY)).split(sep).join("/");
871
+ await mkdir(shimDir, { recursive: true });
872
+ await writeFile(target, prerenderShimSource(vars, specifier.startsWith(".") ? specifier : `./${specifier}`));
820
873
  state.file = target;
821
874
  }
822
875
  }
@@ -1077,10 +1130,11 @@ function defineConfig(configOrOptions = {}) {
1077
1130
  };
1078
1131
  }
1079
1132
  } else if (!nitroOpts.preset && !await nitroSupportsDefaultPreset()) logWarning("The installed `nitro` predates the `defaultPreset` option (3.0.260603-beta), so the Cloudflare fallback is ignored and a zero-config build may target Node instead. Upgrade nitro to >=3.0.260603-beta, or set an explicit `nitro: { preset: \"cloudflare-module\" }`.");
1133
+ const shimDirs = prerenderEnabled ? prerenderShimDirs(options.vite, nitroOpts) : void 0;
1080
1134
  internalPlugins.push(nitro(nitroOpts));
1081
- if (prerenderEnabled) {
1135
+ if (shimDirs) {
1082
1136
  const shimState = {};
1083
- internalPlugins.push(prerenderPreviewShim(shimState), prerenderPreviewShimCleanup(shimState));
1137
+ internalPlugins.push(prerenderPreviewShim(shimState, shimDirs), prerenderPreviewShimCleanup(shimState));
1084
1138
  }
1085
1139
  if (isSandbox) internalPlugins.push(stripRedundantNodejsCompatFlag());
1086
1140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/vite-tanstack-config",
3
- "version": "2.19.3",
3
+ "version": "2.19.4",
4
4
  "description": "Vite config wrapper for Lovable TanStack Start projects",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",