Skip to content

Commit

Permalink
Migrating process.binding('config') to getOptions() in default_resolv…
Browse files Browse the repository at this point in the history
…e.js
  • Loading branch information
jonnyk20 committed Oct 12, 2018
1 parent bcbb937 commit 41c5fa2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const internalFS = require('internal/fs/utils');
const { NativeModule } = require('internal/bootstrap/loaders');
const { extname } = require('path');
const { realpathSync } = require('fs');
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
const preserveSymlinksMain = !!process.binding('config').preserveSymlinksMain;
const { getOptions } = internalBinding('options');
const preserveSymlinks = !!getOptions('--preserve-symlinks');
const preserveSymlinksMain = !!getOptions('--preserve-symlinks-main');
const {
ERR_MISSING_MODULE,
ERR_MODULE_RESOLUTION_LEGACY,
Expand All @@ -33,7 +34,8 @@ function search(target, base) {
const questionedBase = new URL(base);
const tmpMod = new CJSmodule(questionedBase.pathname, null);
tmpMod.paths = CJSmodule._nodeModulePaths(
new URL('./', questionedBase).pathname);
new URL('./', questionedBase).pathname
);
const found = CJSmodule._resolveFilename(target, tmpMod);
error = new ERR_MODULE_RESOLUTION_LEGACY(target, base, found);
} catch (problemChecking) {
Expand Down Expand Up @@ -61,11 +63,15 @@ function resolve(specifier, parentURL) {

let url;
try {
url = search(specifier,
parentURL || pathToFileURL(`${process.cwd()}/`).href);
url = search(
specifier,
parentURL || pathToFileURL(`${process.cwd()}/`).href
);
} catch (e) {
if (typeof e.message === 'string' &&
StringStartsWith(e.message, 'Cannot find module'))
if (
typeof e.message === 'string' &&
StringStartsWith(e.message, 'Cannot find module')
)
e.code = 'MODULE_NOT_FOUND';
throw e;
}
Expand All @@ -86,10 +92,8 @@ function resolve(specifier, parentURL) {

let format = extensionFormatMap[ext];
if (!format) {
if (isMain)
format = 'cjs';
else
throw new ERR_UNKNOWN_FILE_EXTENSION(url.pathname);
if (isMain) format = 'cjs';
else throw new ERR_UNKNOWN_FILE_EXTENSION(url.pathname);
}

return { url: `${url}`, format };
Expand Down

0 comments on commit 41c5fa2

Please sign in to comment.