From 9639352a3bf3a47254e7526e54217663fffe67dc Mon Sep 17 00:00:00 2001 From: EGOIST Date: Tue, 14 Feb 2023 17:17:31 +0800 Subject: [PATCH] refactor(plugin-api): expose entryPoint and more info in chunkInfo --- src/plugin.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index 1a8e31a8..d42410a7 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -16,6 +16,9 @@ export type ChunkInfo = { * Sets the file mode */ mode?: number + entryPoint?: string + exports?: string[] + imports?: Metafile['outputs'][string]['imports'] } export type AssetInfo = { @@ -119,13 +122,18 @@ export class PluginContainer { }) { const files: Array = outputFiles .filter((file) => !file.path.endsWith('.map')) - .map((file) => { + .map((file): ChunkInfo | AssetInfo => { if (isJS(file.path) || isCSS(file.path)) { + const relativePath = path.relative(process.cwd(), file.path) + const meta = metafile?.outputs[relativePath] return { type: 'chunk', path: file.path, code: file.text, map: outputFiles.find((f) => f.path === `${file.path}.map`)?.text, + entryPoint: meta?.entryPoint, + exports: meta?.exports, + imports: meta?.imports, } } else { return { type: 'asset', path: file.path, contents: file.contents }