Skip to content

Commit 3343440

Browse files
committed
fix: remove skipPost from the main plugin
1 parent 70ee8e7 commit 3343440

File tree

1 file changed

+47
-59
lines changed

1 file changed

+47
-59
lines changed

dashboard-plugin/FederationDashboardPlugin.js

+47-59
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ try {
1818
console.error(e);
1919
}
2020

21-
const findPackageJson = filePath => {
21+
const findPackageJson = (filePath) => {
2222
if (filePath.length === 0) {
2323
return false;
2424
}
2525
if (fs.existsSync(path.join(filePath.join(path.sep), "package.json"))) {
2626
try {
2727
return require(path.join(filePath.join(path.sep), "package.json"));
28-
} catch (e) {
29-
30-
}
28+
} catch (e) {}
3129
}
3230

3331
filePath.pop();
@@ -50,7 +48,7 @@ class AddRuntimeRequiremetToPromiseExternal {
5048
apply(compiler) {
5149
compiler.hooks.compilation.tap(
5250
"AddRuntimeRequiremetToPromiseExternal",
53-
compilation => {
51+
(compilation) => {
5452
const { RuntimeGlobals } = compiler.webpack;
5553
if (compilation.outputOptions.trustedTypes) {
5654
compilation.hooks.additionalModuleRuntimeRequirements.tap(
@@ -100,7 +98,7 @@ class FederationDashboardPlugin {
10098
compiler.options.output.uniqueName = `v${Date.now()}`;
10199

102100
new AddRuntimeRequiremetToPromiseExternal().apply(compiler);
103-
const FederationPlugin = compiler.options.plugins.find(plugin => {
101+
const FederationPlugin = compiler.options.plugins.find((plugin) => {
104102
return (
105103
plugin.constructor.name === "ModuleFederationPlugin" ||
106104
plugin.constructor.name === "NextFederationPlugin"
@@ -121,18 +119,16 @@ class FederationDashboardPlugin {
121119
);
122120
}
123121

124-
this.FederationPluginOptions.name = this.FederationPluginOptions.name.replace(
125-
"__REMOTE_VERSION__",
126-
""
127-
);
122+
this.FederationPluginOptions.name =
123+
this.FederationPluginOptions.name.replace("__REMOTE_VERSION__", "");
128124

129-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
125+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
130126
compilation.hooks.processAssets.tapPromise(
131127
{
132128
name: PLUGIN_NAME,
133-
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT
129+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,
134130
},
135-
assets => {
131+
(assets) => {
136132
return this.processWebpackGraph(compilation, assets);
137133
}
138134
);
@@ -146,7 +142,7 @@ class FederationDashboardPlugin {
146142
"process.dashboardURL": JSON.stringify(this._options.dashboardURL),
147143
"process.env.CURRENT_HOST": JSON.stringify(
148144
this.FederationPluginOptions.name
149-
)
145+
),
150146
}).apply(compiler);
151147
}
152148
}
@@ -182,7 +178,7 @@ class FederationDashboardPlugin {
182178
sha: gitSha,
183179
modules: stats.modules,
184180
chunkDependencies,
185-
functionRemotes: this.allArgumentsUsed
181+
functionRemotes: this.allArgumentsUsed,
186182
};
187183

188184
let graphData = null;
@@ -196,18 +192,14 @@ class FederationDashboardPlugin {
196192
if (graphData) {
197193
const dashData = (this._dashData = JSON.stringify(graphData));
198194

199-
if (this._options.skipPost) {
200-
console.info('Skipping post to dashboard')
201-
} else {
202-
if (this._options.dashboardURL && !this._options.nextjs) {
203-
this.postDashboardData(dashData).catch(err => {
204-
if (err) {
205-
curCompiler.errors.push(err);
206-
// eslint-disable-next-line promise/no-callback-in-promise
207-
throw err;
208-
}
209-
});
210-
}
195+
if (this._options.dashboardURL && !this._options.nextjs) {
196+
this.postDashboardData(dashData).catch((err) => {
197+
if (err) {
198+
curCompiler.errors.push(err);
199+
// eslint-disable-next-line promise/no-callback-in-promise
200+
throw err;
201+
}
202+
});
211203
}
212204

213205
return Promise.resolve().then(() => {
@@ -219,7 +211,7 @@ class FederationDashboardPlugin {
219211
},
220212
size() {
221213
return statsBuf.length;
222-
}
214+
},
223215
};
224216
// for dashboard.json
225217
if (curCompiler.emitAsset && this._options.filename) {
@@ -306,15 +298,15 @@ class FederationDashboardPlugin {
306298
}
307299

308300
getRemoteEntryChunk(stats, FederationPluginOptions) {
309-
return stats.chunks.find(chunk =>
310-
chunk.names.find(name => name === FederationPluginOptions.name)
301+
return stats.chunks.find((chunk) =>
302+
chunk.names.find((name) => name === FederationPluginOptions.name)
311303
);
312304
}
313305

314306
getChunkDependencies(validChunkArray) {
315307
return validChunkArray.reduce((acc, chunk) => {
316308
const subset = chunk.getAllReferencedChunks();
317-
const stringifiableChunk = Array.from(subset).map(sub => {
309+
const stringifiableChunk = Array.from(subset).map((sub) => {
318310
const cleanSet = Object.getOwnPropertyNames(sub).reduce((acc, key) => {
319311
if (key === "_groups") return acc;
320312
return Object.assign(acc, { [key]: sub[key] });
@@ -324,7 +316,7 @@ class FederationDashboardPlugin {
324316
});
325317

326318
return Object.assign(acc, {
327-
[chunk.id]: stringifiableChunk
319+
[chunk.id]: stringifiableChunk,
328320
});
329321
}, {});
330322
}
@@ -346,23 +338,23 @@ class FederationDashboardPlugin {
346338
packageJson,
347339
// subPackages: this.directReasons(modules),
348340
shareFrom: ["dependencies"],
349-
ignorePatchversion: false
341+
ignorePatchversion: false,
350342
});
351343
vendorFederation.devDependencies = AutomaticVendorFederation({
352344
exclude: [],
353345
ignoreVersion: false,
354346
packageJson,
355347
// subPackages: this.directReasons(modules),
356348
shareFrom: ["devDependencies"],
357-
ignorePatchversion: false
349+
ignorePatchversion: false,
358350
});
359351
vendorFederation.optionalDependencies = AutomaticVendorFederation({
360352
exclude: [],
361353
ignoreVersion: false,
362354
packageJson,
363355
// subPackages: this.directReasons(modules),
364356
shareFrom: ["optionalDependencies"],
365-
ignorePatchversion: false
357+
ignorePatchversion: false,
366358
});
367359
}
368360

@@ -392,7 +384,7 @@ class FederationDashboardPlugin {
392384
? namedChunkRefs.getAllReferencedChunks()
393385
: [];
394386

395-
AllReferencedChunksByRemote.forEach(chunk => {
387+
AllReferencedChunksByRemote.forEach((chunk) => {
396388
if (chunk.id !== FederationPluginOptions.name) {
397389
validChunkArray.push(chunk);
398390
}
@@ -404,17 +396,19 @@ class FederationDashboardPlugin {
404396
directReasons(modules) {
405397
const directReasons = new Set();
406398

407-
modules.forEach(module => {
399+
modules.forEach((module) => {
408400
if (module.reasons) {
409-
module.reasons.forEach(reason => {
401+
module.reasons.forEach((reason) => {
410402
if (reason.userRequest) {
411403
try {
412404
// grab user required package.json
413-
const subsetPackage = require(path.join(reason.userRequest, "package.json"));
405+
const subsetPackage = require(path.join(
406+
reason.userRequest,
407+
"package.json"
408+
));
414409

415410
directReasons.add(subsetPackage);
416-
} catch (e) {
417-
}
411+
} catch (e) {}
418412
}
419413
});
420414
}
@@ -458,7 +452,7 @@ class FederationDashboardPlugin {
458452
fs.mkdir(
459453
path.join(stats.outputPath, version),
460454
{ recursive: true },
461-
err => {
455+
(err) => {
462456
if (err) throw err;
463457
fs.writeFile(
464458
path.join(
@@ -467,7 +461,7 @@ class FederationDashboardPlugin {
467461
this.FederationPluginOptions.filename
468462
),
469463
file,
470-
err => {
464+
(err) => {
471465
if (this._options.debug) {
472466
console.trace(err);
473467
console.log(
@@ -492,8 +486,7 @@ class FederationDashboardPlugin {
492486
statsPath,
493487
JSON.stringify(stats),
494488
{ encoding: "utf-8" },
495-
() => {
496-
}
489+
() => {}
497490
);
498491
}
499492
}
@@ -506,7 +499,6 @@ class NextMedusaPlugin {
506499
}
507500
}
508501
async postDashboardData(dashData) {
509-
510502
if (!this._options.dashboardURL) {
511503
return Promise.resolve();
512504
}
@@ -520,13 +512,13 @@ class NextMedusaPlugin {
520512
body: dashData,
521513
headers: {
522514
Accept: "application/json",
523-
"Content-type": "application/json"
524-
}
515+
"Content-type": "application/json",
516+
},
525517
});
526518

527519
if (!res.ok) throw new Error(res.statusText);
528520

529-
return res
521+
return res;
530522
} catch (err) {
531523
console.warn(
532524
`Error posting data to dashboard URL: ${this._options.dashboardURL}`
@@ -566,7 +558,7 @@ class NextMedusaPlugin {
566558
new FederationDashboardPlugin({
567559
...this._options,
568560
filename: compiler.options.name + "-" + filename,
569-
nextjs: true
561+
nextjs: true,
570562
}).apply(compiler);
571563

572564
const hostData = path.join(
@@ -575,33 +567,29 @@ class NextMedusaPlugin {
575567
);
576568
compiler.hooks.done.tap(PLUGIN_NAME, () => {
577569
if (fs.existsSync(hostData)) {
578-
fs.writeFileSync(
579-
hostData,
580-
JSON.stringify(require(hostData))
581-
);
570+
fs.writeFileSync(hostData, JSON.stringify(require(hostData)));
582571
}
583572
});
584573

585574
compiler.hooks.afterDone.tap("NextMedusaPlugin", (stats) => {
586575
if (fs.existsSync(hostData)) {
587576
const dashboardData = fs.readFileSync(hostData, "utf8");
588577
if (this._options.skipPost) {
589-
console.info('Skipping post to dashboard')
578+
console.info("Skipping post to dashboard");
590579
} else {
591580
this.postDashboardData(dashboardData)
592581
.then(() => {
593-
console.info('Data has been successfully sent to the dashboard')
582+
console.info("Data has been successfully sent to the dashboard");
594583
})
595584
.catch((error) => {
596-
console.error('Failed to send data to the dashboard:', error)
585+
console.error("Failed to send data to the dashboard:", error);
597586
});
598587
}
599588
}
600589
});
601-
602590
}
603591
}
604592

605593
module.exports = FederationDashboardPlugin;
606594
module.exports.clientVersion = require("./client-version");
607-
module.exports.NextMedusaPlugin = NextMedusaPlugin;
595+
module.exports.NextMedusaPlugin = NextMedusaPlugin;

0 commit comments

Comments
 (0)