@plaudit/webpack-extensions 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
7
|
const webpack_1 = require("webpack");
|
|
9
8
|
const webpack_sources_1 = require("webpack-sources");
|
|
10
9
|
class AdditionalDependencyInjectorPlugin {
|
|
@@ -14,26 +13,33 @@ class AdditionalDependencyInjectorPlugin {
|
|
|
14
13
|
name: "AdditionalDependencyInjectorPlugin_ProcessAssets",
|
|
15
14
|
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE
|
|
16
15
|
}, compilationAssets => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const firstLine = node_fs_1.default.readFileSync(possibleFile, 'utf8').trim().split(/\r?\n/)[0];
|
|
26
|
-
if (firstLine.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
|
|
27
|
-
additionalDependencies.push(...firstLine.substring(26).trim().split(','));
|
|
28
|
-
}
|
|
29
|
-
break dependencyFinder;
|
|
16
|
+
const assetSources = new Map();
|
|
17
|
+
for (const entrypoint of compilation.entrypoints.values()) {
|
|
18
|
+
const typeScriptOrigins = entrypoint.origins.filter(origin => origin.request.endsWith('.ts') || origin.request.endsWith('.tsx'));
|
|
19
|
+
if (typeScriptOrigins.length > 0) {
|
|
20
|
+
for (const chunk of entrypoint.chunks) {
|
|
21
|
+
for (const file of chunk.files) {
|
|
22
|
+
if (file.endsWith('.asset.php')) {
|
|
23
|
+
assetSources.set(file, typeScriptOrigins[0].request);
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const [name, asset] of Object.entries(compilationAssets)) {
|
|
30
|
+
if (name.endsWith(".asset.php") && asset.constructor.name === 'RawSource') {
|
|
31
|
+
const assetSource = assetSources.get(name);
|
|
32
|
+
if (!assetSource) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const firstLine = node_fs_1.default.readFileSync(assetSource, 'utf8').trim().split(/\r?\n/)[0];
|
|
36
|
+
if (firstLine.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
|
|
37
|
+
const additionalDependencies = firstLine.substring(26).trim().split(',');
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
const additionalDeps = additionalDependencies.filter(dep => !seen.has(dep) && seen.add(dep)).sort().map(v => `'${v}'`).join(', ');
|
|
40
|
+
if (additionalDeps) {
|
|
41
|
+
compilation.updateAsset(name, new webpack_sources_1.RawSource(asset.source().replace(/('dependencies'\s+=>\s+(?:array\(|\[))(.*)([)\]], 'version')/g, (match, g1, g2, g3) => `${g1}${g2.length > 0 ? `${g2}, ${additionalDeps}` : additionalDeps}${g3}`)));
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
}
|