File tree 6 files changed +39
-5
lines changed
adapter-cloudflare-workers
6 files changed +39
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { Server } from 'SERVER' ;
2
2
import { manifest , prerendered } from 'MANIFEST' ;
3
+ DURABLE_OBJECT_EXPORTS ;
3
4
import { getAssetFromKV , mapRequestToAsset } from '@cloudflare/kv-asset-handler' ;
4
5
import static_asset_manifest_json from '__STATIC_CONTENT_MANIFEST' ;
5
6
const static_asset_manifest = JSON . parse ( static_asset_manifest_json ) ;
Original file line number Diff line number Diff line change 1
1
import { Adapter } from '@sveltejs/kit' ;
2
2
import './ambient.js' ;
3
3
4
- export default function plugin ( options : { config ?: string } ) : Adapter ;
4
+ export default function plugin ( options : {
5
+ config ?: string
6
+ /**
7
+ * Customize the file that exports DurableObject classes definitions
8
+ * @default "./src/lib/durableObjects.js"
9
+ */
10
+ durableObjectExports ?: string
11
+ } ) : Adapter ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import { fileURLToPath } from 'node:url';
15
15
*/
16
16
17
17
/** @type {import('.').default } */
18
- export default function ( { config = 'wrangler.toml' } = { } ) {
18
+ export default function ( { config = 'wrangler.toml' , ... options } = { } ) {
19
19
return {
20
20
name : '@sveltejs/adapter-cloudflare-workers' ,
21
21
@@ -38,10 +38,20 @@ export default function ({ config = 'wrangler.toml' } = {}) {
38
38
builder . log . minor ( 'Generating worker...' ) ;
39
39
const relativePath = posix . relative ( tmp , builder . getServerDirectory ( ) ) ;
40
40
41
+ let durable_objects_exports = ''
42
+ try {
43
+ readFileSync ( options . durableObjectExports ?? './src/lib/durableObjects.js' )
44
+ } catch {
45
+ if ( options . durableObjectExports ) {
46
+ throw new Error ( 'Specified durableObjectExports file not found' ) ;
47
+ }
48
+ }
49
+
41
50
builder . copy ( `${ files } /entry.js` , `${ tmp } /entry.js` , {
42
51
replace : {
43
52
SERVER : `${ relativePath } /index.js` ,
44
- MANIFEST : './manifest.js'
53
+ MANIFEST : './manifest.js' ,
54
+ DURABLE_OBJECT_EXPORTS : durable_objects_exports
45
55
}
46
56
} ) ;
47
57
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ export interface AdapterOptions {
30
30
*/
31
31
exclude ?: string [ ] ;
32
32
} ;
33
+ /**
34
+ * Customize the file that exports DurableObject classes definitions
35
+ * @default "./src/lib/durableObjects.js"
36
+ */
37
+ durableObjectExports ?: string
33
38
}
34
39
35
40
export interface RoutesJSONSpec {
Original file line number Diff line number Diff line change 1
- import { writeFileSync } from 'node:fs' ;
1
+ import { readFileSync , writeFileSync } from 'node:fs' ;
2
2
import * as path from 'node:path' ;
3
3
import { fileURLToPath } from 'node:url' ;
4
4
import * as esbuild from 'esbuild' ;
@@ -38,10 +38,20 @@ export default function (options = {}) {
38
38
39
39
writeFileSync ( `${ dest } /_headers` , generate_headers ( builder . config . kit . appDir ) , { flag : 'a' } ) ;
40
40
41
+ let durable_objects_exports = ''
42
+ try {
43
+ readFileSync ( options . durableObjectExports ?? './src/lib/durableObjects.js' )
44
+ } catch {
45
+ if ( options . durableObjectExports ) {
46
+ throw new Error ( 'Specified durableObjectExports file not found' ) ;
47
+ }
48
+ }
49
+
41
50
builder . copy ( `${ files } /worker.js` , `${ tmp } /_worker.js` , {
42
51
replace : {
43
52
SERVER : `${ relativePath } /index.js` ,
44
- MANIFEST : './manifest.js'
53
+ MANIFEST : './manifest.js' ,
54
+ DURABLE_OBJECT_EXPORTS : durable_objects_exports
45
55
}
46
56
} ) ;
47
57
Original file line number Diff line number Diff line change 1
1
import { Server } from 'SERVER' ;
2
2
import { manifest , prerendered } from 'MANIFEST' ;
3
+ DURABLE_OBJECT_EXPORTS ;
3
4
import * as Cache from 'worktop/cfw.cache' ;
4
5
5
6
const server = new Server ( manifest ) ;
You can’t perform that action at this time.
0 commit comments