forked from module-federation/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchers.ts
More file actions
39 lines (33 loc) · 1.23 KB
/
matchers.ts
File metadata and controls
39 lines (33 loc) · 1.23 KB
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
37
38
39
import type { Rollup } from 'vite';
import { isRollupAsset, isRollupChunk } from './assertions';
export function getChunkNames(output: Rollup.RollupOutput) {
return output.output.filter(isRollupChunk).map((c) => c.fileName);
}
export function findChunk(
output: Rollup.RollupOutput,
test: string | RegExp
): Rollup.OutputChunk | undefined {
return output.output
.filter(isRollupChunk)
.find((o) => (typeof test === 'string' ? o.fileName.includes(test) : test.test(o.fileName)));
}
export function findAsset(
output: Rollup.RollupOutput,
test: string
): Rollup.OutputAsset | undefined {
return output.output.filter(isRollupAsset).find((o) => o.fileName.includes(test));
}
export function getAllChunkCode(output: Rollup.RollupOutput): string {
return output.output
.filter(isRollupChunk)
.map((c) => c.code)
.join('\n');
}
export function getHtmlAsset(output: Rollup.RollupOutput): Rollup.OutputAsset | undefined {
return output.output.filter(isRollupAsset).find((o) => o.fileName.endsWith('.html'));
}
export function parseManifest(output: Rollup.RollupOutput): object | undefined {
const asset = findAsset(output, 'mf-manifest.json');
if (!asset) return undefined;
return JSON.parse(asset.source as string);
}