@atlassian/wrm-troubleshooting
Version:
A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.
62 lines • 4.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyGeneratedWebResources = exports.checkWrmScanFoldersIsValid = exports.checkWrmPluginHasValidConfig = exports.NPM_PACKAGE_NAME = exports.WRM_PLUGIN_NAME = void 0;
const chalk_1 = __importDefault(require("chalk"));
const fs_1 = require("fs");
const atlassianPluginXml_1 = require("./atlassianPluginXml");
const paths_1 = require("./paths");
const pom_1 = require("./pom");
exports.WRM_PLUGIN_NAME = 'WrmPlugin';
exports.NPM_PACKAGE_NAME = 'atlassian-webresource-webpack-plugin';
async function checkWrmPluginHasValidConfig(pomXml, wrmWebpackPlugin) {
const pomPluginKey = (0, pom_1.getAtlassianPluginKeyFromPom)(pomXml);
const { pluginKey: wrmPluginPluginKey } = wrmWebpackPlugin.options;
if (pomPluginKey !== wrmPluginPluginKey) {
const pluginKeyOption = 'pluginKey';
const pomFile = 'pom.xml';
// TODO: the pom.xml should be atlassian-plugin.xml file I guess
return new Error(`The value of atlassian plugin key provided to the ${chalk_1.default.bold(exports.WRM_PLUGIN_NAME)} webpack plugin doesn't match the plugin key defined in "${chalk_1.default.green(pomFile)}" file:
- ${chalk_1.default.bold(exports.WRM_PLUGIN_NAME)} [${chalk_1.default.bold(pluginKeyOption)}]: "${chalk_1.default.bold.red(wrmPluginPluginKey)}"
- ${chalk_1.default.bold(pomFile)} [${chalk_1.default.bold('project.groupId')}].[${chalk_1.default.bold('project.artifactId')}]: "${chalk_1.default.bold.red(pomPluginKey)}"`);
}
return true;
}
exports.checkWrmPluginHasValidConfig = checkWrmPluginHasValidConfig;
async function checkWrmScanFoldersIsValid(pomXml, pomFile, wrmWebpackPlugin) {
const { xmlDescriptors: wrmXmlDescriptorsFile } = wrmWebpackPlugin.options;
// Get Scan Folders value
const pomScanFolders = (0, pom_1.getAbsoluteScanFoldersConfig)(pomXml, pomFile);
// Check if wrmXmlDescriptorsFile is a child of Scan Folders directory
const isInFolder = (0, paths_1.isSubDirectory)(pomScanFolders, wrmXmlDescriptorsFile);
if (!isInFolder) {
const wrmXmlDescriptorOption = 'xmlDescriptors';
return new Error(`The configuration value of "${chalk_1.default.bold(pom_1.SCAN_FOLDERS_KEY)}" entry in ${chalk_1.default.green((0, paths_1.getRelativePath)(pomFile))} file doesn't overlap with the value of "${chalk_1.default.bold(wrmXmlDescriptorOption)}" in your webpack configuration:
- ${chalk_1.default.bold((0, paths_1.getRelativePath)(pomFile))} [${chalk_1.default.bold(pom_1.SCAN_FOLDERS_KEY)}]: ${chalk_1.default.bold.red((0, paths_1.getRelativePath)(pomScanFolders))}
- ${chalk_1.default.bold(exports.WRM_PLUGIN_NAME)} [${chalk_1.default.bold(wrmXmlDescriptorOption)}]: "${chalk_1.default.bold.red((0, paths_1.getRelativePath)(wrmXmlDescriptorsFile))}"`);
}
return true;
}
exports.checkWrmScanFoldersIsValid = checkWrmScanFoldersIsValid;
async function verifyGeneratedWebResources(pomFile, pomXml, preBundleTimestamp) {
const pomScanFolders = (0, pom_1.getAbsoluteScanFoldersConfig)(pomXml, pomFile);
const generatedXmlPaths = await (0, atlassianPluginXml_1.getGeneratedModuleDescriptorPaths)(pomFile, pomXml);
return verifyXmlFiles(generatedXmlPaths, preBundleTimestamp, pomScanFolders);
}
exports.verifyGeneratedWebResources = verifyGeneratedWebResources;
async function verifyXmlFiles(xmlPaths, preBundleTimestamp, pomScanFolders) {
// Check if any files were generated in the directory
if (!xmlPaths.length) {
return new Error(`No *.xml files were created by webpack under the "${chalk_1.default.green((0, paths_1.getRelativePath)(pomScanFolders))}" directory. Check if running the "webpack" CLI command shows you any errors or warnings that might cause the issue.`);
}
// Check if the XML files were generated during the webpack bundle
const fileStats = await Promise.all(xmlPaths.map((filePath) => fs_1.promises.stat(filePath)));
const filesAreNewer = fileStats.some((stats) => stats.mtimeMs > preBundleTimestamp);
if (!filesAreNewer) {
return new Error(`The *.xml files under the "${chalk_1.default.green((0, paths_1.getRelativePath)(pomScanFolders))}" directory are generated by webpack CLI but are coming from the older webpack bundle. Check if running the "webpack" CLI command shows you any errors or warnings that might cause the issue.`);
}
return true;
}
//# sourceMappingURL=webpackWrmPlugin.js.map