1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const ModuleNotFoundError = require("../ModuleNotFoundError");
|
9 | const LazySet = require("../util/LazySet");
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const RESOLVE_OPTIONS = { dependencyType: "esm" };
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | exports.resolveMatchedConfigs = (compilation, configs) => {
|
32 |
|
33 | const resolved = new Map();
|
34 |
|
35 | const unresolved = new Map();
|
36 |
|
37 | const prefixed = new Map();
|
38 | const resolveContext = {
|
39 |
|
40 | fileDependencies: new LazySet(),
|
41 |
|
42 | contextDependencies: new LazySet(),
|
43 |
|
44 | missingDependencies: new LazySet()
|
45 | };
|
46 | const resolver = compilation.resolverFactory.get("normal", RESOLVE_OPTIONS);
|
47 | const context = compilation.compiler.context;
|
48 |
|
49 | return Promise.all(
|
50 | configs.map(([request, config]) => {
|
51 | if (/^\.\.?(\/|$)/.test(request)) {
|
52 |
|
53 | return new Promise(resolve => {
|
54 | resolver.resolve(
|
55 | {},
|
56 | context,
|
57 | request,
|
58 | resolveContext,
|
59 | (err, result) => {
|
60 | if (err || result === false) {
|
61 | err = err || new Error(`Can't resolve ${request}`);
|
62 | compilation.errors.push(
|
63 | new ModuleNotFoundError(null, err, {
|
64 | name: `shared module ${request}`
|
65 | })
|
66 | );
|
67 | return resolve();
|
68 | }
|
69 | resolved.set(result, config);
|
70 | resolve();
|
71 | }
|
72 | );
|
73 | });
|
74 | } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
|
75 |
|
76 | resolved.set(request, config);
|
77 | } else if (request.endsWith("/")) {
|
78 |
|
79 | prefixed.set(request, config);
|
80 | } else {
|
81 |
|
82 | unresolved.set(request, config);
|
83 | }
|
84 | })
|
85 | ).then(() => {
|
86 | compilation.contextDependencies.addAll(resolveContext.contextDependencies);
|
87 | compilation.fileDependencies.addAll(resolveContext.fileDependencies);
|
88 | compilation.missingDependencies.addAll(resolveContext.missingDependencies);
|
89 | return { resolved, unresolved, prefixed };
|
90 | });
|
91 | };
|