Skip to content

Commit

Permalink
fix: plugin warnings not showing warning.loc (#3824)
Browse files Browse the repository at this point in the history
* fix: plugin warnings not showing warning.loc

Plugin warnings without warning.id but with warning.loc were not emitting loc information
loc information emitting is fundamental for user experience (to locate the source of the error/warning)

* Update batchWarnings.ts

* Add test

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 21, 2020
1 parent b794a13 commit 53e30e2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cli/run/batchWarnings.ts
Expand Up @@ -189,8 +189,9 @@ const deferredHandlers: {
for (const warning of items) {
if (warning.url && warning.url !== lastUrl) info((lastUrl = warning.url));

if (warning.id) {
let loc = relativeId(warning.id);
const id = warning.id || warning.loc?.file;
if (id) {
let loc = relativeId(id);
if (warning.loc) {
loc += `: (${warning.loc.line}:${warning.loc.column})`;
}
Expand Down
17 changes: 17 additions & 0 deletions test/cli/samples/warn-plugin-loc/_config.js
@@ -0,0 +1,17 @@
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'correctly adds locations to plugin warnings',
command: 'rollup -c',
stderr: stderr => {
assertIncludes(
stderr,
'(!) Plugin test: Warning with file and id\n' +
'file1: (1:2)\n' +
'(!) Plugin test: Warning with file\n' +
'file2: (2:3)\n' +
'(!) Plugin test: Warning with id\n' +
'file-id3: (3:4)\n'
);
}
};
1 change: 1 addition & 0 deletions test/cli/samples/warn-plugin-loc/main.js
@@ -0,0 +1 @@
console.log("everyday I'm throwing");
29 changes: 29 additions & 0 deletions test/cli/samples/warn-plugin-loc/rollup.config.js
@@ -0,0 +1,29 @@
const path = require('path');

module.exports = {
input: 'main.js',
output: {
format: 'cjs'
},
plugins: [
{
name: 'test',
buildStart() {
this.warn({
message: 'Warning with file and id',
file: path.join(__dirname, 'file-id1'),
loc: { file: path.join(__dirname, 'file1'), line: 1, column: 2 }
});
this.warn({
message: 'Warning with file',
loc: { file: path.join(__dirname, 'file2'), line: 2, column: 3 }
});
this.warn({
message: 'Warning with id',
id: path.join(__dirname, 'file-id3'),
loc: { line: 3, column: 4 }
});
}
}
]
};

0 comments on commit 53e30e2

Please sign in to comment.