one 1.25.12 → 1.25.13

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 (210) hide show
  1. package/dist/cjs/cli/build.cjs +8 -161
  2. package/dist/cjs/cli/build.native.js +8 -204
  3. package/dist/cjs/cli/build.native.js.map +1 -1
  4. package/dist/cjs/createDevHandleRequest.cjs +151 -0
  5. package/dist/cjs/createDevHandleRequest.native.js +194 -0
  6. package/dist/cjs/createDevHandleRequest.native.js.map +1 -0
  7. package/dist/cjs/createHandleRequest.cjs +1 -123
  8. package/dist/cjs/createHandleRequest.native.js +1 -163
  9. package/dist/cjs/createHandleRequest.native.js.map +1 -1
  10. package/dist/cjs/createHandleRequest.test.cjs +25 -25
  11. package/dist/cjs/createHandleRequest.test.native.js +25 -25
  12. package/dist/cjs/createHandleRequest.test.native.js.map +1 -1
  13. package/dist/cjs/layouts/Drawer.cjs +0 -2
  14. package/dist/cjs/layouts/Drawer.native.js.map +1 -1
  15. package/dist/cjs/layouts/Tabs.cjs +0 -2
  16. package/dist/cjs/layouts/Tabs.native.js.map +1 -1
  17. package/dist/cjs/router/web/WebStackView.cjs +0 -2
  18. package/dist/cjs/router/web/WebStackView.native.js +0 -2
  19. package/dist/cjs/router/web/WebStackView.native.js.map +1 -1
  20. package/dist/cjs/serve-worker.cjs +3 -2
  21. package/dist/cjs/serve-worker.native.js +3 -2
  22. package/dist/cjs/serve-worker.native.js.map +1 -1
  23. package/dist/cjs/server/workerHandler.cjs +12 -7
  24. package/dist/cjs/server/workerHandler.native.js +13 -8
  25. package/dist/cjs/server/workerHandler.native.js.map +1 -1
  26. package/dist/cjs/server/workerHandler.test.cjs +25 -0
  27. package/dist/cjs/server/workerHandler.test.native.js +25 -0
  28. package/dist/cjs/server/workerHandler.test.native.js.map +1 -1
  29. package/dist/cjs/vite/cloudflareWranglerConfig.cjs +247 -0
  30. package/dist/cjs/vite/cloudflareWranglerConfig.native.js +392 -0
  31. package/dist/cjs/vite/cloudflareWranglerConfig.native.js.map +1 -0
  32. package/dist/cjs/vite/cloudflareWranglerConfig.test.cjs +116 -0
  33. package/dist/cjs/vite/cloudflareWranglerConfig.test.native.js +120 -0
  34. package/dist/cjs/vite/cloudflareWranglerConfig.test.native.js.map +1 -0
  35. package/dist/cjs/vite/one.cjs +4 -2
  36. package/dist/cjs/vite/one.native.js +8 -6
  37. package/dist/cjs/vite/one.native.js.map +1 -1
  38. package/dist/cjs/vite/plugins/SSRCSSPlugin.cjs +10 -1
  39. package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js +52 -3
  40. package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
  41. package/dist/cjs/vite/plugins/environmentGuardPlugin.cjs +1 -1
  42. package/dist/cjs/vite/plugins/environmentGuardPlugin.native.js +1 -1
  43. package/dist/cjs/vite/plugins/environmentGuardPlugin.native.js.map +1 -1
  44. package/dist/cjs/vite/plugins/environmentGuardPlugin.test.cjs +4 -0
  45. package/dist/cjs/vite/plugins/environmentGuardPlugin.test.native.js +4 -0
  46. package/dist/cjs/vite/plugins/environmentGuardPlugin.test.native.js.map +1 -1
  47. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +14 -5
  48. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +15 -5
  49. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  50. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.cjs +47 -0
  51. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js +47 -0
  52. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
  53. package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +2 -1
  54. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +2 -1
  55. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  56. package/dist/cjs/vite/plugins/virtualEntryPlugin.test.cjs +12 -0
  57. package/dist/cjs/vite/plugins/virtualEntryPlugin.test.native.js +12 -0
  58. package/dist/cjs/vite/plugins/virtualEntryPlugin.test.native.js.map +1 -1
  59. package/dist/cjs/vite/plugins/workerdDevPlugin.cjs +377 -0
  60. package/dist/cjs/vite/plugins/workerdDevPlugin.native.js +493 -0
  61. package/dist/cjs/vite/plugins/workerdDevPlugin.native.js.map +1 -0
  62. package/dist/cjs/vite/plugins/workerdDevPlugin.test.cjs +42 -0
  63. package/dist/cjs/vite/plugins/workerdDevPlugin.test.native.js +45 -0
  64. package/dist/cjs/vite/plugins/workerdDevPlugin.test.native.js.map +1 -0
  65. package/dist/esm/cli/build.mjs +1 -154
  66. package/dist/esm/cli/build.mjs.map +1 -1
  67. package/dist/esm/cli/build.native.js +1 -197
  68. package/dist/esm/cli/build.native.js.map +1 -1
  69. package/dist/esm/createDevHandleRequest.mjs +126 -0
  70. package/dist/esm/createDevHandleRequest.mjs.map +1 -0
  71. package/dist/esm/createDevHandleRequest.native.js +166 -0
  72. package/dist/esm/createDevHandleRequest.native.js.map +1 -0
  73. package/dist/esm/createHandleRequest.mjs +1 -123
  74. package/dist/esm/createHandleRequest.mjs.map +1 -1
  75. package/dist/esm/createHandleRequest.native.js +1 -163
  76. package/dist/esm/createHandleRequest.native.js.map +1 -1
  77. package/dist/esm/createHandleRequest.test.mjs +1 -1
  78. package/dist/esm/createHandleRequest.test.native.js +1 -1
  79. package/dist/esm/fork/useLinking.native.test.mjs +1 -1
  80. package/dist/esm/getURL.native.test.mjs +1 -1
  81. package/dist/esm/layouts/Drawer.mjs +0 -2
  82. package/dist/esm/layouts/Drawer.mjs.map +1 -1
  83. package/dist/esm/layouts/Drawer.native.js.map +1 -1
  84. package/dist/esm/layouts/Tabs.mjs +0 -2
  85. package/dist/esm/layouts/Tabs.mjs.map +1 -1
  86. package/dist/esm/layouts/Tabs.native.js.map +1 -1
  87. package/dist/esm/router/hmrImport.native.test.mjs +1 -1
  88. package/dist/esm/router/routeHmr.native.test.mjs +1 -1
  89. package/dist/esm/router/routeHmr.native.test.mjs.map +1 -1
  90. package/dist/esm/router/web/WebStackView.mjs +0 -2
  91. package/dist/esm/router/web/WebStackView.mjs.map +1 -1
  92. package/dist/esm/router/web/WebStackView.native.js +0 -2
  93. package/dist/esm/router/web/WebStackView.native.js.map +1 -1
  94. package/dist/esm/serve-worker.mjs +3 -2
  95. package/dist/esm/serve-worker.mjs.map +1 -1
  96. package/dist/esm/serve-worker.native.js +3 -2
  97. package/dist/esm/serve-worker.native.js.map +1 -1
  98. package/dist/esm/server/workerHandler.mjs +12 -7
  99. package/dist/esm/server/workerHandler.mjs.map +1 -1
  100. package/dist/esm/server/workerHandler.native.js +13 -8
  101. package/dist/esm/server/workerHandler.native.js.map +1 -1
  102. package/dist/esm/server/workerHandler.test.mjs +25 -0
  103. package/dist/esm/server/workerHandler.test.mjs.map +1 -1
  104. package/dist/esm/server/workerHandler.test.native.js +25 -0
  105. package/dist/esm/server/workerHandler.test.native.js.map +1 -1
  106. package/dist/esm/vite/cloudflareWranglerConfig.mjs +202 -0
  107. package/dist/esm/vite/cloudflareWranglerConfig.mjs.map +1 -0
  108. package/dist/esm/vite/cloudflareWranglerConfig.native.js +344 -0
  109. package/dist/esm/vite/cloudflareWranglerConfig.native.js.map +1 -0
  110. package/dist/esm/vite/cloudflareWranglerConfig.test.mjs +117 -0
  111. package/dist/esm/vite/cloudflareWranglerConfig.test.mjs.map +1 -0
  112. package/dist/esm/vite/cloudflareWranglerConfig.test.native.js +118 -0
  113. package/dist/esm/vite/cloudflareWranglerConfig.test.native.js.map +1 -0
  114. package/dist/esm/vite/one.mjs +4 -2
  115. package/dist/esm/vite/one.mjs.map +1 -1
  116. package/dist/esm/vite/one.native.js +8 -6
  117. package/dist/esm/vite/one.native.js.map +1 -1
  118. package/dist/esm/vite/plugins/SSRCSSPlugin.mjs +10 -1
  119. package/dist/esm/vite/plugins/SSRCSSPlugin.mjs.map +1 -1
  120. package/dist/esm/vite/plugins/SSRCSSPlugin.native.js +52 -3
  121. package/dist/esm/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
  122. package/dist/esm/vite/plugins/environmentGuardPlugin.mjs +1 -1
  123. package/dist/esm/vite/plugins/environmentGuardPlugin.mjs.map +1 -1
  124. package/dist/esm/vite/plugins/environmentGuardPlugin.native.js +1 -1
  125. package/dist/esm/vite/plugins/environmentGuardPlugin.native.js.map +1 -1
  126. package/dist/esm/vite/plugins/environmentGuardPlugin.test.mjs +4 -0
  127. package/dist/esm/vite/plugins/environmentGuardPlugin.test.mjs.map +1 -1
  128. package/dist/esm/vite/plugins/environmentGuardPlugin.test.native.js +4 -0
  129. package/dist/esm/vite/plugins/environmentGuardPlugin.test.native.js.map +1 -1
  130. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +13 -4
  131. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
  132. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +14 -4
  133. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  134. package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs +47 -0
  135. package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs.map +1 -1
  136. package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js +47 -0
  137. package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
  138. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +2 -1
  139. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
  140. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +2 -1
  141. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  142. package/dist/esm/vite/plugins/virtualEntryPlugin.test.mjs +12 -0
  143. package/dist/esm/vite/plugins/virtualEntryPlugin.test.mjs.map +1 -1
  144. package/dist/esm/vite/plugins/virtualEntryPlugin.test.native.js +12 -0
  145. package/dist/esm/vite/plugins/virtualEntryPlugin.test.native.js.map +1 -1
  146. package/dist/esm/vite/plugins/workerdDevPlugin.mjs +349 -0
  147. package/dist/esm/vite/plugins/workerdDevPlugin.mjs.map +1 -0
  148. package/dist/esm/vite/plugins/workerdDevPlugin.native.js +462 -0
  149. package/dist/esm/vite/plugins/workerdDevPlugin.native.js.map +1 -0
  150. package/dist/esm/vite/plugins/workerdDevPlugin.test.mjs +43 -0
  151. package/dist/esm/vite/plugins/workerdDevPlugin.test.mjs.map +1 -0
  152. package/dist/esm/vite/plugins/workerdDevPlugin.test.native.js +43 -0
  153. package/dist/esm/vite/plugins/workerdDevPlugin.test.native.js.map +1 -0
  154. package/package.json +9 -9
  155. package/src/cli/build.ts +7 -192
  156. package/src/createDevHandleRequest.ts +186 -0
  157. package/src/createHandleRequest.test.ts +1 -1
  158. package/src/createHandleRequest.ts +2 -172
  159. package/src/layouts/Drawer.web.tsx +0 -3
  160. package/src/layouts/Tabs.web.tsx +0 -2
  161. package/src/router/web/WebStackView.tsx +0 -3
  162. package/src/serve-worker.ts +6 -1
  163. package/src/server/workerHandler.test.ts +23 -0
  164. package/src/server/workerHandler.ts +15 -7
  165. package/src/vite/cloudflareWranglerConfig.test.ts +101 -0
  166. package/src/vite/cloudflareWranglerConfig.ts +248 -0
  167. package/src/vite/one.ts +11 -1
  168. package/src/vite/plugins/SSRCSSPlugin.ts +17 -2
  169. package/src/vite/plugins/environmentGuardPlugin.test.ts +5 -0
  170. package/src/vite/plugins/environmentGuardPlugin.ts +2 -2
  171. package/src/vite/plugins/fileSystemRouterPlugin.test.ts +44 -0
  172. package/src/vite/plugins/fileSystemRouterPlugin.tsx +20 -8
  173. package/src/vite/plugins/virtualEntryPlugin.test.ts +13 -0
  174. package/src/vite/plugins/virtualEntryPlugin.ts +3 -1
  175. package/src/vite/plugins/workerdDevPlugin.test.ts +44 -0
  176. package/src/vite/plugins/workerdDevPlugin.ts +408 -0
  177. package/types/cli/build.d.ts.map +1 -1
  178. package/types/createDevHandleRequest.d.ts +10 -0
  179. package/types/createDevHandleRequest.d.ts.map +1 -0
  180. package/types/createHandleRequest.d.ts +2 -9
  181. package/types/createHandleRequest.d.ts.map +1 -1
  182. package/types/layouts/Drawer.web.d.ts.map +1 -1
  183. package/types/layouts/Tabs.web.d.ts.map +1 -1
  184. package/types/router/web/WebStackView.d.ts.map +1 -1
  185. package/types/serve-worker.d.ts +3 -1
  186. package/types/serve-worker.d.ts.map +1 -1
  187. package/types/server/workerHandler.d.ts +1 -0
  188. package/types/server/workerHandler.d.ts.map +1 -1
  189. package/types/vite/cloudflareWranglerConfig.d.ts +21 -0
  190. package/types/vite/cloudflareWranglerConfig.d.ts.map +1 -0
  191. package/types/vite/cloudflareWranglerConfig.test.d.ts +2 -0
  192. package/types/vite/cloudflareWranglerConfig.test.d.ts.map +1 -0
  193. package/types/vite/one.d.ts.map +1 -1
  194. package/types/vite/plugins/SSRCSSPlugin.d.ts.map +1 -1
  195. package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
  196. package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
  197. package/types/vite/plugins/workerdDevPlugin.d.ts +15 -0
  198. package/types/vite/plugins/workerdDevPlugin.d.ts.map +1 -0
  199. package/types/vite/plugins/workerdDevPlugin.test.d.ts +2 -0
  200. package/types/vite/plugins/workerdDevPlugin.test.d.ts.map +1 -0
  201. package/dist/cjs/headless/devHeadlessNote.cjs +0 -34
  202. package/dist/cjs/headless/devHeadlessNote.native.js +0 -37
  203. package/dist/cjs/headless/devHeadlessNote.native.js.map +0 -1
  204. package/dist/esm/headless/devHeadlessNote.mjs +0 -9
  205. package/dist/esm/headless/devHeadlessNote.mjs.map +0 -1
  206. package/dist/esm/headless/devHeadlessNote.native.js +0 -9
  207. package/dist/esm/headless/devHeadlessNote.native.js.map +0 -1
  208. package/src/headless/devHeadlessNote.ts +0 -13
  209. package/types/headless/devHeadlessNote.d.ts +0 -2
  210. package/types/headless/devHeadlessNote.d.ts.map +0 -1
