@zachhandley/ez-i18n 0.3.12 → 0.3.14

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -397,10 +397,12 @@ function vitePlugin(config) {
397
397
  };
398
398
  useCache = true;
399
399
  for (const [locale, files] of Object.entries(cache.discovered)) {
400
+ const filesInPublic = files.length > 0 && isInPublicDir(files[0], projectRoot);
400
401
  translationInfo.set(locale, {
401
402
  locale,
402
403
  files,
403
- localeBaseDir: localeBaseDirs[locale]
404
+ localeBaseDir: localeBaseDirs[locale],
405
+ isPublic: filesInPublic
404
406
  });
405
407
  }
406
408
  }
@@ -894,31 +896,24 @@ function __deepMerge(target, ...sources) {
894
896
  function getPublicLoaderCode() {
895
897
  return `
896
898
  async function __loadPublicJson(url, absolutePath) {
897
- // Browser environment - use fetch with relative URL
899
+ // Browser - use fetch with relative URL
898
900
  if (typeof window !== 'undefined') {
899
901
  return fetch(url).then(r => r.json());
900
902
  }
901
903
 
902
- // Edge runtime detection (Cloudflare Workers, Vercel Edge, Deno, etc.)
903
- // These environments have fetch but no filesystem access
904
- const isEdgeRuntime = typeof globalThis.caches !== 'undefined' || // CF Workers / Service Workers
905
- typeof globalThis.EdgeRuntime !== 'undefined' || // Vercel Edge
906
- typeof Deno !== 'undefined' || // Deno
907
- !globalThis.process?.versions?.node; // No Node.js process
904
+ // Get origin from Astro site config or middleware-set value
905
+ const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
906
+ globalThis.__EZ_I18N_ORIGIN__ ||
907
+ '';
908
908
 
909
- if (isEdgeRuntime) {
910
- // Edge runtime - need absolute URL for fetch
911
- // Priority: Astro site config > middleware-set origin > relative (hope for the best)
912
- const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
913
- globalThis.__EZ_I18N_ORIGIN__ ||
914
- '';
915
- const fetchUrl = origin ? origin + url : url;
916
- return fetch(fetchUrl).then(r => r.json());
909
+ // If we have an origin, use fetch (works in CF Workers, Vercel Edge, etc.)
910
+ if (origin) {
911
+ return fetch(origin + url).then(r => r.json());
917
912
  }
918
913
 
919
- // Traditional Node.js SSR - read from filesystem
920
- const fs = await import('node:fs');
921
- const content = fs.readFileSync(absolutePath, 'utf-8');
914
+ // No origin - try filesystem (traditional Node.js SSR)
915
+ const { readFileSync } = await import('node:fs');
916
+ const content = readFileSync(absolutePath, 'utf-8');
922
917
  return JSON.parse(content);
923
918
  }`;
924
919
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },