Skip to content

Commit 44b31f3

Browse files
committed
build(broccoli): log the build tree after each build into tmp/build.*.log
This log can then be used to visualize the build tree and map paths in the tmp/ dir to individual nodes in the build tree.
1 parent b5431e4 commit 44b31f3

File tree

1 file changed

+56
-7
lines changed

1 file changed

+56
-7
lines changed

tools/broccoli/angular_builder.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var broccoli = require('broccoli');
2-
var fse = require('fs-extra');
2+
var fs = require('fs');
33
var makeBrowserTree = require('./trees/browser_tree');
44
var makeNodeTree = require('./trees/node_tree');
55
var makeDartTree = require('./trees/dart_tree');
@@ -16,31 +16,32 @@ export class AngularBuilder {
1616
private browserProdBuilder: BroccoliBuilder;
1717
private dartBuilder: BroccoliBuilder;
1818
private outputPath: string;
19+
private firstResult: BuildResult;
1920

2021
constructor(public options: AngularBuilderOptions) { this.outputPath = options.outputPath; }
2122

2223

2324
public rebuildBrowserDevTree(): Promise<BuildResult> {
2425
this.browserDevBuilder = this.browserDevBuilder || this.makeBrowserDevBuilder();
25-
return this.rebuild(this.browserDevBuilder);
26+
return this.rebuild(this.browserDevBuilder, 'js.dev');
2627
}
2728

2829

2930
public rebuildBrowserProdTree(): Promise<BuildResult> {
3031
this.browserProdBuilder = this.browserProdBuilder || this.makeBrowserProdBuilder();
31-
return this.rebuild(this.browserProdBuilder);
32+
return this.rebuild(this.browserProdBuilder, 'js.prod');
3233
}
3334

3435

3536
public rebuildNodeTree(): Promise<BuildResult> {
3637
this.nodeBuilder = this.nodeBuilder || this.makeNodeBuilder();
37-
return this.rebuild(this.nodeBuilder);
38+
return this.rebuild(this.nodeBuilder, 'js.cjs');
3839
}
3940

4041

4142
public rebuildDartTree(): Promise<BuildResult> {
4243
this.dartBuilder = this.dartBuilder || this.makeDartBuilder();
43-
return this.rebuild(this.dartBuilder);
44+
return this.rebuild(this.dartBuilder, 'dart');
4445
}
4546

4647

@@ -84,7 +85,55 @@ export class AngularBuilder {
8485
}
8586

8687

87-
private rebuild(builder) {
88-
return builder.build().then((result) => { printSlowTrees(result.graph); });
88+
private rebuild(builder, name) {
89+
return builder.build().then(
90+
(result) => {
91+
if (!this.firstResult) {
92+
this.firstResult = result;
93+
}
94+
95+
printSlowTrees(result.graph);
96+
writeBuildLog(result, name);
97+
},
98+
(error) => {
99+
// the build tree is the same during rebuilds, only leaf properties of the nodes change
100+
// so let's traverse it and get updated values for input/cache/output paths
101+
if (this.firstResult) {
102+
writeBuildLog(this.firstResult, name);
103+
}
104+
throw error;
105+
});
106+
}
107+
}
108+
109+
110+
function writeBuildLog(result: BuildResult, name: string) {
111+
let logPath = `tmp/build.${name}.log`;
112+
let prevLogPath = logPath + '.previous';
113+
let formattedLogContent = JSON.stringify(broccoliNodeToBuildNode(result.graph), null, 2);
114+
115+
if (fs.existsSync(prevLogPath)) fs.unlinkSync(prevLogPath);
116+
if (fs.existsSync(logPath)) fs.renameSync(logPath, prevLogPath);
117+
fs.writeFileSync(logPath, formattedLogContent, {encoding: 'utf-8'});
118+
}
119+
120+
121+
function broccoliNodeToBuildNode(broccoliNode) {
122+
let tree = broccoliNode.tree.newStyleTree || broccoliNode.tree;
123+
124+
return new BuildNode(
125+
tree.description || tree.constructor.name,
126+
tree.inputPath ? [tree.inputPath] : tree.inputPaths,
127+
tree.cachePath,
128+
tree.outputPath,
129+
broccoliNode.subtrees.map(broccoliNodeToBuildNode)
130+
);
131+
}
132+
133+
134+
class BuildNode {
135+
136+
constructor(public pluginName:string, public inputPaths: string[], public cachePath: string,
137+
public outputPath: string, public inputNodes: BroccoliNode[]) {
89138
}
90139
}

0 commit comments

Comments
 (0)