@zachhandley/ez-i18n 0.3.13 → 0.3.15

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
@@ -152,9 +152,6 @@ function toRelativeImport(absolutePath, projectRoot) {
152
152
  }
153
153
  function toGlobPattern(baseDir, projectRoot) {
154
154
  const relativePath = path.relative(projectRoot, baseDir).replace(/\\/g, "/");
155
- if (relativePath.startsWith("public/") || relativePath === "public") {
156
- return null;
157
- }
158
155
  return `/${relativePath}/**/*.json`;
159
156
  }
160
157
  function isInPublicDir(filePath, projectRoot) {
@@ -896,32 +893,27 @@ function __deepMerge(target, ...sources) {
896
893
  function getPublicLoaderCode() {
897
894
  return `
898
895
  async function __loadPublicJson(url, absolutePath) {
899
- // Browser environment - use fetch with relative URL
900
- if (typeof window !== 'undefined') {
896
+ // Browser - fetch with relative URL
897
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
901
898
  return fetch(url).then(r => r.json());
902
899
  }
903
900
 
904
- // Edge runtime detection (Cloudflare Workers, Vercel Edge, Deno, etc.)
905
- // These environments have fetch but no filesystem access
906
- const isEdgeRuntime = typeof globalThis.caches !== 'undefined' || // CF Workers / Service Workers
907
- typeof globalThis.EdgeRuntime !== 'undefined' || // Vercel Edge
908
- typeof Deno !== 'undefined' || // Deno
909
- !globalThis.process?.versions?.node; // No Node.js process
901
+ // Cloudflare Workers - use ASSETS binding (set by middleware)
902
+ const assets = globalThis.__EZ_I18N_ASSETS__;
903
+ if (assets && typeof assets.fetch === 'function') {
904
+ const response = await assets.fetch(new URL(url, 'https://assets.local'));
905
+ return response.json();
906
+ }
910
907
 
911
- if (isEdgeRuntime) {
912
- // Edge runtime - need absolute URL for fetch
913
- // Priority: Astro site config > middleware-set origin > relative (hope for the best)
914
- const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
915
- globalThis.__EZ_I18N_ORIGIN__ ||
916
- '';
917
- const fetchUrl = origin ? origin + url : url;
918
- return fetch(fetchUrl).then(r => r.json());
908
+ // Deno - use Deno.readTextFile
909
+ if (typeof Deno !== 'undefined') {
910
+ const content = await Deno.readTextFile(absolutePath);
911
+ return JSON.parse(content);
919
912
  }
920
913
 
921
- // Traditional Node.js SSR - read from filesystem
922
- const fs = await import('node:fs');
923
- const content = fs.readFileSync(absolutePath, 'utf-8');
924
- return JSON.parse(content);
914
+ // Node.js / Bun - use absolute path with node:fs
915
+ const { readFileSync } = await import('node:fs');
916
+ return JSON.parse(readFileSync(absolutePath, 'utf-8'));
925
917
  }`;
926
918
  }
927
919
  function resolveConfig(config) {
@@ -39,10 +39,11 @@ var onRequest = defineMiddleware(async ({ cookies, request, locals, redirect },
39
39
  locale = browserLang;
40
40
  }
41
41
  locals.locale = locale;
42
+ const runtime = locals.runtime;
43
+ if (runtime?.env?.ASSETS) {
44
+ globalThis.__EZ_I18N_ASSETS__ = runtime.env.ASSETS;
45
+ }
42
46
  try {
43
- if (!import.meta.env.SITE && !globalThis.__EZ_I18N_ORIGIN__) {
44
- globalThis.__EZ_I18N_ORIGIN__ = url.origin;
45
- }
46
47
  const { loadTranslations } = await import("ez-i18n:translations");
47
48
  locals.translations = await loadTranslations(locale);
48
49
  globalThis.__EZ_I18N_SSR__ = {
@@ -56,7 +56,7 @@ declare function toRelativeImport(absolutePath: string, projectRoot: string): st
56
56
  * In virtual modules, globs must start with '/' (project root relative).
57
57
  * Returns null if the path is in public/ (can't use import.meta.glob for public files).
58
58
  */
59
- declare function toGlobPattern(baseDir: string, projectRoot: string): string | null;
59
+ declare function toGlobPattern(baseDir: string, projectRoot: string): string;
60
60
  /**
61
61
  * Get namespace from file path relative to locale base directory.
62
62
  *
@@ -173,9 +173,6 @@ function toRelativeImport(absolutePath, projectRoot) {
173
173
  }
174
174
  function toGlobPattern(baseDir, projectRoot) {
175
175
  const relativePath = path.relative(projectRoot, baseDir).replace(/\\/g, "/");
176
- if (relativePath.startsWith("public/") || relativePath === "public") {
177
- return null;
178
- }
179
176
  return `/${relativePath}/**/*.json`;
180
177
  }
181
178
  function getNamespaceFromPath(filePath, localeDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },