Skip to content

Commit 21cda3e

Browse files
authored
Make "-r <dir>" work with new import-first loading (#4668)
1 parent f033ff1 commit 21cda3e

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lib/esm-utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ exports.requireOrImport = hasStableEsmImplementation
4949
} catch (err) {
5050
if (
5151
err.code === 'ERR_MODULE_NOT_FOUND' ||
52-
err.code === 'ERR_UNKNOWN_FILE_EXTENSION'
52+
err.code === 'ERR_UNKNOWN_FILE_EXTENSION' ||
53+
err.code === 'ERR_UNSUPPORTED_DIR_IMPORT'
5354
) {
5455
return require(file);
5556
} else {

test/integration/esm.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
var path = require('path');
23
var helpers = require('./helpers');
34
var run = helpers.runMochaJSON;
45
var runMochaAsync = helpers.runMochaAsync;
@@ -65,4 +66,19 @@ describe('esm', function() {
6566
done();
6667
});
6768
});
69+
70+
it('should enable requiring/loading a cjs module with "dir" as filename', async function() {
71+
var fixture = 'esm/test-that-uses-dir-cjs-require.fixture.js';
72+
const result = await runMochaAsync(
73+
fixture,
74+
[
75+
...args,
76+
'--require',
77+
path.resolve(__dirname, './fixtures/esm/dir-cjs-require')
78+
],
79+
{stdio: 'pipe'}
80+
);
81+
82+
expect(result, 'to have passed test count', 1);
83+
});
6884
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.testPassesIfThisVariableIsDefined = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// See https://github.com/mochajs/mocha/issues/4665 for an explanation of this test
2+
it('should require a dir import', () => {
3+
expect(global.testPassesIfThisVariableIsDefined, 'to be', true)
4+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy