@b9g/platform-cloudflare 0.1.1 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/platform-cloudflare",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "Cloudflare Workers platform adapter for Shovel - already ServiceWorker-based!",
5
5
  "keywords": [
6
6
  "shovel",
@@ -11,13 +11,13 @@
11
11
  "serviceworker"
12
12
  ],
13
13
  "dependencies": {
14
- "@b9g/platform": "^0.1.1",
15
- "@b9g/cache": "^0.1.1",
16
- "@b9g/assets": "^0.1.1",
14
+ "@b9g/platform": "^0.1.4",
15
+ "@b9g/cache": "^0.1.3",
16
+ "@b9g/assets": "^0.1.4",
17
17
  "@cloudflare/workers-types": "^4.20241218.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@b9g/libuild": "^0.1.10",
20
+ "@b9g/libuild": "^0.1.11",
21
21
  "bun-types": "latest"
22
22
  },
23
23
  "type": "module",
package/src/platform.d.ts CHANGED
@@ -23,12 +23,11 @@ export interface CloudflarePlatformOptions extends PlatformConfig {
23
23
  export declare class CloudflarePlatform extends BasePlatform {
24
24
  readonly name = "cloudflare";
25
25
  private options;
26
- private _dist?;
27
26
  constructor(options?: CloudflarePlatformOptions);
28
27
  /**
29
- * Build artifacts filesystem (not available in Workers runtime)
28
+ * Get filesystem directory handle (memory-only in Workers runtime)
30
29
  */
31
- get distDir(): FileSystemDirectoryHandle;
30
+ getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
32
31
  /**
33
32
  * Get platform-specific default cache configuration for Cloudflare Workers
34
33
  */
package/src/platform.js CHANGED
@@ -1,21 +1,12 @@
1
1
  /// <reference types="./platform.d.ts" />
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
-
10
2
  // src/platform.ts
11
3
  import {
12
4
  BasePlatform
13
5
  } from "@b9g/platform";
14
- import { FileSystemRegistry, getFileSystemRoot, MemoryFileSystemAdapter } from "@b9g/filesystem";
6
+ import { FileSystemRegistry, getDirectoryHandle, MemoryBucket } from "@b9g/filesystem";
15
7
  var CloudflarePlatform = class extends BasePlatform {
16
8
  name = "cloudflare";
17
9
  options;
18
- _dist;
19
10
  constructor(options = {}) {
20
11
  super(options);
21
12
  this.options = {
@@ -26,24 +17,14 @@ var CloudflarePlatform = class extends BasePlatform {
26
17
  durableObjects: {},
27
18
  ...options
28
19
  };
29
- FileSystemRegistry.register("memory", new MemoryFileSystemAdapter());
30
- if (this.options.r2Buckets?.default) {
31
- try {
32
- const { R2FileSystemAdapter } = __require("@b9g/filesystem-r2");
33
- FileSystemRegistry.register("r2", new R2FileSystemAdapter(this.options.r2Buckets.default));
34
- } catch {
35
- console.warn("[Cloudflare] R2 adapter not available, using memory filesystem");
36
- }
37
- }
20
+ FileSystemRegistry.register("memory", new MemoryBucket());
38
21
  }
39
22
  /**
40
- * Build artifacts filesystem (not available in Workers runtime)
23
+ * Get filesystem directory handle (memory-only in Workers runtime)
41
24
  */
42
- get distDir() {
43
- if (!this._dist) {
44
- this._dist = new MemoryFileSystemAdapter().getFileSystemRoot("dist");
45
- }
46
- return this._dist;
25
+ async getDirectoryHandle(name) {
26
+ const adapter = new MemoryBucket();
27
+ return await adapter.getDirectoryHandle(name);
47
28
  }
48
29
  /**
49
30
  * Get platform-specific default cache configuration for Cloudflare Workers
@@ -69,15 +50,19 @@ var CloudflarePlatform = class extends BasePlatform {
69
50
  */
70
51
  createServer(handler, _options = {}) {
71
52
  return {
72
- listen: () => {
53
+ async listen() {
73
54
  console.info("[Cloudflare] Worker handler ready");
74
- return Promise.resolve();
75
55
  },
76
- close: () => {
56
+ async close() {
77
57
  console.info("[Cloudflare] Worker handler stopped");
78
- return Promise.resolve();
79
58
  },
80
- address: () => ({ port: 0, host: "cloudflare-workers" })
59
+ address: () => ({ port: 443, host: "cloudflare-workers" }),
60
+ get url() {
61
+ return "https://cloudflare-workers";
62
+ },
63
+ get ready() {
64
+ return true;
65
+ }
81
66
  };
82
67
  }
83
68
  /**
@@ -117,7 +102,7 @@ var CloudflarePlatform = class extends BasePlatform {
117
102
  * Get filesystem root for File System Access API
118
103
  */
119
104
  async getFileSystemRoot(name = "default") {
120
- return await getFileSystemRoot(name);
105
+ return await getDirectoryHandle(name);
121
106
  }
122
107
  /**
123
108
  * Dispose of platform resources