@gql.tada/cli-utils 1.9.2 → 1.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @gql.tada/cli-utils
2
2
 
3
+ ## 1.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ⚠️ Fix `createExternalFiles()` resolving its `"."` scan directory (from a synthetic file with no directory component) against the calling process's `cwd` instead of the project directory, which could scan unrelated directories and add significant overhead when `generateTurbo`/`generateOutput` are invoked as a library from a different working directory
8
+ Submitted by [@coogie](https://github.com/coogie) (See [#589](https://github.com/0no-co/gql.tada/pull/589))
9
+ - ⚠️ Fix `check` and `generate-persisted` finding no files when a project's `tsconfig.json` lives in a subdirectory of the files it includes. Both commands filtered the program's source files to those nested inside the config's directory, which excluded every file of generated configs like Nuxt's `.nuxt/tsconfig.app.json`. The project's root file names are now taken into account as well
10
+ Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#593](https://github.com/0no-co/gql.tada/pull/593))
11
+ - Skip rewriting the output file when its contents are unchanged. `writeOutput()` always performed an atomic write and then forced `fs.utimes()` on the target to guarantee a change event, so file watchers reloaded even when `generate-output` and `turbo` produced no changes. The file is now left untouched when the generated contents match what is already on disk
12
+ Submitted by [@jonjomckay](https://github.com/jonjomckay) (See [#597](https://github.com/0no-co/gql.tada/pull/597))
13
+
14
+ ## 1.9.3
15
+
16
+ ### Patch Changes
17
+
18
+ - Emit `turbo` cache entries and imports in a stable sorted order. The cache file's contents now only depend on the set of discovered documents rather than file traversal order, which keeps the output stable across refactors and reduces merge conflicts in committed cache files. Existing cache files will be reordered once when `gql-tada turbo` is next run
19
+ Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#579](https://github.com/0no-co/gql.tada/pull/579))
20
+ - Prevent non-interactive stdin and Ctrl-D/EOF bytes from terminating CLI commands with exit code 130
21
+ Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#578](https://github.com/0no-co/gql.tada/pull/578))
22
+ - Updated dependencies (See [#575](https://github.com/0no-co/gql.tada/pull/575))
23
+ - @gql.tada/internal@1.2.2
24
+
3
25
  ## 1.9.2
4
26
 
5
27
  ### Patch Changes
@@ -2769,7 +2769,7 @@ function initTTY(t = {}) {
2769
2769
  i = process.stderr;
2770
2770
  a = process.stdout;
2771
2771
  } else {
2772
- r = i.isTTY;
2772
+ r = r && !!i.isTTY;
2773
2773
  }
2774
2774
  var o = process.argv.includes("--color");
2775
2775
  var s = "FORCE_COLOR" in process.env || !process.env.NO_COLOR && !process.env.CI;
@@ -2791,7 +2791,6 @@ function initTTY(t = {}) {
2791
2791
  function onKeypress(t, n) {
2792
2792
  switch (n.name) {
2793
2793
  case "c":
2794
- case "d":
2795
2794
  case "x":
2796
2795
  if (n.ctrl) {
2797
2796
  return r();
@@ -2865,16 +2864,16 @@ function initTTY(t = {}) {
2865
2864
  i.write(text(...r));
2866
2865
  }
2867
2866
  },
2868
- start: function start(r) {
2867
+ start: function start(a) {
2869
2868
  var write = r => {
2870
2869
  if (!t.silent) {
2871
2870
  i.write("" + r);
2872
2871
  }
2873
2872
  };
2874
- if (t.disableTTY) {
2875
- return pipe(compose(r), onPush(write), toPromise);
2873
+ if (t.disableTTY || !r) {
2874
+ return pipe(compose(a), onPush(write), toPromise);
2876
2875
  } else {
2877
- return pipe(compose(r), onPush(write), takeUntil(c), toPromise);
2876
+ return pipe(compose(a), onPush(write), takeUntil(c), toPromise);
2878
2877
  }
2879
2878
  },
2880
2879
  mode: function mode(...t) {
@@ -3031,6 +3030,9 @@ var writeOutput = async (r, a) => {
3031
3030
  }));
3032
3031
  }));
3033
3032
  }
3033
+ if (await readOutput(r) === a) {
3034
+ return;
3035
+ }
3034
3036
  var n = t.dirname("string" != typeof r ? await d.realpath(r) : r);
3035
3037
  if (!await directoryExists(n)) {
3036
3038
  await d.mkdir(n, {
@@ -4141,33 +4143,39 @@ function createCacheContents(t, a, n, i) {
4141
4143
  for (var l of t) {
4142
4144
  s.set(l.argumentKey, l);
4143
4145
  }
4144
- var c = "";
4145
- for (var d of s.values()) {
4146
- if (c) {
4147
- c += "\n";
4148
- }
4149
- if (d.documentHash) {
4150
- c += ` /** @gql.tada/hash ${d.documentHash} */\n`;
4151
- }
4152
- c += ` ${d.argumentKey}:\n ${d.documentType};`;
4153
- }
4154
- var f = "import type { TadaDocumentNode, $tada } from 'gql.tada';\n";
4155
- var p = "string" == typeof n || n && "object" == typeof n && "toString" in n && !("writable" in n);
4156
- var h = new Set;
4157
- for (var g of a) {
4158
- for (var v of g.imports) {
4159
- if (p) {
4160
- var m = n.toString();
4161
- var y = u.dirname(g.absolutePath);
4162
- if (u.resolve(y, v.specifier) === u.resolve(m) || h.has(v.specifier)) {
4146
+ var c = [ ...s.values() ].sort(((t, r) => compareUtf16(t.argumentKey, r.argumentKey)));
4147
+ var d = "";
4148
+ for (var f of c) {
4149
+ if (d) {
4150
+ d += "\n";
4151
+ }
4152
+ if (f.documentHash) {
4153
+ d += ` /** @gql.tada/hash ${f.documentHash} */\n`;
4154
+ }
4155
+ d += ` ${f.argumentKey}:\n ${f.documentType};`;
4156
+ }
4157
+ var p = "import type { TadaDocumentNode, $tada } from 'gql.tada';\n";
4158
+ var h = "string" == typeof n || n && "object" == typeof n && "toString" in n && !("writable" in n);
4159
+ var g = [ ...a ].sort(((t, r) => compareUtf16(t.absolutePath, r.absolutePath)));
4160
+ var v = new Set;
4161
+ for (var m of g) {
4162
+ for (var y of m.imports) {
4163
+ if (h) {
4164
+ var w = n.toString();
4165
+ var S = u.dirname(m.absolutePath);
4166
+ if (u.resolve(S, y.specifier) === u.resolve(w) || v.has(y.specifier)) {
4163
4167
  continue;
4164
4168
  }
4165
- h.add(v.specifier);
4169
+ v.add(y.specifier);
4166
4170
  }
4167
- f += v.importClause + "\n";
4171
+ p += y.importClause + "\n";
4168
4172
  }
4169
4173
  }
4170
- return o + f + "\ndeclare module 'gql.tada' {\n interface setupCache {\n" + c + "\n }\n}\n";
4174
+ return o + p + "\ndeclare module 'gql.tada' {\n interface setupCache {\n" + d + "\n }\n}\n";
4175
+ }
4176
+
4177
+ function compareUtf16(t, r) {
4178
+ return t < r ? -1 : t > r ? 1 : 0;
4171
4179
  }
4172
4180
 
4173
4181
  class TurboCommand extends Command {
@@ -6546,6 +6554,78 @@ function maybeBind(t, r) {
6546
6554
  return r ? r.bind(t) : void 0;
6547
6555
  }
6548
6556
 
6557
+ var buildProgram = t => {
6558
+ var {program: r, virtualMap: a} = t;
6559
+ var n = ((t, r) => {
6560
+ var toKey = t => "win32" === process.platform ? t.toLowerCase() : t;
6561
+ var a = new Set([ toKey(u.resolve(t)) ]);
6562
+ for (var n of r) {
6563
+ if (u.isAbsolute(n)) {
6564
+ a.add(toKey(u.dirname(n)));
6565
+ }
6566
+ }
6567
+ return t => {
6568
+ var r = toKey(u.dirname(u.resolve(t)));
6569
+ for (;;) {
6570
+ if (a.has(r)) {
6571
+ return !0;
6572
+ }
6573
+ var n = u.dirname(r);
6574
+ if (n === r) {
6575
+ return !1;
6576
+ }
6577
+ r = n;
6578
+ }
6579
+ };
6580
+ })(t.projectRoot, t.rootNames);
6581
+ var i = maybeBind(r, r.isSourceFileFromExternalLibrary);
6582
+ var o = maybeBind(r, r.getModeForResolutionAtIndex);
6583
+ var s = maybeBind(r, r.getSourceFile);
6584
+ var l = maybeBind(r, r.getSourceFiles);
6585
+ var mapSourceFileFn = t => (n, ...i) => {
6586
+ var o = n && a.get(n.fileName);
6587
+ if (o && o.sourceFileId === n?.fileName) {
6588
+ n = s(o.generatedFileId) || n;
6589
+ }
6590
+ return t.call(r, n, ...i);
6591
+ };
6592
+ return Object.assign(r, {
6593
+ getSyntacticDiagnostics: mapSourceFileFn(r.getSyntacticDiagnostics),
6594
+ getSemanticDiagnostics: mapSourceFileFn(r.getSemanticDiagnostics),
6595
+ getDeclarationDiagnostics: mapSourceFileFn(r.getDeclarationDiagnostics),
6596
+ isSourceFileDefaultLibrary: mapSourceFileFn(r.isSourceFileDefaultLibrary),
6597
+ getModeForUsageLocation: mapSourceFileFn(r.getModeForUsageLocation),
6598
+ isSourceFileFromExternalLibrary(t) {
6599
+ var r = a.get(t.fileName);
6600
+ return !(!r || r.sourceFileId !== t.fileName) || i(t);
6601
+ },
6602
+ getSourceFiles() {
6603
+ var t = [];
6604
+ for (var a of l()) {
6605
+ if (n(a.fileName) && !r.isSourceFileFromExternalLibrary(a)) {
6606
+ t.push(a);
6607
+ }
6608
+ }
6609
+ return t;
6610
+ },
6611
+ getSourceFile(t) {
6612
+ var r = a.get(t);
6613
+ if (r && r.sourceFileId === t) {
6614
+ t = r.generatedFileId;
6615
+ }
6616
+ return s(t);
6617
+ },
6618
+ getModeForResolutionAtIndex(t, r) {
6619
+ var n = a.get(t.fileName);
6620
+ if (n && n.sourceFileId === t.fileName) {
6621
+ t = s(n.generatedFileId) || t;
6622
+ r = n.getGeneratedOffset(r)?.[0] ?? r;
6623
+ }
6624
+ return o(t, r);
6625
+ }
6626
+ });
6627
+ };
6628
+
6549
6629
  var buildLanguageService = t => {
6550
6630
  var {virtualMap: r} = t;
6551
6631
  var a = l.createLanguageService(t.languageServiceHost, t.documentRegistry);
@@ -6617,58 +6697,11 @@ var buildLanguageService = t => {
6617
6697
  return i;
6618
6698
  } else {
6619
6699
  var r = n();
6620
- return r ? i = (t => {
6621
- var {program: r, virtualMap: a, projectRoot: n} = t;
6622
- var i = maybeBind(r, r.isSourceFileFromExternalLibrary);
6623
- var o = maybeBind(r, r.getModeForResolutionAtIndex);
6624
- var s = maybeBind(r, r.getSourceFile);
6625
- var l = maybeBind(r, r.getSourceFiles);
6626
- var mapSourceFileFn = t => (n, ...i) => {
6627
- var o = n && a.get(n.fileName);
6628
- if (o && o.sourceFileId === n?.fileName) {
6629
- n = s(o.generatedFileId) || n;
6630
- }
6631
- return t.call(r, n, ...i);
6632
- };
6633
- return Object.assign(r, {
6634
- getSyntacticDiagnostics: mapSourceFileFn(r.getSyntacticDiagnostics),
6635
- getSemanticDiagnostics: mapSourceFileFn(r.getSemanticDiagnostics),
6636
- getDeclarationDiagnostics: mapSourceFileFn(r.getDeclarationDiagnostics),
6637
- isSourceFileDefaultLibrary: mapSourceFileFn(r.isSourceFileDefaultLibrary),
6638
- getModeForUsageLocation: mapSourceFileFn(r.getModeForUsageLocation),
6639
- isSourceFileFromExternalLibrary(t) {
6640
- var r = a.get(t.fileName);
6641
- return !(!r || r.sourceFileId !== t.fileName) || i(t);
6642
- },
6643
- getSourceFiles() {
6644
- var t = [];
6645
- for (var a of l()) {
6646
- if (!u.relative(n, a.fileName).startsWith("..") && !r.isSourceFileFromExternalLibrary(a)) {
6647
- t.push(a);
6648
- }
6649
- }
6650
- return t;
6651
- },
6652
- getSourceFile(t) {
6653
- var r = a.get(t);
6654
- if (r && r.sourceFileId === t) {
6655
- t = r.generatedFileId;
6656
- }
6657
- return s(t);
6658
- },
6659
- getModeForResolutionAtIndex(t, r) {
6660
- var n = a.get(t.fileName);
6661
- if (n && n.sourceFileId === t.fileName) {
6662
- t = s(n.generatedFileId) || t;
6663
- r = n.getGeneratedOffset(r)?.[0] ?? r;
6664
- }
6665
- return o(t, r);
6666
- }
6667
- });
6668
- })({
6700
+ return r ? i = buildProgram({
6669
6701
  program: r,
6670
6702
  virtualMap: t.virtualMap,
6671
- projectRoot: t.projectRoot
6703
+ projectRoot: t.projectRoot,
6704
+ rootNames: t.rootNames
6672
6705
  }) : void 0;
6673
6706
  }
6674
6707
  },
@@ -6904,17 +6937,20 @@ var programFactory = t => {
6904
6937
  var i = new Set(o);
6905
6938
  var s = new Set([ t.rootPath ]);
6906
6939
  for (var c of o) {
6907
- s.add(u.dirname(c));
6908
- }
6909
- for (var d of s) {
6910
- for (var f of n.readDirectory(d, r, [ "**/node_modules" ])) {
6911
- if (!i.has(f)) {
6912
- i.add(f);
6913
- var p = n.readFile(f, "utf8");
6914
- if (p) {
6940
+ var d = u.dirname(c);
6941
+ if (u.isAbsolute(d)) {
6942
+ s.add(d);
6943
+ }
6944
+ }
6945
+ for (var f of s) {
6946
+ for (var p of n.readDirectory(f, r, [ "**/node_modules" ])) {
6947
+ if (!i.has(p)) {
6948
+ i.add(p);
6949
+ var g = n.readFile(p, "utf8");
6950
+ if (g) {
6915
6951
  a.push(h.createSourceFile({
6916
- fileId: f,
6917
- sourceText: p
6952
+ fileId: p,
6953
+ sourceText: g
6918
6954
  }, l.ScriptKind.External));
6919
6955
  }
6920
6956
  }