@tscircuit/cli 0.1.981 → 0.1.983

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/main.js CHANGED
@@ -74395,7 +74395,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
74395
74395
  import { execSync as execSync2 } from "node:child_process";
74396
74396
  var import_semver2 = __toESM2(require_semver2(), 1);
74397
74397
  // package.json
74398
- var version = "0.1.980";
74398
+ var version = "0.1.982";
74399
74399
  var package_default = {
74400
74400
  name: "@tscircuit/cli",
74401
74401
  main: "dist/cli/main.js",
@@ -174364,27 +174364,34 @@ function ora(options) {
174364
174364
 
174365
174365
  // cli/import/register.ts
174366
174366
  var registerImport = (program3) => {
174367
- program3.command("import").description("Search JLCPCB or the tscircuit registry and import a component").argument("<query>", "Chip name, part number, or package name").action(async (query) => {
174367
+ program3.command("import").description("Search JLCPCB or the tscircuit registry and import a component").argument("<query>", "Chip name, part number, or package name").option("--jlcpcb", "Search JLCPCB components").option("--lcsc", "Alias for --jlcpcb").option("--tscircuit", "Search tscircuit registry packages").action(async (query, opts) => {
174368
+ const hasFilters = opts.jlcpcb || opts.lcsc || opts.tscircuit;
174369
+ const searchJlc = opts.jlcpcb || opts.lcsc || !hasFilters;
174370
+ const searchTscircuit = opts.tscircuit || !hasFilters;
174368
174371
  const ky3 = getRegistryApiKy();
174369
174372
  const spinner = ora("Searching...").start();
174370
174373
  let registryResults = [];
174371
174374
  let jlcResults = [];
174372
- try {
174373
- spinner.text = "Searching tscircuit registry...";
174374
- registryResults = (await ky3.post("packages/search", { json: { query } }).json()).packages;
174375
- } catch (error) {
174376
- spinner.fail("Failed to search registry");
174377
- console.error(kleur_default.red("Error:"), error instanceof Error ? error.message : error);
174378
- spinner.start();
174375
+ if (searchTscircuit) {
174376
+ try {
174377
+ spinner.text = "Searching tscircuit registry...";
174378
+ registryResults = (await ky3.post("packages/search", { json: { query } }).json()).packages;
174379
+ } catch (error) {
174380
+ spinner.fail("Failed to search registry");
174381
+ console.error(kleur_default.red("Error:"), error instanceof Error ? error.message : error);
174382
+ spinner.start();
174383
+ }
174379
174384
  }
174380
- try {
174381
- spinner.text = "Searching JLCPCB parts...";
174382
- const searchUrl = "https://jlcsearch.tscircuit.com/api/search?limit=10&q=" + encodeURIComponent(query);
174383
- const resp = await fetch(searchUrl).then((r4) => r4.json());
174384
- jlcResults = resp.components;
174385
- } catch (error) {
174386
- spinner.fail("Failed to search JLCPCB");
174387
- console.error(kleur_default.red("Error:"), error instanceof Error ? error.message : error);
174385
+ if (searchJlc) {
174386
+ try {
174387
+ spinner.text = "Searching JLCPCB parts...";
174388
+ const searchUrl = `https://jlcsearch.tscircuit.com/api/search?limit=10&q=${encodeURIComponent(query)}`;
174389
+ const resp = await fetch(searchUrl).then((r4) => r4.json());
174390
+ jlcResults = resp.components;
174391
+ } catch (error) {
174392
+ spinner.fail("Failed to search JLCPCB");
174393
+ console.error(kleur_default.red("Error:"), error instanceof Error ? error.message : error);
174394
+ }
174388
174395
  }
174389
174396
  spinner.stop();
174390
174397
  if (!registryResults.length && !jlcResults?.length) {
@@ -174406,12 +174413,13 @@ var registerImport = (program3) => {
174406
174413
  selected: !choices.length && idx === 0
174407
174414
  });
174408
174415
  });
174409
- const { choice } = await prompts({
174416
+ const shouldAutoSelectSingleJlcResult = searchJlc && !searchTscircuit && choices.length === 1;
174417
+ const choice = shouldAutoSelectSingleJlcResult ? choices[0].value : (await prompts({
174410
174418
  type: "select",
174411
174419
  name: "choice",
174412
174420
  message: "Select a part to import",
174413
174421
  choices
174414
- });
174422
+ })).choice;
174415
174423
  if (!choice) {
174416
174424
  console.log("Aborted.");
174417
174425
  return process.exit(0);
@@ -175174,6 +175182,17 @@ var buildPreviewImages = async ({
175174
175182
  });
175175
175183
  };
175176
175184
 
175185
+ // cli/build/utils/exit-build.ts
175186
+ var exitBuild = (code, reason) => {
175187
+ const message = `Build exiting with code ${code}: ${reason}`;
175188
+ if (code === 0) {
175189
+ console.log(kleur_default.dim(message));
175190
+ } else {
175191
+ console.error(kleur_default.yellow(message));
175192
+ }
175193
+ process.exit(code);
175194
+ };
175195
+
175177
175196
  // cli/build/generate-kicad-project.ts
175178
175197
  import fs49 from "node:fs";
175179
175198
  import path50 from "node:path";
@@ -175729,10 +175748,14 @@ class WorkerPool {
175729
175748
  initialized = false;
175730
175749
  stopped = false;
175731
175750
  stopReason = null;
175751
+ stopOnFatal = false;
175752
+ cancellationError = null;
175732
175753
  constructor(options) {
175733
175754
  this.concurrency = options.concurrency;
175734
175755
  this.onLog = options.onLog;
175735
175756
  this.workerEntrypointPath = getWorkerEntrypointPath();
175757
+ this.stopOnFatal = options.stopOnFatal ?? false;
175758
+ this.cancellationError = options.cancellationError ?? null;
175736
175759
  }
175737
175760
  async initWorkers() {
175738
175761
  if (this.initialized)
@@ -175761,6 +175784,9 @@ class WorkerPool {
175761
175784
  const completedMsg = message;
175762
175785
  const job = threadWorker.currentJob;
175763
175786
  if (job) {
175787
+ if (this.stopOnFatal && completedMsg.isFatalError && this.cancellationError) {
175788
+ this.stop(this.cancellationError);
175789
+ }
175764
175790
  job.resolve({
175765
175791
  filePath: completedMsg.file_path,
175766
175792
  outputPath: completedMsg.output_path,
@@ -175867,13 +175893,15 @@ class WorkerPool {
175867
175893
  }
175868
175894
  }
175869
175895
  async function buildFilesWithWorkerPool(options) {
175896
+ const cancellationError = new Error("Build cancelled due fatal error");
175870
175897
  const pool = new WorkerPool({
175871
175898
  concurrency: options.concurrency,
175872
- onLog: options.onLog
175899
+ onLog: options.onLog,
175900
+ stopOnFatal: options.stopOnFatal,
175901
+ cancellationError
175873
175902
  });
175874
175903
  const results = [];
175875
175904
  const promises = [];
175876
- const cancellationError = new Error("Build cancelled due fatal error");
175877
175905
  for (const file of options.files) {
175878
175906
  const promise = pool.queueJob({
175879
175907
  filePath: file.filePath,
@@ -175885,9 +175913,6 @@ async function buildFilesWithWorkerPool(options) {
175885
175913
  if (options.onJobComplete) {
175886
175914
  await options.onJobComplete(result);
175887
175915
  }
175888
- if (options.stopOnFatal && result.isFatalError) {
175889
- await pool.stop(cancellationError);
175890
- }
175891
175916
  return result;
175892
175917
  });
175893
175918
  promises.push(promise);
@@ -176088,9 +176113,6 @@ var registerBuild = (program3) => {
176088
176113
  ok: result.ok,
176089
176114
  isFatalError: result.isFatalError
176090
176115
  });
176091
- if (result.isFatalError) {
176092
- process.exit(1);
176093
- }
176094
176116
  }
176095
176117
  });
176096
176118
  };
@@ -176099,9 +176121,6 @@ var registerBuild = (program3) => {
176099
176121
  } else {
176100
176122
  await buildSequentially();
176101
176123
  }
176102
- if (hasFatalErrors || hasErrors && !resolvedOptions?.ignoreErrors) {
176103
- process.exit(1);
176104
- }
176105
176124
  const shouldGeneratePreviewImages = resolvedOptions?.previewImages || resolvedOptions?.allImages;
176106
176125
  if (shouldGeneratePreviewImages) {
176107
176126
  console.log(resolvedOptions?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
@@ -176146,7 +176165,7 @@ var registerBuild = (program3) => {
176146
176165
  console.log("Skipping transpilation because includeBoardFiles is configured and no library entrypoint was found.");
176147
176166
  } else {
176148
176167
  console.error("No entry file found for transpilation. Make sure you have a lib/index.ts or set mainEntrypoint in tscircuit.config.json");
176149
- process.exit(1);
176168
+ exitBuild(1, "transpile entry file not found");
176150
176169
  }
176151
176170
  } else {
176152
176171
  const transpileSuccess = await transpileFile({
@@ -176156,7 +176175,7 @@ var registerBuild = (program3) => {
176156
176175
  });
176157
176176
  if (!transpileSuccess) {
176158
176177
  console.error("Transpilation failed");
176159
- process.exit(1);
176178
+ exitBuild(1, "transpile command failed");
176160
176179
  }
176161
176180
  }
176162
176181
  }
@@ -176191,7 +176210,7 @@ var registerBuild = (program3) => {
176191
176210
  if (!entryFile) {
176192
176211
  console.error("No entry file found for KiCad library generation. Make sure you have a lib/index.ts or set mainEntrypoint/kicadLibraryEntrypointPath in tscircuit.config.json");
176193
176212
  if (!resolvedOptions?.ignoreErrors) {
176194
- process.exit(1);
176213
+ exitBuild(1, "kicad-library entry file not found");
176195
176214
  }
176196
176215
  } else {
176197
176216
  const libraryName = resolvedOptions?.kicadLibraryName || resolveKicadLibraryName({ projectDir });
@@ -176206,7 +176225,7 @@ var registerBuild = (program3) => {
176206
176225
  } catch (err) {
176207
176226
  console.error(`Error generating KiCad library: ${err instanceof Error ? err.message : err}`);
176208
176227
  if (!resolvedOptions?.ignoreErrors) {
176209
- process.exit(1);
176228
+ exitBuild(1, "kicad-library generation failed");
176210
176229
  }
176211
176230
  }
176212
176231
  }
@@ -176225,7 +176244,7 @@ var registerBuild = (program3) => {
176225
176244
  if (!entryFile) {
176226
176245
  console.error("No entry file found for KiCad PCM generation. Make sure you have a lib/index.ts or set mainEntrypoint/kicadLibraryEntrypointPath in tscircuit.config.json");
176227
176246
  if (!resolvedOptions?.ignoreErrors) {
176228
- process.exit(1);
176247
+ exitBuild(1, "kicad-pcm entry file not found");
176229
176248
  }
176230
176249
  } else {
176231
176250
  try {
@@ -176238,11 +176257,12 @@ var registerBuild = (program3) => {
176238
176257
  } catch (err) {
176239
176258
  console.error(`Error generating KiCad PCM assets: ${err instanceof Error ? err.message : err}`);
176240
176259
  if (!resolvedOptions?.ignoreErrors) {
176241
- process.exit(1);
176260
+ exitBuild(1, "kicad-pcm generation failed");
176242
176261
  }
176243
176262
  }
176244
176263
  }
176245
176264
  }
176265
+ const shouldExitNonZero = hasFatalErrors || hasErrors && !resolvedOptions?.ignoreErrors;
176246
176266
  const successCount = builtFiles.filter((f2) => f2.ok).length;
176247
176267
  const failCount = builtFiles.length - successCount;
176248
176268
  const enabledOpts = [
@@ -176278,11 +176298,14 @@ var registerBuild = (program3) => {
176278
176298
  console.log(hasErrors ? kleur_default.yellow(`
176279
176299
  ⚠ Build completed with errors`) : kleur_default.green(`
176280
176300
  ✓ Done`));
176281
- process.exit(0);
176301
+ if (shouldExitNonZero) {
176302
+ exitBuild(1, hasFatalErrors ? "fatal circuit build errors occurred" : "build errors occurred and --ignore-errors was not enabled");
176303
+ }
176304
+ exitBuild(0, "build finished successfully");
176282
176305
  } catch (error) {
176283
176306
  const message = error instanceof Error ? error.message : String(error);
176284
176307
  console.error(message);
176285
- process.exit(1);
176308
+ exitBuild(1, "unexpected exception");
176286
176309
  }
176287
176310
  });
176288
176311
  };
package/dist/lib/index.js CHANGED
@@ -60414,7 +60414,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
60414
60414
  }));
60415
60415
  };
60416
60416
  // package.json
60417
- var version = "0.1.980";
60417
+ var version = "0.1.982";
60418
60418
  var package_default = {
60419
60419
  name: "@tscircuit/cli",
60420
60420
  main: "dist/cli/main.js",
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  ".": "./dist/cli/main.js",
6
6
  "./lib": "./dist/lib/index.js"
7
7
  },
8
- "version": "0.1.981",
8
+ "version": "0.1.983",
9
9
  "devDependencies": {
10
10
  "@babel/standalone": "^7.26.9",
11
11
  "@biomejs/biome": "^1.9.4",