From d0f410d2e08f393f2661c8c92568a0b518fddf99 Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 27 Jul 2023 15:05:21 -0500 Subject: [PATCH] fix: make gapic-tools depend on gax-nodejs (#1480) * fix: make gapic-tools depend on gax-nodejs --- package.json | 7 +++---- tools/package.json | 3 ++- tools/src/compileProtos.ts | 10 ++++++++-- tools/test/compileProtos.ts | 20 ++++++++++++++++++++ tsconfig.json | 3 +++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6ff73734e..55655e0f0 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "c8": "^8.0.0", "codecov": "^3.1.0", "execa": "^5.0.0", - "gapic-tools": "^0.1.7", "google-proto-files": "^3.0.3", "gts": "^3.1.0", "linkinator": "^4.0.0", @@ -74,7 +73,7 @@ "compile-http-protos": "pbjs -t static-module -r http_proto --keep-case google/api/http.proto -p ./protos > protos/http.js && pbts protos/http.js -o protos/http.d.ts", "compile-showcase-proto": "pbjs -t json google/showcase/v1beta1/echo.proto google/showcase/v1beta1/identity.proto google/showcase/v1beta1/messaging.proto google/showcase/v1beta1/testing.proto -p ./protos > test/fixtures/google-gax-packaging-test-app/protos/protos.json && pbjs -t static-module -r showcase_protos google/showcase/v1beta1/echo.proto google/showcase/v1beta1/identity.proto google/showcase/v1beta1/messaging.proto google/showcase/v1beta1/testing.proto -p ./protos > test/fixtures/google-gax-packaging-test-app/protos/protos.js && pbts test/fixtures/google-gax-packaging-test-app/protos/protos.js -o test/fixtures/google-gax-packaging-test-app/protos/protos.d.ts", "fix": "gts fix", - "prepare": "npm run compile && prepublishProtos . && mkdirp build/protos && cp -r protos/* build/protos/ && npm run minify-proto-json", + "prepare": "npm run compile && node ./build/tools/src/prepublish.js . && mkdirp build/protos && cp -r protos/* build/protos/ && npm run minify-proto-json", "system-test": "c8 mocha build/test/system-test --timeout 600000 && npm run test-application", "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", "docs-test": "linkinator docs", @@ -83,8 +82,8 @@ "test-application": "cd test/test-application && npm run prefetch && npm install && npm start", "prelint": "cd samples; npm link ../; npm install", "precompile": "gts clean", - "update-protos": "listProtos .", - "minify-proto-json": "minifyProtoJson" + "update-protos": "node ./build/tools/src/listProtos.js .", + "minify-proto-json": "node ./build/tools/src/minify.js" }, "repository": "googleapis/gax-nodejs", "keywords": [ diff --git a/tools/package.json b/tools/package.json index 970828ab1..8530fdbd8 100644 --- a/tools/package.json +++ b/tools/package.json @@ -4,7 +4,7 @@ "description": "compiles, updates, and minifies protos", "main": "build/src/compileProtos.js", "files": [ - "build/tools/src", + "build/src", "!build/src/**/*.map" ], "scripts": { @@ -28,6 +28,7 @@ "author": "Google API Authors", "license": "Apache-2.0", "dependencies": { + "google-gax": "^4.0.2", "google-proto-files": "^3.0.3", "protobufjs-cli": "1.1.1", "rimraf": "^5.0.1", diff --git a/tools/src/compileProtos.ts b/tools/src/compileProtos.ts index d6245d41e..10d5e24d7 100644 --- a/tools/src/compileProtos.ts +++ b/tools/src/compileProtos.ts @@ -22,6 +22,12 @@ import * as util from 'util'; import * as pbjs from 'protobufjs-cli/pbjs'; import * as pbts from 'protobufjs-cli/pbts'; +export const gaxProtos = path.join( + require.resolve('google-gax'), + '..', + '..', + 'protos' +); const readdir = util.promisify(fs.readdir); const readFile = util.promisify(fs.readFile); const writeFile = util.promisify(fs.writeFile); @@ -246,7 +252,7 @@ async function compileProtos( '-p', 'protos', '-p', - path.join(__dirname, '..', '..', '..', 'google-gax', 'build', 'protos'), + gaxProtos, '-o', jsonOutput, ]; @@ -264,7 +270,7 @@ async function compileProtos( '-p', 'protos', '-p', - path.join(__dirname, '..', '..', '..', 'google-gax', 'build', 'protos'), + gaxProtos, '-o', jsOutput, ]; diff --git a/tools/test/compileProtos.ts b/tools/test/compileProtos.ts index 89b261a65..d9d68b49a 100644 --- a/tools/test/compileProtos.ts +++ b/tools/test/compileProtos.ts @@ -49,6 +49,26 @@ describe('compileProtos tool', () => { process.chdir(cwd); }); + it('fetches gax from the appropriate place', async () => { + assert.deepStrictEqual(fs.readdirSync(compileProtos.gaxProtos), [ + 'compute_operations.d.ts', + 'compute_operations.js', + 'compute_operations.json', + 'google', + 'http.d.ts', + 'http.js', + 'iam_service.d.ts', + 'iam_service.js', + 'iam_service.json', + 'locations.d.ts', + 'locations.js', + 'locations.json', + 'operations.d.ts', + 'operations.js', + 'operations.json', + 'status.json', + ]); + }); it('compiles protos to JSON, JS, TS', async function () { this.timeout(20000); await compileProtos.main([ diff --git a/tsconfig.json b/tsconfig.json index 0e984ded2..0921b23c8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,9 @@ }, "include": [ "src/*.ts", + "tools/src/listProtos.ts", + "tools/src/minify.ts", + "tools/src/prepublish.ts", "src/*/*.ts", "test/system-test/*.ts", "test/unit/*.ts",