@tscircuit/cli 0.1.544 → 0.1.545
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 +92 -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.544";
|
|
72391
72391
|
var package_default = {
|
|
72392
72392
|
name: "@tscircuit/cli",
|
|
72393
72393
|
version,
|
|
@@ -196242,8 +196242,8 @@ var registerRemove = (program3) => {
|
|
|
196242
196242
|
};
|
|
196243
196243
|
|
|
196244
196244
|
// cli/build/register.ts
|
|
196245
|
-
import
|
|
196246
|
-
import
|
|
196245
|
+
import path38 from "node:path";
|
|
196246
|
+
import fs39 from "node:fs";
|
|
196247
196247
|
|
|
196248
196248
|
// cli/build/build-file.ts
|
|
196249
196249
|
import path30 from "node:path";
|
|
@@ -196976,6 +196976,23 @@ var transpileFile = async ({
|
|
|
196976
196976
|
}
|
|
196977
196977
|
};
|
|
196978
196978
|
|
|
196979
|
+
// cli/utils/validate-main-in-dist.ts
|
|
196980
|
+
import fs38 from "node:fs";
|
|
196981
|
+
import path37 from "node:path";
|
|
196982
|
+
var validateMainInDist = (projectDir, distDir) => {
|
|
196983
|
+
const packageJsonPath = path37.join(projectDir, "package.json");
|
|
196984
|
+
if (!fs38.existsSync(packageJsonPath))
|
|
196985
|
+
return;
|
|
196986
|
+
const packageJson = JSON.parse(fs38.readFileSync(packageJsonPath, "utf-8"));
|
|
196987
|
+
if (typeof packageJson.main !== "string")
|
|
196988
|
+
return;
|
|
196989
|
+
const resolvedMainPath = path37.resolve(projectDir, packageJson.main);
|
|
196990
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path37.sep}`);
|
|
196991
|
+
if (!isMainInDist) {
|
|
196992
|
+
throw new Error('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
196993
|
+
}
|
|
196994
|
+
};
|
|
196995
|
+
|
|
196979
196996
|
// cli/build/register.ts
|
|
196980
196997
|
var registerBuild = (program3) => {
|
|
196981
196998
|
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 +197012,8 @@ var registerBuild = (program3) => {
|
|
|
196995
197012
|
}
|
|
196996
197013
|
return config;
|
|
196997
197014
|
})();
|
|
196998
|
-
const distDir =
|
|
196999
|
-
|
|
197015
|
+
const distDir = path38.join(projectDir, "dist");
|
|
197016
|
+
fs39.mkdirSync(distDir, { recursive: true });
|
|
197000
197017
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
197001
197018
|
let hasErrors = false;
|
|
197002
197019
|
const staticFileReferences = [];
|
|
@@ -197004,10 +197021,10 @@ var registerBuild = (program3) => {
|
|
|
197004
197021
|
const kicadProjects = [];
|
|
197005
197022
|
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
197006
197023
|
for (const filePath of circuitFiles) {
|
|
197007
|
-
const relative9 =
|
|
197024
|
+
const relative9 = path38.relative(projectDir, filePath);
|
|
197008
197025
|
console.log(`Building ${relative9}...`);
|
|
197009
197026
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
197010
|
-
const outputPath =
|
|
197027
|
+
const outputPath = path38.join(distDir, outputDirName, "circuit.json");
|
|
197011
197028
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
197012
197029
|
ignoreErrors: options?.ignoreErrors,
|
|
197013
197030
|
ignoreWarnings: options?.ignoreWarnings,
|
|
@@ -197021,17 +197038,17 @@ var registerBuild = (program3) => {
|
|
|
197021
197038
|
if (!buildOutcome.ok) {
|
|
197022
197039
|
hasErrors = true;
|
|
197023
197040
|
} else if (options?.site) {
|
|
197024
|
-
const normalizedSourcePath = relative9.split(
|
|
197025
|
-
const relativeOutputPath =
|
|
197026
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
197041
|
+
const normalizedSourcePath = relative9.split(path38.sep).join("/");
|
|
197042
|
+
const relativeOutputPath = path38.join(outputDirName, "circuit.json");
|
|
197043
|
+
const normalizedOutputPath = relativeOutputPath.split(path38.sep).join("/");
|
|
197027
197044
|
staticFileReferences.push({
|
|
197028
197045
|
filePath: normalizedSourcePath,
|
|
197029
197046
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
197030
197047
|
});
|
|
197031
197048
|
}
|
|
197032
197049
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
197033
|
-
const projectOutputDir =
|
|
197034
|
-
const projectName =
|
|
197050
|
+
const projectOutputDir = path38.join(distDir, outputDirName, "kicad");
|
|
197051
|
+
const projectName = path38.basename(outputDirName);
|
|
197035
197052
|
const project = await generateKicadProject({
|
|
197036
197053
|
circuitJson: buildOutcome.circuitJson,
|
|
197037
197054
|
outputDir: projectOutputDir,
|
|
@@ -197058,6 +197075,7 @@ var registerBuild = (program3) => {
|
|
|
197058
197075
|
});
|
|
197059
197076
|
}
|
|
197060
197077
|
if (options?.transpile) {
|
|
197078
|
+
validateMainInDist(projectDir, distDir);
|
|
197061
197079
|
console.log("Transpiling entry file...");
|
|
197062
197080
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197063
197081
|
if (!entryFile) {
|
|
@@ -197079,8 +197097,8 @@ var registerBuild = (program3) => {
|
|
|
197079
197097
|
files: staticFileReferences,
|
|
197080
197098
|
standaloneScriptSrc: "./standalone.min.js"
|
|
197081
197099
|
});
|
|
197082
|
-
|
|
197083
|
-
|
|
197100
|
+
fs39.writeFileSync(path38.join(distDir, "index.html"), indexHtml);
|
|
197101
|
+
fs39.writeFileSync(path38.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
197084
197102
|
}
|
|
197085
197103
|
if (options?.kicadFootprintLibrary) {
|
|
197086
197104
|
if (kicadProjects.length === 0) {
|
|
@@ -197103,8 +197121,8 @@ var registerBuild = (program3) => {
|
|
|
197103
197121
|
};
|
|
197104
197122
|
|
|
197105
197123
|
// lib/shared/snapshot-project.ts
|
|
197106
|
-
import
|
|
197107
|
-
import
|
|
197124
|
+
import fs41 from "node:fs";
|
|
197125
|
+
import path39 from "node:path";
|
|
197108
197126
|
import looksSame2 from "looks-same";
|
|
197109
197127
|
import {
|
|
197110
197128
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -197115,7 +197133,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
197115
197133
|
|
|
197116
197134
|
// lib/shared/compare-images.ts
|
|
197117
197135
|
import looksSame from "looks-same";
|
|
197118
|
-
import
|
|
197136
|
+
import fs40 from "node:fs/promises";
|
|
197119
197137
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
197120
197138
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
197121
197139
|
strict: false,
|
|
@@ -197131,7 +197149,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
197131
197149
|
tolerance: 2
|
|
197132
197150
|
});
|
|
197133
197151
|
} else {
|
|
197134
|
-
await
|
|
197152
|
+
await fs40.writeFile(diffPath, buffer2);
|
|
197135
197153
|
}
|
|
197136
197154
|
}
|
|
197137
197155
|
return { equal: equal2 };
|
|
@@ -197156,7 +197174,7 @@ var snapshotProject = async ({
|
|
|
197156
197174
|
...DEFAULT_IGNORED_PATTERNS,
|
|
197157
197175
|
...ignored.map(normalizeIgnorePattern)
|
|
197158
197176
|
];
|
|
197159
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
197177
|
+
const resolvedPaths = filePaths.map((f) => path39.resolve(projectDir, f));
|
|
197160
197178
|
const boardFiles = findBoardFiles({
|
|
197161
197179
|
projectDir,
|
|
197162
197180
|
ignore,
|
|
@@ -197170,7 +197188,7 @@ var snapshotProject = async ({
|
|
|
197170
197188
|
const mismatches = [];
|
|
197171
197189
|
let didUpdate = false;
|
|
197172
197190
|
for (const file of boardFiles) {
|
|
197173
|
-
const relativeFilePath =
|
|
197191
|
+
const relativeFilePath = path39.relative(projectDir, file);
|
|
197174
197192
|
let circuitJson;
|
|
197175
197193
|
let pcbSvg;
|
|
197176
197194
|
let schSvg;
|
|
@@ -197224,17 +197242,17 @@ var snapshotProject = async ({
|
|
|
197224
197242
|
} catch (error) {
|
|
197225
197243
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197226
197244
|
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 =
|
|
197245
|
+
const fileDir = path39.dirname(file);
|
|
197246
|
+
const relativeDir = path39.relative(projectDir, fileDir);
|
|
197247
|
+
const snapDir2 = snapshotsDirName ? path39.join(projectDir, snapshotsDirName, relativeDir) : path39.join(fileDir, "__snapshots__");
|
|
197248
|
+
const base2 = path39.basename(file).replace(/\.tsx$/, "");
|
|
197249
|
+
const snap3dPath = path39.join(snapDir2, `${base2}-3d.snap.png`);
|
|
197250
|
+
const existing3dSnapshot = fs41.existsSync(snap3dPath);
|
|
197233
197251
|
if (existing3dSnapshot) {
|
|
197234
197252
|
onError(kleur_default.red(`
|
|
197235
197253
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
197236
197254
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
197237
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
197255
|
+
`) + kleur_default.red(` Existing snapshot: ${path39.relative(projectDir, snap3dPath)}
|
|
197238
197256
|
`));
|
|
197239
197257
|
return onExit(1);
|
|
197240
197258
|
} else {
|
|
@@ -197250,9 +197268,9 @@ var snapshotProject = async ({
|
|
|
197250
197268
|
}
|
|
197251
197269
|
}
|
|
197252
197270
|
}
|
|
197253
|
-
const snapDir = snapshotsDirName ?
|
|
197254
|
-
|
|
197255
|
-
const base =
|
|
197271
|
+
const snapDir = snapshotsDirName ? path39.join(projectDir, snapshotsDirName, path39.relative(projectDir, path39.dirname(file))) : path39.join(path39.dirname(file), "__snapshots__");
|
|
197272
|
+
fs41.mkdirSync(snapDir, { recursive: true });
|
|
197273
|
+
const base = path39.basename(file).replace(/\.tsx$/, "");
|
|
197256
197274
|
const snapshots = [];
|
|
197257
197275
|
if (pcbOnly || !schematicOnly) {
|
|
197258
197276
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -197270,31 +197288,31 @@ var snapshotProject = async ({
|
|
|
197270
197288
|
for (const snapshot of snapshots) {
|
|
197271
197289
|
const { type } = snapshot;
|
|
197272
197290
|
const is3d = type === "3d";
|
|
197273
|
-
const snapPath =
|
|
197274
|
-
const existing =
|
|
197291
|
+
const snapPath = path39.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
197292
|
+
const existing = fs41.existsSync(snapPath);
|
|
197275
197293
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
197276
197294
|
const newContentForFile = snapshot.content;
|
|
197277
197295
|
if (!existing) {
|
|
197278
|
-
|
|
197279
|
-
console.log("✅", kleur_default.gray(
|
|
197296
|
+
fs41.writeFileSync(snapPath, newContentForFile);
|
|
197297
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197280
197298
|
didUpdate = true;
|
|
197281
197299
|
continue;
|
|
197282
197300
|
}
|
|
197283
|
-
const oldContentBuffer =
|
|
197301
|
+
const oldContentBuffer = fs41.readFileSync(snapPath);
|
|
197284
197302
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
197285
197303
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
197286
197304
|
if (update) {
|
|
197287
197305
|
if (!forceUpdate && equal2) {
|
|
197288
|
-
console.log("✅", kleur_default.gray(
|
|
197306
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197289
197307
|
} else {
|
|
197290
|
-
|
|
197291
|
-
console.log("✅", kleur_default.gray(
|
|
197308
|
+
fs41.writeFileSync(snapPath, newContentForFile);
|
|
197309
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197292
197310
|
didUpdate = true;
|
|
197293
197311
|
}
|
|
197294
197312
|
} else if (!equal2) {
|
|
197295
197313
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
197296
197314
|
} else {
|
|
197297
|
-
console.log("✅", kleur_default.gray(
|
|
197315
|
+
console.log("✅", kleur_default.gray(path39.relative(projectDir, snapPath)));
|
|
197298
197316
|
}
|
|
197299
197317
|
}
|
|
197300
197318
|
}
|
|
@@ -197333,22 +197351,22 @@ var registerSnapshot = (program3) => {
|
|
|
197333
197351
|
};
|
|
197334
197352
|
|
|
197335
197353
|
// lib/shared/setup-github-actions.ts
|
|
197336
|
-
import
|
|
197337
|
-
import
|
|
197354
|
+
import fs42 from "node:fs";
|
|
197355
|
+
import path40 from "node:path";
|
|
197338
197356
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
197339
197357
|
const findGitRoot = (startDir) => {
|
|
197340
|
-
let dir =
|
|
197341
|
-
while (dir !==
|
|
197342
|
-
if (
|
|
197358
|
+
let dir = path40.resolve(startDir);
|
|
197359
|
+
while (dir !== path40.parse(dir).root) {
|
|
197360
|
+
if (fs42.existsSync(path40.join(dir, ".git"))) {
|
|
197343
197361
|
return dir;
|
|
197344
197362
|
}
|
|
197345
|
-
dir =
|
|
197363
|
+
dir = path40.dirname(dir);
|
|
197346
197364
|
}
|
|
197347
197365
|
return null;
|
|
197348
197366
|
};
|
|
197349
197367
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
197350
|
-
const workflowsDir =
|
|
197351
|
-
|
|
197368
|
+
const workflowsDir = path40.join(gitRoot, ".github", "workflows");
|
|
197369
|
+
fs42.mkdirSync(workflowsDir, { recursive: true });
|
|
197352
197370
|
const buildWorkflow = `name: tscircuit Build
|
|
197353
197371
|
|
|
197354
197372
|
on:
|
|
@@ -197387,8 +197405,8 @@ jobs:
|
|
|
197387
197405
|
- run: bun install
|
|
197388
197406
|
- run: bunx tsci snapshot
|
|
197389
197407
|
`;
|
|
197390
|
-
writeFileIfNotExists(
|
|
197391
|
-
writeFileIfNotExists(
|
|
197408
|
+
writeFileIfNotExists(path40.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
197409
|
+
writeFileIfNotExists(path40.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
197392
197410
|
};
|
|
197393
197411
|
|
|
197394
197412
|
// cli/setup/register.ts
|
|
@@ -197414,8 +197432,8 @@ var registerSetup = (program3) => {
|
|
|
197414
197432
|
};
|
|
197415
197433
|
|
|
197416
197434
|
// cli/convert/register.ts
|
|
197417
|
-
import
|
|
197418
|
-
import
|
|
197435
|
+
import fs43 from "node:fs/promises";
|
|
197436
|
+
import path41 from "node:path";
|
|
197419
197437
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
197420
197438
|
|
|
197421
197439
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -197535,15 +197553,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
197535
197553
|
var registerConvert = (program3) => {
|
|
197536
197554
|
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
197555
|
try {
|
|
197538
|
-
const inputPath =
|
|
197539
|
-
const modContent = await
|
|
197556
|
+
const inputPath = path41.resolve(file);
|
|
197557
|
+
const modContent = await fs43.readFile(inputPath, "utf-8");
|
|
197540
197558
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
197541
|
-
const componentName = options.name ??
|
|
197559
|
+
const componentName = options.name ?? path41.basename(inputPath, ".kicad_mod");
|
|
197542
197560
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
197543
197561
|
componentName
|
|
197544
197562
|
});
|
|
197545
|
-
const outputPath = options.output ?
|
|
197546
|
-
await
|
|
197563
|
+
const outputPath = options.output ? path41.resolve(options.output) : path41.join(path41.dirname(inputPath), `${componentName}.tsx`);
|
|
197564
|
+
await fs43.writeFile(outputPath, tsx);
|
|
197547
197565
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
197548
197566
|
} catch (error) {
|
|
197549
197567
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -197638,12 +197656,12 @@ var registerSimulate = (program3) => {
|
|
|
197638
197656
|
};
|
|
197639
197657
|
|
|
197640
197658
|
// lib/shared/install-project-dependencies.ts
|
|
197641
|
-
import
|
|
197642
|
-
import
|
|
197659
|
+
import fs45 from "node:fs";
|
|
197660
|
+
import path43 from "node:path";
|
|
197643
197661
|
|
|
197644
197662
|
// lib/shared/collect-tsci-dependencies.ts
|
|
197645
|
-
import
|
|
197646
|
-
import
|
|
197663
|
+
import fs44 from "node:fs";
|
|
197664
|
+
import path42 from "node:path";
|
|
197647
197665
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
197648
197666
|
var DEFAULT_IGNORES = [
|
|
197649
197667
|
"**/node_modules/**",
|
|
@@ -197658,7 +197676,7 @@ function collectTsciDependencies({
|
|
|
197658
197676
|
patterns = DEFAULT_PATTERNS,
|
|
197659
197677
|
ignore = DEFAULT_IGNORES
|
|
197660
197678
|
} = {}) {
|
|
197661
|
-
const searchRoot =
|
|
197679
|
+
const searchRoot = path42.resolve(cwd);
|
|
197662
197680
|
const files = globbySync(patterns, {
|
|
197663
197681
|
cwd: searchRoot,
|
|
197664
197682
|
absolute: true,
|
|
@@ -197668,7 +197686,7 @@ function collectTsciDependencies({
|
|
|
197668
197686
|
const dependencies2 = new Set;
|
|
197669
197687
|
for (const filePath of files) {
|
|
197670
197688
|
try {
|
|
197671
|
-
const fileContents =
|
|
197689
|
+
const fileContents = fs44.readFileSync(filePath, "utf-8");
|
|
197672
197690
|
let match;
|
|
197673
197691
|
while (true) {
|
|
197674
197692
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -197685,26 +197703,26 @@ function collectTsciDependencies({
|
|
|
197685
197703
|
async function installProjectDependencies({
|
|
197686
197704
|
cwd = process.cwd()
|
|
197687
197705
|
} = {}) {
|
|
197688
|
-
const projectRoot =
|
|
197689
|
-
const packageJsonPath =
|
|
197690
|
-
const npmrcPath =
|
|
197706
|
+
const projectRoot = path43.resolve(cwd);
|
|
197707
|
+
const packageJsonPath = path43.join(projectRoot, "package.json");
|
|
197708
|
+
const npmrcPath = path43.join(projectRoot, ".npmrc");
|
|
197691
197709
|
const packageManager = getPackageManager();
|
|
197692
|
-
if (!
|
|
197710
|
+
if (!fs45.existsSync(projectRoot)) {
|
|
197693
197711
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
197694
197712
|
}
|
|
197695
197713
|
let packageJsonCreated = false;
|
|
197696
|
-
if (!
|
|
197714
|
+
if (!fs45.existsSync(packageJsonPath)) {
|
|
197697
197715
|
console.log("No package.json found. Generating a new one.");
|
|
197698
197716
|
generatePackageJson(projectRoot);
|
|
197699
197717
|
packageJsonCreated = true;
|
|
197700
197718
|
} else {
|
|
197701
197719
|
console.log("Found existing package.json.");
|
|
197702
197720
|
}
|
|
197703
|
-
if (!
|
|
197721
|
+
if (!fs45.existsSync(npmrcPath)) {
|
|
197704
197722
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
197705
|
-
|
|
197723
|
+
fs45.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
197706
197724
|
}
|
|
197707
|
-
const packageJson = JSON.parse(
|
|
197725
|
+
const packageJson = JSON.parse(fs45.readFileSync(packageJsonPath, "utf-8"));
|
|
197708
197726
|
if (packageJsonCreated) {
|
|
197709
197727
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
197710
197728
|
if (tsciDependencies.length > 0) {
|
|
@@ -197719,7 +197737,7 @@ async function installProjectDependencies({
|
|
|
197719
197737
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
197720
197738
|
}
|
|
197721
197739
|
}
|
|
197722
|
-
|
|
197740
|
+
fs45.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
197723
197741
|
`);
|
|
197724
197742
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
197725
197743
|
try {
|
|
@@ -197749,26 +197767,15 @@ var registerInstall = (program3) => {
|
|
|
197749
197767
|
};
|
|
197750
197768
|
|
|
197751
197769
|
// cli/transpile/register.ts
|
|
197752
|
-
import
|
|
197753
|
-
import path43 from "node:path";
|
|
197770
|
+
import path44 from "node:path";
|
|
197754
197771
|
var registerTranspile = (program3) => {
|
|
197755
197772
|
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
197773
|
try {
|
|
197757
197774
|
const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
|
|
197758
197775
|
fileOrDir: file
|
|
197759
197776
|
});
|
|
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
|
-
}
|
|
197777
|
+
const distDir = path44.join(projectDir, "dist");
|
|
197778
|
+
validateMainInDist(projectDir, distDir);
|
|
197772
197779
|
console.log("Transpiling entry file...");
|
|
197773
197780
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197774
197781
|
if (!entryFile) {
|