@tscircuit/cli 0.1.1422 → 0.1.1423

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
@@ -100688,7 +100688,7 @@ var import_perfect_cli = __toESM2(require_dist2(), 1);
100688
100688
  // lib/getVersion.ts
100689
100689
  import { createRequire as createRequire2 } from "node:module";
100690
100690
  // package.json
100691
- var version = "0.1.1421";
100691
+ var version = "0.1.1422";
100692
100692
  var package_default = {
100693
100693
  name: "@tscircuit/cli",
100694
100694
  version,
@@ -104485,6 +104485,7 @@ import path42 from "node:path";
104485
104485
  // lib/project-config/index.ts
104486
104486
  import * as fs15 from "node:fs";
104487
104487
  import * as path15 from "node:path";
104488
+ import { pathToFileURL } from "node:url";
104488
104489
 
104489
104490
  // lib/project-config/project-config-schema.ts
104490
104491
  import { z } from "zod";
@@ -104524,13 +104525,61 @@ var projectConfigSchema = z.object({
104524
104525
 
104525
104526
  // lib/project-config/index.ts
104526
104527
  var CONFIG_FILENAME = "tscircuit.config.json";
104528
+ var CONFIG_MODULE_FILENAMES = [
104529
+ "tscircuit.config.ts",
104530
+ "tscircuit.config.js"
104531
+ ];
104532
+ var ENV_FILENAMES = [".env", ".env.local"];
104527
104533
  var CONFIG_SCHEMA_URL = "https://cdn.jsdelivr.net/npm/@tscircuit/cli/types/tscircuit.config.schema.json";
104528
104534
  var DEFAULT_BOARD_FILE_PATTERNS = [
104529
104535
  "**/*.board.tsx",
104530
104536
  "**/*.circuit.tsx",
104531
104537
  "**/*.circuit.json"
104532
104538
  ];
104533
- var loadProjectConfig = (projectDir = process.cwd()) => {
104539
+ var parseProjectConfigObject = (config) => {
104540
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
104541
+ throw new Error("tscircuit config must export an object");
104542
+ }
104543
+ const { platformConfig, ...serializableConfig } = config;
104544
+ const parsedConfig = projectConfigSchema.parse(serializableConfig);
104545
+ if (platformConfig === undefined) {
104546
+ return parsedConfig;
104547
+ }
104548
+ return {
104549
+ ...parsedConfig,
104550
+ platformConfig
104551
+ };
104552
+ };
104553
+ var stripWrappingQuotes = (value) => {
104554
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
104555
+ return value.slice(1, -1);
104556
+ }
104557
+ return value;
104558
+ };
104559
+ var loadProjectEnv = (projectDir) => {
104560
+ const initialEnvKeys = new Set(Object.keys(process.env));
104561
+ for (const envFileName of ENV_FILENAMES) {
104562
+ const envPath = path15.join(projectDir, envFileName);
104563
+ if (!fs15.existsSync(envPath))
104564
+ continue;
104565
+ const envContent = fs15.readFileSync(envPath, "utf8");
104566
+ for (const rawLine of envContent.split(/\r?\n/)) {
104567
+ const line = rawLine.trim();
104568
+ if (!line || line.startsWith("#"))
104569
+ continue;
104570
+ const lineWithoutExport = line.startsWith("export ") ? line.slice("export ".length) : line;
104571
+ const separatorIndex = lineWithoutExport.indexOf("=");
104572
+ if (separatorIndex <= 0)
104573
+ continue;
104574
+ const key = lineWithoutExport.slice(0, separatorIndex).trim();
104575
+ if (!key || initialEnvKeys.has(key))
104576
+ continue;
104577
+ const value = stripWrappingQuotes(lineWithoutExport.slice(separatorIndex + 1).trim());
104578
+ process.env[key] = value;
104579
+ }
104580
+ }
104581
+ };
104582
+ var loadProjectConfigSync = (projectDir = process.cwd()) => {
104534
104583
  const configPath = path15.join(projectDir, CONFIG_FILENAME);
104535
104584
  if (!fs15.existsSync(configPath)) {
104536
104585
  return null;
@@ -104544,8 +104593,50 @@ var loadProjectConfig = (projectDir = process.cwd()) => {
104544
104593
  return null;
104545
104594
  }
104546
104595
  };
104596
+ var loadProjectConfigModule = async (projectDir) => {
104597
+ loadProjectEnv(projectDir);
104598
+ for (const configFileName of CONFIG_MODULE_FILENAMES) {
104599
+ const configPath = path15.join(projectDir, configFileName);
104600
+ if (!fs15.existsSync(configPath))
104601
+ continue;
104602
+ try {
104603
+ const moduleUrl = pathToFileURL(configPath);
104604
+ const stat = fs15.statSync(configPath);
104605
+ moduleUrl.searchParams.set("tsci", String(stat.mtimeMs));
104606
+ const importedModule = await import(moduleUrl.href);
104607
+ const exportedConfig = importedModule.default ?? importedModule.config ?? importedModule;
104608
+ return parseProjectConfigObject(exportedConfig);
104609
+ } catch (error) {
104610
+ console.error(`Error loading ${configFileName}: ${error}`);
104611
+ return null;
104612
+ }
104613
+ }
104614
+ return null;
104615
+ };
104616
+ var loadRuntimeProjectConfig = async (projectDir = process.cwd()) => {
104617
+ const jsonConfig = loadProjectConfigSync(projectDir);
104618
+ const moduleConfig = await loadProjectConfigModule(projectDir);
104619
+ if (!jsonConfig && !moduleConfig) {
104620
+ return null;
104621
+ }
104622
+ return {
104623
+ ...jsonConfig ?? {},
104624
+ ...moduleConfig ?? {},
104625
+ build: {
104626
+ ...jsonConfig?.build,
104627
+ ...moduleConfig?.build
104628
+ },
104629
+ pcbSnapshotSettings: {
104630
+ ...jsonConfig?.pcbSnapshotSettings,
104631
+ ...moduleConfig?.pcbSnapshotSettings
104632
+ }
104633
+ };
104634
+ };
104635
+ var loadProjectConfig = (projectDir = process.cwd()) => {
104636
+ return loadProjectConfigSync(projectDir);
104637
+ };
104547
104638
  var getBoardFilePatterns = (projectDir = process.cwd()) => {
104548
- const config = loadProjectConfig(projectDir);
104639
+ const config = loadProjectConfigSync(projectDir);
104549
104640
  const patterns = config?.includeBoardFiles?.filter((pattern) => pattern.trim());
104550
104641
  if (patterns && patterns.length > 0) {
104551
104642
  return patterns;
@@ -104553,7 +104644,7 @@ var getBoardFilePatterns = (projectDir = process.cwd()) => {
104553
104644
  return DEFAULT_BOARD_FILE_PATTERNS;
104554
104645
  };
104555
104646
  var getSnapshotsDir = (projectDir = process.cwd()) => {
104556
- const config = loadProjectConfig(projectDir);
104647
+ const config = loadProjectConfigSync(projectDir);
104557
104648
  return config?.snapshotsDir;
104558
104649
  };
104559
104650
  var saveProjectConfig = (config, projectDir = process.cwd()) => {
@@ -104574,7 +104665,7 @@ var saveProjectConfig = (config, projectDir = process.cwd()) => {
104574
104665
  // lib/shared/convert-to-kicad-library.tsx
104575
104666
  import fs18 from "node:fs";
104576
104667
  import path18 from "node:path";
104577
- import { pathToFileURL } from "node:url";
104668
+ import { pathToFileURL as pathToFileURL2 } from "node:url";
104578
104669
 
104579
104670
  // node_modules/circuit-json-to-kicad/dist/index.js
104580
104671
  var exports_dist = {};
@@ -109909,7 +110000,7 @@ async function convertToKicadLibrary({
109909
110000
  entrypoint: absoluteFilePath,
109910
110001
  buildFileToCircuitJson: async (filePath2, componentName) => {
109911
110002
  try {
109912
- const module2 = await import(pathToFileURL(filePath2).href);
110003
+ const module2 = await import(pathToFileURL2(filePath2).href);
109913
110004
  const Component = module2[componentName];
109914
110005
  if (!Component || typeof Component !== "function") {
109915
110006
  return null;
@@ -109924,7 +110015,7 @@ async function convertToKicadLibrary({
109924
110015
  }
109925
110016
  },
109926
110017
  getExportsFromTsxFile: async (filePath2) => {
109927
- const module2 = await import(pathToFileURL(filePath2).href);
110018
+ const module2 = await import(pathToFileURL2(filePath2).href);
109928
110019
  return Object.keys(module2);
109929
110020
  },
109930
110021
  includeBuiltins: true,
@@ -110049,13 +110140,13 @@ var getEntrypoint = async ({
110049
110140
  onError(kleur_default.red(`File not found or invalid: '${filePath}'`));
110050
110141
  return null;
110051
110142
  }
110052
- const projectConfig = loadProjectConfig(validatedProjectDir);
110143
+ const projectConfig = await loadRuntimeProjectConfig(validatedProjectDir);
110053
110144
  const configEntrypoint = projectConfig?.mainEntrypoint ?? projectConfig?.libraryEntrypoint;
110054
110145
  if (configEntrypoint && typeof configEntrypoint === "string") {
110055
110146
  const validatedConfigPath = validateFilePath(configEntrypoint, validatedProjectDir);
110056
110147
  if (validatedConfigPath) {
110057
110148
  const relativePath = path19.relative(validatedProjectDir, validatedConfigPath);
110058
- onSuccess(`Using entrypoint from tscircuit.config.json: '${relativePath}'`);
110149
+ onSuccess(`Using entrypoint from tscircuit config: '${relativePath}'`);
110059
110150
  return validatedConfigPath;
110060
110151
  }
110061
110152
  }
@@ -110480,7 +110571,7 @@ function analyzeCircuitJson(circuitJson) {
110480
110571
  // lib/shared/generate-circuit-json.tsx
110481
110572
  import fs24 from "node:fs";
110482
110573
  import path25 from "node:path";
110483
- import { pathToFileURL as pathToFileURL2 } from "node:url";
110574
+ import { pathToFileURL as pathToFileURL3 } from "node:url";
110484
110575
  import Debug from "debug";
110485
110576
 
110486
110577
  // lib/utils/abbreviate-stringify-object.ts
@@ -110565,7 +110656,7 @@ async function generateCircuitJson({
110565
110656
  })
110566
110657
  };
110567
110658
  debug(`fsMap: ${abbreviateStringifyObject(fsMap)}`);
110568
- const MainComponent = await import(pathToFileURL2(absoluteFilePath).href);
110659
+ const MainComponent = await import(pathToFileURL3(absoluteFilePath).href);
110569
110660
  const Component = MainComponent.default || (Object.keys(MainComponent).find((k) => k[0] === k[0].toUpperCase()) !== undefined ? MainComponent[Object.keys(MainComponent).find((k) => k[0] === k[0].toUpperCase())] : undefined);
110570
110661
  if (!Component) {
110571
110662
  throw new Error(`No component found in "${absoluteFilePath}". Make sure you export a component.`);
@@ -110793,7 +110884,7 @@ var getCircuitJsonToGltfOptions = ({
110793
110884
 
110794
110885
  // cli/build/convert-model-urls-to-file-urls.ts
110795
110886
  import path27 from "node:path";
110796
- import { pathToFileURL as pathToFileURL3 } from "node:url";
110887
+ import { pathToFileURL as pathToFileURL4 } from "node:url";
110797
110888
  var convertModelUrlsToFileUrls = (circuitJson) => {
110798
110889
  const modelUrlKeys = [
110799
110890
  "model_glb_url",
@@ -110817,9 +110908,9 @@ var convertModelUrlsToFileUrls = (circuitJson) => {
110817
110908
  if (value.match(/^[a-zA-Z]+:\/\//))
110818
110909
  continue;
110819
110910
  if (value.startsWith("/") || value.match(/^[a-zA-Z]:\\/)) {
110820
- updated[key] = pathToFileURL3(value).href;
110911
+ updated[key] = pathToFileURL4(value).href;
110821
110912
  } else if (value.startsWith(".")) {
110822
- updated[key] = pathToFileURL3(path27.resolve(process.cwd(), value)).href;
110913
+ updated[key] = pathToFileURL4(path27.resolve(process.cwd(), value)).href;
110823
110914
  }
110824
110915
  }
110825
110916
  }
@@ -245976,7 +246067,7 @@ var registerConfigSet = (program2) => {
245976
246067
  } else if (availableProjectConfigKeys.some((k4) => k4 === key)) {
245977
246068
  const projectDir = process.cwd();
245978
246069
  if (key === "mainEntrypoint" || key === "kicadLibraryEntrypointPath" || key === "previewComponentPath" || key === "siteDefaultComponentPath" || key === "prebuildCommand" || key === "buildCommand") {
245979
- const projectConfig2 = loadProjectConfig(projectDir) ?? {};
246070
+ const projectConfig2 = loadProjectConfigSync(projectDir) ?? {};
245980
246071
  projectConfig2[key] = value;
245981
246072
  if (saveProjectConfig(projectConfig2, projectDir)) {
245982
246073
  console.log(kleur_default.cyan(`Set project config ${kleur_default.yellow(key)} to ${kleur_default.yellow(value)} successfully in ${kleur_default.bold(CONFIG_FILENAME)}.`));
package/dist/lib/index.js CHANGED
@@ -58040,11 +58040,11 @@ var require_out = __commonJS((exports2) => {
58040
58040
  async.read(path14, getSettings(optionsOrSettingsOrCallback), callback);
58041
58041
  }
58042
58042
  exports2.stat = stat;
58043
- function statSync(path14, optionsOrSettings) {
58043
+ function statSync2(path14, optionsOrSettings) {
58044
58044
  const settings = getSettings(optionsOrSettings);
58045
58045
  return sync.read(path14, settings);
58046
58046
  }
58047
- exports2.statSync = statSync;
58047
+ exports2.statSync = statSync2;
58048
58048
  function getSettings(settingsOrOptions = {}) {
58049
58049
  if (settingsOrOptions instanceof settings_1.default) {
58050
58050
  return settingsOrOptions;
@@ -65733,7 +65733,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
65733
65733
  }));
65734
65734
  };
65735
65735
  // package.json
65736
- var version = "0.1.1421";
65736
+ var version = "0.1.1422";
65737
65737
  var package_default = {
65738
65738
  name: "@tscircuit/cli",
65739
65739
  version,
@@ -73875,6 +73875,7 @@ var getPackageAuthor = (packageName) => {
73875
73875
  // lib/project-config/index.ts
73876
73876
  import * as fs9 from "node:fs";
73877
73877
  import * as path11 from "node:path";
73878
+ import { pathToFileURL as pathToFileURL2 } from "node:url";
73878
73879
 
73879
73880
  // lib/project-config/project-config-schema.ts
73880
73881
  import { z as z21 } from "zod";
@@ -73914,13 +73915,61 @@ var projectConfigSchema = z21.object({
73914
73915
 
73915
73916
  // lib/project-config/index.ts
73916
73917
  var CONFIG_FILENAME = "tscircuit.config.json";
73918
+ var CONFIG_MODULE_FILENAMES = [
73919
+ "tscircuit.config.ts",
73920
+ "tscircuit.config.js"
73921
+ ];
73922
+ var ENV_FILENAMES = [".env", ".env.local"];
73917
73923
  var CONFIG_SCHEMA_URL = "https://cdn.jsdelivr.net/npm/@tscircuit/cli/types/tscircuit.config.schema.json";
73918
73924
  var DEFAULT_BOARD_FILE_PATTERNS = [
73919
73925
  "**/*.board.tsx",
73920
73926
  "**/*.circuit.tsx",
73921
73927
  "**/*.circuit.json"
73922
73928
  ];
73923
- var loadProjectConfig = (projectDir = process.cwd()) => {
73929
+ var parseProjectConfigObject = (config) => {
73930
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
73931
+ throw new Error("tscircuit config must export an object");
73932
+ }
73933
+ const { platformConfig, ...serializableConfig } = config;
73934
+ const parsedConfig = projectConfigSchema.parse(serializableConfig);
73935
+ if (platformConfig === undefined) {
73936
+ return parsedConfig;
73937
+ }
73938
+ return {
73939
+ ...parsedConfig,
73940
+ platformConfig
73941
+ };
73942
+ };
73943
+ var stripWrappingQuotes = (value) => {
73944
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
73945
+ return value.slice(1, -1);
73946
+ }
73947
+ return value;
73948
+ };
73949
+ var loadProjectEnv = (projectDir) => {
73950
+ const initialEnvKeys = new Set(Object.keys(process.env));
73951
+ for (const envFileName of ENV_FILENAMES) {
73952
+ const envPath = path11.join(projectDir, envFileName);
73953
+ if (!fs9.existsSync(envPath))
73954
+ continue;
73955
+ const envContent = fs9.readFileSync(envPath, "utf8");
73956
+ for (const rawLine of envContent.split(/\r?\n/)) {
73957
+ const line = rawLine.trim();
73958
+ if (!line || line.startsWith("#"))
73959
+ continue;
73960
+ const lineWithoutExport = line.startsWith("export ") ? line.slice("export ".length) : line;
73961
+ const separatorIndex = lineWithoutExport.indexOf("=");
73962
+ if (separatorIndex <= 0)
73963
+ continue;
73964
+ const key = lineWithoutExport.slice(0, separatorIndex).trim();
73965
+ if (!key || initialEnvKeys.has(key))
73966
+ continue;
73967
+ const value = stripWrappingQuotes(lineWithoutExport.slice(separatorIndex + 1).trim());
73968
+ process.env[key] = value;
73969
+ }
73970
+ }
73971
+ };
73972
+ var loadProjectConfigSync = (projectDir = process.cwd()) => {
73924
73973
  const configPath = path11.join(projectDir, CONFIG_FILENAME);
73925
73974
  if (!fs9.existsSync(configPath)) {
73926
73975
  return null;
@@ -73934,8 +73983,50 @@ var loadProjectConfig = (projectDir = process.cwd()) => {
73934
73983
  return null;
73935
73984
  }
73936
73985
  };
73986
+ var loadProjectConfigModule = async (projectDir) => {
73987
+ loadProjectEnv(projectDir);
73988
+ for (const configFileName of CONFIG_MODULE_FILENAMES) {
73989
+ const configPath = path11.join(projectDir, configFileName);
73990
+ if (!fs9.existsSync(configPath))
73991
+ continue;
73992
+ try {
73993
+ const moduleUrl = pathToFileURL2(configPath);
73994
+ const stat = fs9.statSync(configPath);
73995
+ moduleUrl.searchParams.set("tsci", String(stat.mtimeMs));
73996
+ const importedModule = await import(moduleUrl.href);
73997
+ const exportedConfig = importedModule.default ?? importedModule.config ?? importedModule;
73998
+ return parseProjectConfigObject(exportedConfig);
73999
+ } catch (error) {
74000
+ console.error(`Error loading ${configFileName}: ${error}`);
74001
+ return null;
74002
+ }
74003
+ }
74004
+ return null;
74005
+ };
74006
+ var loadRuntimeProjectConfig = async (projectDir = process.cwd()) => {
74007
+ const jsonConfig = loadProjectConfigSync(projectDir);
74008
+ const moduleConfig = await loadProjectConfigModule(projectDir);
74009
+ if (!jsonConfig && !moduleConfig) {
74010
+ return null;
74011
+ }
74012
+ return {
74013
+ ...jsonConfig ?? {},
74014
+ ...moduleConfig ?? {},
74015
+ build: {
74016
+ ...jsonConfig?.build,
74017
+ ...moduleConfig?.build
74018
+ },
74019
+ pcbSnapshotSettings: {
74020
+ ...jsonConfig?.pcbSnapshotSettings,
74021
+ ...moduleConfig?.pcbSnapshotSettings
74022
+ }
74023
+ };
74024
+ };
74025
+ var loadProjectConfig = (projectDir = process.cwd()) => {
74026
+ return loadProjectConfigSync(projectDir);
74027
+ };
73937
74028
  var getBoardFilePatterns = (projectDir = process.cwd()) => {
73938
- const config = loadProjectConfig(projectDir);
74029
+ const config = loadProjectConfigSync(projectDir);
73939
74030
  const patterns = config?.includeBoardFiles?.filter((pattern) => pattern.trim());
73940
74031
  if (patterns && patterns.length > 0) {
73941
74032
  return patterns;
@@ -73943,7 +74034,7 @@ var getBoardFilePatterns = (projectDir = process.cwd()) => {
73943
74034
  return DEFAULT_BOARD_FILE_PATTERNS;
73944
74035
  };
73945
74036
  var getSnapshotsDir = (projectDir = process.cwd()) => {
73946
- const config = loadProjectConfig(projectDir);
74037
+ const config = loadProjectConfigSync(projectDir);
73947
74038
  return config?.snapshotsDir;
73948
74039
  };
73949
74040
  var saveProjectConfig = (config, projectDir = process.cwd()) => {
@@ -78217,13 +78308,13 @@ var getEntrypoint = async ({
78217
78308
  onError(kleur_default.red(`File not found or invalid: '${filePath}'`));
78218
78309
  return null;
78219
78310
  }
78220
- const projectConfig = loadProjectConfig(validatedProjectDir);
78311
+ const projectConfig = await loadRuntimeProjectConfig(validatedProjectDir);
78221
78312
  const configEntrypoint = projectConfig?.mainEntrypoint ?? projectConfig?.libraryEntrypoint;
78222
78313
  if (configEntrypoint && typeof configEntrypoint === "string") {
78223
78314
  const validatedConfigPath = validateFilePath(configEntrypoint, validatedProjectDir);
78224
78315
  if (validatedConfigPath) {
78225
78316
  const relativePath = path22.relative(validatedProjectDir, validatedConfigPath);
78226
- onSuccess(`Using entrypoint from tscircuit.config.json: '${relativePath}'`);
78317
+ onSuccess(`Using entrypoint from tscircuit config: '${relativePath}'`);
78227
78318
  return validatedConfigPath;
78228
78319
  }
78229
78320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.1422",
3
+ "version": "0.1.1423",
4
4
  "main": "dist/cli/main.js",
5
5
  "exports": {
6
6
  ".": "./dist/cli/main.js",