UNPKG

4.93 kBJavaScriptView Raw
1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
2
3/******************************************************************************
4 *
5 * This software is dual-licensed to you under the Universal Permissive License
6 * (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7 * 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
8 * either license.
9 *
10 * If you elect to accept the software under the Apache License, Version 2.0,
11 * the following applies:
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * https://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 * NAME
26 * install.js
27 *
28 * DESCRIPTION
29 * This script is included in the npm bundle of node-oracledb. It
30 * is invoked by package.json during npm install to check the viability
31 * of the installation.
32 *
33 * MAINTENANCE NOTES
34 * This file should only ever 'require' packages included in core Node.js
35 * or that are part of node-oracledb.
36 *
37 *****************************************************************************/
38
39'use strict';
40
41const fs = require('fs');
42const nodbUtil = require('../lib/util.js');
43const errors = require('../lib/errors.js');
44const constants = require('../lib/constants.js');
45
46let installUrl = constants.DEFAULT_ERROR_URL;
47let arch;
48let thickModeErrMsg;
49
50// Log standard output with an 'oracledb' prefix
51function log(message) { // eslint-disable-line
52 const args = Array.from(arguments);
53 args.unshift('oracledb');
54 console.log.apply(console, args);
55}
56
57// Log errors. It combines 'oracledb' with a stylized 'ERR' prefix
58function error(message) { // eslint-disable-line
59 const args = Array.from(arguments);
60 args.unshift('oracledb \x1b[31mERR!\x1b[0m');
61 console.error.apply(console, args);
62}
63
64// Log warnings. It combines 'oracledb' with a stylized 'WARN' prefix
65function warn(message) { // eslint-disable-line
66 const args = Array.from(arguments);
67 args.unshift('oracledb \x1b[31mWARN!\x1b[0m');
68 console.error.apply(console, args);
69}
70
71// This version of node-oracledb works with Node.js 14.6 or later.
72// Note: the checked version is the minimum required for Node-API
73// compatibility. When new Node.js versions are released, older Node.js
74// versions are dropped from the node-oracledb test plan.
75//
76// Keep this code in sync with lib/oracledb.js
77function checkVersion() {
78 const vs = process.version.substring(1).split(".").map(Number);
79 errors.assert(vs[0] > 14 || (vs[0] === 14 && vs[1] >= 6),
80 errors.ERR_NODE_TOO_OLD, nodbUtil.PACKAGE_JSON_VERSION, "14.6");
81}
82
83// Check for the binary node-oracledb module needed for "Thick mode".
84// If one isn't available, only Thin mode can be used.
85function checkThickMode() {
86 try {
87 fs.statSync(nodbUtil.RELEASE_DIR + '/' + nodbUtil.BINARY_FILE);
88 } catch (err) {
89 errors.throwErr(errors.ERR_NO_BINARY_AVAILABLE, process.platform + ' ' + process.arch);
90 }
91}
92
93try {
94 checkVersion();
95} catch (err) {
96 // This version of Node.js is too old
97 error(err.message);
98 error('An older node-oracledb version may work with Node.js ' + process.version);
99 process.exit(87);
100}
101
102try {
103 checkThickMode();
104} catch (err) {
105 // No Thick mode binary was found for this platform
106 thickModeErrMsg = err.message;
107}
108
109// Successfully installed
110
111if (process.arch === 'x64' || process.arch === 'arm64') {
112 arch = '64-bit';
113} else {
114 arch = '32-bit';
115}
116
117if (process.platform === 'linux') {
118 installUrl += '#node-oracledb-installation-on-linux';
119} else if (process.platform === 'darwin') {
120 installUrl += '#node-oracledb-installation-on-apple-macos-intel-x86';
121} else if (process.platform === 'win32') {
122 installUrl += '#node-oracledb-installation-on-microsoft-windowsstallation';
123}
124
125log('********************************************************************************');
126log('** Node-oracledb ' + nodbUtil.PACKAGE_JSON_VERSION + ' installed in Node.js ' + process.versions.node + ' (' + process.platform + ', ' + process.arch + ')');
127log('** To use node-oracledb in Thin mode, no additional steps are needed.');
128if (thickModeErrMsg) {
129 warn(thickModeErrMsg);
130 warn('If you want to use the optional Thick mode, compile node-oracledb code using');
131 warn(installUrl + '#github');
132} else {
133 log('** To use the optional Thick mode, the Oracle Client libraries (' + arch + ')');
134 log('** must be available, see the installation instructions:');
135 log('** ' + installUrl);
136}
137log('********************************************************************************\n');