Skip to content

Commit

Permalink
Inline function to avoid mutating params
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcorlin1 committed May 26, 2024
1 parent 6138634 commit c8f9826
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/esbuild-plugin-node/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ export function openTelemetryPlugin(
};
}

// @see https://github.com/nodejs/node/issues/47000
function dotFriendlyResolve(path: string, directory: string): string {
if (path === '.') {
path = './';
} else if (path === '..') {
path = '../';
}
return require.resolve(path, { paths: [directory] });
}

/**
* For a given full path to a module,
* return the package name it belongs to and the local path to the module
Expand All @@ -135,7 +125,11 @@ function extractPackageAndModulePath(
path: string,
resolveDir: string
): { path: string; extractedModule: ExtractedModule } {
const fullPath = dotFriendlyResolve(path, resolveDir);
// @see https://github.com/nodejs/node/issues/47000
const fullPath = require.resolve(
path === '.' ? './' : path === '..' ? '../' : path,
{ paths: [resolveDir] }
);

const nodeModulesIndex = fullPath.lastIndexOf(NODE_MODULES);
if (nodeModulesIndex < 0) {
Expand Down

0 comments on commit c8f9826

Please sign in to comment.