@@ -53,6 +53,7 @@ var import_getRouterRootFromOneOptions = require("../utils/getRouterRootFromOneO
53
53
  var import_isRolldown = require("../utils/isRolldown.cjs");
54
54
  var import_toAbsolute = require("../utils/toAbsolute.cjs");
55
55
  var import_buildVercelOutputDirectory = require("../vercel/build/buildVercelOutputDirectory.cjs");
56
+ var import_cloudflareWranglerConfig = require("../vite/cloudflareWranglerConfig.cjs");
56
57
  var import_getManifest = require("../vite/getManifest.cjs");
57
58
  var import_loadConfig = require("../vite/loadConfig.cjs");
58
59
  var import_one_server_only = require("../vite/one-server-only.cjs");
@@ -76,161 +77,16 @@ function normalizeDeploy(deploy) {
76
77
  };
77
78
  return deploy;
78
79
  }
79
- const GENERATED_CLOUDFLARE_WRANGLER_RULES = [{
80
- type: "ESModule",
81
- globs: ["./server/**/*.js"],
82
- fallthrough: true
83
- }, {
84
- type: "ESModule",
85
- globs: ["./api/**/*.js"],
86
- fallthrough: true
87
- }, {
88
- type: "ESModule",
89
- globs: ["./middlewares/**/*.js"],
90
- fallthrough: true
91
- }, {
92
- type: "ESModule",
93
- globs: ["./assets/**/*.js"],
94
- fallthrough: true
95
- }];
96
80
  const CLOUDFLARE_DEPLOY_WRANGLER_RULES = [{
97
81
  type: "ESModule",
98
82
  globs: ["assets/**/*.js", "assets/**/*.mjs"]
99
83
  }];
