source: trip-planner-front/node_modules/@babel/helper-define-polyfill-provider/lib/node/dependencies.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: 2.7 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.resolve = resolve;
5exports.has = has;
6exports.logMissing = logMissing;
7exports.laterLogMissing = laterLogMissing;
8
9var _path = _interopRequireDefault(require("path"));
10
11var _lodash = _interopRequireDefault(require("lodash.debounce"));
12
13var _resolve = _interopRequireDefault(require("resolve"));
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9;
18
19function resolve(dirname, moduleName, absoluteImports) {
20 if (absoluteImports === false) return moduleName;
21 let basedir = dirname;
22
23 if (typeof absoluteImports === "string") {
24 basedir = _path.default.resolve(basedir, absoluteImports);
25 }
26
27 let modulePackage, moduleNestedPath;
28 let slash = moduleName.indexOf("/");
29
30 if (moduleName[0] === "@") {
31 slash = moduleName.indexOf("/", slash + 1);
32 }
33
34 if (slash === -1) {
35 modulePackage = moduleName;
36 moduleNestedPath = "";
37 } else {
38 modulePackage = moduleName.slice(0, slash);
39 moduleNestedPath = moduleName.slice(slash);
40 }
41
42 try {
43 let pkg;
44
45 if (nativeRequireResolve) {
46 // $FlowIgnore
47 pkg = require.resolve(`${modulePackage}/package.json`, {
48 paths: [basedir]
49 });
50 } else {
51 pkg = _resolve.default.sync(`${modulePackage}/package.json`, {
52 basedir
53 });
54 }
55
56 return _path.default.dirname(pkg) + moduleNestedPath;
57 } catch (err) {
58 if (err.code !== "MODULE_NOT_FOUND") throw err; // $FlowIgnore
59
60 throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), {
61 code: "BABEL_POLYFILL_NOT_FOUND",
62 polyfill: moduleName,
63 dirname
64 });
65 }
66}
67
68function has(basedir, name) {
69 try {
70 if (nativeRequireResolve) {
71 // $FlowIgnore
72 require.resolve(name, {
73 paths: [basedir]
74 });
75 } else {
76 _resolve.default.sync(name, {
77 basedir
78 });
79 }
80
81 return true;
82 } catch (_unused) {
83 return false;
84 }
85}
86
87function logMissing(missingDeps) {
88 if (missingDeps.size === 0) return;
89 const deps = Array.from(missingDeps).sort().join(" ");
90 console.warn("\nSome polyfills have been added but are not present in your dependencies.\n" + "Please run one of the following commands:\n" + `\tnpm install --save ${deps}\n` + `\tyarn add ${deps}\n`);
91 process.exitCode = 1;
92}
93
94let allMissingDeps = new Set();
95const laterLogMissingDependencies = (0, _lodash.default)(() => {
96 logMissing(allMissingDeps);
97 allMissingDeps = new Set();
98}, 100);
99
100function laterLogMissing(missingDeps) {
101 if (missingDeps.size === 0) return;
102 missingDeps.forEach(name => allMissingDeps.add(name));
103 laterLogMissingDependencies();
104}
Note: See TracBrowser for help on using the repository browser.