Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Oct 5, 2023
1 parent 36cd484 commit 6d1a6e5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/internal/modules/run_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 6d1a6e5

Please sign in to comment.