diff --git a/plugins/GenerateNativeScriptEntryPointsPlugin.js b/plugins/GenerateNativeScriptEntryPointsPlugin.js index d8c689be..3932f3ee 100644 --- a/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ b/plugins/GenerateNativeScriptEntryPointsPlugin.js @@ -1,8 +1,11 @@ const { RawSource } = require("webpack-sources"); const { getPackageJson } = require("../projectHelpers"); -const { SNAPSHOT_ENTRY_MODULE } = require("./NativeScriptSnapshotPlugin"); +const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin"); + exports.GenerateNativeScriptEntryPointsPlugin = (function () { + const GenerationFailedError = "Unable to generate entry files."; + function GenerateNativeScriptEntryPointsPlugin(appEntryName) { this.appEntryName = appEntryName; this.files = {}; @@ -39,8 +42,9 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { } GenerateNativeScriptEntryPointsPlugin.prototype.generateEntryFile = function (compilation, entryPoint) { - const entryPointFileName = `${entryPoint.options.name}.js`; - if (entryPointFileName === SNAPSHOT_ENTRY_MODULE) { + const entryPointName = entryPoint.options.name; + let entryChunk; + if (entryPointName === SNAPSHOT_ENTRY_NAME) { // Do not require the snapshot entry dependencies as the snapshot will fail. return; } @@ -48,17 +52,29 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { const requireDeps = entryPoint.chunks.map(chunk => { let requireChunkFiles = ""; - chunk.files.forEach(fileName => { - if (fileName !== entryPointFileName) { + if (chunk.name === entryPointName) { + entryChunk = chunk; + } else { + chunk.files.forEach(fileName => { requireChunkFiles += `require("./${fileName}");`; - } - }); + }); + } return requireChunkFiles; - }).join("\n"); + }).join(""); + + if (!entryChunk) { + throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`); + } + + entryChunk.files.forEach(fileName => { + if (!compilation.assets[fileName]) { + throw new Error(`${GenerationFailedError} File "${fileName}" not found for entry "${entryPointName}".`); + } - const currentEntryPointContent = compilation.assets[entryPointFileName].source(); - compilation.assets[entryPointFileName] = new RawSource(`${requireDeps}${currentEntryPointContent}`); + const currentEntryFileContent = compilation.assets[fileName].source(); + compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`); + }); } GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) { diff --git a/plugins/NativeScriptSnapshotPlugin/index.js b/plugins/NativeScriptSnapshotPlugin/index.js index a285bb21..97cebd7e 100644 --- a/plugins/NativeScriptSnapshotPlugin/index.js +++ b/plugins/NativeScriptSnapshotPlugin/index.js @@ -12,7 +12,7 @@ const schema = require("./options.json"); const SNAPSHOT_ENTRY_NAME = "snapshot-entry"; const SNAPSHOT_ENTRY_MODULE = `${SNAPSHOT_ENTRY_NAME}.js`; -exports.SNAPSHOT_ENTRY_MODULE = SNAPSHOT_ENTRY_MODULE; +exports.SNAPSHOT_ENTRY_NAME = SNAPSHOT_ENTRY_NAME; exports.NativeScriptSnapshotPlugin = (function () { function NativeScriptSnapshotPlugin(options) {