@atlassian/wrm-troubleshooting
Version:
A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.
60 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function decoratePluginWithNames(config) {
return {
...config,
plugins: config.plugins.filter(Boolean).map((plugin) => {
plugin.pluginName =
plugin.constructor?.name ?? plugin.name;
return plugin;
}),
};
}
const unwantedWebpackPlugins = [
/* prettier-ignore-start */
'BundleAnalyzerPlugin' /* When we serialize the plugin it will generate circular data */,
/* prettier-ignore-end */
];
function cleanUnwantedPlugins(config) {
return {
...config,
plugins: config.plugins.map((plugin) => {
const { pluginName } = plugin;
if (!unwantedWebpackPlugins.includes(pluginName)) {
return plugin;
}
// Clean-up config and only keep the plugin name.
// We are doing that to know what webpack plugins are being used by the project and to keep type safety.
const fakePlugin = {
pluginName,
/* eslint-disable @typescript-eslint/no-empty-function */
constructor() { },
apply() { },
/* eslint-enable @typescript-eslint/no-empty-function */
};
return fakePlugin;
}),
};
}
function normalizeConfig(config) {
const configWithDecoratedPlugins = decoratePluginWithNames(config);
return cleanUnwantedPlugins(configWithDecoratedPlugins);
}
class WebpackRetrieveConfigPlugin {
apply(compiler) {
compiler.hooks.beforeRun.tapAsync('Retrieve Webpack Configuration', function (compiler) {
const config = normalizeConfig(compiler.options);
const serializedConfig = JSON.stringify(config);
// Output the serialized webpack config to process stdout so the WRM troubleshooting tool can read it
console.log(serializedConfig);
// We need a timeout since there is an issue in Node related to flushing stdout
// https://github.com/nodejs/node/issues/12921
setTimeout(() => {
process.exit(0);
}, 50);
});
}
}
exports.default = WebpackRetrieveConfigPlugin;
module.exports = WebpackRetrieveConfigPlugin;
//# sourceMappingURL=WebpackRetrieveConfigPlugin.js.map