-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
debug.js
82 lines (74 loc) 路 2.11 KB
/
debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// @flow
import {
getInclusionReasons,
type Targets,
} from "@babel/helper-compilation-targets";
const wordEnds = (size: number) => {
return size > 1 ? "s" : "";
};
// Outputs a message that shows which target(s) caused an item to be included:
// transform-foo { "edge":"13", "firefox":"49", "ie":"10" }
export const logPluginOrPolyfill = (
item: string,
targetVersions: Targets,
list: { [key: string]: Targets },
) => {
const filteredList = getInclusionReasons(item, targetVersions, list);
const formattedTargets = JSON.stringify(filteredList)
.replace(/,/g, ", ")
.replace(/^\{"/, '{ "')
.replace(/"\}$/, '" }');
console.log(` ${item} ${formattedTargets}`);
};
export const logEntryPolyfills = (
polyfillName: string,
importPolyfillIncluded: boolean,
polyfills: Set<string>,
filename: string,
polyfillTargets: Targets,
allBuiltInsList: { [key: string]: Targets },
) => {
if (!importPolyfillIncluded) {
console.log(`\n[${filename}] Import of ${polyfillName} was not found.`);
return;
}
if (!polyfills.size) {
console.log(
`\n[${filename}] Based on your targets, polyfills were not added.`,
);
return;
}
console.log(
`\n[${filename}] Replaced ${polyfillName} entries with the following polyfill${wordEnds(
polyfills.size,
)}:`,
);
for (const polyfill of polyfills) {
logPluginOrPolyfill(polyfill, polyfillTargets, allBuiltInsList);
}
};
export const logUsagePolyfills = (
polyfills: Set<string>,
filename: string,
polyfillTargets: Targets,
allBuiltInsList: { [key: string]: Targets },
) => {
// normalize filename to generate consistent preset-env test fixtures
if (process.env.BABEL_ENV === "test") {
filename = filename.replace(/\\/g, "/");
}
if (!polyfills.size) {
console.log(
`\n[${filename}] Based on your code and targets, core-js polyfills were not added.`,
);
return;
}
console.log(
`\n[${filename}] Added following core-js polyfill${wordEnds(
polyfills.size,
)}:`,
);
for (const polyfill of polyfills) {
logPluginOrPolyfill(polyfill, polyfillTargets, allBuiltInsList);
}
};