1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.resolve = resolve;
|
---|
5 | exports.has = has;
|
---|
6 | exports.logMissing = logMissing;
|
---|
7 | exports.laterLogMissing = laterLogMissing;
|
---|
8 |
|
---|
9 | var _path = _interopRequireDefault(require("path"));
|
---|
10 |
|
---|
11 | var _lodash = _interopRequireDefault(require("lodash.debounce"));
|
---|
12 |
|
---|
13 | var _resolve = _interopRequireDefault(require("resolve"));
|
---|
14 |
|
---|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
16 |
|
---|
17 | const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9;
|
---|
18 |
|
---|
19 | function 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 |
|
---|
68 | function 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 |
|
---|
87 | function 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 |
|
---|
94 | let allMissingDeps = new Set();
|
---|
95 | const laterLogMissingDependencies = (0, _lodash.default)(() => {
|
---|
96 | logMissing(allMissingDeps);
|
---|
97 | allMissingDeps = new Set();
|
---|
98 | }, 100);
|
---|
99 |
|
---|
100 | function laterLogMissing(missingDeps) {
|
---|
101 | if (missingDeps.size === 0) return;
|
---|
102 | missingDeps.forEach(name => allMissingDeps.add(name));
|
---|
103 | laterLogMissingDependencies();
|
---|
104 | } |
---|