@tscircuit/cli 0.1.101 → 0.1.103

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 (3) hide show
  1. package/README.md +2 -0
  2. package/dist/main.js +133 -39
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -50,6 +50,8 @@ Commands:
50
50
  config Manage tscircuit CLI configuration
51
51
  export [options] <file> Export tscircuit code to various formats
52
52
  add <component> Add a tscircuit component package to your project
53
+ remove <component> Remove a tscircuit component package from your
54
+ project
53
55
  upgrade Upgrade CLI to the latest version
54
56
  search <query> Search for snippets in the tscircuit registry
55
57
  help [command] display help for command
package/dist/main.js CHANGED
@@ -432739,9 +432739,14 @@ var {
432739
432739
  import * as fs4 from "node:fs";
432740
432740
  import * as path5 from "node:path";
432741
432741
 
432742
- // lib/shared/detect-pkg-manager.ts
432742
+ // lib/shared/setup-tsci-packages.ts
432743
+ import fs2 from "node:fs";
432744
+ import path from "node:path";
432745
+
432746
+ // lib/shared/get-package-manager.ts
432743
432747
  import fs from "fs";
432744
- var detectPackageManager = () => {
432748
+ import { execSync } from "node:child_process";
432749
+ function detectPackageManager() {
432745
432750
  const userAgent = process.env.npm_config_user_agent || "";
432746
432751
  if (userAgent.startsWith("yarn"))
432747
432752
  return "yarn";
@@ -432768,27 +432773,89 @@ var detectPackageManager = () => {
432768
432773
  return "bun";
432769
432774
  } catch (error) {}
432770
432775
  return "npm";
432771
- };
432776
+ }
432777
+ function getPackageManager() {
432778
+ const pm = detectPackageManager();
432779
+ return {
432780
+ name: pm,
432781
+ uninstall: ({ name, cwd }) => {
432782
+ let uninstallCommand;
432783
+ if (pm === "yarn") {
432784
+ uninstallCommand = `yarn remove ${name}`;
432785
+ } else if (pm === "pnpm") {
432786
+ uninstallCommand = `pnpm remove ${name}`;
432787
+ } else if (pm === "bun") {
432788
+ uninstallCommand = `bun remove ${name}`;
432789
+ } else {
432790
+ uninstallCommand = `npm uninstall ${name}`;
432791
+ }
432792
+ execSync(uninstallCommand, { stdio: "pipe", cwd });
432793
+ },
432794
+ install: ({ name, cwd }) => {
432795
+ let installCommand;
432796
+ if (pm === "yarn") {
432797
+ installCommand = `yarn add ${name}`;
432798
+ } else if (pm === "pnpm") {
432799
+ installCommand = `pnpm add ${name}`;
432800
+ } else if (pm === "bun") {
432801
+ if (name.startsWith("@tsci/")) {
432802
+ installCommand = `bun add ${name} --registry https://npm.tscircuit.com`;
432803
+ } else {
432804
+ installCommand = `bun add ${name}`;
432805
+ }
432806
+ } else {
432807
+ installCommand = `npm install ${name}`;
432808
+ }
432809
+ execSync(installCommand, { stdio: "pipe", cwd });
432810
+ },
432811
+ init: ({ cwd }) => {
432812
+ const initCommand = getInitCommand();
432813
+ execSync(initCommand, { stdio: "inherit", cwd });
432814
+ },
432815
+ installDeps: ({ deps, cwd, dev }) => {
432816
+ const installCommand = getInstallDepsCommand(deps, dev);
432817
+ execSync(installCommand, { stdio: "inherit", cwd });
432818
+ },
432819
+ getInitCommand,
432820
+ getInstallDepsCommand
432821
+ };
432822
+ function getInitCommand() {
432823
+ if (pm === "yarn")
432824
+ return "yarn init -y";
432825
+ if (pm === "pnpm")
432826
+ return "pnpm init";
432827
+ if (pm === "bun")
432828
+ return "bun init -y";
432829
+ return "npm init -y";
432830
+ }
432831
+ function getInstallDepsCommand(deps, dev) {
432832
+ const depList = deps.join(" ");
432833
+ if (pm === "bun")
432834
+ return dev ? `bun add -d ${depList}` : `bun add ${depList}`;
432835
+ if (pm === "yarn")
432836
+ return dev ? `yarn add -D ${depList}` : `yarn add ${depList}`;
432837
+ if (pm === "pnpm")
432838
+ return dev ? `pnpm add -D ${depList}` : `pnpm add ${depList}`;
432839
+ return dev ? `npm install -D ${depList}` : `npm install ${depList}`;
432840
+ }
432841
+ }
432772
432842
 
432773
432843
  // lib/shared/setup-tsci-packages.ts
432774
- import fs2 from "node:fs";
432775
- import path from "node:path";
432776
- import { execSync } from "node:child_process";
432777
- function setupTsciProject(directory = process.cwd(), dependencies = ["@types/react", "@tscircuit/core"]) {
432844
+ async function setupTsciProject(directory = process.cwd(), dependencies = ["@types/react", "@tscircuit/core"]) {
432778
432845
  const projectPath = path.resolve(directory);
432779
432846
  if (!fs2.existsSync(projectPath)) {
432780
432847
  fs2.mkdirSync(projectPath, { recursive: true });
432781
432848
  }
432782
- const packageManager = detectPackageManager();
432849
+ const packageManager = getPackageManager();
432783
432850
  console.log(`Initializing project in ${projectPath}...`);
432784
432851
  process.chdir(projectPath);
432785
432852
  if (!fs2.existsSync("package.json")) {
432786
- const initCommand = packageManager === "yarn" ? "yarn init -y" : packageManager === "pnpm" ? "pnpm init" : packageManager === "bun" ? "bun init -y" : "npm init -y";
432787
432853
  try {
432788
- execSync(initCommand, { stdio: "inherit" });
432854
+ packageManager.init({ cwd: projectPath });
432789
432855
  console.log("Project initialized successfully.");
432790
432856
  } catch (error) {
432791
- console.warn("Failed to automatically inititialize project.");
432857
+ console.warn("Failed to automatically initialize project.");
432858
+ const initCommand = packageManager.getInitCommand();
432792
432859
  console.warn("Please inititialize using the command:");
432793
432860
  console.warn(` ${initCommand}`);
432794
432861
  }
@@ -432799,12 +432866,16 @@ function setupTsciProject(directory = process.cwd(), dependencies = ["@types/rea
432799
432866
  console.log("Updated package.json to remove unnecessary fields.");
432800
432867
  if (dependencies.length > 0) {
432801
432868
  console.log("Installing dependencies...");
432802
- const installCommand = packageManager === "bun" ? `bun add -D ${dependencies.join(" ")}` : packageManager === "yarn" ? `yarn add -D ${dependencies.join(" ")}` : packageManager === "pnpm" ? `pnpm add -D ${dependencies.join(" ")}` : `npm install -D ${dependencies.join(" ")}`;
432803
432869
  try {
432804
- execSync(installCommand, { stdio: "inherit" });
432870
+ packageManager.installDeps({
432871
+ deps: dependencies,
432872
+ cwd: projectPath,
432873
+ dev: true
432874
+ });
432805
432875
  console.log("Dependencies installed successfully.");
432806
432876
  } catch (error) {
432807
432877
  console.warn("Failed to automatically install the required dependencies.");
432878
+ const installCommand = packageManager.getInstallDepsCommand(dependencies, true);
432808
432879
  console.warn("Please install them manually using the command:");
432809
432880
  console.warn(` ${installCommand}`);
432810
432881
  }
@@ -433425,7 +433496,7 @@ import readline from "node:readline";
433425
433496
  import { execSync as execSync2 } from "node:child_process";
433426
433497
  var import_semver = __toESM2(require_semver2(), 1);
433427
433498
  // package.json
433428
- var version = "0.1.100";
433499
+ var version = "0.1.102";
433429
433500
  var package_default = {
433430
433501
  name: "@tscircuit/cli",
433431
433502
  version,
@@ -433600,8 +433671,8 @@ var checkForTsciUpdates = async () => {
433600
433671
  const userWantsToUpdate = await askConfirmation(`A new version of tsci is available (${currentCliVersion()} → ${latestCliVersion}).
433601
433672
  Would you like to update now?`);
433602
433673
  if (userWantsToUpdate) {
433603
- const packageManager = detectPackageManager();
433604
- const installCommand = getGlobalDepsInstallCommand(packageManager, "@tscircuit/cli@latest");
433674
+ const packageManager = getPackageManager();
433675
+ const installCommand = getGlobalDepsInstallCommand(packageManager.name, "@tscircuit/cli@latest");
433605
433676
  try {
433606
433677
  console.log(`Updating tsci using: ${installCommand}`);
433607
433678
  execSync2(installCommand, { stdio: "inherit" });
@@ -439134,21 +439205,22 @@ var pushSnippet = async ({
439134
439205
  // lib/shared/add-package.ts
439135
439206
  import * as fs17 from "node:fs";
439136
439207
  import * as path17 from "node:path";
439137
- import { execSync as execSync3 } from "node:child_process";
439138
- async function addPackage(componentPath, projectDir = process.cwd()) {
439139
- let packageName;
439208
+ function normalizePackageNameToNpm(componentPath) {
439140
439209
  if (componentPath.startsWith("@tscircuit/")) {
439141
- packageName = componentPath;
439210
+ return componentPath;
439142
439211
  } else if (componentPath.startsWith("@tsci/")) {
439143
- packageName = componentPath;
439212
+ return componentPath;
439144
439213
  } else {
439145
439214
  const match = componentPath.match(/^([^/.]+)[/.](.+)$/);
439146
439215
  if (!match) {
439147
439216
  throw new Error("Invalid component path. Use format: author/component-name, author.component-name, @tscircuit/package-name, or @tsci/author.component-name");
439148
439217
  }
439149
439218
  const [, author, componentName] = match;
439150
- packageName = `@tsci/${author}.${componentName}`;
439219
+ return `@tsci/${author}.${componentName}`;
439151
439220
  }
439221
+ }
439222
+ async function addPackage(componentPath, projectDir = process.cwd()) {
439223
+ const packageName = normalizePackageNameToNpm(componentPath);
439152
439224
  console.log(`Adding ${packageName}...`);
439153
439225
  const npmrcPath = path17.join(projectDir, ".npmrc");
439154
439226
  const npmrcContent = fs17.existsSync(npmrcPath) ? fs17.readFileSync(npmrcPath, "utf-8") : "";
@@ -439168,23 +439240,9 @@ async function addPackage(componentPath, projectDir = process.cwd()) {
439168
439240
  console.log(`Added ${packageName} successfully.`);
439169
439241
  return;
439170
439242
  }
439171
- const packageManager = detectPackageManager();
439172
- let installCommand;
439173
- if (packageManager === "yarn") {
439174
- installCommand = `yarn add ${packageName}`;
439175
- } else if (packageManager === "pnpm") {
439176
- installCommand = `pnpm add ${packageName}`;
439177
- } else if (packageManager === "bun") {
439178
- if (packageName.startsWith("@tsci/")) {
439179
- installCommand = `bun add ${packageName} --registry https://npm.tscircuit.com`;
439180
- } else {
439181
- installCommand = `bun add ${packageName}`;
439182
- }
439183
- } else {
439184
- installCommand = `npm install ${packageName}`;
439185
- }
439243
+ const packageManager = getPackageManager();
439186
439244
  try {
439187
- execSync3(installCommand, { stdio: "pipe", cwd: projectDir });
439245
+ packageManager.install({ name: packageName, cwd: projectDir });
439188
439246
  console.log(`Added ${packageName} successfully.`);
439189
439247
  } catch (error) {
439190
439248
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -464709,9 +464767,37 @@ var registerSearch = (program3) => {
464709
464767
  });
464710
464768
  };
464711
464769
 
464770
+ // lib/shared/remove-package.ts
464771
+ async function removePackage(componentPath, projectDir = process.cwd()) {
464772
+ const packageName = normalizePackageNameToNpm(componentPath);
464773
+ console.log(`Removing ${packageName}...`);
464774
+ const packageManager = getPackageManager();
464775
+ try {
464776
+ packageManager.uninstall({ name: packageName, cwd: projectDir });
464777
+ console.log(`Removed ${packageName} successfully.`);
464778
+ } catch (error) {
464779
+ const errorMessage = error instanceof Error ? error.message : String(error);
464780
+ if (errorMessage.includes("is not in dependencies") || errorMessage.includes("not present in package.json") || errorMessage.includes("No such package") || errorMessage.includes("not found in dependencies")) {
464781
+ console.log(`${packageName} is not a dependency.`);
464782
+ return;
464783
+ }
464784
+ console.error(`Failed to remove ${packageName}:`, errorMessage);
464785
+ throw new Error(`Failed to remove ${packageName}: ${errorMessage}`);
464786
+ }
464787
+ }
464788
+
464789
+ // cli/remove/register.ts
464790
+ var registerRemove = (program3) => {
464791
+ program3.command("remove").description("Remove a tscircuit component package from your project").argument("<component>", "Component to remove (e.g. author/component-name)").action((componentPath) => {
464792
+ return removePackage(componentPath).catch(() => {
464793
+ process.exit(1);
464794
+ });
464795
+ });
464796
+ };
464797
+
464712
464798
  // cli/main.ts
464713
464799
  var program2 = new Command;
464714
- program2.name("tsci").description("CLI for developing tscircuit snippets").version(getVersion());
464800
+ program2.name("tsci").description("CLI for developing tscircuit snippets");
464715
464801
  registerInit(program2);
464716
464802
  registerDev(program2);
464717
464803
  registerClone(program2);
@@ -464726,8 +464812,16 @@ registerConfigPrint(program2);
464726
464812
  registerConfigSet(program2);
464727
464813
  registerExport(program2);
464728
464814
  registerAdd(program2);
464815
+ registerRemove(program2);
464729
464816
  registerUpgradeCommand(program2);
464730
464817
  registerSearch(program2);
464818
+ if (process.argv.includes("--version") || process.argv.includes("-v") || process.argv.includes("-V")) {
464819
+ console.log(getVersion());
464820
+ process.exit(0);
464821
+ }
464822
+ program2.command("version").description("Print CLI version").action(() => {
464823
+ console.log(getVersion());
464824
+ });
464731
464825
  if (process.argv.length === 2) {
464732
464826
  import_perfect_cli.perfectCli(program2, process.argv);
464733
464827
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.101",
3
+ "version": "0.1.103",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",