96
96
} ;
97
97
98
98
// Create a dummy dual package
99
+ //
100
+ /**
101
+ * this creates following directory structure:
102
+ *
103
+ * ./node_modules:
104
+ * |-> my-dual-package
105
+ * |-> es
106
+ * |-> index.js
107
+ * |-> package.json [2]
108
+ * |-> lib
109
+ * |-> index.js
110
+ * |->package.json [1]
111
+ *
112
+ * [1] - main package.json of the package
113
+ * - it contains:
114
+ * - type: 'commonjs'
115
+ * - main: 'lib/mainfile.js'
116
+ * - conditional exports for 'require' (lib/index.js) and
117
+ * 'import' (es/index.js)
118
+ * [2] - package.json add-on for the import case
119
+ * - it only contains:
120
+ * - type: 'module'
121
+ *
122
+ * in case the package is consumed as an ESM by importing it:
123
+ * import * as my-package from 'my-dual-package'
124
+ * it will cause the resolve method to return:
125
+ * {
126
+ * url: '<base_path>/node_modules/my-dual-package/es/index.js',
127
+ * format: 'module'
128
+ * }
129
+ *
130
+ * following testcase ensures that resolve works correctly in this case
131
+ * returning the information as specified above. Source for 'url' value
132
+ * is [1], source for 'format' value is [2]
133
+ */
134
+
99
135
const moduleName = 'my-dual-package' ;
100
136
101
137
const nmDir = rel ( 'node_modules' ) ;
@@ -114,7 +150,7 @@ try {
114
150
115
151
const mainPkgJsonContent = {
116
152
type : 'commonjs' ,
117
- main : 'lib/mainfile .js' ,
153
+ main : 'lib/index .js' ,
118
154
exports : {
119
155
'.' : {
120
156
'require' : './lib/index.js' ,
@@ -140,6 +176,7 @@ try {
140
176
// test the resolve
141
177
const resolveResult = resolve ( `${ moduleName } ` ) ;
142
178
assert . strictEqual ( resolveResult . format , 'module' ) ;
179
+ assert . ok ( resolveResult . url . includes ( 'my-dual-package/es/index.js' ) ) ;
143
180
144
181
// cleanup
145
182
fs . unlinkSync ( esScript ) ;
0 commit comments