-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: self referential modules in repl or
-r
Load self referential modules from the repl and using the preload flag `-r`. In both cases the base path used for resolution is the current `process.cwd()`. Also fixes an internal cycle bug in the REPL exports resolution. PR-URL: #32261 Fixes: #31595 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
- Loading branch information
1 parent
cbe6385
commit e1199af
Showing
7 changed files
with
94 additions
and
8 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
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,4 @@ | ||
'use strict' | ||
|
||
module.exports = 'Self resolution working'; | ||
|
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,13 @@ | ||
{ | ||
"name": "self_ref", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"exports": "./index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const { exec } = require('child_process'); | ||
|
||
const nodeBinary = process.argv[0]; | ||
|
||
if (!common.isMainThread) | ||
common.skip('process.chdir is not available in Workers'); | ||
|
||
const selfRefModule = fixtures.path('self_ref_module'); | ||
const fixtureA = fixtures.path('printA.js'); | ||
|
||
exec(`"${nodeBinary}" -r self_ref "${fixtureA}"`, { cwd: selfRefModule }, | ||
(err, stdout, stderr) => { | ||
assert.ifError(err); | ||
assert.strictEqual(stdout, 'A\n'); | ||
}); |
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,25 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const { spawn } = require('child_process'); | ||
|
||
if (!common.isMainThread) | ||
common.skip('process.chdir is not available in Workers'); | ||
|
||
const selfRefModule = fixtures.path('self_ref_module'); | ||
const child = spawn(process.execPath, | ||
['--interactive'], | ||
{ cwd: selfRefModule } | ||
); | ||
let output = ''; | ||
child.stdout.on('data', (chunk) => output += chunk); | ||
child.on('exit', common.mustCall(() => { | ||
const results = output.replace(/^> /mg, '').split('\n').slice(2); | ||
assert.deepStrictEqual(results, [ "'Self resolution working'", '' ]); | ||
})); | ||
|
||
child.stdin.write('require("self_ref");\n'); | ||
child.stdin.write('.exit'); | ||
child.stdin.end(); |