fix(bazel): fix incorrect rollup plugin method signature (#41101)

Update the resolveBazel method signature to align with the rollup plugin
resolveId API: https://rollupjs.org/guide/en/#resolveid

PR Close #41101
This commit is contained in:
Jason Bedard 2021-03-05 21:39:55 -08:00 committed by Andrew Kushnir
parent 1735430476
commit 5c4914deff
1 changed files with 6 additions and 5 deletions

View File

@ -49,15 +49,16 @@ function fileExists(filePath) {
// This resolver mimics the TypeScript Path Mapping feature, which lets us resolve // This resolver mimics the TypeScript Path Mapping feature, which lets us resolve
// modules based on a mapping of short names to paths. // modules based on a mapping of short names to paths.
function resolveBazel( function resolveBazel(importee, importer) {
importee, importer, baseDir = process.cwd(), resolve = require.resolve, root = rootDir) {
log_verbose(`resolving '${importee}' from ${importer}`); log_verbose(`resolving '${importee}' from ${importer}`);
const baseDir = process.cwd();
function resolveInRootDir(importee) { function resolveInRootDir(importee) {
var candidate = path.join(baseDir, root, importee); var candidate = path.join(baseDir, rootDir, importee);
log_verbose(`try to resolve '${importee}' at '${candidate}'`); log_verbose(`try to resolve '${importee}' at '${candidate}'`);
try { try {
var result = resolve(candidate); var result = require.resolve(candidate);
return result; return result;
} catch (e) { } catch (e) {
return undefined; return undefined;
@ -80,7 +81,7 @@ function resolveBazel(
// relative import // relative import
if (importer) { if (importer) {
let importerRootRelative = path.dirname(importer); let importerRootRelative = path.dirname(importer);
const relative = path.relative(path.join(baseDir, root), importerRootRelative); const relative = path.relative(path.join(baseDir, rootDir), importerRootRelative);
if (!relative.startsWith('.')) { if (!relative.startsWith('.')) {
importerRootRelative = relative; importerRootRelative = relative;
} }