@@ -7,6 +7,11 @@ const polyfillsPath = `${libDirPath}/build/bundlers/polyfills`;
7
7
const nextNodePresetPath = `${ libDirPath } /presets/custom/next/compute/node` ;
8
8
const nodePolyfillsPath = `${ polyfillsPath } /node` ;
9
9
10
+ /**
11
+ * External polyfills are resolved in the build, but as they are for the local environment (Vulcan dev) they are located in #env/polyfills.
12
+ */
13
+ const externalPolyfillsPath = `${ libDirPath } /env/polyfills` ;
14
+
10
15
/**
11
16
* Manages and builds polyfills for Node and global browser environments.
12
17
*/
@@ -21,6 +26,8 @@ class PolyfillsManager {
21
26
this . libs = new Map ( ) ;
22
27
/** @type {Map<string, string|boolean> } */
23
28
this . alias = new Map ( ) ;
29
+ /** @type {Map<string, string|boolean> } */
30
+ this . external = new Map ( ) ;
24
31
}
25
32
26
33
/**
@@ -50,9 +57,18 @@ class PolyfillsManager {
50
57
this . alias . set ( name , path ) ;
51
58
}
52
59
60
+ /**
61
+ * Sets a external libs.
62
+ * @param {string } name - Name of the external.
63
+ * @param {string|boolean } path - Path to the polyfill or a boolean value.
64
+ */
65
+ setExternal ( name , path ) {
66
+ this . external . set ( name , path ) ;
67
+ }
68
+
53
69
/**
54
70
* Builds and retrieves the polyfills for Node and globals.
55
- * @returns {{ libs: Map<string, string|boolean>, globals: Map<string, string>, alias: Map<string, string> } } - Object containing libs and globals.
71
+ * @returns {{ libs: Map<string, string|boolean>, globals: Map<string, string>, alias: Map<string, string>, external: Map<string, string> } } - Object containing libs and globals.
56
72
*/
57
73
buildPolyfills ( ) {
58
74
this . setGlobal ( 'buffer' , `${ nodePolyfillsPath } /globals/buffer.js` ) ;
@@ -70,7 +86,6 @@ class PolyfillsManager {
70
86
) ;
71
87
72
88
this . setLib ( 'accepts' , require . resolve ( 'accepts' ) ) ;
73
- this . setLib ( 'async_hooks' , `${ nodePolyfillsPath } /_empty.js` ) ;
74
89
this . setLib ( 'buffer' , require . resolve ( 'buffer/' ) ) ;
75
90
this . setLib ( 'child_process' , `${ nodePolyfillsPath } /_empty.js` ) ;
76
91
this . setLib ( 'cluster' , `${ nodePolyfillsPath } /_empty.js` ) ;
@@ -131,7 +146,17 @@ class PolyfillsManager {
131
146
this . setAlias ( 'util' , require . resolve ( 'util/' ) ) ;
132
147
this . setAlias ( 'process' , `${ nodePolyfillsPath } /globals/process.js` ) ;
133
148
134
- return { libs : this . libs , globals : this . globals , alias : this . alias } ;
149
+ this . setExternal (
150
+ 'async_hooks' ,
151
+ `${ externalPolyfillsPath } /async_hooks/index.js` ,
152
+ ) ;
153
+
154
+ return {
155
+ libs : this . libs ,
156
+ globals : this . globals ,
157
+ alias : this . alias ,
158
+ external : this . external ,
159
+ } ;
135
160
}
136
161
}
137
162
0 commit comments