Repository navigation
Expand file tree
/
Copy pathgetPaths.js
More file actions
60 lines (54 loc) · 2 KB
/
Copy pathgetPaths.js
File metadata and controls
60 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** @typedef {import("@rspack/core").Compiler} Compiler */
/** @typedef {import("@rspack/core").Stats} Stats */
/** @typedef {import("@rspack/core").MultiStats} MultiStats */
/** @typedef {import("@rspack/core").Asset} Asset */
/** @typedef {import("../index.js").DevServerOption} DevServerOption */
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
/**
* @template {IncomingMessage} Request
* @template {ServerResponse} Response
* @param {import("../index.js").FilledContext<Request, Response>} context context
* @returns {{ outputPath: string, publicPath: string, assetsInfo: Map<string, Asset["info"]> | undefined }[]} paths
*/
function getPaths(context) {
const { stats, options } = context;
/* eslint-disable unicorn/prefer-logical-operator-over-ternary */
/** @type {Stats[]} */
const childStats =
/** @type {MultiStats} */
(stats).stats
? /** @type {MultiStats} */ (stats).stats
: [/** @type {Stats} */ (stats)];
/** @type {{ outputPath: string, publicPath: string, assetsInfo: Map<string, Asset["info"]> | undefined }[]} */
const publicPaths = [];
for (const { compilation } of childStats) {
if (
/** @type {DevServerOption} */
(compilation.options.devServer) === false
) {
continue;
}
// The `output.path` is always present and always absolute
const outputPath = compilation.getPath(
compilation.outputOptions.path || "",
);
const publicPath = options.publicPath
? compilation.getPath(/** @type {any} */ (options.publicPath))
: compilation.outputOptions.publicPath
? compilation.getPath(
/** @type {any} */ (compilation.outputOptions.publicPath),
)
: "";
const assetsInfo = new Map(
compilation.getAssets().map((asset) => [asset.name, asset.info]),
);
publicPaths.push({
outputPath,
publicPath,
assetsInfo,
});
}
return publicPaths;
}
export default getPaths;