File tree Expand file tree Collapse file tree 6 files changed +39
-5
lines changed
adapter-cloudflare-workers Expand file tree Collapse file tree 6 files changed +39
-5
lines changed Original file line number Diff line number Diff line change 11import { Server } from 'SERVER' ;
22import { manifest , prerendered } from 'MANIFEST' ;
3+ DURABLE_OBJECT_EXPORTS ;
34import { getAssetFromKV , mapRequestToAsset } from '@cloudflare/kv-asset-handler' ;
45import static_asset_manifest_json from '__STATIC_CONTENT_MANIFEST' ;
56const static_asset_manifest = JSON . parse ( static_asset_manifest_json ) ;
Original file line number Diff line number Diff line change 11import { Adapter } from '@sveltejs/kit' ;
22import './ambient.js' ;
33
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';
1515 */
1616
1717/** @type {import('.').default } */
18- export default function ( { config = 'wrangler.toml' } = { } ) {
18+ export default function ( { config = 'wrangler.toml' , ... options } = { } ) {
1919 return {
2020 name : '@sveltejs/adapter-cloudflare-workers' ,
2121
@@ -38,10 +38,20 @@ export default function ({ config = 'wrangler.toml' } = {}) {
3838 builder . log . minor ( 'Generating worker...' ) ;
3939 const relativePath = posix . relative ( tmp , builder . getServerDirectory ( ) ) ;
4040
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+
4150 builder . copy ( `${ files } /entry.js` , `${ tmp } /entry.js` , {
4251 replace : {
4352 SERVER : `${ relativePath } /index.js` ,
44- MANIFEST : './manifest.js'
53+ MANIFEST : './manifest.js' ,
54+ DURABLE_OBJECT_EXPORTS : durable_objects_exports
4555 }
4656 } ) ;
4757
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ export interface AdapterOptions {
3030 */
3131 exclude ?: string [ ] ;
3232 } ;
33+ /**
34+ * Customize the file that exports DurableObject classes definitions
35+ * @default "./src/lib/durableObjects.js"
36+ */
37+ durableObjectExports ?: string
3338}
3439
3540export 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' ;
22import * as path from 'node:path' ;
33import { fileURLToPath } from 'node:url' ;
44import * as esbuild from 'esbuild' ;
@@ -38,10 +38,20 @@ export default function (options = {}) {
3838
3939 writeFileSync ( `${ dest } /_headers` , generate_headers ( builder . config . kit . appDir ) , { flag : 'a' } ) ;
4040
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+
4150 builder . copy ( `${ files } /worker.js` , `${ tmp } /_worker.js` , {
4251 replace : {
4352 SERVER : `${ relativePath } /index.js` ,
44- MANIFEST : './manifest.js'
53+ MANIFEST : './manifest.js' ,
54+ DURABLE_OBJECT_EXPORTS : durable_objects_exports
4555 }
4656 } ) ;
4757
Original file line number Diff line number Diff line change 11import { Server } from 'SERVER' ;
22import { manifest , prerendered } from 'MANIFEST' ;
3+ DURABLE_OBJECT_EXPORTS ;
34import * as Cache from 'worktop/cfw.cache' ;
45
56const server = new Server ( manifest ) ;
You can’t perform that action at this time.
0 commit comments