@zachhandley/ez-i18n 0.3.14 → 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,25 +893,27 @@ function __deepMerge(target, ...sources) {
896
893
  function getPublicLoaderCode() {
897
894
  return `
898
895
  async function __loadPublicJson(url, absolutePath) {
899
- // Browser - 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
- // Get origin from Astro site config or middleware-set value
905
- const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
906
- globalThis.__EZ_I18N_ORIGIN__ ||
907
- '';
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
+ }
908
907
 
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());
908
+ // Deno - use Deno.readTextFile
909
+ if (typeof Deno !== 'undefined') {
910
+ const content = await Deno.readTextFile(absolutePath);
911
+ return JSON.parse(content);
912
912
  }
913
913
 
914
- // No origin - try filesystem (traditional Node.js SSR)
914
+ // Node.js / Bun - use absolute path with node:fs
915
915
  const { readFileSync } = await import('node:fs');
916
- const content = readFileSync(absolutePath, 'utf-8');
917
- return JSON.parse(content);
916
+ return JSON.parse(readFileSync(absolutePath, 'utf-8'));
918
917
  }`;
919
918
  }
920
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.14",
3
+ "version": "0.3.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },