@tscircuit/cli 0.1.529 → 0.1.530

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 +85 -28
  2. 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.528";
72390
+ var version = "0.1.529";
72391
72391
  var package_default = {
72392
72392
  name: "@tscircuit/cli",
72393
72393
  version,
@@ -196728,11 +196728,31 @@ var STATIC_ASSET_EXTENSIONS = new Set([
196728
196728
  ".kicad_sch"
196729
196729
  ]);
196730
196730
  var createStaticAssetPlugin = ({
196731
- outputDir
196731
+ outputDir,
196732
+ projectDir
196732
196733
  }) => {
196733
196734
  const copiedAssets = new Map;
196734
196735
  return {
196735
196736
  name: "tsci-static-assets",
196737
+ resolveId(source, importer) {
196738
+ const ext = path35.extname(source).toLowerCase();
196739
+ if (!STATIC_ASSET_EXTENSIONS.has(ext))
196740
+ return null;
196741
+ if (path35.isAbsolute(source)) {
196742
+ return fs36.existsSync(source) ? source : null;
196743
+ }
196744
+ if (importer) {
196745
+ const resolvedFromImporter = path35.resolve(path35.dirname(importer), source);
196746
+ if (fs36.existsSync(resolvedFromImporter)) {
196747
+ return resolvedFromImporter;
196748
+ }
196749
+ }
196750
+ const resolvedFromProject = path35.resolve(projectDir, source);
196751
+ if (fs36.existsSync(resolvedFromProject)) {
196752
+ return resolvedFromProject;
196753
+ }
196754
+ return null;
196755
+ },
196736
196756
  load(id2) {
196737
196757
  const ext = path35.extname(id2).toLowerCase();
196738
196758
  if (!STATIC_ASSET_EXTENSIONS.has(ext))
@@ -196754,13 +196774,42 @@ var createStaticAssetPlugin = ({
196754
196774
  };
196755
196775
 
196756
196776
  // cli/build/transpile/index.ts
196757
- var __dirname = "/home/runner/work/cli/cli/cli/build/transpile";
196758
- var CLI_TYPES_ROOT = path36.resolve(__dirname, "../../../types");
196759
- var externalFunction = (id2) => {
196760
- if (id2.startsWith(".") || id2.startsWith("/")) {
196777
+ var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
196778
+ if (id2.startsWith(".") || id2.startsWith("/") || path36.isAbsolute(id2)) {
196761
196779
  return false;
196762
196780
  }
196763
- if (path36.isAbsolute(id2)) {
196781
+ let baseUrl = projectDir;
196782
+ let pathMappings = {};
196783
+ if (tsconfigPath && fs37.existsSync(tsconfigPath)) {
196784
+ try {
196785
+ const tsconfigContent = fs37.readFileSync(tsconfigPath, "utf-8");
196786
+ const tsconfig = JSON.parse(tsconfigContent);
196787
+ if (tsconfig.compilerOptions?.baseUrl) {
196788
+ baseUrl = path36.resolve(path36.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
196789
+ }
196790
+ if (tsconfig.compilerOptions?.paths) {
196791
+ pathMappings = tsconfig.compilerOptions.paths;
196792
+ }
196793
+ } catch {}
196794
+ }
196795
+ for (const [pattern, targets] of Object.entries(pathMappings)) {
196796
+ const patternWithoutWildcard = pattern.replace("/*", "/");
196797
+ if (id2.startsWith(patternWithoutWildcard)) {
196798
+ return false;
196799
+ }
196800
+ }
196801
+ const potentialPaths = [
196802
+ path36.join(baseUrl, id2),
196803
+ path36.join(baseUrl, `${id2}.ts`),
196804
+ path36.join(baseUrl, `${id2}.tsx`),
196805
+ path36.join(baseUrl, `${id2}.js`),
196806
+ path36.join(baseUrl, `${id2}.jsx`),
196807
+ path36.join(baseUrl, id2, "index.ts"),
196808
+ path36.join(baseUrl, id2, "index.tsx"),
196809
+ path36.join(baseUrl, id2, "index.js"),
196810
+ path36.join(baseUrl, id2, "index.jsx")
196811
+ ];
196812
+ if (potentialPaths.some((p) => fs37.existsSync(p))) {
196764
196813
  return false;
196765
196814
  }
196766
196815
  return true;
@@ -196772,16 +196821,12 @@ var transpileFile = async ({
196772
196821
  }) => {
196773
196822
  try {
196774
196823
  fs37.mkdirSync(outputDir, { recursive: true });
196775
- const typeRootCandidates = [
196776
- path36.join(projectDir, "node_modules", "@types"),
196777
- path36.join(projectDir, "types"),
196778
- CLI_TYPES_ROOT
196779
- ];
196780
- const typeRoots = Array.from(new Set(typeRootCandidates.filter((candidate) => fs37.existsSync(candidate))));
196824
+ const tsconfigPath = path36.join(projectDir, "tsconfig.json");
196825
+ const hasTsConfig = fs37.existsSync(tsconfigPath);
196781
196826
  console.log("Building ESM bundle...");
196782
196827
  const staticAssetExtensions = Array.from(STATIC_ASSET_EXTENSIONS);
196783
- const getPlugins = (moduleKind) => [
196784
- createStaticAssetPlugin({ outputDir }),
196828
+ const getPlugins = () => [
196829
+ createStaticAssetPlugin({ outputDir, projectDir }),
196785
196830
  resolve12({
196786
196831
  extensions: [
196787
196832
  ".ts",
@@ -196795,26 +196840,31 @@ var transpileFile = async ({
196795
196840
  commonjs(),
196796
196841
  json(),
196797
196842
  typescript({
196798
- jsx: "react",
196799
- tsconfig: false,
196800
- compilerOptions: {
196843
+ tsconfig: hasTsConfig ? tsconfigPath : false,
196844
+ compilerOptions: hasTsConfig ? {
196845
+ declaration: false,
196846
+ sourceMap: false,
196847
+ noEmit: false,
196848
+ emitDeclarationOnly: false,
196849
+ allowImportingTsExtensions: false
196850
+ } : {
196801
196851
  target: "ES2020",
196802
- module: moduleKind,
196803
- jsx: "react",
196852
+ module: "ESNext",
196853
+ jsx: "react-jsx",
196804
196854
  declaration: false,
196805
196855
  sourceMap: false,
196806
196856
  skipLibCheck: true,
196807
196857
  resolveJsonModule: true,
196808
196858
  allowSyntheticDefaultImports: true,
196809
196859
  allowArbitraryExtensions: true,
196810
- ...typeRoots.length ? { typeRoots } : {}
196860
+ baseUrl: projectDir
196811
196861
  }
196812
196862
  })
196813
196863
  ];
196814
196864
  const esmBundle = await rollup({
196815
196865
  input,
196816
- external: externalFunction,
196817
- plugins: getPlugins("ESNext")
196866
+ external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
196867
+ plugins: getPlugins()
196818
196868
  });
196819
196869
  const esmOutputPath = path36.join(outputDir, "index.js");
196820
196870
  await esmBundle.write({
@@ -196826,11 +196876,11 @@ var transpileFile = async ({
196826
196876
  console.log("Building CommonJS bundle...");
196827
196877
  const cjsBundle = await rollup({
196828
196878
  input,
196829
- external: externalFunction,
196830
- plugins: getPlugins("CommonJS")
196879
+ external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
196880
+ plugins: getPlugins()
196831
196881
  });
196832
196882
  const cjsOutputPath = path36.join(outputDir, "index.cjs");
196833
- console.log("[DEBUG] Writing CJS bundle to:", cjsOutputPath);
196883
+ console.log("Writing CJS bundle to:", cjsOutputPath);
196834
196884
  await cjsBundle.write({
196835
196885
  file: cjsOutputPath,
196836
196886
  format: "cjs",
@@ -196840,10 +196890,17 @@ var transpileFile = async ({
196840
196890
  console.log("Generating type declarations...");
196841
196891
  const dtsBundle = await rollup({
196842
196892
  input,
196843
- external: externalFunction,
196893
+ external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
196844
196894
  plugins: [
196895
+ resolve12({
196896
+ extensions: [".ts", ".tsx", ".d.ts"]
196897
+ }),
196845
196898
  dts({
196846
- respectExternal: true
196899
+ respectExternal: true,
196900
+ tsconfig: hasTsConfig ? tsconfigPath : undefined,
196901
+ compilerOptions: hasTsConfig ? undefined : {
196902
+ baseUrl: projectDir
196903
+ }
196847
196904
  })
196848
196905
  ]
196849
196906
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.529",
3
+ "version": "0.1.530",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",