@tscircuit/cli 0.1.544 → 0.1.546
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/main.js +101 -85
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -72387,7 +72387,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
72387
72387
|
import { execSync as execSync2 } from "node:child_process";
|
|
72388
72388
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
72389
72389
|
// package.json
|
|
72390
|
-
var version = "0.1.
|
|
72390
|
+
var version = "0.1.545";
|
|
72391
72391
|
var package_default = {
|
|
72392
72392
|
name: "@tscircuit/cli",
|
|
72393
72393
|
version,
|
|
@@ -77427,6 +77427,7 @@ class DevServer {
|
|
|
77427
77427
|
this.eventsWatcher.on("FILE_DELETED", this.handleFileDeletedEventFromServer.bind(this));
|
|
77428
77428
|
this.eventsWatcher.on("REQUEST_TO_SAVE_SNIPPET", this.saveSnippet.bind(this));
|
|
77429
77429
|
this.eventsWatcher.on("INSTALL_PACKAGE", (event) => this.handleInstallPackage(event.full_package_name));
|
|
77430
|
+
this.eventsWatcher.on("TOKEN_UPDATED", (event) => this.handleTokenUpdated(event.registry_token));
|
|
77430
77431
|
this.filesystemWatcher = watch(this.projectDir, {
|
|
77431
77432
|
persistent: true,
|
|
77432
77433
|
ignoreInitial: true,
|
|
@@ -77657,6 +77658,14 @@ class DevServer {
|
|
|
77657
77658
|
await postEvent("PACKAGE_INSTALL_FAILED", err instanceof Error ? err.message : String(err));
|
|
77658
77659
|
}
|
|
77659
77660
|
}
|
|
77661
|
+
handleTokenUpdated(registry_token) {
|
|
77662
|
+
try {
|
|
77663
|
+
setSessionToken(registry_token);
|
|
77664
|
+
console.log(kleur_default.green("Session token overridden successfully via runframe"));
|
|
77665
|
+
} catch (err) {
|
|
77666
|
+
console.error("Failed to update session token:", err);
|
|
77667
|
+
}
|
|
77668
|
+
}
|
|
77660
77669
|
}
|
|
77661
77670
|
|
|
77662
77671
|
// lib/getVersion.ts
|
|
@@ -196242,8 +196251,8 @@ var registerRemove = (program3) => {
|
|
|
196242
196251
|
};
|
|
196243
196252
|
|
|
196244
196253
|
// cli/build/register.ts
|
|
196245
|
-
import
|
|
196246
|
-
import
|
|
196254
|
+
import path38 from "node:path";
|
|
196255
|
+
import fs39 from "node:fs";
|
|
196247
196256
|
|
|
196248
196257
|
// cli/build/build-file.ts
|
|
196249
196258
|
import path30 from "node:path";
|
|
@@ -196976,6 +196985,23 @@ var transpileFile = async ({
|
|
|
196976
196985
|
}
|
|
196977
196986
|
};
|
|
196978
196987
|
|
|
196988
|
+
// cli/utils/validate-main-in-dist.ts
|
|
196989
|
+
import fs38 from "node:fs";
|
|
196990
|
+
import path37 from "node:path";
|
|
196991
|
+
var validateMainInDist = (projectDir, distDir) => {
|
|
196992
|
+
const packageJsonPath = path37.join(projectDir, "package.json");
|
|
196993
|
+
if (!fs38.existsSync(packageJsonPath))
|
|
196994
|
+
return;
|
|
196995
|
+
const packageJson = JSON.parse(fs38.readFileSync(packageJsonPath, "utf-8"));
|
|
196996
|
+
if (typeof packageJson.main !== "string")
|
|
196997
|
+
return;
|
|
196998
|
+
const resolvedMainPath = path37.resolve(projectDir, packageJson.main);
|
|
196999
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path37.sep}`);
|
|
197000
|
+
if (!isMainInDist) {
|
|
197001
|
+
throw new Error('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
197002
|
+
}
|
|
197003
|
+
};
|
|
197004
|
+
|
|
196979
197005
|
// cli/build/register.ts
|
|
196980
197006
|
var registerBuild = (program3) => {
|
|
196981
197007
|
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad", "Generate KiCad project directories for each successful build output").option("--kicad-footprint-library", "Generate a KiCad footprint library from all successful build outputs").action(async (file, options) => {
|
|
@@ -196995,8 +197021,8 @@ var registerBuild = (program3) => {
|
|
|
196995
197021
|
}
|
|
196996
197022
|
return config;
|
|
196997
197023
|
})();
|
|
196998
|
-
const distDir =
|
|
196999
|
-
|
|
197024
|
+
const distDir = path38.join(projectDir, "dist");
|
|
197025
|
+
fs39.mkdirSync(distDir, { recursive: true });
|
|
197000
197026
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
197001
197027
|
let hasErrors = false;
|
|
197002
197028
|
const staticFileReferences = [];
|
|
@@ -197004,10 +197030,10 @@ var registerBuild = (program3) => {
|
|
|
197004
197030
|
const kicadProjects = [];
|
|
197005
197031
|
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
197006
197032
|
for (const filePath of circuitFiles) {
|
|
197007
|
-
const relative9 =
|
|
197033
|
+
const relative9 = path38.relative(projectDir, filePath);
|
|
197008
197034
|
console.log(`Building ${relative9}...`);
|
|
197009
197035
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
197010
|
-
const outputPath =
|
|
197036
|
+
const outputPath = path38.join(distDir, outputDirName, "circuit.json");
|
|
197011
197037
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
197012
197038
|
ignoreErrors: options?.ignoreErrors,
|
|
197013
197039
|
ignoreWarnings: options?.ignoreWarnings,
|
|
@@ -197021,17 +197047,17 @@ var registerBuild = (program3) => {
|
|
|
197021
197047
|
if (!buildOutcome.ok) {
|
|
197022
197048
|
hasErrors = true;
|
|
197023
197049
|
} else if (options?.site) {
|
|
197024
|
-
const normalizedSourcePath = relative9.split(
|
|
197025
|
-
const relativeOutputPath =
|
|
197026
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
197050
|
+
const normalizedSourcePath = relative9.split(path38.sep).join("/");
|
|
197051
|
+
const relativeOutputPath = path38.join(outputDirName, "circuit.json");
|
|
197052
|
+
const normalizedOutputPath = relativeOutputPath.split(path38.sep).join("/");
|
|
197027
197053
|
staticFileReferences.push({
|
|
197028
197054
|
filePath: normalizedSourcePath,
|
|
197029
197055
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
197030
197056
|
});
|
|
197031
197057
|
}
|
|
197032
197058
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
197033
|
-
const projectOutputDir =
|
|
197034
|
-
const projectName =
|
|
197059
|
+
const projectOutputDir = path38.join(distDir, outputDirName, "kicad");
|
|
197060
|
+
const projectName = path38.basename(outputDirName);
|
|
197035
197061
|
const project = await generateKicadProject({
|
|
197036
197062
|
circuitJson: buildOutcome.circuitJson,
|
|
197037
197063
|
outputDir: projectOutputDir,
|
|
@@ -197058,6 +197084,7 @@ var registerBuild = (program3) => {
|
|
|
197058
197084
|
});
|
|
197059
197085
|
}
|
|
197060
197086
|
if (options?.transpile) {
|
|
197087
|
+
validateMainInDist(projectDir, distDir);
|
|
197061
197088
|
console.log("Transpiling entry file...");
|
|
197062
197089
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197063
197090
|
if (!entryFile) {
|
|
@@ -197079,8 +197106,8 @@ var registerBuild = (program3) => {
|
|
|
197079
197106
|
files: staticFileReferences,
|
|
197080
197107
|
standaloneScriptSrc: "./standalone.min.js"
|
|
197081
197108
|
});
|
|
197082
|
-
|
|
197083
|
-
|
|
197109
|
+
fs39.writeFileSync(path38.join(distDir, "index.html"), indexHtml);
|
|
197110
|
+
fs39.writeFileSync(path38.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
197084
197111
|
}
|
|
197085
197112
|
if (options?.kicadFootprintLibrary) {
|
|
197086
197113
|
if (kicadProjects.length === 0) {
|
|
@@ -197103,8 +197130,8 @@ var registerBuild = (program3) => {
|
|
|
197103
197130
|
};
|
|
197104
197131
|
|
|
197105
197132
|
// lib/shared/snapshot-project.ts
|
|
197106
|
-
import
|
|
197107
|
-
import
|
|
197133
|
+
import fs41 from "node:fs";
|
|
197134
|
+
import path39 from "node:path";
|
|
197108
197135
|
import looksSame2 from "looks-same";
|
|
197109
197136
|
import {
|
|
197110
197137
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -197115,7 +197142,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
197115
197142
|
|
|
197116
197143
|
// lib/shared/compare-images.ts
|
|
197117
197144
|
import looksSame from "looks-same";
|
|
197118
|
-
import
|
|
197145
|
+
import fs40 from "node:fs/promises";
|
|
197119
197146
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
197120
197147
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
197121
197148
|
strict: false,
|
|
@@ -197131,7 +197158,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
197131
197158
|
tolerance: 2
|
|
197132
197159
|
});
|
|
197133
197160
|
} else {
|
|
197134
|
-
await
|
|
197161
|
+
await fs40.writeFile(diffPath, buffer2);
|
|
197135
197162
|
}
|
|
197136
197163
|
}
|
|
197137
197164
|
return { equal: equal2 };
|
|
@@ -197156,7 +197183,7 @@ var snapshotProject = async ({
|
|
|
197156
197183
|
...DEFAULT_IGNORED_PATTERNS,
|
|
197157
197184
|
...ignored.map(normalizeIgnorePattern)
|
|
197158
197185
|
];
|
|
197159
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
197186
|
+
const resolvedPaths = filePaths.map((f) => path39.resolve(projectDir, f));
|
|
197160
197187
|
const boardFiles = findBoardFiles({
|
|
197161
197188
|
projectDir,
|
|
197162
197189
|
ignore,
|
|
@@ -197170,7 +197197,7 @@ var snapshotProject = async ({
|
|
|
197170
197197
|
const mismatches = [];
|
|
197171
197198
|
let didUpdate = false;
|
|
197172
197199
|
for (const file of boardFiles) {
|
|
197173
|
-
const relativeFilePath =
|
|
197200
|
+
const relativeFilePath = path39.relative(projectDir, file);
|
|
197174
197201
|
let circuitJson;
|
|
197175
197202
|
let pcbSvg;
|
|
197176
197203
|
let schSvg;
|
|
@@ -197224,17 +197251,17 @@ var snapshotProject = async ({
|
|
|
197224
197251
|
} catch (error) {
|
|
197225
197252
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197226
197253
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
197227
|
-
const fileDir =
|
|
197228
|
-
const relativeDir =
|
|
197229
|
-
const snapDir2 = snapshotsDirName ?
|
|
197230
|
-
const base2 =
|
|
197231
|
-
const snap3dPath =
|
|
197232
|
-
const existing3dSnapshot =
|
|
197254
|
+
const fileDir = path39.dirname(file);
|
|
197255
|
+
const relativeDir = path39.relative(projectDir, fileDir);
|
|
197256
|
+
const snapDir2 = snapshotsDirName ? path39.join(projectDir, snapshotsDirName, relativeDir) : path39.join(fileDir, "__snapshots__");
|
|
197257
|
+
const base2 = path39.basename(file).replace(/\.tsx$/, "");
|
|
197258
|
+
const snap3dPath = path39.join(snapDir2, `${base2}-3d.snap.png`);
|
|
197259
|
+
const existing3dSnapshot = fs41.existsSync(snap3dPath);
|
|
197233
197260
|
if (existing3dSnapshot) {
|
|
197234
197261
|
onError(kleur_default.red(`
|
|
197235
197262
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
197236
197263
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
197237
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
197264
|
+
`) + kleur_default.red(` Existing snapshot: ${path39.relative(projectDir, snap3dPath)}
|
|
197238
197265
|
`));
|
|
197239
197266
|
return onExit(1);
|
|
197240
197267
|
} else {
|
|
@@ -197250,9 +197277,9 @@ var snapshotProject = async ({
|
|
|
197250
197277
|
}
|
|
197251
197278
|
}
|
|
197252
197279
|
}
|
|
197253
|
-
const snapDir = snapshotsDirName ?
|
|
197254
|
-
|
|
197255
|
-
const base =
|
|
197280
|
+
const snapDir = snapshotsDirName ? path39.join(projectDir, snapshotsDirName, path39.relative(projectDir, path39.dirname(file))) : path39.join(path39.dirname(file), "__snapshots__");
|
|
197281
|
+
fs41.mkdirSync(snapDir, { recursive: true });
|
|
197282
|
+
const base = path39.basename(file).replace(/\.tsx$/, "");
|
|
197256
197283
|
const snapshots = [];
|
|
197257
197284
|
if (pcbOnly || !schematicOnly) {
|
|
197258
197285
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -197270,31 +197297,31 @@ var snapshotProject = async ({
|
|
|
197270
197297
|
for (const snapshot of snapshots) {
|
|
197271
197298
|
const { type } = snapshot;
|
|
197272
197299
|
const is3d = type === "3d";
|
|
197273
|
-
const snapPath =
|
|
197274
|
-
const existing =
|
|
197300
|
+
const snapPath = path39.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
197301
|
+
const existing = fs41.existsSync(snapPath);
|
|
197275
197302
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
197276
197303
|
const newContentForFile = snapshot.content;
|
|
197277
197304
|
if (!existing) {
|
|
197278
|
-
|
|
197279
|
-
console.log("✅", kleur_default.gray(
|
|
197305
|
+
fs41.writeFileSync(snapPath, newContentForFile);
|
|
197306
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197280
197307
|
didUpdate = true;
|
|
197281
197308
|
continue;
|
|
197282
197309
|
}
|
|
197283
|
-
const oldContentBuffer =
|
|
197310
|
+
const oldContentBuffer = fs41.readFileSync(snapPath);
|
|
197284
197311
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
197285
197312
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
197286
197313
|
if (update) {
|
|
197287
197314
|
if (!forceUpdate && equal2) {
|
|
197288
|
-
console.log("✅", kleur_default.gray(
|
|
197315
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197289
197316
|
} else {
|
|
197290
|
-
|
|
197291
|
-
console.log("✅", kleur_default.gray(
|
|
197317
|
+
fs41.writeFileSync(snapPath, newContentForFile);
|
|
197318
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197292
197319
|
didUpdate = true;
|
|
197293
197320
|
}
|
|
197294
197321
|
} else if (!equal2) {
|
|
197295
197322
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
197296
197323
|
} else {
|
|
197297
|
-
console.log("✅", kleur_default.gray(
|
|
197324
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197298
197325
|
}
|
|
197299
197326
|
}
|
|
197300
197327
|
}
|
|
@@ -197333,22 +197360,22 @@ var registerSnapshot = (program3) => {
|
|
|
197333
197360
|
};
|
|
197334
197361
|
|
|
197335
197362
|
// lib/shared/setup-github-actions.ts
|
|
197336
|
-
import
|
|
197337
|
-
import
|
|
197363
|
+
import fs42 from "node:fs";
|
|
197364
|
+
import path40 from "node:path";
|
|
197338
197365
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
197339
197366
|
const findGitRoot = (startDir) => {
|
|
197340
|
-
let dir =
|
|
197341
|
-
while (dir !==
|
|
197342
|
-
if (
|
|
197367
|
+
let dir = path40.resolve(startDir);
|
|
197368
|
+
while (dir !== path40.parse(dir).root) {
|
|
197369
|
+
if (fs42.existsSync(path40.join(dir, ".git"))) {
|
|
197343
197370
|
return dir;
|
|
197344
197371
|
}
|
|
197345
|
-
dir =
|
|
197372
|
+
dir = path40.dirname(dir);
|
|
197346
197373
|
}
|
|
197347
197374
|
return null;
|
|
197348
197375
|
};
|
|
197349
197376
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
197350
|
-
const workflowsDir =
|
|
197351
|
-
|
|
197377
|
+
const workflowsDir = path40.join(gitRoot, ".github", "workflows");
|
|
197378
|
+
fs42.mkdirSync(workflowsDir, { recursive: true });
|
|
197352
197379
|
const buildWorkflow = `name: tscircuit Build
|
|
197353
197380
|
|
|
197354
197381
|
on:
|
|
@@ -197387,8 +197414,8 @@ jobs:
|
|
|
197387
197414
|
- run: bun install
|
|
197388
197415
|
- run: bunx tsci snapshot
|
|
197389
197416
|
`;
|
|
197390
|
-
writeFileIfNotExists(
|
|
197391
|
-
writeFileIfNotExists(
|
|
197417
|
+
writeFileIfNotExists(path40.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
197418
|
+
writeFileIfNotExists(path40.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
197392
197419
|
};
|
|
197393
197420
|
|
|
197394
197421
|
// cli/setup/register.ts
|
|
@@ -197414,8 +197441,8 @@ var registerSetup = (program3) => {
|
|
|
197414
197441
|
};
|
|
197415
197442
|
|
|
197416
197443
|
// cli/convert/register.ts
|
|
197417
|
-
import
|
|
197418
|
-
import
|
|
197444
|
+
import fs43 from "node:fs/promises";
|
|
197445
|
+
import path41 from "node:path";
|
|
197419
197446
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
197420
197447
|
|
|
197421
197448
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -197535,15 +197562,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
197535
197562
|
var registerConvert = (program3) => {
|
|
197536
197563
|
program3.command("convert").description("Convert a .kicad_mod footprint to a tscircuit component").argument("<file>", "Path to the .kicad_mod file").option("-o, --output <path>", "Output TSX file path").option("-n, --name <component>", "Component name for export").action(async (file, options) => {
|
|
197537
197564
|
try {
|
|
197538
|
-
const inputPath =
|
|
197539
|
-
const modContent = await
|
|
197565
|
+
const inputPath = path41.resolve(file);
|
|
197566
|
+
const modContent = await fs43.readFile(inputPath, "utf-8");
|
|
197540
197567
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
197541
|
-
const componentName = options.name ??
|
|
197568
|
+
const componentName = options.name ?? path41.basename(inputPath, ".kicad_mod");
|
|
197542
197569
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
197543
197570
|
componentName
|
|
197544
197571
|
});
|
|
197545
|
-
const outputPath = options.output ?
|
|
197546
|
-
await
|
|
197572
|
+
const outputPath = options.output ? path41.resolve(options.output) : path41.join(path41.dirname(inputPath), `${componentName}.tsx`);
|
|
197573
|
+
await fs43.writeFile(outputPath, tsx);
|
|
197547
197574
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
197548
197575
|
} catch (error) {
|
|
197549
197576
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -197638,12 +197665,12 @@ var registerSimulate = (program3) => {
|
|
|
197638
197665
|
};
|
|
197639
197666
|
|
|
197640
197667
|
// lib/shared/install-project-dependencies.ts
|
|
197641
|
-
import
|
|
197642
|
-
import
|
|
197668
|
+
import fs45 from "node:fs";
|
|
197669
|
+
import path43 from "node:path";
|
|
197643
197670
|
|
|
197644
197671
|
// lib/shared/collect-tsci-dependencies.ts
|
|
197645
|
-
import
|
|
197646
|
-
import
|
|
197672
|
+
import fs44 from "node:fs";
|
|
197673
|
+
import path42 from "node:path";
|
|
197647
197674
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
197648
197675
|
var DEFAULT_IGNORES = [
|
|
197649
197676
|
"**/node_modules/**",
|
|
@@ -197658,7 +197685,7 @@ function collectTsciDependencies({
|
|
|
197658
197685
|
patterns = DEFAULT_PATTERNS,
|
|
197659
197686
|
ignore = DEFAULT_IGNORES
|
|
197660
197687
|
} = {}) {
|
|
197661
|
-
const searchRoot =
|
|
197688
|
+
const searchRoot = path42.resolve(cwd);
|
|
197662
197689
|
const files = globbySync(patterns, {
|
|
197663
197690
|
cwd: searchRoot,
|
|
197664
197691
|
absolute: true,
|
|
@@ -197668,7 +197695,7 @@ function collectTsciDependencies({
|
|
|
197668
197695
|
const dependencies2 = new Set;
|
|
197669
197696
|
for (const filePath of files) {
|
|
197670
197697
|
try {
|
|
197671
|
-
const fileContents =
|
|
197698
|
+
const fileContents = fs44.readFileSync(filePath, "utf-8");
|
|
197672
197699
|
let match;
|
|
197673
197700
|
while (true) {
|
|
197674
197701
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -197685,26 +197712,26 @@ function collectTsciDependencies({
|
|
|
197685
197712
|
async function installProjectDependencies({
|
|
197686
197713
|
cwd = process.cwd()
|
|
197687
197714
|
} = {}) {
|
|
197688
|
-
const projectRoot =
|
|
197689
|
-
const packageJsonPath =
|
|
197690
|
-
const npmrcPath =
|
|
197715
|
+
const projectRoot = path43.resolve(cwd);
|
|
197716
|
+
const packageJsonPath = path43.join(projectRoot, "package.json");
|
|
197717
|
+
const npmrcPath = path43.join(projectRoot, ".npmrc");
|
|
197691
197718
|
const packageManager = getPackageManager();
|
|
197692
|
-
if (!
|
|
197719
|
+
if (!fs45.existsSync(projectRoot)) {
|
|
197693
197720
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
197694
197721
|
}
|
|
197695
197722
|
let packageJsonCreated = false;
|
|
197696
|
-
if (!
|
|
197723
|
+
if (!fs45.existsSync(packageJsonPath)) {
|
|
197697
197724
|
console.log("No package.json found. Generating a new one.");
|
|
197698
197725
|
generatePackageJson(projectRoot);
|
|
197699
197726
|
packageJsonCreated = true;
|
|
197700
197727
|
} else {
|
|
197701
197728
|
console.log("Found existing package.json.");
|
|
197702
197729
|
}
|
|
197703
|
-
if (!
|
|
197730
|
+
if (!fs45.existsSync(npmrcPath)) {
|
|
197704
197731
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
197705
|
-
|
|
197732
|
+
fs45.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
197706
197733
|
}
|
|
197707
|
-
const packageJson = JSON.parse(
|
|
197734
|
+
const packageJson = JSON.parse(fs45.readFileSync(packageJsonPath, "utf-8"));
|
|
197708
197735
|
if (packageJsonCreated) {
|
|
197709
197736
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
197710
197737
|
if (tsciDependencies.length > 0) {
|
|
@@ -197719,7 +197746,7 @@ async function installProjectDependencies({
|
|
|
197719
197746
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
197720
197747
|
}
|
|
197721
197748
|
}
|
|
197722
|
-
|
|
197749
|
+
fs45.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
197723
197750
|
`);
|
|
197724
197751
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
197725
197752
|
try {
|
|
@@ -197749,26 +197776,15 @@ var registerInstall = (program3) => {
|
|
|
197749
197776
|
};
|
|
197750
197777
|
|
|
197751
197778
|
// cli/transpile/register.ts
|
|
197752
|
-
import
|
|
197753
|
-
import path43 from "node:path";
|
|
197779
|
+
import path44 from "node:path";
|
|
197754
197780
|
var registerTranspile = (program3) => {
|
|
197755
197781
|
program3.command("transpile").description("Transpile TypeScript/TSX to JavaScript (ESM, CommonJS, and type declarations)").argument("[file]", "Path to the entry file").action(async (file) => {
|
|
197756
197782
|
try {
|
|
197757
197783
|
const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
|
|
197758
197784
|
fileOrDir: file
|
|
197759
197785
|
});
|
|
197760
|
-
const distDir =
|
|
197761
|
-
|
|
197762
|
-
if (fs45.existsSync(packageJsonPath)) {
|
|
197763
|
-
const packageJson = JSON.parse(fs45.readFileSync(packageJsonPath, "utf-8"));
|
|
197764
|
-
if (typeof packageJson.main === "string") {
|
|
197765
|
-
const resolvedMainPath = path43.resolve(projectDir, packageJson.main);
|
|
197766
|
-
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path43.sep}`);
|
|
197767
|
-
if (!isMainInDist) {
|
|
197768
|
-
throw new Error('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
197769
|
-
}
|
|
197770
|
-
}
|
|
197771
|
-
}
|
|
197786
|
+
const distDir = path44.join(projectDir, "dist");
|
|
197787
|
+
validateMainInDist(projectDir, distDir);
|
|
197772
197788
|
console.log("Transpiling entry file...");
|
|
197773
197789
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197774
197790
|
if (!entryFile) {
|