diff --git a/gulpfile.ts b/gulpfile.ts index 367b4d1b..a09931a1 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -18,28 +18,29 @@ import * as gulp from 'gulp'; import * as healthCheck from './packages/grpc-health-check/gulpfile'; import * as jsCore from './packages/grpc-js/gulpfile'; +import * as jsXds from './packages/grpc-js-xds/gulpfile'; import * as protobuf from './packages/proto-loader/gulpfile'; import * as internalTest from './test/gulpfile'; -const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install); +const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install, jsXds.install); const lint = gulp.parallel(jsCore.lint); -const build = gulp.series(jsCore.compile, protobuf.compile); +const build = gulp.series(jsCore.compile, protobuf.compile, jsXds.compile); const setup = gulp.series(installAll); const setupPureJSInterop = gulp.series(jsCore.install, protobuf.install, internalTest.install); -const clean = gulp.series(jsCore.clean, protobuf.clean); +const clean = gulp.series(jsCore.clean, protobuf.clean, jsXds.clean); -const cleanAll = gulp.series(jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll); +const cleanAll = gulp.series(jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll, jsXds.cleanAll); const nativeTestOnly = gulp.parallel(healthCheck.test); const nativeTest = gulp.series(build, nativeTestOnly); -const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test); +const testOnly = gulp.parallel(jsCore.test, nativeTestOnly, protobuf.test, jsXds.test); const test = gulp.series(build, testOnly, internalTest.test); diff --git a/packages/grpc-js-xds/gulpfile.ts b/packages/grpc-js-xds/gulpfile.ts new file mode 100644 index 00000000..4ee6ac2c --- /dev/null +++ b/packages/grpc-js-xds/gulpfile.ts @@ -0,0 +1,78 @@ +/* + * Copyright 2020 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import * as gulp from 'gulp'; + +import * as mocha from 'gulp-mocha'; +import * as path from 'path'; +import * as execa from 'execa'; +import * as semver from 'semver'; + +Error.stackTraceLimit = Infinity; + +const jsCoreDir = __dirname; +const outDir = path.resolve(jsCoreDir, 'build'); + +const pkgPath = path.resolve(jsCoreDir, 'package.json'); +const supportedVersionRange = require(pkgPath).engines.node; +const versionNotSupported = () => { + console.log(`Skipping grpc-js-xds task for Node ${process.version}`); + return () => { return Promise.resolve(); }; +}; +const identity = (value: any): any => value; +const checkTask = semver.satisfies(process.version, supportedVersionRange) ? + identity : versionNotSupported; + +const execNpmVerb = (verb: string, ...args: string[]) => + execa('npm', [verb, ...args], {cwd: jsCoreDir, stdio: 'inherit'}); +const execNpmCommand = execNpmVerb.bind(null, 'run'); + +const install = checkTask(() => execNpmVerb('install', '--unsafe-perm')); + +/** + * Runs tslint on files in src/, with linting rules defined in tslint.json. + */ +const lint = checkTask(() => execNpmCommand('check')); + +const cleanFiles = checkTask(() => execNpmCommand('clean')); + +const clean = gulp.series(install, cleanFiles); + +const cleanAll = gulp.parallel(clean); + +/** + * Transpiles TypeScript files in src/ to JavaScript according to the settings + * found in tsconfig.json. + */ +const compile = checkTask(() => execNpmCommand('compile')); + +const runTests = checkTask(() => { + return gulp.src(`${outDir}/test/**/*.js`) + .pipe(mocha({reporter: 'mocha-jenkins-reporter', + require: ['ts-node/register']})); +}); + +const test = gulp.series(install, runTests); + +export { + install, + lint, + clean, + cleanAll, + compile, + test +} diff --git a/packages/grpc-js-xds/package.json b/packages/grpc-js-xds/package.json index e22b40f5..78d90c1d 100644 --- a/packages/grpc-js-xds/package.json +++ b/packages/grpc-js-xds/package.json @@ -46,5 +46,8 @@ }, "peerDependencies": { "@grpc/grpc-js": "~1.2.0" + }, + "engines": { + "node": ">=10.10.0" } } diff --git a/packages/grpc-js-xds/src/index.ts b/packages/grpc-js-xds/src/index.ts index 5aea005d..06bea990 100644 --- a/packages/grpc-js-xds/src/index.ts +++ b/packages/grpc-js-xds/src/index.ts @@ -22,6 +22,9 @@ import * as load_balancer_lrs from './load-balancer-lrs'; import * as load_balancer_priority from './load-balancer-priority'; import * as load_balancer_weighted_target from './load-balancer-weighted-target'; +/** + * Register the "xds:" name scheme with the @grpc/grpc-js library. + */ export function register() { resolver_xds.setup(); load_balancer_cds.setup(); diff --git a/packages/grpc-js-xds/test/test-register.ts b/packages/grpc-js-xds/test/test-register.ts new file mode 100644 index 00000000..e7a07927 --- /dev/null +++ b/packages/grpc-js-xds/test/test-register.ts @@ -0,0 +1,27 @@ +/* + * Copyright 2020 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import * as assert from 'assert'; +import { register } from '../src'; + +/* This is just a basic test to confirm that the package builds and the setup + * code runs. */ +describe('register function', () => { + it('Should succeed without errors', () => { + assert.doesNotThrow(register); + }); +}); \ No newline at end of file diff --git a/packages/grpc-js-xds/tsconfig.json b/packages/grpc-js-xds/tsconfig.json index 3148d112..c121a5f6 100644 --- a/packages/grpc-js-xds/tsconfig.json +++ b/packages/grpc-js-xds/tsconfig.json @@ -10,6 +10,7 @@ }, "include": [ "src/**/*.ts", + "test/**/*.ts", "interop/**/*.ts" ] }