Skip to content

Commit a6ea3f8

Browse files
authored
feat: append plugin name to logs (#205)
1 parent 849736d commit a6ea3f8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,7 @@ test.skip('adjust worker build error for worker.format', async () => {
886886
expect.unreachable()
887887
})
888888

889-
// rolldown does not append plugin name to the message automatically
890-
describe.skip('onRollupLog', () => {
889+
describe('onRollupLog', () => {
891890
const pluginName = 'rollup-plugin-test'
892891
const msgInfo = 'This is the INFO message.'
893892
const msgWarn = 'This is the WARN message.'
@@ -980,7 +979,7 @@ describe.skip('onRollupLog', () => {
980979
},
981980
})
982981
expect(onLogInfo).toBeCalledWith(
983-
expect.objectContaining({ message: `[plugin ${pluginName}] ${msgInfo}` }),
982+
expect.objectContaining({ message: msgInfo, plugin: pluginName }),
984983
)
985984
})
986985

@@ -994,7 +993,7 @@ describe.skip('onRollupLog', () => {
994993
},
995994
})
996995
expect(onWarn).toBeCalledWith(
997-
expect.objectContaining({ message: `[plugin ${pluginName}] ${msgWarn}` }),
996+
expect.objectContaining({ message: msgWarn, plugin: pluginName }),
998997
)
999998
})
1000999

packages/vite/src/node/build.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,23 +1134,29 @@ export function onRollupLog(
11341134
}
11351135
}
11361136

1137+
// append plugin name to align with Rollup's behavior
1138+
let message = logging.message
1139+
if (logging.plugin) {
1140+
message = `[plugin ${logging.plugin}] ${message}`
1141+
}
1142+
11371143
switch (logLeveling) {
11381144
case 'info':
1139-
environment.logger.info(logging.message)
1145+
environment.logger.info(message)
11401146
return
11411147
case 'warn':
1142-
environment.logger.warn(colors.yellow(logging.message))
1148+
environment.logger.warn(colors.yellow(message))
11431149
return
11441150
case 'error':
1145-
environment.logger.error(colors.red(logging.message))
1151+
environment.logger.error(colors.red(message))
11461152
return
11471153
case 'debug':
1148-
debugLogger?.(logging.message)
1154+
debugLogger?.(message)
11491155
return
11501156
default:
11511157
logLeveling satisfies never
11521158
// fallback to info if a unknown log level is passed
1153-
environment.logger.info(logging.message)
1159+
environment.logger.info(message)
11541160
return
11551161
}
11561162
}

0 commit comments

Comments
 (0)