forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: fix submodules loaded by require() and import()
Previously there is an edge case where submodules loaded by require() may not be loaded by import() again from different intermediate edges in the graph. This patch fixes that, added tests, and added debug logs. Drive-by: make loader a private field so it doesn't show up in logs. PR-URL: nodejs#52487 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
1 parent
e258303
commit 7298d8d
Showing
8 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Flags: --experimental-require-module | ||
'use strict'; | ||
|
||
// This tests that previously synchronously loaded submodule can still | ||
// be loaded by dynamic import(). | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
(async () => { | ||
const required = require('../fixtures/es-modules/require-and-import/load.cjs'); | ||
const imported = await import('../fixtures/es-modules/require-and-import/load.mjs'); | ||
assert.deepStrictEqual({ ...required }, { ...imported }); | ||
})().then(common.mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Flags: --experimental-require-module | ||
'use strict'; | ||
|
||
// This tests that previously asynchronously loaded submodule can still | ||
// be loaded by require(). | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
(async () => { | ||
const imported = await import('../fixtures/es-modules/require-and-import/load.mjs'); | ||
const required = require('../fixtures/es-modules/require-and-import/load.cjs'); | ||
assert.deepStrictEqual({ ...required }, { ...imported }); | ||
})().then(common.mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports = require('dep'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from 'dep'; | ||
|
2 changes: 2 additions & 0 deletions
2
test/fixtures/es-modules/require-and-import/node_modules/dep/mod.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
test/fixtures/es-modules/require-and-import/node_modules/dep/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.