-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
- Version: v12.0.0
- Platform: macOS 10.14.4
- Subsystem: module
Calling createRequireFromPath('.') does not honour process.cwd() when called a second time after an effective call to process.chdir(…).
Best explained by this: https://github.com/SMotaal/esm/blob/master/tests/create-require.mjs#L8
import {createRequireFromPath} from 'module';
import {fileURLToPath} from 'url';
const specifier = './package.json';
const [scope, ...paths] = ['../../', '../', './'].map(path => fileURLToPath(new URL(path, import.meta.url)));
const sanitize = path => path.replace(scope, '‹scope›/');
for (const path of process.argv.includes('-t2') ? paths.reverse() : paths) {
process.chdir(path);
console.group('\nprocess.chdir(%o)', sanitize(process.cwd()));
console.log();
try {
const require = createRequireFromPath('.');
console.log(
`createRequireFromPath(%o)\n .resolve(%o)\n => %o`,
'.',
specifier,
sanitize(require.resolve(specifier)),
);
} catch (exception) {
console.warn(
`createRequireFromPath(%o)\n .resolve(%o)\n => %o`,
'.',
specifier,
`${exception}`.split('\n', 1)[0],
);
}
console.log();
console.groupEnd();
}
/*******************************************************************************
* $ node --experimental-modules esm/tests/create-require.mjs
*
* process.chdir('‹scope›/esm/')
*
* createRequireFromPath('.')
* .resolve('./package.json')
* => '‹scope›/esm/package.json'
*
* process.chdir('‹scope›/esm/tests/')
*
* createRequireFromPath('.')
* .resolve('./package.json')
* => '‹scope›/esm/package.json'
*
******************************************************************************
* $ node --experimental-modules esm/tests/create-require.mjs -t2
*
* process.chdir('‹scope›/esm/tests/')
*
* createRequireFromPath('.')
* .resolve('./package.json')
* => '‹scope›/esm/tests/package.json'
*
* process.chdir('‹scope›/esm/')
*
* createRequireFromPath('.')
* .resolve('./package.json')
* => '‹scope›/esm/tests/package.json'
*
******************************************************************************/Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.