Commit c908f9e
authored
fix: enhance js plugin hook error like rollup (#2767)
### Description
- related #2551
As requested in #2551, this
automatically injects plugin, hook name, etc.. to errors thrown by js
plugin. I also updated error summary formatting to include those
details.
<details><summary>Example</summary>
For the following plugin:
```js
plugins: [
{
name: 'my-plugin',
transform() {
this.error("my-error", 2)
}
}
]
```
Build error now shows this:
```
$ pnpm -C examples/basic-typescript build
> @example/typescript@ build /home/hiroshi/code/others/rolldown/examples/basic-typescript
> rolldown --config ./rolldown.config.js
file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:168
const wrapper = new Error(summary);
^
Error: Build failed with 1 error:
[plugin my-plugin] /home/hiroshi/code/others/rolldown/examples/basic-typescript/index.ts:1:2
RollupError: my-error
1: import { hello } from './hello'
^
2:
3: console.log(hello())
at error (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:817:24)
at TransformPluginContext.error (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:1321:11)
at TransformPluginContext.transform (file:///home/hiroshi/code/others/rolldown/examples/basic-typescript/rolldown.config.js:17:14)
at plugin (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:1537:25)
at handleOutputErrors (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:168:19)
at transformToRollupOutput (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:152:2)
at RolldownBuild.write (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-f-_TEmuT.mjs:2907:10)
at async bundleInner (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/esm/cli.mjs:393:23) {
errors: [Getter/Setter]
}
Node.js v20.18.0
```
which previously was
```
$ pnpm -C examples/basic-typescript build
> @example/typescript@ build /home/hiroshi/code/others/rolldown/examples/basic-typescript
> rolldown --config ./rolldown.config.js
file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:169
const wrapper = new Error(summary);
^
Error: Build failed with 1 error:
RollupError: my-error
at error (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:790:24)
at TransformPluginContext.error (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:1294:11)
at TransformPluginContext.transform (file:///home/hiroshi/code/others/rolldown/examples/basic-typescript/rolldown.config.js:17:14)
at plugin (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:1490:30)
at handleOutputErrors (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:169:19)
at transformToRollupOutput (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:152:2)
at RolldownBuild.write (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/shared/src_index-BcFJfRrY.mjs:2786:10)
at async bundleInner (file:///home/hiroshi/code/others/rolldown/packages/rolldown/dist/esm/cli.mjs:393:23) {
errors: [Getter/Setter]
}
```
</details>1 parent 9eb7103 commit c908f9e
8 files changed
Lines changed: 133 additions & 3 deletions
File tree
- packages/rolldown
- src
- plugin
- utils
- tests/fixtures/misc/error
- load
- plugin-context
- renderChunk
- resolveId
- transform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
195 | 239 | | |
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
159 | 191 | | |
160 | 192 | | |
161 | 193 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
0 commit comments