1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.applyMissingDependenciesDefaults = applyMissingDependenciesDefaults;
|
---|
5 | exports.validateIncludeExclude = validateIncludeExclude;
|
---|
6 | var _utils = require("./utils");
|
---|
7 | function patternToRegExp(pattern) {
|
---|
8 | if (pattern instanceof RegExp) return pattern;
|
---|
9 | try {
|
---|
10 | return new RegExp(`^${pattern}$`);
|
---|
11 | } catch (_unused) {
|
---|
12 | return null;
|
---|
13 | }
|
---|
14 | }
|
---|
15 | function buildUnusedError(label, unused) {
|
---|
16 | if (!unused.length) return "";
|
---|
17 | return ` - The following "${label}" patterns didn't match any polyfill:\n` + unused.map(original => ` ${String(original)}\n`).join("");
|
---|
18 | }
|
---|
19 | function buldDuplicatesError(duplicates) {
|
---|
20 | if (!duplicates.size) return "";
|
---|
21 | return ` - The following polyfills were matched both by "include" and "exclude" patterns:\n` + Array.from(duplicates, name => ` ${name}\n`).join("");
|
---|
22 | }
|
---|
23 | function validateIncludeExclude(provider, polyfills, includePatterns, excludePatterns) {
|
---|
24 | let current;
|
---|
25 | const filter = pattern => {
|
---|
26 | const regexp = patternToRegExp(pattern);
|
---|
27 | if (!regexp) return false;
|
---|
28 | let matched = false;
|
---|
29 | for (const polyfill of polyfills.keys()) {
|
---|
30 | if (regexp.test(polyfill)) {
|
---|
31 | matched = true;
|
---|
32 | current.add(polyfill);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | return !matched;
|
---|
36 | };
|
---|
37 |
|
---|
38 | // prettier-ignore
|
---|
39 | const include = current = new Set();
|
---|
40 | const unusedInclude = Array.from(includePatterns).filter(filter);
|
---|
41 |
|
---|
42 | // prettier-ignore
|
---|
43 | const exclude = current = new Set();
|
---|
44 | const unusedExclude = Array.from(excludePatterns).filter(filter);
|
---|
45 | const duplicates = (0, _utils.intersection)(include, exclude);
|
---|
46 | if (duplicates.size > 0 || unusedInclude.length > 0 || unusedExclude.length > 0) {
|
---|
47 | throw new Error(`Error while validating the "${provider}" provider options:\n` + buildUnusedError("include", unusedInclude) + buildUnusedError("exclude", unusedExclude) + buldDuplicatesError(duplicates));
|
---|
48 | }
|
---|
49 | return {
|
---|
50 | include,
|
---|
51 | exclude
|
---|
52 | };
|
---|
53 | }
|
---|
54 | function applyMissingDependenciesDefaults(options, babelApi) {
|
---|
55 | const {
|
---|
56 | missingDependencies = {}
|
---|
57 | } = options;
|
---|
58 | if (missingDependencies === false) return false;
|
---|
59 | const caller = babelApi.caller(caller => caller == null ? void 0 : caller.name);
|
---|
60 | const {
|
---|
61 | log = "deferred",
|
---|
62 | inject = caller === "rollup-plugin-babel" ? "throw" : "import",
|
---|
63 | all = false
|
---|
64 | } = missingDependencies;
|
---|
65 | return {
|
---|
66 | log,
|
---|
67 | inject,
|
---|
68 | all
|
---|
69 | };
|
---|
70 | } |
---|