@prisma/composer 0.6.0 → 0.8.0

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 (83) hide show
  1. package/dist/{app-config-Cbv_lA38-BHJsd1DF.d.mts → app-config-BinBcpPf-1akTl5h4.d.mts} +130 -17
  2. package/dist/app-config-BinBcpPf-1akTl5h4.d.mts.map +1 -0
  3. package/dist/config-647Wkm51.d.mts +1 -0
  4. package/dist/config.d.mts +3 -3
  5. package/dist/control.d.mts +260 -0
  6. package/dist/control.d.mts.map +1 -0
  7. package/dist/control.mjs +71 -0
  8. package/dist/control.mjs.map +1 -0
  9. package/dist/deploy-647Wkm51.d.mts +1 -0
  10. package/dist/deploy.d.mts +2 -2
  11. package/dist/deploy.mjs +312 -1
  12. package/dist/deploy.mjs.map +1 -0
  13. package/dist/deployment-summary-DswOl_9E-B9MhYYDt.mjs +70 -0
  14. package/dist/deployment-summary-DswOl_9E-B9MhYYDt.mjs.map +1 -0
  15. package/dist/{dist-BdvFDCLV.mjs → dist-C5rZnr4n.mjs} +2 -2
  16. package/dist/{dist-BdvFDCLV.mjs.map → dist-C5rZnr4n.mjs.map} +1 -1
  17. package/dist/dist-CVk7Pk4B.mjs +42 -0
  18. package/dist/dist-CVk7Pk4B.mjs.map +1 -0
  19. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs +24 -0
  20. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs.map +1 -0
  21. package/dist/errors-0e8IVwzi.mjs +88 -0
  22. package/dist/errors-0e8IVwzi.mjs.map +1 -0
  23. package/dist/execute-deploy-destroy-DRl6Tfg9-B8LE2Lh5.mjs +405 -0
  24. package/dist/execute-deploy-destroy-DRl6Tfg9-B8LE2Lh5.mjs.map +1 -0
  25. package/dist/execute-dev-BMTFWfFc-7MifQgpp.mjs +2014 -0
  26. package/dist/execute-dev-BMTFWfFc-7MifQgpp.mjs.map +1 -0
  27. package/dist/execute-log-Cay9hlKW-BcvKPOW1.mjs +160 -0
  28. package/dist/execute-log-Cay9hlKW-BcvKPOW1.mjs.map +1 -0
  29. package/dist/{graph-DgbALPDo-BEHF94BN.mjs → graph-BJgUfGB0-kvgFzT4q.mjs} +13 -7
  30. package/dist/graph-BJgUfGB0-kvgFzT4q.mjs.map +1 -0
  31. package/dist/{graph-DDpXh7S8-b-93BcHn.d.mts → graph-DqklX5Sf-BNS2aO1j.d.mts} +3 -3
  32. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts.map +1 -0
  33. package/dist/{graph-types-C3FOaaXm-C6_rGzfn.d.mts → graph-types-N6brq1zY-1VMNwtkJ.d.mts} +88 -5
  34. package/dist/graph-types-N6brq1zY-1VMNwtkJ.d.mts.map +1 -0
  35. package/dist/{index-BQVrMGfe.d.mts → index-DryPyF9U.d.mts} +3 -3
  36. package/dist/{index-BQVrMGfe.d.mts.map → index-DryPyF9U.d.mts.map} +1 -1
  37. package/dist/index.d.mts +3 -3
  38. package/dist/index.mjs +2 -2
  39. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs +18 -0
  40. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs.map +1 -0
  41. package/dist/local-target-DnA2E8IN.mjs +47 -0
  42. package/dist/local-target-DnA2E8IN.mjs.map +1 -0
  43. package/dist/local-target.d.mts +1 -1
  44. package/dist/local-target.mjs +2 -46
  45. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts → nextjs-DLyeRR7M-DZODs9tk.d.mts} +3 -3
  46. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts.map → nextjs-DLyeRR7M-DZODs9tk.d.mts.map} +1 -1
  47. package/dist/nextjs-control.d.mts +4 -4
  48. package/dist/nextjs-control.mjs +138 -34
  49. package/dist/nextjs-control.mjs.map +1 -1
  50. package/dist/nextjs.d.mts +1 -1
  51. package/dist/node-control.d.mts +3 -3
  52. package/dist/node-control.mjs +21814 -55
  53. package/dist/node-control.mjs.map +1 -1
  54. package/dist/node.d.mts +2 -2
  55. package/dist/pipeline-AoW8zq4I-Dg8xQ7nC.mjs +452 -0
  56. package/dist/pipeline-AoW8zq4I-Dg8xQ7nC.mjs.map +1 -0
  57. package/dist/report.d.mts +4 -3
  58. package/dist/report.d.mts.map +1 -1
  59. package/dist/report.mjs +4 -1
  60. package/dist/report.mjs.map +1 -1
  61. package/dist/result-D95kAAek.mjs +247 -0
  62. package/dist/result-D95kAAek.mjs.map +1 -0
  63. package/dist/run-alchemy-D44OZlyB-Cw5CVbUQ.mjs +93 -0
  64. package/dist/run-alchemy-D44OZlyB-Cw5CVbUQ.mjs.map +1 -0
  65. package/dist/run-report-C2o98uD--AX8kpz4Q.mjs +60 -0
  66. package/dist/run-report-C2o98uD--AX8kpz4Q.mjs.map +1 -0
  67. package/dist/service-rpc.d.mts +2 -2
  68. package/dist/service-rpc.mjs +2 -2
  69. package/dist/testing.d.mts +1 -1
  70. package/package.json +17 -21
  71. package/src/exports/control.ts +1 -0
  72. package/src/exports/testing.ts +5 -0
  73. package/dist/app-config-Cbv_lA38-BHJsd1DF.d.mts.map +0 -1
  74. package/dist/bin.mjs +0 -3283
  75. package/dist/bin.mjs.map +0 -1
  76. package/dist/config-whuqZ5xT.d.mts +0 -1
  77. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs +0 -313
  78. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs.map +0 -1
  79. package/dist/deploy-whuqZ5xT.d.mts +0 -1
  80. package/dist/graph-DDpXh7S8-b-93BcHn.d.mts.map +0 -1
  81. package/dist/graph-DgbALPDo-BEHF94BN.mjs.map +0 -1
  82. package/dist/graph-types-C3FOaaXm-C6_rGzfn.d.mts.map +0 -1
  83. package/dist/local-target.mjs.map +0 -1
