From 3cc5a8c231eaeed31215807158ef9f6070e18c8f Mon Sep 17 00:00:00 2001 From: "Lucio M. Tato" Date: Fri, 16 Oct 2020 19:48:36 -0300 Subject: [PATCH 1/3] 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) --- cli/run/batchWarnings.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index 36d3afc41f2..b0c2d67c2d9 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -196,6 +196,9 @@ const deferredHandlers: { } stderr(bold(loc)); } + else if (warning.loc) { + info(yellow(`${rollup.relativeId(warning.loc.file)}:${warning.loc.line}:${warning.loc.column}`)+' error '+message); + } if (warning.frame) info(warning.frame); } } From a8739730509ad26eb251ed9af9dddbd705b64cae Mon Sep 17 00:00:00 2001 From: "Lucio M. Tato" Date: Wed, 21 Oct 2020 01:01:15 -0300 Subject: [PATCH 2/3] Update batchWarnings.ts --- cli/run/batchWarnings.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cli/run/batchWarnings.ts b/cli/run/batchWarnings.ts index b0c2d67c2d9..1fe3d03ae30 100644 --- a/cli/run/batchWarnings.ts +++ b/cli/run/batchWarnings.ts @@ -189,16 +189,14 @@ 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})`; } stderr(bold(loc)); } - else if (warning.loc) { - info(yellow(`${rollup.relativeId(warning.loc.file)}:${warning.loc.line}:${warning.loc.column}`)+' error '+message); - } if (warning.frame) info(warning.frame); } } From e3d72ca5337f9d9e77ed630f0eaecbda056d7ec0 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 21 Oct 2020 06:31:56 +0200 Subject: [PATCH 3/3] Add test --- test/cli/samples/warn-plugin-loc/_config.js | 17 +++++++++++ test/cli/samples/warn-plugin-loc/main.js | 1 + .../samples/warn-plugin-loc/rollup.config.js | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/cli/samples/warn-plugin-loc/_config.js create mode 100644 test/cli/samples/warn-plugin-loc/main.js create mode 100644 test/cli/samples/warn-plugin-loc/rollup.config.js diff --git a/test/cli/samples/warn-plugin-loc/_config.js b/test/cli/samples/warn-plugin-loc/_config.js new file mode 100644 index 00000000000..8b8f52bb4e9 --- /dev/null +++ b/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' + ); + } +}; diff --git a/test/cli/samples/warn-plugin-loc/main.js b/test/cli/samples/warn-plugin-loc/main.js new file mode 100644 index 00000000000..983961490bb --- /dev/null +++ b/test/cli/samples/warn-plugin-loc/main.js @@ -0,0 +1 @@ +console.log("everyday I'm throwing"); diff --git a/test/cli/samples/warn-plugin-loc/rollup.config.js b/test/cli/samples/warn-plugin-loc/rollup.config.js new file mode 100644 index 00000000000..78f47655e95 --- /dev/null +++ b/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 } + }); + } + } + ] +};