@farm.js/core 0.1.14 → 0.1.16

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 (123) hide show
  1. package/dist/agent-runtime.d.mts +5 -2
  2. package/dist/agent-runtime.d.ts +5 -2
  3. package/dist/api/client.d.mts +3 -2
  4. package/dist/api/client.d.ts +3 -2
  5. package/dist/api/route-manager.d.mts +5 -2
  6. package/dist/api/route-manager.d.ts +5 -2
  7. package/dist/api/runtime.d.mts +3 -2
  8. package/dist/api/runtime.d.ts +3 -2
  9. package/dist/{api-client-C8d7BZNp.d.mts → api-client-B-n3pm_Q.d.mts} +2 -1
  10. package/dist/{api-client-BWrEbxfO.d.ts → api-client-C0_NZEBl.d.ts} +2 -1
  11. package/dist/api.d.mts +7 -4
  12. package/dist/api.d.ts +7 -4
  13. package/dist/{app-wIYse61b.d.ts → app-AyjEsCBq.d.ts} +3 -3
  14. package/dist/{app-B3nVSjen.d.mts → app-CYPHeOo_.d.mts} +3 -3
  15. package/dist/app-markdown.d.mts +6 -3
  16. package/dist/app-markdown.d.ts +6 -3
  17. package/dist/{chunk-FOGLGRDS.mjs → chunk-7HDZYYS4.mjs} +100 -8
  18. package/dist/{chunk-DNCKVMSV.mjs → chunk-IL5RWYK7.mjs} +1 -1
  19. package/dist/{chunk-GNTPTTLA.mjs → chunk-IXTEENRS.mjs} +1 -1
  20. package/dist/{chunk-J2F5LFQ2.mjs → chunk-NHHKW2T6.mjs} +175 -8
  21. package/dist/{chunk-NJ47VORC.mjs → chunk-NUD6XBMO.mjs} +1 -1
  22. package/dist/{chunk-U6CRU23N.mjs → chunk-TYVVIQ5M.mjs} +10 -7
  23. package/dist/{chunk-W7IVHTOP.mjs → chunk-UQZPTIML.mjs} +15 -2
  24. package/dist/{chunk-S3QW3BIS.mjs → chunk-VVTREAG5.mjs} +89 -4
  25. package/dist/{client-plugins-C1EgdoJM.d.mts → client-plugins-CIPRtSsW.d.mts} +16 -4
  26. package/dist/{client-plugins-CslwYp3E.d.ts → client-plugins-CqVtZi5X.d.ts} +16 -4
  27. package/dist/client-plugins.d.mts +5 -2
  28. package/dist/client-plugins.d.ts +5 -2
  29. package/dist/client.d.mts +8 -7
  30. package/dist/client.d.ts +8 -7
  31. package/dist/config.d.mts +5 -2
  32. package/dist/config.d.ts +5 -2
  33. package/dist/{devtools-PCGEBRSC.mjs → devtools-IU7LKZOH.mjs} +2 -2
  34. package/dist/docs.cjs +74 -3
  35. package/dist/docs.mjs +3 -3
  36. package/dist/{route-C6UClI1z.d.mts → endpoint-Bu3XgeMK.d.mts} +3 -128
  37. package/dist/{route-CHBaW55F.d.ts → endpoint-kSAxE52R.d.ts} +3 -128
  38. package/dist/env.cjs +101 -8
  39. package/dist/env.d.mts +20 -2
  40. package/dist/env.d.ts +20 -2
  41. package/dist/env.mjs +3 -1
  42. package/dist/index.cjs +383 -24
  43. package/dist/index.d.mts +16 -15
  44. package/dist/index.d.ts +16 -15
  45. package/dist/index.mjs +20 -8
  46. package/dist/integrations.d.mts +5 -2
  47. package/dist/integrations.d.ts +5 -2
  48. package/dist/internal/app-markdown-runtime.d.mts +5 -2
  49. package/dist/internal/app-markdown-runtime.d.ts +5 -2
  50. package/dist/internal/build-runtime.cjs +435 -174
  51. package/dist/internal/build-runtime.d.mts +7 -4
  52. package/dist/internal/build-runtime.d.ts +7 -4
  53. package/dist/internal/build-runtime.mjs +6 -6
  54. package/dist/internal/cli-runtime.cjs +68 -4
  55. package/dist/internal/cli-runtime.mjs +2 -2
  56. package/dist/internal/client-error-overlay.cjs +1 -1
  57. package/dist/internal/client-error-overlay.mjs +1 -1
  58. package/dist/internal/compression-runtime.d.mts +5 -2
  59. package/dist/internal/compression-runtime.d.ts +5 -2
  60. package/dist/internal/config-runtime.cjs +68 -4
  61. package/dist/internal/config-runtime.d.mts +6 -3
  62. package/dist/internal/config-runtime.d.ts +6 -3
  63. package/dist/internal/config-runtime.mjs +2 -2
  64. package/dist/internal/product-telemetry-runtime.cjs +1 -1
  65. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  66. package/dist/internal/production-runtime.d.mts +11 -8
  67. package/dist/internal/production-runtime.d.ts +11 -8
  68. package/dist/{metadata-BsUcOEXg.d.ts → metadata-8g__AMPM.d.ts} +1 -1
  69. package/dist/{metadata-B1bxCPUY.d.mts → metadata-OMX6wFNf.d.mts} +1 -1
  70. package/dist/middleware.d.mts +7 -4
  71. package/dist/middleware.d.ts +7 -4
  72. package/dist/{nitro-ICBP5APY.mjs → nitro-3N4ZXRYM.mjs} +5 -2
  73. package/dist/plugin.cjs +278 -11
  74. package/dist/plugin.d.mts +5 -2
  75. package/dist/plugin.d.ts +5 -2
  76. package/dist/plugin.mjs +3 -3
  77. package/dist/{production-runtime-CsNn2-zx.d.ts → production-runtime-BJh7o6Cr.d.ts} +1 -1
  78. package/dist/{production-runtime-BDllolVh.d.mts → production-runtime-W3M0eNDV.d.mts} +1 -1
  79. package/dist/{render-plan-EG4hNFjy.d.ts → render-plan-Be4ZGTJP.d.ts} +1 -1
  80. package/dist/{render-plan-CNUlzylR.d.mts → render-plan-io7pvDNc.d.mts} +1 -1
  81. package/dist/renderer-client.d.mts +5 -4
  82. package/dist/renderer-client.d.ts +5 -4
  83. package/dist/{request-Blh_f7Z3.d.mts → request-DZkHYQ89.d.mts} +1 -1
  84. package/dist/{request-DsVSQVfD.d.ts → request-G8JhKr4F.d.ts} +1 -1
  85. package/dist/request.d.mts +6 -3
  86. package/dist/request.d.ts +6 -3
  87. package/dist/route-BxNJT447.d.ts +128 -0
  88. package/dist/route-C_eLaFTZ.d.mts +128 -0
  89. package/dist/{route-rendering-hUETRCbM.d.ts → route-rendering-BcLLPJgN.d.ts} +1 -1
  90. package/dist/{route-rendering-LT4XSoQK.d.mts → route-rendering-CbAKr1TY.d.mts} +1 -1
  91. package/dist/routes.d.mts +4 -2
  92. package/dist/routes.d.ts +4 -2
  93. package/dist/server-fn-client.d.mts +3 -2
  94. package/dist/server-fn-client.d.ts +3 -2
  95. package/dist/server-fn.cjs +141 -3
  96. package/dist/server-fn.d.mts +72 -1
  97. package/dist/server-fn.d.ts +72 -1
  98. package/dist/server-fn.mjs +12 -1
  99. package/dist/server-plugins.d.mts +6 -3
  100. package/dist/server-plugins.d.ts +6 -3
  101. package/dist/server-query-client.d.mts +1 -0
  102. package/dist/server-query-client.d.ts +1 -0
  103. package/dist/server-query.cjs +60 -3
  104. package/dist/server-query.d.mts +6 -1
  105. package/dist/server-query.d.ts +6 -1
  106. package/dist/server-query.mjs +3 -2
  107. package/dist/server.cjs +331 -15
  108. package/dist/server.d.mts +9 -8
  109. package/dist/server.d.ts +9 -8
  110. package/dist/server.mjs +6 -6
  111. package/dist/{spa-router-csKR9Ebj.d.mts → spa-router-BcS_4nqm.d.mts} +2 -2
  112. package/dist/{spa-router-Y_2FSJQK.d.ts → spa-router-BzFBUJkn.d.ts} +2 -2
  113. package/dist/testing.d.mts +5 -3
  114. package/dist/testing.d.ts +5 -3
  115. package/dist/{utils-DR2wfZAn.d.mts → utils-5kQP1mFR.d.mts} +1 -1
  116. package/dist/{utils-jISOE9SD.d.ts → utils-C4yrAhNc.d.ts} +1 -1
  117. package/dist/version.cjs +1 -1
  118. package/dist/version.mjs +1 -1
  119. package/dist/vite.cjs +416 -153
  120. package/dist/vite.d.mts +5 -2
  121. package/dist/vite.d.ts +5 -2
  122. package/dist/vite.mjs +3 -3
  123. package/package.json +3 -3
