devflare 1.0.0-next.22 → 1.0.0-next.23

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 (114) hide show
  1. package/LLM.md +144 -5
  2. package/dist/account-j8nfggg4.js +475 -0
  3. package/dist/account-qhe8vtds.js +475 -0
  4. package/dist/bridge/miniflare.d.ts +1 -1
  5. package/dist/bridge/miniflare.d.ts.map +1 -1
  6. package/dist/browser.d.ts +13 -13
  7. package/dist/browser.d.ts.map +1 -1
  8. package/dist/browser.js +4 -2
  9. package/dist/build-vy95gy3f.js +54 -0
  10. package/dist/build-yzx0gsaj.js +54 -0
  11. package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
  12. package/dist/cli/commands/config.d.ts.map +1 -1
  13. package/dist/cli/commands/type-generation/generator.d.ts +4 -2
  14. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
  15. package/dist/cli/commands/types.d.ts.map +1 -1
  16. package/dist/cli/index.js +1 -1
  17. package/dist/config/compiler/types.d.ts +1 -1
  18. package/dist/config/compiler/types.d.ts.map +1 -1
  19. package/dist/config/define.d.ts +7 -4
  20. package/dist/config/define.d.ts.map +1 -1
  21. package/dist/config/env-vars.d.ts +309 -0
  22. package/dist/config/env-vars.d.ts.map +1 -0
  23. package/dist/config/index.d.ts +2 -1
  24. package/dist/config/index.d.ts.map +1 -1
  25. package/dist/config/loader.d.ts.map +1 -1
  26. package/dist/config/local-dev-vars.d.ts +2 -2
  27. package/dist/config/local-dev-vars.d.ts.map +1 -1
  28. package/dist/config/schema-env.d.ts +6 -6
  29. package/dist/config/schema-types-bindings-platform.d.ts +378 -0
  30. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  31. package/dist/config/schema-types-bindings-resources.d.ts +551 -0
  32. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  33. package/dist/config/schema-types-bindings.d.ts +254 -0
  34. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  35. package/dist/config/schema-types-build.d.ts +86 -0
  36. package/dist/config/schema-types-build.d.ts.map +1 -0
  37. package/dist/config/schema-types-runtime.d.ts +882 -0
  38. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  39. package/dist/config/schema-types.d.ts +377 -0
  40. package/dist/config/schema-types.d.ts.map +1 -0
  41. package/dist/config/schema.d.ts +14 -15
  42. package/dist/config/schema.d.ts.map +1 -1
  43. package/dist/config-entry.d.ts +2 -0
  44. package/dist/config-entry.d.ts.map +1 -1
  45. package/dist/config-entry.js +3 -1
  46. package/dist/config-gq5jh4cx.js +105 -0
  47. package/dist/config-vec13050.js +105 -0
  48. package/dist/deploy-01j0ep5n.js +1055 -0
  49. package/dist/deploy-tjypkhg7.js +1055 -0
  50. package/dist/dev-bh581ew3.js +2597 -0
  51. package/dist/dev-gn5y93z9.js +2597 -0
  52. package/dist/dev-server/server.d.ts.map +1 -1
  53. package/dist/doctor-h5q28qt1.js +259 -0
  54. package/dist/doctor-khk550tw.js +259 -0
  55. package/dist/env.d.ts +10 -0
  56. package/dist/env.d.ts.map +1 -1
  57. package/dist/index-0bv2qjs1.js +1555 -0
  58. package/dist/index-3tkzn06q.js +413 -0
  59. package/dist/index-8fyz6gcm.js +699 -0
  60. package/dist/index-97z629zr.js +109 -0
  61. package/dist/index-b28c4yr4.js +1205 -0
  62. package/dist/index-c8p4njqy.js +479 -0
  63. package/dist/index-cr06zrgw.js +1033 -0
  64. package/dist/index-cwjjdtgn.js +74 -0
  65. package/dist/index-dref9ecb.js +476 -0
  66. package/dist/index-e151t4ge.js +895 -0
  67. package/dist/index-e7kakw0j.js +1033 -0
  68. package/dist/index-f1g5jdm8.js +1426 -0
  69. package/dist/index-f46984zs.js +1554 -0
  70. package/dist/index-grk8pzhr.js +185 -0
  71. package/dist/index-hzmpecq9.js +52 -0
  72. package/dist/index-j1csb7gb.js +581 -0
  73. package/dist/index-j7x7f72h.js +185 -0
  74. package/dist/index-jkqbjwt2.js +476 -0
  75. package/dist/index-mh5renra.js +895 -0
  76. package/dist/index-p9xq83p7.js +147 -0
  77. package/dist/index-q15nj71j.js +52 -0
  78. package/dist/index-qqp65pyv.js +699 -0
  79. package/dist/index-s0fmwxbk.js +74 -0
  80. package/dist/index-stzx8nc4.js +111 -0
  81. package/dist/index-th4vrnbk.js +1205 -0
  82. package/dist/index-vtcmsgaf.js +581 -0
  83. package/dist/index-x2k3awjs.js +147 -0
  84. package/dist/index-x8x547tz.js +1426 -0
  85. package/dist/index-xxxd0mvw.js +109 -0
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +8 -6
  89. package/dist/login-280p2cm9.js +77 -0
  90. package/dist/login-4n266whq.js +77 -0
  91. package/dist/previews-3m3ffpaw.js +1337 -0
  92. package/dist/previews-tr8sm03d.js +1337 -0
  93. package/dist/productions-62y489ff.js +505 -0
  94. package/dist/productions-cgn3fz7d.js +505 -0
  95. package/dist/runtime/exports.d.ts +23 -0
  96. package/dist/runtime/exports.d.ts.map +1 -1
  97. package/dist/runtime/index.d.ts +1 -1
  98. package/dist/runtime/index.d.ts.map +1 -1
  99. package/dist/runtime/index.js +5 -3
  100. package/dist/secrets-4050kqf5.js +91 -0
  101. package/dist/secrets-p112cajt.js +91 -0
  102. package/dist/sveltekit/index.js +4 -4
  103. package/dist/test/index.js +23 -11
  104. package/dist/test/resolve-service-bindings.d.ts +1 -1
  105. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  106. package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
  107. package/dist/types-apmt10yj.js +705 -0
  108. package/dist/types-ttrrgdfj.js +705 -0
  109. package/dist/vite/index.js +5 -5
  110. package/dist/vite/plugin-context.d.ts.map +1 -1
  111. package/dist/vite/plugin-programmatic.d.ts.map +1 -1
  112. package/dist/worker-2k1jyr6p.js +513 -0
  113. package/dist/worker-jqgn6jyj.js +513 -0
  114. package/package.json +1 -1
