@componentor/fs 3.0.18 → 3.0.20

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/README.md CHANGED
@@ -82,6 +82,7 @@ const fs = new VFSFileSystem({
82
82
  strictPermissions: false, // Enforce Unix permissions (default: false)
83
83
  sabSize: 4194304, // SharedArrayBuffer size in bytes (default: 4MB)
84
84
  debug: false, // Enable debug logging (default: false)
85
+ swUrl: undefined, // URL of the service worker script (default: auto-resolved)
85
86
  swScope: undefined, // Custom service worker scope (default: auto-scoped per root)
86
87
  limits: { // Upper bounds for VFS validation (prevents corrupt data from causing OOM)
87
88
  maxInodes: 4_000_000, // Max inode count (default: 4M)
@@ -160,6 +161,30 @@ console.log(fs.mode); // 'hybrid'
160
161
 
161
162
  `setMode()` terminates internal workers, allocates fresh shared memory, and reinitializes the filesystem in the requested mode.
162
163
 
164
+ ### Service Worker Setup (Multi-Tab)
165
+
166
+ Multi-tab coordination requires a service worker that acts as a MessagePort broker between tabs. The built service worker is shipped at `dist/workers/service.worker.js`. Unlike regular workers (which are resolved by the bundler), **service workers must be served as a real file at a public URL**.
167
+
168
+ Most bundlers (Vite, webpack) handle `new URL('./workers/service.worker.js', import.meta.url)` automatically, but if the default resolution doesn't work in your setup, use the `swUrl` option:
169
+
170
+ ```typescript
171
+ const fs = new VFSFileSystem({
172
+ swUrl: '/vfs-service-worker.js', // your public URL
173
+ });
174
+ ```
175
+
176
+ **Vite example** — copy the file to `public/`:
177
+
178
+ ```bash
179
+ cp node_modules/@componentor/fs/dist/workers/service.worker.js public/vfs-service-worker.js
180
+ ```
181
+
182
+ ```typescript
183
+ const fs = new VFSFileSystem({ swUrl: '/vfs-service-worker.js' });
184
+ ```
185
+
186
+ If you only use a single tab, the service worker is not needed — the tab always runs as the leader.
187
+
163
188
  ## COOP/COEP Headers
164
189
 
165
190
  To enable the sync API, your page must be `crossOriginIsolated`. Add these headers:
@@ -577,6 +602,12 @@ Make sure `opfsSync` is enabled (it's `true` by default). Files are mirrored to
577
602
 
578
603
  ## Changelog
579
604
 
605
+ ### v3.0.19-v3.0.20 (2026)
606
+
607
+ **Features:**
608
+ - Add `swUrl` config option to specify a custom service worker URL for multi-tab support in bundled environments where the default auto-resolved URL doesn't work
609
+ - Remove `type: 'module'` from service worker registration (built output is plain script, not ESM)
610
+
580
611
  ### v3.0.18 (2026)
581
612
 
582
613
  **Features:**
package/dist/index.d.mts CHANGED
@@ -167,8 +167,12 @@ interface VFSConfig {
167
167
  strictPermissions?: boolean;
168
168
  sabSize?: number;
169
169
  debug?: boolean;
170
+ /** URL of the service worker script. Defaults to `'./workers/service.worker.js'`
171
+ * relative to `import.meta.url`. Override when the library is bundled and the
172
+ * default relative URL no longer resolves to the correct location. */
173
+ swUrl?: string;
170
174
  /** Scope for the internal service worker registration. Defaults to
171
- * `'./opfs-fs-sw/'` (relative to the SW script URL) so it won't collide
175
+ * `'./${ns}/'` (relative to the SW script URL) so it won't collide
172
176
  * with the host application's service worker. */
173
177
  swScope?: string;
174
178
  /** Upper bounds for VFS validation (prevents corrupt data from causing OOM/hangs). */
package/dist/index.js CHANGED
@@ -1351,6 +1351,7 @@ var VFSFileSystem = class {
1351
1351
  strictPermissions: config.strictPermissions ?? false,
1352
1352
  sabSize: config.sabSize ?? DEFAULT_SAB_SIZE,
1353
1353
  debug: config.debug ?? false,
1354
+ swUrl: config.swUrl,
1354
1355
  swScope: config.swScope,
1355
1356
  limits: config.limits
1356
1357
  };
@@ -1560,9 +1561,9 @@ var VFSFileSystem = class {
1560
1561
  /** Register the VFS service worker and return the active SW */
1561
1562
  async getServiceWorker() {
1562
1563
  if (!this.swReg) {
1563
- const swUrl = new URL("./workers/service.worker.js", import.meta.url);
1564
+ const swUrl = this.config.swUrl ? new URL(this.config.swUrl, location.origin) : new URL("./workers/service.worker.js", import.meta.url);
1564
1565
  const scope = this.config.swScope ?? new URL(`./${this.ns}/`, swUrl).href;
1565
- this.swReg = await navigator.serviceWorker.register(swUrl.href, { type: "module", scope });
1566
+ this.swReg = await navigator.serviceWorker.register(swUrl.href, { scope });
1566
1567
  }
1567
1568
  const reg = this.swReg;
1568
1569
  if (reg.active) return reg.active;