@@ -31,6 +31,259 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  ));
32
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
33
 
34
+ // src/env.ts
35
+ function resolveEnv(config, source = getProcessEnv()) {
36
+ const resolved = {
37
+ server: resolveEnvScope(config?.server, source, "server"),
38
+ public: resolveEnvScope(config?.public, source, "public")
39
+ };
40
+ return resolved;
41
+ }
42
+ function createBundledEnv(env2, source = getProcessEnv()) {
43
+ const resolved = normalizeResolvedEnv(env2 ?? {});
44
+ const server = {};
45
+ const runtime3 = {};
46
+ for (const [key, value] of Object.entries(resolved.server)) {
47
+ if (source[key] === void 0) {
48
+ server[key] = value;
49
+ } else {
50
+ runtime3[key] = getRuntimeEnvType(value);
51
+ }
52
+ }
53
+ return {
54
+ server,
55
+ public: resolved.public,
56
+ ...Object.keys(runtime3).length > 0 ? { runtime: { server: runtime3 } } : {}
57
+ };
58
+ }
59
+ function setEnv(env2) {
60
+ currentEnv = prepareEnv(env2);
61
+ if (typeof window === "undefined") {
62
+ farmEnvGlobal[FARM_ENV_SYMBOL] = currentEnv;
63
+ }
64
+ }
65
+ function getResolvedEnv() {
66
+ const env2 = getCurrentEnv();
67
+ if (typeof window === "undefined") readRuntimeServerEnv(env2);
68
+ return env2;
69
+ }
70
+ function resolveEnvScope(shape, source, scope) {
71
+ if (!shape) {
72
+ return {};
73
+ }
74
+ const resolved = {};
75
+ for (const [key, parser] of Object.entries(shape)) {
76
+ try {
77
+ resolved[key] = parseEnvValue(parser, source[key], key, scope);
78
+ } catch (error) {
79
+ const message = error instanceof Error ? error.message : String(error);
80
+ throw new Error(`Invalid ${scope} env "${key}": ${message}`);
81
+ }
82
+ }
83
+ return resolved;
84
+ }
85
+ function parseEnvValue(parser, value, key, scope) {
86
+ if (typeof parser === "function") {
87
+ return parser(value, { key, scope });
88
+ }
89
+ if (parser && typeof parser.parse === "function") {
90
+ return parser.parse(value);
91
+ }
92
+ throw new Error("expected a parser function or schema with parse()");
93
+ }
94
+ function createEnvProxy(scope) {
95
+ return new Proxy(
96
+ {},
97
+ {
98
+ get(_target, property) {
99
+ if (typeof property === "symbol") {
100
+ return void 0;
101
+ }
102
+ const env2 = getEnvScope(scope);
103
+ return scope === "server" ? readServerEnvKey(env2, property) : env2[property];
104
+ },
105
+ ownKeys() {
106
+ return Reflect.ownKeys(getEnvScope(scope));
107
+ },
108
+ getOwnPropertyDescriptor(_target, property) {
109
+ const env2 = getEnvScope(scope);
110
+ if (!(property in env2)) {
111
+ return void 0;
112
+ }
113
+ return {
114
+ enumerable: true,
115
+ configurable: true,
116
+ value: env2[property]
117
+ };
118
+ },
119
+ has(_target, property) {
120
+ return property in getEnvScope(scope);
121
+ }
122
+ }
123
+ );
124
+ }
125
+ function getEnvScope(scope) {
126
+ const env2 = getCurrentEnv();
127
+ if (scope === "server") {
128
+ assertServerEnvAccess();
129
+ readRuntimeServerEnv(env2);
130
+ }
131
+ return env2[scope] || {};
132
+ }
133
+ function readServerEnvKey(server, key) {
134
+ const value = server[key];
135
+ if (value === void 0) {
136
+ const state = getCurrentEnv()[FARM_ENV_RUNTIME_SYMBOL];
137
+ if (state && key in state.pending && !state.warned.has(key)) {
138
+ state.warned.add(key);
139
+ console.warn(
140
+ `[Farm] Server env "${key}" was set when this app was built but is not set where the server runs, so it reads as undefined. Farm reads server env at runtime and does not store it in the build output; set "${key}" in the server's environment.`
141
+ );
142
+ }
143
+ }
144
+ return value;
145
+ }
146
+ function readRuntimeServerEnv(env2) {
147
+ const state = env2[FARM_ENV_RUNTIME_SYMBOL];
148
+ if (!state) return;
149
+ const source = getProcessEnv();
150
+ for (const [key, type] of Object.entries(state.pending)) {
151
+ const raw = source[key];
152
+ if (raw === void 0) continue;
153
+ env2.server[key] = coerceRuntimeEnvValue(raw, type);
154
+ delete state.pending[key];
155
+ }
156
+ }
157
+ function getRuntimeEnvType(value) {
158
+ if (typeof value === "number") return "number";
159
+ if (typeof value === "boolean") return "boolean";
160
+ if (value !== null && typeof value === "object" && !(value instanceof Date)) return "json";
161
+ return "string";
162
+ }
163
+ function coerceRuntimeEnvValue(raw, type) {
164
+ if (type === "number") {
165
+ const value = Number(raw);
166
+ return raw.trim() !== "" && Number.isFinite(value) ? value : raw;
167
+ }
168
+ if (type === "boolean") {
169
+ if (/^(true|1)$/i.test(raw.trim())) return true;
170
+ if (/^(false|0|)$/i.test(raw.trim())) return false;
171
+ return raw;
172
+ }
173
+ if (type === "json") {
174
+ try {
175
+ return JSON.parse(raw);
176
+ } catch {
177
+ return raw;
178
+ }
179
+ }
180
+ return raw;
181
+ }
182
+ function prepareEnv(env2) {
183
+ const normalized = normalizeResolvedEnv(env2);
184
+ const runtime3 = env2.runtime?.server;
185
+ if (!isRecord(runtime3) || Object.keys(runtime3).length === 0) return normalized;
186
+ const prepared = { server: { ...normalized.server }, public: normalized.public };
187
+ Object.defineProperty(prepared, FARM_ENV_RUNTIME_SYMBOL, {
188
+ value: {
189
+ pending: { ...runtime3 },
190
+ warned: /* @__PURE__ */ new Set()
191
+ },
192
+ enumerable: false
193
+ });
194
+ return prepared;
195
+ }
196
+ function assertServerEnvAccess() {
197
+ if (typeof window !== "undefined") {
198
+ throw new Error("Farm server env is not available in the browser. Use publicEnv.");
199
+ }
200
+ }
201
+ function getInitialEnv() {
202
+ const injectedEnv = getInjectedEnv();
203
+ if (injectedEnv) {
204
+ return injectedEnv;
205
+ }
206
+ if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
207
+ return normalizeResolvedEnv(farmEnvGlobal[FARM_ENV_SYMBOL]);
208
+ }
209
+ return {
210
+ server: {},
211
+ public: getInjectedPublicEnv()
212
+ };
213
+ }
214
+ function getCurrentEnv() {
215
+ if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
216
+ return farmEnvGlobal[FARM_ENV_SYMBOL];
217
+ }
218
+ return currentEnv;
219
+ }
220
+ function getInjectedEnv() {
221
+ try {
222
+ if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
223
+ return prepareEnv(__FARM_ENV__);
224
+ }
225
+ } catch {
226
+ }
227
+ return null;
228
+ }
229
+ function getInjectedPublicEnv() {
230
+ try {
231
+ if (typeof __FARM_PUBLIC_ENV__ !== "undefined" && __FARM_PUBLIC_ENV__) {
232
+ return __FARM_PUBLIC_ENV__;
233
+ }
234
+ } catch {
235
+ }
236
+ return {};
237
+ }
238
+ function normalizeResolvedEnv(env2) {
239
+ return {
240
+ server: isRecord(env2.server) ? env2.server : {},
241
+ public: isRecord(env2.public) ? env2.public : {}
242
+ };
243
+ }
244
+ function isRecord(value) {
245
+ return !!value && typeof value === "object" && !Array.isArray(value);
246
+ }
247
+ function getProcessEnv() {
248
+ if (typeof process !== "undefined" && process.env) {
249
+ return process.env;
250
+ }
251
+ return {};
252
+ }
253
+ var FARM_ENV_SYMBOL, FARM_ENV_RUNTIME_SYMBOL, farmEnvGlobal, currentEnv, env, publicEnv;
254
+ var init_env = __esm({
255
+ "src/env.ts"() {
256
+ "use strict";
257
+ FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
258
+ FARM_ENV_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env.runtime");
259
+ farmEnvGlobal = globalThis;
260
+ currentEnv = getInitialEnv();
261
+ __name(resolveEnv, "resolveEnv");
262
+ __name(createBundledEnv, "createBundledEnv");
263
+ __name(setEnv, "setEnv");
264
+ __name(getResolvedEnv, "getResolvedEnv");
265
+ env = createEnvProxy("server");
266
+ publicEnv = createEnvProxy("public");
267
+ __name(resolveEnvScope, "resolveEnvScope");
268
+ __name(parseEnvValue, "parseEnvValue");
269
+ __name(createEnvProxy, "createEnvProxy");
270
+ __name(getEnvScope, "getEnvScope");
271
+ __name(readServerEnvKey, "readServerEnvKey");
272
+ __name(readRuntimeServerEnv, "readRuntimeServerEnv");
273
+ __name(getRuntimeEnvType, "getRuntimeEnvType");
274
+ __name(coerceRuntimeEnvValue, "coerceRuntimeEnvValue");
275
+ __name(prepareEnv, "prepareEnv");
276
+ __name(assertServerEnvAccess, "assertServerEnvAccess");
277
+ __name(getInitialEnv, "getInitialEnv");
278
+ __name(getCurrentEnv, "getCurrentEnv");
279
+ __name(getInjectedEnv, "getInjectedEnv");
280
+ __name(getInjectedPublicEnv, "getInjectedPublicEnv");
281
+ __name(normalizeResolvedEnv, "normalizeResolvedEnv");
282
+ __name(isRecord, "isRecord");
283
+ __name(getProcessEnv, "getProcessEnv");
284
+ }
285
+ });
286
+
34
287
  // src/plugin-dependencies.ts
