@tscircuit/cli 0.1.547 → 0.1.548

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 +46 -20
  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.546";
72390
+ var version = "0.1.547";
72391
72391
  var package_default = {
72392
72392
  name: "@tscircuit/cli",
72393
72393
  version,
@@ -196759,6 +196759,7 @@ var createStaticAssetPlugin = ({
196759
196759
  const copiedAssets = new Map;
196760
196760
  const resolvedBaseUrl = baseUrl ?? projectDir;
196761
196761
  const resolvedPathMappings = pathMappings ?? {};
196762
+ const assetIdToOutputPath = new Map;
196762
196763
  return {
196763
196764
  name: "tsci-static-assets",
196764
196765
  resolveId(source, importer) {
@@ -196766,17 +196767,17 @@ var createStaticAssetPlugin = ({
196766
196767
  if (!STATIC_ASSET_EXTENSIONS.has(ext))
196767
196768
  return null;
196768
196769
  if (path35.isAbsolute(source)) {
196769
- return fs36.existsSync(source) ? source : null;
196770
+ return fs36.existsSync(source) ? { id: source, external: true } : null;
196770
196771
  }
196771
196772
  if (importer) {
196772
196773
  const resolvedFromImporter = path35.resolve(path35.dirname(importer), source);
196773
196774
  if (fs36.existsSync(resolvedFromImporter)) {
196774
- return resolvedFromImporter;
196775
+ return { id: resolvedFromImporter, external: true };
196775
196776
  }
196776
196777
  }
196777
196778
  const resolvedFromProject = path35.resolve(resolvedBaseUrl, source);
196778
196779
  if (fs36.existsSync(resolvedFromProject)) {
196779
- return resolvedFromProject;
196780
+ return { id: resolvedFromProject, external: true };
196780
196781
  }
196781
196782
  for (const [pattern, targets] of Object.entries(resolvedPathMappings)) {
196782
196783
  const isWildcard = pattern.endsWith("/*");
@@ -196787,32 +196788,57 @@ var createStaticAssetPlugin = ({
196787
196788
  const targetPath = isWildcard ? target.replace("*", wildcard) : target;
196788
196789
  const resolvedTarget = path35.resolve(resolvedBaseUrl, targetPath);
196789
196790
  if (fs36.existsSync(resolvedTarget)) {
196790
- return resolvedTarget;
196791
+ return { id: resolvedTarget, external: true };
196791
196792
  }
196792
196793
  }
196793
196794
  }
196794
196795
  }
196795
196796
  return null;
196796
196797
  },
196797
- load(id2) {
196798
- const ext = path35.extname(id2).toLowerCase();
196799
- if (!STATIC_ASSET_EXTENSIONS.has(ext))
196800
- return null;
196801
- const assetDir = path35.join(outputDir, "assets");
196802
- fs36.mkdirSync(assetDir, { recursive: true });
196803
- const fileBuffer = fs36.readFileSync(id2);
196804
- const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
196805
- const fileName = `${path35.basename(id2, ext)}-${hash}${ext}`;
196806
- const outputPath = path35.join(assetDir, fileName);
196807
- if (!copiedAssets.has(id2)) {
196808
- fs36.writeFileSync(outputPath, fileBuffer);
196809
- copiedAssets.set(id2, outputPath);
196798
+ buildStart() {
196799
+ assetIdToOutputPath.clear();
196800
+ },
196801
+ renderChunk(code) {
196802
+ let modifiedCode = code;
196803
+ for (const [assetId, outputPath] of assetIdToOutputPath) {
196804
+ modifiedCode = modifiedCode.replace(new RegExp(escapeRegExp(assetId), "g"), outputPath);
196805
+ }
196806
+ return { code: modifiedCode, map: null };
196807
+ },
196808
+ generateBundle(_options, bundle) {
196809
+ for (const chunk of Object.values(bundle)) {
196810
+ if (chunk.type !== "chunk")
196811
+ continue;
196812
+ for (const importedId of chunk.imports) {
196813
+ const ext = path35.extname(importedId).toLowerCase();
196814
+ if (!STATIC_ASSET_EXTENSIONS.has(ext))
196815
+ continue;
196816
+ if (!copiedAssets.has(importedId)) {
196817
+ const assetDir = path35.join(outputDir, "assets");
196818
+ fs36.mkdirSync(assetDir, { recursive: true });
196819
+ const fileBuffer = fs36.readFileSync(importedId);
196820
+ const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
196821
+ const fileName = `${path35.basename(importedId, ext)}-${hash}${ext}`;
196822
+ const outputFilePath = path35.join(assetDir, fileName);
196823
+ fs36.writeFileSync(outputFilePath, fileBuffer);
196824
+ copiedAssets.set(importedId, `./assets/${fileName}`);
196825
+ assetIdToOutputPath.set(importedId, `./assets/${fileName}`);
196826
+ }
196827
+ }
196828
+ if (chunk.code) {
196829
+ let modifiedCode = chunk.code;
196830
+ for (const [assetId, relativePath] of copiedAssets) {
196831
+ modifiedCode = modifiedCode.replace(new RegExp(escapeRegExp(assetId), "g"), relativePath);
196832
+ }
196833
+ chunk.code = modifiedCode;
196834
+ }
196810
196835
  }
196811
- const relativePath = `./assets/${fileName}`;
196812
- return `export default ${JSON.stringify(relativePath)};`;
196813
196836
  }
196814
196837
  };
196815
196838
  };
196839
+ function escapeRegExp(string) {
196840
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
196841
+ }
196816
196842
 
196817
196843
  // cli/build/transpile/index.ts
196818
196844
  var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.547",
3
+ "version": "0.1.548",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",