Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: fix builtin reexport tracing #35500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function lazyTypes() {
}

const { readFileSync } = require('fs');
const { extname } = require('path');
const { extname, isAbsolute } = require('path');
const {
stripBOM,
loadNativeModule
Expand Down Expand Up @@ -244,7 +244,8 @@ function cjsPreparseModuleExports(filename) {
continue;
}
const ext = extname(resolved);
if (ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) {
if ((ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) &&
isAbsolute(resolved)) {
const { exportNames: reexportNames } = cjsPreparseModuleExports(resolved);
for (const name of reexportNames)
exportNames.add(name);
Expand Down
21 changes: 21 additions & 0 deletions test/es-module/test-esm-cjs-builtins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');
const { spawn } = require('child_process');
const assert = require('assert');

const entry = fixtures.path('/es-modules/builtin-imports-case.mjs');

const child = spawn(process.execPath, [entry]);
child.stderr.setEncoding('utf8');
let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
stdout += data;
});
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(stdout, 'ok\n');
}));
5 changes: 5 additions & 0 deletions test/fixtures/es-modules/builtin-imports-case.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { strictEqual } from 'assert';
import './dep1.js';
import { assert as depAssert } from './dep2.js';
strictEqual(depAssert.strictEqual, strictEqual);
console.log('ok');
1 change: 1 addition & 0 deletions test/fixtures/es-modules/dep1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('assert');
1 change: 1 addition & 0 deletions test/fixtures/es-modules/dep2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.assert = require('assert');