@tscircuit/cli 0.1.484 → 0.1.486

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 (2) hide show
  1. package/dist/main.js +134 -2
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -70022,7 +70022,13 @@ function getPackageManager() {
70022
70022
  execSync(installCommand, { stdio: "inherit", cwd });
70023
70023
  },
70024
70024
  getInitCommand,
70025
- getInstallDepsCommand
70025
+ getInstallDepsCommand,
70026
+ installAll: ({ cwd }) => {
70027
+ const installCommand = getInstallAllCommand();
70028
+ console.log(kleur_default.gray(`> ${installCommand}`));
70029
+ execSync(installCommand, { stdio: "inherit", cwd });
70030
+ },
70031
+ getInstallAllCommand
70026
70032
  };
70027
70033
  function getInitCommand() {
70028
70034
  if (pm === "yarn")
@@ -70033,6 +70039,15 @@ function getPackageManager() {
70033
70039
  return "bun init -y";
70034
70040
  return "npm init -y";
70035
70041
  }
70042
+ function getInstallAllCommand() {
70043
+ if (pm === "yarn")
70044
+ return "yarn install";
70045
+ if (pm === "pnpm")
70046
+ return "pnpm install";
70047
+ if (pm === "bun")
70048
+ return "bun install";
70049
+ return "npm install";
70050
+ }
70036
70051
  function getInstallDepsCommand(deps, dev) {
70037
70052
  const depList = deps.join(" ");
70038
70053
  if (pm === "bun")
@@ -70181,6 +70196,9 @@ var generatePackageJson = (dir, opts = {}) => {
70181
70196
  snapshot: "tsci snapshot",
70182
70197
  "snapshot:update": "tsci snapshot --update",
70183
70198
  start: "tsci dev"
70199
+ },
70200
+ devDependencies: {
70201
+ tscircuit: "latest"
70184
70202
  }
70185
70203
  };
70186
70204
  writeFileIfNotExists(packageJsonPath, JSON.stringify(packageJsonContent, null, 2));
@@ -72369,7 +72387,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
72369
72387
  import { execSync as execSync2 } from "node:child_process";
72370
72388
  var import_semver2 = __toESM2(require_semver2(), 1);
72371
72389
  // package.json
72372
- var version = "0.1.483";
72390
+ var version = "0.1.485";
72373
72391
  var package_default = {
72374
72392
  name: "@tscircuit/cli",
72375
72393
  version,
@@ -94121,6 +94139,8 @@ async function generateCircuitJson({
94121
94139
  platformConfig
94122
94140
  }) {
94123
94141
  debug11(`Generating circuit JSON for ${filePath}`);
94142
+ const React = await importFromUserLand("react");
94143
+ globalThis.React = React;
94124
94144
  const userLandTscircuit = await importFromUserLand("tscircuit");
94125
94145
  const runner = new userLandTscircuit.RootCircuit({
94126
94146
  platform: platformConfig
@@ -196888,6 +196908,117 @@ var registerSimulate = (program3) => {
196888
196908
  });
196889
196909
  };
196890
196910
 
196911
+ // lib/shared/install-project-dependencies.ts
196912
+ import fs40 from "node:fs";
196913
+ import path38 from "node:path";
196914
+
196915
+ // lib/shared/collect-tsci-dependencies.ts
196916
+ import fs39 from "node:fs";
196917
+ import path37 from "node:path";
196918
+ var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
196919
+ var DEFAULT_IGNORES = [
196920
+ "**/node_modules/**",
196921
+ "**/.git/**",
196922
+ "**/dist/**",
196923
+ "**/build/**",
196924
+ "**/.tsci/**"
196925
+ ];
196926
+ var IMPORT_PATTERN = /["'`](@tsci\/[A-Za-z0-9._/-]+)["'`]/g;
196927
+ function collectTsciDependencies({
196928
+ cwd = process.cwd(),
196929
+ patterns = DEFAULT_PATTERNS,
196930
+ ignore = DEFAULT_IGNORES
196931
+ } = {}) {
196932
+ const searchRoot = path37.resolve(cwd);
196933
+ const files = globbySync(patterns, {
196934
+ cwd: searchRoot,
196935
+ absolute: true,
196936
+ ignore,
196937
+ gitignore: true
196938
+ });
196939
+ const dependencies2 = new Set;
196940
+ for (const filePath of files) {
196941
+ try {
196942
+ const fileContents = fs39.readFileSync(filePath, "utf-8");
196943
+ let match;
196944
+ while (true) {
196945
+ match = IMPORT_PATTERN.exec(fileContents);
196946
+ if (match === null)
196947
+ break;
196948
+ dependencies2.add(match[1]);
196949
+ }
196950
+ } catch (error) {}
196951
+ }
196952
+ return Array.from(dependencies2);
196953
+ }
196954
+
196955
+ // lib/shared/install-project-dependencies.ts
196956
+ async function installProjectDependencies({
196957
+ cwd = process.cwd()
196958
+ } = {}) {
196959
+ const projectRoot = path38.resolve(cwd);
196960
+ const packageJsonPath = path38.join(projectRoot, "package.json");
196961
+ const npmrcPath = path38.join(projectRoot, ".npmrc");
196962
+ const packageManager = getPackageManager();
196963
+ if (!fs40.existsSync(projectRoot)) {
196964
+ throw new Error(`Directory not found: ${projectRoot}`);
196965
+ }
196966
+ let packageJsonCreated = false;
196967
+ if (!fs40.existsSync(packageJsonPath)) {
196968
+ console.log("No package.json found. Generating a new one.");
196969
+ generatePackageJson(projectRoot);
196970
+ packageJsonCreated = true;
196971
+ } else {
196972
+ console.log("Found existing package.json.");
196973
+ }
196974
+ if (!fs40.existsSync(npmrcPath)) {
196975
+ console.log("Creating .npmrc with tscircuit registry configuration.");
196976
+ fs40.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
196977
+ }
196978
+ const packageJson = JSON.parse(fs40.readFileSync(packageJsonPath, "utf-8"));
196979
+ if (packageJsonCreated) {
196980
+ const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
196981
+ if (tsciDependencies.length > 0) {
196982
+ packageJson.dependencies = packageJson.dependencies || {};
196983
+ for (const dependency of tsciDependencies) {
196984
+ if (!packageJson.dependencies[dependency]) {
196985
+ packageJson.dependencies[dependency] = "latest";
196986
+ }
196987
+ }
196988
+ console.log(`Added ${tsciDependencies.length} @tsci dependencies to package.json.`);
196989
+ } else {
196990
+ console.log("No @tsci dependencies detected in circuit files.");
196991
+ }
196992
+ }
196993
+ fs40.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
196994
+ `);
196995
+ console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
196996
+ try {
196997
+ packageManager.installAll({ cwd: projectRoot });
196998
+ console.log("Dependencies installed successfully.");
196999
+ } catch (error) {
197000
+ console.warn("Failed to automatically install dependencies.");
197001
+ console.warn(`Please run \`${packageManager.getInstallAllCommand()}\` manually.`);
197002
+ throw error;
197003
+ }
197004
+ }
197005
+
197006
+ // cli/install/register.ts
197007
+ var registerInstall = (program3) => {
197008
+ program3.command("install").description("Install project dependencies and generate package.json if needed").action(async () => {
197009
+ try {
197010
+ await installProjectDependencies();
197011
+ } catch (error) {
197012
+ if (error instanceof Error) {
197013
+ console.error(error.message);
197014
+ } else {
197015
+ console.error(error);
197016
+ }
197017
+ process.exit(1);
197018
+ }
197019
+ });
197020
+ };
197021
+
196891
197022
  // cli/main.ts
196892
197023
  var program2 = new Command;
196893
197024
  program2.name("tsci").description("CLI for developing tscircuit packages");
@@ -196910,6 +197041,7 @@ registerAdd(program2);
196910
197041
  registerRemove(program2);
196911
197042
  registerSnapshot(program2);
196912
197043
  registerSetup(program2);
197044
+ registerInstall(program2);
196913
197045
  registerUpgradeCommand(program2);
196914
197046
  registerSearch(program2);
196915
197047
  registerImport(program2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.484",
3
+ "version": "0.1.486",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",