From 6d1a6e51118d1c4bd45cb21fad337ac2f87c8aa1 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 4 Oct 2023 20:07:33 -0700 Subject: [PATCH] Optimize --- lib/internal/modules/run_main.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js index 0a50813499d3c1e..d130522af2d797a 100644 --- a/lib/internal/modules/run_main.js +++ b/lib/internal/modules/run_main.js @@ -12,6 +12,8 @@ const path = require('path'); * @param {string} main - Entry point path */ function resolveMainPath(main) { + if (getOptionValue('--preserve-symlinks-main')) { return; } + const defaultType = getOptionValue('--experimental-default-type'); /** @type {string} */ let mainPath; @@ -25,21 +27,18 @@ function resolveMainPath(main) { } if (!mainPath) { return; } - const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); - if (!preserveSymlinksMain) { - const { toRealPath } = require('internal/modules/helpers'); - try { - mainPath = toRealPath(mainPath); - } catch (err) { - if (err.code === 'ENOENT' && defaultType === 'module') { - const { decorateErrorWithCommonJSHints } = require('internal/modules/esm/resolve'); - const { getCWDURL } = require('internal/util'); - decorateErrorWithCommonJSHints(err, mainPath, getCWDURL()); - } - throw err; + // Follow symlinks + const { toRealPath } = require('internal/modules/helpers'); + try { + mainPath = toRealPath(mainPath); + } catch (err) { + if (err.code === 'ENOENT' && defaultType === 'module') { + const { decorateErrorWithCommonJSHints } = require('internal/modules/esm/resolve'); + const { getCWDURL } = require('internal/util'); + decorateErrorWithCommonJSHints(err, mainPath, getCWDURL()); } + throw err; } - return mainPath; }