Skip to content

Commit 52356d7

Browse files
committed
Install now keeps all binaries; chooose at runtime
1 parent d6bded1 commit 52356d7

14 files changed

+347
-366
lines changed

.npmignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ INSTALL.md
66
CONTRIBUTING.md
77
Makefile
88
binding.gyp
9-
oracledb-*.tgz
9+
*.tgz
1010
/doc
1111
/examples
1212
/test
@@ -26,8 +26,8 @@ oracledb-*.tgz
2626
/build/gyp-mac-tool
2727
/node_modules
2828
/oracle_private
29-
/package/build.js
30-
/package/buildv6binary.js
29+
/package/buildbinary.js
30+
/package/buildpackage.js
3131
/package/Staging
3232
/odpi
3333
/src

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ This release is currently under development.
5656
String limited to the VARCHAR2 length.
5757

5858
- Update install processes by bundling all pre-built binaries into the
59-
package uploaded to https://www.npmjs.com/package/oracledb. This
60-
removes the need for the installer to download a binary package from
61-
GitHub. Also, source code is no longer included in the npm package.
59+
https://www.npmjs.com/package/oracledb package, removing the need
60+
for a separate binary package download from GitHub. At runtime an
61+
appropriate binary is loaded by `require()`, if it exists, allowing
62+
one `node_modules/oracledb` install to be usable in different
63+
environments. Also, source code is no longer included in the npm
64+
package.
6265