@@ -0,0 +1,2014 @@
1
+ import { t as CliStructuredError } from "./errors-0e8IVwzi.mjs";
2
+ import { t as containerEnv } from "./container-transport-DKmKg5JQ-DKWs0ubK.mjs";
3
+ import { t as DEV_DIR } from "./app-config-joXc-BKm-CdcXqNMD.mjs";
4
+ import { n as ok, s as toStructured, t as notOk } from "./result-D95kAAek.mjs";
5
+ import { n as resolveLocalTargets } from "./local-target-DnA2E8IN.mjs";
6
+ import { n as spawnAlchemy, t as alchemyInvocation } from "./run-alchemy-D44OZlyB-Cw5CVbUQ.mjs";
7
+ import { n as runPipeline } from "./pipeline-AoW8zq4I-Dg8xQ7nC.mjs";
8
+ import { t as withEmulatorRetry } from "./emulator-retry-DGonap4g-S8BNrXFD.mjs";
9
+ import * as fs$1 from "node:fs";
10
+ import * as path$1 from "node:path";
11
+ import { join, relative, resolve, sep } from "node:path";
12
+ import * as sysPath from "path";
13
+ import { stat, unwatchFile, watch, watchFile } from "fs";
14
+ import { Readable } from "node:stream";
15
+ import { lstat, readdir, realpath, stat as stat$1 } from "node:fs/promises";
16
+ import { type } from "os";
17
+ import { EventEmitter } from "events";
18
+ import { lstat as lstat$1, open, readdir as readdir$1, realpath as realpath$1, stat as stat$2 } from "fs/promises";
19
+ //#region ../../0-framework/3-tooling/cli/node_modules/readdirp/esm/index.js
20
+ const EntryTypes = {
21
+ FILE_TYPE: "files",
22
+ DIR_TYPE: "directories",
23
+ FILE_DIR_TYPE: "files_directories",
24
+ EVERYTHING_TYPE: "all"
25
+ };
26
+ const defaultOptions = {
27
+ root: ".",
28
+ fileFilter: (_entryInfo) => true,
29
+ directoryFilter: (_entryInfo) => true,
30
+ type: EntryTypes.FILE_TYPE,
31
+ lstat: false,
32
+ depth: 2147483648,
33
+ alwaysStat: false,
34
+ highWaterMark: 4096
35
+ };
36
+ Object.freeze(defaultOptions);
37
+ const RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
38
+ const NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set([
39
+ "ENOENT",
40
+ "EPERM",
41
+ "EACCES",
42
+ "ELOOP",
43
+ RECURSIVE_ERROR_CODE
44
+ ]);
45
+ const ALL_TYPES = [
46
+ EntryTypes.DIR_TYPE,
47
+ EntryTypes.EVERYTHING_TYPE,
48
+ EntryTypes.FILE_DIR_TYPE,
49
+ EntryTypes.FILE_TYPE
50
+ ];
51
+ const DIR_TYPES = /* @__PURE__ */ new Set([
52
+ EntryTypes.DIR_TYPE,
53
+ EntryTypes.EVERYTHING_TYPE,
54
+ EntryTypes.FILE_DIR_TYPE
55
+ ]);
56
+ const FILE_TYPES = /* @__PURE__ */ new Set([
57
+ EntryTypes.EVERYTHING_TYPE,
58
+ EntryTypes.FILE_DIR_TYPE,
59
+ EntryTypes.FILE_TYPE
60
+ ]);
61
+ const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
62
+ const wantBigintFsStats = process.platform === "win32";
63
+ const emptyFn = (_entryInfo) => true;
64
+ const normalizeFilter = (filter) => {
65
+ if (filter === void 0) return emptyFn;
66
+ if (typeof filter === "function") return filter;
67
+ if (typeof filter === "string") {
68
+ const fl = filter.trim();
69
+ return (entry) => entry.basename === fl;
70
+ }
71
+ if (Array.isArray(filter)) {
72
+ const trItems = filter.map((item) => item.trim());
73
+ return (entry) => trItems.some((f) => entry.basename === f);
74
+ }
75
+ return emptyFn;
76
+ };
77
+ /** Readable readdir stream, emitting new files as they're being listed. */
78
+ var ReaddirpStream = class extends Readable {
79
+ constructor(options = {}) {
80
+ super({
81
+ objectMode: true,
82
+ autoDestroy: true,
83
+ highWaterMark: options.highWaterMark
84
+ });
85
+ const opts = {
86
+ ...defaultOptions,
87
+ ...options
88
+ };
89
+ const { root, type } = opts;
90
+ this._fileFilter = normalizeFilter(opts.fileFilter);
91
+ this._directoryFilter = normalizeFilter(opts.directoryFilter);
92
+ const statMethod = opts.lstat ? lstat : stat$1;
93
+ if (wantBigintFsStats) this._stat = (path) => statMethod(path, { bigint: true });
94
+ else this._stat = statMethod;
95
+ this._maxDepth = opts.depth ?? defaultOptions.depth;
96
+ this._wantsDir = type ? DIR_TYPES.has(type) : false;
97
+ this._wantsFile = type ? FILE_TYPES.has(type) : false;
98
+ this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
99
+ this._root = resolve(root);
100
+ this._isDirent = !opts.alwaysStat;
101
+ this._statsProp = this._isDirent ? "dirent" : "stats";
102
+ this._rdOptions = {
103
+ encoding: "utf8",
104
+ withFileTypes: this._isDirent
105
+ };
106
+ this.parents = [this._exploreDir(root, 1)];
107
+ this.reading = false;
108
+ this.parent = void 0;
109
+ }
110
+ async _read(batch) {
111
+ if (this.reading) return;
112
+ this.reading = true;
113
+ try {
114
+ while (!this.destroyed && batch > 0) {
115
+ const par = this.parent;
116
+ const fil = par && par.files;
117
+ if (fil && fil.length > 0) {
118
+ const { path, depth } = par;
119
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
120
+ const awaited = await Promise.all(slice);
121
+ for (const entry of awaited) {
122
+ if (!entry) continue;
123
+ if (this.destroyed) return;
124
+ const entryType = await this._getEntryType(entry);
125
+ if (entryType === "directory" && this._directoryFilter(entry)) {
126
+ if (depth <= this._maxDepth) this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
127
+ if (this._wantsDir) {
128
+ this.push(entry);
129
+ batch--;
130
+ }
131
+ } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
132
+ if (this._wantsFile) {
133
+ this.push(entry);
134
+ batch--;
135
+ }
136
+ }
137
+ }
138
+ } else {
139
+ const parent = this.parents.pop();
140
+ if (!parent) {
141
+ this.push(null);
142
+ break;
143
+ }
144
+ this.parent = await parent;
145
+ if (this.destroyed) return;
146
+ }
147
+ }
148
+ } catch (error) {
149
+ this.destroy(error);
150
+ } finally {
151
+ this.reading = false;
152
+ }
153
+ }
154
+ async _exploreDir(path, depth) {
155
+ let files;
156
+ try {
157
+ files = await readdir(path, this._rdOptions);
158
+ } catch (error) {
159
+ this._onError(error);
160
+ }
161
+ return {
162
+ files,
163
+ depth,
164
+ path
165
+ };
166
+ }
167
+ async _formatEntry(dirent, path) {
168
+ let entry;
169
+ const basename = this._isDirent ? dirent.name : dirent;
170
+ try {
171
+ const fullPath = resolve(join(path, basename));
172
+ entry = {
173
+ path: relative(this._root, fullPath),
174
+ fullPath,
175
+ basename
176
+ };
177
+ entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
178
+ } catch (err) {
179
+ this._onError(err);
180
+ return;
181
+ }
182
+ return entry;
183
+ }
184
+ _onError(err) {
185
+ if (isNormalFlowError(err) && !this.destroyed) this.emit("warn", err);
186
+ else this.destroy(err);
187
+ }
188
+ async _getEntryType(entry) {
189
+ if (!entry && this._statsProp in entry) return "";
190
+ const stats = entry[this._statsProp];
191
+ if (stats.isFile()) return "file";
192
+ if (stats.isDirectory()) return "directory";
193
+ if (stats && stats.isSymbolicLink()) {
194
+ const full = entry.fullPath;
195
+ try {
196
+ const entryRealPath = await realpath(full);
197
+ const entryRealPathStats = await lstat(entryRealPath);
198
+ if (entryRealPathStats.isFile()) return "file";
199
+ if (entryRealPathStats.isDirectory()) {
200
+ const len = entryRealPath.length;
201
+ if (full.startsWith(entryRealPath) && full.substr(len, 1) === sep) {
202
+ const recursiveError = /* @__PURE__ */ new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
203
+ recursiveError.code = RECURSIVE_ERROR_CODE;
204
+ return this._onError(recursiveError);
205
+ }
206
+ return "directory";
207
+ }
208
+ } catch (error) {
209
+ this._onError(error);
210
+ return "";
211
+ }
212
+ }
213
+ }
214
+ _includeAsFile(entry) {
215
+ const stats = entry && entry[this._statsProp];
216
+ return stats && this._wantsEverything && !stats.isDirectory();
217
+ }
218
+ };
219
+ /**
220
+ * Streaming version: Reads all files and directories in given root recursively.
221
+ * Consumes ~constant small amount of RAM.
222
+ * @param root Root directory
223
+ * @param options Options to specify root (start directory), filters and recursion depth
224
+ */
225
+ function readdirp(root, options = {}) {
226
+ let type = options.entryType || options.type;
227
+ if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
228
+ if (type) options.type = type;
229
+ if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
230
+ else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
231
+ else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
232
+ options.root = root;
233
+ return new ReaddirpStream(options);
234
+ }
235
+ //#endregion
236
+ //#region ../../0-framework/3-tooling/cli/node_modules/chokidar/esm/handler.js
237
+ const STR_DATA = "data";
238
+ const STR_CLOSE = "close";
239
+ const EMPTY_FN = () => {};
240
+ const pl = process.platform;
241
+ const isWindows = pl === "win32";
242
+ const isMacos = pl === "darwin";
243
+ const isLinux = pl === "linux";
244
+ const isFreeBSD = pl === "freebsd";
245
+ const isIBMi = type() === "OS400";
246
+ const EVENTS = {
247
+ ALL: "all",
248
+ READY: "ready",
249
+ ADD: "add",
250
+ CHANGE: "change",
251
+ ADD_DIR: "addDir",
252
+ UNLINK: "unlink",
253
+ UNLINK_DIR: "unlinkDir",
254
+ RAW: "raw",
255
+ ERROR: "error"
256
+ };
257
+ const EV = EVENTS;
258
+ const THROTTLE_MODE_WATCH = "watch";
259
+ const statMethods = {
260
+ lstat: lstat$1,
261
+ stat: stat$2
262
+ };
263
+ const KEY_LISTENERS = "listeners";
264
+ const KEY_ERR = "errHandlers";
265
+ const KEY_RAW = "rawEmitters";
266
+ const HANDLER_KEYS = [
267
+ KEY_LISTENERS,
268
+ KEY_ERR,
269
+ KEY_RAW
270
+ ];
271
+ const binaryExtensions = /* @__PURE__ */ new Set([
272
+ "3dm",
273
+ "3ds",
274
+ "3g2",
275
+ "3gp",
276
+ "7z",
277
+ "a",
278
+ "aac",
279
+ "adp",
280
+ "afdesign",
281
+ "afphoto",
282
+ "afpub",
283
+ "ai",
284
+ "aif",
285
+ "aiff",
286
+ "alz",
287
+ "ape",
288
+ "apk",
289
+ "appimage",
290
+ "ar",
291
+ "arj",
292
+ "asf",
293
+ "au",
294
+ "avi",
295
+ "bak",
296
+ "baml",
297
+ "bh",
298
+ "bin",
299
+ "bk",
300
+ "bmp",
301
+ "btif",
302
+ "bz2",
303
+ "bzip2",
304
+ "cab",
305
+ "caf",
306
+ "cgm",
307
+ "class",
308
+ "cmx",
309
+ "cpio",
310
+ "cr2",
311
+ "cur",
312
+ "dat",
313
+ "dcm",
314
+ "deb",
315
+ "dex",
316
+ "djvu",
317
+ "dll",
318
+ "dmg",
319
+ "dng",
320
+ "doc",
321
+ "docm",
322
+ "docx",
323
+ "dot",
324
+ "dotm",
325
+ "dra",
326
+ "DS_Store",
327
+ "dsk",
328
+ "dts",
329
+ "dtshd",
330
+ "dvb",
331
+ "dwg",
332
+ "dxf",
333
+ "ecelp4800",
334
+ "ecelp7470",
335
+ "ecelp9600",
336
+ "egg",
337
+ "eol",
338
+ "eot",
339
+ "epub",
340
+ "exe",
341
+ "f4v",
342
+ "fbs",
343
+ "fh",
344
+ "fla",
345
+ "flac",
346
+ "flatpak",
347
+ "fli",
348
+ "flv",
349
+ "fpx",
350
+ "fst",
351
+ "fvt",
352
+ "g3",
353
+ "gh",
354
+ "gif",
355
+ "graffle",
356
+ "gz",
357
+ "gzip",
358
+ "h261",
359
+ "h263",
360
+ "h264",
361
+ "icns",
362
+ "ico",
363
+ "ief",
364
+ "img",
365
+ "ipa",
366
+ "iso",
367
+ "jar",
368
+ "jpeg",
369
+ "jpg",
370
+ "jpgv",
371
+ "jpm",
372
+ "jxr",
373
+ "key",
374
+ "ktx",
375
+ "lha",
376
+ "lib",
377
+ "lvp",
378
+ "lz",
379
+ "lzh",
380
+ "lzma",
381
+ "lzo",
382
+ "m3u",
383
+ "m4a",
384
+ "m4v",
385
+ "mar",
386
+ "mdi",
387
+ "mht",
388
+ "mid",
389
+ "midi",
390
+ "mj2",
391
+ "mka",
392
+ "mkv",
393
+ "mmr",
394
+ "mng",
395
+ "mobi",
396
+ "mov",
397
+ "movie",
398
+ "mp3",
399
+ "mp4",
400
+ "mp4a",
401
+ "mpeg",
402
+ "mpg",
403
+ "mpga",
404
+ "mxu",
405
+ "nef",
406
+ "npx",
407
+ "numbers",
408
+ "nupkg",
409
+ "o",
410
+ "odp",
411
+ "ods",
412
+ "odt",
413
+ "oga",
414
+ "ogg",
415
+ "ogv",
416
+ "otf",
417
+ "ott",
418
+ "pages",
419
+ "pbm",
420
+ "pcx",
421
+ "pdb",
422
+ "pdf",
423
+ "pea",
424
+ "pgm",
425
+ "pic",
426
+ "png",
427
+ "pnm",
428
+ "pot",
429
+ "potm",
430
+ "potx",
431
+ "ppa",
432
+ "ppam",
433
+ "ppm",
434
+ "pps",
435
+ "ppsm",
436
+ "ppsx",
437
+ "ppt",
438
+ "pptm",
439
+ "pptx",
440
+ "psd",
441
+ "pya",
442
+ "pyc",
443
+ "pyo",
444
+ "pyv",
445
+ "qt",
446
+ "rar",
447
+ "ras",
448
+ "raw",
449
+ "resources",
450
+ "rgb",
451
+ "rip",
452
+ "rlc",
453
+ "rmf",
454
+ "rmvb",
455
+ "rpm",
456
+ "rtf",
457
+ "rz",
458
+ "s3m",
459
+ "s7z",
460
+ "scpt",
461
+ "sgi",
462
+ "shar",
463
+ "snap",
464
+ "sil",
465
+ "sketch",
466
+ "slk",
467
+ "smv",
468
+ "snk",
469
+ "so",
470
+ "stl",
471
+ "suo",
472
+ "sub",
473
+ "swf",
474
+ "tar",
475
+ "tbz",
476
+ "tbz2",
477
+ "tga",
478
+ "tgz",
479
+ "thmx",
480
+ "tif",
481
+ "tiff",
482
+ "tlz",
483
+ "ttc",
484
+ "ttf",
485
+ "txz",
486
+ "udf",
487
+ "uvh",
488
+ "uvi",
489
+ "uvm",
490
+ "uvp",
491
+ "uvs",
492
+ "uvu",
493
+ "viv",
494
+ "vob",
495
+ "war",
496
+ "wav",
497
+ "wax",
498
+ "wbmp",
499
+ "wdp",
500
+ "weba",
501
+ "webm",
502
+ "webp",
503
+ "whl",
504
+ "wim",
505
+ "wm",
506
+ "wma",
507
+ "wmv",
508
+ "wmx",
509
+ "woff",
510
+ "woff2",
511
+ "wrm",
512
+ "wvx",
513
+ "xbm",
514
+ "xif",
515
+ "xla",
516
+ "xlam",
517
+ "xls",
518
+ "xlsb",
519
+ "xlsm",
520
+ "xlsx",
521
+ "xlt",
522
+ "xltm",
523
+ "xltx",
524
+ "xm",
525
+ "xmind",
526
+ "xpi",
527
+ "xpm",
528
+ "xwd",
529
+ "xz",
530
+ "z",
531
+ "zip",
532
+ "zipx"
533
+ ]);
534
+ const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
535
+ const foreach = (val, fn) => {
536
+ if (val instanceof Set) val.forEach(fn);
537
+ else fn(val);
538
+ };
539
+ const addAndConvert = (main, prop, item) => {
540
+ let container = main[prop];
541
+ if (!(container instanceof Set)) main[prop] = container = /* @__PURE__ */ new Set([container]);
542
+ container.add(item);
543
+ };
544
+ const clearItem = (cont) => (key) => {
545
+ const set = cont[key];
546
+ if (set instanceof Set) set.clear();
547
+ else delete cont[key];
548
+ };
549
+ const delFromSet = (main, prop, item) => {
550
+ const container = main[prop];
551
+ if (container instanceof Set) container.delete(item);
552
+ else if (container === item) delete main[prop];
553
+ };
554
+ const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
555
+ const FsWatchInstances = /* @__PURE__ */ new Map();
556
+ /**
557
+ * Instantiates the fs_watch interface
558
+ * @param path to be watched
559
+ * @param options to be passed to fs_watch
560
+ * @param listener main event handler
561
+ * @param errHandler emits info about errors
562
+ * @param emitRaw emits raw event data
563
+ * @returns {NativeFsWatcher}
564
+ */
565
+ function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
566
+ const handleEvent = (rawEvent, evPath) => {
567
+ listener(path);
568
+ emitRaw(rawEvent, evPath, { watchedPath: path });
569
+ if (evPath && path !== evPath) fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
570
+ };
571
+ try {
572
+ return watch(path, { persistent: options.persistent }, handleEvent);
573
+ } catch (error) {
574
+ errHandler(error);
575
+ return;
576
+ }
577
+ }
578
+ /**
579
+ * Helper for passing fs_watch event data to a collection of listeners
580
+ * @param fullPath absolute path bound to fs_watch instance
581
+ */
582
+ const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
583
+ const cont = FsWatchInstances.get(fullPath);
584
+ if (!cont) return;
585
+ foreach(cont[listenerType], (listener) => {
586
+ listener(val1, val2, val3);
587
+ });
588
+ };
589
+ /**
590
+ * Instantiates the fs_watch interface or binds listeners
591
+ * to an existing one covering the same file system entry
592
+ * @param path
593
+ * @param fullPath absolute path
594
+ * @param options to be passed to fs_watch
595
+ * @param handlers container for event listener functions
596
+ */
597
+ const setFsWatchListener = (path, fullPath, options, handlers) => {
598
+ const { listener, errHandler, rawEmitter } = handlers;
599
+ let cont = FsWatchInstances.get(fullPath);
600
+ let watcher;
601
+ if (!options.persistent) {
602
+ watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
603
+ if (!watcher) return;
604
+ return watcher.close.bind(watcher);
605
+ }
606
+ if (cont) {
607
+ addAndConvert(cont, KEY_LISTENERS, listener);
608
+ addAndConvert(cont, KEY_ERR, errHandler);
609
+ addAndConvert(cont, KEY_RAW, rawEmitter);
610
+ } else {
611
+ watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
612
+ if (!watcher) return;
613
+ watcher.on(EV.ERROR, async (error) => {
614
+ const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
615
+ if (cont) cont.watcherUnusable = true;
616
+ if (isWindows && error.code === "EPERM") try {
617
+ await (await open(path, "r")).close();
618
+ broadcastErr(error);
619
+ } catch (err) {}
620
+ else broadcastErr(error);
621
+ });
622
+ cont = {
623
+ listeners: listener,
624
+ errHandlers: errHandler,
625
+ rawEmitters: rawEmitter,
626
+ watcher
627
+ };
628
+ FsWatchInstances.set(fullPath, cont);
629
+ }
630
+ return () => {
631
+ delFromSet(cont, KEY_LISTENERS, listener);
632
+ delFromSet(cont, KEY_ERR, errHandler);
633
+ delFromSet(cont, KEY_RAW, rawEmitter);
634
+ if (isEmptySet(cont.listeners)) {
635
+ cont.watcher.close();
636
+ FsWatchInstances.delete(fullPath);
637
+ HANDLER_KEYS.forEach(clearItem(cont));
638
+ cont.watcher = void 0;
639
+ Object.freeze(cont);
640
+ }
641
+ };
642
+ };
643
+ const FsWatchFileInstances = /* @__PURE__ */ new Map();
644
+ /**
645
+ * Instantiates the fs_watchFile interface or binds listeners
646
+ * to an existing one covering the same file system entry
647
+ * @param path to be watched
648
+ * @param fullPath absolute path
649
+ * @param options options to be passed to fs_watchFile
650
+ * @param handlers container for event listener functions
651
+ * @returns closer
652
+ */
653
+ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
654
+ const { listener, rawEmitter } = handlers;
655
+ let cont = FsWatchFileInstances.get(fullPath);
656
+ const copts = cont && cont.options;
657
+ if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
658
+ unwatchFile(fullPath);
659
+ cont = void 0;
660
+ }
661
+ if (cont) {
662
+ addAndConvert(cont, KEY_LISTENERS, listener);
663
+ addAndConvert(cont, KEY_RAW, rawEmitter);
664
+ } else {
665
+ cont = {
666
+ listeners: listener,
667
+ rawEmitters: rawEmitter,
668
+ options,
669
+ watcher: watchFile(fullPath, options, (curr, prev) => {
670
+ foreach(cont.rawEmitters, (rawEmitter) => {
671
+ rawEmitter(EV.CHANGE, fullPath, {
672
+ curr,
673
+ prev
674
+ });
675
+ });
676
+ const currmtime = curr.mtimeMs;
677
+ if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener) => listener(path, curr));
678
+ })
679
+ };
680
+ FsWatchFileInstances.set(fullPath, cont);
681
+ }
682
+ return () => {
683
+ delFromSet(cont, KEY_LISTENERS, listener);
684
+ delFromSet(cont, KEY_RAW, rawEmitter);
685
+ if (isEmptySet(cont.listeners)) {
686
+ FsWatchFileInstances.delete(fullPath);
687
+ unwatchFile(fullPath);
688
+ cont.options = cont.watcher = void 0;
689
+ Object.freeze(cont);
690
+ }
691
+ };
692
+ };
693
+ /**
694
+ * @mixin
695
+ */
696
+ var NodeFsHandler = class {
697
+ constructor(fsW) {
698
+ this.fsw = fsW;
699
+ this._boundHandleError = (error) => fsW._handleError(error);
700
+ }
701
+ /**
702
+ * Watch file for changes with fs_watchFile or fs_watch.
703
+ * @param path to file or dir
704
+ * @param listener on fs change
705
+ * @returns closer for the watcher instance
706
+ */
707
+ _watchWithNodeFs(path, listener) {
708
+ const opts = this.fsw.options;
709
+ const directory = sysPath.dirname(path);
710
+ const basename = sysPath.basename(path);
711
+ this.fsw._getWatchedDir(directory).add(basename);
712
+ const absolutePath = sysPath.resolve(path);
713
+ const options = { persistent: opts.persistent };
714
+ if (!listener) listener = EMPTY_FN;
715
+ let closer;
716
+ if (opts.usePolling) {
717
+ options.interval = opts.interval !== opts.binaryInterval && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
718
+ closer = setFsWatchFileListener(path, absolutePath, options, {
719
+ listener,
720
+ rawEmitter: this.fsw._emitRaw
721
+ });
722
+ } else closer = setFsWatchListener(path, absolutePath, options, {
723
+ listener,
724
+ errHandler: this._boundHandleError,
725
+ rawEmitter: this.fsw._emitRaw
726
+ });
727
+ return closer;
728
+ }
729
+ /**
730
+ * Watch a file and emit add event if warranted.
731
+ * @returns closer for the watcher instance
732
+ */
733
+ _handleFile(file, stats, initialAdd) {
734
+ if (this.fsw.closed) return;
735
+ const dirname = sysPath.dirname(file);
736
+ const basename = sysPath.basename(file);
737
+ const parent = this.fsw._getWatchedDir(dirname);
738
+ let prevStats = stats;
739
+ if (parent.has(basename)) return;
740
+ const listener = async (path, newStats) => {
741
+ if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
742
+ if (!newStats || newStats.mtimeMs === 0) try {
743
+ const newStats = await stat$2(file);
744
+ if (this.fsw.closed) return;
745
+ const at = newStats.atimeMs;
746
+ const mt = newStats.mtimeMs;
747
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
748
+ if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
749
+ this.fsw._closeFile(path);
750
+ prevStats = newStats;
751
+ const closer = this._watchWithNodeFs(file, listener);
752
+ if (closer) this.fsw._addPathCloser(path, closer);
753
+ } else prevStats = newStats;
754
+ } catch (error) {
755
+ this.fsw._remove(dirname, basename);
756
+ }
757
+ else if (parent.has(basename)) {
758
+ const at = newStats.atimeMs;
759
+ const mt = newStats.mtimeMs;
760
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
761
+ prevStats = newStats;
762
+ }
763
+ };
764
+ const closer = this._watchWithNodeFs(file, listener);
765
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
766
+ if (!this.fsw._throttle(EV.ADD, file, 0)) return;
767
+ this.fsw._emit(EV.ADD, file, stats);
768
+ }
769
+ return closer;
770
+ }
771
+ /**
772
+ * Handle symlinks encountered while reading a dir.
773
+ * @param entry returned by readdirp
774
+ * @param directory path of dir being read
775
+ * @param path of this item
776
+ * @param item basename of this item
777
+ * @returns true if no more processing is needed for this entry.
778
+ */
779
+ async _handleSymlink(entry, directory, path, item) {
780
+ if (this.fsw.closed) return;
781
+ const full = entry.fullPath;
782
+ const dir = this.fsw._getWatchedDir(directory);
783
+ if (!this.fsw.options.followSymlinks) {
784
+ this.fsw._incrReadyCount();
785
+ let linkPath;
786
+ try {
787
+ linkPath = await realpath$1(path);
788
+ } catch (e) {
789
+ this.fsw._emitReady();
790
+ return true;
791
+ }
792
+ if (this.fsw.closed) return;
793
+ if (dir.has(item)) {
794
+ if (this.fsw._symlinkPaths.get(full) !== linkPath) {
795
+ this.fsw._symlinkPaths.set(full, linkPath);
796
+ this.fsw._emit(EV.CHANGE, path, entry.stats);
797
+ }
798
+ } else {
799
+ dir.add(item);
800
+ this.fsw._symlinkPaths.set(full, linkPath);
801
+ this.fsw._emit(EV.ADD, path, entry.stats);
802
+ }
803
+ this.fsw._emitReady();
804
+ return true;
805
+ }
806
+ if (this.fsw._symlinkPaths.has(full)) return true;
807
+ this.fsw._symlinkPaths.set(full, true);
808
+ }
809
+ _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
810
+ directory = sysPath.join(directory, "");
811
+ throttler = this.fsw._throttle("readdir", directory, 1e3);
812
+ if (!throttler) return;
813
+ const previous = this.fsw._getWatchedDir(wh.path);
814
+ const current = /* @__PURE__ */ new Set();
815
+ let stream = this.fsw._readdirp(directory, {
816
+ fileFilter: (entry) => wh.filterPath(entry),
817
+ directoryFilter: (entry) => wh.filterDir(entry)
818
+ });
819
+ if (!stream) return;
820
+ stream.on(STR_DATA, async (entry) => {
821
+ if (this.fsw.closed) {
822
+ stream = void 0;
823
+ return;
824
+ }
825
+ const item = entry.path;
826
+ let path = sysPath.join(directory, item);
827
+ current.add(item);
828
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) return;
829
+ if (this.fsw.closed) {
830
+ stream = void 0;
831
+ return;
832
+ }
833
+ if (item === target || !target && !previous.has(item)) {
834
+ this.fsw._incrReadyCount();
835
+ path = sysPath.join(dir, sysPath.relative(dir, path));
836
+ this._addToNodeFs(path, initialAdd, wh, depth + 1);
837
+ }
838
+ }).on(EV.ERROR, this._boundHandleError);
839
+ return new Promise((resolve, reject) => {
840
+ if (!stream) return reject();
841
+ stream.once("end", () => {
842
+ if (this.fsw.closed) {
843
+ stream = void 0;
844
+ return;
845
+ }
846
+ const wasThrottled = throttler ? throttler.clear() : false;
847
+ resolve(void 0);
848
+ previous.getChildren().filter((item) => {
849
+ return item !== directory && !current.has(item);
850
+ }).forEach((item) => {
851
+ this.fsw._remove(directory, item);
852
+ });
853
+ stream = void 0;
854
+ if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
855
+ });
856
+ });
857
+ }
858
+ /**
859
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
860
+ * @param dir fs path
861
+ * @param stats
862
+ * @param initialAdd
863
+ * @param depth relative to user-supplied path
864
+ * @param target child path targeted for watch
865
+ * @param wh Common watch helpers for this path
866
+ * @param realpath
867
+ * @returns closer for the watcher instance.
868
+ */
869
+ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
870
+ const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
871
+ const tracked = parentDir.has(sysPath.basename(dir));
872
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
873
+ parentDir.add(sysPath.basename(dir));
874
+ this.fsw._getWatchedDir(dir);
875
+ let throttler;
876
+ let closer;
877
+ const oDepth = this.fsw.options.depth;
878
+ if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
879
+ if (!target) {
880
+ await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
881
+ if (this.fsw.closed) return;
882
+ }
883
+ closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
884
+ if (stats && stats.mtimeMs === 0) return;
885
+ this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
886
+ });
887
+ }
888
+ return closer;
889
+ }
890
+ /**
891
+ * Handle added file, directory, or glob pattern.
892
+ * Delegates call to _handleFile / _handleDir after checks.
893
+ * @param path to file or ir
894
+ * @param initialAdd was the file added at watch instantiation?
895
+ * @param priorWh depth relative to user-supplied path
896
+ * @param depth Child path actually targeted for watch
897
+ * @param target Child path actually targeted for watch
898
+ */
899
+ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
900
+ const ready = this.fsw._emitReady;
901
+ if (this.fsw._isIgnored(path) || this.fsw.closed) {
902
+ ready();
903
+ return false;
904
+ }
905
+ const wh = this.fsw._getWatchHelpers(path);
906
+ if (priorWh) {
907
+ wh.filterPath = (entry) => priorWh.filterPath(entry);
908
+ wh.filterDir = (entry) => priorWh.filterDir(entry);
909
+ }
910
+ try {
911
+ const stats = await statMethods[wh.statMethod](wh.watchPath);
912
+ if (this.fsw.closed) return;
913
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
914
+ ready();
915
+ return false;
916
+ }
917
+ const follow = this.fsw.options.followSymlinks;
918
+ let closer;
919
+ if (stats.isDirectory()) {
920
+ const absPath = sysPath.resolve(path);
921
+ const targetPath = follow ? await realpath$1(path) : path;
922
+ if (this.fsw.closed) return;
923
+ closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
924
+ if (this.fsw.closed) return;
925
+ if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
926
+ } else if (stats.isSymbolicLink()) {
927
+ const targetPath = follow ? await realpath$1(path) : path;
928
+ if (this.fsw.closed) return;
929
+ const parent = sysPath.dirname(wh.watchPath);
930
+ this.fsw._getWatchedDir(parent).add(wh.watchPath);
931
+ this.fsw._emit(EV.ADD, wh.watchPath, stats);
932
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
933
+ if (this.fsw.closed) return;
934
+ if (targetPath !== void 0) this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
935
+ } else closer = this._handleFile(wh.watchPath, stats, initialAdd);
936
+ ready();
937
+ if (closer) this.fsw._addPathCloser(path, closer);
938
+ return false;
939
+ } catch (error) {
940
+ if (this.fsw._handleError(error)) {
941
+ ready();
942
+ return path;
943
+ }
944
+ }
945
+ }
946
+ };
947
+ //#endregion
948
+ //#region ../../0-framework/3-tooling/cli/node_modules/chokidar/esm/index.js
949
+ /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
950
+ const SLASH = "/";
951
+ const SLASH_SLASH = "//";
952
+ const ONE_DOT = ".";
953
+ const TWO_DOTS = "..";
954
+ const STRING_TYPE = "string";
955
+ const BACK_SLASH_RE = /\\/g;
956
+ const DOUBLE_SLASH_RE = /\/\//;
957
+ const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
958
+ const REPLACER_RE = /^\.[/\\]/;
959
+ function arrify(item) {
960
+ return Array.isArray(item) ? item : [item];
961
+ }
962
+ const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
963
+ function createPattern(matcher) {
964
+ if (typeof matcher === "function") return matcher;
965
+ if (typeof matcher === "string") return (string) => matcher === string;
966
+ if (matcher instanceof RegExp) return (string) => matcher.test(string);
967
+ if (typeof matcher === "object" && matcher !== null) return (string) => {
968
+ if (matcher.path === string) return true;
969
+ if (matcher.recursive) {
970
+ const relative = sysPath.relative(matcher.path, string);
971
+ if (!relative) return false;
972
+ return !relative.startsWith("..") && !sysPath.isAbsolute(relative);
973
+ }
974
+ return false;
975
+ };
976
+ return () => false;
977
+ }
978
+ function normalizePath(path) {
979
+ if (typeof path !== "string") throw new Error("string expected");
980
+ path = sysPath.normalize(path);
981
+ path = path.replace(/\\/g, "/");
982
+ let prepend = false;
983
+ if (path.startsWith("//")) prepend = true;
984
+ const DOUBLE_SLASH_RE = /\/\//;
985
+ while (path.match(DOUBLE_SLASH_RE)) path = path.replace(DOUBLE_SLASH_RE, "/");
986
+ if (prepend) path = "/" + path;
987
+ return path;
988
+ }
989
+ function matchPatterns(patterns, testString, stats) {
990
+ const path = normalizePath(testString);
991
+ for (let index = 0; index < patterns.length; index++) {
992
+ const pattern = patterns[index];
993
+ if (pattern(path, stats)) return true;
994
+ }
995
+ return false;
996
+ }
997
+ function anymatch(matchers, testString) {
998
+ if (matchers == null) throw new TypeError("anymatch: specify first argument");
999
+ const patterns = arrify(matchers).map((matcher) => createPattern(matcher));
1000
+ if (testString == null) return (testString, stats) => {
1001
+ return matchPatterns(patterns, testString, stats);
1002
+ };
1003
+ return matchPatterns(patterns, testString);
1004
+ }
1005
+ const unifyPaths = (paths_) => {
1006
+ const paths = arrify(paths_).flat();
1007
+ if (!paths.every((p) => typeof p === STRING_TYPE)) throw new TypeError(`Non-string provided as watch path: ${paths}`);
1008
+ return paths.map(normalizePathToUnix);
1009
+ };
1010
+ const toUnix = (string) => {
1011
+ let str = string.replace(BACK_SLASH_RE, SLASH);
1012
+ let prepend = false;
1013
+ if (str.startsWith(SLASH_SLASH)) prepend = true;
1014
+ while (str.match(DOUBLE_SLASH_RE)) str = str.replace(DOUBLE_SLASH_RE, SLASH);
1015
+ if (prepend) str = SLASH + str;
1016
+ return str;
1017
+ };
1018
+ const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
1019
+ const normalizeIgnored = (cwd = "") => (path) => {
1020
+ if (typeof path === "string") return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
1021
+ else return path;
1022
+ };
1023
+ const getAbsolutePath = (path, cwd) => {
1024
+ if (sysPath.isAbsolute(path)) return path;
1025
+ return sysPath.join(cwd, path);
1026
+ };
1027
+ const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
1028
+ /**
1029
+ * Directory entry.
1030
+ */
1031
+ var DirEntry = class {
1032
+ constructor(dir, removeWatcher) {
1033
+ this.path = dir;
1034
+ this._removeWatcher = removeWatcher;
1035
+ this.items = /* @__PURE__ */ new Set();
1036
+ }
1037
+ add(item) {
1038
+ const { items } = this;
1039
+ if (!items) return;
1040
+ if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
1041
+ }
1042
+ async remove(item) {
1043
+ const { items } = this;
1044
+ if (!items) return;
1045
+ items.delete(item);
1046
+ if (items.size > 0) return;
1047
+ const dir = this.path;
1048
+ try {
1049
+ await readdir$1(dir);
1050
+ } catch (err) {
1051
+ if (this._removeWatcher) this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
1052
+ }
1053
+ }
1054
+ has(item) {
1055
+ const { items } = this;
1056
+ if (!items) return;
1057
+ return items.has(item);
1058
+ }
1059
+ getChildren() {
1060
+ const { items } = this;
1061
+ if (!items) return [];
1062
+ return [...items.values()];
1063
+ }
1064
+ dispose() {
1065
+ this.items.clear();
1066
+ this.path = "";
1067
+ this._removeWatcher = EMPTY_FN;
1068
+ this.items = EMPTY_SET;
1069
+ Object.freeze(this);
1070
+ }
1071
+ };
1072
+ const STAT_METHOD_F = "stat";
1073
+ const STAT_METHOD_L = "lstat";
1074
+ var WatchHelper = class {
1075
+ constructor(path, follow, fsw) {
1076
+ this.fsw = fsw;
1077
+ const watchPath = path;
1078
+ this.path = path = path.replace(REPLACER_RE, "");
1079
+ this.watchPath = watchPath;
1080
+ this.fullWatchPath = sysPath.resolve(watchPath);
1081
+ this.dirParts = [];
1082
+ this.dirParts.forEach((parts) => {
1083
+ if (parts.length > 1) parts.pop();
1084
+ });
1085
+ this.followSymlinks = follow;
1086
+ this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
1087
+ }
1088
+ entryPath(entry) {
1089
+ return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
1090
+ }
1091
+ filterPath(entry) {
1092
+ const { stats } = entry;
1093
+ if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
1094
+ const resolvedPath = this.entryPath(entry);
1095
+ return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
1096
+ }
1097
+ filterDir(entry) {
1098
+ return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
1099
+ }
1100
+ };
1101
+ /**
1102
+ * Watches files & directories for changes. Emitted events:
1103
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
1104
+ *
1105
+ * new FSWatcher()
1106
+ * .add(directories)
1107
+ * .on('add', path => log('File', path, 'was added'))
1108
+ */
1109
+ var FSWatcher = class extends EventEmitter {
1110
+ constructor(_opts = {}) {
1111
+ super();
1112
+ this.closed = false;
1113
+ this._closers = /* @__PURE__ */ new Map();
1114
+ this._ignoredPaths = /* @__PURE__ */ new Set();
1115
+ this._throttled = /* @__PURE__ */ new Map();
1116
+ this._streams = /* @__PURE__ */ new Set();
1117
+ this._symlinkPaths = /* @__PURE__ */ new Map();
1118
+ this._watched = /* @__PURE__ */ new Map();
1119
+ this._pendingWrites = /* @__PURE__ */ new Map();
1120
+ this._pendingUnlinks = /* @__PURE__ */ new Map();
1121
+ this._readyCount = 0;
1122
+ this._readyEmitted = false;
1123
+ const awf = _opts.awaitWriteFinish;
1124
+ const DEF_AWF = {
1125
+ stabilityThreshold: 2e3,
1126
+ pollInterval: 100
1127
+ };
1128
+ const opts = {
1129
+ persistent: true,
1130
+ ignoreInitial: false,
1131
+ ignorePermissionErrors: false,
1132
+ interval: 100,
1133
+ binaryInterval: 300,
1134
+ followSymlinks: true,
1135
+ usePolling: false,
1136
+ atomic: true,
1137
+ ..._opts,
1138
+ ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
1139
+ awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? {
1140
+ ...DEF_AWF,
1141
+ ...awf
1142
+ } : false
1143
+ };
1144
+ if (isIBMi) opts.usePolling = true;
1145
+ if (opts.atomic === void 0) opts.atomic = !opts.usePolling;
1146
+ const envPoll = process.env.CHOKIDAR_USEPOLLING;
1147
+ if (envPoll !== void 0) {
1148
+ const envLower = envPoll.toLowerCase();
1149
+ if (envLower === "false" || envLower === "0") opts.usePolling = false;
1150
+ else if (envLower === "true" || envLower === "1") opts.usePolling = true;
1151
+ else opts.usePolling = !!envLower;
1152
+ }
1153
+ const envInterval = process.env.CHOKIDAR_INTERVAL;
1154
+ if (envInterval) opts.interval = Number.parseInt(envInterval, 10);
1155
+ let readyCalls = 0;
1156
+ this._emitReady = () => {
1157
+ readyCalls++;
1158
+ if (readyCalls >= this._readyCount) {
1159
+ this._emitReady = EMPTY_FN;
1160
+ this._readyEmitted = true;
1161
+ process.nextTick(() => this.emit(EVENTS.READY));
1162
+ }
1163
+ };
1164
+ this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
1165
+ this._boundRemove = this._remove.bind(this);
1166
+ this.options = opts;
1167
+ this._nodeFsHandler = new NodeFsHandler(this);
1168
+ Object.freeze(opts);
1169
+ }
1170
+ _addIgnoredPath(matcher) {
1171
+ if (isMatcherObject(matcher)) {
1172
+ for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
1173
+ }
1174
+ this._ignoredPaths.add(matcher);
1175
+ }
1176
+ _removeIgnoredPath(matcher) {
1177
+ this._ignoredPaths.delete(matcher);
1178
+ if (typeof matcher === "string") {
1179
+ for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher) this._ignoredPaths.delete(ignored);
1180
+ }
1181
+ }
1182
+ /**
1183
+ * Adds paths to be watched on an existing FSWatcher instance.
1184
+ * @param paths_ file or file list. Other arguments are unused
1185
+ */
1186
+ add(paths_, _origAdd, _internal) {
1187
+ const { cwd } = this.options;
1188
+ this.closed = false;
1189
+ this._closePromise = void 0;
1190
+ let paths = unifyPaths(paths_);
1191
+ if (cwd) paths = paths.map((path) => {
1192
+ return getAbsolutePath(path, cwd);
1193
+ });
1194
+ paths.forEach((path) => {
1195
+ this._removeIgnoredPath(path);
1196
+ });
1197
+ this._userIgnored = void 0;
1198
+ if (!this._readyCount) this._readyCount = 0;
1199
+ this._readyCount += paths.length;
1200
+ Promise.all(paths.map(async (path) => {
1201
+ const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
1202
+ if (res) this._emitReady();
1203
+ return res;
1204
+ })).then((results) => {
1205
+ if (this.closed) return;
1206
+ results.forEach((item) => {
1207
+ if (item) this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
1208
+ });
1209
+ });
1210
+ return this;
1211
+ }
1212
+ /**
1213
+ * Close watchers or start ignoring events from specified paths.
1214
+ */
1215
+ unwatch(paths_) {
1216
+ if (this.closed) return this;
1217
+ const paths = unifyPaths(paths_);
1218
+ const { cwd } = this.options;
1219
+ paths.forEach((path) => {
1220
+ if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
1221
+ if (cwd) path = sysPath.join(cwd, path);
1222
+ path = sysPath.resolve(path);
1223
+ }
1224
+ this._closePath(path);
1225
+ this._addIgnoredPath(path);
1226
+ if (this._watched.has(path)) this._addIgnoredPath({
1227
+ path,
1228
+ recursive: true
1229
+ });
1230
+ this._userIgnored = void 0;
1231
+ });
1232
+ return this;
1233
+ }
1234
+ /**
1235
+ * Close watchers and remove all listeners from watched paths.
1236
+ */
1237
+ close() {
1238
+ if (this._closePromise) return this._closePromise;
1239
+ this.closed = true;
1240
+ this.removeAllListeners();
1241
+ const closers = [];
1242
+ this._closers.forEach((closerList) => closerList.forEach((closer) => {
1243
+ const promise = closer();
1244
+ if (promise instanceof Promise) closers.push(promise);
1245
+ }));
1246
+ this._streams.forEach((stream) => stream.destroy());
1247
+ this._userIgnored = void 0;
1248
+ this._readyCount = 0;
1249
+ this._readyEmitted = false;
1250
+ this._watched.forEach((dirent) => dirent.dispose());
1251
+ this._closers.clear();
1252
+ this._watched.clear();
1253
+ this._streams.clear();
1254
+ this._symlinkPaths.clear();
1255
+ this._throttled.clear();
1256
+ this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
1257
+ return this._closePromise;
1258
+ }
1259
+ /**
1260
+ * Expose list of watched paths
1261
+ * @returns for chaining
1262
+ */
1263
+ getWatched() {
1264
+ const watchList = {};
1265
+ this._watched.forEach((entry, dir) => {
1266
+ const index = (this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir) || ONE_DOT;
1267
+ watchList[index] = entry.getChildren().sort();
1268
+ });
1269
+ return watchList;
1270
+ }
1271
+ emitWithAll(event, args) {
1272
+ this.emit(event, ...args);
1273
+ if (event !== EVENTS.ERROR) this.emit(EVENTS.ALL, event, ...args);
1274
+ }
1275
+ /**
1276
+ * Normalize and emit events.
1277
+ * Calling _emit DOES NOT MEAN emit() would be called!
1278
+ * @param event Type of event
1279
+ * @param path File or directory path
1280
+ * @param stats arguments to be passed with event
1281
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1282
+ */
1283
+ async _emit(event, path, stats) {
1284
+ if (this.closed) return;
1285
+ const opts = this.options;
1286
+ if (isWindows) path = sysPath.normalize(path);
1287
+ if (opts.cwd) path = sysPath.relative(opts.cwd, path);
1288
+ const args = [path];
1289
+ if (stats != null) args.push(stats);
1290
+ const awf = opts.awaitWriteFinish;
1291
+ let pw;
1292
+ if (awf && (pw = this._pendingWrites.get(path))) {
1293
+ pw.lastChange = /* @__PURE__ */ new Date();
1294
+ return this;
1295
+ }
1296
+ if (opts.atomic) {
1297
+ if (event === EVENTS.UNLINK) {
1298
+ this._pendingUnlinks.set(path, [event, ...args]);
1299
+ setTimeout(() => {
1300
+ this._pendingUnlinks.forEach((entry, path) => {
1301
+ this.emit(...entry);
1302
+ this.emit(EVENTS.ALL, ...entry);
1303
+ this._pendingUnlinks.delete(path);
1304
+ });
1305
+ }, typeof opts.atomic === "number" ? opts.atomic : 100);
1306
+ return this;
1307
+ }
1308
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
1309
+ event = EVENTS.CHANGE;
1310
+ this._pendingUnlinks.delete(path);
1311
+ }
1312
+ }
1313
+ if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
1314
+ const awfEmit = (err, stats) => {
1315
+ if (err) {
1316
+ event = EVENTS.ERROR;
1317
+ args[0] = err;
1318
+ this.emitWithAll(event, args);
1319
+ } else if (stats) {
1320
+ if (args.length > 1) args[1] = stats;
1321
+ else args.push(stats);
1322
+ this.emitWithAll(event, args);
1323
+ }
1324
+ };
1325
+ this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
1326
+ return this;
1327
+ }
1328
+ if (event === EVENTS.CHANGE) {
1329
+ if (!this._throttle(EVENTS.CHANGE, path, 50)) return this;
1330
+ }
1331
+ if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
1332
+ const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
1333
+ let stats;
1334
+ try {
1335
+ stats = await stat$2(fullPath);
1336
+ } catch (err) {}
1337
+ if (!stats || this.closed) return;
1338
+ args.push(stats);
1339
+ }
1340
+ this.emitWithAll(event, args);
1341
+ return this;
1342
+ }
1343
+ /**
1344
+ * Common handler for errors
1345
+ * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1346
+ */
1347
+ _handleError(error) {
1348
+ const code = error && error.code;
1349
+ if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) this.emit(EVENTS.ERROR, error);
1350
+ return error || this.closed;
1351
+ }
1352
+ /**
1353
+ * Helper utility for throttling
1354
+ * @param actionType type being throttled
1355
+ * @param path being acted upon
1356
+ * @param timeout duration of time to suppress duplicate actions
1357
+ * @returns tracking object or false if action should be suppressed
1358
+ */
1359
+ _throttle(actionType, path, timeout) {
1360
+ if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
1361
+ const action = this._throttled.get(actionType);
1362
+ if (!action) throw new Error("invalid throttle");
1363
+ const actionPath = action.get(path);
1364
+ if (actionPath) {
1365
+ actionPath.count++;
1366
+ return false;
1367
+ }
1368
+ let timeoutObject;
1369
+ const clear = () => {
1370
+ const item = action.get(path);
1371
+ const count = item ? item.count : 0;
1372
+ action.delete(path);
1373
+ clearTimeout(timeoutObject);
1374
+ if (item) clearTimeout(item.timeoutObject);
1375
+ return count;
1376
+ };
1377
+ timeoutObject = setTimeout(clear, timeout);
1378
+ const thr = {
1379
+ timeoutObject,
1380
+ clear,
1381
+ count: 0
1382
+ };
1383
+ action.set(path, thr);
1384
+ return thr;
1385
+ }
1386
+ _incrReadyCount() {
1387
+ return this._readyCount++;
1388
+ }
1389
+ /**
1390
+ * Awaits write operation to finish.
1391
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
1392
+ * @param path being acted upon
1393
+ * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
1394
+ * @param event
1395
+ * @param awfEmit Callback to be called when ready for event to be emitted.
1396
+ */
1397
+ _awaitWriteFinish(path, threshold, event, awfEmit) {
1398
+ const awf = this.options.awaitWriteFinish;
1399
+ if (typeof awf !== "object") return;
1400
+ const pollInterval = awf.pollInterval;
1401
+ let timeoutHandler;
1402
+ let fullPath = path;
1403
+ if (this.options.cwd && !sysPath.isAbsolute(path)) fullPath = sysPath.join(this.options.cwd, path);
1404
+ const now = /* @__PURE__ */ new Date();
1405
+ const writes = this._pendingWrites;
1406
+ function awaitWriteFinishFn(prevStat) {
1407
+ stat(fullPath, (err, curStat) => {
1408
+ if (err || !writes.has(path)) {
1409
+ if (err && err.code !== "ENOENT") awfEmit(err);
1410
+ return;
1411
+ }
1412
+ const now = Number(/* @__PURE__ */ new Date());
1413
+ if (prevStat && curStat.size !== prevStat.size) writes.get(path).lastChange = now;
1414
+ if (now - writes.get(path).lastChange >= threshold) {
1415
+ writes.delete(path);
1416
+ awfEmit(void 0, curStat);
1417
+ } else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
1418
+ });
1419
+ }
1420
+ if (!writes.has(path)) {
1421
+ writes.set(path, {
1422
+ lastChange: now,
1423
+ cancelWait: () => {
1424
+ writes.delete(path);
1425
+ clearTimeout(timeoutHandler);
1426
+ return event;
1427
+ }
1428
+ });
1429
+ timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
1430
+ }
1431
+ }
1432
+ /**
1433
+ * Determines whether user has asked to ignore this path.
1434
+ */
1435
+ _isIgnored(path, stats) {
1436
+ if (this.options.atomic && DOT_RE.test(path)) return true;
1437
+ if (!this._userIgnored) {
1438
+ const { cwd } = this.options;
1439
+ const ignored = (this.options.ignored || []).map(normalizeIgnored(cwd));
1440
+ const list = [...[...this._ignoredPaths].map(normalizeIgnored(cwd)), ...ignored];
1441
+ this._userIgnored = anymatch(list, void 0);
1442
+ }
1443
+ return this._userIgnored(path, stats);
1444
+ }
1445
+ _isntIgnored(path, stat) {
1446
+ return !this._isIgnored(path, stat);
1447
+ }
1448
+ /**
1449
+ * Provides a set of common helpers and properties relating to symlink handling.
1450
+ * @param path file or directory pattern being watched
1451
+ */
1452
+ _getWatchHelpers(path) {
1453
+ return new WatchHelper(path, this.options.followSymlinks, this);
1454
+ }
1455
+ /**
1456
+ * Provides directory tracking objects
1457
+ * @param directory path of the directory
1458
+ */
1459
+ _getWatchedDir(directory) {
1460
+ const dir = sysPath.resolve(directory);
1461
+ if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
1462
+ return this._watched.get(dir);
1463
+ }
1464
+ /**
1465
+ * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
1466
+ */
1467
+ _hasReadPermissions(stats) {
1468
+ if (this.options.ignorePermissionErrors) return true;
1469
+ return Boolean(Number(stats.mode) & 256);
1470
+ }
1471
+ /**
1472
+ * Handles emitting unlink events for
1473
+ * files and directories, and via recursion, for
1474
+ * files and directories within directories that are unlinked
1475
+ * @param directory within which the following item is located
1476
+ * @param item base path of item/directory
1477
+ */
1478
+ _remove(directory, item, isDirectory) {
1479
+ const path = sysPath.join(directory, item);
1480
+ const fullPath = sysPath.resolve(path);
1481
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
1482
+ if (!this._throttle("remove", path, 100)) return;
1483
+ if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
1484
+ this._getWatchedDir(path).getChildren().forEach((nested) => this._remove(path, nested));
1485
+ const parent = this._getWatchedDir(directory);
1486
+ const wasTracked = parent.has(item);
1487
+ parent.remove(item);
1488
+ if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
1489
+ let relPath = path;
1490
+ if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
1491
+ if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
1492
+ if (this._pendingWrites.get(relPath).cancelWait() === EVENTS.ADD) return;
1493
+ }
1494
+ this._watched.delete(path);
1495
+ this._watched.delete(fullPath);
1496
+ const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
1497
+ if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
1498
+ this._closePath(path);
1499
+ }
1500
+ /**
1501
+ * Closes all watchers for a path
1502
+ */
1503
+ _closePath(path) {
1504
+ this._closeFile(path);
1505
+ const dir = sysPath.dirname(path);
1506
+ this._getWatchedDir(dir).remove(sysPath.basename(path));
1507
+ }
1508
+ /**
1509
+ * Closes only file-specific watchers
1510
+ */
1511
+ _closeFile(path) {
1512
+ const closers = this._closers.get(path);
1513
+ if (!closers) return;
1514
+ closers.forEach((closer) => closer());
1515
+ this._closers.delete(path);
1516
+ }
1517
+ _addPathCloser(path, closer) {
1518
+ if (!closer) return;
1519
+ let list = this._closers.get(path);
1520
+ if (!list) {
1521
+ list = [];
1522
+ this._closers.set(path, list);
1523
+ }
1524
+ list.push(closer);
1525
+ }
1526
+ _readdirp(root, opts) {
1527
+ if (this.closed) return;
1528
+ let stream = readdirp(root, {
1529
+ type: EVENTS.ALL,
1530
+ alwaysStat: true,
1531
+ lstat: true,
1532
+ ...opts,
1533
+ depth: 0
1534
+ });
1535
+ this._streams.add(stream);
1536
+ stream.once(STR_CLOSE, () => {
1537
+ stream = void 0;
1538
+ });
1539
+ stream.once("end", () => {
1540
+ if (stream) {
1541
+ this._streams.delete(stream);
1542
+ stream = void 0;
1543
+ }
1544
+ });
1545
+ return stream;
1546
+ }
1547
+ };
1548
+ /**
1549
+ * Instantiates watcher with paths to be tracked.
1550
+ * @param paths file / directory paths
1551
+ * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
1552
+ * @returns an instance of FSWatcher for chaining.
1553
+ * @example
1554
+ * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
1555
+ * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
1556
+ */
1557
+ function watch$1(paths, options = {}) {
1558
+ const watcher = new FSWatcher(options);
1559
+ watcher.add(paths);
1560
+ return watcher;
1561
+ }
1562
+ var esm_default = {
1563
+ watch: watch$1,
1564
+ FSWatcher
1565
+ };
1566
+ //#endregion
1567
+ //#region ../../0-framework/3-tooling/cli/dist/execute-dev-BMTFWfFc.mjs
1568
+ /**
1569
+ * Local-dev spec § 6 `generate-dev-stack.ts`: like generate-stack.ts but at
1570
+ * `.prisma-composer/dev/alchemy.run.ts`, always Alchemy stage `dev`, using
1571
+ * Alchemy's own `localState()` and no `report` — dev prints its own front
1572
+ * door (run-dev.ts), so core's presentation-free lower() gets nothing to
1573
+ * call back into. The generated module IS the one orchestration point where
1574
+ * dev provenance is resolved (spec § 3 REVISED): it deserializes the
1575
+ * containers, top-level-awaits `resolveLocalTargets(config)` (the lazy
1576
+ * `localTarget` thunks, ADR-0041), and passes
1577
+ * `providers: localTargetProviders(...)` + `state: localState()` explicitly
1578
+ * — `lower()` learns nothing about dev.
1579
+ */
1580
+ const DEV_GENERATED_DIR = ".prisma-composer/dev";
1581
+ const DEV_GENERATED_FILE = "alchemy.run.ts";
1582
+ /** A relative import specifier from `.prisma-composer/dev/alchemy.run.ts` to `target` (posix separators). */
1583
+ function relativeImportSpecifier(generatedDir, target) {
1584
+ const rel = path$1.relative(generatedDir, target).split(path$1.sep).join("/");
1585
+ return rel.startsWith(".") ? rel : `./${rel}`;
1586
+ }
1587
+ function quote(value) {
1588
+ return JSON.stringify(value);
1589
+ }
1590
+ function renderBundle(bundle) {
1591
+ return `{ dir: ${quote(bundle.dir)}, entry: ${quote(bundle.entry)} }`;
1592
+ }
1593
+ function renderOptions(input) {
1594
+ const lines = [];
1595
+ lines.push(` name: ${quote(input.name)},`);
1596
+ lines.push(" bundles: {");
1597
+ for (const [id, bundle] of Object.entries(input.assembled.bundles)) lines.push(` ${quote(id)}: ${renderBundle(bundle)},`);
1598
+ lines.push(" },");
1599
+ lines.push(" providers: localTargetProviders(resolved, containers, devDir),");
1600
+ lines.push(" state: localState(),");
1601
+ return lines.join("\n");
1602
+ }
1603
+ /** Renders the dev stack module's source (tests assert on it without touching disk). */
1604
+ function renderDevStackFile(input) {
1605
+ const generatedDir = path$1.join(input.cwd, DEV_GENERATED_DIR);
1606
+ const appImport = relativeImportSpecifier(generatedDir, input.entryPath);
1607
+ const configImport = relativeImportSpecifier(generatedDir, input.configPath);
1608
+ return `// Generated by \`prisma-composer dev\` — overwritten on every run; do not
1609
+ // edit by hand. Independently runnable from ${quote(input.cwd)}:
1610
+ //
1611
+ // alchemy deploy ${DEV_GENERATED_DIR}/${DEV_GENERATED_FILE} --stage dev
1612
+ //
1613
+ // bisects a CLI bug from an Alchemy bug (deploy-cli.md § Implementation decisions).
1614
+ import * as path from 'node:path';
1615
+ import { deserializeContainers } from '@prisma/composer/config';
1616
+ import { lower } from '@prisma/composer/deploy';
1617
+ import { DEV_DIR, localTargetProviders, resolveLocalTargets } from '@prisma/composer/local-target';
1618
+ import { localState } from 'alchemy/State/LocalState';
1619
+ import config from ${quote(configImport)};
1620
+ import app from ${quote(appImport)};
1621
+
1622
+ const containers = deserializeContainers(config.extensions, process.env);
1623
+ const resolved = await resolveLocalTargets(config);
1624
+ const devDir = path.join(process.cwd(), DEV_DIR);
1625
+
1626
+ export default lower(app, config, {
1627
+ ${renderOptions(input)}
1628
+ });
1629
+ `;
1630
+ }
1631
+ /** Writes the dev stack file, returning its absolute path. */
1632
+ function writeDevStackFile(input) {
1633
+ const generatedDir = path$1.join(input.cwd, DEV_GENERATED_DIR);
1634
+ fs$1.mkdirSync(generatedDir, { recursive: true });
1635
+ const filePath = path$1.join(generatedDir, DEV_GENERATED_FILE);
1636
+ fs$1.writeFileSync(filePath, renderDevStackFile(input));
1637
+ return filePath;
1638
+ }
1639
+ const DEV_STACK_RELATIVE_PATH = path$1.join(DEV_GENERATED_DIR, DEV_GENERATED_FILE);
1640
+ /**
1641
+ * Local-dev spec § 6 `watch.ts`: watches each assembled bundle's declared
1642
+ * `watch` paths (a directory watched recursively, a file watched through
1643
+ * its parent — see `startWatch`), debounced 300 ms and coalesced across
1644
+ * every service — one edit across several files/services still fires
1645
+ * exactly one rebuild.
1646
+ *
1647
+ * The watch ENGINE is `chokidar` v4 (operator decision, design tip 74272d8:
1648
+ * don't-reinvent-the-wheel beats the no-new-deps contract here — it absorbs
1649
+ * the atomic-rename class and the cross-platform recursive-watch
1650
+ * differences; v4 is pure JS, no native code, no glob surface — irrelevant
1651
+ * here anyway, since every target is a literal file or directory path,
1652
+ * never a pattern). The parent-directory indirection for FILE targets stays
1653
+ * OURS (`startWatch` explains why), as does the debounce: chokidar's own
1654
+ * `awaitWriteFinish` is a per-file "has this file's size stopped changing"
1655
+ * poll, a different semantic from "coalesce a burst across many files into
1656
+ * one callback," which is what the dev loop actually needs.
1657
+ */
1658
+ const DEBOUNCE_MS = 300;
1659
+ /** Bundles → watch targets, plus the addresses with nothing watchable (the pinned one-line startup note). */
1660
+ function watchTargetsFrom(bundles) {
1661
+ const targets = [];
1662
+ const unwatchable = [];
1663
+ for (const [address, bundle] of Object.entries(bundles)) {
1664
+ const paths = bundle.watch;
1665
+ if (paths === void 0 || paths.length === 0) {
1666
+ unwatchable.push(address);
1667
+ continue;
1668
+ }
1669
+ targets.push({
1670
+ address,
1671
+ paths
1672
+ });
1673
+ }
1674
+ return {
1675
+ targets,
1676
+ unwatchable
1677
+ };
1678
+ }
1679
+ /**
1680
+ * Watches every target's paths via chokidar, debounced 300 ms and coalesced
1681
+ * across every service, invoking `onChange` once per burst.
1682
+ *
1683
+ * File targets are watched THROUGH their parent directory, filtered to the
1684
+ * exact path: a watch bound directly to a file dies with the file's inode
1685
+ * on Linux, so `rm -rf dist && bun build --outfile dist/x.mjs` — every
1686
+ * rebuild's shape — would go silently unobserved after the first delete
1687
+ * (chokidar absorbs atomic renames, not unlink+recreate of a directly
1688
+ * watched file; proven by the delete-recreate test failing on Linux CI
1689
+ * only). Directory targets are watched recursively as themselves; a
1690
+ * nonexistent path is treated as a file target, so it starts reporting the
1691
+ * moment something creates it.
1692
+ */
1693
+ function startWatch(targets, onChange, onError) {
1694
+ let timer;
1695
+ const trigger = () => {
1696
+ if (timer !== void 0) clearTimeout(timer);
1697
+ timer = setTimeout(() => {
1698
+ timer = void 0;
1699
+ onChange();
1700
+ }, DEBOUNCE_MS);
1701
+ };
1702
+ const fileTargets = /* @__PURE__ */ new Set();
1703
+ const directoryRoots = /* @__PURE__ */ new Set();
1704
+ const parentRoots = /* @__PURE__ */ new Set();
1705
+ for (const target of targets) for (const p of target.paths) {
1706
+ const abs = path$1.resolve(p);
1707
+ let isDirectory = false;
1708
+ try {
1709
+ isDirectory = fs$1.statSync(abs).isDirectory();
1710
+ } catch {}
1711
+ if (isDirectory) directoryRoots.add(abs);
1712
+ else {
1713
+ fileTargets.add(abs);
1714
+ parentRoots.add(path$1.dirname(abs));
1715
+ }
1716
+ }
1717
+ const reportError = (error) => {
1718
+ onError?.(error);
1719
+ };
1720
+ const watchers = [];
1721
+ if (directoryRoots.size > 0) {
1722
+ const directoryWatcher = esm_default.watch([...directoryRoots], { ignoreInitial: true });
1723
+ directoryWatcher.on("all", () => trigger());
1724
+ directoryWatcher.on("error", reportError);
1725
+ watchers.push(directoryWatcher);
1726
+ }
1727
+ if (parentRoots.size > 0) {
1728
+ const parentWatcher = esm_default.watch([...parentRoots], {
1729
+ ignoreInitial: true,
1730
+ depth: 0
1731
+ });
1732
+ parentWatcher.on("all", (_event, eventPath) => {
1733
+ if (fileTargets.has(path$1.resolve(eventPath))) trigger();
1734
+ });
1735
+ parentWatcher.on("error", reportError);
1736
+ watchers.push(parentWatcher);
1737
+ }
1738
+ let markReady = () => {};
1739
+ const allReady = Promise.all(watchers.map((watcher) => new Promise((resolve) => watcher.on("ready", () => resolve())))).then(() => {});
1740
+ return {
1741
+ ready: Promise.race([allReady, new Promise((resolve) => markReady = resolve)]),
1742
+ stop: () => {
1743
+ if (timer !== void 0) clearTimeout(timer);
1744
+ markReady();
1745
+ for (const watcher of watchers) watcher.close();
1746
+ }
1747
+ };
1748
+ }
1749
+ /**
1750
+ * The dev executor — run-dev.ts's pipeline (local-dev spec § 6) with console
1751
+ * and signal handling removed: events out through `onEvent`, lifetime owned by
1752
+ * the returned DevSession. The operation NEVER touches process signal
1753
+ * handlers — the host does (see run-dev.ts). Reached only by lazy import
1754
+ * from dev.ts — this module's static graph transitively loads alchemy's
1755
+ * provider tree, so the control entry must never import it statically.
1756
+ */
1757
+ function failureMessage(error) {
1758
+ return error instanceof Error ? error.message : String(error);
1759
+ }
1760
+ async function mergedEndpoints(attachments) {
1761
+ return (await Promise.all(attachments.map((a) => withEmulatorRetry(() => a.endpoints())))).flat();
1762
+ }
1763
+ /** Runs the full dev pipeline; resolves to a running session or a structured failure. */
1764
+ async function executeDev(input, deps, cwd) {
1765
+ if (process.platform === "win32") return notOk(new CliStructuredError("DEV.PLATFORM_UNSUPPORTED", "local dev is not supported on Windows yet."));
1766
+ const { onEvent } = input;
1767
+ const devDir = path$1.join(cwd, DEV_DIR);
1768
+ let pipeline;
1769
+ let resolved;
1770
+ const containers = /* @__PURE__ */ new Map();
1771
+ try {
1772
+ const pipelineDeps = {
1773
+ runAssembler: deps.runAssembler,
1774
+ config: deps.config,
1775
+ configPath: deps.configPath
1776
+ };
1777
+ pipeline = await runPipeline(input.entry, input.name, cwd, pipelineDeps);
1778
+ const { config, graph, name } = pipeline;
1779
+ resolved = await resolveLocalTargets(config);
1780
+ for (const [id, dev] of resolved) try {
1781
+ containers.set(id, await dev.container.ensure({
1782
+ appName: name,
1783
+ stage: void 0
1784
+ }));
1785
+ } catch (error) {
1786
+ throw toStructured("DEV.CONTAINER_FAILED", error);
1787
+ }
1788
+ if (input.fresh === true) for (const [id, dev] of resolved) {
1789
+ if (dev.teardown === void 0) continue;
1790
+ try {
1791
+ await dev.teardown({
1792
+ container: containers.get(id),
1793
+ stage: void 0
1794
+ });
1795
+ } catch (error) {
1796
+ throw toStructured("DEV.TEARDOWN_FAILED", error);
1797
+ }
1798
+ }
1799
+ for (const [id, dev] of resolved) {
1800
+ if (dev.preflight === void 0) continue;
1801
+ try {
1802
+ await dev.preflight({
1803
+ graph,
1804
+ container: containers.get(id),
1805
+ stage: void 0
1806
+ });
1807
+ } catch (error) {
1808
+ throw toStructured("DEV.PREFLIGHT_FAILED", error);
1809
+ }
1810
+ }
1811
+ for (const [id, dev] of resolved) {
1812
+ if (dev.emulators === void 0) continue;
1813
+ try {
1814
+ await dev.emulators({
1815
+ graph,
1816
+ container: containers.get(id),
1817
+ devDir
1818
+ });
1819
+ } catch (error) {
1820
+ throw toStructured("DEV.EMULATOR_FAILED", error);
1821
+ }
1822
+ }
1823
+ } catch (error) {
1824
+ if (CliStructuredError.is(error)) return notOk(error);
1825
+ throw error;
1826
+ }
1827
+ const reproduceCommand = `alchemy deploy ${DEV_STACK_RELATIVE_PATH} --yes --stage dev`;
1828
+ const converge = async () => {
1829
+ let stackPath;
1830
+ try {
1831
+ stackPath = writeDevStackFile({
1832
+ entryPath: pipeline.entryModule.path,
1833
+ cwd,
1834
+ configPath: pipeline.configPath,
1835
+ name: pipeline.name,
1836
+ assembled: pipeline.assembled
1837
+ });
1838
+ } catch (error) {
1839
+ throw toStructured("DEV.STACK_WRITE_FAILED", error);
1840
+ }
1841
+ let outcome;
1842
+ try {
1843
+ outcome = await (deps.alchemy ?? spawnAlchemy)(alchemyInvocation({
1844
+ command: "deploy",
1845
+ stackFileRelativePath: DEV_STACK_RELATIVE_PATH,
1846
+ cwd,
1847
+ stage: "dev",
1848
+ containerEnv: containerEnv(containers)
1849
+ }));
1850
+ } catch (error) {
1851
+ if (CliStructuredError.is(error)) throw error;
1852
+ throw new CliStructuredError("DEV.CONVERGE_FAILED", failureMessage(error), {
1853
+ cause: error,
1854
+ meta: { diagnostics: {
1855
+ exitCode: void 0,
1856
+ stackFilePath: stackPath,
1857
+ reproduceCommand,
1858
+ cwd
1859
+ } }
1860
+ });
1861
+ }
1862
+ return {
1863
+ outcome,
1864
+ stackPath
1865
+ };
1866
+ };
1867
+ let first;
1868
+ try {
1869
+ first = await converge();
1870
+ } catch (error) {
1871
+ if (CliStructuredError.is(error)) return notOk(error);
1872
+ throw error;
1873
+ }
1874
+ const firstStatus = first.outcome.signal !== null ? null : first.outcome.exitCode ?? 1;
1875
+ if (firstStatus !== 0) return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", first.outcome.signal !== null ? `alchemy deploy was interrupted by ${first.outcome.signal}.` : `alchemy deploy exited with status ${String(firstStatus)}.`, { meta: {
1876
+ ...first.outcome.signal !== null ? { signal: first.outcome.signal } : { exitCode: firstStatus },
1877
+ diagnostics: {
1878
+ exitCode: firstStatus ?? void 0,
1879
+ ...first.outcome.signal !== null ? { signal: first.outcome.signal } : {},
1880
+ stackFilePath: first.stackPath,
1881
+ reproduceCommand,
1882
+ cwd
1883
+ }
1884
+ } }));
1885
+ const emit = (event) => {
1886
+ try {
1887
+ onEvent?.(event);
1888
+ } catch {}
1889
+ };
1890
+ const attachments = [];
1891
+ const started = [];
1892
+ let watch;
1893
+ try {
1894
+ for (const [id, dev] of resolved) try {
1895
+ attachments.push(await dev.attach({
1896
+ container: containers.get(id),
1897
+ devDir
1898
+ }));
1899
+ } catch (error) {
1900
+ throw toStructured("DEV.ATTACH_FAILED", error);
1901
+ }
1902
+ for (const attachment of attachments) {
1903
+ started.push(attachment);
1904
+ try {
1905
+ await withEmulatorRetry(() => attachment.startServices());
1906
+ } catch (error) {
1907
+ throw toStructured("DEV.SERVICE_START_FAILED", error);
1908
+ }
1909
+ }
1910
+ let endpoints;
1911
+ try {
1912
+ endpoints = await mergedEndpoints(attachments);
1913
+ } catch (error) {
1914
+ throw toStructured("DEV.ATTACH_FAILED", error);
1915
+ }
1916
+ emit({
1917
+ kind: "ready",
1918
+ endpoints
1919
+ });
1920
+ const { targets, unwatchable } = watchTargetsFrom(pipeline.assembled.bundles);
1921
+ for (const address of unwatchable) emit({
1922
+ kind: "unwatchable",
1923
+ address
1924
+ });
1925
+ const watchDeps = {
1926
+ runAssembler: deps.runAssembler,
1927
+ config: deps.config,
1928
+ configPath: deps.configPath
1929
+ };
1930
+ watch = startWatch(targets, () => {
1931
+ (async () => {
1932
+ try {
1933
+ const rePipeline = await runPipeline(input.entry, input.name, cwd, watchDeps);
1934
+ const stackPath = writeDevStackFile({
1935
+ entryPath: rePipeline.entryModule.path,
1936
+ cwd,
1937
+ configPath: rePipeline.configPath,
1938
+ name: rePipeline.name,
1939
+ assembled: rePipeline.assembled
1940
+ });
1941
+ const outcome = await (deps.alchemy ?? spawnAlchemy)(alchemyInvocation({
1942
+ command: "deploy",
1943
+ stackFileRelativePath: DEV_STACK_RELATIVE_PATH,
1944
+ cwd,
1945
+ stage: "dev",
1946
+ containerEnv: containerEnv(containers)
1947
+ }));
1948
+ if (outcome.signal !== null || outcome.exitCode !== 0) {
1949
+ emit({
1950
+ kind: "converge-failed",
1951
+ stackFilePath: stackPath,
1952
+ reproduceCommand,
1953
+ cwd
1954
+ });
1955
+ return;
1956
+ }
1957
+ emit({
1958
+ kind: "ready",
1959
+ endpoints: await mergedEndpoints(attachments)
1960
+ });
1961
+ } catch (error) {
1962
+ emit({
1963
+ kind: "rebuild-failed",
1964
+ message: failureMessage(error)
1965
+ });
1966
+ }
1967
+ })();
1968
+ }, (error) => emit({
1969
+ kind: "watch-error",
1970
+ message: failureMessage(error)
1971
+ }));
1972
+ const startedWatch = watch;
1973
+ await watch.ready;
1974
+ let stopping = false;
1975
+ let resolveClosed = () => void 0;
1976
+ const closed = new Promise((resolve) => {
1977
+ resolveClosed = resolve;
1978
+ });
1979
+ const stop = () => {
1980
+ if (!stopping) {
1981
+ stopping = true;
1982
+ emit({ kind: "stopping" });
1983
+ startedWatch.stop();
1984
+ (async () => {
1985
+ for (const attachment of attachments) try {
1986
+ await attachment.stopServices();
1987
+ } catch (error) {
1988
+ emit({
1989
+ kind: "stop-error",
1990
+ message: failureMessage(error)
1991
+ });
1992
+ }
1993
+ emit({ kind: "stopped" });
1994
+ resolveClosed();
1995
+ })();
1996
+ }
1997
+ return closed;
1998
+ };
1999
+ return ok({
2000
+ endpoints,
2001
+ stop,
2002
+ closed
2003
+ });
2004
+ } catch (error) {
2005
+ watch?.stop();
2006
+ await Promise.all(started.map((a) => a.stopServices().catch(() => void 0)));
2007
+ if (CliStructuredError.is(error)) return notOk(error);
2008
+ throw error;
2009
+ }
2010
+ }
2011
+ //#endregion
2012
+ export { executeDev };
2013
+
2014
+ //# sourceMappingURL=execute-dev-BMTFWfFc-7MifQgpp.mjs.map