@sidecar-ai/compiler 0.1.0-alpha.8 → 0.1.0-alpha.9

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/index.js CHANGED
@@ -721,6 +721,7 @@ function warnRuntimeSchemaFallback(sourcePath, error) {
721
721
  import { createHash } from "crypto";
722
722
  import { existsSync as existsSync3 } from "fs";
723
723
  import { mkdir, readFile, writeFile } from "fs/promises";
724
+ import { createRequire } from "module";
724
725
  import path4 from "path";
725
726
  import { pathToFileURL as pathToFileURL2 } from "url";
726
727
  import { build as esbuild } from "esbuild";
@@ -730,6 +731,7 @@ import {
730
731
  SyntaxKind
731
732
  } from "ts-morph";
732
733
  var CLAUDE_FONT_RESOURCE_DOMAIN = "https://assets.claude.ai";
734
+ var requireFromCompiler = createRequire(import.meta.url);
733
735
  async function buildWidgets(rootDir, outDir, tools, config = void 0) {
734
736
  const widgets = tools.filter(
735
737
  (entry) => Boolean(entry.widget)
@@ -762,7 +764,7 @@ createRoot(document.getElementById("root")!).render(
762
764
  );
763
765
  const baseOptions = enforceWidgetBuildInvariants({
764
766
  absWorkingDir: rootDir,
765
- alias: devSidecarBundleAliases(rootDir),
767
+ alias: sidecarWidgetAliases(rootDir),
766
768
  bundle: true,
767
769
  entryPoints: [entryFile],
768
770
  format: "iife",
@@ -893,9 +895,11 @@ function mergeWidgetBuildOptions(...options) {
893
895
  return merged;
894
896
  }
895
897
  function enforceWidgetBuildInvariants(options, required) {
898
+ const aliases = required ? { ...options.alias ?? {}, ...reactSingletonAliases(required.rootDir) } : options.alias;
896
899
  return {
897
900
  ...options,
898
901
  absWorkingDir: required?.rootDir ?? options.absWorkingDir,
902
+ alias: aliases,
899
903
  bundle: true,
900
904
  entryPoints: required ? [required.entryFile] : options.entryPoints,
901
905
  format: "iife",
@@ -904,6 +908,27 @@ function enforceWidgetBuildInvariants(options, required) {
904
908
  write: false
905
909
  };
906
910
  }
911
+ function sidecarWidgetAliases(rootDir) {
912
+ return {
913
+ ...devSidecarBundleAliases(rootDir) ?? {},
914
+ ...reactSingletonAliases(rootDir)
915
+ };
916
+ }
917
+ function reactSingletonAliases(rootDir) {
918
+ return {
919
+ react: resolveProjectModule(rootDir, "react"),
920
+ "react/jsx-runtime": resolveProjectModule(rootDir, "react/jsx-runtime"),
921
+ "react/jsx-dev-runtime": resolveProjectModule(rootDir, "react/jsx-dev-runtime"),
922
+ "react-dom": resolveProjectModule(rootDir, "react-dom"),
923
+ "react-dom/client": resolveProjectModule(rootDir, "react-dom/client"),
924
+ "react-dom/server": resolveProjectModule(rootDir, "react-dom/server")
925
+ };
926
+ }
927
+ function resolveProjectModule(rootDir, specifier) {
928
+ return requireFromCompiler.resolve(specifier, {
929
+ paths: [rootDir, process.cwd()]
930
+ });
931
+ }
907
932
  function normalizeAliases(rootDir, aliases) {
908
933
  if (!aliases) {
909
934
  return void 0;