@@ -7,17 +7,17 @@ import {
7
7
  resolveEffectiveViteProject,
8
8
  resolveViteUserConfig,
9
9
  writeGeneratedViteConfig
10
- } from "../index-zpy9caxn.js";
11
- import"../index-s9q605sq.js";
10
+ } from "../index-b28c4yr4.js";
11
+ import"../index-e7kakw0j.js";
12
12
  import"../index-3edvz3hs.js";
13
13
  import"../index-qwgr4q7s.js";
14
14
  import"../index-aqrwyy57.js";
15
15
  import"../index-vhqww6tt.js";
16
- import"../index-c3nxftnp.js";
17
- import"../index-syscwrjp.js";
16
+ import"../index-8fyz6gcm.js";
17
+ import"../index-0bv2qjs1.js";
18
18
  import"../index-1d4jg11n.js";
19
19
  import"../index-mg8vwqxf.js";
20
- import"../index-z40mjts9.js";
20
+ import"../index-c8p4njqy.js";
21
21
  import"../index-q8f4kawk.js";
22
22
  import"../index-37x76zdn.js";
23
23
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-context.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-context.ts"],"names":[],"mappings":"AAcA,OAAO,EAON,KAAK,cAAc,EACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAItD,OAAO,EAGN,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,MAAM,0BAA0B,CAAA;AAMjC,MAAM,WAAW,0BAA0B;IAC1C,cAAc,EAAE,cAAc,CAAA;IAC9B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,qBAAqB,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACnD,sBAAsB,EAAE,qBAAqB,EAAE,CAAA;IAC/C,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChD,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC;AAcD;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,MAAM,EACpB,IAAI,GAAE,OAAO,GAAG,OAAiB,EACjC,SAAS,GAAE,MAAoB,GAC7B,OAAO,CAAC,0BAA0B,CAAC,CA+ErC;AAED,wBAAsB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAanF;AAED,wBAAsB,4BAA4B,CACjD,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC5B,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAsB,uBAAuB,CAC5C,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB"}
1
+ {"version":3,"file":"plugin-context.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-context.ts"],"names":[],"mappings":"AAcA,OAAO,EAON,KAAK,cAAc,EACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAItD,OAAO,EAGN,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,MAAM,0BAA0B,CAAA;AAMjC,MAAM,WAAW,0BAA0B;IAC1C,cAAc,EAAE,cAAc,CAAA;IAC9B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,qBAAqB,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACnD,sBAAsB,EAAE,qBAAqB,EAAE,CAAA;IAC/C,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChD,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC;AAcD;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,MAAM,EACpB,IAAI,GAAE,OAAO,GAAG,OAAiB,EACjC,SAAS,GAAE,MAAoB,GAC7B,OAAO,CAAC,0BAA0B,CAAC,CAmFrC;AAED,wBAAsB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAanF;AAED,wBAAsB,4BAA4B,CACjD,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC5B,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAsB,uBAAuB,CAC5C,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-programmatic.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-programmatic.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGN,KAAK,qBAAqB,EAC1B,MAAM,0BAA0B,CAAA;AAIjC,UAAU,yBAAyB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAA;CACpC;AAmFD;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAGlC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,gBAAgB,EAAE,qBAAqB,EAAE,CAAA;CACzC,CAAC,CAGD"}
1
+ {"version":3,"file":"plugin-programmatic.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-programmatic.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGN,KAAK,qBAAqB,EAC1B,MAAM,0BAA0B,CAAA;AAIjC,UAAU,yBAAyB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAA;CACpC;AAwFD;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAGlC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,GAAE,yBAA8B,GACrC,OAAO,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,gBAAgB,EAAE,qBAAqB,EAAE,CAAA;CACzC,CAAC,CAGD"}
@@ -0,0 +1,513 @@
1
+ import {
2
+ findConfigPathsUnderDirectory,
3
+ formatSupportedConfigFilenames,
4
+ resolveConfigCandidatePath
5
+ } from "./index-hzmpecq9.js";
6
+ import {
7
+ asOptionalString,
8
+ resolveCloudflareAccountId
9
+ } from "./index-s0fmwxbk.js";
10
+ import {
11
+ account
12
+ } from "./index-0m6e4mxz.js";
13
+ import"./index-k7m5f1dg.js";
14
+ import"./index-3jme4hgw.js";
15
+ import {
16
+ bold,
17
+ createCliTheme,
18
+ dim,
19
+ green,
20
+ logLine,
21
+ whiteDim,
22
+ yellow
23
+ } from "./index-stgn34cr.js";
24
+ import"./index-3t6rypgc.js";
25
+ import"./index-15fpa5tx.js";
26
+ import"./index-qwgr4q7s.js";
27
+ import"./index-8fyz6gcm.js";
28
+ import {
29
+ loadConfig,
30
+ normalizeDOBinding
31
+ } from "./index-0bv2qjs1.js";
32
+ import"./index-1d4jg11n.js";
33
+ import"./index-mg8vwqxf.js";
34
+ import"./index-c8p4njqy.js";
35
+ import"./index-q8f4kawk.js";
36
+ import {
37
+ __require
38
+ } from "./index-37x76zdn.js";
39
+
40
+ // src/cli/commands/worker.ts
41
+ import MagicString from "magic-string";
42
+ import { basename, dirname, relative, resolve } from "pathe";
43
+ function formatPathForLog(cwd, filePath) {
44
+ const relativePath = relative(cwd, filePath).replace(/\\/g, "/");
45
+ return relativePath && !relativePath.startsWith("..") ? relativePath : filePath;
46
+ }
47
+ async function loadConfigFromPath(configPath) {
48
+ return {
49
+ configPath,
50
+ config: await loadConfig({
51
+ cwd: dirname(configPath),
52
+ configFile: basename(configPath)
53
+ })
54
+ };
55
+ }
56
+ async function loadDiscoveredConfigs(cwd, explicitConfigPath) {
57
+ const candidatePaths = new Set;
58
+ const discoveredPaths = await findConfigPathsUnderDirectory(cwd);
59
+ for (const configPath of discoveredPaths) {
60
+ candidatePaths.add(configPath);
61
+ }
62
+ if (explicitConfigPath) {
63
+ candidatePaths.add(explicitConfigPath);
64
+ }
65
+ const loadedConfigs = [];
66
+ for (const configPath of [...candidatePaths].sort((left, right) => left.localeCompare(right))) {
67
+ try {
68
+ loadedConfigs.push(await loadConfigFromPath(configPath));
69
+ } catch (error) {
70
+ if (explicitConfigPath && explicitConfigPath === configPath) {
71
+ throw error;
72
+ }
73
+ }
74
+ }
75
+ return loadedConfigs;
76
+ }
77
+ function formatConfigChoices(matches, cwd) {
78
+ return matches.map((match) => ` - ${formatPathForLog(cwd, match.configPath)} (${match.config.name})`).join(`
79
+ `);
80
+ }
81
+ function selectTargetConfig(loadedConfigs, cwd, oldName, newName, explicitConfigPath) {
82
+ if (loadedConfigs.length === 0) {
83
+ throw new Error(`Could not find ${formatSupportedConfigFilenames()} under ${cwd}.`);
84
+ }
85
+ if (explicitConfigPath) {
86
+ const target = loadedConfigs.find((candidate) => candidate.configPath === explicitConfigPath);
87
+ if (!target) {
88
+ throw new Error(`Could not load the selected config: ${explicitConfigPath}`);
89
+ }
90
+ if (target.config.name === oldName) {
91
+ return {
92
+ target,
93
+ localConfigAlreadyUpdated: false,
94
+ allConfigs: loadedConfigs
95
+ };
96
+ }
97
+ if (target.config.name === newName) {
98
+ return {
99
+ target,
100
+ localConfigAlreadyUpdated: true,
101
+ allConfigs: loadedConfigs
102
+ };
103
+ }
104
+ throw new Error(`The selected config uses \`${target.config.name}\`, not \`${oldName}\` or \`${newName}\`.`);
105
+ }
106
+ const matchingConfigs = loadedConfigs.filter((candidate) => {
107
+ return candidate.config.name === oldName || candidate.config.name === newName;
108
+ });
109
+ const oldMatches = matchingConfigs.filter((candidate) => candidate.config.name === oldName);
110
+ const newMatches = matchingConfigs.filter((candidate) => candidate.config.name === newName);
111
+ if (oldMatches.length === 1 && matchingConfigs.length === 1) {
112
+ return {
113
+ target: oldMatches[0],
114
+ localConfigAlreadyUpdated: false,
115
+ allConfigs: loadedConfigs
116
+ };
117
+ }
118
+ if (newMatches.length === 1 && matchingConfigs.length === 1) {
119
+ return {
120
+ target: newMatches[0],
121
+ localConfigAlreadyUpdated: true,
122
+ allConfigs: loadedConfigs
123
+ };
124
+ }
125
+ if (matchingConfigs.length === 0) {
126
+ throw new Error(`Could not find a matching devflare config under ${cwd}. Expected a config whose \`name\` is \`${oldName}\` or \`${newName}\`.`);
127
+ }
128
+ throw new Error(`Multiple matching devflare configs were found. Use --config to pick one explicitly.
129
+ ${formatConfigChoices(matchingConfigs, cwd)}`);
130
+ }
131
+ async function resolveAccountId(parsed, config) {
132
+ return resolveCloudflareAccountId({
133
+ explicitAccountId: asOptionalString(parsed.options.account),
134
+ configuredAccountId: config.accountId
135
+ });
136
+ }
137
+ function skipWhitespaceAndComments(source, start, end) {
138
+ let index = start;
139
+ while (index < end) {
140
+ const char = source[index];
141
+ if (/\s/.test(char)) {
142
+ index++;
143
+ continue;
144
+ }
145
+ const nextIndex = consumeComment(source, index, end);
146
+ if (nextIndex !== null) {
147
+ index = nextIndex;
148
+ continue;
149
+ }
150
+ break;
151
+ }
152
+ return index;
153
+ }
154
+ function consumeQuotedLiteral(source, start, end) {
155
+ const quote = source[start];
156
+ let index = start + 1;
157
+ while (index < end) {
158
+ const char = source[index];
159
+ if (char === "\\") {
160
+ index += 2;
161
+ continue;
162
+ }
163
+ if (char === quote) {
164
+ return index + 1;
165
+ }
166
+ index++;
167
+ }
168
+ throw new Error("Unterminated string literal in devflare config.");
169
+ }
170
+ function consumeComment(source, start, end) {
171
+ if (source[start] !== "/") {
172
+ return null;
173
+ }
174
+ if (source[start + 1] === "/") {
175
+ let index = start + 2;
176
+ while (index < end && source[index] !== `
177
+ `) {
178
+ index++;
179
+ }
180
+ return index;
181
+ }
182
+ if (source[start + 1] === "*") {
183
+ let index = start + 2;
184
+ while (index < end && !(source[index] === "*" && source[index + 1] === "/")) {
185
+ index++;
186
+ }
187
+ return Math.min(index + 2, end);
188
+ }
189
+ return null;
190
+ }
191
+ function findConfigObjectStart(source) {
192
+ const defineConfigIndex = source.indexOf("defineConfig");
193
+ if (defineConfigIndex >= 0) {
194
+ const parenIndex = source.indexOf("(", defineConfigIndex);
195
+ if (parenIndex >= 0) {
196
+ const objectIndex = source.indexOf("{", parenIndex);
197
+ if (objectIndex >= 0) {
198
+ return objectIndex;
199
+ }
200
+ }
201
+ }
202
+ const exportDefaultIndex = source.indexOf("export default");
203
+ if (exportDefaultIndex >= 0) {
204
+ const objectIndex = source.indexOf("{", exportDefaultIndex);
205
+ if (objectIndex >= 0) {
206
+ return objectIndex;
207
+ }
208
+ }
209
+ return -1;
210
+ }
211
+ function getRootPropertySlices(source, objectStart) {
212
+ const slices = [];
213
+ let curlyDepth = 1;
214
+ let squareDepth = 0;
215
+ let parenDepth = 0;
216
+ let propertyStart = objectStart + 1;
217
+ let index = objectStart + 1;
218
+ while (index < source.length) {
219
+ const char = source[index];
220
+ if (char === "'" || char === '"' || char === "`") {
221
+ index = consumeQuotedLiteral(source, index, source.length);
222
+ continue;
223
+ }
224
+ const nextIndex = consumeComment(source, index, source.length);
225
+ if (nextIndex !== null) {
226
+ index = nextIndex;
227
+ continue;
228
+ }
229
+ if (char === "{") {
230
+ curlyDepth++;
231
+ index++;
232
+ continue;
233
+ }
234
+ if (char === "}") {
235
+ curlyDepth--;
236
+ if (curlyDepth === 0) {
237
+ slices.push({ start: propertyStart, end: index });
238
+ return slices;
239
+ }
240
+ index++;
241
+ continue;
242
+ }
243
+ if (char === "[") {
244
+ squareDepth++;
245
+ index++;
246
+ continue;
247
+ }
248
+ if (char === "]") {
249
+ squareDepth--;
250
+ index++;
251
+ continue;
252
+ }
253
+ if (char === "(") {
254
+ parenDepth++;
255
+ index++;
256
+ continue;
257
+ }
258
+ if (char === ")") {
259
+ parenDepth--;
260
+ index++;
261
+ continue;
262
+ }
263
+ if (char === "," && curlyDepth === 1 && squareDepth === 0 && parenDepth === 0) {
264
+ slices.push({ start: propertyStart, end: index });
265
+ propertyStart = index + 1;
266
+ }
267
+ index++;
268
+ }
269
+ throw new Error("Could not parse the root object in devflare config.");
270
+ }
271
+ function findTopLevelColon(source, start, end) {
272
+ let curlyDepth = 0;
273
+ let squareDepth = 0;
274
+ let parenDepth = 0;
275
+ let index = start;
276
+ while (index < end) {
277
+ const char = source[index];
278
+ if (char === "'" || char === '"' || char === "`") {
279
+ index = consumeQuotedLiteral(source, index, end);
280
+ continue;
281
+ }
282
+ const nextIndex = consumeComment(source, index, end);
283
+ if (nextIndex !== null) {
284
+ index = nextIndex;
285
+ continue;
286
+ }
287
+ if (char === "{") {
288
+ curlyDepth++;
289
+ index++;
290
+ continue;
291
+ }
292
+ if (char === "}") {
293
+ curlyDepth--;
294
+ index++;
295
+ continue;
296
+ }
297
+ if (char === "[") {
298
+ squareDepth++;
299
+ index++;
300
+ continue;
301
+ }
302
+ if (char === "]") {
303
+ squareDepth--;
304
+ index++;
305
+ continue;
306
+ }
307
+ if (char === "(") {
308
+ parenDepth++;
309
+ index++;
310
+ continue;
311
+ }
312
+ if (char === ")") {
313
+ parenDepth--;
314
+ index++;
315
+ continue;
316
+ }
317
+ if (char === ":" && curlyDepth === 0 && squareDepth === 0 && parenDepth === 0) {
318
+ return index;
319
+ }
320
+ index++;
321
+ }
322
+ return -1;
323
+ }
324
+ function normalizePropertyKey(rawKey) {
325
+ const trimmed = rawKey.trim();
326
+ if (trimmed.startsWith("'") && trimmed.endsWith("'") || trimmed.startsWith('"') && trimmed.endsWith('"')) {
327
+ return trimmed.slice(1, -1);
328
+ }
329
+ return trimmed;
330
+ }
331
+ function findRootNameLiteralRange(source) {
332
+ const objectStart = findConfigObjectStart(source);
333
+ if (objectStart < 0) {
334
+ return null;
335
+ }
336
+ for (const slice of getRootPropertySlices(source, objectStart)) {
337
+ const keyStart = skipWhitespaceAndComments(source, slice.start, slice.end);
338
+ const colonIndex = findTopLevelColon(source, keyStart, slice.end);
339
+ if (colonIndex < 0) {
340
+ continue;
341
+ }
342
+ const key = normalizePropertyKey(source.slice(keyStart, colonIndex));
343
+ if (key !== "name") {
344
+ continue;
345
+ }
346
+ const valueStart = skipWhitespaceAndComments(source, colonIndex + 1, slice.end);
347
+ const quote = source[valueStart];
348
+ if (quote !== "'" && quote !== '"') {
349
+ throw new Error("The top-level `name` property must be a string literal to be updated automatically.");
350
+ }
351
+ return {
352
+ start: valueStart,
353
+ end: consumeQuotedLiteral(source, valueStart, slice.end),
354
+ quote
355
+ };
356
+ }
357
+ return null;
358
+ }
359
+ function quoteWorkerName(value, quote) {
360
+ const escapedValue = value.replace(/\\/g, "\\\\").replace(new RegExp(`\\${quote}`, "g"), `\\${quote}`);
361
+ return `${quote}${escapedValue}${quote}`;
362
+ }
363
+ async function updateConfigName(configPath, newName) {
364
+ const fs = await import("node:fs/promises");
365
+ const source = await fs.readFile(configPath, "utf-8");
366
+ const literalRange = findRootNameLiteralRange(source);
367
+ if (!literalRange) {
368
+ throw new Error("Could not locate a top-level string literal `name` property in the selected devflare config.");
369
+ }
370
+ const magicString = new MagicString(source);
371
+ magicString.overwrite(literalRange.start, literalRange.end, quoteWorkerName(newName, literalRange.quote));
372
+ await fs.writeFile(configPath, magicString.toString(), "utf-8");
373
+ }
374
+ function collectReferenceHitsFromConfig(configPath, configLike, oldName, scope) {
375
+ if (!configLike?.bindings) {
376
+ return [];
377
+ }
378
+ const hits = [];
379
+ for (const [bindingName, bindingConfig] of Object.entries(configLike.bindings.services ?? {})) {
380
+ if (bindingConfig.service === oldName) {
381
+ hits.push({
382
+ configPath,
383
+ scope,
384
+ kind: "service",
385
+ bindingName
386
+ });
387
+ }
388
+ }
389
+ for (const [bindingName, bindingConfig] of Object.entries(configLike.bindings.durableObjects ?? {})) {
390
+ const normalized = normalizeDOBinding(bindingConfig);
391
+ if (normalized.scriptName === oldName) {
392
+ hits.push({
393
+ configPath,
394
+ scope,
395
+ kind: "durable-object",
396
+ bindingName
397
+ });
398
+ }
399
+ }
400
+ return hits;
401
+ }
402
+ function collectReferenceHits(loadedConfigs, oldName) {
403
+ const hits = [];
404
+ for (const record of loadedConfigs) {
405
+ hits.push(...collectReferenceHitsFromConfig(record.configPath, record.config, oldName, "root"));
406
+ for (const [envName, envConfig] of Object.entries(record.config.env ?? {})) {
407
+ hits.push(...collectReferenceHitsFromConfig(record.configPath, envConfig, oldName, `env.${envName}`));
408
+ }
409
+ }
410
+ return hits;
411
+ }
412
+ async function runWorkerCommand(parsed, logger, options) {
413
+ const cwd = options.cwd ?? process.cwd();
414
+ const theme = createCliTheme(parsed.options);
415
+ const subcommand = parsed.args[0];
416
+ const oldName = parsed.args[1]?.trim();
417
+ const newName = asOptionalString(parsed.options.to);
418
+ const explicitConfigPath = asOptionalString(parsed.options.config);
419
+ if (subcommand !== "rename") {
420
+ logger.error(`Unknown worker subcommand: ${subcommand ?? "<none>"}`);
421
+ logLine(logger, dim("Usage: devflare worker rename <old-name> --to <new-name> [--config <path>]", theme));
422
+ return { exitCode: 1 };
423
+ }
424
+ if (!oldName) {
425
+ logger.error("A current Worker name is required.");
426
+ logLine(logger, dim("Usage: devflare worker rename <old-name> --to <new-name> [--config <path>]", theme));
427
+ return { exitCode: 1 };
428
+ }
429
+ if (!newName) {
430
+ logger.error("The new Worker name must be provided with --to.");
431
+ return { exitCode: 1 };
432
+ }
433
+ if (oldName === newName) {
434
+ logger.error("The new Worker name must be different from the current name.");
435
+ return { exitCode: 1 };
436
+ }
437
+ logLine(logger);
438
+ logLine(logger, `${yellow("worker", theme)} ${dim("Renaming Worker identity", theme)}`);
439
+ logLine(logger, `${dim("from", theme)} ${whiteDim(oldName, theme)}`);
440
+ logLine(logger, `${dim("to", theme)} ${green(newName, theme)}`);
441
+ if (!await account.isAuthenticated()) {
442
+ logger.error("Not authenticated with Cloudflare");
443
+ logLine(logger, dim("Run `devflare login` first.", theme));
444
+ return { exitCode: 1 };
445
+ }
446
+ let remoteRenamed = false;
447
+ try {
448
+ const explicitResolvedConfigPath = explicitConfigPath ? await resolveConfigCandidatePath(resolve(cwd, explicitConfigPath)) : null;
449
+ if (explicitConfigPath && !explicitResolvedConfigPath) {
450
+ throw new Error(`${formatSupportedConfigFilenames()} not found for --config ${explicitConfigPath}.`);
451
+ }
452
+ const selection = selectTargetConfig(await loadDiscoveredConfigs(cwd, explicitResolvedConfigPath ?? undefined), cwd, oldName, newName, explicitResolvedConfigPath ?? undefined);
453
+ const { target, localConfigAlreadyUpdated, allConfigs } = selection;
454
+ const accountId = await resolveAccountId(parsed, target.config);
455
+ if (!accountId) {
456
+ logger.error("No Cloudflare account could be resolved for this config.");
457
+ logLine(logger, dim("Set accountId in devflare.config.ts, pass --account, or configure a default account.", theme));
458
+ return { exitCode: 1 };
459
+ }
460
+ logLine(logger, `${dim("config", theme)} ${whiteDim(formatPathForLog(cwd, target.configPath), theme)}`);
461
+ logLine(logger, `${dim("account", theme)} ${whiteDim(accountId, theme)}`);
462
+ logLine(logger);
463
+ const workers = await account.workers(accountId);
464
+ const hasOldWorker = workers.some((worker) => worker.name === oldName);
465
+ const hasNewWorker = workers.some((worker) => worker.name === newName);
466
+ if (hasOldWorker && hasNewWorker) {
467
+ logger.error(`Both \`${oldName}\` and \`${newName}\` already exist in Cloudflare.`);
468
+ logLine(logger, dim("Refusing to rename because the target Worker name is already taken.", theme));
469
+ return { exitCode: 1 };
470
+ }
471
+ if (!hasOldWorker && !hasNewWorker) {
472
+ logger.error(`Neither \`${oldName}\` nor \`${newName}\` exists in Cloudflare for account ${accountId}.`);
473
+ return { exitCode: 1 };
474
+ }
475
+ if (hasOldWorker && !hasNewWorker) {
476
+ await account.renameWorker(accountId, oldName, newName);
477
+ remoteRenamed = true;
478
+ logger.success(`Renamed remote Worker ${oldName} → ${newName}`);
479
+ } else {
480
+ logLine(logger, `${dim("remote", theme)} ${green(newName, theme)} ${dim("is already the active Worker name in Cloudflare", theme)}`);
481
+ }
482
+ if (!localConfigAlreadyUpdated) {
483
+ await updateConfigName(target.configPath, newName);
484
+ logger.success(`Updated ${formatPathForLog(cwd, target.configPath)}`);
485
+ } else {
486
+ logLine(logger, `${dim("config", theme)} ${green("already updated locally", theme)}`);
487
+ }
488
+ const referenceHits = collectReferenceHits(allConfigs, oldName);
489
+ if (referenceHits.length > 0) {
490
+ logger.warn(`Found ${referenceHits.length} local reference(s) that still use \`${oldName}\`.`);
491
+ for (const hit of referenceHits) {
492
+ logLine(logger, ` ${formatPathForLog(cwd, hit.configPath)} ${dim(`(${hit.scope})`, theme)} ${dim("—", theme)} ${hit.kind === "service" ? "service binding" : "durable object binding"} ${bold(hit.bindingName, theme)}`);
493
+ }
494
+ }
495
+ logLine(logger);
496
+ logLine(logger, `${yellow("preview urls", theme)} ${dim("Existing preview URLs and registry entries may continue using the old Worker name until you upload fresh previews for the renamed Worker.", theme)}`);
497
+ logLine(logger, dim("Future deploys and preview uploads from this config will target the new Worker name.", theme));
498
+ return { exitCode: 0 };
499
+ } catch (error) {
500
+ if (remoteRenamed) {
501
+ logger.warn("The remote Worker rename succeeded, but the local config update did not complete.");
502
+ logLine(logger, dim("Update devflare.config.ts manually so future deploys target the renamed Worker.", theme));
503
+ }
504
+ if (error instanceof Error) {
505
+ logger.error(error.message);
506
+ return { exitCode: 1 };
507
+ }
508
+ throw error;
509
+ }
510
+ }
511
+ export {
512
+ runWorkerCommand
513
+ };