Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin warnings not showing warning.loc #3824

Merged
merged 4 commits into from Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }
});
}
}
]
};