source: trip-planner-front/node_modules/webpack/lib/dependencies/LocalModulesHelpers.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[6a3a178]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const LocalModule = require("./LocalModule");
9
10const lookup = (parent, mod) => {
11 if (mod.charAt(0) !== ".") return mod;
12
13 var path = parent.split("/");
14 var segments = mod.split("/");
15 path.pop();
16
17 for (let i = 0; i < segments.length; i++) {
18 const seg = segments[i];
19 if (seg === "..") {
20 path.pop();
21 } else if (seg !== ".") {
22 path.push(seg);
23 }
24 }
25
26 return path.join("/");
27};
28
29exports.addLocalModule = (state, name) => {
30 if (!state.localModules) {
31 state.localModules = [];
32 }
33 const m = new LocalModule(name, state.localModules.length);
34 state.localModules.push(m);
35 return m;
36};
37
38exports.getLocalModule = (state, name, namedModule) => {
39 if (!state.localModules) return null;
40 if (namedModule) {
41 // resolve dependency name relative to the defining named module
42 name = lookup(namedModule, name);
43 }
44 for (let i = 0; i < state.localModules.length; i++) {
45 if (state.localModules[i].name === name) {
46 return state.localModules[i];
47 }
48 }
49 return null;
50};
Note: See TracBrowser for help on using the repository browser.