File tree 4 files changed +70
-0
lines changed
4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,42 @@ const require = createRequire(import.meta.url);
66
66
const siblingModule = require (' ./sibling-module' );
67
67
` ` `
68
68
69
+ ### ` module .customConditions `
70
+
71
+ <!-- YAML
72
+ added: REPLACEME
73
+ -->
74
+
75
+ * Type: {Set<string>}
76
+
77
+ The custom resolution conditions specified by the user. The default Node.js conditions are not included.
78
+
79
+ For example, assuming the following script for ` module - customconditions .js ` :
80
+
81
+ ` ` ` mjs
82
+ import module from ' node:module' ;
83
+
84
+ console .log (' conditions:' , module .customConditions );
85
+ ` ` `
86
+
87
+ ` ` ` cjs
88
+ const module = require (' node:module' );
89
+
90
+ console .log (' conditions:' , module .customConditions );
91
+ ` ` `
92
+
93
+ Launching the Node.js process as:
94
+
95
+ ` ` ` console
96
+ $ node - C additional module - customconditions .js
97
+ ` ` `
98
+
99
+ Would generate the output:
100
+
101
+ ` ` ` text
102
+ conditions: Set (1 ) { ' additional' }
103
+ ` ` `
104
+
69
105
### ` module .findPackageJSON (specifier[, base])`
70
106
71
107
<!-- YAML
Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ function toRealPath(requestPath) {
63
63
} ) ;
64
64
}
65
65
66
+ /** @type {Set<string> } */
67
+ let userConditions ;
68
+
69
+ function getUserConditions ( ) {
70
+ if ( userConditions === undefined ) {
71
+ userConditions = new SafeSet ( [
72
+ ...getOptionValue ( '--conditions' ) ,
73
+ ] ) ;
74
+ }
75
+ return userConditions ;
76
+ }
77
+
66
78
/** @type {Set<string> } */
67
79
let cjsConditions ;
68
80
/**
@@ -407,6 +419,7 @@ module.exports = {
407
419
enableCompileCache,
408
420
flushCompileCache,
409
421
getBuiltinModule,
422
+ getUserConditions,
410
423
getCjsConditions,
411
424
getCompileCacheDir,
412
425
initializeCjsConditions,
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const {
4
+ ObjectDefineProperty,
5
+ } = primordials ;
3
6
const {
4
7
findSourceMap,
5
8
getSourceMapsSupport,
@@ -15,6 +18,7 @@ const {
15
18
enableCompileCache,
16
19
flushCompileCache,
17
20
getCompileCacheDir,
21
+ getUserConditions,
18
22
} = require ( 'internal/modules/helpers' ) ;
19
23
const {
20
24
findPackageJSON,
@@ -23,6 +27,13 @@ const { stripTypeScriptTypes } = require('internal/modules/typescript');
23
27
24
28
Module . register = register ;
25
29
Module . constants = constants ;
30
+ ObjectDefineProperty ( Module , 'customConditions' , {
31
+ __proto__ : null ,
32
+ get ( ) {
33
+ return getUserConditions ( ) ;
34
+ } ,
35
+ enumerable : true ,
36
+ } ) ;
26
37
Module . enableCompileCache = enableCompileCache ;
27
38
Module . findPackageJSON = findPackageJSON ;
28
39
Module . flushCompileCache = flushCompileCache ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ // Flags: -C additional --expose-internals
4
+
5
+ require ( '../common' ) ;
6
+ const { SafeSet } = require ( 'internal/test/binding' ) . primordials ;
7
+ const assert = require ( 'node:assert' ) ;
8
+ const { customConditions } = require ( 'module' ) ;
9
+
10
+ assert . deepStrictEqual ( customConditions , new SafeSet ( [ 'additional' ] ) ) ;
You can’t perform that action at this time.
0 commit comments