Skip to content

Commit 022a2eb

Browse files
committed
fixup! fixup! fixup! loader: return package format from defaultResolve if known
1 parent 5935065 commit 022a2eb

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

test/es-module/test-esm-resolve-type.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ try {
9696
};
9797

9898
// 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+
99135
const moduleName = 'my-dual-package';
100136

101137
const nmDir = rel('node_modules');
@@ -114,7 +150,7 @@ try {
114150

115151
const mainPkgJsonContent = {
116152
type: 'commonjs',
117-
main: 'lib/mainfile.js',
153+
main: 'lib/index.js',
118154
exports: {
119155
'.': {
120156
'require': './lib/index.js',
@@ -140,6 +176,7 @@ try {
140176
// test the resolve
141177
const resolveResult = resolve(`${moduleName}`);
142178
assert.strictEqual(resolveResult.format, 'module');
179+
assert.ok(resolveResult.url.includes('my-dual-package/es/index.js'));
143180

144181
// cleanup
145182
fs.unlinkSync(esScript);

0 commit comments

Comments
 (0)