@soda-gql/metro-plugin 0.2.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.
@@ -0,0 +1,961 @@
1
+ import { t as __require } from "./chunk--GtjC1aJ.mjs";
2
+ import { createPluginSession, getSharedArtifact, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getSharedTransformerType, getStateKey, setSharedArtifact, setSharedPluginSession, setSharedSwcTransformer } from "@soda-gql/plugin-common";
3
+ import crypto from "node:crypto";
4
+ import { transformSync } from "@babel/core";
5
+ import { createPluginWithArtifact } from "@soda-gql/babel-plugin";
6
+ import { normalizePath } from "@soda-gql/common";
7
+
8
+ //#region node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
9
+ var comma = ",".charCodeAt(0);
10
+ var semicolon = ";".charCodeAt(0);
11
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
12
+ var intToChar = new Uint8Array(64);
13
+ var charToInt = new Uint8Array(128);
14
+ for (let i = 0; i < chars.length; i++) {
15
+ const c = chars.charCodeAt(i);
16
+ intToChar[i] = c;
17
+ charToInt[c] = i;
18
+ }
19
+ function decodeInteger(reader, relative) {
20
+ let value = 0;
21
+ let shift = 0;
22
+ let integer = 0;
23
+ do {
24
+ integer = charToInt[reader.next()];
25
+ value |= (integer & 31) << shift;
26
+ shift += 5;
27
+ } while (integer & 32);
28
+ const shouldNegate = value & 1;
29
+ value >>>= 1;
30
+ if (shouldNegate) value = -2147483648 | -value;
31
+ return relative + value;
32
+ }
33
+ function encodeInteger(builder, num, relative) {
34
+ let delta = num - relative;
35
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
36
+ do {
37
+ let clamped = delta & 31;
38
+ delta >>>= 5;
39
+ if (delta > 0) clamped |= 32;
40
+ builder.write(intToChar[clamped]);
41
+ } while (delta > 0);
42
+ return num;
43
+ }
44
+ function hasMoreVlq(reader, max) {
45
+ if (reader.pos >= max) return false;
46
+ return reader.peek() !== comma;
47
+ }
48
+ var bufLength = 1024 * 16;
49
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
50
+ return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
51
+ } } : { decode(buf) {
52
+ let out = "";
53
+ for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
54
+ return out;
55
+ } };
56
+ var StringWriter = class {
57
+ constructor() {
58
+ this.pos = 0;
59
+ this.out = "";
60
+ this.buffer = new Uint8Array(bufLength);
61
+ }
62
+ write(v) {
63
+ const { buffer } = this;
64
+ buffer[this.pos++] = v;
65
+ if (this.pos === bufLength) {
66
+ this.out += td.decode(buffer);
67
+ this.pos = 0;
68
+ }
69
+ }
70
+ flush() {
71
+ const { buffer, out, pos } = this;
72
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
73
+ }
74
+ };
75
+ var StringReader = class {
76
+ constructor(buffer) {
77
+ this.pos = 0;
78
+ this.buffer = buffer;
79
+ }
80
+ next() {
81
+ return this.buffer.charCodeAt(this.pos++);
82
+ }
83
+ peek() {
84
+ return this.buffer.charCodeAt(this.pos);
85
+ }
86
+ indexOf(char) {
87
+ const { buffer, pos } = this;
88
+ const idx = buffer.indexOf(char, pos);
89
+ return idx === -1 ? buffer.length : idx;
90
+ }
91
+ };
92
+ function decode(mappings) {
93
+ const { length } = mappings;
94
+ const reader = new StringReader(mappings);
95
+ const decoded = [];
96
+ let genColumn = 0;
97
+ let sourcesIndex = 0;
98
+ let sourceLine = 0;
99
+ let sourceColumn = 0;
100
+ let namesIndex = 0;
101
+ do {
102
+ const semi = reader.indexOf(";");
103
+ const line = [];
104
+ let sorted = true;
105
+ let lastCol = 0;
106
+ genColumn = 0;
107
+ while (reader.pos < semi) {
108
+ let seg;
109
+ genColumn = decodeInteger(reader, genColumn);
110
+ if (genColumn < lastCol) sorted = false;
111
+ lastCol = genColumn;
112
+ if (hasMoreVlq(reader, semi)) {
113
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
114
+ sourceLine = decodeInteger(reader, sourceLine);
115
+ sourceColumn = decodeInteger(reader, sourceColumn);
116
+ if (hasMoreVlq(reader, semi)) {
117
+ namesIndex = decodeInteger(reader, namesIndex);
118
+ seg = [
119
+ genColumn,
120
+ sourcesIndex,
121
+ sourceLine,
122
+ sourceColumn,
123
+ namesIndex
124
+ ];
125
+ } else seg = [
126
+ genColumn,
127
+ sourcesIndex,
128
+ sourceLine,
129
+ sourceColumn
130
+ ];
131
+ } else seg = [genColumn];
132
+ line.push(seg);
133
+ reader.pos++;
134
+ }
135
+ if (!sorted) sort(line);
136
+ decoded.push(line);
137
+ reader.pos = semi + 1;
138
+ } while (reader.pos <= length);
139
+ return decoded;
140
+ }
141
+ function sort(line) {
142
+ line.sort(sortComparator$1);
143
+ }
144
+ function sortComparator$1(a, b) {
145
+ return a[0] - b[0];
146
+ }
147
+ function encode(decoded) {
148
+ const writer = new StringWriter();
149
+ let sourcesIndex = 0;
150
+ let sourceLine = 0;
151
+ let sourceColumn = 0;
152
+ let namesIndex = 0;
153
+ for (let i = 0; i < decoded.length; i++) {
154
+ const line = decoded[i];
155
+ if (i > 0) writer.write(semicolon);
156
+ if (line.length === 0) continue;
157
+ let genColumn = 0;
158
+ for (let j = 0; j < line.length; j++) {
159
+ const segment = line[j];
160
+ if (j > 0) writer.write(comma);
161
+ genColumn = encodeInteger(writer, segment[0], genColumn);
162
+ if (segment.length === 1) continue;
163
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
164
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
165
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
166
+ if (segment.length === 4) continue;
167
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
168
+ }
169
+ }
170
+ return writer.flush();
171
+ }
172
+
173
+ //#endregion
174
+ //#region node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
175
+ const schemeRegex = /^[\w+.-]+:\/\//;
176
+ /**
177
+ * Matches the parts of a URL:
178
+ * 1. Scheme, including ":", guaranteed.
179
+ * 2. User/password, including "@", optional.
180
+ * 3. Host, guaranteed.
181
+ * 4. Port, including ":", optional.
182
+ * 5. Path, including "/", optional.
183
+ * 6. Query, including "?", optional.
184
+ * 7. Hash, including "#", optional.
185
+ */
186
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
187
+ /**
188
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
189
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
190
+ *
191
+ * 1. Host, optional.
192
+ * 2. Path, which may include "/", guaranteed.
193
+ * 3. Query, including "?", optional.
194
+ * 4. Hash, including "#", optional.
195
+ */
196
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
197
+ function isAbsoluteUrl(input) {
198
+ return schemeRegex.test(input);
199
+ }
200
+ function isSchemeRelativeUrl(input) {
201
+ return input.startsWith("//");
202
+ }
203
+ function isAbsolutePath(input) {
204
+ return input.startsWith("/");
205
+ }
206
+ function isFileUrl(input) {
207
+ return input.startsWith("file:");
208
+ }
209
+ function isRelative(input) {
210
+ return /^[.?#]/.test(input);
211
+ }
212
+ function parseAbsoluteUrl(input) {
213
+ const match = urlRegex.exec(input);
214
+ return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
215
+ }
216
+ function parseFileUrl(input) {
217
+ const match = fileRegex.exec(input);
218
+ const path = match[2];
219
+ return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
220
+ }
221
+ function makeUrl(scheme, user, host, port, path, query, hash) {
222
+ return {
223
+ scheme,
224
+ user,
225
+ host,
226
+ port,
227
+ path,
228
+ query,
229
+ hash,
230
+ type: 7
231
+ };
232
+ }
233
+ function parseUrl(input) {
234
+ if (isSchemeRelativeUrl(input)) {
235
+ const url$1 = parseAbsoluteUrl("http:" + input);
236
+ url$1.scheme = "";
237
+ url$1.type = 6;
238
+ return url$1;
239
+ }
240
+ if (isAbsolutePath(input)) {
241
+ const url$1 = parseAbsoluteUrl("http://foo.com" + input);
242
+ url$1.scheme = "";
243
+ url$1.host = "";
244
+ url$1.type = 5;
245
+ return url$1;
246
+ }
247
+ if (isFileUrl(input)) return parseFileUrl(input);
248
+ if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
249
+ const url = parseAbsoluteUrl("http://foo.com/" + input);
250
+ url.scheme = "";
251
+ url.host = "";
252
+ url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
253
+ return url;
254
+ }
255
+ function stripPathFilename(path) {
256
+ if (path.endsWith("/..")) return path;
257
+ const index = path.lastIndexOf("/");
258
+ return path.slice(0, index + 1);
259
+ }
260
+ function mergePaths(url, base) {
261
+ normalizePath$1(base, base.type);
262
+ if (url.path === "/") url.path = base.path;
263
+ else url.path = stripPathFilename(base.path) + url.path;
264
+ }
265
+ /**
266
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
267
+ * "foo/.". We need to normalize to a standard representation.
268
+ */
269
+ function normalizePath$1(url, type) {
270
+ const rel = type <= 4;
271
+ const pieces = url.path.split("/");
272
+ let pointer = 1;
273
+ let positive = 0;
274
+ let addTrailingSlash = false;
275
+ for (let i = 1; i < pieces.length; i++) {
276
+ const piece = pieces[i];
277
+ if (!piece) {
278
+ addTrailingSlash = true;
279
+ continue;
280
+ }
281
+ addTrailingSlash = false;
282
+ if (piece === ".") continue;
283
+ if (piece === "..") {
284
+ if (positive) {
285
+ addTrailingSlash = true;
286
+ positive--;
287
+ pointer--;
288
+ } else if (rel) pieces[pointer++] = piece;
289
+ continue;
290
+ }
291
+ pieces[pointer++] = piece;
292
+ positive++;
293
+ }
294
+ let path = "";
295
+ for (let i = 1; i < pointer; i++) path += "/" + pieces[i];
296
+ if (!path || addTrailingSlash && !path.endsWith("/..")) path += "/";
297
+ url.path = path;
298
+ }
299
+ /**
300
+ * Attempts to resolve `input` URL/path relative to `base`.
301
+ */
302
+ function resolve(input, base) {
303
+ if (!input && !base) return "";
304
+ const url = parseUrl(input);
305
+ let inputType = url.type;
306
+ if (base && inputType !== 7) {
307
+ const baseUrl = parseUrl(base);
308
+ const baseType = baseUrl.type;
309
+ switch (inputType) {
310
+ case 1: url.hash = baseUrl.hash;
311
+ case 2: url.query = baseUrl.query;
312
+ case 3:
313
+ case 4: mergePaths(url, baseUrl);
314
+ case 5:
315
+ url.user = baseUrl.user;
316
+ url.host = baseUrl.host;
317
+ url.port = baseUrl.port;
318
+ case 6: url.scheme = baseUrl.scheme;
319
+ }
320
+ if (baseType > inputType) inputType = baseType;
321
+ }
322
+ normalizePath$1(url, inputType);
323
+ const queryHash = url.query + url.hash;
324
+ switch (inputType) {
325
+ case 2:
326
+ case 3: return queryHash;
327
+ case 4: {
328
+ const path = url.path.slice(1);
329
+ if (!path) return queryHash || ".";
330
+ if (isRelative(base || input) && !isRelative(path)) return "./" + path + queryHash;
331
+ return path + queryHash;
332
+ }
333
+ case 5: return url.path + queryHash;
334
+ default: return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
335
+ }
336
+ }
337
+
338
+ //#endregion
339
+ //#region node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
340
+ function stripFilename(path) {
341
+ if (!path) return "";
342
+ const index = path.lastIndexOf("/");
343
+ return path.slice(0, index + 1);
344
+ }
345
+ function resolver(mapUrl, sourceRoot) {
346
+ const from = stripFilename(mapUrl);
347
+ const prefix = sourceRoot ? sourceRoot + "/" : "";
348
+ return (source) => resolve(prefix + (source || ""), from);
349
+ }
350
+ var COLUMN$1 = 0;
351
+ function maybeSort(mappings, owned) {
352
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
353
+ if (unsortedIndex === mappings.length) return mappings;
354
+ if (!owned) mappings = mappings.slice();
355
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) mappings[i] = sortSegments(mappings[i], owned);
356
+ return mappings;
357
+ }
358
+ function nextUnsortedSegmentLine(mappings, start) {
359
+ for (let i = start; i < mappings.length; i++) if (!isSorted(mappings[i])) return i;
360
+ return mappings.length;
361
+ }
362
+ function isSorted(line) {
363
+ for (let j = 1; j < line.length; j++) if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) return false;
364
+ return true;
365
+ }
366
+ function sortSegments(line, owned) {
367
+ if (!owned) line = line.slice();
368
+ return line.sort(sortComparator);
369
+ }
370
+ function sortComparator(a, b) {
371
+ return a[COLUMN$1] - b[COLUMN$1];
372
+ }
373
+ var found = false;
374
+ function binarySearch(haystack, needle, low, high) {
375
+ while (low <= high) {
376
+ const mid = low + (high - low >> 1);
377
+ const cmp = haystack[mid][COLUMN$1] - needle;
378
+ if (cmp === 0) {
379
+ found = true;
380
+ return mid;
381
+ }
382
+ if (cmp < 0) low = mid + 1;
383
+ else high = mid - 1;
384
+ }
385
+ found = false;
386
+ return low - 1;
387
+ }
388
+ function upperBound(haystack, needle, index) {
389
+ for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN$1] !== needle) break;
390
+ return index;
391
+ }
392
+ function lowerBound(haystack, needle, index) {
393
+ for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN$1] !== needle) break;
394
+ return index;
395
+ }
396
+ function memoizedState() {
397
+ return {
398
+ lastKey: -1,
399
+ lastNeedle: -1,
400
+ lastIndex: -1
401
+ };
402
+ }
403
+ function memoizedBinarySearch(haystack, needle, state, key) {
404
+ const { lastKey, lastNeedle, lastIndex } = state;
405
+ let low = 0;
406
+ let high = haystack.length - 1;
407
+ if (key === lastKey) {
408
+ if (needle === lastNeedle) {
409
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
410
+ return lastIndex;
411
+ }
412
+ if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
413
+ else high = lastIndex;
414
+ }
415
+ state.lastKey = key;
416
+ state.lastNeedle = needle;
417
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
418
+ }
419
+ function parse(map) {
420
+ return typeof map === "string" ? JSON.parse(map) : map;
421
+ }
422
+ var LEAST_UPPER_BOUND = -1;
423
+ var GREATEST_LOWER_BOUND = 1;
424
+ var TraceMap = class {
425
+ constructor(map, mapUrl) {
426
+ const isString = typeof map === "string";
427
+ if (!isString && map._decodedMemo) return map;
428
+ const parsed = parse(map);
429
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
430
+ this.version = version;
431
+ this.file = file;
432
+ this.names = names || [];
433
+ this.sourceRoot = sourceRoot;
434
+ this.sources = sources;
435
+ this.sourcesContent = sourcesContent;
436
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
437
+ const resolve$1 = resolver(mapUrl, sourceRoot);
438
+ this.resolvedSources = sources.map(resolve$1);
439
+ const { mappings } = parsed;
440
+ if (typeof mappings === "string") {
441
+ this._encoded = mappings;
442
+ this._decoded = void 0;
443
+ } else if (Array.isArray(mappings)) {
444
+ this._encoded = void 0;
445
+ this._decoded = maybeSort(mappings, isString);
446
+ } else if (parsed.sections) throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
447
+ else throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
448
+ this._decodedMemo = memoizedState();
449
+ this._bySources = void 0;
450
+ this._bySourceMemos = void 0;
451
+ }
452
+ };
453
+ function cast$1(map) {
454
+ return map;
455
+ }
456
+ function decodedMappings(map) {
457
+ var _a;
458
+ return (_a = cast$1(map))._decoded || (_a._decoded = decode(cast$1(map)._encoded));
459
+ }
460
+ function traceSegment(map, line, column) {
461
+ const decoded = decodedMappings(map);
462
+ if (line >= decoded.length) return null;
463
+ const segments = decoded[line];
464
+ const index = traceSegmentInternal(segments, cast$1(map)._decodedMemo, line, column, GREATEST_LOWER_BOUND);
465
+ return index === -1 ? null : segments[index];
466
+ }
467
+ function traceSegmentInternal(segments, memo, line, column, bias) {
468
+ let index = memoizedBinarySearch(segments, column, memo, line);
469
+ if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
470
+ else if (bias === LEAST_UPPER_BOUND) index++;
471
+ if (index === -1 || index === segments.length) return -1;
472
+ return index;
473
+ }
474
+
475
+ //#endregion
476
+ //#region node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
477
+ var SetArray = class {
478
+ constructor() {
479
+ this._indexes = { __proto__: null };
480
+ this.array = [];
481
+ }
482
+ };
483
+ function cast(set) {
484
+ return set;
485
+ }
486
+ function get(setarr, key) {
487
+ return cast(setarr)._indexes[key];
488
+ }
489
+ function put(setarr, key) {
490
+ const index = get(setarr, key);
491
+ if (index !== void 0) return index;
492
+ const { array, _indexes: indexes } = cast(setarr);
493
+ return indexes[key] = array.push(key) - 1;
494
+ }
495
+ function remove(setarr, key) {
496
+ const index = get(setarr, key);
497
+ if (index === void 0) return;
498
+ const { array, _indexes: indexes } = cast(setarr);
499
+ for (let i = index + 1; i < array.length; i++) {
500
+ const k = array[i];
501
+ array[i - 1] = k;
502
+ indexes[k]--;
503
+ }
504
+ indexes[key] = void 0;
505
+ array.pop();
506
+ }
507
+ var COLUMN = 0;
508
+ var SOURCES_INDEX = 1;
509
+ var SOURCE_LINE = 2;
510
+ var SOURCE_COLUMN = 3;
511
+ var NAMES_INDEX = 4;
512
+ var NO_NAME = -1;
513
+ var GenMapping = class {
514
+ constructor({ file, sourceRoot } = {}) {
515
+ this._names = new SetArray();
516
+ this._sources = new SetArray();
517
+ this._sourcesContent = [];
518
+ this._mappings = [];
519
+ this.file = file;
520
+ this.sourceRoot = sourceRoot;
521
+ this._ignoreList = new SetArray();
522
+ }
523
+ };
524
+ function cast2(map) {
525
+ return map;
526
+ }
527
+ var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
528
+ return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
529
+ };
530
+ function setSourceContent(map, source, content) {
531
+ const { _sources: sources, _sourcesContent: sourcesContent } = cast2(map);
532
+ const index = put(sources, source);
533
+ sourcesContent[index] = content;
534
+ }
535
+ function setIgnore(map, source, ignore = true) {
536
+ const { _sources: sources, _sourcesContent: sourcesContent, _ignoreList: ignoreList } = cast2(map);
537
+ const index = put(sources, source);
538
+ if (index === sourcesContent.length) sourcesContent[index] = null;
539
+ if (ignore) put(ignoreList, index);
540
+ else remove(ignoreList, index);
541
+ }
542
+ function toDecodedMap(map) {
543
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList } = cast2(map);
544
+ removeEmptyFinalLines(mappings);
545
+ return {
546
+ version: 3,
547
+ file: map.file || void 0,
548
+ names: names.array,
549
+ sourceRoot: map.sourceRoot || void 0,
550
+ sources: sources.array,
551
+ sourcesContent,
552
+ mappings,
553
+ ignoreList: ignoreList.array
554
+ };
555
+ }
556
+ function toEncodedMap(map) {
557
+ const decoded = toDecodedMap(map);
558
+ return Object.assign({}, decoded, { mappings: encode(decoded.mappings) });
559
+ }
560
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
561
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names } = cast2(map);
562
+ const line = getIndex(mappings, genLine);
563
+ const index = getColumnIndex(line, genColumn);
564
+ if (!source) {
565
+ if (skipable && skipSourceless(line, index)) return;
566
+ return insert(line, index, [genColumn]);
567
+ }
568
+ assert(sourceLine);
569
+ assert(sourceColumn);
570
+ const sourcesIndex = put(sources, source);
571
+ const namesIndex = name ? put(names, name) : NO_NAME;
572
+ if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
573
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) return;
574
+ return insert(line, index, name ? [
575
+ genColumn,
576
+ sourcesIndex,
577
+ sourceLine,
578
+ sourceColumn,
579
+ namesIndex
580
+ ] : [
581
+ genColumn,
582
+ sourcesIndex,
583
+ sourceLine,
584
+ sourceColumn
585
+ ]);
586
+ }
587
+ function assert(_val) {}
588
+ function getIndex(arr, index) {
589
+ for (let i = arr.length; i <= index; i++) arr[i] = [];
590
+ return arr[index];
591
+ }
592
+ function getColumnIndex(line, genColumn) {
593
+ let index = line.length;
594
+ for (let i = index - 1; i >= 0; index = i--) if (genColumn >= line[i][COLUMN]) break;
595
+ return index;
596
+ }
597
+ function insert(array, index, value) {
598
+ for (let i = array.length; i > index; i--) array[i] = array[i - 1];
599
+ array[index] = value;
600
+ }
601
+ function removeEmptyFinalLines(mappings) {
602
+ const { length } = mappings;
603
+ let len = length;
604
+ for (let i = len - 1; i >= 0; len = i, i--) if (mappings[i].length > 0) break;
605
+ if (len < length) mappings.length = len;
606
+ }
607
+ function skipSourceless(line, index) {
608
+ if (index === 0) return true;
609
+ return line[index - 1].length === 1;
610
+ }
611
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
612
+ if (index === 0) return false;
613
+ const prev = line[index - 1];
614
+ if (prev.length === 1) return false;
615
+ return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
616
+ }
617
+
618
+ //#endregion
619
+ //#region node_modules/@ampproject/remapping/dist/remapping.mjs
620
+ const SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
621
+ const EMPTY_SOURCES = [];
622
+ function SegmentObject(source, line, column, name, content, ignore) {
623
+ return {
624
+ source,
625
+ line,
626
+ column,
627
+ name,
628
+ content,
629
+ ignore
630
+ };
631
+ }
632
+ function Source(map, sources, source, content, ignore) {
633
+ return {
634
+ map,
635
+ sources,
636
+ source,
637
+ content,
638
+ ignore
639
+ };
640
+ }
641
+ /**
642
+ * MapSource represents a single sourcemap, with the ability to trace mappings into its child nodes
643
+ * (which may themselves be SourceMapTrees).
644
+ */
645
+ function MapSource(map, sources) {
646
+ return Source(map, sources, "", null, false);
647
+ }
648
+ /**
649
+ * A "leaf" node in the sourcemap tree, representing an original, unmodified source file. Recursive
650
+ * segment tracing ends at the `OriginalSource`.
651
+ */
652
+ function OriginalSource(source, content, ignore) {
653
+ return Source(null, EMPTY_SOURCES, source, content, ignore);
654
+ }
655
+ /**
656
+ * traceMappings is only called on the root level SourceMapTree, and begins the process of
657
+ * resolving each mapping in terms of the original source files.
658
+ */
659
+ function traceMappings(tree) {
660
+ const gen = new GenMapping({ file: tree.map.file });
661
+ const { sources: rootSources, map } = tree;
662
+ const rootNames = map.names;
663
+ const rootMappings = decodedMappings(map);
664
+ for (let i = 0; i < rootMappings.length; i++) {
665
+ const segments = rootMappings[i];
666
+ for (let j = 0; j < segments.length; j++) {
667
+ const segment = segments[j];
668
+ const genCol = segment[0];
669
+ let traced = SOURCELESS_MAPPING;
670
+ if (segment.length !== 1) {
671
+ const source$1 = rootSources[segment[1]];
672
+ traced = originalPositionFor(source$1, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
673
+ if (traced == null) continue;
674
+ }
675
+ const { column, line, name, content, source, ignore } = traced;
676
+ maybeAddSegment(gen, i, genCol, source, line, column, name);
677
+ if (source && content != null) setSourceContent(gen, source, content);
678
+ if (ignore) setIgnore(gen, source, true);
679
+ }
680
+ }
681
+ return gen;
682
+ }
683
+ /**
684
+ * originalPositionFor is only called on children SourceMapTrees. It recurses down into its own
685
+ * child SourceMapTrees, until we find the original source map.
686
+ */
687
+ function originalPositionFor(source, line, column, name) {
688
+ if (!source.map) return SegmentObject(source.source, line, column, name, source.content, source.ignore);
689
+ const segment = traceSegment(source.map, line, column);
690
+ if (segment == null) return null;
691
+ if (segment.length === 1) return SOURCELESS_MAPPING;
692
+ return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
693
+ }
694
+ function asArray(value) {
695
+ if (Array.isArray(value)) return value;
696
+ return [value];
697
+ }
698
+ /**
699
+ * Recursively builds a tree structure out of sourcemap files, with each node
700
+ * being either an `OriginalSource` "leaf" or a `SourceMapTree` composed of
701
+ * `OriginalSource`s and `SourceMapTree`s.
702
+ *
703
+ * Every sourcemap is composed of a collection of source files and mappings
704
+ * into locations of those source files. When we generate a `SourceMapTree` for
705
+ * the sourcemap, we attempt to load each source file's own sourcemap. If it
706
+ * does not have an associated sourcemap, it is considered an original,
707
+ * unmodified source file.
708
+ */
709
+ function buildSourceMapTree(input, loader) {
710
+ const maps = asArray(input).map((m) => new TraceMap(m, ""));
711
+ const map = maps.pop();
712
+ for (let i = 0; i < maps.length; i++) if (maps[i].sources.length > 1) throw new Error(`Transformation map ${i} must have exactly one source file.\nDid you specify these with the most recent transformation maps first?`);
713
+ let tree = build(map, loader, "", 0);
714
+ for (let i = maps.length - 1; i >= 0; i--) tree = MapSource(maps[i], [tree]);
715
+ return tree;
716
+ }
717
+ function build(map, loader, importer, importerDepth) {
718
+ const { resolvedSources, sourcesContent, ignoreList } = map;
719
+ const depth = importerDepth + 1;
720
+ return MapSource(map, resolvedSources.map((sourceFile, i) => {
721
+ const ctx = {
722
+ importer,
723
+ depth,
724
+ source: sourceFile || "",
725
+ content: void 0,
726
+ ignore: void 0
727
+ };
728
+ const sourceMap = loader(ctx.source, ctx);
729
+ const { source, content, ignore } = ctx;
730
+ if (sourceMap) return build(new TraceMap(sourceMap, source), loader, source, depth);
731
+ return OriginalSource(source, content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null, ignore !== void 0 ? ignore : ignoreList ? ignoreList.includes(i) : false);
732
+ }));
733
+ }
734
+ /**
735
+ * A SourceMap v3 compatible sourcemap, which only includes fields that were
736
+ * provided to it.
737
+ */
738
+ var SourceMap = class {
739
+ constructor(map, options) {
740
+ const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
741
+ this.version = out.version;
742
+ this.file = out.file;
743
+ this.mappings = out.mappings;
744
+ this.names = out.names;
745
+ this.ignoreList = out.ignoreList;
746
+ this.sourceRoot = out.sourceRoot;
747
+ this.sources = out.sources;
748
+ if (!options.excludeContent) this.sourcesContent = out.sourcesContent;
749
+ }
750
+ toString() {
751
+ return JSON.stringify(this);
752
+ }
753
+ };
754
+ /**
755
+ * Traces through all the mappings in the root sourcemap, through the sources
756
+ * (and their sourcemaps), all the way back to the original source location.
757
+ *
758
+ * `loader` will be called every time we encounter a source file. If it returns
759
+ * a sourcemap, we will recurse into that sourcemap to continue the trace. If
760
+ * it returns a falsey value, that source file is treated as an original,
761
+ * unmodified source file.
762
+ *
763
+ * Pass `excludeContent` to exclude any self-containing source file content
764
+ * from the output sourcemap.
765
+ *
766
+ * Pass `decodedMappings` to receive a SourceMap with decoded (instead of
767
+ * VLQ encoded) mappings.
768
+ */
769
+ function remapping(input, loader, options) {
770
+ const opts = typeof options === "object" ? options : {
771
+ excludeContent: !!options,
772
+ decodedMappings: false
773
+ };
774
+ return new SourceMap(traceMappings(buildSourceMapTree(input, loader)), opts);
775
+ }
776
+
777
+ //#endregion
778
+ //#region packages/metro-plugin/src/transformer.ts
779
+ /**
780
+ * Upstream transformer candidates in order of preference.
781
+ * - Expo projects: @expo/metro-config/babel-transformer
782
+ * - React Native 0.73+: @react-native/metro-babel-transformer
783
+ * - Legacy React Native: metro-react-native-babel-transformer
784
+ */
785
+ const UPSTREAM_TRANSFORMER_CANDIDATES = [
786
+ "@expo/metro-config/babel-transformer",
787
+ "@react-native/metro-babel-transformer",
788
+ "metro-react-native-babel-transformer"
789
+ ];
790
+ /**
791
+ * Cached upstream transformer module.
792
+ */
793
+ let upstreamTransformer = null;
794
+ /**
795
+ * Try to resolve a module from multiple locations.
796
+ * Falls back through various resolution strategies.
797
+ */
798
+ const tryResolve = (moduleName) => {
799
+ try {
800
+ return __require.resolve(moduleName);
801
+ } catch {}
802
+ try {
803
+ return __require.resolve(moduleName, { paths: [process.cwd()] });
804
+ } catch {}
805
+ return null;
806
+ };
807
+ /**
808
+ * Detect and load the upstream Metro Babel transformer.
809
+ * Tries multiple candidates in order of preference.
810
+ */
811
+ const getUpstreamTransformer = () => {
812
+ if (upstreamTransformer) return upstreamTransformer;
813
+ for (const candidate of UPSTREAM_TRANSFORMER_CANDIDATES) {
814
+ const resolved = tryResolve(candidate);
815
+ if (resolved) {
816
+ upstreamTransformer = __require(resolved);
817
+ return upstreamTransformer;
818
+ }
819
+ }
820
+ throw new Error(`No compatible Metro Babel transformer found. Tried: ${UPSTREAM_TRANSFORMER_CANDIDATES.join(", ")}. Please install one of these packages.`);
821
+ };
822
+ /**
823
+ * Cached plugin session.
824
+ */
825
+ let pluginSession = null;
826
+ let sessionInitialized = false;
827
+ /**
828
+ * Ensure plugin session is initialized.
829
+ * First tries to use shared session, falls back to creating own.
830
+ */
831
+ const ensurePluginSession = () => {
832
+ const stateKey = getStateKey();
833
+ const sharedSession = getSharedPluginSession(stateKey);
834
+ if (sharedSession) return sharedSession;
835
+ if (!sessionInitialized) {
836
+ sessionInitialized = true;
837
+ pluginSession = createPluginSession({}, "@soda-gql/metro-plugin");
838
+ if (pluginSession) setSharedPluginSession(stateKey, pluginSession);
839
+ }
840
+ return pluginSession;
841
+ };
842
+ /**
843
+ * Whether SWC transformer initialization has been attempted.
844
+ */
845
+ let swcInitialized = false;
846
+ /**
847
+ * Initialize SWC transformer if configured.
848
+ */
849
+ const initializeSwcTransformer = async (artifact, config) => {
850
+ const stateKey = getStateKey();
851
+ const existing = getSharedSwcTransformer(stateKey);
852
+ if (existing || swcInitialized) return existing;
853
+ swcInitialized = true;
854
+ if (getSharedTransformerType(stateKey) !== "swc") return null;
855
+ try {
856
+ const { createTransformer } = await import("@soda-gql/swc-transformer");
857
+ const transformer = await createTransformer({
858
+ config,
859
+ artifact,
860
+ sourceMap: true
861
+ });
862
+ setSharedSwcTransformer(stateKey, transformer);
863
+ return transformer;
864
+ } catch (error) {
865
+ console.warn(`[@soda-gql/metro-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc-transformer is installed. Falling back to Babel.`);
866
+ return null;
867
+ }
868
+ };
869
+ /**
870
+ * Transform source code with soda-gql transformations.
871
+ * Wraps the upstream Metro Babel transformer.
872
+ */
873
+ async function transform(params) {
874
+ const { src, filename, options } = params;
875
+ const stateKey = getStateKey();
876
+ const upstream = getUpstreamTransformer();
877
+ const session = ensurePluginSession();
878
+ if (!session) return upstream.transform(params);
879
+ let artifact = getSharedArtifact(stateKey);
880
+ if (!artifact) {
881
+ artifact = await session.getArtifactAsync();
882
+ if (artifact) setSharedArtifact(stateKey, artifact);
883
+ }
884
+ if (!artifact) return upstream.transform(params);
885
+ const normalizedPath = normalizePath(filename);
886
+ if (!Object.values(artifact.elements).some((element) => normalizePath(element.metadata.sourcePath) === normalizedPath)) return upstream.transform(params);
887
+ const swcTransformer = await initializeSwcTransformer(artifact, session.config);
888
+ if (swcTransformer) {
889
+ const swcResult = swcTransformer.transform({
890
+ sourceCode: src,
891
+ sourcePath: filename
892
+ });
893
+ if (swcResult.transformed) {
894
+ const upstreamResult$1 = await upstream.transform({
895
+ src: swcResult.sourceCode,
896
+ filename,
897
+ options
898
+ });
899
+ if (swcResult.sourceMap && upstreamResult$1.map) {
900
+ const mergedMap = remapping([upstreamResult$1.map, JSON.parse(swcResult.sourceMap)], () => null);
901
+ return {
902
+ ...upstreamResult$1,
903
+ map: mergedMap
904
+ };
905
+ }
906
+ if (swcResult.sourceMap) return {
907
+ ...upstreamResult$1,
908
+ map: JSON.parse(swcResult.sourceMap)
909
+ };
910
+ return upstreamResult$1;
911
+ }
912
+ return upstream.transform(params);
913
+ }
914
+ const babelResult = transformSync(src, {
915
+ filename,
916
+ babelrc: false,
917
+ configFile: false,
918
+ plugins: [createPluginWithArtifact({
919
+ artifact,
920
+ config: session.config
921
+ })],
922
+ sourceMaps: true
923
+ });
924
+ if (!babelResult?.code) return upstream.transform(params);
925
+ const upstreamResult = await upstream.transform({
926
+ src: babelResult.code,
927
+ filename,
928
+ options
929
+ });
930
+ if (babelResult.map && upstreamResult.map) {
931
+ const mergedMap = remapping([upstreamResult.map, babelResult.map], () => null);
932
+ return {
933
+ ...upstreamResult,
934
+ map: mergedMap
935
+ };
936
+ }
937
+ if (babelResult.map) return {
938
+ ...upstreamResult,
939
+ map: babelResult.map
940
+ };
941
+ return upstreamResult;
942
+ }
943
+ /**
944
+ * Get cache key for the transformer.
945
+ * Includes artifact generation to ensure cache invalidation when models change.
946
+ */
947
+ function getCacheKey() {
948
+ const state = getSharedState(getStateKey());
949
+ const artifact = state.currentArtifact;
950
+ const upstream = getUpstreamTransformer();
951
+ const hash = crypto.createHash("md5");
952
+ hash.update("@soda-gql/metro-plugin:v1");
953
+ if (upstream.getCacheKey) hash.update(upstream.getCacheKey());
954
+ hash.update(String(state.generation));
955
+ if (artifact) hash.update(String(Object.keys(artifact.elements).length));
956
+ return hash.digest("hex");
957
+ }
958
+
959
+ //#endregion
960
+ export { getCacheKey, transform };
961
+ //# sourceMappingURL=transformer.mjs.map