source: trip-planner-front/node_modules/license-webpack-plugin/dist/PluginFileHandler.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1"use strict";
2var __values = (this && this.__values) || function(o) {
3 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4 if (m) return m.call(o);
5 if (o && typeof o.length === "number") return {
6 next: function () {
7 if (o && i >= o.length) o = void 0;
8 return { value: o && o[i++], done: !o };
9 }
10 };
11 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.PluginFileHandler = void 0;
15var PluginFileHandler = /** @class */ (function () {
16 function PluginFileHandler(fileSystem, buildRoot, modulesDirectories, excludedPackageTest) {
17 this.fileSystem = fileSystem;
18 this.buildRoot = buildRoot;
19 this.modulesDirectories = modulesDirectories;
20 this.excludedPackageTest = excludedPackageTest;
21 this.cache = {};
22 }
23 PluginFileHandler.prototype.getModule = function (filename) {
24 return this.cache[filename] === undefined
25 ? (this.cache[filename] = this.getModuleInternal(filename))
26 : this.cache[filename];
27 };
28 PluginFileHandler.prototype.getModuleInternal = function (filename) {
29 var e_1, _a;
30 if (filename === null || filename === undefined) {
31 return null;
32 }
33 if (this.modulesDirectories !== null) {
34 var foundInModuleDirectory = false;
35 try {
36 for (var _b = __values(this.modulesDirectories), _c = _b.next(); !_c.done; _c = _b.next()) {
37 var modulesDirectory = _c.value;
38 if (this.fileSystem
39 .resolvePath(filename)
40 .startsWith(this.fileSystem.resolvePath(modulesDirectory))) {
41 foundInModuleDirectory = true;
42 }
43 }
44 }
45 catch (e_1_1) { e_1 = { error: e_1_1 }; }
46 finally {
47 try {
48 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
49 }
50 finally { if (e_1) throw e_1.error; }
51 }
52 if (!foundInModuleDirectory) {
53 return null;
54 }
55 }
56 var module = this.findModuleDir(filename);
57 if (module !== null && this.excludedPackageTest(module.name)) {
58 return null;
59 }
60 return module;
61 };
62 PluginFileHandler.prototype.findModuleDir = function (filename) {
63 var pathSeparator = this.fileSystem.pathSeparator;
64 var dirOfModule = filename.substring(0, filename.lastIndexOf(pathSeparator));
65 var oldDirOfModule = null;
66 while (!this.dirContainsValidPackageJson(dirOfModule)) {
67 // check parent directory
68 oldDirOfModule = dirOfModule;
69 dirOfModule = this.fileSystem.resolvePath("" + dirOfModule + pathSeparator + ".." + pathSeparator);
70 // reached filesystem root
71 if (oldDirOfModule === dirOfModule) {
72 return null;
73 }
74 }
75 if (this.buildRoot === dirOfModule) {
76 return null;
77 }
78 var packageJson = this.parsePackageJson(dirOfModule);
79 return {
80 packageJson: packageJson,
81 name: packageJson.name,
82 directory: dirOfModule
83 };
84 };
85 PluginFileHandler.prototype.parsePackageJson = function (dirOfModule) {
86 var packageJsonText = this.fileSystem.readFileAsUtf8(this.fileSystem.join(dirOfModule, PluginFileHandler.PACKAGE_JSON));
87 var packageJson = JSON.parse(packageJsonText);
88 return packageJson;
89 };
90 PluginFileHandler.prototype.dirContainsValidPackageJson = function (dirOfModule) {
91 if (!this.fileSystem.pathExists(this.fileSystem.join(dirOfModule, PluginFileHandler.PACKAGE_JSON))) {
92 return false;
93 }
94 var packageJson = this.parsePackageJson(dirOfModule);
95 return !!packageJson.name;
96 };
97 PluginFileHandler.PACKAGE_JSON = 'package.json';
98 return PluginFileHandler;
99}());
100exports.PluginFileHandler = PluginFileHandler;
Note: See TracBrowser for help on using the repository browser.