Skip to content

Commit b6ee592

Browse files
committed
feat(): add rollup module info to stats and upgrade rollup.
1 parent e1314be commit b6ee592

6 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"estree-walker": "^0.5.2",
5353
"jsdom": "11.11.0",
5454
"magic-string": "^0.22.5",
55-
"rollup": "0.64.1",
55+
"rollup": "0.65.0",
5656
"rollup-plugin-commonjs": "9.1.5",
5757
"rollup-plugin-node-builtins": "2.1.2",
5858
"rollup-plugin-node-resolve": "3.3.0",

‎src/compiler/build/build-results.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export function generateBuildResults(config: d.Config, compilerCtx: d.CompilerCt
2929
transpileBuildCount: buildCtx.transpileBuildCount,
3030

3131
components: [],
32-
3332
entries: generateBuildResultsEntries(config, buildCtx)
3433
};
3534

‎src/compiler/build/build-stats.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export async function generateStatsOutputTarget(config: d.Config, compilerCtx: d
4545
},
4646
components: buildResults.components,
4747
entries: buildResults.entries,
48+
rollupResults: buildCtx.rollupResults,
4849
sourceGraph: {},
4950
collections: buildCtx.collections.map(c => {
5051
return {

‎src/compiler/bundle/rollup-bundle.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import nodeEnvVars from './rollup-plugins/node-env-vars';
1010
import pathsResolution from './rollup-plugins/paths-resolution';
1111
import rollupPluginReplace from './rollup-plugins/rollup-plugin-replace';
1212
import globals from './rollup-plugins/node-globals';
13+
import statsPlugin from './rollup-plugins/rollup-stats-plugin';
1314

1415

1516
export async function createBundle(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, entryModules: d.EntryModule[]) {
@@ -65,6 +66,7 @@ export async function createBundle(config: d.Config, compilerCtx: d.CompilerCtx,
6566
localResolution(config, compilerCtx),
6667
nodeEnvVars(config),
6768
...config.plugins,
69+
statsPlugin(buildCtx),
6870
abortPlugin(buildCtx)
6971
],
7072
onwarn: createOnWarnFn(config, buildCtx.diagnostics)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { OutputChunk, Plugin } from 'rollup';
2+
import * as d from '../../../declarations';
3+
4+
function sortBundles(a: OutputChunk, b: OutputChunk) {
5+
if (a.isEntry && !b.isEntry) {
6+
return -1;
7+
}
8+
if (b.isEntry) {
9+
return 1;
10+
}
11+
12+
const nameA = a.fileName.toUpperCase();
13+
const nameB = b.fileName.toUpperCase();
14+
if (nameA < nameB) {
15+
return -1;
16+
}
17+
if (nameA > nameB) {
18+
return 1;
19+
}
20+
return 0;
21+
}
22+
23+
export default function statsPlugin(buildCtx: d.BuildCtx) {
24+
const plugin: Plugin = {
25+
name: 'stats-plugin',
26+
generateBundle(options, bundle) {
27+
options;
28+
const modules = Object.keys(bundle)
29+
.map(b => bundle[b])
30+
.sort(sortBundles)
31+
.map((b: OutputChunk) => {
32+
return {
33+
id: b.fileName,
34+
isEntry: b.isEntry,
35+
imports: b.imports.filter(i => !!i),
36+
exports: b.exports,
37+
modules: Object.keys(b.modules).map(m => ({
38+
filename: m,
39+
exports: b.modules[m].renderedExports
40+
}))
41+
};
42+
});
43+
44+
buildCtx.rollupResults = {
45+
modules: modules
46+
};
47+
}
48+
};
49+
50+
return plugin;
51+
}

‎src/declarations/build.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as d from '.';
22

3+
export interface RollupResultModule {
4+
id: string;
5+
}
6+
export interface RollupResults {
7+
modules: RollupResultModule[];
8+
}
39

410
export interface BuildCtx {
511
abort(): Promise<BuildResults>;
@@ -44,6 +50,7 @@ export interface BuildCtx {
4450
scriptsAdded: string[];
4551
scriptsDeleted: string[];
4652
hasError: boolean;
53+
rollupResults?: RollupResults;
4754
startTime: number;
4855
styleBuildCount: number;
4956
stylesUpdated: BuildStyleUpdate[];
@@ -145,6 +152,7 @@ export interface BuildStats {
145152
};
146153
components: BuildComponent[];
147154
entries: BuildEntry[];
155+
rollupResults: RollupResults;
148156
sourceGraph: BuildSourceGraph;
149157
collections: {
150158
name: string;

0 commit comments

Comments
 (0)