From 41c5fa21e2fe61e9bb4e7e715257d7fca971f988 Mon Sep 17 00:00:00 2001 From: Jonny Kalambay Date: Fri, 12 Oct 2018 10:11:51 -0700 Subject: [PATCH] Migrating process.binding('config') to getOptions() in default_resolve.js --- lib/internal/modules/esm/default_resolve.js | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 8f8efcb5360d63..236699c5c973a2 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -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, @@ -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) { @@ -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; } @@ -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 };