Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit daa04fb

Browse files
author
Dimitar Tachev
authored
Merge pull request #929 from NativeScript/tachev/fix-inspector
fix: handle file dependencies in non root entry modules
2 parents 545290d + bcf0a5c commit daa04fb

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

plugins/GenerateNativeScriptEntryPointsPlugin.js

+27-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { RawSource } = require("webpack-sources");
22
const { getPackageJson } = require("../projectHelpers");
33
const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
4-
4+
const path = require("path");
55

66
exports.GenerateNativeScriptEntryPointsPlugin = (function () {
77
const GenerationFailedError = "Unable to generate entry files.";
@@ -49,38 +49,42 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
4949
return;
5050
}
5151

52-
const requireDeps =
53-
entryPoint.chunks.map(chunk => {
54-
let requireChunkFiles = "";
55-
if (chunk.name === entryPointName) {
56-
entryChunk = chunk;
57-
} else {
58-
chunk.files.forEach(fileName => {
59-
if (!this.isHMRFile(fileName)) {
60-
requireChunkFiles += `require("./${fileName}");`;
61-
}
62-
});
63-
}
64-
65-
return requireChunkFiles;
66-
}).join("");
52+
const requiredFiles = [];
53+
entryPoint.chunks.forEach(chunk => {
54+
if (chunk.name === entryPointName) {
55+
entryChunk = chunk;
56+
} else {
57+
chunk.files.forEach(fileName => {
58+
if (!this.isHMRFile(fileName)) {
59+
requiredFiles.push(fileName);
60+
}
61+
});
62+
}
63+
});
6764

6865
if (!entryChunk) {
6966
throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`);
7067
}
7168

72-
entryChunk.files.forEach(fileName => {
73-
if (!compilation.assets[fileName]) {
74-
throw new Error(`${GenerationFailedError} File "${fileName}" not found for entry "${entryPointName}".`);
69+
entryChunk.files.forEach(filePath => {
70+
if (!compilation.assets[filePath]) {
71+
throw new Error(`${GenerationFailedError} File "${filePath}" not found for entry "${entryPointName}".`);
7572
}
7673

77-
if (!this.isHMRFile(fileName)) {
78-
const currentEntryFileContent = compilation.assets[fileName].source();
79-
compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
74+
if (!this.isHMRFile(filePath)) {
75+
const currFileDirRelativePath = path.dirname(filePath);
76+
const pathToRootFromCurrFile = path.relative(currFileDirRelativePath, ".");
77+
78+
const requireDeps = requiredFiles.map(depPath => {
79+
const depRelativePath = path.join(pathToRootFromCurrFile, depPath);
80+
81+
return `require("./${depRelativePath}");`;
82+
}).join("");
83+
const currentEntryFileContent = compilation.assets[filePath].source();
84+
compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
8085
}
8186
});
8287
}
83-
8488
GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) {
8589
if (this.files[name] !== content) {
8690
this.files[name] = content;

0 commit comments

Comments
 (0)