35
288
  function pluginShortName(name2) {
36
289
  return name2.slice(Math.max(name2.lastIndexOf(":"), name2.lastIndexOf("/")) + 1);
@@ -5786,168 +6039,6 @@ var init_cron = __esm({
5786
6039
  }
5787
6040
  });
5788
6041
 
5789
- // src/env.ts
5790
- function resolveEnv(config, source = getProcessEnv()) {
5791
- const resolved = {
5792
- server: resolveEnvScope(config?.server, source, "server"),
5793
- public: resolveEnvScope(config?.public, source, "public")
5794
- };
5795
- return resolved;
5796
- }
5797
- function setEnv(env2) {
5798
- currentEnv = normalizeResolvedEnv(env2);
5799
- if (typeof window === "undefined") {
5800
- farmEnvGlobal[FARM_ENV_SYMBOL] = currentEnv;
5801
- }
5802
- }
5803
- function getResolvedEnv() {
5804
- return getCurrentEnv();
5805
- }
5806
- function resolveEnvScope(shape, source, scope) {
5807
- if (!shape) {
5808
- return {};
5809
- }
5810
- const resolved = {};
5811
- for (const [key, parser] of Object.entries(shape)) {
5812
- try {
5813
- resolved[key] = parseEnvValue(parser, source[key], key, scope);
5814
- } catch (error) {
5815
- const message = error instanceof Error ? error.message : String(error);
5816
- throw new Error(`Invalid ${scope} env "${key}": ${message}`);
5817
- }
5818
- }
5819
- return resolved;
5820
- }
5821
- function parseEnvValue(parser, value, key, scope) {
5822
- if (typeof parser === "function") {
5823
- return parser(value, { key, scope });
5824
- }
5825
- if (parser && typeof parser.parse === "function") {
5826
- return parser.parse(value);
5827
- }
5828
- throw new Error("expected a parser function or schema with parse()");
5829
- }
5830
- function createEnvProxy(scope) {
5831
- return new Proxy(
5832
- {},
5833
- {
5834
- get(_target, property) {
5835
- if (typeof property === "symbol") {
5836
- return void 0;
5837
- }
5838
- const env2 = getEnvScope(scope);
5839
- return env2[property];
5840
- },
5841
- ownKeys() {
5842
- return Reflect.ownKeys(getEnvScope(scope));
5843
- },
5844
- getOwnPropertyDescriptor(_target, property) {
5845
- const env2 = getEnvScope(scope);
5846
- if (!(property in env2)) {
5847
- return void 0;
5848
- }
5849
- return {
5850
- enumerable: true,
5851
- configurable: true,
5852
- value: env2[property]
5853
- };
5854
- },
5855
- has(_target, property) {
5856
- return property in getEnvScope(scope);
5857
- }
5858
- }
5859
- );
5860
- }
5861
- function getEnvScope(scope) {
5862
- if (scope === "server") {
5863
- assertServerEnvAccess();
5864
- }
5865
- return getCurrentEnv()[scope] || {};
5866
- }
5867
- function assertServerEnvAccess() {
5868
- if (typeof window !== "undefined") {
5869
- throw new Error("Farm server env is not available in the browser. Use publicEnv.");
5870
- }
5871
- }
5872
- function getInitialEnv() {
5873
- const injectedEnv = getInjectedEnv();
5874
- if (injectedEnv) {
5875
- return injectedEnv;
5876
- }
5877
- if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
5878
- return normalizeResolvedEnv(farmEnvGlobal[FARM_ENV_SYMBOL]);
5879
- }
5880
- return {
5881
- server: {},
5882
- public: getInjectedPublicEnv()
5883
- };
5884
- }
5885
- function getCurrentEnv() {
5886
- if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
5887
- return farmEnvGlobal[FARM_ENV_SYMBOL];
5888
- }
5889
- return currentEnv;
5890
- }
5891
- function getInjectedEnv() {
5892
- try {
5893
- if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
5894
- return normalizeResolvedEnv(__FARM_ENV__);
5895
- }
5896
- } catch {
5897
- }
5898
- return null;
5899
- }
5900
- function getInjectedPublicEnv() {
5901
- try {
5902
- if (typeof __FARM_PUBLIC_ENV__ !== "undefined" && __FARM_PUBLIC_ENV__) {
5903
- return __FARM_PUBLIC_ENV__;
5904
- }
5905
- } catch {
5906
- }
5907
- return {};
5908
- }
5909
- function normalizeResolvedEnv(env2) {
5910
- return {
5911
- server: isRecord(env2.server) ? env2.server : {},
5912
- public: isRecord(env2.public) ? env2.public : {}
5913
- };
5914
- }
5915
- function isRecord(value) {
5916
- return !!value && typeof value === "object" && !Array.isArray(value);
5917
- }
5918
- function getProcessEnv() {
5919
- if (typeof process !== "undefined" && process.env) {
5920
- return process.env;
5921
- }
5922
- return {};
5923
- }
5924
- var FARM_ENV_SYMBOL, farmEnvGlobal, currentEnv, env, publicEnv;
5925
- var init_env = __esm({
5926
- "src/env.ts"() {
5927
- "use strict";
5928
- FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
5929
- farmEnvGlobal = globalThis;
5930
- currentEnv = getInitialEnv();
5931
- __name(resolveEnv, "resolveEnv");
5932
- __name(setEnv, "setEnv");
5933
- __name(getResolvedEnv, "getResolvedEnv");
5934
- env = createEnvProxy("server");
5935
- publicEnv = createEnvProxy("public");
5936
- __name(resolveEnvScope, "resolveEnvScope");
5937
- __name(parseEnvValue, "parseEnvValue");
5938
- __name(createEnvProxy, "createEnvProxy");
5939
- __name(getEnvScope, "getEnvScope");
5940
- __name(assertServerEnvAccess, "assertServerEnvAccess");
5941
- __name(getInitialEnv, "getInitialEnv");
5942
- __name(getCurrentEnv, "getCurrentEnv");
5943
- __name(getInjectedEnv, "getInjectedEnv");
5944
- __name(getInjectedPublicEnv, "getInjectedPublicEnv");
5945
- __name(normalizeResolvedEnv, "normalizeResolvedEnv");
5946
- __name(isRecord, "isRecord");
5947
- __name(getProcessEnv, "getProcessEnv");
5948
- }
5949
- });
5950
-
5951
6042
  // src/app-markdown-config.ts
