@kodycodes/cli 3.45.0 → 3.45.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{auth-KYEYWPJC.js → auth-L5NDLZUF.js} +4 -5
- package/dist/bin.js +5 -6
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-DD2JGPDQ.js → chunk-2RRDYVW3.js} +5 -7
- package/dist/chunk-2RRDYVW3.js.map +6 -0
- package/dist/{chunk-YS6Z7JVP.js → chunk-CBFPAQOZ.js} +4 -6
- package/dist/chunk-CBFPAQOZ.js.map +6 -0
- package/dist/{chunk-YCJTZL7G.js → chunk-DUS7SBZT.js} +41 -43
- package/dist/chunk-DUS7SBZT.js.map +6 -0
- package/dist/{chunk-LXYTANRJ.js → chunk-FZ67GC66.js} +46 -14
- package/dist/chunk-FZ67GC66.js.map +6 -0
- package/dist/{chunk-EHGFMAHV.js → chunk-GGHTMLFJ.js} +2 -2
- package/dist/{chunk-5XG7DKFK.js → chunk-HVFE4XCI.js} +2 -2
- package/dist/{chunk-V7EVS6AD.js → chunk-L6VBRGS6.js} +14 -4
- package/dist/chunk-L6VBRGS6.js.map +6 -0
- package/dist/{chunk-66BF6YCZ.js → chunk-M6JCNIX6.js} +3 -3
- package/dist/chunk-TB7NX637.js +868 -0
- package/dist/chunk-TB7NX637.js.map +6 -0
- package/dist/{chunk-4J5XVKTW.js → chunk-TIN6KMVQ.js} +5 -7
- package/dist/chunk-TIN6KMVQ.js.map +6 -0
- package/dist/{chunk-ELBWKUTY.js → chunk-UC2OBYKG.js} +22 -7
- package/dist/chunk-UC2OBYKG.js.map +6 -0
- package/dist/{chunk-2DIHJVLK.js → chunk-Z5EBUX3U.js} +6 -6
- package/dist/cli.js +5 -6
- package/dist/{commands-BU3XAQUF.js → commands-BMIGLU7X.js} +2 -2
- package/dist/dev/dev-watcher.d.ts +5 -0
- package/dist/{dev-command-RP4IY5TL.js → dev-command-TEJPQEPO.js} +142 -761
- package/dist/dev-command-TEJPQEPO.js.map +6 -0
- package/dist/fetch-body-package-scan.d.ts +1 -0
- package/dist/{git-credential-GFUWDRRV.js → git-credential-6MV6GGR5.js} +5 -6
- package/dist/git-credential-6MV6GGR5.js.map +6 -0
- package/dist/{local-execute-XO65HZAX.js → local-execute-TL2JIRBK.js} +4 -5
- package/dist/local-execute-TL2JIRBK.js.map +6 -0
- package/dist/{local-kody-RYKBNHAP.js → local-kody-UP6W2YSF.js} +128 -29
- package/dist/local-kody-UP6W2YSF.js.map +6 -0
- package/dist/{local-package-graph-JSWSRB3S.js → local-package-graph-VN53AG4I.js} +3 -4
- package/dist/{local-package-run-QCKYALIQ.js → local-package-run-BXFC2HQE.js} +7 -8
- package/dist/{local-secrets-563FQE2A.js → local-secrets-WUAERJHG.js} +3 -4
- package/dist/local-secrets-WUAERJHG.js.map +6 -0
- package/dist/{mock-dep-resolve-7FJ6P6PE.js → mock-dep-resolve-EMFQ6ANZ.js} +2 -2
- package/dist/{mock-local-deps-KTMRYDRZ.js → mock-local-deps-2G5NX4MR.js} +8 -5
- package/dist/mock-local-deps.d.ts +18 -0
- package/dist/{mock-server-KTBYHEPH.js → mock-server-NM6XOOS3.js} +2 -2
- package/dist/{open-api-client-ITRRSEXW.js → open-api-client-QI5I3NFE.js} +3 -4
- package/dist/package-app-dev.d.ts +6 -1
- package/dist/publish-builder.js +101 -15
- package/dist/{remote-execute-CLWEHTAF.js → remote-execute-K5T677LE.js} +3 -4
- package/dist/remote-execute-K5T677LE.js.map +6 -0
- package/dist/{run-executor-3UIWBJGZ.js → run-executor-WN6W7JKN.js} +2 -2
- package/dist/{setup-git-IWA34U2C.js → setup-git-Q3TZZEGS.js} +4 -5
- package/dist/{whoami-G42DDVJW.js → whoami-WZNTBYDS.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-3IYBIEX6.js +0 -225
- package/dist/chunk-3IYBIEX6.js.map +0 -6
- package/dist/chunk-4J5XVKTW.js.map +0 -6
- package/dist/chunk-DD2JGPDQ.js.map +0 -6
- package/dist/chunk-ELBWKUTY.js.map +0 -6
- package/dist/chunk-G6LJWROP.js +0 -18
- package/dist/chunk-G6LJWROP.js.map +0 -6
- package/dist/chunk-LXYTANRJ.js.map +0 -6
- package/dist/chunk-V7EVS6AD.js.map +0 -6
- package/dist/chunk-YCJTZL7G.js.map +0 -6
- package/dist/chunk-YS6Z7JVP.js.map +0 -6
- package/dist/dev-command-RP4IY5TL.js.map +0 -6
- package/dist/git-credential-GFUWDRRV.js.map +0 -6
- package/dist/local-execute-XO65HZAX.js.map +0 -6
- package/dist/local-kody-RYKBNHAP.js.map +0 -6
- package/dist/local-secrets-563FQE2A.js.map +0 -6
- package/dist/remote-execute-CLWEHTAF.js.map +0 -6
- /package/dist/{auth-KYEYWPJC.js.map → auth-L5NDLZUF.js.map} +0 -0
- /package/dist/{chunk-EHGFMAHV.js.map → chunk-GGHTMLFJ.js.map} +0 -0
- /package/dist/{chunk-5XG7DKFK.js.map → chunk-HVFE4XCI.js.map} +0 -0
- /package/dist/{chunk-66BF6YCZ.js.map → chunk-M6JCNIX6.js.map} +0 -0
- /package/dist/{chunk-2DIHJVLK.js.map → chunk-Z5EBUX3U.js.map} +0 -0
- /package/dist/{commands-BU3XAQUF.js.map → commands-BMIGLU7X.js.map} +0 -0
- /package/dist/{local-package-graph-JSWSRB3S.js.map → local-package-graph-VN53AG4I.js.map} +0 -0
- /package/dist/{local-package-run-QCKYALIQ.js.map → local-package-run-BXFC2HQE.js.map} +0 -0
- /package/dist/{mock-dep-resolve-7FJ6P6PE.js.map → mock-dep-resolve-EMFQ6ANZ.js.map} +0 -0
- /package/dist/{mock-local-deps-KTMRYDRZ.js.map → mock-local-deps-2G5NX4MR.js.map} +0 -0
- /package/dist/{mock-server-KTBYHEPH.js.map → mock-server-NM6XOOS3.js.map} +0 -0
- /package/dist/{open-api-client-ITRRSEXW.js.map → open-api-client-QI5I3NFE.js.map} +0 -0
- /package/dist/{run-executor-3UIWBJGZ.js.map → run-executor-WN6W7JKN.js.map} +0 -0
- /package/dist/{setup-git-IWA34U2C.js.map → setup-git-Q3TZZEGS.js.map} +0 -0
- /package/dist/{whoami-G42DDVJW.js.map → whoami-WZNTBYDS.js.map} +0 -0
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
resolveLocalPackageBinding,
|
|
13
13
|
runLocalPackageModule,
|
|
14
14
|
trustedDevHostFromHostedUrl
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-Z5EBUX3U.js";
|
|
16
16
|
import {
|
|
17
17
|
assertDevHostAllowed,
|
|
18
18
|
defaultDevHost,
|
|
@@ -23,11 +23,13 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
collectPackageCheckFiles,
|
|
25
25
|
devPackageAppOrigin,
|
|
26
|
+
findPackageFetchBodyWarnings,
|
|
27
|
+
formatFetchBodySecretResolutionWarning,
|
|
26
28
|
formatUnpublishedBundleInputMessage,
|
|
27
29
|
listPackageCheckPaths,
|
|
28
30
|
localUsernameFor,
|
|
29
31
|
unpublishedBundleInputPaths
|
|
30
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-TB7NX637.js";
|
|
31
33
|
import {
|
|
32
34
|
publishOutsideCloudAdvice
|
|
33
35
|
} from "./chunk-XQY2VX3O.js";
|
|
@@ -36,10 +38,10 @@ import {
|
|
|
36
38
|
forwardLocalGatewayFetchStream,
|
|
37
39
|
installMockFetchShimModules,
|
|
38
40
|
startLocalRuntimeBridge
|
|
39
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-M6JCNIX6.js";
|
|
40
42
|
import {
|
|
41
43
|
ensureMockTarget
|
|
42
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-UC2OBYKG.js";
|
|
43
45
|
import {
|
|
44
46
|
packageMocksRelativePath,
|
|
45
47
|
resolveMockFetchGateway,
|
|
@@ -50,7 +52,7 @@ import {
|
|
|
50
52
|
cleanWorkerdStderrLine,
|
|
51
53
|
startWorkerd
|
|
52
54
|
} from "./chunk-PPVTGF73.js";
|
|
53
|
-
import "./chunk-
|
|
55
|
+
import "./chunk-FZ67GC66.js";
|
|
54
56
|
import {
|
|
55
57
|
BundleError,
|
|
56
58
|
bundleInputs,
|
|
@@ -69,7 +71,7 @@ import {
|
|
|
69
71
|
resolveLocalPackageGraph,
|
|
70
72
|
runSecretEnvVar,
|
|
71
73
|
writePackageModuleFiles
|
|
72
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-2RRDYVW3.js";
|
|
73
75
|
import "./chunk-2PCUYOMX.js";
|
|
74
76
|
import {
|
|
75
77
|
loadPackageManifest,
|
|
@@ -85,13 +87,12 @@ import {
|
|
|
85
87
|
import {
|
|
86
88
|
redact
|
|
87
89
|
} from "./chunk-CASGRYOF.js";
|
|
88
|
-
import "./chunk-
|
|
90
|
+
import "./chunk-CBFPAQOZ.js";
|
|
89
91
|
import {
|
|
90
92
|
assertTokenSafeApiUrl,
|
|
91
93
|
callCapabilityProxy
|
|
92
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-L6VBRGS6.js";
|
|
93
95
|
import "./chunk-F6N7JCMD.js";
|
|
94
|
-
import "./chunk-G6LJWROP.js";
|
|
95
96
|
import "./chunk-6JQXFR73.js";
|
|
96
97
|
import "./chunk-AM2SBW3C.js";
|
|
97
98
|
import "./chunk-N33Y3A4H.js";
|
|
@@ -106,8 +107,8 @@ import "./chunk-YVWOK4LV.js";
|
|
|
106
107
|
import "./chunk-UW6AWLXX.js";
|
|
107
108
|
|
|
108
109
|
// src/dev-command.ts
|
|
109
|
-
import { access, mkdir as mkdir3, readFile as
|
|
110
|
-
import { dirname as
|
|
110
|
+
import { access, mkdir as mkdir3, readFile as readFile4, rm as rm4, writeFile as writeFile4 } from "node:fs/promises";
|
|
111
|
+
import { dirname as dirname3, join as join8, resolve as resolve7 } from "node:path";
|
|
111
112
|
|
|
112
113
|
// src/credentialed-fetch-scan.ts
|
|
113
114
|
var esModuleLexerReady = init();
|
|
@@ -179,642 +180,6 @@ function mocksSuggestionDetail(input) {
|
|
|
179
180
|
return `suggested \u2014 package uses credentialed fetch (${kinds}); add .kody/mocks.ts so --target mock can MSW-match outbound requests (unmocked credentialed hops fail closed)`;
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
// src/fetch-body-secret-resolution.ts
|
|
183
|
-
var fetchBodySecretResolutionWarningLead = 'WARNING: a fetch sends a body without x-kody-secret-resolution. The gateway fills {{secret:name}} anywhere in that body, so text this package did not write can fail with Secret "name" was not found, or a saved secret can be sent to a host the credential allows. Set x-kody-secret-resolution: headers-only on that fetch (headers still resolve). This does not block publish.';
|
|
184
|
-
var secretResolutionHeaderName = "x-kody-secret-resolution";
|
|
185
|
-
var maxWarningSites = 8;
|
|
186
|
-
function findFetchBodiesMissingSecretResolution(source) {
|
|
187
|
-
const hits = [];
|
|
188
|
-
for (const call of findFetchLikeCalls(source)) {
|
|
189
|
-
if (callSendsUnresolvedDynamicBody(call.args)) {
|
|
190
|
-
hits.push({ line: lineAt(source, call.index) });
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return hits;
|
|
194
|
-
}
|
|
195
|
-
function formatFetchBodySecretResolutionWarning(hits) {
|
|
196
|
-
if (hits.length === 0) return null;
|
|
197
|
-
const ordered = [...hits].sort((left, right) => {
|
|
198
|
-
const byPath = left.path.localeCompare(right.path);
|
|
199
|
-
return byPath === 0 ? left.line - right.line : byPath;
|
|
200
|
-
});
|
|
201
|
-
const shown = ordered.slice(0, maxWarningSites);
|
|
202
|
-
const extra = ordered.length - shown.length;
|
|
203
|
-
return [
|
|
204
|
-
fetchBodySecretResolutionWarningLead,
|
|
205
|
-
...shown.map((hit) => `- ${hit.path}:${hit.line}`),
|
|
206
|
-
...extra > 0 ? [`- ${extra} more`] : []
|
|
207
|
-
].join("\n");
|
|
208
|
-
}
|
|
209
|
-
function findFetchLikeCalls(source) {
|
|
210
|
-
const calls = [];
|
|
211
|
-
scanCode(source, 0, "eof", calls);
|
|
212
|
-
return calls;
|
|
213
|
-
}
|
|
214
|
-
function scanCode(source, start, stop, calls) {
|
|
215
|
-
let index = start;
|
|
216
|
-
let lastWord = "";
|
|
217
|
-
let braceDepth = 0;
|
|
218
|
-
while (index < source.length) {
|
|
219
|
-
const char = source[index];
|
|
220
|
-
if (isWhitespace(char)) {
|
|
221
|
-
index += 1;
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
225
|
-
index = skipLineComment(source, index);
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
229
|
-
index = skipBlockComment(source, index);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (char === "'" || char === '"') {
|
|
233
|
-
index = skipQuotedString(source, index);
|
|
234
|
-
lastWord = "";
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (char === "`") {
|
|
238
|
-
index = skipTemplate(source, index, calls);
|
|
239
|
-
lastWord = "";
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (isIdentStart(char)) {
|
|
243
|
-
const wordStart = index;
|
|
244
|
-
index += 1;
|
|
245
|
-
while (index < source.length && isIdentPart(source[index])) index += 1;
|
|
246
|
-
const word = source.slice(wordStart, index);
|
|
247
|
-
const openParen = skipWhitespaceAndComments(source, index);
|
|
248
|
-
const isFetch = word === "fetch" && lastWord !== "function" && lastWord !== "async";
|
|
249
|
-
const isRequest = word === "Request" && lastWord === "new";
|
|
250
|
-
if ((isFetch || isRequest) && source[openParen] === "(") {
|
|
251
|
-
const call = readCallArguments(source, openParen);
|
|
252
|
-
if (call) calls.push({ index: wordStart, args: call.args });
|
|
253
|
-
}
|
|
254
|
-
lastWord = word;
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (char === "{") {
|
|
258
|
-
braceDepth += 1;
|
|
259
|
-
lastWord = "";
|
|
260
|
-
index += 1;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
if (char === "}") {
|
|
264
|
-
if (stop === "brace" && braceDepth === 0) return index + 1;
|
|
265
|
-
braceDepth -= 1;
|
|
266
|
-
lastWord = "";
|
|
267
|
-
index += 1;
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
lastWord = "";
|
|
271
|
-
index += 1;
|
|
272
|
-
}
|
|
273
|
-
return index;
|
|
274
|
-
}
|
|
275
|
-
function callSendsUnresolvedDynamicBody(args) {
|
|
276
|
-
const init2 = args[1]?.trim();
|
|
277
|
-
if (init2 == null || !init2.startsWith("{")) return false;
|
|
278
|
-
const properties = readObjectProperties(init2);
|
|
279
|
-
if (properties == null) return false;
|
|
280
|
-
const body = lastProperty(properties, "body");
|
|
281
|
-
if (body == null || body.spread || body.method) return false;
|
|
282
|
-
if (isStaticExpression(body.value)) return false;
|
|
283
|
-
const headers = lastProperty(properties, "headers");
|
|
284
|
-
if (headers == null) return true;
|
|
285
|
-
if (headers.spread || headers.method) return true;
|
|
286
|
-
return headersLeaveBodyResolutionOn(headers.value);
|
|
287
|
-
}
|
|
288
|
-
function headersLeaveBodyResolutionOn(headersValue) {
|
|
289
|
-
const text = headersValue.trim();
|
|
290
|
-
if (!text.startsWith("{")) return true;
|
|
291
|
-
const properties = readObjectProperties(text);
|
|
292
|
-
if (properties == null) return true;
|
|
293
|
-
if (properties.some((property) => property.spread)) return true;
|
|
294
|
-
const resolution = lastProperty(properties, secretResolutionHeaderName, {
|
|
295
|
-
caseInsensitive: true
|
|
296
|
-
});
|
|
297
|
-
if (resolution == null || resolution.method) return true;
|
|
298
|
-
const mode = staticStringValue(resolution.value);
|
|
299
|
-
if (mode == null) return false;
|
|
300
|
-
return mode.trim().toLowerCase() === "on";
|
|
301
|
-
}
|
|
302
|
-
function lastProperty(properties, key, options) {
|
|
303
|
-
const needle = options?.caseInsensitive ? key.toLowerCase() : key;
|
|
304
|
-
for (let index = properties.length - 1; index >= 0; index -= 1) {
|
|
305
|
-
const property = properties[index];
|
|
306
|
-
const name = property.key;
|
|
307
|
-
if (name == null) continue;
|
|
308
|
-
const match = options?.caseInsensitive ? name.toLowerCase() : name;
|
|
309
|
-
if (match === needle) return property;
|
|
310
|
-
}
|
|
311
|
-
return void 0;
|
|
312
|
-
}
|
|
313
|
-
function readObjectProperties(source) {
|
|
314
|
-
const text = source.trim();
|
|
315
|
-
if (!text.startsWith("{")) return null;
|
|
316
|
-
const properties = [];
|
|
317
|
-
let index = 1;
|
|
318
|
-
while (index < text.length) {
|
|
319
|
-
index = skipWhitespaceAndComments(text, index);
|
|
320
|
-
if (index >= text.length) return null;
|
|
321
|
-
if (text[index] === "}") return properties;
|
|
322
|
-
if (text[index] === ",") {
|
|
323
|
-
index += 1;
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
if (text.startsWith("...", index)) {
|
|
327
|
-
const spread = readExpression(text, index + 3);
|
|
328
|
-
if (spread == null) return null;
|
|
329
|
-
properties.push({
|
|
330
|
-
key: null,
|
|
331
|
-
value: spread.text,
|
|
332
|
-
spread: true,
|
|
333
|
-
method: false
|
|
334
|
-
});
|
|
335
|
-
index = spread.end;
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
const key = readPropertyKey(text, index);
|
|
339
|
-
if (key == null) return null;
|
|
340
|
-
index = skipWhitespaceAndComments(text, key.end);
|
|
341
|
-
if (text[index] === "(" || text.startsWith("async ", key.start)) {
|
|
342
|
-
const method = skipMethod(text, index);
|
|
343
|
-
if (method == null) return null;
|
|
344
|
-
properties.push({
|
|
345
|
-
key: key.name,
|
|
346
|
-
value: "",
|
|
347
|
-
spread: false,
|
|
348
|
-
method: true
|
|
349
|
-
});
|
|
350
|
-
index = method;
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (text[index] !== ":") {
|
|
354
|
-
properties.push({
|
|
355
|
-
key: key.name,
|
|
356
|
-
value: key.raw,
|
|
357
|
-
spread: false,
|
|
358
|
-
method: false
|
|
359
|
-
});
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const value = readExpression(text, index + 1);
|
|
363
|
-
if (value == null) return null;
|
|
364
|
-
properties.push({
|
|
365
|
-
key: key.name,
|
|
366
|
-
value: value.text,
|
|
367
|
-
spread: false,
|
|
368
|
-
method: false
|
|
369
|
-
});
|
|
370
|
-
index = value.end;
|
|
371
|
-
}
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
function readPropertyKey(source, start) {
|
|
375
|
-
const index = skipWhitespaceAndComments(source, start);
|
|
376
|
-
const char = source[index];
|
|
377
|
-
if (char === "'" || char === '"') {
|
|
378
|
-
const end = skipQuotedString(source, index);
|
|
379
|
-
const raw = source.slice(index, end);
|
|
380
|
-
return { name: staticStringValue(raw), raw, start: index, end };
|
|
381
|
-
}
|
|
382
|
-
if (char === "[") {
|
|
383
|
-
const computed = readBalanced(source, index, "[", "]");
|
|
384
|
-
if (computed == null) return null;
|
|
385
|
-
return { name: null, raw: computed.text, start: index, end: computed.end };
|
|
386
|
-
}
|
|
387
|
-
if (char != null && isIdentStart(char)) {
|
|
388
|
-
let end = index + 1;
|
|
389
|
-
while (end < source.length && isIdentPart(source[end])) end += 1;
|
|
390
|
-
const raw = source.slice(index, end);
|
|
391
|
-
return { name: raw, raw, start: index, end };
|
|
392
|
-
}
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
function readExpression(source, start) {
|
|
396
|
-
const index = skipWhitespaceAndComments(source, start);
|
|
397
|
-
const balanced = readUntilSeparator(source, index);
|
|
398
|
-
if (balanced == null) return null;
|
|
399
|
-
return { text: source.slice(index, balanced), end: balanced };
|
|
400
|
-
}
|
|
401
|
-
function readUntilSeparator(source, start) {
|
|
402
|
-
let index = start;
|
|
403
|
-
let paren = 0;
|
|
404
|
-
let brace = 0;
|
|
405
|
-
let bracket = 0;
|
|
406
|
-
while (index < source.length) {
|
|
407
|
-
const char = source[index];
|
|
408
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
409
|
-
index = skipLineComment(source, index);
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
413
|
-
index = skipBlockComment(source, index);
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
if (char === "'" || char === '"') {
|
|
417
|
-
index = skipQuotedString(source, index);
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
if (char === "`") {
|
|
421
|
-
index = skipTemplate(source, index, []);
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
if (char === "(") paren += 1;
|
|
425
|
-
else if (char === ")") {
|
|
426
|
-
if (paren === 0) return index;
|
|
427
|
-
paren -= 1;
|
|
428
|
-
} else if (char === "{") brace += 1;
|
|
429
|
-
else if (char === "}") {
|
|
430
|
-
if (brace === 0 && paren === 0 && bracket === 0) return index;
|
|
431
|
-
brace -= 1;
|
|
432
|
-
} else if (char === "[") bracket += 1;
|
|
433
|
-
else if (char === "]") {
|
|
434
|
-
if (bracket === 0) return index;
|
|
435
|
-
bracket -= 1;
|
|
436
|
-
} else if (char === "," && paren === 0 && brace === 0 && bracket === 0) {
|
|
437
|
-
return index;
|
|
438
|
-
}
|
|
439
|
-
index += 1;
|
|
440
|
-
}
|
|
441
|
-
return null;
|
|
442
|
-
}
|
|
443
|
-
function skipMethod(source, openParen) {
|
|
444
|
-
const params = readBalanced(source, openParen, "(", ")");
|
|
445
|
-
if (params == null) return null;
|
|
446
|
-
const bodyAt = skipWhitespaceAndComments(source, params.end);
|
|
447
|
-
if (source[bodyAt] !== "{") return null;
|
|
448
|
-
const body = readBalanced(source, bodyAt, "{", "}");
|
|
449
|
-
return body?.end ?? null;
|
|
450
|
-
}
|
|
451
|
-
function readCallArguments(source, openParen) {
|
|
452
|
-
const args = [];
|
|
453
|
-
let index = openParen + 1;
|
|
454
|
-
let argStart = index;
|
|
455
|
-
let paren = 1;
|
|
456
|
-
let brace = 0;
|
|
457
|
-
let bracket = 0;
|
|
458
|
-
while (index < source.length) {
|
|
459
|
-
const char = source[index];
|
|
460
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
461
|
-
index = skipLineComment(source, index);
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
465
|
-
index = skipBlockComment(source, index);
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
if (char === "'" || char === '"') {
|
|
469
|
-
index = skipQuotedString(source, index);
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
if (char === "`") {
|
|
473
|
-
index = skipTemplate(source, index, []);
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
if (char === "(") paren += 1;
|
|
477
|
-
else if (char === ")") {
|
|
478
|
-
paren -= 1;
|
|
479
|
-
if (paren === 0) {
|
|
480
|
-
args.push(source.slice(argStart, index));
|
|
481
|
-
return { args };
|
|
482
|
-
}
|
|
483
|
-
} else if (char === "{") brace += 1;
|
|
484
|
-
else if (char === "}") brace -= 1;
|
|
485
|
-
else if (char === "[") bracket += 1;
|
|
486
|
-
else if (char === "]") bracket -= 1;
|
|
487
|
-
else if (char === "," && paren === 1 && brace === 0 && bracket === 0) {
|
|
488
|
-
args.push(source.slice(argStart, index));
|
|
489
|
-
argStart = index + 1;
|
|
490
|
-
}
|
|
491
|
-
index += 1;
|
|
492
|
-
}
|
|
493
|
-
return null;
|
|
494
|
-
}
|
|
495
|
-
function readBalanced(source, openIndex, open2, close) {
|
|
496
|
-
let depth = 0;
|
|
497
|
-
let index = openIndex;
|
|
498
|
-
while (index < source.length) {
|
|
499
|
-
const char = source[index];
|
|
500
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
501
|
-
index = skipLineComment(source, index);
|
|
502
|
-
continue;
|
|
503
|
-
}
|
|
504
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
505
|
-
index = skipBlockComment(source, index);
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
if (char === "'" || char === '"') {
|
|
509
|
-
index = skipQuotedString(source, index);
|
|
510
|
-
continue;
|
|
511
|
-
}
|
|
512
|
-
if (char === "`") {
|
|
513
|
-
index = skipTemplate(source, index, []);
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
if (char === open2) depth += 1;
|
|
517
|
-
else if (char === close) {
|
|
518
|
-
depth -= 1;
|
|
519
|
-
if (depth === 0) {
|
|
520
|
-
return { text: source.slice(openIndex, index + 1), end: index + 1 };
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
index += 1;
|
|
524
|
-
}
|
|
525
|
-
return null;
|
|
526
|
-
}
|
|
527
|
-
function isStaticExpression(expression) {
|
|
528
|
-
const text = expression.trim();
|
|
529
|
-
if (isLiteral(text)) return true;
|
|
530
|
-
const stringify = matchCallee(text, "JSON.stringify");
|
|
531
|
-
if (stringify != null) {
|
|
532
|
-
const data = stringify.args[0];
|
|
533
|
-
return data != null && stringify.args.slice(1).every((arg) => isLiteral(arg.trim())) && isStaticData(data);
|
|
534
|
-
}
|
|
535
|
-
const params = matchNewCallee(text, "URLSearchParams");
|
|
536
|
-
if (params != null) {
|
|
537
|
-
if (params.args.length === 0) return true;
|
|
538
|
-
const data = params.args[0];
|
|
539
|
-
return data != null && params.args.length === 1 && isStaticData(data);
|
|
540
|
-
}
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
function isStaticData(expression) {
|
|
544
|
-
const text = expression.trim();
|
|
545
|
-
if (isLiteral(text)) return true;
|
|
546
|
-
if (text.startsWith("{")) {
|
|
547
|
-
const closed = readBalanced(text, 0, "{", "}");
|
|
548
|
-
if (closed == null || closed.end !== text.length) return false;
|
|
549
|
-
const properties = readObjectProperties(text);
|
|
550
|
-
if (properties == null) return false;
|
|
551
|
-
return properties.every(
|
|
552
|
-
(property) => !property.spread && !property.method && property.key != null && isStaticData(property.value)
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
if (text.startsWith("[")) {
|
|
556
|
-
const closed = readBalanced(text, 0, "[", "]");
|
|
557
|
-
if (closed == null || closed.end !== text.length) return false;
|
|
558
|
-
const elements = readArrayElements(text);
|
|
559
|
-
if (elements == null) return false;
|
|
560
|
-
return elements.every((element) => isStaticData(element));
|
|
561
|
-
}
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
function readArrayElements(source) {
|
|
565
|
-
const text = source.trim();
|
|
566
|
-
if (!text.startsWith("[")) return null;
|
|
567
|
-
const elements = [];
|
|
568
|
-
let index = 1;
|
|
569
|
-
while (index < text.length) {
|
|
570
|
-
index = skipWhitespaceAndComments(text, index);
|
|
571
|
-
if (text[index] === "]") return elements;
|
|
572
|
-
if (text[index] === ",") {
|
|
573
|
-
index += 1;
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
if (text.startsWith("...", index)) return null;
|
|
577
|
-
const value = readExpression(text, index);
|
|
578
|
-
if (value == null) return null;
|
|
579
|
-
elements.push(value.text);
|
|
580
|
-
index = value.end;
|
|
581
|
-
}
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
function isLiteral(expression) {
|
|
585
|
-
const text = expression.trim();
|
|
586
|
-
if (/^(?:null|undefined|true|false|-?\d+(?:\.\d+)?)$/.test(text)) return true;
|
|
587
|
-
if (isPlainTemplate(text)) return true;
|
|
588
|
-
return staticStringValue(text) != null && (text.startsWith("'") || text.startsWith('"'));
|
|
589
|
-
}
|
|
590
|
-
function staticStringValue(expression) {
|
|
591
|
-
const text = expression.trim();
|
|
592
|
-
if (isPlainTemplate(text)) return text.slice(1, -1);
|
|
593
|
-
if (text.startsWith("'") && text.endsWith("'") || text.startsWith('"') && text.endsWith('"')) {
|
|
594
|
-
if (text.length < 2) return null;
|
|
595
|
-
const body = text.slice(1, -1);
|
|
596
|
-
if (body.includes(text[0]) || body.includes("\n")) return null;
|
|
597
|
-
return body.replace(/\\(.)/g, "$1");
|
|
598
|
-
}
|
|
599
|
-
return null;
|
|
600
|
-
}
|
|
601
|
-
function isPlainTemplate(expression) {
|
|
602
|
-
const text = expression.trim();
|
|
603
|
-
return text.startsWith("`") && text.endsWith("`") && !text.slice(1, -1).includes("${");
|
|
604
|
-
}
|
|
605
|
-
function matchCallee(expression, callee) {
|
|
606
|
-
const text = expression.trim();
|
|
607
|
-
if (!text.startsWith(callee)) return null;
|
|
608
|
-
const open2 = skipWhitespaceAndComments(text, callee.length);
|
|
609
|
-
if (text[open2] !== "(") return null;
|
|
610
|
-
const call = readCallArguments(text, open2);
|
|
611
|
-
if (call == null) return null;
|
|
612
|
-
const end = skipWhitespaceAndComments(text, endOfCall(text, open2));
|
|
613
|
-
if (end !== text.length) return null;
|
|
614
|
-
return call;
|
|
615
|
-
}
|
|
616
|
-
function matchNewCallee(expression, name) {
|
|
617
|
-
const text = expression.trim();
|
|
618
|
-
if (!text.startsWith("new")) return null;
|
|
619
|
-
const nameAt = skipWhitespaceAndComments(text, "new".length);
|
|
620
|
-
if (!text.startsWith(name, nameAt)) return null;
|
|
621
|
-
return matchCallee(text.slice(nameAt), name);
|
|
622
|
-
}
|
|
623
|
-
function endOfCall(source, openParen) {
|
|
624
|
-
const args = readCallArguments(source, openParen);
|
|
625
|
-
if (args == null) return openParen;
|
|
626
|
-
let index = openParen;
|
|
627
|
-
let paren = 0;
|
|
628
|
-
while (index < source.length) {
|
|
629
|
-
const char = source[index];
|
|
630
|
-
if (char === "'" || char === '"') {
|
|
631
|
-
index = skipQuotedString(source, index);
|
|
632
|
-
continue;
|
|
633
|
-
}
|
|
634
|
-
if (char === "`") {
|
|
635
|
-
index = skipTemplate(source, index, []);
|
|
636
|
-
continue;
|
|
637
|
-
}
|
|
638
|
-
if (char === "(") paren += 1;
|
|
639
|
-
else if (char === ")") {
|
|
640
|
-
paren -= 1;
|
|
641
|
-
if (paren === 0) return index + 1;
|
|
642
|
-
}
|
|
643
|
-
index += 1;
|
|
644
|
-
}
|
|
645
|
-
return source.length;
|
|
646
|
-
}
|
|
647
|
-
function skipTemplate(source, start, calls) {
|
|
648
|
-
let index = start + 1;
|
|
649
|
-
while (index < source.length) {
|
|
650
|
-
const char = source[index];
|
|
651
|
-
if (char === "\\") {
|
|
652
|
-
index += 2;
|
|
653
|
-
continue;
|
|
654
|
-
}
|
|
655
|
-
if (char === "`") return index + 1;
|
|
656
|
-
if (char === "$" && source[index + 1] === "{") {
|
|
657
|
-
index = scanCode(source, index + 2, "brace", calls);
|
|
658
|
-
continue;
|
|
659
|
-
}
|
|
660
|
-
index += 1;
|
|
661
|
-
}
|
|
662
|
-
return index;
|
|
663
|
-
}
|
|
664
|
-
function skipQuotedString(source, start) {
|
|
665
|
-
const quote = source[start];
|
|
666
|
-
let index = start + 1;
|
|
667
|
-
while (index < source.length) {
|
|
668
|
-
const char = source[index];
|
|
669
|
-
if (char === "\\") {
|
|
670
|
-
index += 2;
|
|
671
|
-
continue;
|
|
672
|
-
}
|
|
673
|
-
if (char === quote) return index + 1;
|
|
674
|
-
if (char === "\n") return index;
|
|
675
|
-
index += 1;
|
|
676
|
-
}
|
|
677
|
-
return index;
|
|
678
|
-
}
|
|
679
|
-
function skipLineComment(source, start) {
|
|
680
|
-
const newline = source.indexOf("\n", start);
|
|
681
|
-
return newline === -1 ? source.length : newline + 1;
|
|
682
|
-
}
|
|
683
|
-
function skipBlockComment(source, start) {
|
|
684
|
-
const end = source.indexOf("*/", start + 2);
|
|
685
|
-
return end === -1 ? source.length : end + 2;
|
|
686
|
-
}
|
|
687
|
-
function skipWhitespaceAndComments(source, start) {
|
|
688
|
-
let index = start;
|
|
689
|
-
while (index < source.length) {
|
|
690
|
-
const char = source[index];
|
|
691
|
-
if (isWhitespace(char)) {
|
|
692
|
-
index += 1;
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
696
|
-
index = skipLineComment(source, index);
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
700
|
-
index = skipBlockComment(source, index);
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
return index;
|
|
706
|
-
}
|
|
707
|
-
function lineAt(source, index) {
|
|
708
|
-
let line = 1;
|
|
709
|
-
for (let cursor = 0; cursor < index && cursor < source.length; cursor += 1) {
|
|
710
|
-
if (source[cursor] === "\n") line += 1;
|
|
711
|
-
}
|
|
712
|
-
return line;
|
|
713
|
-
}
|
|
714
|
-
function isWhitespace(char) {
|
|
715
|
-
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
716
|
-
}
|
|
717
|
-
function isIdentStart(char) {
|
|
718
|
-
return /[A-Za-z_$]/.test(char);
|
|
719
|
-
}
|
|
720
|
-
function isIdentPart(char) {
|
|
721
|
-
return /[A-Za-z0-9_$]/.test(char);
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// src/fetch-body-package-scan.ts
|
|
725
|
-
import { readFile, stat } from "node:fs/promises";
|
|
726
|
-
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
727
|
-
import { transform } from "esbuild";
|
|
728
|
-
var esModuleLexerReady2 = init();
|
|
729
|
-
var sourceExtensions = [
|
|
730
|
-
".ts",
|
|
731
|
-
".tsx",
|
|
732
|
-
".mts",
|
|
733
|
-
".cts",
|
|
734
|
-
".js",
|
|
735
|
-
".mjs",
|
|
736
|
-
".cjs",
|
|
737
|
-
".jsx"
|
|
738
|
-
];
|
|
739
|
-
var maxModules = 200;
|
|
740
|
-
async function findPackageFetchBodyWarnings(input) {
|
|
741
|
-
await esModuleLexerReady2;
|
|
742
|
-
const hits = [];
|
|
743
|
-
const seen = /* @__PURE__ */ new Set();
|
|
744
|
-
const queue = [input.entryPath];
|
|
745
|
-
while (queue.length > 0 && seen.size < maxModules) {
|
|
746
|
-
const resolved = await resolveSourceFile(queue.pop());
|
|
747
|
-
if (resolved == null || seen.has(resolved)) continue;
|
|
748
|
-
const rel = relative(input.packageRoot, resolved).split("\\").join("/");
|
|
749
|
-
if (rel.startsWith("..") || rel.split("/").includes("node_modules") || isTestModule(rel)) {
|
|
750
|
-
continue;
|
|
751
|
-
}
|
|
752
|
-
seen.add(resolved);
|
|
753
|
-
let source;
|
|
754
|
-
try {
|
|
755
|
-
source = await readFile(resolved, "utf8");
|
|
756
|
-
} catch {
|
|
757
|
-
continue;
|
|
758
|
-
}
|
|
759
|
-
for (const hit of findFetchBodiesMissingSecretResolution(source)) {
|
|
760
|
-
hits.push({ path: rel, line: hit.line });
|
|
761
|
-
}
|
|
762
|
-
let imports;
|
|
763
|
-
try {
|
|
764
|
-
imports = parse(await lexableModuleSource(resolved, source))[0];
|
|
765
|
-
} catch {
|
|
766
|
-
continue;
|
|
767
|
-
}
|
|
768
|
-
for (const im of imports) {
|
|
769
|
-
if (im.type === "dynamic" || im.typeOnly === true) continue;
|
|
770
|
-
const specifier = im.specifier;
|
|
771
|
-
if (typeof specifier !== "string" || !specifier.startsWith(".")) continue;
|
|
772
|
-
queue.push(resolve(dirname(resolved), specifier));
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return hits;
|
|
776
|
-
}
|
|
777
|
-
function moduleLoaderForPath(path) {
|
|
778
|
-
switch (extname(path).toLowerCase()) {
|
|
779
|
-
case ".ts":
|
|
780
|
-
case ".mts":
|
|
781
|
-
case ".cts":
|
|
782
|
-
return "ts";
|
|
783
|
-
case ".tsx":
|
|
784
|
-
return "tsx";
|
|
785
|
-
case ".jsx":
|
|
786
|
-
return "jsx";
|
|
787
|
-
default:
|
|
788
|
-
return "js";
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
async function lexableModuleSource(path, source) {
|
|
792
|
-
const loader = moduleLoaderForPath(path);
|
|
793
|
-
if (loader === "js") return source;
|
|
794
|
-
const result = await transform(source, { loader, format: "esm" });
|
|
795
|
-
return result.code;
|
|
796
|
-
}
|
|
797
|
-
function isTestModule(path) {
|
|
798
|
-
return /\.(?:test|spec)\.[cm]?[jt]sx?$/.test(path);
|
|
799
|
-
}
|
|
800
|
-
async function resolveSourceFile(absPath) {
|
|
801
|
-
const candidates = [absPath];
|
|
802
|
-
if (extname(absPath) === "") {
|
|
803
|
-
for (const ext of sourceExtensions) {
|
|
804
|
-
candidates.push(`${absPath}${ext}`);
|
|
805
|
-
candidates.push(join(absPath, `index${ext}`));
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
for (const candidate of candidates) {
|
|
809
|
-
try {
|
|
810
|
-
const info = await stat(candidate);
|
|
811
|
-
if (info.isFile()) return candidate;
|
|
812
|
-
} catch {
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return null;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
183
|
// src/package-app-dev.ts
|
|
819
184
|
import { randomBytes } from "node:crypto";
|
|
820
185
|
import { rmSync, statSync } from "node:fs";
|
|
@@ -824,19 +189,19 @@ import {
|
|
|
824
189
|
request as httpRequest
|
|
825
190
|
} from "node:http";
|
|
826
191
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
827
|
-
import { join as
|
|
192
|
+
import { join as join7, relative as relative4, resolve as resolve6, sep as sep3 } from "node:path";
|
|
828
193
|
|
|
829
194
|
// src/dev/dev-assets.ts
|
|
830
195
|
import * as esbuild2 from "esbuild";
|
|
831
196
|
import { createHash } from "node:crypto";
|
|
832
|
-
import { readFile
|
|
833
|
-
import { join as
|
|
197
|
+
import { readFile, stat } from "node:fs/promises";
|
|
198
|
+
import { join as join2, resolve as resolve2, sep } from "node:path";
|
|
834
199
|
|
|
835
200
|
// src/dev/dev-bundler.ts
|
|
836
201
|
import * as esbuild from "esbuild";
|
|
837
|
-
import { join
|
|
202
|
+
import { join, resolve } from "node:path";
|
|
838
203
|
function createDevBundler(input) {
|
|
839
|
-
const entry =
|
|
204
|
+
const entry = resolve(input.entryPath);
|
|
840
205
|
const base = localBundleOptions(entry);
|
|
841
206
|
const options = {
|
|
842
207
|
...base,
|
|
@@ -844,7 +209,7 @@ function createDevBundler(input) {
|
|
|
844
209
|
sourcesContent: false,
|
|
845
210
|
metafile: true,
|
|
846
211
|
// Never written (write: false); only anchors source map paths at the root.
|
|
847
|
-
outfile:
|
|
212
|
+
outfile: join(input.root, "__kody_dev_bundle.js")
|
|
848
213
|
};
|
|
849
214
|
const paths = { workingDir: base.absWorkingDir, displayRoot: input.root };
|
|
850
215
|
let disposed = false;
|
|
@@ -897,7 +262,7 @@ function createDevClientBundler(input) {
|
|
|
897
262
|
let context3 = null;
|
|
898
263
|
const createContext = () => esbuild2.context({
|
|
899
264
|
absWorkingDir: workingDir,
|
|
900
|
-
entryPoints: [
|
|
265
|
+
entryPoints: [resolve2(input.entryPath)],
|
|
901
266
|
bundle: true,
|
|
902
267
|
write: false,
|
|
903
268
|
metafile: true,
|
|
@@ -906,7 +271,7 @@ function createDevClientBundler(input) {
|
|
|
906
271
|
target: "es2022",
|
|
907
272
|
sourcemap: "inline",
|
|
908
273
|
logLevel: "silent",
|
|
909
|
-
outfile:
|
|
274
|
+
outfile: join2(input.root, "_assets", "client.js"),
|
|
910
275
|
plugins: externals.length > 0 ? [clientExternalsPlugin(externals)] : []
|
|
911
276
|
});
|
|
912
277
|
return {
|
|
@@ -962,8 +327,8 @@ function parseDevAssetPath(pathname) {
|
|
|
962
327
|
}
|
|
963
328
|
function resolveDevAssetFile(assetsDir, relativePath) {
|
|
964
329
|
if (relativePath.includes("\0") || relativePath.startsWith("/")) return null;
|
|
965
|
-
const root =
|
|
966
|
-
const file =
|
|
330
|
+
const root = resolve2(assetsDir);
|
|
331
|
+
const file = resolve2(root, relativePath);
|
|
967
332
|
return file.startsWith(`${root}${sep}`) ? file : null;
|
|
968
333
|
}
|
|
969
334
|
async function serveDevAsset(input) {
|
|
@@ -1011,8 +376,8 @@ async function serveDevAsset(input) {
|
|
|
1011
376
|
}
|
|
1012
377
|
async function readAssetFile(file) {
|
|
1013
378
|
try {
|
|
1014
|
-
if (!(await
|
|
1015
|
-
return await
|
|
379
|
+
if (!(await stat(file)).isFile()) return null;
|
|
380
|
+
return await readFile(file);
|
|
1016
381
|
} catch {
|
|
1017
382
|
return null;
|
|
1018
383
|
}
|
|
@@ -1207,7 +572,7 @@ async function listenDevServer(server, input) {
|
|
|
1207
572
|
async function reserveDevPort(input) {
|
|
1208
573
|
const probe = createServer();
|
|
1209
574
|
const port = await listenDevServer(probe, input);
|
|
1210
|
-
await new Promise((
|
|
575
|
+
await new Promise((resolve8) => probe.close(() => resolve8()));
|
|
1211
576
|
return port;
|
|
1212
577
|
}
|
|
1213
578
|
function portInUseError(host, port) {
|
|
@@ -1231,14 +596,14 @@ function wrapPort(port) {
|
|
|
1231
596
|
return port > 65535 ? devPortRange.min + (port - 65536) : port;
|
|
1232
597
|
}
|
|
1233
598
|
function listenOnce(server, host, port) {
|
|
1234
|
-
return new Promise((
|
|
599
|
+
return new Promise((resolve8, reject) => {
|
|
1235
600
|
const onError = (error) => {
|
|
1236
601
|
server.off("listening", onListening);
|
|
1237
602
|
reject(error);
|
|
1238
603
|
};
|
|
1239
604
|
const onListening = () => {
|
|
1240
605
|
server.off("error", onError);
|
|
1241
|
-
|
|
606
|
+
resolve8();
|
|
1242
607
|
};
|
|
1243
608
|
server.once("error", onError);
|
|
1244
609
|
server.once("listening", onListening);
|
|
@@ -1254,14 +619,14 @@ function isPortReserved(error) {
|
|
|
1254
619
|
|
|
1255
620
|
// src/dev/dev-registry.ts
|
|
1256
621
|
import { createHash as createHash3 } from "node:crypto";
|
|
1257
|
-
import { mkdir, readFile as
|
|
1258
|
-
import { join as
|
|
622
|
+
import { mkdir, readFile as readFile3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
623
|
+
import { join as join4 } from "node:path";
|
|
1259
624
|
|
|
1260
625
|
// src/dev/process-reaper.ts
|
|
1261
626
|
import { spawn } from "node:child_process";
|
|
1262
|
-
import { readdir, readFile as
|
|
627
|
+
import { readdir, readFile as readFile2, rm, stat as stat2, writeFile } from "node:fs/promises";
|
|
1263
628
|
import { tmpdir } from "node:os";
|
|
1264
|
-
import { join as
|
|
629
|
+
import { join as join3 } from "node:path";
|
|
1265
630
|
import psList from "ps-list";
|
|
1266
631
|
var devWorkDirPrefix = "kody-dev-";
|
|
1267
632
|
var ownerFileName = "owner.json";
|
|
@@ -1284,7 +649,7 @@ rm -rf "$1"
|
|
|
1284
649
|
`;
|
|
1285
650
|
async function startProcessReaper(input) {
|
|
1286
651
|
await writeFile(
|
|
1287
|
-
|
|
652
|
+
join3(input.workDir, ownerFileName),
|
|
1288
653
|
JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
1289
654
|
);
|
|
1290
655
|
let reaper;
|
|
@@ -1346,7 +711,7 @@ async function sweepStaleDevDirs(input = {}) {
|
|
|
1346
711
|
}
|
|
1347
712
|
const byPid = new Map(processes.map((item) => [item.pid, item]));
|
|
1348
713
|
for (const name of entries) {
|
|
1349
|
-
const dir =
|
|
714
|
+
const dir = join3(tmp, name);
|
|
1350
715
|
try {
|
|
1351
716
|
const owner = await readOwnerPid(dir);
|
|
1352
717
|
if (owner !== null && isAlive(owner)) continue;
|
|
@@ -1354,7 +719,7 @@ async function sweepStaleDevDirs(input = {}) {
|
|
|
1354
719
|
(item) => /workerd/.test(item.name) && (item.cmd ?? "").includes(`${dir}/`)
|
|
1355
720
|
);
|
|
1356
721
|
if (owner === null) {
|
|
1357
|
-
const info = await
|
|
722
|
+
const info = await stat2(dir);
|
|
1358
723
|
if (now - info.mtimeMs < legacyDirMinAgeMs) continue;
|
|
1359
724
|
if (workerds.some((item) => !isOrphaned(item, byPid, isAlive))) continue;
|
|
1360
725
|
}
|
|
@@ -1381,7 +746,7 @@ function isOrphaned(item, byPid, isAlive) {
|
|
|
1381
746
|
async function readOwnerPid(dir) {
|
|
1382
747
|
try {
|
|
1383
748
|
const parsed = JSON.parse(
|
|
1384
|
-
await
|
|
749
|
+
await readFile2(join3(dir, ownerFileName), "utf8")
|
|
1385
750
|
);
|
|
1386
751
|
return typeof parsed.pid === "number" ? parsed.pid : null;
|
|
1387
752
|
} catch {
|
|
@@ -1403,11 +768,11 @@ var devOutboxPath = "/__kody/dev/outbox";
|
|
|
1403
768
|
var devCallPath = "/__kody/dev/call";
|
|
1404
769
|
function devRegistryPath(root, target, cacheDir = userCacheDir()) {
|
|
1405
770
|
const key = createHash3("sha256").update(`${root}\0${target}`).digest("hex").slice(0, 16);
|
|
1406
|
-
return
|
|
771
|
+
return join4(cacheDir, "dev-servers", `${key}.json`);
|
|
1407
772
|
}
|
|
1408
773
|
async function writeDevRegistration(registration, cacheDir) {
|
|
1409
774
|
const path = devRegistryPath(registration.root, registration.target, cacheDir);
|
|
1410
|
-
await mkdir(
|
|
775
|
+
await mkdir(join4(path, ".."), { recursive: true });
|
|
1411
776
|
await writeFile2(path, `${JSON.stringify(registration, null, 2)}
|
|
1412
777
|
`);
|
|
1413
778
|
return path;
|
|
@@ -1450,7 +815,7 @@ async function findRunningDevServer(input) {
|
|
|
1450
815
|
async function readRegistration(path) {
|
|
1451
816
|
try {
|
|
1452
817
|
const parsed = JSON.parse(
|
|
1453
|
-
await
|
|
818
|
+
await readFile3(path, "utf8")
|
|
1454
819
|
);
|
|
1455
820
|
if (typeof parsed.pid !== "number" || typeof parsed.origin !== "string" || typeof parsed.root !== "string" || parsed.target !== "mock" && parsed.target !== "prod") {
|
|
1456
821
|
return null;
|
|
@@ -1470,12 +835,12 @@ async function readRegistration(path) {
|
|
|
1470
835
|
|
|
1471
836
|
// node_modules/chokidar/esm/index.js
|
|
1472
837
|
import { stat as statcb } from "fs";
|
|
1473
|
-
import { stat as
|
|
838
|
+
import { stat as stat5, readdir as readdir3 } from "fs/promises";
|
|
1474
839
|
import { EventEmitter } from "events";
|
|
1475
840
|
import * as sysPath2 from "path";
|
|
1476
841
|
|
|
1477
842
|
// node_modules/readdirp/esm/index.js
|
|
1478
|
-
import { stat as
|
|
843
|
+
import { stat as stat3, lstat, readdir as readdir2, realpath } from "node:fs/promises";
|
|
1479
844
|
import { Readable } from "node:stream";
|
|
1480
845
|
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "node:path";
|
|
1481
846
|
var EntryTypes = {
|
|
@@ -1542,7 +907,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
1542
907
|
const { root, type } = opts;
|
|
1543
908
|
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
1544
909
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
1545
|
-
const statMethod = opts.lstat ? lstat :
|
|
910
|
+
const statMethod = opts.lstat ? lstat : stat3;
|
|
1546
911
|
if (wantBigintFsStats) {
|
|
1547
912
|
this._stat = (path) => statMethod(path, { bigint: true });
|
|
1548
913
|
} else {
|
|
@@ -1695,7 +1060,7 @@ function readdirp(root, options = {}) {
|
|
|
1695
1060
|
|
|
1696
1061
|
// node_modules/chokidar/esm/handler.js
|
|
1697
1062
|
import { watchFile, unwatchFile, watch as fs_watch } from "fs";
|
|
1698
|
-
import { open, stat as
|
|
1063
|
+
import { open, stat as stat4, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
|
|
1699
1064
|
import * as sysPath from "path";
|
|
1700
1065
|
import { type as osType } from "os";
|
|
1701
1066
|
var STR_DATA = "data";
|
|
@@ -1722,7 +1087,7 @@ var EVENTS = {
|
|
|
1722
1087
|
};
|
|
1723
1088
|
var EV = EVENTS;
|
|
1724
1089
|
var THROTTLE_MODE_WATCH = "watch";
|
|
1725
|
-
var statMethods = { lstat: lstat2, stat:
|
|
1090
|
+
var statMethods = { lstat: lstat2, stat: stat4 };
|
|
1726
1091
|
var KEY_LISTENERS = "listeners";
|
|
1727
1092
|
var KEY_ERR = "errHandlers";
|
|
1728
1093
|
var KEY_RAW = "rawEmitters";
|
|
@@ -2197,9 +1562,9 @@ var NodeFsHandler = class {
|
|
|
2197
1562
|
if (this.fsw.closed) {
|
|
2198
1563
|
return;
|
|
2199
1564
|
}
|
|
2200
|
-
const
|
|
1565
|
+
const dirname4 = sysPath.dirname(file);
|
|
2201
1566
|
const basename3 = sysPath.basename(file);
|
|
2202
|
-
const parent = this.fsw._getWatchedDir(
|
|
1567
|
+
const parent = this.fsw._getWatchedDir(dirname4);
|
|
2203
1568
|
let prevStats = stats;
|
|
2204
1569
|
if (parent.has(basename3))
|
|
2205
1570
|
return;
|
|
@@ -2208,7 +1573,7 @@ var NodeFsHandler = class {
|
|
|
2208
1573
|
return;
|
|
2209
1574
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
2210
1575
|
try {
|
|
2211
|
-
const newStats2 = await
|
|
1576
|
+
const newStats2 = await stat4(file);
|
|
2212
1577
|
if (this.fsw.closed)
|
|
2213
1578
|
return;
|
|
2214
1579
|
const at = newStats2.atimeMs;
|
|
@@ -2226,7 +1591,7 @@ var NodeFsHandler = class {
|
|
|
2226
1591
|
prevStats = newStats2;
|
|
2227
1592
|
}
|
|
2228
1593
|
} catch (error) {
|
|
2229
|
-
this.fsw._remove(
|
|
1594
|
+
this.fsw._remove(dirname4, basename3);
|
|
2230
1595
|
}
|
|
2231
1596
|
} else if (parent.has(basename3)) {
|
|
2232
1597
|
const at = newStats.atimeMs;
|
|
@@ -2322,7 +1687,7 @@ var NodeFsHandler = class {
|
|
|
2322
1687
|
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
2323
1688
|
}
|
|
2324
1689
|
}).on(EV.ERROR, this._boundHandleError);
|
|
2325
|
-
return new Promise((
|
|
1690
|
+
return new Promise((resolve8, reject) => {
|
|
2326
1691
|
if (!stream)
|
|
2327
1692
|
return reject();
|
|
2328
1693
|
stream.once(STR_END, () => {
|
|
@@ -2331,7 +1696,7 @@ var NodeFsHandler = class {
|
|
|
2331
1696
|
return;
|
|
2332
1697
|
}
|
|
2333
1698
|
const wasThrottled = throttler ? throttler.clear() : false;
|
|
2334
|
-
|
|
1699
|
+
resolve8(void 0);
|
|
2335
1700
|
previous.getChildren().filter((item) => {
|
|
2336
1701
|
return item !== directory && !current.has(item);
|
|
2337
1702
|
}).forEach((item) => {
|
|
@@ -2475,11 +1840,11 @@ function createPattern(matcher) {
|
|
|
2475
1840
|
if (matcher.path === string)
|
|
2476
1841
|
return true;
|
|
2477
1842
|
if (matcher.recursive) {
|
|
2478
|
-
const
|
|
2479
|
-
if (!
|
|
1843
|
+
const relative5 = sysPath2.relative(matcher.path, string);
|
|
1844
|
+
if (!relative5) {
|
|
2480
1845
|
return false;
|
|
2481
1846
|
}
|
|
2482
|
-
return !
|
|
1847
|
+
return !relative5.startsWith("..") && !sysPath2.isAbsolute(relative5);
|
|
2483
1848
|
}
|
|
2484
1849
|
return false;
|
|
2485
1850
|
};
|
|
@@ -2907,7 +2272,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
2907
2272
|
const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path) : path;
|
|
2908
2273
|
let stats2;
|
|
2909
2274
|
try {
|
|
2910
|
-
stats2 = await
|
|
2275
|
+
stats2 = await stat5(fullPath);
|
|
2911
2276
|
} catch (err) {
|
|
2912
2277
|
}
|
|
2913
2278
|
if (!stats2 || this.closed)
|
|
@@ -3034,8 +2399,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
3034
2399
|
}
|
|
3035
2400
|
return this._userIgnored(path, stats);
|
|
3036
2401
|
}
|
|
3037
|
-
_isntIgnored(path,
|
|
3038
|
-
return !this._isIgnored(path,
|
|
2402
|
+
_isntIgnored(path, stat7) {
|
|
2403
|
+
return !this._isIgnored(path, stat7);
|
|
3039
2404
|
}
|
|
3040
2405
|
/**
|
|
3041
2406
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
@@ -3160,12 +2525,12 @@ function watch(paths, options = {}) {
|
|
|
3160
2525
|
var esm_default = { watch, FSWatcher };
|
|
3161
2526
|
|
|
3162
2527
|
// src/dev/dev-watcher.ts
|
|
3163
|
-
import { stat as
|
|
3164
|
-
import { relative as
|
|
2528
|
+
import { stat as stat6 } from "node:fs/promises";
|
|
2529
|
+
import { relative as relative3, sep as sep2 } from "node:path";
|
|
3165
2530
|
var defaultPollIntervalMs = 1e3;
|
|
3166
2531
|
function createDevWatcher(input) {
|
|
3167
2532
|
const ignorePrefixes = (input.ignore ?? []).map(normalizePrefix).filter(Boolean);
|
|
3168
|
-
const ignored = (path) => shouldIgnoreWatchPath(
|
|
2533
|
+
const ignored = (path) => shouldIgnoreWatchPath(relative3(input.root, path), ignorePrefixes);
|
|
3169
2534
|
const watcher = esm_default.watch(input.root, {
|
|
3170
2535
|
ignoreInitial: true,
|
|
3171
2536
|
ignored,
|
|
@@ -3175,10 +2540,10 @@ function createDevWatcher(input) {
|
|
|
3175
2540
|
if (!ignored(path)) input.onChange(path);
|
|
3176
2541
|
});
|
|
3177
2542
|
let readySettled = false;
|
|
3178
|
-
const ready = new Promise((
|
|
2543
|
+
const ready = new Promise((resolve8, reject) => {
|
|
3179
2544
|
watcher.once("ready", () => {
|
|
3180
2545
|
readySettled = true;
|
|
3181
|
-
|
|
2546
|
+
resolve8();
|
|
3182
2547
|
});
|
|
3183
2548
|
watcher.on("error", (error) => {
|
|
3184
2549
|
if (readySettled) return;
|
|
@@ -3240,8 +2605,9 @@ function createDevWatcher(input) {
|
|
|
3240
2605
|
tracked = /* @__PURE__ */ new Map();
|
|
3241
2606
|
const changedDuringBuild = [];
|
|
3242
2607
|
const next = /* @__PURE__ */ new Map();
|
|
3243
|
-
|
|
3244
|
-
|
|
2608
|
+
const external = new Set(options?.external ?? []);
|
|
2609
|
+
for (const path of [...paths, ...external]) {
|
|
2610
|
+
if (!external.has(path) && ignored(path)) continue;
|
|
3245
2611
|
const current = await fingerprint(path);
|
|
3246
2612
|
if (generation !== trackGeneration) return [];
|
|
3247
2613
|
const previous = previousTracked.get(path);
|
|
@@ -3265,7 +2631,7 @@ function createDevWatcher(input) {
|
|
|
3265
2631
|
}
|
|
3266
2632
|
async function fingerprint(path) {
|
|
3267
2633
|
try {
|
|
3268
|
-
const info = await
|
|
2634
|
+
const info = await stat6(path);
|
|
3269
2635
|
return `${info.ino}:${info.size}:${info.mtimeMs}`;
|
|
3270
2636
|
} catch {
|
|
3271
2637
|
return "missing";
|
|
@@ -3541,9 +2907,9 @@ async function runPrebuild(input) {
|
|
|
3541
2907
|
else input.signal.addEventListener("abort", killChild, { once: true });
|
|
3542
2908
|
}
|
|
3543
2909
|
try {
|
|
3544
|
-
const result = await new Promise((
|
|
2910
|
+
const result = await new Promise((resolve8, reject) => {
|
|
3545
2911
|
child.once("error", reject);
|
|
3546
|
-
child.once("close", (code, signal) =>
|
|
2912
|
+
child.once("close", (code, signal) => resolve8({ code, signal }));
|
|
3547
2913
|
});
|
|
3548
2914
|
if (input.signal?.aborted) {
|
|
3549
2915
|
throw new PrebuildError("kody.dev.prebuild aborted");
|
|
@@ -3790,7 +3156,7 @@ function normalizePath2(url, type) {
|
|
|
3790
3156
|
}
|
|
3791
3157
|
url.path = path;
|
|
3792
3158
|
}
|
|
3793
|
-
function
|
|
3159
|
+
function resolve5(input, base) {
|
|
3794
3160
|
if (!input && !base)
|
|
3795
3161
|
return "";
|
|
3796
3162
|
const url = parseUrl(input);
|
|
@@ -3853,7 +3219,7 @@ function stripFilename(path) {
|
|
|
3853
3219
|
function resolver(mapUrl, sourceRoot) {
|
|
3854
3220
|
const from = stripFilename(mapUrl);
|
|
3855
3221
|
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
3856
|
-
return (source) =>
|
|
3222
|
+
return (source) => resolve5(prefix + (source || ""), from);
|
|
3857
3223
|
}
|
|
3858
3224
|
var COLUMN = 0;
|
|
3859
3225
|
var SOURCES_INDEX = 1;
|
|
@@ -3966,8 +3332,8 @@ var TraceMap = class {
|
|
|
3966
3332
|
this.sources = sources;
|
|
3967
3333
|
this.sourcesContent = sourcesContent;
|
|
3968
3334
|
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
3969
|
-
const
|
|
3970
|
-
this.resolvedSources = sources.map(
|
|
3335
|
+
const resolve8 = resolver(mapUrl, sourceRoot);
|
|
3336
|
+
this.resolvedSources = sources.map(resolve8);
|
|
3971
3337
|
const { mappings } = parsed;
|
|
3972
3338
|
if (typeof mappings === "string") {
|
|
3973
3339
|
this._encoded = mappings;
|
|
@@ -4114,7 +3480,7 @@ async function startPackageAppDev(options) {
|
|
|
4114
3480
|
const errorPageTail = liveReload ? `<script>globalThis.__kodyDevErrorPage = true</script>${liveReloadScriptTag}` : "";
|
|
4115
3481
|
void sweepStaleDevDirs().catch(() => {
|
|
4116
3482
|
});
|
|
4117
|
-
const workDir = await mkdtemp(
|
|
3483
|
+
const workDir = await mkdtemp(join7(tmpdir2(), devWorkDirPrefix));
|
|
4118
3484
|
const reaper = await startProcessReaper({ workDir });
|
|
4119
3485
|
const workerdPath = options.workerdPath ?? await ensureWorkerdBinary({
|
|
4120
3486
|
onDownload: (url) => options.onStatus?.(`Downloading workerd from ${url}\u2026`)
|
|
@@ -4150,8 +3516,8 @@ async function startPackageAppDev(options) {
|
|
|
4150
3516
|
let buildFailureAt = startedAt;
|
|
4151
3517
|
let markStarted = () => {
|
|
4152
3518
|
};
|
|
4153
|
-
const started = new Promise((
|
|
4154
|
-
markStarted =
|
|
3519
|
+
const started = new Promise((resolve8) => {
|
|
3520
|
+
markStarted = resolve8;
|
|
4155
3521
|
});
|
|
4156
3522
|
const killAllSync = () => {
|
|
4157
3523
|
for (const generation of generations) {
|
|
@@ -4264,8 +3630,8 @@ async function startPackageAppDev(options) {
|
|
|
4264
3630
|
process.off("exit", killAllSync);
|
|
4265
3631
|
reaper.close();
|
|
4266
3632
|
proxy.closeAllConnections();
|
|
4267
|
-
await new Promise((
|
|
4268
|
-
proxy.close(() =>
|
|
3633
|
+
await new Promise((resolve8) => {
|
|
3634
|
+
proxy.close(() => resolve8());
|
|
4269
3635
|
});
|
|
4270
3636
|
await rm3(workDir, { recursive: true, force: true, maxRetries: 10 });
|
|
4271
3637
|
throw error;
|
|
@@ -4320,7 +3686,7 @@ async function startPackageAppDev(options) {
|
|
|
4320
3686
|
root,
|
|
4321
3687
|
externals: app.clientExternals
|
|
4322
3688
|
}) : null;
|
|
4323
|
-
const assetsDir = app.assets ?
|
|
3689
|
+
const assetsDir = app.assets ? resolve6(root, app.assets) : null;
|
|
4324
3690
|
const prebuild = options.manifest.dev?.prebuild;
|
|
4325
3691
|
let prebuildRunning = false;
|
|
4326
3692
|
let prebuildSettledAt = 0;
|
|
@@ -4357,7 +3723,7 @@ async function startPackageAppDev(options) {
|
|
|
4357
3723
|
currentBuildFiles = files;
|
|
4358
3724
|
emit({
|
|
4359
3725
|
type: "rebuild_start",
|
|
4360
|
-
files: files.map((file) =>
|
|
3726
|
+
files: files.map((file) => relative4(root, file) || file)
|
|
4361
3727
|
});
|
|
4362
3728
|
const assetsChanged = assetsDir !== null && files.some(
|
|
4363
3729
|
(file) => file === assetsDir || file.startsWith(`${assetsDir}${sep3}`)
|
|
@@ -4370,19 +3736,29 @@ async function startPackageAppDev(options) {
|
|
|
4370
3736
|
bundler.build(),
|
|
4371
3737
|
clientBundler ? clientBundler.build() : Promise.resolve(null)
|
|
4372
3738
|
]);
|
|
4373
|
-
const
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
3739
|
+
const depFiles = options.localKody?.watchPaths() ?? [];
|
|
3740
|
+
const trackInputs = async () => {
|
|
3741
|
+
const midBuildEdits = await watcher?.track(
|
|
3742
|
+
[
|
|
3743
|
+
...bundle.inputs,
|
|
3744
|
+
...client2?.inputs ?? [],
|
|
3745
|
+
options.manifest.packageJsonPath
|
|
3746
|
+
],
|
|
3747
|
+
{
|
|
3748
|
+
ignoreChanges: files,
|
|
3749
|
+
external: options.localKody?.watchPaths()
|
|
3750
|
+
}
|
|
3751
|
+
) ?? [];
|
|
3752
|
+
if (midBuildEdits.length > 0) {
|
|
3753
|
+
for (const path of midBuildEdits) changedFiles.add(path);
|
|
3754
|
+
rebuildAgain = true;
|
|
3755
|
+
}
|
|
3756
|
+
};
|
|
3757
|
+
await trackInputs();
|
|
3758
|
+
const depChanged = options.localKody !== void 0 && files.some(
|
|
3759
|
+
(file) => depFiles.includes(file) || file === options.manifest.packageJsonPath
|
|
3760
|
+
);
|
|
3761
|
+
if (active && !buildFailure && !depChanged && bundle.code === active.code && client2?.name === active.client?.name) {
|
|
4386
3762
|
lastRebuild = { ms: elapsed(started2), at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4387
3763
|
emit({
|
|
4388
3764
|
type: "rebuild_ok",
|
|
@@ -4398,7 +3774,12 @@ async function startPackageAppDev(options) {
|
|
|
4398
3774
|
}
|
|
4399
3775
|
return;
|
|
4400
3776
|
}
|
|
4401
|
-
|
|
3777
|
+
let generation;
|
|
3778
|
+
try {
|
|
3779
|
+
generation = await startGeneration(bundle, client2);
|
|
3780
|
+
} finally {
|
|
3781
|
+
if (options.localKody) await trackInputs();
|
|
3782
|
+
}
|
|
4402
3783
|
if (closed) {
|
|
4403
3784
|
await stopGeneration(generation);
|
|
4404
3785
|
return;
|
|
@@ -4491,7 +3872,7 @@ async function startPackageAppDev(options) {
|
|
|
4491
3872
|
}
|
|
4492
3873
|
async function startGeneration(bundle, client2) {
|
|
4493
3874
|
const id = ++generationCounter;
|
|
4494
|
-
const dir =
|
|
3875
|
+
const dir = join7(workDir, `g${id}`);
|
|
4495
3876
|
if (options.localKody) {
|
|
4496
3877
|
await options.localKody.sync();
|
|
4497
3878
|
const generation2 = {
|
|
@@ -4540,7 +3921,7 @@ async function startPackageAppDev(options) {
|
|
|
4540
3921
|
try {
|
|
4541
3922
|
workerd = await startWorkerd({
|
|
4542
3923
|
workerdPath,
|
|
4543
|
-
configPath:
|
|
3924
|
+
configPath: join7(dir, "config.capnp"),
|
|
4544
3925
|
cwd: dir,
|
|
4545
3926
|
env: workerdEnv,
|
|
4546
3927
|
onSpawn: (pid) => {
|
|
@@ -4621,7 +4002,7 @@ async function startPackageAppDev(options) {
|
|
|
4621
4002
|
pending.catch(() => {
|
|
4622
4003
|
}),
|
|
4623
4004
|
new Promise(
|
|
4624
|
-
(
|
|
4005
|
+
(resolve8) => setTimeout(resolve8, rebuildGateMs).unref()
|
|
4625
4006
|
)
|
|
4626
4007
|
]);
|
|
4627
4008
|
}
|
|
@@ -4850,7 +4231,7 @@ async function startPackageAppDev(options) {
|
|
|
4850
4231
|
request: tag
|
|
4851
4232
|
});
|
|
4852
4233
|
};
|
|
4853
|
-
return new Promise((
|
|
4234
|
+
return new Promise((resolve8, reject) => {
|
|
4854
4235
|
const upstream2 = httpRequest(
|
|
4855
4236
|
forwardUrl,
|
|
4856
4237
|
{ method: req.method, headers },
|
|
@@ -4859,7 +4240,7 @@ async function startPackageAppDev(options) {
|
|
|
4859
4240
|
if (upstreamRes.headers[devErrorHeader]) {
|
|
4860
4241
|
void readStream(upstreamRes).then((raw) => {
|
|
4861
4242
|
respondWithRuntimeError(generation, req, res, tag, raw);
|
|
4862
|
-
|
|
4243
|
+
resolve8();
|
|
4863
4244
|
}).catch(reject);
|
|
4864
4245
|
return;
|
|
4865
4246
|
}
|
|
@@ -4886,7 +4267,7 @@ async function startPackageAppDev(options) {
|
|
|
4886
4267
|
headers2["content-length"] = String(body.length);
|
|
4887
4268
|
res.writeHead(status2, headers2);
|
|
4888
4269
|
res.end(body);
|
|
4889
|
-
|
|
4270
|
+
resolve8();
|
|
4890
4271
|
}).catch(reject);
|
|
4891
4272
|
return;
|
|
4892
4273
|
}
|
|
@@ -4894,7 +4275,7 @@ async function startPackageAppDev(options) {
|
|
|
4894
4275
|
upstreamRes.pipe(res);
|
|
4895
4276
|
upstreamRes.on("end", () => {
|
|
4896
4277
|
warnIfOverCpuLimit();
|
|
4897
|
-
|
|
4278
|
+
resolve8();
|
|
4898
4279
|
});
|
|
4899
4280
|
upstreamRes.on("error", reject);
|
|
4900
4281
|
}
|
|
@@ -4902,7 +4283,7 @@ async function startPackageAppDev(options) {
|
|
|
4902
4283
|
upstream2.on("error", reject);
|
|
4903
4284
|
res.on("close", () => {
|
|
4904
4285
|
if (!res.writableFinished) upstream2.destroy();
|
|
4905
|
-
|
|
4286
|
+
resolve8();
|
|
4906
4287
|
});
|
|
4907
4288
|
req.pipe(upstream2);
|
|
4908
4289
|
});
|
|
@@ -4951,10 +4332,10 @@ fix: ${fix}` : mapped,
|
|
|
4951
4332
|
pending.clear();
|
|
4952
4333
|
clearTimeout(debounceTimer);
|
|
4953
4334
|
debouncePending = false;
|
|
4954
|
-
const
|
|
4335
|
+
const resolve8 = resolveDebounceFlush;
|
|
4955
4336
|
resolveDebounceFlush = null;
|
|
4956
4337
|
debounceFlush = null;
|
|
4957
|
-
|
|
4338
|
+
resolve8?.();
|
|
4958
4339
|
};
|
|
4959
4340
|
return createDevWatcher({
|
|
4960
4341
|
root,
|
|
@@ -4977,8 +4358,8 @@ fix: ${fix}` : mapped,
|
|
|
4977
4358
|
pending.add(path);
|
|
4978
4359
|
debouncePending = true;
|
|
4979
4360
|
if (!debounceFlush) {
|
|
4980
|
-
debounceFlush = new Promise((
|
|
4981
|
-
resolveDebounceFlush =
|
|
4361
|
+
debounceFlush = new Promise((resolve8) => {
|
|
4362
|
+
resolveDebounceFlush = resolve8;
|
|
4982
4363
|
});
|
|
4983
4364
|
}
|
|
4984
4365
|
clearTimeout(debounceTimer);
|
|
@@ -4987,10 +4368,10 @@ fix: ${fix}` : mapped,
|
|
|
4987
4368
|
pending.clear();
|
|
4988
4369
|
debouncePending = false;
|
|
4989
4370
|
const build = requestBuild(paths);
|
|
4990
|
-
const
|
|
4371
|
+
const resolve8 = resolveDebounceFlush;
|
|
4991
4372
|
resolveDebounceFlush = null;
|
|
4992
4373
|
debounceFlush = null;
|
|
4993
|
-
|
|
4374
|
+
resolve8?.();
|
|
4994
4375
|
void build;
|
|
4995
4376
|
}, options.debounceMs ?? defaultDebounceMs);
|
|
4996
4377
|
}
|
|
@@ -5002,10 +4383,10 @@ fix: ${fix}` : mapped,
|
|
|
5002
4383
|
process.off("exit", killAllSync);
|
|
5003
4384
|
clearTimeout(debounceTimer);
|
|
5004
4385
|
debouncePending = false;
|
|
5005
|
-
const
|
|
4386
|
+
const resolve8 = resolveDebounceFlush;
|
|
5006
4387
|
resolveDebounceFlush = null;
|
|
5007
4388
|
debounceFlush = null;
|
|
5008
|
-
|
|
4389
|
+
resolve8?.();
|
|
5009
4390
|
prebuildAbort?.abort();
|
|
5010
4391
|
await watcher?.close();
|
|
5011
4392
|
await buildLoop?.catch(() => {
|
|
@@ -5019,8 +4400,8 @@ fix: ${fix}` : mapped,
|
|
|
5019
4400
|
await bridge.close();
|
|
5020
4401
|
liveReloadHub.close();
|
|
5021
4402
|
proxy.closeAllConnections();
|
|
5022
|
-
await new Promise((
|
|
5023
|
-
proxy.close(() =>
|
|
4403
|
+
await new Promise((resolve9) => {
|
|
4404
|
+
proxy.close(() => resolve9());
|
|
5024
4405
|
});
|
|
5025
4406
|
await rm3(workDir, { recursive: true, force: true, maxRetries: 10 });
|
|
5026
4407
|
};
|
|
@@ -5136,7 +4517,7 @@ async function writeWorkerFiles(input) {
|
|
|
5136
4517
|
input.workDir,
|
|
5137
4518
|
packageGraph,
|
|
5138
4519
|
writeFile3,
|
|
5139
|
-
|
|
4520
|
+
join7
|
|
5140
4521
|
);
|
|
5141
4522
|
let gatewayFetchShimModules = packageGraph.modules.map((module) => module.name).filter((name) => name === localExecuteGatewayFetchShimModuleName);
|
|
5142
4523
|
if (input.mockFetchGateway) {
|
|
@@ -5148,12 +4529,12 @@ async function writeWorkerFiles(input) {
|
|
|
5148
4529
|
gatewayFetchShimModules = installed.sideEffectModules;
|
|
5149
4530
|
}
|
|
5150
4531
|
await writeFile3(
|
|
5151
|
-
|
|
4532
|
+
join7(input.workDir, files.entry),
|
|
5152
4533
|
createPackageAppEntrySource({ sideEffectModules: gatewayFetchShimModules })
|
|
5153
4534
|
);
|
|
5154
|
-
await writeFile3(
|
|
4535
|
+
await writeFile3(join7(input.workDir, files.user), input.code);
|
|
5155
4536
|
await writeFile3(
|
|
5156
|
-
|
|
4537
|
+
join7(input.workDir, files.runtime),
|
|
5157
4538
|
createPackageLocalRuntimeModuleSource({
|
|
5158
4539
|
packageContext,
|
|
5159
4540
|
mockStorage: input.mockStorage,
|
|
@@ -5161,11 +4542,11 @@ async function writeWorkerFiles(input) {
|
|
|
5161
4542
|
})
|
|
5162
4543
|
);
|
|
5163
4544
|
await writeFile3(
|
|
5164
|
-
|
|
4545
|
+
join7(input.workDir, localWorkerModuleNames.runtimeFlatAlias),
|
|
5165
4546
|
createRuntimeFlatAliasSource()
|
|
5166
4547
|
);
|
|
5167
4548
|
await writeFile3(
|
|
5168
|
-
|
|
4549
|
+
join7(input.workDir, "config.capnp"),
|
|
5169
4550
|
createWorkerdConfig({
|
|
5170
4551
|
bridgePort: input.bridgePort,
|
|
5171
4552
|
files,
|
|
@@ -5414,7 +4795,7 @@ async function runDevServe(input) {
|
|
|
5414
4795
|
}
|
|
5415
4796
|
}
|
|
5416
4797
|
if (input.readyFile) {
|
|
5417
|
-
await mkdir3(
|
|
4798
|
+
await mkdir3(dirname3(input.readyFile), { recursive: true });
|
|
5418
4799
|
await writeFile4(input.readyFile, `${JSON.stringify(ready, null, 2)}
|
|
5419
4800
|
`);
|
|
5420
4801
|
}
|
|
@@ -5605,7 +4986,7 @@ async function tryAttachedDevCall(input) {
|
|
|
5605
4986
|
};
|
|
5606
4987
|
} else {
|
|
5607
4988
|
if (process.env.KODY_DEV_STUB_RUNTIME === "1") return null;
|
|
5608
|
-
const local = await import("./local-kody-
|
|
4989
|
+
const local = await import("./local-kody-UP6W2YSF.js");
|
|
5609
4990
|
const kody = await local.startLocalKody({
|
|
5610
4991
|
manifest,
|
|
5611
4992
|
packageAppPort: defaultDevPort(manifest.kodyId),
|
|
@@ -5725,8 +5106,8 @@ async function runDevWebhook(input) {
|
|
|
5725
5106
|
target: input.target
|
|
5726
5107
|
});
|
|
5727
5108
|
}
|
|
5728
|
-
const rawBody = await
|
|
5729
|
-
|
|
5109
|
+
const rawBody = await readFile4(
|
|
5110
|
+
resolve7(input.cwd ?? process.cwd(), input.bodyPath),
|
|
5730
5111
|
"utf8"
|
|
5731
5112
|
);
|
|
5732
5113
|
let jsonBody = null;
|
|
@@ -5813,8 +5194,8 @@ async function runDevEmit(input) {
|
|
|
5813
5194
|
target: input.target
|
|
5814
5195
|
});
|
|
5815
5196
|
}
|
|
5816
|
-
const rawBody = await
|
|
5817
|
-
|
|
5197
|
+
const rawBody = await readFile4(
|
|
5198
|
+
resolve7(input.cwd ?? process.cwd(), input.bodyPath),
|
|
5818
5199
|
"utf8"
|
|
5819
5200
|
);
|
|
5820
5201
|
let envelope;
|
|
@@ -5959,7 +5340,7 @@ async function runPublishChecksWithRetry(input) {
|
|
|
5959
5340
|
`
|
|
5960
5341
|
);
|
|
5961
5342
|
await new Promise(
|
|
5962
|
-
(
|
|
5343
|
+
(resolve8) => setTimeout(resolve8, input.delayMs ?? 2e3 * attempt)
|
|
5963
5344
|
);
|
|
5964
5345
|
}
|
|
5965
5346
|
}
|
|
@@ -6057,13 +5438,13 @@ async function runDevCheck(input) {
|
|
|
6057
5438
|
}
|
|
6058
5439
|
}
|
|
6059
5440
|
try {
|
|
6060
|
-
await
|
|
5441
|
+
await readFile4(resolve7(manifest.root, "README.md"));
|
|
6061
5442
|
push("README.md", true);
|
|
6062
5443
|
} catch {
|
|
6063
5444
|
push("README.md", false, "Publish requires README.md");
|
|
6064
5445
|
}
|
|
6065
5446
|
try {
|
|
6066
|
-
await
|
|
5447
|
+
await readFile4(resolve7(manifest.root, "AGENTS.md"));
|
|
6067
5448
|
push("AGENTS.md", true);
|
|
6068
5449
|
} catch {
|
|
6069
5450
|
push("AGENTS.md", false, "Publish requires AGENTS.md");
|
|
@@ -6096,7 +5477,7 @@ async function runDevCheck(input) {
|
|
|
6096
5477
|
}
|
|
6097
5478
|
let hasMocksFile = false;
|
|
6098
5479
|
try {
|
|
6099
|
-
await access(
|
|
5480
|
+
await access(join8(manifest.root, packageMocksRelativePath));
|
|
6100
5481
|
hasMocksFile = true;
|
|
6101
5482
|
} catch {
|
|
6102
5483
|
hasMocksFile = false;
|
|
@@ -6299,7 +5680,7 @@ function parseDevSubcommand(positionals) {
|
|
|
6299
5680
|
}
|
|
6300
5681
|
async function removeOwnedReadyFile(path, ownerPid) {
|
|
6301
5682
|
try {
|
|
6302
|
-
const parsed = JSON.parse(await
|
|
5683
|
+
const parsed = JSON.parse(await readFile4(path, "utf8"));
|
|
6303
5684
|
if (parsed.pid !== ownerPid) return;
|
|
6304
5685
|
await rm4(path, { force: true });
|
|
6305
5686
|
} catch {
|
|
@@ -6326,4 +5707,4 @@ export {
|
|
|
6326
5707
|
chokidar/esm/index.js:
|
|
6327
5708
|
(*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
|
|
6328
5709
|
*/
|
|
6329
|
-
//# sourceMappingURL=dev-command-
|
|
5710
|
+
//# sourceMappingURL=dev-command-TEJPQEPO.js.map
|