build: fix es2015 resolution issue in ng_rollup_bundle tool (#33808)
This fixes an issue bundling es2015 with ng_rollup_bundle that was covered up by a typo when refactoring ng_rollup_bundle to not use legacy rollup_bundle internals and to use the new terser_minified rule and npm_package_bin to call brotli. Note: ng_rollup_bundle is only used in the angular repo and not externally so this issue does not affect users PR Close #33808
This commit is contained in:
parent
a67cb92e6b
commit
e7dd7525cb
|
@ -55,6 +55,7 @@ function resolveBazel(
|
||||||
log_verbose(`resolving '${importee}' from ${importer}`);
|
log_verbose(`resolving '${importee}' from ${importer}`);
|
||||||
|
|
||||||
function resolveInRootDir(importee) {
|
function resolveInRootDir(importee) {
|
||||||
|
function tryImportee(importee) {
|
||||||
var candidate = path.join(baseDir, root, importee);
|
var candidate = path.join(baseDir, root, importee);
|
||||||
log_verbose(`try to resolve '${importee}' at '${candidate}'`);
|
log_verbose(`try to resolve '${importee}' at '${candidate}'`);
|
||||||
try {
|
try {
|
||||||
|
@ -64,6 +65,18 @@ function resolveBazel(
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Attempt to resovle first as specified, then in the following order
|
||||||
|
// {importee}.mjs, {importee}/index.mjs, {importee}.js, {importee}/index.js.
|
||||||
|
// TODO(gregmagolan): clean this up in the future as the .mjs es2015 outputs
|
||||||
|
// along side the .js es5 outputs from ts_library creates this unusual situation for
|
||||||
|
// which we can't rely on standard node module resolution to do the right thing.
|
||||||
|
// In the future ts_library (or equivalent) should only produce a single flavor of
|
||||||
|
// output and ng_rollup_bundle should also just use the use the vanilla rollup_bundle
|
||||||
|
// rule without the need for a custom bazel resolver.
|
||||||
|
return tryImportee(importee) || tryImportee(`${importee}.mjs`) ||
|
||||||
|
tryImportee(`${importee}/index.mjs`) || tryImportee(`${importee}.js`) ||
|
||||||
|
tryImportee(`${importee}/index.js`);
|
||||||
|
}
|
||||||
|
|
||||||
// Since mappings are always in POSIX paths, when comparing the importee to mappings
|
// Since mappings are always in POSIX paths, when comparing the importee to mappings
|
||||||
// we should normalize the importee.
|
// we should normalize the importee.
|
||||||
|
@ -117,13 +130,6 @@ function resolveBazel(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
if (path.extname(resolved) == '.js') {
|
|
||||||
// check for .mjs file and prioritize that
|
|
||||||
const resolved_mjs = resolved.substr(0, resolved.length - 3) + '.mjs';
|
|
||||||
if (fileExists(resolved_mjs)) {
|
|
||||||
resolved = resolved_mjs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log_verbose(`resolved to ${resolved}`);
|
log_verbose(`resolved to ${resolved}`);
|
||||||
} else {
|
} else {
|
||||||
log_verbose(`allowing rollup to resolve '${importee}' with node module resolution`);
|
log_verbose(`allowing rollup to resolve '${importee}' with node module resolution`);
|
||||||
|
|
Loading…
Reference in New Issue