@tscircuit/cli 0.1.838 → 0.1.840
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/build/build-worker-entrypoint.js +45 -8
- package/dist/main.js +346 -265
- package/package.json +2 -2
|
@@ -2454,8 +2454,8 @@ export default {
|
|
|
2454
2454
|
});
|
|
2455
2455
|
|
|
2456
2456
|
// cli/build/build-worker-entrypoint.ts
|
|
2457
|
-
import
|
|
2458
|
-
import
|
|
2457
|
+
import path5 from "node:path";
|
|
2458
|
+
import fs5 from "node:fs";
|
|
2459
2459
|
import { parentPort } from "node:worker_threads";
|
|
2460
2460
|
|
|
2461
2461
|
// lib/shared/generate-circuit-json.tsx
|
|
@@ -2611,6 +2611,8 @@ function analyzeCircuitJson(circuitJson) {
|
|
|
2611
2611
|
|
|
2612
2612
|
// lib/shared/get-complete-platform-config.ts
|
|
2613
2613
|
import { getPlatformConfig } from "@tscircuit/eval/platform-config";
|
|
2614
|
+
import path3 from "node:path";
|
|
2615
|
+
import fs3 from "node:fs";
|
|
2614
2616
|
function getCompletePlatformConfig(userConfig) {
|
|
2615
2617
|
const basePlatformConfig = getPlatformConfig();
|
|
2616
2618
|
const defaultConfig = {
|
|
@@ -2619,7 +2621,23 @@ function getCompletePlatformConfig(userConfig) {
|
|
|
2619
2621
|
...basePlatformConfig.footprintFileParserMap,
|
|
2620
2622
|
kicad_mod: {
|
|
2621
2623
|
loadFromUrl: async (url) => {
|
|
2622
|
-
|
|
2624
|
+
let fetchUrl = url;
|
|
2625
|
+
if (url.startsWith("./") || url.startsWith("../")) {
|
|
2626
|
+
const absolutePath = path3.resolve(process.cwd(), url);
|
|
2627
|
+
fetchUrl = `file://${absolutePath}`;
|
|
2628
|
+
} else if (url.startsWith("/")) {
|
|
2629
|
+
if (fs3.existsSync(url)) {
|
|
2630
|
+
fetchUrl = `file://${url}`;
|
|
2631
|
+
} else {
|
|
2632
|
+
const relativePath = `.${url}`;
|
|
2633
|
+
const absolutePath = path3.resolve(process.cwd(), relativePath);
|
|
2634
|
+
if (fs3.existsSync(absolutePath)) {
|
|
2635
|
+
fetchUrl = `file://${absolutePath}`;
|
|
2636
|
+
} else {
|
|
2637
|
+
fetchUrl = `file://${url}`;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2623
2641
|
return basePlatformConfig.footprintFileParserMap.kicad_mod.loadFromUrl(fetchUrl);
|
|
2624
2642
|
}
|
|
2625
2643
|
}
|
|
@@ -2639,6 +2657,8 @@ function getCompletePlatformConfig(userConfig) {
|
|
|
2639
2657
|
}
|
|
2640
2658
|
|
|
2641
2659
|
// lib/shared/register-static-asset-loaders.ts
|
|
2660
|
+
import fs4 from "node:fs";
|
|
2661
|
+
import path4 from "node:path";
|
|
2642
2662
|
var TEXT_STATIC_ASSET_EXTENSIONS = [
|
|
2643
2663
|
".gltf",
|
|
2644
2664
|
".step",
|
|
@@ -2649,17 +2669,34 @@ var TEXT_STATIC_ASSET_EXTENSIONS = [
|
|
|
2649
2669
|
];
|
|
2650
2670
|
var staticAssetFilter = new RegExp(`(${TEXT_STATIC_ASSET_EXTENSIONS.map((ext) => ext.replace(".", "\\.")).join("|")})$`, "i");
|
|
2651
2671
|
var registered = false;
|
|
2672
|
+
var getBaseUrlFromTsConfig = () => {
|
|
2673
|
+
const tsconfigPath = path4.join(process.cwd(), "tsconfig.json");
|
|
2674
|
+
try {
|
|
2675
|
+
if (!fs4.existsSync(tsconfigPath)) {
|
|
2676
|
+
return null;
|
|
2677
|
+
}
|
|
2678
|
+
const tsconfigContent = fs4.readFileSync(tsconfigPath, "utf-8");
|
|
2679
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
2680
|
+
if (tsconfig.compilerOptions?.baseUrl) {
|
|
2681
|
+
return tsconfig.compilerOptions.baseUrl;
|
|
2682
|
+
}
|
|
2683
|
+
} catch {}
|
|
2684
|
+
return null;
|
|
2685
|
+
};
|
|
2652
2686
|
var registerStaticAssetLoaders = () => {
|
|
2653
2687
|
if (registered)
|
|
2654
2688
|
return;
|
|
2655
2689
|
registered = true;
|
|
2656
2690
|
if (typeof Bun !== "undefined" && typeof Bun.plugin === "function") {
|
|
2691
|
+
const baseUrl = getBaseUrlFromTsConfig();
|
|
2657
2692
|
Bun.plugin({
|
|
2658
2693
|
name: "tsci-static-assets",
|
|
2659
2694
|
setup(build) {
|
|
2660
2695
|
build.onLoad({ filter: staticAssetFilter }, (args) => {
|
|
2696
|
+
const baseDir = baseUrl ? path4.resolve(process.cwd(), baseUrl) : process.cwd();
|
|
2697
|
+
const relativePath = path4.relative(baseDir, args.path).split(path4.sep).join("/");
|
|
2661
2698
|
return {
|
|
2662
|
-
contents: `export default ${JSON.stringify(
|
|
2699
|
+
contents: `export default ${JSON.stringify(`./${relativePath}`)};`,
|
|
2663
2700
|
loader: "js"
|
|
2664
2701
|
};
|
|
2665
2702
|
});
|
|
@@ -2688,16 +2725,16 @@ var handleBuildFile = async (filePath, outputPath, projectDir, options) => {
|
|
|
2688
2725
|
const warnings = [];
|
|
2689
2726
|
try {
|
|
2690
2727
|
process.chdir(projectDir);
|
|
2691
|
-
workerLog(`Generating circuit JSON for ${
|
|
2728
|
+
workerLog(`Generating circuit JSON for ${path5.relative(projectDir, filePath)}...`);
|
|
2692
2729
|
await registerStaticAssetLoaders();
|
|
2693
2730
|
const completePlatformConfig = getCompletePlatformConfig(options?.platformConfig);
|
|
2694
2731
|
const result = await generateCircuitJson({
|
|
2695
2732
|
filePath,
|
|
2696
2733
|
platformConfig: completePlatformConfig
|
|
2697
2734
|
});
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
workerLog(`Circuit JSON written to ${
|
|
2735
|
+
fs5.mkdirSync(path5.dirname(outputPath), { recursive: true });
|
|
2736
|
+
fs5.writeFileSync(outputPath, JSON.stringify(result.circuitJson, null, 2));
|
|
2737
|
+
workerLog(`Circuit JSON written to ${path5.relative(projectDir, outputPath)}`);
|
|
2701
2738
|
const diagnostics = analyzeCircuitJson(result.circuitJson);
|
|
2702
2739
|
if (!options?.ignoreWarnings) {
|
|
2703
2740
|
for (const warn of diagnostics.warnings) {
|