File tree Expand file tree Collapse file tree 4 files changed +25
-64
lines changed Expand file tree Collapse file tree 4 files changed +25
-64
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , expect , it } from '@rstest/core' ;
2
+ // @ts -expect-error node builtin module
3
+ import _http_common from '_http_common' ;
4
+
5
+ describe ( 'node built-in modules' , ( ) => {
6
+ it ( 'should load node built-in modules correctly' , ( ) => {
7
+ expect ( _http_common ) . toBeDefined ( ) ;
8
+ } ) ;
9
+ } ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ describe('happy-dom', () => {
31
31
await expectExecSuccess ( ) ;
32
32
} ) ;
33
33
34
+ it ( 'should load node built-in modules correctly' , async ( ) => {
35
+ const { expectExecSuccess } = await runCli ( 'test/node' , 'happy-dom' ) ;
36
+ await expectExecSuccess ( ) ;
37
+ } ) ;
38
+
34
39
it ( 'should run test correctly with custom externals' , async ( ) => {
35
40
const { expectExecSuccess } = await runCli ( appFilters , 'happy-dom' , {
36
41
args : externalConfigArgs ,
Original file line number Diff line number Diff line change
1
+ import { isBuiltin } from 'node:module' ;
1
2
import type { RsbuildPlugin , Rspack } from '@rsbuild/core' ;
2
3
import type { RstestContext } from '../../types' ;
3
- import { castArray , NODE_BUILTINS } from '../../utils' ;
4
+ import { ADDITIONAL_NODE_BUILTINS , castArray } from '../../utils' ;
4
5
5
6
const autoExternalNodeModules : (
6
7
data : Rspack . ExternalItemFunctionData ,
@@ -59,13 +60,15 @@ function autoExternalNodeBuiltin(
59
60
return ;
60
61
}
61
62
62
- const isNodeBuiltin = NODE_BUILTINS . some ( ( builtin ) => {
63
- if ( typeof builtin === 'string' ) {
64
- return builtin === request ;
65
- }
63
+ const isNodeBuiltin =
64
+ isBuiltin ( request ) ||
65
+ ADDITIONAL_NODE_BUILTINS . some ( ( builtin ) => {
66
+ if ( typeof builtin === 'string' ) {
67
+ return builtin === request ;
68
+ }
66
69
67
- return builtin . test ( request ) ;
68
- } ) ;
70
+ return builtin . test ( request ) ;
71
+ } ) ;
69
72
70
73
if ( isNodeBuiltin ) {
71
74
callback (
Original file line number Diff line number Diff line change @@ -170,64 +170,8 @@ export const needFlagExperimentalDetectModule = (): boolean => {
170
170
return false ;
171
171
} ;
172
172
173
- // Ported from https://github.com/webpack/webpack/blob/21b28a82f7a6ec677752e1c8fb722a830a2adf69/lib/node/NodeTargetPlugin.js.
174
- export const NODE_BUILTINS : ( string | RegExp ) [ ] = [
175
- 'assert' ,
176
- 'assert/strict' ,
177
- 'async_hooks' ,
178
- 'buffer' ,
179
- 'child_process' ,
180
- 'cluster' ,
181
- 'console' ,
182
- 'constants' ,
183
- 'crypto' ,
184
- 'dgram' ,
185
- 'diagnostics_channel' ,
186
- 'dns' ,
187
- 'dns/promises' ,
188
- 'domain' ,
189
- 'events' ,
190
- 'fs' ,
191
- 'fs/promises' ,
192
- 'http' ,
193
- 'http2' ,
194
- 'https' ,
195
- 'inspector' ,
196
- 'inspector/promises' ,
197
- 'module' ,
198
- 'net' ,
199
- 'os' ,
200
- 'path' ,
201
- 'path/posix' ,
202
- 'path/win32' ,
203
- 'perf_hooks' ,
204
- 'process' ,
205
- 'punycode' ,
206
- 'querystring' ,
207
- 'readline' ,
208
- 'readline/promises' ,
209
- 'repl' ,
210
- 'stream' ,
211
- 'stream/consumers' ,
212
- 'stream/promises' ,
213
- 'stream/web' ,
214
- 'string_decoder' ,
215
- 'sys' ,
216
- 'timers' ,
217
- 'timers/promises' ,
218
- 'tls' ,
219
- 'trace_events' ,
220
- 'tty' ,
221
- 'url' ,
222
- 'util' ,
223
- 'util/types' ,
224
- 'v8' ,
225
- 'vm' ,
226
- 'wasi' ,
227
- 'worker_threads' ,
228
- 'zlib' ,
173
+ export const ADDITIONAL_NODE_BUILTINS : ( string | RegExp ) [ ] = [
229
174
/ ^ n o d e : / ,
230
-
231
175
// cspell:word pnpapi
232
176
// Yarn PnP adds pnpapi as "builtin"
233
177
'pnpapi' ,
You can’t perform that action at this time.
0 commit comments