Skip to content

Commit acc4793

Browse files
committedSep 6, 2019
backport the latest postinstall script related changes
1 parent 6a3fe85 commit acc4793

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Changelog
2+
##### Unreleased [LEGACY]
3+
- Show similar `postinstall` messages only once per `npm i`, [#597](https://github.com/zloirock/core-js/issues/597)
4+
25
##### 2.6.9 [LEGACY] - 2019.05.27
36
- Some fixes and improvements of the `postinstall` script like support `npm` color config ([#556](https://github.com/zloirock/core-js/issues/556)) or adding support of `ADBLOCK` env variable
47

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"promises-tests": "promises-aplus-tests tests/promises-aplus/adapter",
3939
"observables-tests": "node tests/observables/adapter && node tests/observables/adapter-library",
4040
"test": "npm run grunt clean copy && npm run lint && npm run grunt livescript client karma:default && npm run grunt library karma:library && npm run promises-tests && npm run observables-tests && lsc tests/commonjs",
41-
"postinstall": "node scripts/postinstall || echo \"ignore\""
41+
"postinstall": "node postinstall || echo \"ignore\""
4242
},
4343
"license": "MIT",
4444
"keywords": [

‎postinstall.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable max-len */
2+
var fs = require('fs');
3+
var os = require('os');
4+
var path = require('path');
5+
var env = process.env;
6+
7+
var ADBLOCK = is(env.ADBLOCK);
8+
var CI = is(env.CI);
9+
var COLOR = is(env.npm_config_color);
10+
var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
11+
var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
12+
var MINUTE = 60 * 1000;
13+
14+
var 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' +
15+
'\u001B[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: \u001B[0m' +
16+
'\u001B[96m>\u001B[94m https://opencollective.com/core-js \u001B[0m' +
17+
'\u001B[96m>\u001B[94m https://www.patreon.com/zloirock \u001B[0m\n' +
18+
'\u001B[96mAlso, the author of core-js (\u001B[94m https://github.com/zloirock \u001B[96m) is looking for a good job -)\u001B[0m\n';
19+
20+
function is(it) {
21+
return !!it && it !== '0' && it !== 'false';
22+
}
23+
24+
function isBannerRequired() {
25+
if (ADBLOCK || CI || DISABLE_OPENCOLLECTIVE || SILENT) return false;
26+
var file = path.join(os.tmpdir(), 'core-js-banners');
27+
var banners = [];
28+
try {
29+
var DELTA = Date.now() - fs.statSync(file).mtime;
30+
if (DELTA >= 0 && DELTA < MINUTE * 3) {
31+
banners = JSON.parse(fs.readFileSync(file, 'utf8'));
32+
if (banners.indexOf(BANNER) !== -1) return false;
33+
}
34+
} catch (error) {
35+
banners = [];
36+
}
37+
try {
38+
banners.push(BANNER);
39+
fs.writeFileSync(file, JSON.stringify(banners), 'utf8');
40+
} catch (error) { /* empty */ }
41+
return true;
42+
}
43+
44+
function showBanner() {
45+
// eslint-disable-next-line no-console,no-control-regex
46+
console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
47+
}
48+
49+
if (isBannerRequired()) showBanner();

‎scripts/postinstall.js

-23
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.