Skip to content

Commit 6637cd6

Browse files
Feat: Adding git SHA (#418)
* Adding git sha to object * enable stats file output * removing comment * relocate git sha calc to function body * bump package version
1 parent 59bfe78 commit 6637cd6

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

dashboard-example/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
find-package-json "^1.2.0"
419419

420420
"@module-federation/dashboard-plugin@*", "@module-federation/dashboard-plugin@file:../dashboard-plugin":
421-
version "2.3.0"
421+
version "2.4.0"
422422
dependencies:
423423
"@babel/generator" "^7.15.4"
424424
"@babel/parser" "^7.15.5"

dashboard-plugin/FederationDashboardPlugin.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class FederationDashboardPlugin {
6161
name: PLUGIN_NAME,
6262
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,
6363
},
64-
() => this.processWebpackGraph(compilation)
64+
() => this.processWebpackGraph(compilation)
6565
);
6666
});
6767

@@ -177,6 +177,15 @@ class FederationDashboardPlugin {
177177
this.parseModuleAst(curCompiler);
178178
}
179179

180+
let gitSha
181+
try {
182+
gitSha = require('child_process')
183+
.execSync('git rev-parse HEAD')
184+
.toString().trim()
185+
} catch(e) {
186+
console.error(e)
187+
}
188+
180189
// filter modules
181190
const modules = this.getFilteredModules(stats);
182191
// get RemoteEntryChunk
@@ -202,6 +211,7 @@ class FederationDashboardPlugin {
202211
version: this._options.publishVersion || "1.0.0", // '1.0.0' if not specified
203212
posted: this._options.posted, // Date.now() if not specified
204213
group: this._options.group, // 'default' if not specified
214+
sha: gitSha,
205215
modules,
206216
chunkDependencies,
207217
functionRemotes: this.allArgumentsUsed,
@@ -217,8 +227,7 @@ class FederationDashboardPlugin {
217227

218228
if (graphData) {
219229
const dashData = (this._dashData = JSON.stringify(graphData));
220-
221-
// this.writeStatsFiles(stats, dashData);
230+
this.writeStatsFiles(stats, dashData);
222231

223232
if (this._options.dashboardURL) {
224233
this.postDashboardData(dashData)
@@ -269,7 +278,6 @@ class FederationDashboardPlugin {
269278
new RegExp(`__REMOTE_VERSION__`, "g"),
270279
cleanVersion
271280
);
272-
273281
const rewriteTempalteFromMain = codeSource.replace(
274282
new RegExp(`__REMOTE_VERSION__`, "g"),
275283
""
@@ -455,7 +463,7 @@ class FederationDashboardPlugin {
455463
writeStatsFiles(stats, dashData) {
456464
if (this._options.filename) {
457465
const hashPath = path.join(stats.outputPath, this._options.filename);
458-
if (fs.existsSync(stats.outputPath)) {
466+
if (!fs.existsSync(stats.outputPath)) {
459467
fs.mkdirSync(stats.outputPath);
460468
}
461469
fs.writeFile(hashPath, dashData, { encoding: "utf-8" }, () => {});

dashboard-plugin/convertToGraph.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const convertToGraph = (
1212
posted,
1313
group,
1414
functionRemotes,
15+
sha,
16+
buildHash
1517
},
1618
standalone
1719
) => {
@@ -174,6 +176,8 @@ const convertToGraph = (
174176
version,
175177
posted,
176178
group,
179+
sha,
180+
buildHash
177181
};
178182

179183
return out;

dashboard-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@module-federation/dashboard-plugin",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"main": "FederationDashboardPlugin.js",
55
"bin": "bin/federation-report.js",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)