diff --git a/internal/rollup/rollup.config.js b/internal/rollup/rollup.config.js index 69bd3f3575..22a5acd3a8 100644 --- a/internal/rollup/rollup.config.js +++ b/internal/rollup/rollup.config.js @@ -154,26 +154,26 @@ const inputs = [TMPL_inputs]; const enableCodeSplitting = inputs.length > 1; const config = { - resolveBazel, - banner, - onwarn: (warning) => { + onwarn: ({loc, frame, message}) => { // Always fail on warnings, assuming we don't know which are harmless. // We can add exclusions here based on warning.code, if we discover some // types of warning should always be ignored under bazel. - throw new Error(warning.message); + if (loc) { + throw new Error(`${loc.file} (${loc.line}:${loc.column}) ${message}`); + } + throw new Error(message); }, plugins: [TMPL_additional_plugins].concat([ - {resolveId: resolveBazel}, + {name: 'bazel-resolve', resolveId: resolveBazel}, nodeResolve( {jsnext: true, module: true, customResolveOptions: {moduleDirectory: nodeModulesRoot}}), - {resolveId: notResolved}, + {name: 'bazel-not-resolved', resolveId: notResolved}, sourcemaps(), ]) } if (enableCodeSplitting) { config.experimentalCodeSplitting = true; - config.experimentalDynamicImport = true; config.input = inputs; config.output = { format: 'TMPL_output_format', @@ -190,4 +190,6 @@ else { }; } +config.output.banner = banner; + module.exports = config; diff --git a/internal/rollup/rollup.config.spec.js b/internal/rollup/rollup.config.spec.js index 3620774340..54af7d98ff 100644 --- a/internal/rollup/rollup.config.spec.js +++ b/internal/rollup/rollup.config.spec.js @@ -31,9 +31,10 @@ const resolve = } const rollupConfig = require('./rollup.config'); +const resolveBazel = rollupConfig.plugins.find(({name}) => name === 'bazel-resolve').resolveId; function doResolve(importee, importer) { - const resolved = rollupConfig.resolveBazel(importee, importer, baseDir, resolve, rootDir); + const resolved = resolveBazel(importee, importer, baseDir, resolve, rootDir); if (resolved) { return resolved.replace(/\\/g, '/'); } else { @@ -72,7 +73,7 @@ describe('rollup config', () => { expect(doResolve(`other${sep}thing`)) .toEqual(`${baseDir}/bazel-bin/path/to/a.esm5/external/other_wksp/path/to/other_lib/thing`); expect(doResolve(`@bar${sep}baz${sep}foo`)) - .toEqual(`${baseDir}/bazel-bin/path/to/a.esm5/path/to/bar/baz_lib/foo`); + .toEqual(`${baseDir}/bazel-bin/path/to/a.esm5/path/to/bar/baz_lib/foo`); }); it('should find paths in any root', () => { diff --git a/internal/rollup/rollup_bundle.bzl b/internal/rollup/rollup_bundle.bzl index 99174bb218..ef915ee6d3 100644 --- a/internal/rollup/rollup_bundle.bzl +++ b/internal/rollup/rollup_bundle.bzl @@ -169,7 +169,10 @@ def _run_rollup(ctx, sources, config, output, map_output = None): # We will produce errors as needed. Anything else is spammy: a well-behaved # bazel rule prints nothing on success. - args.add("--silent") + # + # TODO(https://github.com/rollup/rollup/issues/2582): Uncomment the following + # line once rollup stops reporting build errors with onwarn. + # args.add("--silent") if ctx.attr.globals: args.add("--external")