100
- function isPlainObject(value) {
101
- return !!value && typeof value === "object" && !Array.isArray(value);
102
- }
103
- function mergeJsonObjects(base, overrides) {
104
- const merged = {
105
- ...base
106
- };
107
- for (const [key, value] of Object.entries(overrides)) {
108
- const baseValue = merged[key];
109
- if (isPlainObject(baseValue) && isPlainObject(value)) {
110
- merged[key] = mergeJsonObjects(baseValue, value);
111
- } else {
112
- merged[key] = value;
113
- }
114
- }
115
- return merged;
116
- }
117
- function dedupeJsonValues(values) {
118
- const seen = /* @__PURE__ */new Set();
119
- return values.filter(value => {
120
- const key = JSON.stringify(value);
121
- if (seen.has(key)) return false;
122
- seen.add(key);
123
- return true;
124
- });
125
- }
126
- function mergeCloudflareCompatibilityFlags(flags) {
127
- const userFlags = Array.isArray(flags) ? flags.filter(flag => typeof flag === "string") : [];
128
- return dedupeJsonValues(["nodejs_compat", ...userFlags]);
129
- }
130
- function mergeCloudflareRules(rules) {
131
- const userRules = Array.isArray(rules) ? rules.filter(rule => isPlainObject(rule)) : [];
132
- return dedupeJsonValues([...GENERATED_CLOUDFLARE_WRANGLER_RULES, ...userRules]);
133
- }
134
- function parseJsonc(text) {
135
- let out = "";
136
- let i = 0;
137
- let inString = false;
138
- let quote = "";
139
- while (i < text.length) {
140
- const ch = text[i];
141
- const next = text[i + 1];
142
- if (inString) {
143
- if (ch === "\\") {
144
- out += ch + (next ?? "");
145
- i += 2;
146
- continue;
147
- }
148
- if (ch === quote) inString = false;
149
- out += ch;
150
- i++;
151
- continue;
152
- }
153
- if (ch === '"' || ch === "'") {
154
- inString = true;
155
- quote = ch;
156
- out += ch;
157
- i++;
158
- continue;
159
- }
160
- if (ch === "/" && next === "/") {
161
- while (i < text.length && text[i] !== "\n") i++;
162
- continue;
163
- }
164
- if (ch === "/" && next === "*") {
165
- i += 2;
166
- while (i < text.length - 1 && !(text[i] === "*" && text[i + 1] === "/")) i++;
167
- i += 2;
168
- continue;
169
- }
170
- out += ch;
171
- i++;
172
- }
173
- return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
174
- }
175
- async function loadUserWranglerConfig(root) {
176
- const candidateRoots = [... /* @__PURE__ */new Set([root, process.cwd()])];
177
- for (const candidateRoot of candidateRoots) {
178
- for (const fileName of ["wrangler.jsonc", "wrangler.json"]) {
179
- const configPath = (0, import_node_path.join)(candidateRoot, fileName);
180
- if (!(await import_fs_extra.default.pathExists(configPath))) {
181
- continue;
182
- }
183
- const contents = await import_fs_extra.default.readFile(configPath, "utf-8");
184
- let parsed;
185
- try {
186
- parsed = parseJsonc(contents);
187
- } catch (err) {
188
- throw new Error(`Failed to parse ${(0, import_node_path.relative)(process.cwd(), configPath)}: ${err.message}`);
189
- }
190
- if (!isPlainObject(parsed)) {
191
- throw new Error(`Expected ${(0, import_node_path.relative)(process.cwd(), configPath)} to contain a top-level JSON object`);
192
- }
193
- return {
194
- path: configPath,
195
- config: parsed
196
- };
197
- }
198
- }
199
- return null;
200
- }
201
- function createCloudflareWranglerConfig(projectName, userConfig) {
202
- const generatedConfig = {
203
- name: projectName,
204
- main: "worker.js",
205
- compatibility_date: "2024-12-05",
206
- compatibility_flags: ["nodejs_compat"],
207
- find_additional_modules: true,
208
- rules: GENERATED_CLOUDFLARE_WRANGLER_RULES,
209
- assets: {
210
- directory: "client",
211
- binding: "ASSETS",
212
- run_worker_first: true
213
- }
214
- };
215
- const mergedConfig = userConfig ? mergeJsonObjects(generatedConfig, userConfig) : generatedConfig;
216
- mergedConfig.main = "worker.js";
217
- mergedConfig.find_additional_modules = true;
218
- mergedConfig.compatibility_flags = mergeCloudflareCompatibilityFlags(mergedConfig.compatibility_flags);
219
- mergedConfig.rules = mergeCloudflareRules(mergedConfig.rules);
220
- mergedConfig.assets = {
221
- ...(isPlainObject(mergedConfig.assets) ? mergedConfig.assets : {}),
222
- directory: "client",
223
- binding: "ASSETS",
224
- run_worker_first: true
225
- };
226
- return mergedConfig;
227
- }
228
84
  function omitEmptyJsonValues(value) {
229
85
  if (Array.isArray(value)) {
230
86
  const items = value.map(item => omitEmptyJsonValues(item)).filter(item => item !== void 0);
231
87
  return items.length > 0 ? items : void 0;
232
88
  }
233
- if (isPlainObject(value)) {
89
+ if ((0, import_cloudflareWranglerConfig.isPlainObject)(value)) {
234
90
  const entries = Object.entries(value).map(([key, item]) => [key, omitEmptyJsonValues(item)]).filter(entry => entry[1] !== void 0);
235
91
  return entries.length > 0 ? Object.fromEntries(entries) : void 0;
236
92
  }
@@ -238,26 +94,17 @@ function omitEmptyJsonValues(value) {
238
94
  }
239
95
  async function finalizeCloudflareWranglerDeployConfig(configPath) {
240
96
  const parsed = JSON.parse(await import_fs_extra.default.readFile(configPath, "utf-8"));
241
- if (!isPlainObject(parsed)) {
97
+ if (!(0, import_cloudflareWranglerConfig.isPlainObject)(parsed)) {
242
98
  throw new Error(`Expected ${(0, import_node_path.relative)(process.cwd(), configPath)} to contain a JSON object`);
243
99
  }
244
100
  parsed.rules = CLOUDFLARE_DEPLOY_WRANGLER_RULES;
245
101
  const config = omitEmptyJsonValues(parsed);
246
- if (!isPlainObject(config)) {
102
+ if (!(0, import_cloudflareWranglerConfig.isPlainObject)(config)) {
247
103
  throw new Error(`Expected ${(0, import_node_path.relative)(process.cwd(), configPath)} to contain deploy config`);
248
104
  }
249
105
  await import_fs_extra.default.writeFile(configPath, `${JSON.stringify(config, null, 2)}
250
106
  `);
251
107
  }
252
- async function getCloudflareProjectName(root) {
253
- try {
254
- const pkg = JSON.parse(await import_fs_extra.default.readFile((0, import_node_path.join)(root, "package.json"), "utf-8"));
255
- if (pkg.name) {
256
- return pkg.name.replace(/^@[^/]+\//, "");
257
- }
258
- } catch {}
259
- return "one-app";
260
- }
261
108
  process.env.ONE_CACHE_KEY = constants.CACHE_KEY;
262
109
  function shouldUseWorkers(oneOptions) {
263
110
  if (process.env.ONE_BUILD_WORKERS === "0") return false;
@@ -335,7 +182,7 @@ async function build(args) {
335
182
  }
336
183
  const deployConfig = normalizeDeploy(oneOptions.web?.deploy);
337
184
  if (!process.env.ONE_SERVER_URL && deployConfig) {
338
- const url = deployConfig.url ?? (deployConfig.target === "cloudflare" ? `https://${await getCloudflareProjectName(process.cwd())}.workers.dev` : void 0);
185
+ const url = deployConfig.url ?? (deployConfig.target === "cloudflare" ? `https://${await (0, import_cloudflareWranglerConfig.getCloudflareProjectName)(process.cwd())}.workers.dev` : void 0);
339
186
  if (url) {
340
187
  process.env.ONE_SERVER_URL = url;
341
188
  console.info(`
@@ -1110,9 +957,9 @@ export default {
1110
957
  }
1111
958
  `;
1112
959
  await import_fs_extra.default.writeFile(workerSrcPath, workerCode);
1113
- const projectName = await getCloudflareProjectName(options.root);
1114
- const userWranglerConfig = await loadUserWranglerConfig(options.root);
1115
- const wranglerInputConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig?.config);
960
+ const projectName = await (0, import_cloudflareWranglerConfig.getCloudflareProjectName)(options.root);
961
+ const userWranglerConfig = await (0, import_cloudflareWranglerConfig.loadUserWranglerConfig)(options.root);
962
+ const wranglerInputConfig = (0, import_cloudflareWranglerConfig.createCloudflareWranglerConfig)(projectName, userWranglerConfig?.config);
1116
963
  wranglerInputConfig.main = (0, import_vite.normalizePath)((0, import_node_path.relative)((0, import_node_path.join)(options.root, outDir), workerSrcPath));
1117
964
  const wranglerInputPath = (0, import_node_path.join)(options.root, outDir, "_wrangler.input.jsonc");
1118
965
  await import_fs_extra.default.writeFile(wranglerInputPath, `${JSON.stringify(wranglerInputConfig, null, 2)}
@@ -55,6 +55,7 @@ var import_getRouterRootFromOneOptions = require("../utils/getRouterRootFromOneO
55
55
  var import_isRolldown = require("../utils/isRolldown.native.js");
56
56
  var import_toAbsolute = require("../utils/toAbsolute.native.js");
57
57
  var import_buildVercelOutputDirectory = require("../vercel/build/buildVercelOutputDirectory.native.js");
58
+ var import_cloudflareWranglerConfig = require("../vite/cloudflareWranglerConfig.native.js");
58
59
  var import_getManifest = require("../vite/getManifest.native.js");
59
60
  var import_loadConfig = require("../vite/loadConfig.native.js");
60
61
  var import_one_server_only = require("../vite/one-server-only.native.js");
@@ -83,198 +84,10 @@ function normalizeDeploy(deploy) {
83
84
  };
84
85
  return deploy;
85
86
  }
86
- var GENERATED_CLOUDFLARE_WRANGLER_RULES = [{
87
- type: "ESModule",
88
- globs: ["./server/**/*.js"],
89
- fallthrough: true
90
- }, {
91
- type: "ESModule",
92
- globs: ["./api/**/*.js"],
93
- fallthrough: true
94
- }, {
95
- type: "ESModule",
96
- globs: ["./middlewares/**/*.js"],
97
- fallthrough: true
98
- }, {
99
- type: "ESModule",
100
- globs: ["./assets/**/*.js"],
101
- fallthrough: true
102
- }];
103
87
  var CLOUDFLARE_DEPLOY_WRANGLER_RULES = [{
104
88
  type: "ESModule",
105
89
  globs: ["assets/**/*.js", "assets/**/*.mjs"]
106
90
  }];
107
- function isPlainObject(value) {
108
- return !!value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && !Array.isArray(value);
109
- }
110
- function mergeJsonObjects(base, overrides) {
111
- var merged = {
112
- ...base
113
- };
114
- var _iteratorNormalCompletion = true,
115
- _didIteratorError = false,
116
- _iteratorError = void 0;
117
- try {
118
- for (var _iterator = Object.entries(overrides)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
119
- var [key, value] = _step.value;
120
- var baseValue = merged[key];
121
- if (isPlainObject(baseValue) && isPlainObject(value)) {
122
- merged[key] = mergeJsonObjects(baseValue, value);
123
- } else {
124
- merged[key] = value;
125
- }
126
- }
127
- } catch (err) {
128
- _didIteratorError = true;
129
- _iteratorError = err;
130
- } finally {
131
- try {
132
- if (!_iteratorNormalCompletion && _iterator.return != null) {
133
- _iterator.return();
134
- }
135
- } finally {
136
- if (_didIteratorError) {
137
- throw _iteratorError;
138
- }
139
- }
140
- }
141
- return merged;
142
- }
143
- function dedupeJsonValues(values) {
144
- var seen = /* @__PURE__ */new Set();
145
- return values.filter(function (value) {
146
- var key = JSON.stringify(value);
147
- if (seen.has(key)) return false;
148
- seen.add(key);
149
- return true;
150
- });
151
- }
152
- function mergeCloudflareCompatibilityFlags(flags) {
153
- var userFlags = Array.isArray(flags) ? flags.filter(function (flag) {
154
- return typeof flag === "string";
155
- }) : [];
156
- return dedupeJsonValues(["nodejs_compat", ...userFlags]);
157
- }
158
- function mergeCloudflareRules(rules) {
159
- var userRules = Array.isArray(rules) ? rules.filter(function (rule) {
160
- return isPlainObject(rule);
161
- }) : [];
162
- return dedupeJsonValues([...GENERATED_CLOUDFLARE_WRANGLER_RULES, ...userRules]);
163
- }
164
- function parseJsonc(text) {
165
- var out = "";
166
- var i = 0;
167
- var inString = false;
168
- var quote = "";
169
- while (i < text.length) {
170
- var ch = text[i];
171
- var next = text[i + 1];
172
- if (inString) {
173
- if (ch === "\\") {
174
- out += ch + (next !== null && next !== void 0 ? next : "");
175
- i += 2;
176
- continue;
177
- }
178
- if (ch === quote) inString = false;
179
- out += ch;
180
- i++;
181
- continue;
182
- }
183
- if (ch === '"' || ch === "'") {
184
- inString = true;
185
- quote = ch;
186
- out += ch;
187
- i++;
188
- continue;
189
- }
190
- if (ch === "/" && next === "/") {
191
- while (i < text.length && text[i] !== "\n") i++;
192
- continue;
193
- }
194
- if (ch === "/" && next === "*") {
195
- i += 2;
196
- while (i < text.length - 1 && !(text[i] === "*" && text[i + 1] === "/")) i++;
197
- i += 2;
198
- continue;
199
- }
200
- out += ch;
201
- i++;
202
- }
203
- return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
204
- }
205
- async function loadUserWranglerConfig(root) {
206
- var candidateRoots = [... /* @__PURE__ */new Set([root, process.cwd()])];
207
- var _iteratorNormalCompletion = true,
208
- _didIteratorError = false,
209
- _iteratorError = void 0;
210
- try {
211
- for (var _iterator = candidateRoots[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
212
- var candidateRoot = _step.value;
213
- for (var _i = 0, _iter = ["wrangler.jsonc", "wrangler.json"]; _i < _iter.length; _i++) {
214
- var fileName = _iter[_i];
215
- var configPath = (0, import_path.join)(candidateRoot, fileName);
216
- if (!(await import_fs_extra.default.pathExists(configPath))) {
217
- continue;
218
- }
219
- var contents = await import_fs_extra.default.readFile(configPath, "utf-8");
220
- var parsed = void 0;
221
- try {
222
- parsed = parseJsonc(contents);
223
- } catch (err) {
224
- throw new Error(`Failed to parse ${(0, import_path.relative)(process.cwd(), configPath)}: ${err.message}`);
225
- }
226
- if (!isPlainObject(parsed)) {
227
- throw new Error(`Expected ${(0, import_path.relative)(process.cwd(), configPath)} to contain a top-level JSON object`);
228
- }
229
- return {
230
- path: configPath,
231
- config: parsed
232
- };
233
- }
234
- }
235
- } catch (err) {
236
- _didIteratorError = true;
237
- _iteratorError = err;
238
- } finally {
239
- try {
240
- if (!_iteratorNormalCompletion && _iterator.return != null) {
241
- _iterator.return();
242
- }
243
- } finally {
244
- if (_didIteratorError) {
245
- throw _iteratorError;
246
- }
247
- }
248
- }
249
- return null;
250
- }
251
- function createCloudflareWranglerConfig(projectName, userConfig) {
252
- var generatedConfig = {
253
- name: projectName,
254
- main: "worker.js",
255
- compatibility_date: "2024-12-05",
256
- compatibility_flags: ["nodejs_compat"],
257
- find_additional_modules: true,
258
- rules: GENERATED_CLOUDFLARE_WRANGLER_RULES,
259
- assets: {
260
- directory: "client",
261
- binding: "ASSETS",
262
- run_worker_first: true
263
- }
264
- };
265
- var mergedConfig = userConfig ? mergeJsonObjects(generatedConfig, userConfig) : generatedConfig;
266
- mergedConfig.main = "worker.js";
267
- mergedConfig.find_additional_modules = true;
268
- mergedConfig.compatibility_flags = mergeCloudflareCompatibilityFlags(mergedConfig.compatibility_flags);
269
- mergedConfig.rules = mergeCloudflareRules(mergedConfig.rules);
270
- mergedConfig.assets = {
271
- ...(isPlainObject(mergedConfig.assets) ? mergedConfig.assets : {}),
272
- directory: "client",
273
- binding: "ASSETS",
274
- run_worker_first: true
275
- };
276
- return mergedConfig;
277
- }
278
91
  function omitEmptyJsonValues(value) {
279
92
  if (Array.isArray(value)) {
280
93
  var items = value.map(function (item) {
@@ -284,7 +97,7 @@ function omitEmptyJsonValues(value) {
284
97
  });
285
98
  return items.length > 0 ? items : void 0;
286
99
  }
287
- if (isPlainObject(value)) {
100
+ if ((0, import_cloudflareWranglerConfig.isPlainObject)(value)) {
288
101
  var entries = Object.entries(value).map(function (param) {
289
102
  var [key, item] = param;
290
103
  return [key, omitEmptyJsonValues(item)];
@@ -297,26 +110,17 @@ function omitEmptyJsonValues(value) {
297
110
  }
298
111
  async function finalizeCloudflareWranglerDeployConfig(configPath) {
299
112
  var parsed = JSON.parse(await import_fs_extra.default.readFile(configPath, "utf-8"));
300
- if (!isPlainObject(parsed)) {
113
+ if (!(0, import_cloudflareWranglerConfig.isPlainObject)(parsed)) {
301
114
  throw new Error(`Expected ${(0, import_path.relative)(process.cwd(), configPath)} to contain a JSON object`);
302
115
  }
303
116
  parsed.rules = CLOUDFLARE_DEPLOY_WRANGLER_RULES;
304
117
  var config = omitEmptyJsonValues(parsed);
305
- if (!isPlainObject(config)) {
118
+ if (!(0, import_cloudflareWranglerConfig.isPlainObject)(config)) {
306
119
  throw new Error(`Expected ${(0, import_path.relative)(process.cwd(), configPath)} to contain deploy config`);
307
120
  }
308
121
  await import_fs_extra.default.writeFile(configPath, `${JSON.stringify(config, null, 2)}
309
122
  `);
310
123
  }
311
- async function getCloudflareProjectName(root) {
312
- try {
313
- var pkg = JSON.parse(await import_fs_extra.default.readFile((0, import_path.join)(root, "package.json"), "utf-8"));
314
- if (pkg.name) {
315
- return pkg.name.replace(/^@[^/]+\//, "");
316
- }
317
- } catch (unused) {}
318
- return "one-app";
319
- }
320
124
  process.env.ONE_CACHE_KEY = constants.CACHE_KEY;
321
125
  function shouldUseWorkers(oneOptions) {
322
126
  var _oneOptions_build;
@@ -417,7 +221,7 @@ async function build(args) {
417
221
  var deployConfig = normalizeDeploy((_oneOptions_web1 = oneOptions.web) === null || _oneOptions_web1 === void 0 ? void 0 : _oneOptions_web1.deploy);
418
222
  if (!process.env.ONE_SERVER_URL && deployConfig) {
419
223
  var _deployConfig_url;
420
- var url = (_deployConfig_url = deployConfig.url) !== null && _deployConfig_url !== void 0 ? _deployConfig_url : deployConfig.target === "cloudflare" ? `https://${await getCloudflareProjectName(process.cwd())}.workers.dev` : void 0;
224
+ var url = (_deployConfig_url = deployConfig.url) !== null && _deployConfig_url !== void 0 ? _deployConfig_url : deployConfig.target === "cloudflare" ? `https://${await (0, import_cloudflareWranglerConfig.getCloudflareProjectName)(process.cwd())}.workers.dev` : void 0;
421
225
  if (url) {
422
226
  process.env.ONE_SERVER_URL = url;
423
227
  console.info(`
@@ -1566,9 +1370,9 @@ export default {
1566
1370
  }
1567
1371
  `;
1568
1372
  await import_fs_extra.default.writeFile(workerSrcPath, workerCode);
1569
- var projectName = await getCloudflareProjectName(options.root);
1570
- var userWranglerConfig = await loadUserWranglerConfig(options.root);
1571
- var wranglerInputConfig = createCloudflareWranglerConfig(projectName, userWranglerConfig === null || userWranglerConfig === void 0 ? void 0 : userWranglerConfig.config);
1373
+ var projectName = await (0, import_cloudflareWranglerConfig.getCloudflareProjectName)(options.root);
1374
+ var userWranglerConfig = await (0, import_cloudflareWranglerConfig.loadUserWranglerConfig)(options.root);
1375
+ var wranglerInputConfig = (0, import_cloudflareWranglerConfig.createCloudflareWranglerConfig)(projectName, userWranglerConfig === null || userWranglerConfig === void 0 ? void 0 : userWranglerConfig.config);
1572
1376
  wranglerInputConfig.main = (0, import_vite.normalizePath)((0, import_path.relative)((0, import_path.join)(options.root, outDir), workerSrcPath));
1573
1377
  var wranglerInputPath = (0, import_path.join)(options.root, outDir, "_wrangler.input.jsonc");
1574
1378
  await import_fs_extra.default.writeFile(wranglerInputPath, `${JSON.stringify(wranglerInputConfig, null, 2)}