mirror of https://github.com/grpc/grpc-node.git
client lib integration changes
This commit is contained in:
parent
68c4ca311a
commit
6c1f4bc621
|
@ -1 +1 @@
|
||||||
nodejs-*/
|
libs/nodejs-*/
|
|
@ -3,11 +3,13 @@
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
for dir in $(node -p "require('./repositories.json').join('\n')"); do
|
for dir in $(node -p "require('./repositories.json').join('\n')"); do
|
||||||
|
pushd libs
|
||||||
if [ ! -d $dir ]; then
|
if [ ! -d $dir ]; then
|
||||||
git clone https://github.com/googleapis/$dir
|
git clone https://github.com/googleapis/$dir
|
||||||
fi
|
|
||||||
pushd $dir
|
pushd $dir
|
||||||
npm install
|
npm install
|
||||||
popd
|
popd
|
||||||
node --require ./use-grpc-js.js $(npm bin)/_mocha --timeout 60000 $dir/system-test/*.js
|
fi
|
||||||
|
popd
|
||||||
|
SMOKE_TEST_PROJECT=$GCLOUD_PROJECT node --require ./use-grpc-js.js $(npm bin)/_mocha --timeout 60000 libs/$dir/system-test/*.js
|
||||||
done
|
done
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"dot-prop": "^4.2.0",
|
||||||
|
"google-proto-files": "^0.15.1",
|
||||||
"mocha": "^5.0.4",
|
"mocha": "^5.0.4",
|
||||||
"shimmer": "^1.2.0"
|
"shimmer": "^1.2.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
[
|
[
|
||||||
|
"nodejs-bigtable",
|
||||||
"nodejs-datastore",
|
"nodejs-datastore",
|
||||||
"nodejs-language",
|
|
||||||
"nodejs-storage",
|
|
||||||
"nodejs-translate",
|
|
||||||
"nodejs-logging",
|
|
||||||
"nodejs-video-intelligence",
|
|
||||||
"nodejs-dlp",
|
"nodejs-dlp",
|
||||||
"nodejs-firestore",
|
"nodejs-firestore",
|
||||||
|
"nodejs-language",
|
||||||
|
"nodejs-logging",
|
||||||
|
"nodejs-monitoring",
|
||||||
"nodejs-pubsub",
|
"nodejs-pubsub",
|
||||||
"nodejs-spanner",
|
"nodejs-spanner",
|
||||||
"nodejs-speech",
|
"nodejs-speech",
|
||||||
"nodejs-vision",
|
"nodejs-video-intelligence",
|
||||||
"nodejs-bigquery",
|
"nodejs-vision"
|
||||||
"nodejs-monitoring",
|
|
||||||
"nodejs-bigtable",
|
|
||||||
"nodejs-dns",
|
|
||||||
"nodejs-resource",
|
|
||||||
"nodejs-compute"
|
|
||||||
]
|
]
|
|
@ -1,18 +1,97 @@
|
||||||
|
require('source-map-support/register');
|
||||||
const Module = require('module');
|
const Module = require('module');
|
||||||
const shimmer = require('shimmer');
|
const shimmer = require('shimmer');
|
||||||
|
|
||||||
const grpcImpl = require('../../packages/grpc-js-core');
|
|
||||||
const grpcPJson = require('../../packages/grpc-js-core/package');
|
const grpcPJson = require('../../packages/grpc-js-core/package');
|
||||||
|
const grpcImpl = require('../../packages/grpc-js-core');
|
||||||
|
const grpcProtobuf = require('../../packages/grpc-protobufjs');
|
||||||
|
|
||||||
shimmer.wrap(Module, '_load', (moduleLoad) => {
|
if (!process.env.USE_GRPC_NATIVE) {
|
||||||
return function Module_load(path, parent) {
|
shimmer.wrap(Module, '_load', (moduleLoad) => {
|
||||||
if (path === 'grpc') {
|
return function Module_load(moduleName, parent) {
|
||||||
|
if (moduleName === 'grpc') {
|
||||||
|
// load grpc-js when grpc is requested.
|
||||||
return grpcImpl;
|
return grpcImpl;
|
||||||
} else if (path.startsWith('grpc/package')) {
|
} else if (moduleName.startsWith('grpc/package')) {
|
||||||
|
// load grpc-js's package.json when grpc's package.json is requested.
|
||||||
return grpcPJson;
|
return grpcPJson;
|
||||||
} else {
|
} else {
|
||||||
const result = moduleLoad.apply(this, arguments);
|
const result = moduleLoad.apply(this, arguments);
|
||||||
|
// monkeypatch google-gax and @google-cloud/common-grpc to avoid all
|
||||||
|
// references to grpc.load and grpc.loadObject, implementing functions
|
||||||
|
// on top of the new API for loading proto files.
|
||||||
|
if (moduleName === 'google-gax') {
|
||||||
|
if (!result.grpc.prototype.load.__wrapped) {
|
||||||
|
shimmer.wrap(result.grpc.prototype, 'load', (gaxLoad) => {
|
||||||
|
return function (filename, format, options) {
|
||||||
|
if (Array.isArray(filename)) {
|
||||||
|
options = filename[2];
|
||||||
|
filename = filename[0];
|
||||||
|
}
|
||||||
|
const packageDef = grpcProtobuf.loadSync(filename.file, {
|
||||||
|
keepCase: false,
|
||||||
|
defaults: true,
|
||||||
|
enums: String,
|
||||||
|
include: [filename.root]
|
||||||
|
});
|
||||||
|
return grpcImpl.loadPackageDefinition(packageDef);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!result.grpc.prototype.loadProto.__wrapped) {
|
||||||
|
shimmer.wrap(result.grpc.prototype, 'loadProto', (gaxLoadProto) => {
|
||||||
|
const path = require('path');
|
||||||
|
const googleProtoFilesDir = require('google-proto-files')('..');
|
||||||
|
|
||||||
|
return function (protoPath, filename) {
|
||||||
|
const packageDef = grpcProtobuf.loadSync(filename, {
|
||||||
|
keepCase: false,
|
||||||
|
defaults: true,
|
||||||
|
enums: String,
|
||||||
|
include: [protoPath, googleProtoFilesDir]
|
||||||
|
});
|
||||||
|
return grpcImpl.loadPackageDefinition(packageDef);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (moduleName === '@google-cloud/common-grpc') {
|
||||||
|
if (!result.Service.prototype.loadProtoFile_.__wrapped) {
|
||||||
|
shimmer.wrap(result.Service.prototype, 'loadProtoFile_', (commonLoad) => {
|
||||||
|
const dotProp = require('dot-prop');
|
||||||
|
// loadProtoFile_ uses a module-scope cache of loaded proto
|
||||||
|
// objects which isn't referenced anywhere else
|
||||||
|
const protoObjectCache = {};
|
||||||
|
|
||||||
|
return function (protoConfig, config) {
|
||||||
|
if (typeof protoConfig === 'string') {
|
||||||
|
protoConfig = { path: protoConfig };
|
||||||
|
}
|
||||||
|
|
||||||
|
const protoObjectCacheKey = [
|
||||||
|
config.protosDir,
|
||||||
|
protoConfig.path,
|
||||||
|
protoConfig.service,
|
||||||
|
].join('$');
|
||||||
|
|
||||||
|
if (!protoObjectCache[protoObjectCacheKey]) {
|
||||||
|
const services = grpcProtobuf.loadSync(protoConfig.path, {
|
||||||
|
keepCase: false,
|
||||||
|
bytes: 'string',
|
||||||
|
defaults: true,
|
||||||
|
enums: String,
|
||||||
|
include: [config.protosDir]
|
||||||
|
});
|
||||||
|
const service = dotProp.get(services.google, protoConfig.service);
|
||||||
|
protoObjectCache[protoObjectCacheKey] = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
return protoObjectCache[protoObjectCacheKey];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue