UNPKG

2.44 kBJavaScriptView Raw
1'use strict';
2/* eslint-disable node/no-sync -- avoiding overcomplicating */
3/* eslint-disable unicorn/prefer-node-protocol -- ancient env possible */
4var fs = require('fs');
5var os = require('os');
6var path = require('path');
7
8var env = process.env;
9var ADBLOCK = is(env.ADBLOCK);
10var COLOR = is(env.npm_config_color);
11var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
12var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
13var OPEN_SOURCE_CONTRIBUTOR = is(env.OPEN_SOURCE_CONTRIBUTOR);
14var MINUTE = 60 * 1000;
15
16// you could add a PR with an env variable for your CI detection
17var CI = [
18 'BUILD_NUMBER',
19 'CI',
20 'CONTINUOUS_INTEGRATION',
21 'DRONE',
22 'RUN_ID'
23].some(function (it) { return is(env[it]); });
24
25var BANNER = '\u001B[96mThank you for using core-js (\u001B[94m https://github.com/zloirock/core-js \u001B[96m) for polyfilling JavaScript standard library!\u001B[0m\n\n' +
26 '\u001B[96mThe project needs your help! Please consider supporting core-js:\u001B[0m\n' +
27 '\u001B[96m>\u001B[94m https://opencollective.com/core-js \u001B[0m\n' +
28 '\u001B[96m>\u001B[94m https://patreon.com/zloirock \u001B[0m\n' +
29 '\u001B[96m>\u001B[94m https://boosty.to/zloirock \u001B[0m\n' +
30 '\u001B[96m>\u001B[94m bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz \u001B[0m\n\n' +
31 '\u001B[96mI highly recommend reading this:\u001B[94m https://github.com/zloirock/core-js/blob/master/docs/2023-02-14-so-whats-next.md \u001B[96m\u001B[0m\n';
32
33function is(it) {
34 return !!it && it !== '0' && it !== 'false';
35}
36
37function isBannerRequired() {
38 if (ADBLOCK || CI || DISABLE_OPENCOLLECTIVE || SILENT || OPEN_SOURCE_CONTRIBUTOR) return false;
39 var file = path.join(os.tmpdir(), 'core-js-banners');
40 var banners = [];
41 try {
42 var DELTA = Date.now() - fs.statSync(file).mtime;
43 if (DELTA >= 0 && DELTA < MINUTE * 3) {
44 banners = JSON.parse(fs.readFileSync(file));
45 if (banners.indexOf(BANNER) !== -1) return false;
46 }
47 } catch (error) {
48 banners = [];
49 }
50 try {
51 banners.push(BANNER);
52 fs.writeFileSync(file, JSON.stringify(banners), 'utf8');
53 } catch (error) { /* empty */ }
54 return true;
55}
56
57function showBanner() {
58 // eslint-disable-next-line no-console, regexp/no-control-character -- output
59 console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
60}
61
62if (isBannerRequired()) showBanner();