UNPKG

atlassian-webresource-webpack-plugin

Version:

Auto-generates web-resource definitions from your webpacked code, for usage in an Atlassian product or plugin.

44 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const provided_dependencies_1 = require("./deps/provided-dependencies"); const file_system_1 = require("./helpers/file-system"); const logger_1 = require("./logger"); const WebpackHelpers_1 = require("./WebpackHelpers"); const WebpackRuntimeHelpers_1 = require("./WebpackRuntimeHelpers"); class WrmManifestPlugin { constructor(appResourcesFactory, outputPath, pluginKey) { this.pluginKey = pluginKey; this.appResourcesFactory = appResourcesFactory; this.outputPath = outputPath; } apply(compiler) { const { outputPath, appResourcesFactory, pluginKey } = this; const { name, target } = (0, WebpackHelpers_1.extractLibraryDetailsFromWebpackConfig)(compiler); if (!name || !target) { (0, logger_1.error)('Can only use wrmManifestPath in conjunction with output.library and output.libraryTarget'); return; } if (target !== 'amd') { (0, logger_1.error)(`Could not create manifest mapping. LibraryTarget '${target}' is not supported. Use 'amd'`); return; } (0, WebpackRuntimeHelpers_1.hookIntoCompileDoneToGenerateReports)('wrm manifest - generate deps', compiler, (compilation, cb) => { const appResourceGenerator = appResourcesFactory.build(compiler, compilation); const wrmManifestMapping = appResourceGenerator .getEntryPointsResourceDescriptors() .filter(({ attributes }) => attributes.moduleId) .reduce((result, { attributes: { key: resourceKey, moduleId } }) => { const libraryName = compilation.getAssetPath(name, { chunk: { name: moduleId, id: moduleId, hash: moduleId }, }); result[moduleId] = (0, provided_dependencies_1.buildProvidedDependency)(pluginKey, resourceKey, `require('${libraryName}')`, libraryName); return result; }, {}); const wrmManifestJSON = JSON.stringify({ providedDependencies: wrmManifestMapping }, null, 4); (0, file_system_1.writeFileSync)(outputPath, wrmManifestJSON); cb(); }); } } exports.default = WrmManifestPlugin; //# sourceMappingURL=WrmManifestPlugin.js.map