source: imaps-frontend/node_modules/webpack/lib/sharing/resolveMatchedConfigs.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const ModuleNotFoundError = require("../ModuleNotFoundError");
9const LazySet = require("../util/LazySet");
10
11/** @typedef {import("../Compilation")} Compilation */
12/** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
13
14/**
15 * @template T
16 * @typedef {object} MatchedConfigs
17 * @property {Map<string, T>} resolved
18 * @property {Map<string, T>} unresolved
19 * @property {Map<string, T>} prefixed
20 */
21
22/** @type {ResolveOptionsWithDependencyType} */
23const RESOLVE_OPTIONS = { dependencyType: "esm" };
24
25/**
26 * @template T
27 * @param {Compilation} compilation the compilation
28 * @param {[string, T][]} configs to be processed configs
29 * @returns {Promise<MatchedConfigs<T>>} resolved matchers
30 */
31module.exports.resolveMatchedConfigs = (compilation, configs) => {
32 /** @type {Map<string, T>} */
33 const resolved = new Map();
34 /** @type {Map<string, T>} */
35 const unresolved = new Map();
36 /** @type {Map<string, T>} */
37 const prefixed = new Map();
38 const resolveContext = {
39 /** @type {LazySet<string>} */
40 fileDependencies: new LazySet(),
41 /** @type {LazySet<string>} */
42 contextDependencies: new LazySet(),
43 /** @type {LazySet<string>} */
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 // eslint-disable-next-line array-callback-return
51 configs.map(([request, config]) => {
52 if (/^\.\.?(\/|$)/.test(request)) {
53 // relative request
54 return new Promise(resolve => {
55 resolver.resolve(
56 {},
57 context,
58 request,
59 resolveContext,
60 (err, result) => {
61 if (err || result === false) {
62 err = err || new Error(`Can't resolve ${request}`);
63 compilation.errors.push(
64 new ModuleNotFoundError(null, err, {
65 name: `shared module ${request}`
66 })
67 );
68 return resolve(null);
69 }
70 resolved.set(/** @type {string} */ (result), config);
71 resolve(null);
72 }
73 );
74 });
75 } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
76 // absolute path
77 resolved.set(request, config);
78 } else if (request.endsWith("/")) {
79 // module request prefix
80 prefixed.set(request, config);
81 } else {
82 // module request
83 unresolved.set(request, config);
84 }
85 })
86 ).then(() => {
87 compilation.contextDependencies.addAll(resolveContext.contextDependencies);
88 compilation.fileDependencies.addAll(resolveContext.fileDependencies);
89 compilation.missingDependencies.addAll(resolveContext.missingDependencies);
90 return { resolved, unresolved, prefixed };
91 });
92};
Note: See TracBrowser for help on using the repository browser.