UNPKG

@eaglesong/task-panorama

Version:
70 lines 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const js_yaml_1 = tslib_1.__importDefault(require("js-yaml")); const util_1 = require("util"); const ModuleDependency_1 = tslib_1.__importDefault(require("webpack/lib/dependencies/ModuleDependency")); const identifier_1 = require("webpack/lib/util/identifier"); const WebpackError_1 = tslib_1.__importDefault(require("webpack/lib/WebpackError")); class PanoramaManifestError extends WebpackError_1.default { constructor(filename, message) { super(`Panorama manifest ${filename}\n${message}`); this.name = 'PanoramaManifestError'; Error.captureStackTrace(this, this.constructor); } } class PanoramaEntryDependency extends ModuleDependency_1.default { constructor() { super(...arguments); this.type = 'panorama entry'; } } class PanoramaEntriesPlugin { constructor(manifest) { this.manifest = manifest; } apply(compiler) { // FIXME: delete compiler.options.entry; // @ts-ignore // eslint-disable-next-line prefer-destructuring const context = compiler.context; // @ts-ignore const readFile = util_1.promisify(compiler.inputFileSystem.readFile.bind(compiler.inputFileSystem)); compiler.hooks.compilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => { // @ts-ignore compilation.dependencyFactories.set(PanoramaEntryDependency, normalModuleFactory); }); compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => { // @ts-ignore compilation.compilationDependencies.add(this.manifest); const result = await readFile(this.manifest); let entries; try { entries = js_yaml_1.default.safeLoad(result.toString('utf8')); } catch (error) { // @ts-ignore const manifestPath = identifier_1.makePathsRelative(compiler.options.context, this.manifest); compilation.errors.push(new PanoramaManifestError(manifestPath, error.message)); return; } await Promise.all(entries.map(async ({ source, name }) => { const dep = new PanoramaEntryDependency(source); dep.loc = { name }; await new Promise(resolve => compilation.addEntry(context, dep, name, resolve)); })); compilation.hooks.reviveChunks.tap(this.constructor.name, chunks => { var _a; for (const chunk of chunks) { const entry = entries.find(e => e.name === chunk.name); if (((_a = entry) === null || _a === void 0 ? void 0 : _a.type) != null) { chunk.__type = entry.type; } } }); }); } } exports.PanoramaEntriesPlugin = PanoramaEntriesPlugin; //# sourceMappingURL=PanoramaEntriesPlugin.js.map