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

Commit 1ef9be3

Browse files
committed
fix: handle file dependencies in non root entry modules (e.g. tns_modules/tns_core_modules/inspector_modules)
1 parent ae9cb8e commit 1ef9be3

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

plugins/GenerateNativeScriptEntryPointsPlugin.js

+28-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,43 @@ 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 currFileDirAbsolutePath = path.join(compilation.compiler.outputPath, currFileDirRelativePath);
77+
const pathToRootFromCurrFile = path.relative(currFileDirAbsolutePath, compilation.compiler.outputPath);
78+
79+
const requireDeps = requiredFiles.map(depPath => {
80+
const depRelativePath = path.join(pathToRootFromCurrFile, depPath);
81+
82+
return `require("./${depRelativePath}");`;
83+
}).join("");
84+
const currentEntryFileContent = compilation.assets[filePath].source();
85+
compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
8086
}
8187
});
8288
}
83-
8489
GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) {
8590
if (this.files[name] !== content) {
8691
this.files[name] = content;

0 commit comments

Comments
 (0)