thinkwell 0.5.5 → 0.5.7

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 (46) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +232 -278
  3. package/dist/agent.js.map +1 -1
  4. package/dist/build.js +44 -98
  5. package/dist/cli/build.js +92 -227
  6. package/dist/cli/bundle.js +570 -1136
  7. package/dist/cli/check.js +125 -214
  8. package/dist/cli/commands.js +63 -177
  9. package/dist/cli/compiler-host.js +81 -190
  10. package/dist/cli/dependency-check.js +125 -269
  11. package/dist/cli/dependency-errors.js +12 -84
  12. package/dist/cli/fmt.js +1 -13
  13. package/dist/cli/init-command.js +21 -68
  14. package/dist/cli/init.js +90 -220
  15. package/dist/cli/loader.js +95 -361
  16. package/dist/cli/new-command.js +25 -73
  17. package/dist/cli/package-manager.js +50 -117
  18. package/dist/cli/schema.d.ts.map +1 -1
  19. package/dist/cli/schema.js +91 -245
  20. package/dist/cli/schema.js.map +1 -1
  21. package/dist/cli/workspace.js +92 -226
  22. package/dist/connectors/index.js +1 -7
  23. package/dist/generated/features.d.ts +6 -0
  24. package/dist/generated/features.d.ts.map +1 -0
  25. package/dist/generated/features.js +5 -0
  26. package/dist/generated/features.js.map +1 -0
  27. package/dist/index.js +0 -5
  28. package/dist/schema.js +3 -36
  29. package/dist/session.js +50 -82
  30. package/dist/think-builder.d.ts.map +1 -1
  31. package/dist/think-builder.js +287 -368
  32. package/dist/think-builder.js.map +1 -1
  33. package/dist/thought-event.d.ts +1 -0
  34. package/dist/thought-event.d.ts.map +1 -1
  35. package/dist/thought-event.js +0 -1
  36. package/dist/thought-stream.js +60 -96
  37. package/dist-pkg/acp.cjs +13386 -1876
  38. package/dist-pkg/cli-build.cjs +264 -446
  39. package/dist-pkg/cli-bundle.cjs +433 -818
  40. package/dist-pkg/cli-check.cjs +302 -499
  41. package/dist-pkg/cli-dependency-check.cjs +39 -82
  42. package/dist-pkg/cli-dependency-errors.cjs +9 -41
  43. package/dist-pkg/cli-loader.cjs +91 -173
  44. package/dist-pkg/protocol.cjs +2 -8
  45. package/dist-pkg/thinkwell.cjs +927 -1846
  46. package/package.json +9 -7