5952
6043
  function resolveMdxConfig(config) {
5953
6044
  return {
@@ -14322,9 +14413,10 @@ function collectIsolatedClientBoundaries(ownerPath, root, options = {}) {
14322
14413
  const importedBindings = getStaticImportBindings(content);
14323
14414
  let estimatedBoundaryCount2 = 0;
14324
14415
  for (const specifier of new Set(getImportSpecifiers(content))) {
14325
- const importedPath = resolveImportedModuleSourcePath(moduleSourcePath, specifier, root);
14416
+ const imported = resolveImportedModule(moduleSourcePath, specifier, root);
14417
+ const importedPath = imported.path;
14326
14418
  if (!importedPath) continue;
14327
- if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
14419
+ if (!imported.local) {
14328
14420
  const packageMetadata = inspectPackageClientBoundary(importedPath, root, /* @__PURE__ */ new Set());
14329
14421
  if (packageMetadata.shouldHydrate) {
14330
14422
  if (options.staticPackageBoundaries) {
@@ -14392,8 +14484,8 @@ function inspectClientModuleMetadata(resolvedPath, root, visited, inspectIslandE
14392
14484
  let importsClientBoundary = false;
14393
14485
  let importedIslandStrategy = null;
14394
14486
  for (const specifier of getImportSpecifiers(content)) {
14395
- const importedPath = resolveImportedModuleSourcePath(resolvedPath, specifier, root);
14396
- const importedMetadata = !specifier.startsWith(".") && !specifier.startsWith("/") ? inspectPackageClientBoundary(importedPath, root, visited) : inspectClientModuleMetadata(importedPath, root, visited, false);
14487
+ const imported = resolveImportedModule(resolvedPath, specifier, root);
14488
+ const importedMetadata = imported.local ? inspectClientModuleMetadata(imported.path, root, visited, false) : inspectPackageClientBoundary(imported.path, root, visited);
14397
14489
  if (importedMetadata.isClientComponent || importedMetadata.shouldHydrate) {
14398
14490
  importsClientBoundary = true;
14399
14491
  if (importedIslandStrategy === null) {
@@ -14518,6 +14610,161 @@ function isTypeOnlyNamedClause(tokens, startIndex, endIndex) {
14518
14610
  }
14519
14611
  return true;
14520
14612
  }
14613
+ function resolveImportedModule(importerPath, specifier, root) {
14614
+ if (specifier.startsWith(".") || specifier.startsWith("/")) {
14615
+ return { path: resolveImportedModuleSourcePath(importerPath, specifier, root), local: true };
14616
+ }
14617
+ const aliased = resolveProjectAliasSourcePath(specifier, root);
14618
+ if (aliased !== void 0) return { path: aliased, local: true };
14619
+ return { path: resolvePackageModuleSourcePath(importerPath, specifier, root), local: false };
14620
+ }
14621
+ function resolveProjectAliasSourcePath(specifier, root) {
14622
+ if (!root) return void 0;
14623
+ const projectRoot = import_path5.default.resolve(root);
14624
+ let match;
14625
+ for (const alias of getProjectImportAliases(projectRoot)) {
14626
+ const captured = matchProjectImportAlias(alias, specifier);
14627
+ if (captured === null) continue;
14628
+ if (!match || alias.prefix.length > match.alias.prefix.length) match = { alias, captured };
14629
+ }
14630
+ if (!match) return void 0;
14631
+ return resolveSourceCandidate(
14632
+ match.alias.targets.map(
14633
+ (target) => import_path5.default.normalize(match.alias.wildcard ? target.replace("*", match.captured) : target)
14634
+ )
14635
+ );
14636
+ }
14637
+ function matchProjectImportAlias(alias, specifier) {
14638
+ if (!alias.wildcard) return specifier === alias.prefix ? "" : null;
14639
+ if (specifier.length < alias.prefix.length + alias.suffix.length || !specifier.startsWith(alias.prefix) || !specifier.endsWith(alias.suffix)) {
14640
+ return null;
14641
+ }
14642
+ return specifier.slice(alias.prefix.length, specifier.length - alias.suffix.length);
14643
+ }
14644
+ function getProjectImportAliases(projectRoot) {
14645
+ const stamp = PROJECT_ALIAS_FILES.map((file) => {
14646
+ try {
14647
+ return String(import_fs2.default.statSync(import_path5.default.join(projectRoot, file)).mtimeMs);
14648
+ } catch {
14649
+ return "-";
14650
+ }
14651
+ }).join(":");
14652
+ const cached = projectImportAliasCache.get(projectRoot);
14653
+ if (cached?.stamp === stamp) return cached.aliases;
14654
+ const aliases = [
14655
+ ...readTsconfigPathAliases(projectRoot),
14656
+ ...readPackageImportAliases(projectRoot)
14657
+ ];
14658
+ if (!aliases.some((alias) => alias.prefix === "@/")) {
14659
+ aliases.push({
14660
+ prefix: "@/",
14661
+ suffix: "",
14662
+ wildcard: true,
14663
+ targets: [import_path5.default.join(projectRoot, "src", "*")]
14664
+ });
14665
+ }
14666
+ projectImportAliasCache.set(projectRoot, { stamp, aliases });
14667
+ return aliases;
14668
+ }
14669
+ function readTsconfigPathAliases(projectRoot) {
14670
+ for (const name2 of ["tsconfig.json", "jsconfig.json"]) {
14671
+ const configPath = import_path5.default.join(projectRoot, name2);
14672
+ if (!import_fs2.default.existsSync(configPath)) continue;
14673
+ const resolved = readTsconfigPaths(configPath, /* @__PURE__ */ new Set());
14674
+ if (!resolved?.paths) return [];
14675
+ const base = resolved.baseUrl ?? resolved.pathsDirectory;
14676
+ return Object.entries(resolved.paths).flatMap(([pattern, targets]) => {
14677
+ if (!Array.isArray(targets)) return [];
14678
+ const wildcardIndex = pattern.indexOf("*");
14679
+ return [
14680
+ {
14681
+ prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
14682
+ suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
14683
+ wildcard: wildcardIndex !== -1,
14684
+ targets: targets.filter((target) => typeof target === "string").map((target) => import_path5.default.resolve(base, target))
14685
+ }
14686
+ ];
14687
+ });
14688
+ }
14689
+ return [];
14690
+ }
14691
+ function readTsconfigPaths(configPath, visited) {
14692
+ if (visited.has(configPath)) return null;
14693
+ visited.add(configPath);
14694
+ const config = readJsonWithComments(configPath);
14695
+ if (!config) return null;
14696
+ const directory = import_path5.default.dirname(configPath);
14697
+ const parents = (Array.isArray(config.extends) ? config.extends : [config.extends]).filter(
14698
+ (parent) => typeof parent === "string" && parent.startsWith(".")
14699
+ );
14700
+ let inherited = null;
14701
+ for (const parent of parents) {
14702
+ const parentPath = import_path5.default.resolve(
14703
+ directory,
14704
+ parent.endsWith(".json") ? parent : `${parent}.json`
14705
+ );
14706
+ inherited = readTsconfigPaths(parentPath, visited) ?? inherited;
14707
+ }
14708
+ const options = config.compilerOptions ?? {};
14709
+ const baseUrl = typeof options.baseUrl === "string" ? import_path5.default.resolve(directory, options.baseUrl) : inherited?.baseUrl;
14710
+ if (options.paths && typeof options.paths === "object") {
14711
+ return { paths: options.paths, pathsDirectory: directory, baseUrl };
14712
+ }
14713
+ return inherited ? { ...inherited, baseUrl } : { pathsDirectory: directory, baseUrl };
14714
+ }
14715
+ function readPackageImportAliases(projectRoot) {
14716
+ const imports = readPackageJson(import_path5.default.join(projectRoot, "package.json"))?.imports;
14717
+ if (!imports || typeof imports !== "object") return [];
14718
+ return Object.entries(imports).flatMap(([pattern, value]) => {
14719
+ const target = resolveConditionalExportTarget(value);
14720
+ if (!pattern.startsWith("#") || !target?.startsWith("./")) return [];
14721
+ const wildcardIndex = pattern.indexOf("*");
14722
+ return [
14723
+ {
14724
+ prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
14725
+ suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
14726
+ wildcard: wildcardIndex !== -1,
14727
+ targets: [import_path5.default.resolve(projectRoot, target)]
14728
+ }
14729
+ ];
14730
+ });
14731
+ }
14732
+ function readJsonWithComments(filePath) {
14733
+ let source;
14734
+ try {
14735
+ source = import_fs2.default.readFileSync(filePath, "utf8");
14736
+ } catch {
14737
+ return null;
14738
+ }
14739
+ let output = "";
14740
+ let inString = false;
14741
+ for (let index = 0; index < source.length; index++) {
14742
+ const char = source[index];
14743
+ if (inString) {
14744
+ output += char;
14745
+ if (char === "\\") output += source[++index] ?? "";
14746
+ else if (char === '"') inString = false;
14747
+ continue;
14748
+ }
14749
+ if (char === '"') {
14750
+ inString = true;
14751
+ output += char;
14752
+ } else if (char === "/" && source[index + 1] === "/") {
14753
+ while (index < source.length && source[index] !== "\n") index++;
14754
+ output += "\n";
14755
+ } else if (char === "/" && source[index + 1] === "*") {
14756
+ const end = source.indexOf("*/", index + 2);
14757
+ index = end === -1 ? source.length : end + 1;
14758
+ } else {
14759
+ output += char;
14760
+ }
14761
+ }
14762
+ try {
14763
+ return JSON.parse(output.replace(/,(\s*[}\]])/g, "$1"));
14764
+ } catch {
14765
+ return null;
14766
+ }
14767
+ }
14521
14768
  function resolveImportedModuleSourcePath(importerPath, specifier, root) {
14522
14769
  if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
14523
14770
  return resolvePackageModuleSourcePath(importerPath, specifier, root);
@@ -14648,7 +14895,7 @@ function resolveSourceCandidate(candidates) {
14648
14895
  }
14649
14896
  return null;
14650
14897
  }
14651
- var import_fs2, import_path5, import_url3, FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES, RESOLVABLE_SOURCE_EXTENSIONS, REGEXP_PREFIX_PUNCTUATION, REGEXP_PREFIX_KEYWORDS, PARSER_SENSITIVE_JSX_CONTAINERS;
14898
+ var import_fs2, import_path5, import_url3, FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES, RESOLVABLE_SOURCE_EXTENSIONS, REGEXP_PREFIX_PUNCTUATION, REGEXP_PREFIX_KEYWORDS, PARSER_SENSITIVE_JSX_CONTAINERS, projectImportAliasCache, PROJECT_ALIAS_FILES;
14652
14899
  var init_client_component = __esm({
14653
14900
  "src/utils/client-component.ts"() {
14654
14901
  "use strict";
@@ -14754,6 +15001,16 @@ var init_client_component = __esm({
14754
15001
  __name(inspectPackageClientBoundary, "inspectPackageClientBoundary");
14755
15002
  __name(getImportSpecifiers, "getImportSpecifiers");
14756
15003
  __name(isTypeOnlyNamedClause, "isTypeOnlyNamedClause");
15004
+ __name(resolveImportedModule, "resolveImportedModule");
15005
+ projectImportAliasCache = /* @__PURE__ */ new Map();
15006
+ PROJECT_ALIAS_FILES = ["tsconfig.json", "jsconfig.json", "package.json"];
15007
+ __name(resolveProjectAliasSourcePath, "resolveProjectAliasSourcePath");
15008
+ __name(matchProjectImportAlias, "matchProjectImportAlias");
15009
+ __name(getProjectImportAliases, "getProjectImportAliases");
15010
+ __name(readTsconfigPathAliases, "readTsconfigPathAliases");
15011
+ __name(readTsconfigPaths, "readTsconfigPaths");
15012
+ __name(readPackageImportAliases, "readPackageImportAliases");
15013
+ __name(readJsonWithComments, "readJsonWithComments");
14757
15014
  __name(resolveImportedModuleSourcePath, "resolveImportedModuleSourcePath");
14758
15015
  __name(resolvePackageModuleSourcePath, "resolvePackageModuleSourcePath");
14759
15016
  __name(findPackageDirectory, "findPackageDirectory");
@@ -20221,7 +20478,7 @@ var init_server3 = __esm({
20221
20478
  var version;
20222
20479
  var init_package = __esm({
20223
20480
  "package.json"() {
20224
- version = "0.1.14";
20481
+ version = "0.1.16";
20225
20482
  }
20226
20483
  });
20227
20484
 
@@ -36305,7 +36562,7 @@ function getEnvDefines(config, configEnv) {
36305
36562
  )
36306
36563
  };
36307
36564
  if (configEnv?.isSsrBuild) {
36308
- defines.__FARM_ENV__ = JSON.stringify(getFullEnvDefine(config));
36565
+ defines.__FARM_ENV__ = JSON.stringify(createBundledEnv(getFullEnvDefine(config)));
36309
36566
  }
36310
36567
  return defines;
36311
36568
  }
@@ -40700,6 +40957,7 @@ var fs15, path43, import_node_url12, ALL_TYPE_ARTIFACTS, createEmptyTypeArtifact
40700
40957
  var init_vite2 = __esm({
40701
40958
  "src/vite.ts"() {
40702
40959
  "use strict";
40960
+ init_env();
40703
40961
  init_app();
40704
40962
  init_utils();
40705
40963
  init_plugin();
@@ -40915,7 +41173,7 @@ export const farmRegistry: {
40915
41173
  clientManifest?: any;
40916
41174
  routePaths?: Record<string, string>;
40917
41175
  } = {
40918
- env: ${JSON.stringify(config.env || { server: {}, public: {} }, null, 2)},
41176
+ env: ${JSON.stringify(createBundledEnv(config.env), null, 2)},
40919
41177
  deploymentId: ${JSON.stringify(config.deploymentId)},
40920
41178
  basePath: ${JSON.stringify(config.basePath)},
40921
41179
  apiBasePath: ${JSON.stringify(apiBasePath)},
@@ -41419,7 +41677,7 @@ export default defineEventHandler(async (event: H3Event) => {
41419
41677
  farmRegistry.apiRouteManager = apiRouteManager;
41420
41678
  farmRegistry.routeManager = routeManager;
41421
41679
  farmRegistry.serverRenderer = serverRenderer;
41422
- farmRegistry.env = config.env || { server: {}, public: {} };
41680
+ farmRegistry.env = createBundledEnv(config.env);
41423
41681
  farmRegistry.deploymentId = config.deploymentId;
41424
41682
  farmRegistry.basePath = config.basePath;
41425
41683
  };
@@ -41484,6 +41742,7 @@ var import_path16;
41484
41742
  var init_nitro = __esm({
41485
41743
  "src/nitro/index.ts"() {
41486
41744
  "use strict";
41745
+ init_env();
41487
41746
  import_path16 = __toESM(require("path"));
41488
41747
  init_workflows();
41489
41748
  init_cron();
@@ -41506,6 +41765,7 @@ __export(build_runtime_exports, {
41506
41765
  module.exports = __toCommonJS(build_runtime_exports);
41507
41766
 
41508
41767
  // src/build/index.ts
41768
+ init_env();
41509
41769
  init_config4();
41510
41770
  var import_path17 = __toESM(require("path"));
41511
41771
  var import_node_fs14 = require("fs");
@@ -41516,6 +41776,7 @@ init_server_path();
41516
41776
  init_layers();
41517
41777
 
41518
41778
  // src/nitro/universal-build.ts
41779
+ init_env();
41519
41780
  init_config4();
41520
41781
 
41521
41782
  // src/nitro/client-css-href.ts
@@ -46200,7 +46461,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
46200
46461
  },
46201
46462
  define: {
46202
46463
  __FARM_API_BASE_URL__: JSON.stringify(config.api.baseURL),
46203
- __FARM_ENV__: JSON.stringify(config.env || { server: {}, public: {} }),
46464
+ __FARM_ENV__: JSON.stringify(createBundledEnv(config.env)),
46204
46465
  __FARM_PUBLIC_ENV__: JSON.stringify(config.env?.public || {})
46205
46466
  },
46206
46467
  plugins: [
@@ -51651,7 +51912,7 @@ async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
51651
51912
  },
51652
51913
  define: {
51653
51914
  __FARM_API_BASE_URL__: JSON.stringify(config.api.baseURL),
51654
- __FARM_ENV__: JSON.stringify(config.env || { server: {}, public: {} }),
51915
+ __FARM_ENV__: JSON.stringify(createBundledEnv(config.env)),
51655
51916
  __FARM_PUBLIC_ENV__: JSON.stringify(config.env?.public || {})
51656
51917
  },
51657
51918
  plugins: [
@@ -51734,7 +51995,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
51734
51995
  farmRegistry.apiRouteManager = apiRouteManager;
51735
51996
  farmRegistry.routeManager = routeManager;
51736
51997
  farmRegistry.serverRenderer = serverRenderer;
51737
- farmRegistry.env = config.env || { server: {}, public: {} };
51998
+ farmRegistry.env = createBundledEnv(config.env);
51738
51999
  const routePaths = {};
51739
52000
  for (const [pattern, entry] of routeManager.getRoutes()) {
51740
52001
  const bundledPath = entry.modulePath.replace(/.*\/src\/app\//, "").replace(/\.(tsx?|jsx?)$/, ".js");