Skip to content

Commit 5c879a9

Browse files
guybedforddanielleadams
authored andcommitted
module: fix builtin reexport tracing
PR-URL: #35500 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 91ef862 commit 5c879a9

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

lib/internal/modules/esm/translators.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function lazyTypes() {
2424
}
2525

2626
const { readFileSync } = require('fs');
27-
const { extname } = require('path');
27+
const { extname, isAbsolute } = require('path');
2828
const {
2929
stripBOM,
3030
loadNativeModule
@@ -244,7 +244,8 @@ function cjsPreparseModuleExports(filename) {
244244
continue;
245245
}
246246
const ext = extname(resolved);
247-
if (ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) {
247+
if ((ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) &&
248+
isAbsolute(resolved)) {
248249
const { exportNames: reexportNames } = cjsPreparseModuleExports(resolved);
249250
for (const name of reexportNames)
250251
exportNames.add(name);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
const { spawn } = require('child_process');
6+
const assert = require('assert');
7+
8+
const entry = fixtures.path('/es-modules/builtin-imports-case.mjs');
9+
10+
const child = spawn(process.execPath, [entry]);
11+
child.stderr.setEncoding('utf8');
12+
let stdout = '';
13+
child.stdout.setEncoding('utf8');
14+
child.stdout.on('data', (data) => {
15+
stdout += data;
16+
});
17+
child.on('close', common.mustCall((code, signal) => {
18+
assert.strictEqual(code, 0);
19+
assert.strictEqual(signal, null);
20+
assert.strictEqual(stdout, 'ok\n');
21+
}));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { strictEqual } from 'assert';
2+
import './dep1.js';
3+
import { assert as depAssert } from './dep2.js';
4+
strictEqual(depAssert.strictEqual, strictEqual);
5+
console.log('ok');

test/fixtures/es-modules/dep1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('assert');

test/fixtures/es-modules/dep2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.assert = require('assert');

0 commit comments

Comments
 (0)