6366
- Fixed a crash with high frequency notifications from CQN
6467
([#1009](https://github.com/oracle/node-oracledb/issues/1009)).

INSTALL.md

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ limitations under the License.
4141
- 3.11 [Node-oracledb Installation Without Internet Access](#offline)
4242
- 3.11.1 [Copying node-oracledb Binaries on Windows](#winbins)
4343
- 3.12 [Installing Node.js and Node-oracledb RPMs from yum.oracle.com](#instnoderpms)
44-
- 3.13 [Hosting your own node-oracledb Packages](#selfhost)
44+
- 3.13 [Building and Hosting your own node-oracledb Packages](#selfhost)
4545
4. [Installing Node-oracledb 1.x or 2.x](#installingoldvers)
4646
5. [Useful Resources for Node-oracledb](#otherresources)
4747
6. [Troubleshooting Node-oracledb Installation Problems](#troubleshooting)
@@ -69,8 +69,10 @@ guaranteed to be available or usable in your environment.
6969
#### <a name="mig31"></a> 1.1 Changes in node-oracledb version 3.1
7070

7171
Pre-built binaries are now contained in the package downloaded from
72-
npm. This removes the internally executed step of downloading a
73-
binary package from GitHub.
72+
npm. This removes the previous internally executed step of
73+
downloading a suitable binary package from GitHub. If install size is
74+
an issue, all binaries except those for the current Node.js version
75+
can be deleted with `npm run prune`.
7476

7577
Source code is no longer included in the package available from npm.
7678
To compile from source code, you need access to GitHub or its [Oracle
@@ -315,8 +317,7 @@ included in Node.js:
315317
npm install oracledb
316318
```
317319

318-
Available pre-built node-oracledb binaries can been seen on the
319-
[releases][41] page. They were built on Oracle Linux 6.
320+
The pre-built binaries were built on Oracle Linux 6.
320321

321322
If a pre-built binary is successfully installed but isn't usable
322323
because it depends on a different glibc version, uninstall
@@ -458,8 +459,7 @@ included in Node.js:
458459
npm install oracledb
459460
```
460461

461-
Available pre-built node-oracledb binaries can been seen on the
462-
[releases][41] page. They were built on Oracle Linux 6.
462+
The pre-built binaries were built on Oracle Linux 6.
463463

464464
If a pre-built binary is successfully installed but isn't usable
465465
because it depends on a different glibc version, uninstall
@@ -595,9 +595,6 @@ included in Node.js:
595595
npm install oracledb
596596
```
597597

598-
Available pre-built node-oracledb binaries can been seen on the
599-
[releases][41] page.
600-
601598
If a pre-built binary is successfully installed but isn't usable
602599
because it depends on a different glibc version, uninstall
603600
node-oracledb and install again from source code.
@@ -695,9 +692,6 @@ included in Node.js:
695692
npm install oracledb
696693
```
697694

698-
Available pre-built node-oracledb binaries can been seen on the
699-
[releases][41] page.
700-
701695
##### To install from source code:
702696

703697
If a pre-built node-oracledb binary is not installable, the binary can
@@ -819,9 +813,6 @@ included in Node.js:
819813
npm install oracledb
820814
```
821815

822-
Available pre-built node-oracledb binaries can been seen on the
823-
[releases][41] page.
824-
825816
##### To install from source code:
826817

827818
If a pre-built node-oracledb binary is not installable, the binary can
@@ -919,7 +910,7 @@ client installation. Make sure that `PATH` contains the correct
919910
binary directory, for example `C:\oracle\product\12.2.0\dbhome_1\bin`.
920911

921912
For easy development, the free [Oracle XE][20] version of the database
922-
is available on Linux. Applications developed with XE may be
913+
is available on Windows. Applications developed with XE may be
923914
immediately used with other editions of the Oracle Database.
924915

925916
You may need Administrator privileges to set environment variables or
@@ -952,9 +943,6 @@ included in Node.js:
952943
npm install oracledb
953944
```
954945

955-
Available pre-built node-oracledb binaries can been seen on the
956-
[releases][41] page.
957-
958946
##### To install from source code:
959947

960948
If a pre-built node-oracledb binary is not installable, the binary can
@@ -1427,7 +1415,7 @@ export NODE_PATH=$(npm root -g)
14271415
node myapp.js
14281416
```
14291417

1430-
### <a name="selfhost"></a> 3.13 Hosting your own node-oracledb Packages
1418+
### <a name="selfhost"></a> 3.13 Building and Hosting your own node-oracledb Packages
14311419

14321420
You can host node-oracledb packages locally.
14331421

@@ -1440,9 +1428,9 @@ can be used. See
14401428
[package/README](https://github.com/oracle/node-oracledb/blob/master/package/README.md)
14411429
for details.
14421430

1443-
If you make the package accessible on your local machine, for example
1444-
at https://www.example.com/oracledb-3.1.0.tgz, then your install
1445-
command would be:
1431+
If you make the package accessible on your local web server, for
1432+
example at https://www.example.com/oracledb-3.1.0.tgz, then your
1433+
install command would be:
14461434

14471435
```
14481436
npm install https://www.example.com/oracledb-3.1.0.tgz

lib/oracledb.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -30,44 +30,39 @@ var getConnectionPromisified;
3030
var poolCache = {};
3131
var tempUsedPoolAliases = {};
3232
var defaultPoolAlias = 'default';
33-
var binaryReleasePath = '../build/Release/oracledb.node';
34-
var binaryDebugPath = '../build/Debug/oracledb.node';
35-
36-
// Load the node-oracledb binary add-on that was built when 'npm
37-
// install' invoked node-gyp.
38-
// The Debug version of node-oracledb will only exist if 'npm install
39-
// --debug oracledb' was used. Typically only the maintainers of
40-
// node-oracledb do this.
41-
try {
42-
oracledbCLib = require(binaryReleasePath);
43-
} catch (err) {
44-
var nodeInfo = process.versions.node + ' (' + process.platform + ', ' + process.arch +')\n';
45-
var fullReleasePath = require('path').resolve(__dirname, binaryReleasePath);
46-
if (err.code === 'MODULE_NOT_FOUND') {
47-
try {
48-
oracledbCLib = require(binaryDebugPath);
49-
} catch (err) {
33+
34+
// Load the Oracledb binary
35+
36+
var binaryLocations = [
37+
'../' + nodbUtil.RELEASE_DIR + '/' + nodbUtil.BINARY_FILE, // pre-built binary
38+
'../' + nodbUtil.RELEASE_DIR + '/' + 'oracledb.node', // binary built from source
39+
'../build/Debug/oracledb.node' // debug binary
40+
];
41+
42+
for (var i = 0; i < binaryLocations.length; i++) {
43+
try {
44+
oracledbCLib = require(binaryLocations[i]);
45+
break;
46+
} catch(err) {
47+
if (err.code !== 'MODULE_NOT_FOUND' || i == binaryLocations.length - 1) {
48+
var nodeInfo;
5049
if (err.code === 'MODULE_NOT_FOUND') {
51-
// Neither Release or Debug binary was found but assume users wanted Release binary
52-
nodeInfo += 'Cannot find module ' + fullReleasePath + '\n' + nodbUtil.getInstallHelp();
53-
throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
50+
// none of the three binaries could be found
51+
nodeInfo = `\n Looked for ${binaryLocations.map(x => require('path').resolve(__dirname, x)).join(', ')}\n ${nodbUtil.getInstallURL()}\n`;
5452
} else {
55-
nodeInfo += 'Cannot load ' + binaryDebugPath + '\n';
56-
nodeInfo += 'Node.js require() error was: \n ' + err.message + '\n' + nodbUtil.getInstallHelp();
57-
throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
53+
nodeInfo = `\n Node.js require('oracledb') error was:\n ${err.message}\n ${nodbUtil.getInstallHelp()}\n`;
5854
}
55+
throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
5956
}
60-
} else {
61-
nodeInfo += 'Cannot load ' + fullReleasePath + '\n' + err.message + '\n' + nodbUtil.getInstallHelp();
62-
throw new Error(nodbUtil.getErrorMessage('NJS-045', nodeInfo));
6357
}
6458
}
6559

60+
// Oracledb functions and classes
61+
6662
oracledbCLib.Oracledb.prototype.newLob = function(iLob) {
6763
return new Lob(iLob, null, oracledbInst);
6864
};
6965

70-
7166
// This createPool function is used the override the createPool method of the
7267
// Oracledb class, which is defined in the C layer. The override allows us to do
7368
// things like extend out the pool instance prior to passing it to the caller.

lib/util.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -21,6 +21,18 @@
2121

2222
var util = require('util');
2323

24+
// Directory containing the node-oracledb add-on binary
25+
const RELEASE_DIR = 'build/Release';
26+
module.exports.RELEASE_DIR = RELEASE_DIR;
27+
28+
// The default node-oracledb add-on binary filename for this Node.js
29+
const BINARY_FILE = 'oracledb-abi' + process.versions.modules + '-' + process.platform + '-' + process.arch + '.node';
30+
module.exports.BINARY_FILE = BINARY_FILE;
31+
32+
// Staging directory used by maintainers building the npm package
33+
const STAGING_DIR = 'package/Staging';
34+
module.exports.STAGING_DIR = STAGING_DIR;
35+
2436
var EventEmitter = require('events').EventEmitter;
2537
var eventEmitterKeys = Object.keys(EventEmitter.prototype);
2638
var eventEmitterFuncKeys = eventEmitterKeys.filter(function(key) {
@@ -40,7 +52,7 @@ var errorMessages = {
4052
'NJS-041': 'NJS-041: cannot convert ResultSet to QueryStream after invoking methods',
4153
'NJS-042': 'NJS-042: cannot invoke ResultSet methods after converting to QueryStream',
4254
'NJS-043': 'NJS-043: ResultSet already converted to QueryStream',
43-
'NJS-045': 'NJS-045: cannot load the oracledb add-on binary for Node.js %s',
55+
'NJS-045': 'NJS-045: cannot load a node-oracledb binary for Node.js ' + process.versions.node + ' (' + process.platform + ' ' + process.arch + ') %s',
4456
'NJS-046': 'NJS-046: poolAlias "%s" already exists in the connection pool cache',
4557
'NJS-047': 'NJS-047: poolAlias "%s" not found in the connection pool cache',
4658
'NJS-054': 'NJS-054: binary build/Release/oracledb.node was not installed',
@@ -49,11 +61,17 @@ var errorMessages = {
4961
'NJS-067': 'NJS-067: a pre-built node-oracledb binary was not found for Node.js %s'
5062
};
5163

64+
// getInstallURL returns a string with installation URL
65+
function getInstallURL() {
66+
return('Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html');
67+
}
68+
69+
module.exports.getInstallURL = getInstallURL;
70+
5271
// getInstallHelp returns a string with installation usage tips that may be helpful
5372
function getInstallHelp() {
54-
var arch, url, mesg = '';
55-
mesg = 'Node-oracledb installation instructions: ';
56-
mesg += 'https://oracle.github.io/node-oracledb/INSTALL.html\n';
73+
var arch, url;
74+
var mesg = getInstallURL() + '\n';
5775
if (process.platform === 'linux') {
5876
if (process.arch === 'x64') {
5977
url = 'http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html\n';

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"scripts": {
4040
"testv6": "mocha --opts test/opts/mochaNodeV6.opts",
4141
"test": "mocha --opts test/opts/mocha.opts",
42-
"posttest": "node test/opts/version.js"
42+
"posttest": "node test/opts/version.js",
43+
"buildbinary": "node package/buildbinary.js",
44+
"buildpackage": "node package/buildpackage.js"
4345
},
4446
"engines": {
4547
"node": ">=6"

package/README.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
# Overview
22

3-
This directory is used for building the node-oracledb npm package.
3+
This directory is used for building the [node-oracledb npm
4+
package](https://www.npmjs.com/package/oracledb). The scripts can
5+
also be used to create custom packages for hosting on a local server.
6+
47
Most users do not need to use anything in this directory.
58

69
# Maintainers
710

8-
- The file `build.js` is used by node-oracledb maintainers to create
9-
node-oracledb binaries and the package to be uploaded to
10-
[npm](https://www.npmjs.com/package/oracledb).
11+
In a clone or copy of the repository:
1112

12-
- `node build.js binary` creates a binary for the current Node.js /
13-
node-oracledb / platform combination. The command `node
14-
buildv6binary.js` can be used with Node 6.
13+
- `npm run buildbinary` calls `buildbinary.js` to create a binary for
14+
the current node-oracledb / Node.js / platform combination.
1515

16-
- `node build.js package` makes the node-oracledb package containing
17-
the node-oracledb JavaScript files, the binaries, and a package.json
18-
that has an "install" script.
16+
- `npm run buildpackage` calls `buildpackage.js` to make the
17+
node-oracledb package containing the node-oracledb JavaScript files,
18+
the available binaries, and a package.json that has an "install"
19+
script and a "prune" script. The package will be created in the top
20+
level directory.
1921

20-
Before running this, all binaries and related build metadata
21-
information files from all Node.js / node-oracledb / platform
22-
combinations should be placed in the `package/Staging` directory.
22+
Before executing `npm run buildpackage`, all binaries and related
23+
build metadata information files from all node-oracledb / Node.js /
24+
platform combinations should be placed in the `package/Staging`
25+
directory.
2326

24-
- As part of `npm install oracledb`, the `package.json` install script
25-
invokes `package/install.js` to move the appropriate binary module
26-
to the correct directory.
27+
Package installation:
2728

28-
If a suitable binary is not available, installation will fail.
29-
Users must then compile node-oracledb using source code from GitHub.
29+
- As part of an `npm install` that uses the created package, the
30+
`package.json` install script runs `package/install.js` to check a
31+
binary module for the current Node.js and platform is available.
3032

31-
- By default `../package.json` doesn't have an install script target.
32-
This means that node-gyp will be invoked to compile node-oracledb.
33-
This allows installation from source code (via GitHub) when no
34-
suitable pre-built binary is available.
33+
If a suitable binary is not available, installation will fail.
34+
Users must then compile node-oracledb using source code from GitHub,
35+
or choose an alternative Node.js / platform that has a pre-built
36+
binary module.
37+
38+
- After install, space conscious users can run `npm run prune` which
39+
removes pre-built binaries for all other Node.js releases and
40+
architectures.
41+
42+
By default the top level `package.json` doesn't have an install script
43+
target. This means that node-gyp will be invoked to compile
44+
node-oracledb. This allows installation from [source
45+
code](https://oracle.github.io/node-oracledb/INSTALL.html#github) (via
46+
GitHub) when no suitable pre-built binary is available.

0 commit comments

Comments
 (0)