@aprovan/patchwork-compiler 0.1.2-dev.03aaf5b → 0.1.2-dev.1a732c5

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.d.cts CHANGED
@@ -136,6 +136,12 @@ interface CompilerOptions {
136
136
  cdnBaseUrl?: string;
137
137
  /** Base URL for widget imports (default: same as cdnBaseUrl). Used for transforming imports in widget code. */
138
138
  widgetCdnBaseUrl?: string;
139
+ /**
140
+ * URL overrides for bundled assets/packages.
141
+ * Keys are asset identifiers (e.g., 'esbuild-wasm/esbuild.wasm'), values are local URLs.
142
+ * Use this to bundle assets locally for offline support or improved performance.
143
+ */
144
+ urlOverrides?: Record<string, string>;
139
145
  }
140
146
  interface Compiler {
141
147
  /** Pre-load an image package */
@@ -679,6 +685,7 @@ declare class VFSStore {
679
685
  listFiles(prefix?: string): Promise<string[]>;
680
686
  loadProject(id: string): Promise<VirtualProject | null>;
681
687
  saveProject(project: VirtualProject): Promise<void>;
688
+ watch(path: string, callback: WatchCallback): () => void;
682
689
  sync(): Promise<SyncResult>;
683
690
  on<T extends SyncEventType>(event: T, callback: SyncEventCallback<T extends "change" ? ChangeRecord : T extends "conflict" ? ConflictRecord : T extends "error" ? Error : SyncStatus>): () => void;
684
691
  private remotePath;
@@ -825,4 +832,4 @@ declare function createIframeServiceProxy(): ServiceProxy;
825
832
  */
826
833
  declare function generateIframeBridgeScript(services: string[]): string;
827
834
 
828
- export { type BridgeMessage, type BridgeMessageType, type CdnTransformOptions, type ChangeRecord, type CompileOptions, CompileOptionsSchema, type CompiledWidget, type Compiler, type CompilerOptions, DEFAULT_CLI_IMAGE_CONFIG, DEFAULT_IMAGE_CONFIG, DEV_SANDBOX, EsbuildConfigSchema, type GlobalInterfaceDefinition, HttpBackend, type HttpBackendConfig, type ImageConfig$1 as ImageConfig, ImageConfigSchema, type ImageMountFn, ImageRegistry, IndexedDBBackend, type InputSpec, InputSpecSchema, type LoadedImage, type Manifest$1 as Manifest, ManifestSchema, type MountMode, MountModeSchema, type MountOptions, MountOptionsSchema, type MountedWidget, ParentBridge, type Platform, PlatformSchema, type ServiceCallHandler, type ServiceCallPayload, type ServiceProxy, type ServiceResultPayload, type VFSPluginOptions, VFSStore, type VFSStoreOptions, type VirtualFile, type VirtualProject, cdnTransformPlugin, createCompiler, createFieldAccessProxy, createHttpServiceProxy, createIframeServiceProxy, createImageRegistry, createProjectFromFiles, createSingleFileProject, detectMainFile, disposeIframeBridge, extractNamespaces, fetchPackageJson, generateIframeBridgeScript, generateImportMap, generateNamespaceGlobals, getCdnBaseUrl, getImageRegistry, injectNamespaceGlobals, loadImage, mountEmbedded, mountIframe, parseImageConfig, parseImageSpec, parseManifest, reloadEmbedded, reloadIframe, removeNamespaceGlobals, resolveEntry, safeParseImageConfig, safeParseManifest, setCdnBaseUrl, vfsPlugin };
835
+ export { type BridgeMessage, type BridgeMessageType, type CdnTransformOptions, type ChangeRecord, type CompileOptions, CompileOptionsSchema, type CompiledWidget, type Compiler, type CompilerOptions, DEFAULT_CLI_IMAGE_CONFIG, DEFAULT_IMAGE_CONFIG, DEV_SANDBOX, EsbuildConfigSchema, type GlobalInterfaceDefinition, HttpBackend, type HttpBackendConfig, type ImageConfig$1 as ImageConfig, ImageConfigSchema, type ImageMountFn, ImageRegistry, IndexedDBBackend, type InputSpec, InputSpecSchema, type LoadedImage, type Manifest$1 as Manifest, ManifestSchema, type MountMode, MountModeSchema, type MountOptions, MountOptionsSchema, type MountedWidget, ParentBridge, type Platform, PlatformSchema, type ServiceCallHandler, type ServiceCallPayload, type ServiceProxy, type ServiceResultPayload, type VFSPluginOptions, VFSStore, type VFSStoreOptions, type VirtualFile, type VirtualProject, type WatchCallback, type WatchEventType, cdnTransformPlugin, createCompiler, createFieldAccessProxy, createHttpServiceProxy, createIframeServiceProxy, createImageRegistry, createProjectFromFiles, createSingleFileProject, detectMainFile, disposeIframeBridge, extractNamespaces, fetchPackageJson, generateIframeBridgeScript, generateImportMap, generateNamespaceGlobals, getCdnBaseUrl, getImageRegistry, injectNamespaceGlobals, loadImage, mountEmbedded, mountIframe, parseImageConfig, parseImageSpec, parseManifest, reloadEmbedded, reloadIframe, removeNamespaceGlobals, resolveEntry, safeParseImageConfig, safeParseManifest, setCdnBaseUrl, vfsPlugin };
package/dist/index.d.ts CHANGED
@@ -136,6 +136,12 @@ interface CompilerOptions {
136
136
  cdnBaseUrl?: string;
137
137
  /** Base URL for widget imports (default: same as cdnBaseUrl). Used for transforming imports in widget code. */
138
138
  widgetCdnBaseUrl?: string;
139
+ /**
140
+ * URL overrides for bundled assets/packages.
141
+ * Keys are asset identifiers (e.g., 'esbuild-wasm/esbuild.wasm'), values are local URLs.
142
+ * Use this to bundle assets locally for offline support or improved performance.
143
+ */
144
+ urlOverrides?: Record<string, string>;
139
145
  }
140
146
  interface Compiler {
141
147
  /** Pre-load an image package */
@@ -679,6 +685,7 @@ declare class VFSStore {
679
685
  listFiles(prefix?: string): Promise<string[]>;
680
686
  loadProject(id: string): Promise<VirtualProject | null>;
681
687
  saveProject(project: VirtualProject): Promise<void>;
688
+ watch(path: string, callback: WatchCallback): () => void;
682
689
  sync(): Promise<SyncResult>;
683
690
  on<T extends SyncEventType>(event: T, callback: SyncEventCallback<T extends "change" ? ChangeRecord : T extends "conflict" ? ConflictRecord : T extends "error" ? Error : SyncStatus>): () => void;
684
691
  private remotePath;
@@ -825,4 +832,4 @@ declare function createIframeServiceProxy(): ServiceProxy;
825
832
  */
826
833
  declare function generateIframeBridgeScript(services: string[]): string;
827
834
 
828
- export { type BridgeMessage, type BridgeMessageType, type CdnTransformOptions, type ChangeRecord, type CompileOptions, CompileOptionsSchema, type CompiledWidget, type Compiler, type CompilerOptions, DEFAULT_CLI_IMAGE_CONFIG, DEFAULT_IMAGE_CONFIG, DEV_SANDBOX, EsbuildConfigSchema, type GlobalInterfaceDefinition, HttpBackend, type HttpBackendConfig, type ImageConfig$1 as ImageConfig, ImageConfigSchema, type ImageMountFn, ImageRegistry, IndexedDBBackend, type InputSpec, InputSpecSchema, type LoadedImage, type Manifest$1 as Manifest, ManifestSchema, type MountMode, MountModeSchema, type MountOptions, MountOptionsSchema, type MountedWidget, ParentBridge, type Platform, PlatformSchema, type ServiceCallHandler, type ServiceCallPayload, type ServiceProxy, type ServiceResultPayload, type VFSPluginOptions, VFSStore, type VFSStoreOptions, type VirtualFile, type VirtualProject, cdnTransformPlugin, createCompiler, createFieldAccessProxy, createHttpServiceProxy, createIframeServiceProxy, createImageRegistry, createProjectFromFiles, createSingleFileProject, detectMainFile, disposeIframeBridge, extractNamespaces, fetchPackageJson, generateIframeBridgeScript, generateImportMap, generateNamespaceGlobals, getCdnBaseUrl, getImageRegistry, injectNamespaceGlobals, loadImage, mountEmbedded, mountIframe, parseImageConfig, parseImageSpec, parseManifest, reloadEmbedded, reloadIframe, removeNamespaceGlobals, resolveEntry, safeParseImageConfig, safeParseManifest, setCdnBaseUrl, vfsPlugin };
835
+ export { type BridgeMessage, type BridgeMessageType, type CdnTransformOptions, type ChangeRecord, type CompileOptions, CompileOptionsSchema, type CompiledWidget, type Compiler, type CompilerOptions, DEFAULT_CLI_IMAGE_CONFIG, DEFAULT_IMAGE_CONFIG, DEV_SANDBOX, EsbuildConfigSchema, type GlobalInterfaceDefinition, HttpBackend, type HttpBackendConfig, type ImageConfig$1 as ImageConfig, ImageConfigSchema, type ImageMountFn, ImageRegistry, IndexedDBBackend, type InputSpec, InputSpecSchema, type LoadedImage, type Manifest$1 as Manifest, ManifestSchema, type MountMode, MountModeSchema, type MountOptions, MountOptionsSchema, type MountedWidget, ParentBridge, type Platform, PlatformSchema, type ServiceCallHandler, type ServiceCallPayload, type ServiceProxy, type ServiceResultPayload, type VFSPluginOptions, VFSStore, type VFSStoreOptions, type VirtualFile, type VirtualProject, type WatchCallback, type WatchEventType, cdnTransformPlugin, createCompiler, createFieldAccessProxy, createHttpServiceProxy, createIframeServiceProxy, createImageRegistry, createProjectFromFiles, createSingleFileProject, detectMainFile, disposeIframeBridge, extractNamespaces, fetchPackageJson, generateIframeBridgeScript, generateImportMap, generateNamespaceGlobals, getCdnBaseUrl, getImageRegistry, injectNamespaceGlobals, loadImage, mountEmbedded, mountIframe, parseImageConfig, parseImageSpec, parseManifest, reloadEmbedded, reloadIframe, removeNamespaceGlobals, resolveEntry, safeParseImageConfig, safeParseManifest, setCdnBaseUrl, vfsPlugin };
package/dist/index.js CHANGED
@@ -1477,13 +1477,15 @@ function disposeIframeBridge() {
1477
1477
  // src/compiler.ts
1478
1478
  var esbuildInitialized = false;
1479
1479
  var esbuildInitPromise = null;
1480
- async function initEsbuild() {
1480
+ var DEFAULT_ESBUILD_WASM_URL = "https://unpkg.com/esbuild-wasm/esbuild.wasm";
1481
+ async function initEsbuild(urlOverrides) {
1481
1482
  if (esbuildInitialized) return;
1482
1483
  if (esbuildInitPromise) return esbuildInitPromise;
1484
+ const wasmUrl = urlOverrides?.["esbuild-wasm/esbuild.wasm"] || DEFAULT_ESBUILD_WASM_URL;
1483
1485
  esbuildInitPromise = (async () => {
1484
1486
  try {
1485
1487
  await esbuild.initialize({
1486
- wasmURL: "https://unpkg.com/esbuild-wasm/esbuild.wasm"
1488
+ wasmURL: wasmUrl
1487
1489
  });
1488
1490
  esbuildInitialized = true;
1489
1491
  } catch (error) {
@@ -1506,7 +1508,7 @@ function hashContent(content) {
1506
1508
  return Math.abs(hash).toString(16).padStart(8, "0");
1507
1509
  }
1508
1510
  async function createCompiler(options) {
1509
- await initEsbuild();
1511
+ await initEsbuild(options.urlOverrides);
1510
1512
  const { image: imageSpec, proxyUrl, cdnBaseUrl: cdnBaseUrl3, widgetCdnBaseUrl } = options;
1511
1513
  if (cdnBaseUrl3) {
1512
1514
  setCdnBaseUrl(cdnBaseUrl3);
@@ -1795,11 +1797,13 @@ var VirtualFS = class {
1795
1797
  return this.backend.readFile(path, encoding);
1796
1798
  }
1797
1799
  async writeFile(path, content) {
1800
+ await this.ensureParentDir(path);
1798
1801
  const existed = await this.backend.exists(path);
1799
1802
  await this.backend.writeFile(path, content);
1800
1803
  this.recordChange(path, existed ? "update" : "create");
1801
1804
  }
1802
1805
  async applyRemoteFile(path, content) {
1806
+ await this.ensureParentDir(path);
1803
1807
  await this.backend.writeFile(path, content);
1804
1808
  }
1805
1809
  async applyRemoteDelete(path) {
@@ -1871,6 +1875,11 @@ var VirtualFS = class {
1871
1875
  listener(record);
1872
1876
  }
1873
1877
  }
1878
+ async ensureParentDir(path) {
1879
+ const dir = dirname2(path);
1880
+ if (!dir) return;
1881
+ await this.backend.mkdir(dir, { recursive: true });
1882
+ }
1874
1883
  };
1875
1884
 
1876
1885
  // src/vfs/sync/differ.ts
@@ -2647,6 +2656,13 @@ var VFSStore = class {
2647
2656
  )
2648
2657
  );
2649
2658
  }
2659
+ watch(path, callback) {
2660
+ if (this.provider.watch) {
2661
+ return this.provider.watch(this.remotePath(path), callback);
2662
+ }
2663
+ return () => {
2664
+ };
2665
+ }
2650
2666
  async sync() {
2651
2667
  if (!this.syncEngine) {
2652
2668
  return { pushed: 0, pulled: 0, conflicts: [] };