[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports.has = has;
|
---|
| 5 | exports.laterLogMissing = laterLogMissing;
|
---|
| 6 | exports.logMissing = logMissing;
|
---|
| 7 | exports.resolve = resolve;
|
---|
| 8 | var _path = _interopRequireDefault(require("path"));
|
---|
| 9 | var _lodash = _interopRequireDefault(require("lodash.debounce"));
|
---|
| 10 | var _resolve = _interopRequireDefault(require("resolve"));
|
---|
| 11 | var _module = require("module");
|
---|
| 12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 13 | const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9;
|
---|
| 14 | // eslint-disable-line
|
---|
| 15 |
|
---|
| 16 | function myResolve(name, basedir) {
|
---|
| 17 | if (nativeRequireResolve) {
|
---|
| 18 | return require.resolve(name, {
|
---|
| 19 | paths: [basedir]
|
---|
| 20 | }).replace(/\\/g, "/");
|
---|
| 21 | } else {
|
---|
| 22 | return _resolve.default.sync(name, {
|
---|
| 23 | basedir
|
---|
| 24 | }).replace(/\\/g, "/");
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 | function resolve(dirname, moduleName, absoluteImports) {
|
---|
| 28 | if (absoluteImports === false) return moduleName;
|
---|
| 29 | let basedir = dirname;
|
---|
| 30 | if (typeof absoluteImports === "string") {
|
---|
| 31 | basedir = _path.default.resolve(basedir, absoluteImports);
|
---|
| 32 | }
|
---|
| 33 | try {
|
---|
| 34 | return myResolve(moduleName, basedir);
|
---|
| 35 | } catch (err) {
|
---|
| 36 | if (err.code !== "MODULE_NOT_FOUND") throw err;
|
---|
| 37 | throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), {
|
---|
| 38 | code: "BABEL_POLYFILL_NOT_FOUND",
|
---|
| 39 | polyfill: moduleName,
|
---|
| 40 | dirname
|
---|
| 41 | });
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | function has(basedir, name) {
|
---|
| 45 | try {
|
---|
| 46 | myResolve(name, basedir);
|
---|
| 47 | return true;
|
---|
| 48 | } catch (_unused) {
|
---|
| 49 | return false;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | function logMissing(missingDeps) {
|
---|
| 53 | if (missingDeps.size === 0) return;
|
---|
| 54 | const deps = Array.from(missingDeps).sort().join(" ");
|
---|
| 55 | 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`);
|
---|
| 56 | process.exitCode = 1;
|
---|
| 57 | }
|
---|
| 58 | let allMissingDeps = new Set();
|
---|
| 59 | const laterLogMissingDependencies = (0, _lodash.default)(() => {
|
---|
| 60 | logMissing(allMissingDeps);
|
---|
| 61 | allMissingDeps = new Set();
|
---|
| 62 | }, 100);
|
---|
| 63 | function laterLogMissing(missingDeps) {
|
---|
| 64 | if (missingDeps.size === 0) return;
|
---|
| 65 | missingDeps.forEach(name => allMissingDeps.add(name));
|
---|
| 66 | laterLogMissingDependencies();
|
---|
| 67 | } |
---|