-
Notifications
You must be signed in to change notification settings - Fork 31
/
postinstall.js
94 lines (81 loc) · 3.67 KB
/
postinstall.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
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2015 IBM Corporation and Others. All Rights Reserved.
const fs = require('fs')
const path = require('path')
const fullIcu = require('./full-icu')
const myname = process.env.npm_package_name || 'full-icu'
function exit (reason) {
console.log(reason)
process.exit(0)
}
if (fullIcu.oldNode) {
exit('Not sure how to handle node < 0.12. Exiting.')
} else if (fullIcu.noi18n) {
exit('Note: Your node was not compiled with i18n support. Nothing to do, Exiting.')
} else if (fullIcu.icu_system) {
exit('Note: Your node was compiled to link against an ' +
'externally-provided ICU, so the locale data is not customizable ' +
'through this script. Exiting.')
} else if (!fullIcu.icu_small) {
// maybe already full icu, or some as-yet-unforseen case.
exit('Note: Your node was not compiled with the ‘small-icu’ case,' +
' so the ICU data is not customizable through this script. Exiting.')
} else if (fullIcu.icumaj < 54) {
// This is kind of a sanity check that the ICU version is correct.
// ICU 54 was what Node v0.12 started with.
throw Error('Don’t know how to work with ICU version ' + fullIcu.icumaj + ', sorry.')
}
const cwd = fs.realpathSync('.')
const isglobal = process.env.npm_config_global === 'true'
const relpath = isglobal ? cwd : path.join('node_modules', myname)
function advice () {
if (fullIcu.nodeDetectIcu) {
console.log('Note: If you manually copy ' + path.join(relpath, fullIcu.icudat) + ' to the directory ' +
path.normalize(path.join(relpath, '..', '.node-icu')) +
' node will automatically detect this data.')
if (fullIcu.nodeDetectIcu === 'maybe') {
console.log(' - at least when https://github.com/nodejs/node/issues/3460 lands')
}
}
if (fullIcu.nodeDetectIcu !== true) {
console.log('Node will use this ICU datafile if the environment variable NODE_ICU_DATA is set to “' + relpath + '”')
console.log('or with node --icu-data-dir=' + relpath + ' YOURAPP.js')
const asJson = { scripts: { start: 'node --icu-data-dir=' + relpath + ' YOURAPP.js' } }
console.log(' For package.json:')
console.log(JSON.stringify(asJson))
}
console.log('')
console.log('By the way, if you have full data, running this in node:')
// 9E8 is 10 days into January, so TimeZone independent
console.log("> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));")
console.log("... will show “enero”. If it shows “January” you don't have full data.")
}
// Choose install method
let npmInstall
// GitHub has v50+ as releases
// Experimentally, pull from GitHub for little endian
if (!process.env.FULL_ICU_PREFER_NPM) {
if (fullIcu.icumaj >= 67) {
// Pull from bin data zip, first arrived in ICU v67
// https://unicode-org.atlassian.net/browse/ICU-20600
npmInstall = require('./install-gh-data')
} else {
if (fullIcu.icuend === 'l') {
// Little Endian can pull from icu4c-src.zip which contains a prebuilt data file
npmInstall = require('./install-gh')
} else {
// Fall back to npm
console.log(`ICU data bin zip not available until ICU v${fullIcu.icumaj} for endianness ${fullIcu.icuend}: Falling back to npm`)
npmInstall = require('./install-spawn')
}
}
} else {
npmInstall = require('./install-spawn')
}
if (fs.existsSync(fullIcu.icudat)) {
console.log('√ ' + fullIcu.icudat + ' Already there (for Node ' + fullIcu.nodever + ' and small-icu ' + fullIcu.icuver + ')')
advice()
} else {
console.log('npm install ' + fullIcu.icupkg + ' (Node ' + fullIcu.nodever + ' and small-icu ' + fullIcu.icuver + ') -> ' + fullIcu.icudat)
npmInstall(fullIcu, advice)
}
console.log('News: Please see https://github.com/nodejs/full-icu-npm/issues/6')