UNPKG

4.11 kBJavaScriptView Raw
1/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. */
2
3/******************************************************************************
4 *
5 * You may not use the identified files except in compliance with the Apache
6 * License, Version 2.0 (the "License.")
7 *
8 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0.
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * NAME
19 * install.js
20 *
21 * DESCRIPTION
22 * This script is included in the npm bundle of node-oracledb. It
23 * is invoked by package.json during npm install.
24 *
25 * MAINTENANCE NOTES
26 * This file should only ever 'require' packages included in core Node.js.
27 *
28 *****************************************************************************/
29
30'use strict';
31
32const fs = require('fs');
33const nodbUtil = require('../lib/util.js');
34
35// Log standard output with an 'oracledb' prefix
36function log(message) { // eslint-disable-line
37 const args = Array.from(arguments);
38 args.unshift('oracledb');
39 console.log.apply(console, args);
40}
41
42// Log errors. It combines 'oracledb' with a stylized 'ERR' prefix
43function error(message) { // eslint-disable-line
44 const args = Array.from(arguments);
45 args.unshift('oracledb \x1b[31mERR!\x1b[0m');
46 console.error.apply(console, args);
47}
48
49// Print concluding messages and quit
50function done(err) {
51 let installUrl = 'https://oracle.github.io/node-oracledb/INSTALL.html';
52
53 if (err) { // Couldn't install the binary
54 error(err.message);
55 if (err.message.match(/^NJS-067/)) {
56 error('Try compiling node-oracledb source code using ' + installUrl + '#github');
57 } else if (err.message.match(/^NJS-069/)) {
58 error('An older node-oracledb version may work with Node.js ' + process.version);
59 }
60 process.exit(87);
61 } else { // Successfully installed
62 let arch;
63
64 if (process.arch === 'x64') {
65 arch = '64-bit';
66 } else {
67 arch = '32-bit';
68 }
69
70 if (process.platform === 'linux') {
71 installUrl += '#linuxinstall';
72 } else if (process.platform === 'darwin') {
73 installUrl += '#instosx';
74 } else if (process.platform === 'win32') {
75 installUrl += '#windowsinstallation';
76 }
77
78 log('********************************************************************************');
79 log('** Node-oracledb ' + nodbUtil.PACKAGE_JSON_VERSION + ' installed in Node.js ' + process.versions.node + ' (' + process.platform + ', ' + process.arch + ')');
80 log('**');
81 log('** To use node-oracledb:');
82 log('** - Oracle Client libraries (' + arch + ') must be available.');
83 log('** - Follow the installation instructions:');
84 log('** ' + installUrl);
85 log('********************************************************************************\n');
86 }
87}
88
89// Check for a usable binary file for the node-oracledb module. Node.js 8.16
90// and 10.16 (and 12.0) contain an important Node-API performance regression fix.
91// Note that the checked versions are the minimum required for Node-API
92// compatibility; as new Node.js versions are released, older Node.js versions
93// are dropped from the node-oracledb test plan. For example, the obsolete
94// Node.js 9 and 11 versions are not tested.
95
96function checkAvailable(cb) {
97 let vs = process.version.substring(1).split(".").map(Number);
98 if (vs[0] < 8 || (vs[0] === 8 && vs[1] < 16)) {
99 cb(new Error(nodbUtil.getErrorMessage('NJS-069', nodbUtil.PACKAGE_JSON_VERSION, "8.16")));
100 } else if (vs[0] === 10 && vs[1] < 16) {
101 cb(new Error(nodbUtil.getErrorMessage('NJS-069', nodbUtil.PACKAGE_JSON_VERSION, "10.16")));
102 } else {
103 try {
104 fs.statSync(nodbUtil.RELEASE_DIR + '/' + nodbUtil.BINARY_FILE);
105 cb();
106 } catch (err) {
107 cb(new Error(nodbUtil.getErrorMessage('NJS-067', process.platform + ' ' + process.arch)));
108 }
109 }
110}
111
112checkAvailable(done);