File tree 3 files changed +41
-28
lines changed
adapter-cloudflare-workers
3 files changed +41
-28
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/adapter-cloudflare-workers ' : minor
3
+ ' @sveltejs/adapter-cloudflare ' : minor
4
+ ---
5
+
6
+ feat: support compatible node modules without prefixes
Original file line number Diff line number Diff line change @@ -15,6 +15,21 @@ import { fileURLToPath } from 'node:url';
15
15
* }} WranglerConfig
16
16
*/
17
17
18
+ // list from https://developers.cloudflare.com/workers/runtime-apis/nodejs/
19
+ const compatible_node_modules = [
20
+ 'assert' ,
21
+ 'async_hooks' ,
22
+ 'buffer' ,
23
+ 'crypto' ,
24
+ 'diagnostics_channel' ,
25
+ 'events' ,
26
+ 'path' ,
27
+ 'process' ,
28
+ 'stream' ,
29
+ 'string_decoder' ,
30
+ 'util'
31
+ ] ;
32
+
18
33
/** @type {import('./index.js').default } */
19
34
export default function ( { config = 'wrangler.toml' } = { } ) {
20
35
return {
@@ -64,19 +79,7 @@ export default function ({ config = 'wrangler.toml' } = {}) {
64
79
65
80
const external = [ '__STATIC_CONTENT_MANIFEST' , 'cloudflare:*' ] ;
66
81
if ( compatibility_flags && compatibility_flags . includes ( 'nodejs_compat' ) ) {
67
- external . push (
68
- 'node:assert' ,
69
- 'node:async_hooks' ,
70
- 'node:buffer' ,
71
- 'node:crypto' ,
72
- 'node:diagnostics_channel' ,
73
- 'node:events' ,
74
- 'node:path' ,
75
- 'node:process' ,
76
- 'node:stream' ,
77
- 'node:string_decoder' ,
78
- 'node:util'
79
- ) ;
82
+ external . push ( ...compatible_node_modules . map ( ( id ) => `node:${ id } ` ) ) ;
80
83
}
81
84
82
85
await esbuild . build ( {
@@ -88,6 +91,7 @@ export default function ({ config = 'wrangler.toml' } = {}) {
88
91
outfile : main ,
89
92
bundle : true ,
90
93
external,
94
+ alias : Object . fromEntries ( compatible_node_modules . map ( ( id ) => [ id , `node:${ id } ` ] ) ) ,
91
95
format : 'esm' ,
92
96
loader : {
93
97
'.wasm' : 'copy'
Original file line number Diff line number Diff line change @@ -3,6 +3,21 @@ import * as path from 'node:path';
3
3
import { fileURLToPath } from 'node:url' ;
4
4
import * as esbuild from 'esbuild' ;
5
5
6
+ // list from https://developers.cloudflare.com/workers/runtime-apis/nodejs/
7
+ const compatible_node_modules = [
8
+ 'assert' ,
9
+ 'async_hooks' ,
10
+ 'buffer' ,
11
+ 'crypto' ,
12
+ 'diagnostics_channel' ,
13
+ 'events' ,
14
+ 'path' ,
15
+ 'process' ,
16
+ 'stream' ,
17
+ 'string_decoder' ,
18
+ 'util'
19
+ ] ;
20
+
6
21
/** @type {import('./index.js').default } */
7
22
export default function ( options = { } ) {
8
23
return {
@@ -53,20 +68,7 @@ export default function (options = {}) {
53
68
}
54
69
} ) ;
55
70
56
- const external = [
57
- 'cloudflare:*' ,
58
- 'node:assert' ,
59
- 'node:async_hooks' ,
60
- 'node:buffer' ,
61
- 'node:crypto' ,
62
- 'node:diagnostics_channel' ,
63
- 'node:events' ,
64
- 'node:path' ,
65
- 'node:process' ,
66
- 'node:stream' ,
67
- 'node:string_decoder' ,
68
- 'node:util'
69
- ] ;
71
+ const external = [ 'cloudflare:*' , ...compatible_node_modules . map ( ( id ) => `node:${ id } ` ) ] ;
70
72
71
73
await esbuild . build ( {
72
74
platform : 'browser' ,
@@ -81,7 +83,8 @@ export default function (options = {}) {
81
83
loader : {
82
84
'.wasm' : 'copy'
83
85
} ,
84
- external
86
+ external,
87
+ alias : Object . fromEntries ( compatible_node_modules . map ( ( id ) => [ id , `node:${ id } ` ] ) )
85
88
} ) ;
86
89
}
87
90
} ;
You can’t perform that action at this time.
0 commit comments