@@ -532,16 +532,16 @@ var require_typescript = __commonJS({
532
532
  var tsp;
533
533
  (function(tsp2) {
534
534
  const activeProgramTransformers = /* @__PURE__ */ new Set();
535
- const { dirname: dirname4 } = require("path");
535
+ const { dirname: dirname5 } = require("path");
536
536
  function getProjectDir(compilerOptions) {
537
- return compilerOptions.configFilePath && dirname4(compilerOptions.configFilePath);
537
+ return compilerOptions.configFilePath && dirname5(compilerOptions.configFilePath);
538
538
  }
539
539
  __name(getProjectDir, "getProjectDir");
540
540
  function getProjectConfig(compilerOptions, rootFileNames) {
541
541
  let configFilePath = compilerOptions.configFilePath;
542
542
  let projectDir = getProjectDir(compilerOptions);
543
543
  if (configFilePath === void 0) {
544
- const baseDir = rootFileNames.length > 0 ? dirname4(rootFileNames[0]) : projectDir ?? process.cwd();
544
+ const baseDir = rootFileNames.length > 0 ? dirname5(rootFileNames[0]) : projectDir ?? process.cwd();
545
545
  configFilePath = tsp2.tsShim.findConfigFile(baseDir, tsp2.tsShim.sys.fileExists);
546
546
  if (configFilePath) {
547
547
  const config = readConfig(configFilePath);
@@ -553,7 +553,7 @@ var require_typescript = __commonJS({
553
553
  }
554
554
  __name(getProjectConfig, "getProjectConfig");
555
555
  function readConfig(configFileNamePath) {
556
- const projectDir = dirname4(configFileNamePath);
556
+ const projectDir = dirname5(configFileNamePath);
557
557
  const result = tsp2.tsShim.readConfigFile(configFileNamePath, tsp2.tsShim.sys.readFile);
558
558
  if (result.error)
559
559
  throw new tsp2.TsPatchError("Error in tsconfig.json: " + result.error.messageText);
@@ -131462,7 +131462,7 @@ ${lanes.join("\n")}
131462
131462
  }
131463
131463
  __name(createImportCallExpressionUMD, "createImportCallExpressionUMD");
131464
131464
  function createImportCallExpressionAMD(arg, containsLexicalThis) {
131465
- const resolve4 = factory2.createUniqueName("resolve");
131465
+ const resolve5 = factory2.createUniqueName("resolve");
131466
131466
  const reject = factory2.createUniqueName("reject");
131467
131467
  const parameters = [
131468
131468
  factory2.createParameterDeclaration(
@@ -131471,7 +131471,7 @@ ${lanes.join("\n")}
131471
131471
  /*dotDotDotToken*/
131472
131472
  void 0,
131473
131473
  /*name*/
131474
- resolve4
131474
+ resolve5
131475
131475
  ),
131476
131476
  factory2.createParameterDeclaration(
131477
131477
  /*modifiers*/
@@ -131488,7 +131488,7 @@ ${lanes.join("\n")}
131488
131488
  factory2.createIdentifier("require"),
131489
131489
  /*typeArguments*/
131490
131490
  void 0,
131491
- [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve4, reject]
131491
+ [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve5, reject]
131492
131492
  )
131493
131493
  )
131494
131494
  ]);
@@ -145024,10 +145024,10 @@ ${lanes.join("\n")}
145024
145024
  /*ignoreCase*/
145025
145025
  false
145026
145026
  )) {
145027
- const basename = getBaseFileName(a.fileName);
145028
- if (basename === "lib.d.ts" || basename === "lib.es6.d.ts")
145027
+ const basename2 = getBaseFileName(a.fileName);
145028
+ if (basename2 === "lib.d.ts" || basename2 === "lib.es6.d.ts")
145029
145029
  return 0;
145030
- const name = removeSuffix(removePrefix(basename, "lib."), ".d.ts");
145030
+ const name = removeSuffix(removePrefix(basename2, "lib."), ".d.ts");
145031
145031
  const index = libs.indexOf(name);
145032
145032
  if (index !== -1)
145033
145033
  return index + 1;
@@ -211800,8 +211800,8 @@ ${options.prefix}` : "\n" : options.prefix
211800
211800
  }
211801
211801
  }, "createProjectWatcher");
211802
211802
  for (const file of files) {
211803
- const basename = getBaseFileName(file);
211804
- if (basename === "package.json" || basename === "bower.json") {
211803
+ const basename2 = getBaseFileName(file);
211804
+ if (basename2 === "package.json" || basename2 === "bower.json") {
211805
211805
  createProjectWatcher(
211806
211806
  file,
211807
211807
  "FileWatcher"
@@ -215547,8 +215547,8 @@ All files are: ${JSON.stringify(names)}`,
215547
215547
  var _a;
215548
215548
  const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
215549
215549
  if (!fileOrDirectoryPath) return;
215550
- const basename = getBaseFileName(fileOrDirectoryPath);
215551
- if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename === "package.json" || basename === "node_modules")) {
215550
+ const basename2 = getBaseFileName(fileOrDirectoryPath);
215551
+ if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename2 === "package.json" || basename2 === "node_modules")) {
215552
215552
  result.affectedModuleSpecifierCacheProjects.forEach((project) => {
215553
215553
  var _a2;
215554
215554
  (_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
@@ -222134,8 +222134,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
222134
222134
  installPackage(options) {
222135
222135
  this.packageInstallId++;
222136
222136
  const request = { kind: "installPackage", ...options, id: this.packageInstallId };
222137
- const promise = new Promise((resolve4, reject) => {
222138
- (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve4, reject });
222137
+ const promise = new Promise((resolve5, reject) => {
222138
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve5, reject });
222139
222139
  });
222140
222140
  this.installer.send(request);
222141
222141
  return promise;
@@ -222538,12 +222538,12 @@ function __metadata(metadataKey, metadataValue) {
222538
222538
  }
222539
222539
  function __awaiter(thisArg, _arguments, P, generator) {
222540
222540
  function adopt(value) {
222541
- return value instanceof P ? value : new P(function(resolve4) {
222542
- resolve4(value);
222541
+ return value instanceof P ? value : new P(function(resolve5) {
222542
+ resolve5(value);
222543
222543
  });
222544
222544
  }
222545
222545
  __name(adopt, "adopt");
222546
- return new (P || (P = Promise))(function(resolve4, reject) {
222546
+ return new (P || (P = Promise))(function(resolve5, reject) {
222547
222547
  function fulfilled(value) {
222548
222548
  try {
222549
222549
  step(generator.next(value));
@@ -222561,7 +222561,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
222561
222561
  }
222562
222562
  __name(rejected, "rejected");
222563
222563
  function step(result) {
222564
- result.done ? resolve4(result.value) : adopt(result.value).then(fulfilled, rejected);
222564
+ result.done ? resolve5(result.value) : adopt(result.value).then(fulfilled, rejected);
222565
222565
  }
222566
222566
  __name(step, "step");
222567
222567
  step((generator = generator.apply(thisArg, _arguments || [])).next());
@@ -222763,15 +222763,15 @@ function __asyncValues(o) {
222763
222763
  }, i);
222764
222764
  function verb(n) {
222765
222765
  i[n] = o[n] && function(v) {
222766
- return new Promise(function(resolve4, reject) {
222767
- v = o[n](v), settle(resolve4, reject, v.done, v.value);
222766
+ return new Promise(function(resolve5, reject) {
222767
+ v = o[n](v), settle(resolve5, reject, v.done, v.value);
222768
222768
  });
222769
222769
  };
222770
222770
  }
222771
222771
  __name(verb, "verb");
222772
- function settle(resolve4, reject, d, v) {
222772
+ function settle(resolve5, reject, d, v) {
222773
222773
  Promise.resolve(v).then(function(v2) {
222774
- resolve4({ value: v2, done: d });
222774
+ resolve5({ value: v2, done: d });
222775
222775
  }, reject);
222776
222776
  }
222777
222777
  __name(settle, "settle");
@@ -223419,7 +223419,7 @@ var require_safe_stable_stringify = __commonJS({
223419
223419
  return circularValue;
223420
223420
  }
223421
223421
  let res = "";
223422
- let join8 = ",";
223422
+ let join9 = ",";
223423
223423
  const originalIndentation = indentation;
223424
223424
  if (Array.isArray(value)) {
223425
223425
  if (value.length === 0) {
@@ -223433,7 +223433,7 @@ var require_safe_stable_stringify = __commonJS({
223433
223433
  indentation += spacer;
223434
223434
  res += `
223435
223435
  ${indentation}`;
223436
- join8 = `,
223436
+ join9 = `,
223437
223437
  ${indentation}`;
223438
223438
  }
223439
223439
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -223441,13 +223441,13 @@ ${indentation}`;
223441
223441
  for (; i < maximumValuesToStringify - 1; i++) {
223442
223442
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
223443
223443
  res += tmp2 !== void 0 ? tmp2 : "null";
223444
- res += join8;
223444
+ res += join9;
223445
223445
  }
223446
223446
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
223447
223447
  res += tmp !== void 0 ? tmp : "null";
223448
223448
  if (value.length - 1 > maximumBreadth) {
223449
223449
  const removedKeys = value.length - maximumBreadth - 1;
223450
- res += `${join8}"... ${getItemCount(removedKeys)} not stringified"`;
223450
+ res += `${join9}"... ${getItemCount(removedKeys)} not stringified"`;
223451
223451
  }
223452
223452
  if (spacer !== "") {
223453
223453
  res += `
@@ -223468,7 +223468,7 @@ ${originalIndentation}`;
223468
223468
  let separator = "";
223469
223469
  if (spacer !== "") {
223470
223470
  indentation += spacer;
223471
- join8 = `,
223471
+ join9 = `,
223472
223472
  ${indentation}`;
223473
223473
  whitespace = " ";
223474
223474
  }
@@ -223482,13 +223482,13 @@ ${indentation}`;
223482
223482
  const tmp = stringifyFnReplacer(key3, value, stack, replacer, spacer, indentation);
223483
223483
  if (tmp !== void 0) {
223484
223484
  res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
223485
- separator = join8;
223485
+ separator = join9;
223486
223486
  }
223487
223487
  }
223488
223488
  if (keyLength > maximumBreadth) {
223489
223489
  const removedKeys = keyLength - maximumBreadth;
223490
223490
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
223491
- separator = join8;
223491
+ separator = join9;
223492
223492
  }
223493
223493
  if (spacer !== "" && separator.length > 1) {
223494
223494
  res = `
@@ -223530,7 +223530,7 @@ ${originalIndentation}`;
223530
223530
  }
223531
223531
  const originalIndentation = indentation;
223532
223532
  let res = "";
223533
- let join8 = ",";
223533
+ let join9 = ",";
223534
223534
  if (Array.isArray(value)) {
223535
223535
  if (value.length === 0) {
223536
223536
  return "[]";
@@ -223543,7 +223543,7 @@ ${originalIndentation}`;
223543
223543
  indentation += spacer;
223544
223544
  res += `
223545
223545
  ${indentation}`;
223546
- join8 = `,
223546
+ join9 = `,
223547
223547
  ${indentation}`;
223548
223548
  }
223549
223549
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -223551,13 +223551,13 @@ ${indentation}`;
223551
223551
  for (; i < maximumValuesToStringify - 1; i++) {
223552
223552
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
223553
223553
  res += tmp2 !== void 0 ? tmp2 : "null";
223554
- res += join8;
223554
+ res += join9;
223555
223555
  }
223556
223556
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
223557
223557
  res += tmp !== void 0 ? tmp : "null";
223558
223558
  if (value.length - 1 > maximumBreadth) {
223559
223559
  const removedKeys = value.length - maximumBreadth - 1;
223560
- res += `${join8}"... ${getItemCount(removedKeys)} not stringified"`;
223560
+ res += `${join9}"... ${getItemCount(removedKeys)} not stringified"`;
223561
223561
  }
223562
223562
  if (spacer !== "") {
223563
223563
  res += `
@@ -223570,7 +223570,7 @@ ${originalIndentation}`;
223570
223570
  let whitespace = "";
223571
223571
  if (spacer !== "") {
223572
223572
  indentation += spacer;
223573
- join8 = `,
223573
+ join9 = `,
223574
223574
  ${indentation}`;
223575
223575
  whitespace = " ";
223576
223576
  }
@@ -223579,7 +223579,7 @@ ${indentation}`;
223579
223579
  const tmp = stringifyArrayReplacer(key3, value[key3], stack, replacer, spacer, indentation);
223580
223580
  if (tmp !== void 0) {
223581
223581
  res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
223582
- separator = join8;
223582
+ separator = join9;
223583
223583
  }
223584
223584
  }
223585
223585
  if (spacer !== "" && separator.length > 1) {
@@ -223638,20 +223638,20 @@ ${originalIndentation}`;
223638
223638
  indentation += spacer;
223639
223639
  let res2 = `
223640
223640
  ${indentation}`;
223641
- const join9 = `,
223641
+ const join10 = `,
223642
223642
  ${indentation}`;
223643
223643
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
223644
223644
  let i = 0;
223645
223645
  for (; i < maximumValuesToStringify - 1; i++) {
223646
223646
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
223647
223647
  res2 += tmp2 !== void 0 ? tmp2 : "null";
223648
- res2 += join9;
223648
+ res2 += join10;
223649
223649
  }
223650
223650
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
223651
223651
  res2 += tmp !== void 0 ? tmp : "null";
223652
223652
  if (value.length - 1 > maximumBreadth) {
223653
223653
  const removedKeys = value.length - maximumBreadth - 1;
223654
- res2 += `${join9}"... ${getItemCount(removedKeys)} not stringified"`;
223654
+ res2 += `${join10}"... ${getItemCount(removedKeys)} not stringified"`;
223655
223655
  }
223656
223656
  res2 += `
223657
223657
  ${originalIndentation}`;
@@ -223667,16 +223667,16 @@ ${originalIndentation}`;
223667
223667
  return '"[Object]"';
223668
223668
  }
223669
223669
  indentation += spacer;
223670
- const join8 = `,
223670
+ const join9 = `,
223671
223671
  ${indentation}`;
223672
223672
  let res = "";
223673
223673
  let separator = "";
223674
223674
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
223675
223675
  if (isTypedArrayWithEntries(value)) {
223676
- res += stringifyTypedArray(value, join8, maximumBreadth);
223676
+ res += stringifyTypedArray(value, join9, maximumBreadth);
223677
223677
  keys = keys.slice(value.length);
223678
223678
  maximumPropertiesToStringify -= value.length;
223679
- separator = join8;
223679
+ separator = join9;
223680
223680
  }
223681
223681
  if (deterministic) {
223682
223682
  keys = sort(keys, comparator);
@@ -223687,13 +223687,13 @@ ${indentation}`;
223687
223687
  const tmp = stringifyIndent(key3, value[key3], stack, spacer, indentation);
223688
223688
  if (tmp !== void 0) {
223689
223689
  res += `${separator}${strEscape(key3)}: ${tmp}`;
223690
- separator = join8;
223690
+ separator = join9;
223691
223691
  }
223692
223692
  }
223693
223693
  if (keyLength > maximumBreadth) {
223694
223694
  const removedKeys = keyLength - maximumBreadth;
223695
223695
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
223696
- separator = join8;
223696
+ separator = join9;
223697
223697
  }
223698
223698
  if (separator !== "") {
223699
223699
  res = `
@@ -235168,10 +235168,10 @@ var require_commonjs5 = __commonJS({
235168
235168
  * Return a void Promise that resolves once the stream ends.
235169
235169
  */
235170
235170
  async promise() {
235171
- return new Promise((resolve4, reject) => {
235171
+ return new Promise((resolve5, reject) => {
235172
235172
  this.on(DESTROYED, () => reject(new Error("stream destroyed")));
235173
235173
  this.on("error", (er) => reject(er));
235174
- this.on("end", () => resolve4());
235174
+ this.on("end", () => resolve5());
235175
235175
  });
235176
235176
  }
235177
235177
  /**
@@ -235195,7 +235195,7 @@ var require_commonjs5 = __commonJS({
235195
235195
  return Promise.resolve({ done: false, value: res });
235196
235196
  if (this[EOF])
235197
235197
  return stop();
235198
- let resolve4;
235198
+ let resolve5;
235199
235199
  let reject;
235200
235200
  const onerr = /* @__PURE__ */ __name((er) => {
235201
235201
  this.off("data", ondata);
@@ -235209,19 +235209,19 @@ var require_commonjs5 = __commonJS({
235209
235209
  this.off("end", onend);
235210
235210
  this.off(DESTROYED, ondestroy);
235211
235211
  this.pause();
235212
- resolve4({ value, done: !!this[EOF] });
235212
+ resolve5({ value, done: !!this[EOF] });
235213
235213
  }, "ondata");
235214
235214
  const onend = /* @__PURE__ */ __name(() => {
235215
235215
  this.off("error", onerr);
235216
235216
  this.off("data", ondata);
235217
235217
  this.off(DESTROYED, ondestroy);
235218
235218
  stop();
235219
- resolve4({ done: true, value: void 0 });
235219
+ resolve5({ done: true, value: void 0 });
235220
235220
  }, "onend");
235221
235221
  const ondestroy = /* @__PURE__ */ __name(() => onerr(new Error("stream destroyed")), "ondestroy");
235222
235222
  return new Promise((res2, rej) => {
235223
235223
  reject = rej;
235224
- resolve4 = res2;
235224
+ resolve5 = res2;
235225
235225
  this.once(DESTROYED, ondestroy);
235226
235226
  this.once("error", onerr);
235227
235227
  this.once("end", onend);
@@ -236246,9 +236246,9 @@ var require_commonjs6 = __commonJS({
236246
236246
  if (this.#asyncReaddirInFlight) {
236247
236247
  await this.#asyncReaddirInFlight;
236248
236248
  } else {
236249
- let resolve4 = /* @__PURE__ */ __name(() => {
236249
+ let resolve5 = /* @__PURE__ */ __name(() => {
236250
236250
  }, "resolve");
236251
- this.#asyncReaddirInFlight = new Promise((res) => resolve4 = res);
236251
+ this.#asyncReaddirInFlight = new Promise((res) => resolve5 = res);
236252
236252
  try {
236253
236253
  for (const e of await this.#fs.promises.readdir(fullpath, {
236254
236254
  withFileTypes: true
@@ -236261,7 +236261,7 @@ var require_commonjs6 = __commonJS({
236261
236261
  children.provisional = 0;
236262
236262
  }
236263
236263
  this.#asyncReaddirInFlight = void 0;
236264
- resolve4();
236264
+ resolve5();
236265
236265
  }
236266
236266
  return children.slice(0, children.provisional);
236267
236267
  }
@@ -238603,18 +238603,18 @@ __export(check_exports, {
238603
238603
  });
238604
238604
  module.exports = __toCommonJS(check_exports);
238605
238605
  var import_typescript3 = __toESM(require_typescript(), 1);
238606
- var import_node_fs6 = require("node:fs");
238607
- var import_node_path7 = require("node:path");
238606
+ var import_node_fs7 = require("node:fs");
238607
+ var import_node_path8 = require("node:path");
238608
238608
 
238609
238609
  // dist/cli/compiler-host.js
238610
238610
  var import_typescript2 = __toESM(require_typescript(), 1);
238611
- var import_node_path3 = require("node:path");
238612
- var import_node_fs2 = require("node:fs");
238611
+ var import_node_path4 = require("node:path");
238612
+ var import_node_fs3 = require("node:fs");
238613
238613
 
238614
238614
  // dist/cli/schema.js
238615
238615
  var import_typescript = __toESM(require_typescript(), 1);
238616
- var import_node_path2 = require("node:path");
238617
- var import_node_module = require("node:module");
238616
+ var import_node_path3 = require("node:path");
238617
+ var import_node_module2 = require("node:module");
238618
238618
 
238619
238619
  // dist/build.js
238620
238620
  var import_node_path = require("node:path");
@@ -238622,61 +238622,49 @@ var import_node_fs = require("node:fs");
238622
238622
  var import_ts_json_schema_generator = __toESM(require_dist(), 1);
238623
238623
  function findTsConfig(startDir) {
238624
238624
  let dir = startDir;
238625
- while (true) {
238625
+ for (; ; ) {
238626
238626
  const configPath = (0, import_node_path.join)(dir, "tsconfig.json");
238627
- if ((0, import_node_fs.existsSync)(configPath)) {
238627
+ if ((0, import_node_fs.existsSync)(configPath))
238628
238628
  return configPath;
238629
- }
238630
238629
  const parent = (0, import_node_path.dirname)(dir);
238631
- if (parent === dir) {
238632
- return void 0;
238633
- }
238630
+ if (parent === dir)
238631
+ return;
238634
238632
  dir = parent;
238635
238633
  }
238636
238634
  }
238637
238635
  __name(findTsConfig, "findTsConfig");
238638
238636
  function inlineRefs(obj, definitions) {
238639
- if (obj === null || typeof obj !== "object") {
238637
+ if (obj === null || typeof obj != "object")
238640
238638
  return obj;
238641
- }
238642
- if (Array.isArray(obj)) {
238639
+ if (Array.isArray(obj))
238643
238640
  return obj.map((item) => inlineRefs(item, definitions));
238644
- }
238645
238641
  const record = obj;
238646
- if (typeof record["$ref"] === "string") {
238647
- const ref = record["$ref"];
238648
- const match = ref.match(/^#\/definitions\/(.+)$/);
238649
- if (match && definitions[match[1]]) {
238642
+ if (typeof record.$ref == "string") {
238643
+ const match = record.$ref.match(/^#\/definitions\/(.+)$/);
238644
+ if (match && definitions[match[1]])
238650
238645
  return inlineRefs(definitions[match[1]], definitions);
238651
- }
238652
238646
  }
238653
238647
  const result = {};
238654
- for (const [key2, value] of Object.entries(record)) {
238648
+ for (const [key2, value] of Object.entries(record))
238655
238649
  result[key2] = inlineRefs(value, definitions);
238656
- }
238657
238650
  return result;
238658
238651
  }
238659
238652
  __name(inlineRefs, "inlineRefs");
238660
238653
  function cleanSchema(typeName, schema) {
238661
238654
  const definitions = schema.definitions || {};
238662
238655
  let result = definitions[typeName] || schema;
238663
- result = inlineRefs(result, definitions);
238664
- if (typeof result === "object" && result !== null) {
238656
+ if (result = inlineRefs(result, definitions), typeof result == "object" && result !== null) {
238665
238657
  const cleaned = { ...result };
238666
- delete cleaned["$schema"];
238667
- delete cleaned["definitions"];
238668
- return cleaned;
238658
+ return delete cleaned.$schema, delete cleaned.definitions, cleaned;
238669
238659
  }
238670
238660
  return result;
238671
238661
  }
238672
238662
  __name(cleanSchema, "cleanSchema");
238673
238663
  function generateSchemas(filePath, typeNames) {
238674
238664
  const schemas = /* @__PURE__ */ new Map();
238675
- if (typeNames.length === 0) {
238665
+ if (typeNames.length === 0)
238676
238666
  return schemas;
238677
- }
238678
- const configPath = findTsConfig((0, import_node_path.dirname)(filePath));
238679
- const generator = (0, import_ts_json_schema_generator.createGenerator)({
238667
+ const configPath = findTsConfig((0, import_node_path.dirname)(filePath)), generator = (0, import_ts_json_schema_generator.createGenerator)({
238680
238668
  path: filePath,
238681
238669
  ...configPath && { tsconfig: configPath },
238682
238670
  skipTypeCheck: true,
@@ -238690,11 +238678,25 @@ function generateSchemas(filePath, typeNames) {
238690
238678
  }
238691
238679
  __name(generateSchemas, "generateSchemas");
238692
238680
 
238681
+ // dist/cli/loader.js
238682
+ var import_node_fs2 = require("node:fs");
238683
+ var import_node_path2 = require("node:path");
238684
+ var import_node_crypto = require("node:crypto");
238685
+ var import_node_module = require("node:module");
238686
+ function extractShebang(source) {
238687
+ if (source.startsWith("#!")) {
238688
+ const newlineIndex = source.indexOf(`
238689
+ `);
238690
+ return newlineIndex !== -1 ? [source.slice(0, newlineIndex + 1), source.slice(newlineIndex + 1)] : [source, ""];
238691
+ }
238692
+ return ["", source];
238693
+ }
238694
+ __name(extractShebang, "extractShebang");
238695
+
238693
238696
  // dist/cli/schema.js
238694
238697
  var JSONSCHEMA_TAG = "JSONSchema";
238695
238698
  function hasJsDocTag(node, tagName) {
238696
- const jsDocNodes = import_typescript.default.getJSDocTags(node);
238697
- return jsDocNodes.some((tag) => tag.tagName.text === tagName);
238699
+ return import_typescript.default.getJSDocTags(node).some((tag) => tag.tagName.text === tagName);
238698
238700
  }
238699
238701
  __name(hasJsDocTag, "hasJsDocTag");
238700
238702
  function findMarkedTypes(path, source) {
@@ -238704,48 +238706,36 @@ function findMarkedTypes(path, source) {
238704
238706
  import_typescript.default.ScriptTarget.Latest,
238705
238707
  true
238706
238708
  // setParentNodes - needed for JSDoc traversal
238707
- );
238708
- const results = [];
238709
- import_typescript.default.forEachChild(sourceFile, /* @__PURE__ */ __name(function visit(node) {
238710
- if (import_typescript.default.isInterfaceDeclaration(node) || import_typescript.default.isTypeAliasDeclaration(node) || import_typescript.default.isEnumDeclaration(node) || import_typescript.default.isClassDeclaration(node)) {
238711
- if (hasJsDocTag(node, JSONSCHEMA_TAG)) {
238712
- const name = node.name?.text;
238713
- if (name) {
238714
- const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
238715
- let keyword = "interface";
238716
- if (import_typescript.default.isTypeAliasDeclaration(node))
238717
- keyword = "type";
238718
- else if (import_typescript.default.isEnumDeclaration(node))
238719
- keyword = "enum";
238720
- else if (import_typescript.default.isClassDeclaration(node))
238721
- keyword = "class";
238722
- const declarationLength = keyword.length + 1 + name.length;
238723
- const isExported = node.modifiers?.some((m) => m.kind === import_typescript.default.SyntaxKind.ExportKeyword) ?? false;
238724
- results.push({
238725
- name,
238726
- node,
238727
- startPosition: node.getStart(),
238728
- endPosition: node.getEnd(),
238729
- line: line + 1,
238730
- column: character + 1,
238731
- declarationLength,
238732
- isExported
238733
- });
238734
- }
238709
+ ), results = [];
238710
+ return import_typescript.default.forEachChild(sourceFile, /* @__PURE__ */ __name(function visit(node) {
238711
+ if ((import_typescript.default.isInterfaceDeclaration(node) || import_typescript.default.isTypeAliasDeclaration(node) || import_typescript.default.isEnumDeclaration(node) || import_typescript.default.isClassDeclaration(node)) && hasJsDocTag(node, JSONSCHEMA_TAG)) {
238712
+ const name = node.name?.text;
238713
+ if (name) {
238714
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
238715
+ let keyword = "interface";
238716
+ import_typescript.default.isTypeAliasDeclaration(node) ? keyword = "type" : import_typescript.default.isEnumDeclaration(node) ? keyword = "enum" : import_typescript.default.isClassDeclaration(node) && (keyword = "class");
238717
+ const declarationLength = keyword.length + 1 + name.length, isExported = node.modifiers?.some((m) => m.kind === import_typescript.default.SyntaxKind.ExportKeyword) ?? false;
238718
+ results.push({
238719
+ name,
238720
+ node,
238721
+ startPosition: node.getStart(),
238722
+ endPosition: node.getEnd(),
238723
+ line: line + 1,
238724
+ column: character + 1,
238725
+ declarationLength,
238726
+ isExported
238727
+ });
238735
238728
  }
238736
238729
  }
238737
238730
  import_typescript.default.forEachChild(node, visit);
238738
- }, "visit"));
238739
- return results;
238731
+ }, "visit")), results;
238740
238732
  }
238741
238733
  __name(findMarkedTypes, "findMarkedTypes");
238742
238734
  function resolveGenerateSchemas(projectDir) {
238743
238735
  if (projectDir) {
238744
- const projectRequire = (0, import_node_module.createRequire)((0, import_node_path2.join)(projectDir, "package.json"));
238745
- const buildMod = projectRequire("thinkwell/build");
238746
- if (typeof buildMod.generateSchemas === "function") {
238736
+ const buildMod = (0, import_node_module2.createRequire)((0, import_node_path3.join)(projectDir, "package.json"))("thinkwell/build");
238737
+ if (typeof buildMod.generateSchemas == "function")
238747
238738
  return buildMod.generateSchemas;
238748
- }
238749
238739
  throw new Error(`thinkwell/build resolved from ${projectDir} but does not export generateSchemas. This may indicate a version mismatch \u2014 try updating the thinkwell dependency.`);
238750
238740
  }
238751
238741
  return generateSchemas;
@@ -238753,18 +238743,14 @@ function resolveGenerateSchemas(projectDir) {
238753
238743
  __name(resolveGenerateSchemas, "resolveGenerateSchemas");
238754
238744
  function generateSchemas2(path, types, sourceCode, projectDir) {
238755
238745
  const schemas = /* @__PURE__ */ new Map();
238756
- if (types.length === 0) {
238746
+ if (types.length === 0)
238757
238747
  return schemas;
238758
- }
238759
238748
  const buildGenerateSchemas = resolveGenerateSchemas(projectDir);
238760
238749
  for (const typeInfo of types) {
238761
238750
  const { name, line, column } = typeInfo;
238762
238751
  try {
238763
- const result = buildGenerateSchemas(path, [name]);
238764
- const schema = result.get(name);
238765
- if (schema) {
238766
- schemas.set(name, schema);
238767
- }
238752
+ const schema = buildGenerateSchemas(path, [name]).get(name);
238753
+ schema && schemas.set(name, schema);
238768
238754
  } catch (error) {
238769
238755
  const errorMessage = error instanceof Error ? error.message : String(error);
238770
238756
  throw new Error(`Failed to generate schema for type '${name}' at ${path}:${line}:${column}
@@ -238777,27 +238763,27 @@ function generateSchemas2(path, types, sourceCode, projectDir) {
238777
238763
  __name(generateSchemas2, "generateSchemas");
238778
238764
  var ACP_NAMESPACE = "$$__thinkwell__acp__$$";
238779
238765
  function generateNamespace(name, schema, isExported) {
238780
- const schemaJson = JSON.stringify(schema, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n");
238781
- const exportPrefix = isExported ? "export " : "";
238766
+ const schemaJson = JSON.stringify(schema, null, 2).split(`
238767
+ `).map((line, i) => i === 0 ? line : " " + line).join(`
238768
+ `);
238782
238769
  return [
238783
- `${exportPrefix}namespace ${name} {`,
238770
+ `${isExported ? "export " : ""}namespace ${name} {`,
238784
238771
  ` export const Schema: ${ACP_NAMESPACE}.SchemaProvider<${name}> = {`,
238785
238772
  ` toJsonSchema: () => (${schemaJson}) as ${ACP_NAMESPACE}.JsonSchema,`,
238786
- ` };`,
238787
- `}`
238788
- ].join("\n");
238773
+ " };",
238774
+ "}"
238775
+ ].join(`
238776
+ `);
238789
238777
  }
238790
238778
  __name(generateNamespace, "generateNamespace");
238791
238779
  function generateInsertions(types, schemas) {
238792
238780
  const insertions = [];
238793
238781
  for (const { name, endPosition, isExported } of types) {
238794
238782
  const schema = schemas.get(name);
238795
- if (!schema) {
238796
- continue;
238797
- }
238798
- insertions.push({
238783
+ schema && insertions.push({
238799
238784
  position: endPosition,
238800
- code: "\n" + generateNamespace(name, schema, isExported)
238785
+ code: `
238786
+ ` + generateNamespace(name, schema, isExported)
238801
238787
  });
238802
238788
  }
238803
238789
  return insertions.sort((a, b) => b.position - a.position);
@@ -238809,9 +238795,8 @@ function generateSchemaImport() {
238809
238795
  __name(generateSchemaImport, "generateSchemaImport");
238810
238796
  function applyInsertions(source, insertions) {
238811
238797
  let result = source;
238812
- for (const { position, code } of insertions) {
238798
+ for (const { position, code } of insertions)
238813
238799
  result = result.slice(0, position) + code + result.slice(position);
238814
- }
238815
238800
  return result;
238816
238801
  }
238817
238802
  __name(applyInsertions, "applyInsertions");
@@ -238820,43 +238805,38 @@ function hasJsonSchemaMarkers(source) {
238820
238805
  }
238821
238806
  __name(hasJsonSchemaMarkers, "hasJsonSchemaMarkers");
238822
238807
  function transformJsonSchemas(path, source, projectDir) {
238823
- if (!hasJsonSchemaMarkers(source)) {
238808
+ if (!hasJsonSchemaMarkers(source))
238824
238809
  return source;
238825
- }
238826
238810
  const markedTypes = findMarkedTypes(path, source);
238827
- if (markedTypes.length === 0) {
238811
+ if (markedTypes.length === 0)
238828
238812
  return source;
238829
- }
238830
- const schemas = generateSchemas2(path, markedTypes, source, projectDir);
238831
- const insertions = generateInsertions(markedTypes, schemas);
238813
+ const schemas = generateSchemas2(path, markedTypes, source, projectDir), insertions = generateInsertions(markedTypes, schemas);
238832
238814
  let modifiedSource = applyInsertions(source, insertions);
238833
- modifiedSource = generateSchemaImport() + "\n" + modifiedSource;
238834
- return modifiedSource;
238815
+ const [shebang, rest] = extractShebang(modifiedSource);
238816
+ return modifiedSource = shebang + generateSchemaImport() + `
238817
+ ` + rest, modifiedSource;
238835
238818
  }
238836
238819
  __name(transformJsonSchemas, "transformJsonSchemas");
238837
238820
 
238838
238821
  // dist/cli/compiler-host.js
238839
238822
  function getTypeScriptLibDir() {
238840
- if (typeof process.pkg !== "undefined") {
238823
+ if (typeof process.pkg < "u") {
238841
238824
  const snapshotLibDir = "/snapshot/thinkwell/packages/thinkwell/dist-pkg/typescript-lib";
238842
- if ((0, import_node_fs2.existsSync)(snapshotLibDir)) {
238825
+ if ((0, import_node_fs3.existsSync)(snapshotLibDir))
238843
238826
  return snapshotLibDir;
238844
- }
238845
238827
  }
238846
- return (0, import_node_path3.dirname)(import_typescript2.default.getDefaultLibFilePath({}));
238828
+ return (0, import_node_path4.dirname)(import_typescript2.default.getDefaultLibFilePath({}));
238847
238829
  }
238848
238830
  __name(getTypeScriptLibDir, "getTypeScriptLibDir");
238849
238831
  function parseTsConfig(configPath) {
238850
238832
  const configFile = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
238851
- if (configFile.error) {
238833
+ if (configFile.error)
238852
238834
  return {
238853
238835
  options: {},
238854
238836
  fileNames: [],
238855
238837
  errors: [configFile.error]
238856
238838
  };
238857
- }
238858
- const configDir = (0, import_node_path3.dirname)(configPath);
238859
- const parsed = import_typescript2.default.parseJsonConfigFileContent(
238839
+ const configDir = (0, import_node_path4.dirname)(configPath), parsed = import_typescript2.default.parseJsonConfigFileContent(
238860
238840
  configFile.config,
238861
238841
  import_typescript2.default.sys,
238862
238842
  configDir,
@@ -238872,32 +238852,17 @@ function parseTsConfig(configPath) {
238872
238852
  }
238873
238853
  __name(parseTsConfig, "parseTsConfig");
238874
238854
  function shouldTransform(fileName) {
238875
- if (fileName.includes("node_modules"))
238876
- return false;
238877
- if (fileName.includes("/lib/lib."))
238878
- return false;
238879
- return true;
238855
+ return !(fileName.includes("node_modules") || fileName.includes("/lib/lib."));
238880
238856
  }
238881
238857
  __name(shouldTransform, "shouldTransform");
238882
238858
  function isThinkwellHostOptions(options) {
238883
- return typeof options.compilerOptions === "object" && options.compilerOptions !== null && !Array.isArray(options.compilerOptions);
238859
+ return typeof options.compilerOptions == "object" && options.compilerOptions !== null && !Array.isArray(options.compilerOptions);
238884
238860
  }
238885
238861
  __name(isThinkwellHostOptions, "isThinkwellHostOptions");
238886
238862
  function createThinkwellHost(options) {
238887
- let compilerOptions;
238888
- let fileFilter;
238889
- let projectDir;
238890
- if (isThinkwellHostOptions(options)) {
238891
- compilerOptions = options.compilerOptions;
238892
- fileFilter = options.fileFilter;
238893
- projectDir = options.projectDir;
238894
- } else {
238895
- compilerOptions = options;
238896
- fileFilter = void 0;
238897
- projectDir = void 0;
238898
- }
238899
- const defaultHost = import_typescript2.default.createCompilerHost(compilerOptions);
238900
- const tsLibDir = getTypeScriptLibDir();
238863
+ let compilerOptions, fileFilter, projectDir;
238864
+ isThinkwellHostOptions(options) ? (compilerOptions = options.compilerOptions, fileFilter = options.fileFilter, projectDir = options.projectDir) : (compilerOptions = options, fileFilter = void 0, projectDir = void 0);
238865
+ const defaultHost = import_typescript2.default.createCompilerHost(compilerOptions), tsLibDir = getTypeScriptLibDir();
238901
238866
  return {
238902
238867
  ...defaultHost,
238903
238868
  // Override getDefaultLibLocation to point to our bundled TypeScript lib files
@@ -238907,45 +238872,33 @@ function createThinkwellHost(options) {
238907
238872
  return tsLibDir;
238908
238873
  },
238909
238874
  getDefaultLibFileName(options2) {
238910
- return (0, import_node_path3.join)(tsLibDir, import_typescript2.default.getDefaultLibFileName(options2));
238875
+ return (0, import_node_path4.join)(tsLibDir, import_typescript2.default.getDefaultLibFileName(options2));
238911
238876
  },
238912
238877
  getSourceFile(fileName, languageVersionOrOptions) {
238913
238878
  const source = import_typescript2.default.sys.readFile(fileName);
238914
- if (source === void 0) {
238915
- return void 0;
238916
- }
238917
- if (shouldTransform(fileName) && hasJsonSchemaMarkers(source)) {
238918
- if (!fileFilter || fileFilter(fileName)) {
238879
+ if (source !== void 0) {
238880
+ if (shouldTransform(fileName) && hasJsonSchemaMarkers(source) && (!fileFilter || fileFilter(fileName))) {
238919
238881
  const transformed = transformJsonSchemas(fileName, source, projectDir);
238920
238882
  return import_typescript2.default.createSourceFile(fileName, transformed, languageVersionOrOptions);
238921
238883
  }
238884
+ return import_typescript2.default.createSourceFile(fileName, source, languageVersionOrOptions);
238922
238885
  }
238923
- return import_typescript2.default.createSourceFile(fileName, source, languageVersionOrOptions);
238924
238886
  }
238925
238887
  };
238926
238888
  }
238927
238889
  __name(createThinkwellHost, "createThinkwellHost");
238928
238890
  function createThinkwellProgram(configPathOrOptions) {
238929
- const configPath = typeof configPathOrOptions === "string" ? configPathOrOptions : configPathOrOptions.configPath;
238930
- const fileFilter = typeof configPathOrOptions === "object" ? configPathOrOptions.fileFilter : void 0;
238931
- const projectDir = typeof configPathOrOptions === "object" ? configPathOrOptions.projectDir : void 0;
238932
- const resolvedConfigPath = (0, import_node_path3.resolve)(configPath);
238933
- const { options, fileNames, errors } = parseTsConfig(resolvedConfigPath);
238891
+ const configPath = typeof configPathOrOptions == "string" ? configPathOrOptions : configPathOrOptions.configPath, fileFilter = typeof configPathOrOptions == "object" ? configPathOrOptions.fileFilter : void 0, projectDir = typeof configPathOrOptions == "object" ? configPathOrOptions.projectDir : void 0, resolvedConfigPath = (0, import_node_path4.resolve)(configPath), { options, fileNames, errors } = parseTsConfig(resolvedConfigPath);
238934
238892
  function makeHost() {
238935
- return fileFilter || projectDir ? createThinkwellHost({ compilerOptions: options, fileFilter, projectDir }) : createThinkwellHost(options);
238893
+ return createThinkwellHost(fileFilter || projectDir ? { compilerOptions: options, fileFilter, projectDir } : options);
238936
238894
  }
238937
238895
  __name(makeHost, "makeHost");
238938
- if (errors.length > 0) {
238939
- const fatalErrors = errors.filter((d) => d.category === import_typescript2.default.DiagnosticCategory.Error);
238940
- if (fatalErrors.length > 0) {
238941
- const host2 = makeHost();
238942
- const program2 = import_typescript2.default.createProgram([], options, host2);
238943
- return { program: program2, configErrors: errors };
238944
- }
238896
+ if (errors.length > 0 && errors.filter((d) => d.category === import_typescript2.default.DiagnosticCategory.Error).length > 0) {
238897
+ const host2 = makeHost();
238898
+ return { program: import_typescript2.default.createProgram([], options, host2), configErrors: errors };
238945
238899
  }
238946
238900
  const host = makeHost();
238947
- const program = import_typescript2.default.createProgram(fileNames, options, host);
238948
- return { program, configErrors: errors };
238901
+ return { program: import_typescript2.default.createProgram(fileNames, options, host), configErrors: errors };
238949
238902
  }
238950
238903
  __name(createThinkwellProgram, "createThinkwellProgram");
238951
238904
 
@@ -238958,11 +238911,11 @@ var whiteBold = /* @__PURE__ */ __name((t) => (0, import_node_util.styleText)(["
238958
238911
  var dim = /* @__PURE__ */ __name((t) => (0, import_node_util.styleText)("dim", t), "dim");
238959
238912
 
238960
238913
  // dist/cli/workspace.js
238961
- var import_node_fs3 = require("node:fs");
238962
- var import_node_path4 = require("node:path");
238914
+ var import_node_fs4 = require("node:fs");
238915
+ var import_node_path5 = require("node:path");
238963
238916
  function parsePnpmWorkspaceYaml(content) {
238964
- const patterns = [];
238965
- const lines = content.split("\n");
238917
+ const patterns = [], lines = content.split(`
238918
+ `);
238966
238919
  let inPackages = false;
238967
238920
  for (const line of lines) {
238968
238921
  const trimmed = line.trim();
@@ -238970,14 +238923,11 @@ function parsePnpmWorkspaceYaml(content) {
238970
238923
  inPackages = true;
238971
238924
  continue;
238972
238925
  }
238973
- if (inPackages && trimmed.length > 0 && !trimmed.startsWith("-") && !line.startsWith(" ") && !line.startsWith(" ")) {
238926
+ if (inPackages && trimmed.length > 0 && !trimmed.startsWith("-") && !line.startsWith(" ") && !line.startsWith(" "))
238974
238927
  break;
238975
- }
238976
238928
  if (inPackages && trimmed.startsWith("-")) {
238977
238929
  const value = trimmed.slice(1).trim().replace(/^["']|["']$/g, "");
238978
- if (value.length > 0) {
238979
- patterns.push(value);
238980
- }
238930
+ value.length > 0 && patterns.push(value);
238981
238931
  }
238982
238932
  }
238983
238933
  return patterns;
@@ -238985,42 +238935,29 @@ function parsePnpmWorkspaceYaml(content) {
238985
238935
  __name(parsePnpmWorkspaceYaml, "parsePnpmWorkspaceYaml");
238986
238936
  function expandWorkspaceGlobs(rootDir, patterns) {
238987
238937
  const dirs = [];
238988
- for (const pattern of patterns) {
238989
- if (pattern.startsWith("!"))
238990
- continue;
238991
- if (pattern.includes("*")) {
238992
- const parts = pattern.split("/");
238993
- const globIndex = parts.findIndex((p) => p.includes("*"));
238994
- const prefix = parts.slice(0, globIndex).join("/");
238995
- const globPart = parts[globIndex];
238996
- const suffix = parts.slice(globIndex + 1).join("/");
238997
- const baseDir = (0, import_node_path4.resolve)(rootDir, prefix);
238998
- if (!(0, import_node_fs3.existsSync)(baseDir))
238999
- continue;
239000
- if (globPart === "*") {
239001
- const entries = (0, import_node_fs3.readdirSync)(baseDir);
239002
- for (const entry of entries) {
239003
- const fullPath = suffix ? (0, import_node_path4.resolve)(baseDir, entry, suffix) : (0, import_node_path4.resolve)(baseDir, entry);
239004
- if ((0, import_node_fs3.existsSync)(fullPath) && isDirectory(fullPath)) {
239005
- dirs.push(fullPath);
238938
+ for (const pattern of patterns)
238939
+ if (!pattern.startsWith("!"))
238940
+ if (pattern.includes("*")) {
238941
+ const parts = pattern.split("/"), globIndex = parts.findIndex((p) => p.includes("*")), prefix = parts.slice(0, globIndex).join("/"), globPart = parts[globIndex], suffix = parts.slice(globIndex + 1).join("/"), baseDir = (0, import_node_path5.resolve)(rootDir, prefix);
238942
+ if (!(0, import_node_fs4.existsSync)(baseDir))
238943
+ continue;
238944
+ if (globPart === "*") {
238945
+ const entries = (0, import_node_fs4.readdirSync)(baseDir);
238946
+ for (const entry of entries) {
238947
+ const fullPath = suffix ? (0, import_node_path5.resolve)(baseDir, entry, suffix) : (0, import_node_path5.resolve)(baseDir, entry);
238948
+ (0, import_node_fs4.existsSync)(fullPath) && isDirectory(fullPath) && dirs.push(fullPath);
239006
238949
  }
239007
- }
239008
- } else if (globPart === "**") {
239009
- collectDirectories(baseDir, suffix, dirs);
239010
- }
239011
- } else {
239012
- const fullPath = (0, import_node_path4.resolve)(rootDir, pattern);
239013
- if ((0, import_node_fs3.existsSync)(fullPath) && isDirectory(fullPath)) {
239014
- dirs.push(fullPath);
238950
+ } else globPart === "**" && collectDirectories(baseDir, suffix, dirs);
238951
+ } else {
238952
+ const fullPath = (0, import_node_path5.resolve)(rootDir, pattern);
238953
+ (0, import_node_fs4.existsSync)(fullPath) && isDirectory(fullPath) && dirs.push(fullPath);
239015
238954
  }
239016
- }
239017
- }
239018
238955
  return dirs;
239019
238956
  }
239020
238957
  __name(expandWorkspaceGlobs, "expandWorkspaceGlobs");
239021
238958
  function isDirectory(path) {
239022
238959
  try {
239023
- return (0, import_node_fs3.statSync)(path).isDirectory();
238960
+ return (0, import_node_fs4.statSync)(path).isDirectory();
239024
238961
  } catch {
239025
238962
  return false;
239026
238963
  }
@@ -239029,90 +238966,66 @@ __name(isDirectory, "isDirectory");
239029
238966
  function collectDirectories(baseDir, suffix, result) {
239030
238967
  let entries;
239031
238968
  try {
239032
- entries = (0, import_node_fs3.readdirSync)(baseDir);
238969
+ entries = (0, import_node_fs4.readdirSync)(baseDir);
239033
238970
  } catch {
239034
238971
  return;
239035
238972
  }
239036
238973
  for (const entry of entries) {
239037
238974
  if (entry.startsWith(".") || entry === "node_modules")
239038
238975
  continue;
239039
- const fullPath = (0, import_node_path4.resolve)(baseDir, entry);
238976
+ const fullPath = (0, import_node_path5.resolve)(baseDir, entry);
239040
238977
  if (!isDirectory(fullPath))
239041
238978
  continue;
239042
- const candidate = suffix ? (0, import_node_path4.resolve)(fullPath, suffix) : fullPath;
239043
- if ((0, import_node_fs3.existsSync)(candidate) && isDirectory(candidate)) {
239044
- result.push(candidate);
239045
- }
239046
- collectDirectories(fullPath, suffix, result);
238979
+ const candidate = suffix ? (0, import_node_path5.resolve)(fullPath, suffix) : fullPath;
238980
+ (0, import_node_fs4.existsSync)(candidate) && isDirectory(candidate) && result.push(candidate), collectDirectories(fullPath, suffix, result);
239047
238981
  }
239048
238982
  }
239049
238983
  __name(collectDirectories, "collectDirectories");
239050
238984
  function readMember(dir) {
239051
- const pkgPath = (0, import_node_path4.join)(dir, "package.json");
239052
- if (!(0, import_node_fs3.existsSync)(pkgPath))
239053
- return void 0;
239054
- try {
239055
- const content = (0, import_node_fs3.readFileSync)(pkgPath, "utf-8");
239056
- const pkg = JSON.parse(content);
239057
- if (!pkg.name || typeof pkg.name !== "string")
239058
- return void 0;
239059
- return {
239060
- name: pkg.name,
239061
- dir,
239062
- hasTsConfig: (0, import_node_fs3.existsSync)((0, import_node_path4.join)(dir, "tsconfig.json"))
239063
- };
239064
- } catch {
239065
- return void 0;
239066
- }
238985
+ const pkgPath = (0, import_node_path5.join)(dir, "package.json");
238986
+ if ((0, import_node_fs4.existsSync)(pkgPath))
238987
+ try {
238988
+ const content = (0, import_node_fs4.readFileSync)(pkgPath, "utf-8"), pkg = JSON.parse(content);
238989
+ return !pkg.name || typeof pkg.name != "string" ? void 0 : {
238990
+ name: pkg.name,
238991
+ dir,
238992
+ hasTsConfig: (0, import_node_fs4.existsSync)((0, import_node_path5.join)(dir, "tsconfig.json"))
238993
+ };
238994
+ } catch {
238995
+ return;
238996
+ }
239067
238997
  }
239068
238998
  __name(readMember, "readMember");
239069
238999
  function detectWorkspace(rootDir) {
239070
- const absRoot = (0, import_node_path4.resolve)(rootDir);
239071
- const pnpmPath = (0, import_node_path4.join)(absRoot, "pnpm-workspace.yaml");
239072
- if ((0, import_node_fs3.existsSync)(pnpmPath)) {
239073
- const content = (0, import_node_fs3.readFileSync)(pnpmPath, "utf-8");
239074
- const patterns = parsePnpmWorkspaceYaml(content);
239000
+ const absRoot = (0, import_node_path5.resolve)(rootDir), pnpmPath = (0, import_node_path5.join)(absRoot, "pnpm-workspace.yaml");
239001
+ if ((0, import_node_fs4.existsSync)(pnpmPath)) {
239002
+ const content = (0, import_node_fs4.readFileSync)(pnpmPath, "utf-8"), patterns = parsePnpmWorkspaceYaml(content);
239075
239003
  if (patterns.length > 0) {
239076
- const dirs = expandWorkspaceGlobs(absRoot, patterns);
239077
- const members = dirs.map(readMember).filter((m) => m !== void 0);
239004
+ const members = expandWorkspaceGlobs(absRoot, patterns).map(readMember).filter((m) => m !== void 0);
239078
239005
  return { rootDir: absRoot, type: "pnpm", members };
239079
239006
  }
239080
239007
  }
239081
- const pkgPath = (0, import_node_path4.join)(absRoot, "package.json");
239082
- if ((0, import_node_fs3.existsSync)(pkgPath)) {
239008
+ const pkgPath = (0, import_node_path5.join)(absRoot, "package.json");
239009
+ if ((0, import_node_fs4.existsSync)(pkgPath))
239083
239010
  try {
239084
- const content = (0, import_node_fs3.readFileSync)(pkgPath, "utf-8");
239085
- const pkg = JSON.parse(content);
239011
+ const content = (0, import_node_fs4.readFileSync)(pkgPath, "utf-8"), pkg = JSON.parse(content);
239086
239012
  if (Array.isArray(pkg.workspaces)) {
239087
- const patterns = pkg.workspaces.filter((p) => typeof p === "string");
239013
+ const patterns = pkg.workspaces.filter((p) => typeof p == "string");
239088
239014
  if (patterns.length > 0) {
239089
- const dirs = expandWorkspaceGlobs(absRoot, patterns);
239090
- const members = dirs.map(readMember).filter((m) => m !== void 0);
239015
+ const members = expandWorkspaceGlobs(absRoot, patterns).map(readMember).filter((m) => m !== void 0);
239091
239016
  return { rootDir: absRoot, type: "npm", members };
239092
239017
  }
239093
239018
  }
239094
239019
  } catch {
239095
239020
  }
239096
- }
239097
- return void 0;
239098
239021
  }
239099
239022
  __name(detectWorkspace, "detectWorkspace");
239100
239023
  function resolvePackageName(name, members) {
239101
239024
  const exact = members.find((m) => m.name === name);
239102
- if (exact) {
239025
+ if (exact)
239103
239026
  return { kind: "found", member: exact };
239104
- }
239105
- const shortMatches = members.filter((m) => {
239106
- const lastSegment = m.name.includes("/") ? m.name.split("/").pop() : m.name;
239107
- return lastSegment === name;
239108
- });
239109
- if (shortMatches.length === 1) {
239110
- return { kind: "found", member: shortMatches[0] };
239111
- }
239112
- if (shortMatches.length > 1) {
239113
- return { kind: "ambiguous", name, matches: shortMatches };
239114
- }
239115
- return {
239027
+ const shortMatches = members.filter((m) => (m.name.includes("/") ? m.name.split("/").pop() : m.name) === name);
239028
+ return shortMatches.length === 1 ? { kind: "found", member: shortMatches[0] } : shortMatches.length > 1 ? { kind: "ambiguous", name, matches: shortMatches } : {
239116
239029
  kind: "not-found",
239117
239030
  name,
239118
239031
  available: members.map((m) => m.name)
@@ -239121,13 +239034,13 @@ function resolvePackageName(name, members) {
239121
239034
  __name(resolvePackageName, "resolvePackageName");
239122
239035
 
239123
239036
  // dist/cli/dependency-check.js
239124
- var import_node_fs5 = require("node:fs");
239125
- var import_node_path6 = require("node:path");
239037
+ var import_node_fs6 = require("node:fs");
239038
+ var import_node_path7 = require("node:path");
239126
239039
  var import_node_child_process = require("node:child_process");
239127
239040
 
239128
239041
  // dist/cli/package-manager.js
239129
- var import_node_fs4 = require("node:fs");
239130
- var import_node_path5 = require("node:path");
239042
+ var import_node_fs5 = require("node:fs");
239043
+ var import_node_path6 = require("node:path");
239131
239044
  var LOCKFILES = [
239132
239045
  { file: "pnpm-lock.yaml", pm: "pnpm" },
239133
239046
  { file: "yarn.lock", pm: "yarn" },
@@ -239135,34 +239048,26 @@ var LOCKFILES = [
239135
239048
  ];
239136
239049
  function detectByLockfile(projectDir) {
239137
239050
  for (const { file, pm } of LOCKFILES) {
239138
- const lockfilePath = (0, import_node_path5.join)(projectDir, file);
239139
- if ((0, import_node_fs4.existsSync)(lockfilePath)) {
239051
+ const lockfilePath = (0, import_node_path6.join)(projectDir, file);
239052
+ if ((0, import_node_fs5.existsSync)(lockfilePath))
239140
239053
  return { pm, lockfile: file };
239141
- }
239142
239054
  }
239143
239055
  return null;
239144
239056
  }
239145
239057
  __name(detectByLockfile, "detectByLockfile");
239146
239058
  function parsePackageManagerField(value) {
239147
- if (typeof value !== "string") {
239059
+ if (typeof value != "string")
239148
239060
  return null;
239149
- }
239150
- const atIndex = value.indexOf("@");
239151
- const name = atIndex > 0 ? value.slice(0, atIndex) : value;
239152
- if (name === "pnpm" || name === "npm" || name === "yarn") {
239153
- return name;
239154
- }
239155
- return null;
239061
+ const atIndex = value.indexOf("@"), name = atIndex > 0 ? value.slice(0, atIndex) : value;
239062
+ return name === "pnpm" || name === "npm" || name === "yarn" ? name : null;
239156
239063
  }
239157
239064
  __name(parsePackageManagerField, "parsePackageManagerField");
239158
239065
  function detectByPackageJson(projectDir) {
239159
- const pkgPath = (0, import_node_path5.join)(projectDir, "package.json");
239160
- if (!(0, import_node_fs4.existsSync)(pkgPath)) {
239066
+ const pkgPath = (0, import_node_path6.join)(projectDir, "package.json");
239067
+ if (!(0, import_node_fs5.existsSync)(pkgPath))
239161
239068
  return null;
239162
- }
239163
239069
  try {
239164
- const content = (0, import_node_fs4.readFileSync)(pkgPath, "utf-8");
239165
- const pkg = JSON.parse(content);
239070
+ const content = (0, import_node_fs5.readFileSync)(pkgPath, "utf-8"), pkg = JSON.parse(content);
239166
239071
  return parsePackageManagerField(pkg.packageManager);
239167
239072
  } catch {
239168
239073
  return null;
@@ -239198,25 +239103,20 @@ function createPackageManagerInfo(name, lockfile) {
239198
239103
  __name(createPackageManagerInfo, "createPackageManagerInfo");
239199
239104
  function detectPackageManager(projectDir) {
239200
239105
  const lockfileResult = detectByLockfile(projectDir);
239201
- if (lockfileResult) {
239106
+ if (lockfileResult)
239202
239107
  return createPackageManagerInfo(lockfileResult.pm, lockfileResult.lockfile);
239203
- }
239204
239108
  const fromField = detectByPackageJson(projectDir);
239205
- if (fromField) {
239206
- return createPackageManagerInfo(fromField, null);
239207
- }
239208
- return createPackageManagerInfo("npm", null);
239109
+ return createPackageManagerInfo(fromField || "npm", null);
239209
239110
  }
239210
239111
  __name(detectPackageManager, "detectPackageManager");
239211
239112
 
239212
239113
  // dist/cli/dependency-check.js
239213
239114
  function readPackageJson(dir) {
239214
- const pkgPath = (0, import_node_path6.join)(dir, "package.json");
239215
- if (!(0, import_node_fs5.existsSync)(pkgPath)) {
239115
+ const pkgPath = (0, import_node_path7.join)(dir, "package.json");
239116
+ if (!(0, import_node_fs6.existsSync)(pkgPath))
239216
239117
  return null;
239217
- }
239218
239118
  try {
239219
- const content = (0, import_node_fs5.readFileSync)(pkgPath, "utf-8");
239119
+ const content = (0, import_node_fs6.readFileSync)(pkgPath, "utf-8");
239220
239120
  return JSON.parse(content);
239221
239121
  } catch {
239222
239122
  return null;
@@ -239230,42 +239130,31 @@ function checkPackageJsonDirect(pkg, packageName) {
239230
239130
  pkg.peerDependencies,
239231
239131
  pkg.optionalDependencies
239232
239132
  ];
239233
- for (const deps of depTypes) {
239234
- if (deps && packageName in deps) {
239133
+ for (const deps of depTypes)
239134
+ if (deps && packageName in deps)
239235
239135
  return {
239236
239136
  found: true,
239237
239137
  version: deps[packageName],
239238
239138
  source: "package.json"
239239
239139
  };
239240
- }
239241
- }
239242
239140
  return null;
239243
239141
  }
239244
239142
  __name(checkPackageJsonDirect, "checkPackageJsonDirect");
239245
239143
  function execCommand(cmd, cwd) {
239246
- return new Promise((resolve4, reject) => {
239247
- const [command, ...args] = cmd;
239248
- const proc = (0, import_node_child_process.spawn)(command, args, {
239144
+ return new Promise((resolve5, reject) => {
239145
+ const [command, ...args] = cmd, proc = (0, import_node_child_process.spawn)(command, args, {
239249
239146
  cwd,
239250
239147
  stdio: ["ignore", "pipe", "pipe"]
239251
239148
  });
239252
- let stdout = "";
239253
- let stderr = "";
239149
+ let stdout = "", stderr = "";
239254
239150
  proc.stdout.on("data", (data) => {
239255
239151
  stdout += data.toString();
239256
- });
239257
- proc.stderr.on("data", (data) => {
239152
+ }), proc.stderr.on("data", (data) => {
239258
239153
  stderr += data.toString();
239259
- });
239260
- proc.on("error", (err) => {
239154
+ }), proc.on("error", (err) => {
239261
239155
  reject(err);
239262
- });
239263
- proc.on("close", (code) => {
239264
- if (code === 0) {
239265
- resolve4({ stdout, stderr });
239266
- } else {
239267
- reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
239268
- }
239156
+ }), proc.on("close", (code) => {
239157
+ code === 0 ? resolve5({ stdout, stderr }) : reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
239269
239158
  });
239270
239159
  });
239271
239160
  }
@@ -239273,15 +239162,11 @@ __name(execCommand, "execCommand");
239273
239162
  function parsePnpmWhyOutput(stdout, packageName) {
239274
239163
  try {
239275
239164
  const result = JSON.parse(stdout);
239276
- if (result && typeof result === "object" && packageName in result) {
239277
- const info = result[packageName];
239278
- return {
239279
- found: true,
239280
- version: info?.version,
239281
- source: "workspace"
239282
- };
239283
- }
239284
- return null;
239165
+ return result && typeof result == "object" && packageName in result ? {
239166
+ found: true,
239167
+ version: result[packageName]?.version,
239168
+ source: "workspace"
239169
+ } : null;
239285
239170
  } catch {
239286
239171
  return null;
239287
239172
  }
@@ -239290,15 +239175,11 @@ __name(parsePnpmWhyOutput, "parsePnpmWhyOutput");
239290
239175
  function parseNpmWhyOutput(stdout, _packageName) {
239291
239176
  try {
239292
239177
  const result = JSON.parse(stdout);
239293
- if (Array.isArray(result) && result.length > 0) {
239294
- const first = result[0];
239295
- return {
239296
- found: true,
239297
- version: first?.version,
239298
- source: "workspace"
239299
- };
239300
- }
239301
- return null;
239178
+ return Array.isArray(result) && result.length > 0 ? {
239179
+ found: true,
239180
+ version: result[0]?.version,
239181
+ source: "workspace"
239182
+ } : null;
239302
239183
  } catch {
239303
239184
  return null;
239304
239185
  }
@@ -239308,7 +239189,8 @@ function parseYarnWhyOutput(stdout, _packageName) {
239308
239189
  if (stdout.trim().length > 0) {
239309
239190
  let version;
239310
239191
  try {
239311
- const lines = stdout.trim().split("\n");
239192
+ const lines = stdout.trim().split(`
239193
+ `);
239312
239194
  for (const line of lines) {
239313
239195
  const obj = JSON.parse(line);
239314
239196
  if (obj.type === "info" && obj.data) {
@@ -239348,31 +239230,21 @@ async function checkViaPackageManager(pm, packageName, cwd) {
239348
239230
  }
239349
239231
  __name(checkViaPackageManager, "checkViaPackageManager");
239350
239232
  async function checkDependencies(projectDir) {
239351
- const pm = detectPackageManager(projectDir);
239352
- const pkg = readPackageJson(projectDir);
239353
- let thinkwellStatus = { found: false };
239354
- let typescriptStatus = { found: false };
239233
+ const pm = detectPackageManager(projectDir), pkg = readPackageJson(projectDir);
239234
+ let thinkwellStatus = { found: false }, typescriptStatus = { found: false };
239355
239235
  if (pkg) {
239356
239236
  const thinkwellDirect = checkPackageJsonDirect(pkg, "thinkwell");
239357
- if (thinkwellDirect) {
239358
- thinkwellStatus = thinkwellDirect;
239359
- }
239237
+ thinkwellDirect && (thinkwellStatus = thinkwellDirect);
239360
239238
  const typescriptDirect = checkPackageJsonDirect(pkg, "typescript");
239361
- if (typescriptDirect) {
239362
- typescriptStatus = typescriptDirect;
239363
- }
239239
+ typescriptDirect && (typescriptStatus = typescriptDirect);
239364
239240
  }
239365
239241
  if (!thinkwellStatus.found) {
239366
239242
  const result = await checkViaPackageManager(pm, "thinkwell", projectDir);
239367
- if (result) {
239368
- thinkwellStatus = result;
239369
- }
239243
+ result && (thinkwellStatus = result);
239370
239244
  }
239371
239245
  if (!typescriptStatus.found) {
239372
239246
  const result = await checkViaPackageManager(pm, "typescript", projectDir);
239373
- if (result) {
239374
- typescriptStatus = result;
239375
- }
239247
+ result && (typescriptStatus = result);
239376
239248
  }
239377
239249
  return {
239378
239250
  thinkwell: thinkwellStatus,
@@ -239382,40 +239254,18 @@ async function checkDependencies(projectDir) {
239382
239254
  }
239383
239255
  __name(checkDependencies, "checkDependencies");
239384
239256
  function hasPackageJson(projectDir) {
239385
- return (0, import_node_fs5.existsSync)((0, import_node_path6.join)(projectDir, "package.json"));
239257
+ return (0, import_node_fs6.existsSync)((0, import_node_path7.join)(projectDir, "package.json"));
239386
239258
  }
239387
239259
  __name(hasPackageJson, "hasPackageJson");
239388
239260
 
239389
239261
  // dist/cli/dependency-errors.js
239390
239262
  function formatMissingDependencyError(result) {
239391
- const { thinkwell, typescript, packageManager } = result;
239392
- const pm = packageManager;
239393
- const missing = [];
239394
- if (!thinkwell.found)
239395
- missing.push("thinkwell");
239396
- if (!typescript.found)
239397
- missing.push("typescript");
239398
- if (missing.length === 0) {
239263
+ const { thinkwell, typescript, packageManager } = result, pm = packageManager, missing = [];
239264
+ if (thinkwell.found || missing.push("thinkwell"), typescript.found || missing.push("typescript"), missing.length === 0)
239399
239265
  return "";
239400
- }
239401
239266
  const lines = [];
239402
- if (missing.length === 1) {
239403
- lines.push(`Error: This project has a package.json but no dependency on '${missing[0]}'.`);
239404
- } else {
239405
- lines.push(`Error: This project has a package.json but is missing required dependencies.`);
239406
- }
239407
- lines.push("");
239408
- lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies.");
239409
- lines.push("This ensures you get the versions you expect, not versions bundled with the CLI.");
239410
- lines.push("");
239411
- lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:");
239412
- if (!thinkwell.found) {
239413
- lines.push(` ${pm.addCommand("thinkwell")}`);
239414
- }
239415
- if (!typescript.found) {
239416
- lines.push(` ${pm.addCommand("typescript", true)}`);
239417
- }
239418
- return lines.join("\n");
239267
+ return missing.length === 1 ? lines.push(`Error: This project has a package.json but no dependency on '${missing[0]}'.`) : lines.push("Error: This project has a package.json but is missing required dependencies."), lines.push(""), lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies."), lines.push("This ensures you get the versions you expect, not versions bundled with the CLI."), lines.push(""), lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:"), thinkwell.found || lines.push(` ${pm.addCommand("thinkwell")}`), typescript.found || lines.push(` ${pm.addCommand("typescript", true)}`), lines.join(`
239268
+ `);
239419
239269
  }
239420
239270
  __name(formatMissingDependencyError, "formatMissingDependencyError");
239421
239271
  function hasMissingDependencies(result) {
@@ -239440,73 +239290,49 @@ function formatDiagnostics(diagnostics, pretty) {
239440
239290
  }
239441
239291
  __name(formatDiagnostics, "formatDiagnostics");
239442
239292
  function checkPackage(dir, pretty, projectDir) {
239443
- const configPath = (0, import_node_path7.resolve)(dir, "tsconfig.json");
239444
- const { program, configErrors } = projectDir ? createThinkwellProgram({ configPath, projectDir }) : createThinkwellProgram(configPath);
239445
- if (configErrors.length > 0) {
239446
- process.stderr.write(formatDiagnostics(configErrors, pretty));
239447
- const hasFatal = configErrors.some((d) => d.category === import_typescript3.default.DiagnosticCategory.Error);
239448
- if (hasFatal) {
239449
- return configErrors.filter((d) => d.category === import_typescript3.default.DiagnosticCategory.Error).length;
239450
- }
239451
- }
239452
- const diagnostics = import_typescript3.default.getPreEmitDiagnostics(program);
239453
- const errors = diagnostics.filter((d) => d.category === import_typescript3.default.DiagnosticCategory.Error);
239454
- if (diagnostics.length > 0) {
239455
- process.stderr.write("\n");
239456
- process.stderr.write(formatDiagnostics(diagnostics, pretty));
239457
- }
239458
- return errors.length;
239293
+ const configPath = (0, import_node_path8.resolve)(dir, "tsconfig.json"), { program, configErrors } = projectDir ? createThinkwellProgram({ configPath, projectDir }) : createThinkwellProgram(configPath);
239294
+ if (configErrors.length > 0 && (process.stderr.write(formatDiagnostics(configErrors, pretty)), configErrors.some((d) => d.category === import_typescript3.default.DiagnosticCategory.Error)))
239295
+ return configErrors.filter((d) => d.category === import_typescript3.default.DiagnosticCategory.Error).length;
239296
+ const diagnostics = import_typescript3.default.getPreEmitDiagnostics(program), errors = diagnostics.filter((d) => d.category === import_typescript3.default.DiagnosticCategory.Error);
239297
+ return diagnostics.length > 0 && (process.stderr.write(`
239298
+ `), process.stderr.write(formatDiagnostics(diagnostics, pretty))), errors.length;
239459
239299
  }
239460
239300
  __name(checkPackage, "checkPackage");
239461
239301
  async function runCheck(options) {
239462
- const cwd = process.cwd();
239463
- const pretty = options.pretty ?? process.stdout.isTTY ?? false;
239464
- const workspace = detectWorkspace(cwd);
239465
- if (options.packages && options.packages.length > 0 && !workspace) {
239466
- process.stderr.write('Error: --package can only be used in a workspace.\nNo pnpm-workspace.yaml or package.json "workspaces" found in current directory.\n');
239467
- process.exit(2);
239468
- }
239469
- if (!workspace) {
239302
+ const cwd = process.cwd(), pretty = options.pretty ?? process.stdout.isTTY ?? false, workspace = detectWorkspace(cwd);
239303
+ if (options.packages && options.packages.length > 0 && !workspace && (process.stderr.write(`Error: --package can only be used in a workspace.
239304
+ No pnpm-workspace.yaml or package.json "workspaces" found in current directory.
239305
+ `), process.exit(2)), !workspace) {
239470
239306
  if (hasPackageJson(cwd)) {
239471
239307
  const depCheck = await checkDependencies(cwd);
239472
- if (hasMissingDependencies(depCheck)) {
239473
- process.stderr.write(formatMissingDependencyError(depCheck) + "\n");
239474
- process.exit(2);
239475
- }
239476
- }
239477
- const configPath = (0, import_node_path7.resolve)(cwd, "tsconfig.json");
239478
- if (!(0, import_node_fs6.existsSync)(configPath)) {
239479
- process.stderr.write("Error: Cannot find tsconfig.json\n");
239480
- process.stderr.write("\n");
239481
- process.stderr.write(" Run this command from a directory with a tsconfig.json.\n");
239482
- process.exit(2);
239308
+ hasMissingDependencies(depCheck) && (process.stderr.write(formatMissingDependencyError(depCheck) + `
239309
+ `), process.exit(2));
239483
239310
  }
239311
+ const configPath = (0, import_node_path8.resolve)(cwd, "tsconfig.json");
239312
+ (0, import_node_fs7.existsSync)(configPath) || (process.stderr.write(`Error: Cannot find tsconfig.json
239313
+ `), process.stderr.write(`
239314
+ `), process.stderr.write(` Run this command from a directory with a tsconfig.json.
239315
+ `), process.exit(2));
239484
239316
  let pkgName = cwd.split("/").pop() ?? "project";
239485
239317
  try {
239486
- const pkgPath = (0, import_node_path7.join)(cwd, "package.json");
239487
- if ((0, import_node_fs6.existsSync)(pkgPath)) {
239318
+ const pkgPath = (0, import_node_path8.join)(cwd, "package.json");
239319
+ if ((0, import_node_fs7.existsSync)(pkgPath)) {
239488
239320
  const pkg = JSON.parse((await import("node:fs")).readFileSync(pkgPath, "utf-8"));
239489
- if (pkg.name)
239490
- pkgName = pkg.name;
239321
+ pkg.name && (pkgName = pkg.name);
239491
239322
  }
239492
239323
  } catch {
239493
239324
  }
239494
239325
  process.stderr.write(` Checking ${pkgName}...
239495
239326
  `);
239496
239327
  const projectDir = hasPackageJson(cwd) ? cwd : void 0;
239497
- const errorCount = checkPackage(cwd, pretty, projectDir);
239498
- if (errorCount > 0) {
239499
- process.exit(1);
239500
- }
239501
- process.stderr.write(" No type errors found.\n");
239328
+ checkPackage(cwd, pretty, projectDir) > 0 && process.exit(1), process.stderr.write(` No type errors found.
239329
+ `);
239502
239330
  return;
239503
239331
  }
239504
239332
  if (hasPackageJson(workspace.rootDir)) {
239505
239333
  const depCheck = await checkDependencies(workspace.rootDir);
239506
- if (hasMissingDependencies(depCheck)) {
239507
- process.stderr.write(formatMissingDependencyError(depCheck) + "\n");
239508
- process.exit(2);
239509
- }
239334
+ hasMissingDependencies(depCheck) && (process.stderr.write(formatMissingDependencyError(depCheck) + `
239335
+ `), process.exit(2));
239510
239336
  }
239511
239337
  let packagesToCheck;
239512
239338
  if (options.packages && options.packages.length > 0) {
@@ -239515,45 +239341,37 @@ async function runCheck(options) {
239515
239341
  const result = resolvePackageName(name, workspace.members);
239516
239342
  switch (result.kind) {
239517
239343
  case "found":
239518
- if (!result.member.hasTsConfig) {
239519
- process.stderr.write(`Error: Package "${result.member.name}" has no tsconfig.json.
239520
- `);
239521
- process.exit(2);
239522
- }
239523
- packagesToCheck.push(result.member);
239344
+ result.member.hasTsConfig || (process.stderr.write(`Error: Package "${result.member.name}" has no tsconfig.json.
239345
+ `), process.exit(2)), packagesToCheck.push(result.member);
239524
239346
  break;
239525
239347
  case "ambiguous":
239526
239348
  process.stderr.write(`Error: Ambiguous package name "${result.name}". Matches:
239527
239349
  `);
239528
- for (const m of result.matches) {
239350
+ for (const m of result.matches)
239529
239351
  process.stderr.write(` - ${m.name}
239530
239352
  `);
239531
- }
239532
- process.stderr.write("\nUse the full package name to disambiguate.\n");
239533
- process.exit(2);
239353
+ process.stderr.write(`
239354
+ Use the full package name to disambiguate.
239355
+ `), process.exit(2);
239534
239356
  break;
239535
239357
  // unreachable but satisfies control flow
239536
239358
  case "not-found":
239537
239359
  process.stderr.write(`Error: Package "${result.name}" not found in workspace.
239360
+ `), process.stderr.write(`
239361
+ Available packages:
239538
239362
  `);
239539
- process.stderr.write("\nAvailable packages:\n");
239540
- for (const available of result.available) {
239363
+ for (const available of result.available)
239541
239364
  process.stderr.write(` - ${available}
239542
239365
  `);
239543
- }
239544
239366
  process.exit(2);
239545
239367
  break;
239546
239368
  }
239547
239369
  }
239548
- } else {
239370
+ } else
239549
239371
  packagesToCheck = workspace.members.filter((m) => m.hasTsConfig);
239550
- }
239551
- if (packagesToCheck.length === 0) {
239552
- process.stderr.write("No TypeScript packages found in workspace.\n");
239553
- process.exit(2);
239554
- }
239555
- let totalErrors = 0;
239556
- let packagesWithErrors = 0;
239372
+ packagesToCheck.length === 0 && (process.stderr.write(`No TypeScript packages found in workspace.
239373
+ `), process.exit(2));
239374
+ let totalErrors = 0, packagesWithErrors = 0;
239557
239375
  const total = packagesToCheck.length;
239558
239376
  for (const member of packagesToCheck) {
239559
239377
  process.stderr.write(` Checking ${member.name}...`);
@@ -239561,53 +239379,37 @@ async function runCheck(options) {
239561
239379
  process.chdir(member.dir);
239562
239380
  try {
239563
239381
  const errorCount = checkPackage(member.dir, pretty, member.dir);
239564
- if (errorCount > 0) {
239565
- totalErrors += errorCount;
239566
- packagesWithErrors++;
239567
- } else {
239568
- process.stderr.write(" ok\n");
239569
- }
239382
+ errorCount > 0 ? (totalErrors += errorCount, packagesWithErrors++) : process.stderr.write(` ok
239383
+ `);
239570
239384
  } finally {
239571
239385
  process.chdir(originalCwd);
239572
239386
  }
239573
239387
  }
239574
- process.stderr.write("\n");
239575
- if (packagesWithErrors > 0) {
239576
- process.stderr.write(` ${packagesWithErrors} of ${total} package${total === 1 ? "" : "s"} had errors.
239577
- `);
239578
- process.exit(1);
239579
- }
239580
- process.stderr.write(` All ${total} package${total === 1 ? "" : "s"} passed.
239388
+ process.stderr.write(`
239389
+ `), packagesWithErrors > 0 && (process.stderr.write(` ${packagesWithErrors} of ${total} package${total === 1 ? "" : "s"} had errors.
239390
+ `), process.exit(1)), process.stderr.write(` All ${total} package${total === 1 ? "" : "s"} passed.
239581
239391
  `);
239582
239392
  }
239583
239393
  __name(runCheck, "runCheck");
239584
239394
  function parseCheckArgs(args) {
239585
239395
  const options = {};
239586
239396
  let i = 0;
239587
- while (i < args.length) {
239397
+ for (; i < args.length; ) {
239588
239398
  const arg = args[i];
239589
239399
  if (arg === "-p" || arg === "--package") {
239590
- i++;
239591
- if (i >= args.length) {
239400
+ if (i++, i >= args.length)
239592
239401
  throw new Error("Missing value for --package");
239593
- }
239594
- if (!options.packages)
239595
- options.packages = [];
239596
- options.packages.push(args[i]);
239597
- } else if (arg === "--pretty") {
239402
+ options.packages || (options.packages = []), options.packages.push(args[i]);
239403
+ } else if (arg === "--pretty")
239598
239404
  options.pretty = true;
239599
- } else if (arg === "--no-pretty") {
239405
+ else if (arg === "--no-pretty")
239600
239406
  options.pretty = false;
239601
- } else if (arg.startsWith("-")) {
239602
- throw new Error(`Unknown option: ${arg}`);
239603
- } else {
239604
- throw new Error(`Unexpected argument: ${arg}
239407
+ else throw arg.startsWith("-") ? new Error(`Unknown option: ${arg}`) : new Error(`Unexpected argument: ${arg}
239605
239408
 
239606
239409
  "thinkwell check" type-checks the project without producing output.
239607
239410
  It does not take positional arguments.
239608
239411
 
239609
239412
  To check a specific workspace package, use: thinkwell check -p ${arg}`);
239610
- }
239611
239413
  i++;
239612
239414
  }
239613
239415
  return options;
@@ -239646,7 +239448,8 @@ ${greenBold("Examples:")}
239646
239448
  ${cyanBold("thinkwell check")} ${cyan("-p acp")} Check a specific workspace package
239647
239449
  ${cyanBold("thinkwell check")} ${cyan("-p acp -p protocol")} Check multiple packages
239648
239450
  ${cyanBold("thinkwell check")} ${cyan("--no-pretty")} Disable colorized output ${dim("(for CI)")}
239649
- `.trim() + "\n");
239451
+ `.trim() + `
239452
+ `);
239650
239453
  }
239651
239454
  __name(showCheckHelp, "showCheckHelp");
239652
239455
  // Annotate the CommonJS export names for ESM import in node: