Skip to content

Commit

Permalink
util: use in other scenarios of internal/modules
Browse files Browse the repository at this point in the history
Use `getCwdSafe` in other scenarios of `internal/modules` package.
  • Loading branch information
jlenon7 committed Jun 12, 2023
1 parent 4afce30 commit b52c56a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const {
kEmptyObject,
filterOwnProperties,
setOwnProperty,
getCwdSafe,
getLazy,
} = require('internal/util');
const { internalCompileFunction } = require('internal/vm');
Expand Down Expand Up @@ -1025,7 +1026,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
}

if (request[0] === '#' && (parent?.filename || parent?.id === '<repl>')) {
const parentPath = parent?.filename ?? process.cwd() + path.sep;
const parentPath = parent?.filename ?? getCwdSafe();
const pkg = readPackageScope(parentPath) || {};
if (pkg.data?.imports != null) {
try {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const experimentalNetworkImports =
getOptionValue('--experimental-network-imports');
const typeFlag = getOptionValue('--input-type');
const { URL, pathToFileURL, fileURLToPath, isURL, toPathIfFileURL } = require('internal/url');
const { getCwdSafe } = require('internal/util');
const { canParse: URLCanParse } = internalBinding('url');
const {
ERR_INPUT_TYPE_NOT_ALLOWED,
Expand Down Expand Up @@ -1018,7 +1019,7 @@ function defaultResolve(specifier, context = {}) {

const isMain = parentURL === undefined;
if (isMain) {
parentURL = pathToFileURL(`${process.cwd()}/`).href;
parentURL = pathToFileURL(getCwdSafe()).href;

// This is the initial entry point to the program, and --input-type has
// been passed as an option; but --input-type can only be used with
Expand Down

0 comments on commit b52c56a

Please sign in to comment.