Skip to content

Commit 411e8eb

Browse files
fix: [tasks] Add client library version to headers (#5083)
* fix: Add client library version to headers fix: Allow bundlers to bundle JSON files correctly for ESM deps: Update dependency google-gax to ^4.3.1 fix: Export types from protos in ESM PiperOrigin-RevId: 609821360 Source-Link: googleapis/googleapis@5c5ecf0 Source-Link: googleapis/googleapis-gen@b875fcd Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXN0b3JhZ2VpbnNpZ2h0cy8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXN1cHBvcnQvLk93bEJvdC55YW1sIiwiaCI6ImI4NzVmY2RkMTRiNGRlZjY1MjE4MjkzMDAzZDliZWM0Yjg0MmVjYTcifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRhbGVudC8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRhc2tzLy5Pd2xCb3QueWFtbCIsImgiOiJiODc1ZmNkZDE0YjRkZWY2NTIxODI5MzAwM2Q5YmVjNGI4NDJlY2E3In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRleHR0b3NwZWVjaC8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRwdS8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoic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lLWNsb3VkLXZtd2FyZWVuZ2luZS8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXZwY2FjY2Vzcy8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXdlYnJpc2svLk93bEJvdC55YW1sIiwiaCI6ImI4NzVmY2RkMTRiNGRlZjY1MjE4MjkzMDAzZDliZWM0Yjg0MmVjYTcifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXdlYnNlY3VyaXR5c2Nhbm5lci8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXdvcmtmbG93cy1leGVjdXRpb25zLy5Pd2xCb3QueWFtbCIsImgiOiJiODc1ZmNkZDE0YjRkZWY2NTIxODI5MzAwM2Q5YmVjNGI4NDJlY2E3In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXdvcmtzdGF0aW9ucy8uT3dsQm90LnlhbWwiLCJoIjoiYjg3NWZjZGQxNGI0ZGVmNjUyMTgyOTMwMDNkOWJlYzRiODQyZWNhNyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWRhdGFmbG93Ly5Pd2xCb3QueWFtbCIsImgiOiJiODc1ZmNkZDE0YjRkZWY2NTIxODI5MzAwM2Q5YmVjNGI4NDJlY2E3In0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update package.json --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: sofisl <[email protected]>
1 parent 86b0c1f commit 411e8eb

6 files changed

Lines changed: 67 additions & 49 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/* eslint-disable node/no-missing-require */
16+
function getJSON(path) {
17+
return require(path);
18+
}
19+
20+
exports.getJSON = getJSON;

packages/google-cloud-tasks/esm/src/v2/cloud_tasks_client.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
3535
import fs from 'fs';
3636
import path from 'path';
3737
import {fileURLToPath} from 'url';
38+
import {getJSON} from '../json-helper.cjs';
3839
// @ts-ignore
3940
const dirname = path.dirname(fileURLToPath(import.meta.url));
4041

@@ -43,20 +44,16 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
4344
* `src/v2/cloud_tasks_client_config.json`.
4445
* This file defines retry strategy and timeouts for all API methods in this library.
4546
*/
46-
const gapicConfig = JSON.parse(
47-
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
47+
const gapicConfig = getJSON(
48+
path.join(dirname, 'cloud_tasks_client_config.json')
4849
);
49-
const jsonProtos = JSON.parse(
50-
fs.readFileSync(
51-
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
52-
'utf8'
53-
)
50+
51+
const jsonProtos = getJSON(
52+
path.join(dirname, '..', '..', '..', 'protos/protos.json')
5453
);
55-
const version = JSON.parse(
56-
fs.readFileSync(
57-
path.join(dirname, '..', '..', '..', '..', 'package.json'),
58-
'utf8'
59-
)
54+
55+
const version = getJSON(
56+
path.join(dirname, '..', '..', '..', '..', 'package.json')
6057
).version;
6158

6259
/**
@@ -215,10 +212,8 @@ export class CloudTasksClient {
215212
}
216213
// Add ESM headers
217214
const isEsm = true;
218-
if (opts.libVersion && isEsm) {
219-
clientHeader.push(`${opts.libVersion}-esm`);
220-
} else if (opts.libVersion && !isEsm) {
221-
clientHeader.push(`${opts.libVersion}-cjs`);
215+
if ((opts.libVersion || version) && isEsm) {
216+
clientHeader.push(`${opts.libVersion ?? version}-esm`);
222217
}
223218

224219
// Load the applicable protos.

packages/google-cloud-tasks/esm/src/v2beta2/cloud_tasks_client.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
3535
import fs from 'fs';
3636
import path from 'path';
3737
import {fileURLToPath} from 'url';
38+
import {getJSON} from '../json-helper.cjs';
3839
// @ts-ignore
3940
const dirname = path.dirname(fileURLToPath(import.meta.url));
4041

@@ -43,20 +44,16 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
4344
* `src/v2beta2/cloud_tasks_client_config.json`.
4445
* This file defines retry strategy and timeouts for all API methods in this library.
4546
*/
46-
const gapicConfig = JSON.parse(
47-
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
47+
const gapicConfig = getJSON(
48+
path.join(dirname, 'cloud_tasks_client_config.json')
4849
);
49-
const jsonProtos = JSON.parse(
50-
fs.readFileSync(
51-
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
52-
'utf8'
53-
)
50+
51+
const jsonProtos = getJSON(
52+
path.join(dirname, '..', '..', '..', 'protos/protos.json')
5453
);
55-
const version = JSON.parse(
56-
fs.readFileSync(
57-
path.join(dirname, '..', '..', '..', '..', 'package.json'),
58-
'utf8'
59-
)
54+
55+
const version = getJSON(
56+
path.join(dirname, '..', '..', '..', '..', 'package.json')
6057
).version;
6158

6259
/**
@@ -215,10 +212,8 @@ export class CloudTasksClient {
215212
}
216213
// Add ESM headers
217214
const isEsm = true;
218-
if (opts.libVersion && isEsm) {
219-
clientHeader.push(`${opts.libVersion}-esm`);
220-
} else if (opts.libVersion && !isEsm) {
221-
clientHeader.push(`${opts.libVersion}-cjs`);
215+
if ((opts.libVersion || version) && isEsm) {
216+
clientHeader.push(`${opts.libVersion ?? version}-esm`);
222217
}
223218

224219
// Load the applicable protos.

packages/google-cloud-tasks/esm/src/v2beta3/cloud_tasks_client.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
3535
import fs from 'fs';
3636
import path from 'path';
3737
import {fileURLToPath} from 'url';
38+
import {getJSON} from '../json-helper.cjs';
3839
// @ts-ignore
3940
const dirname = path.dirname(fileURLToPath(import.meta.url));
4041

@@ -43,20 +44,16 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
4344
* `src/v2beta3/cloud_tasks_client_config.json`.
4445
* This file defines retry strategy and timeouts for all API methods in this library.
4546
*/
46-
const gapicConfig = JSON.parse(
47-
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
47+
const gapicConfig = getJSON(
48+
path.join(dirname, 'cloud_tasks_client_config.json')
4849
);
49-
const jsonProtos = JSON.parse(
50-
fs.readFileSync(
51-
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
52-
'utf8'
53-
)
50+
51+
const jsonProtos = getJSON(
52+
path.join(dirname, '..', '..', '..', 'protos/protos.json')
5453
);
55-
const version = JSON.parse(
56-
fs.readFileSync(
57-
path.join(dirname, '..', '..', '..', '..', 'package.json'),
58-
'utf8'
59-
)
54+
55+
const version = getJSON(
56+
path.join(dirname, '..', '..', '..', '..', 'package.json')
6057
).version;
6158

6259
/**
@@ -215,10 +212,8 @@ export class CloudTasksClient {
215212
}
216213
// Add ESM headers
217214
const isEsm = true;
218-
if (opts.libVersion && isEsm) {
219-
clientHeader.push(`${opts.libVersion}-esm`);
220-
} else if (opts.libVersion && !isEsm) {
221-
clientHeader.push(`${opts.libVersion}-cjs`);
215+
if ((opts.libVersion || version) && isEsm) {
216+
clientHeader.push(`${opts.libVersion ?? version}-esm`);
222217
}
223218

224219
// Load the applicable protos.

packages/google-cloud-tasks/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
"types": "./build/cjs/src/index.d.ts",
2323
"default": "./build/cjs/src/index.cjs"
2424
}
25+
},
26+
"./build/protos/protos": {
27+
"import": {
28+
"types": "./build/protos/protos/protos.d.ts",
29+
"default": "./build/protos/protos/protos.js"
30+
},
31+
"require": {
32+
"types": "./build/protos/protos/protos.d.ts",
33+
"default": "./build/protos/protos/protos.cjs"
34+
}
2535
}
2636
},
2737
"files": [
@@ -62,7 +72,7 @@
6272
"prelint": "cd samples; npm link ../; npm i",
6373
"samples-test": "cd samples/ && npm link ../ && npm i && npm test",
6474
"test": "npm run test:esm && npm run test:cjs",
65-
"compile:esm": "tsc -p ./tsconfig.esm.json",
75+
"compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs",
6676
"babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files",
6777
"compile:cjs": "tsc -p ./tsconfig.json && npm run babel",
6878
"compile": "npm run compile:esm && npm run compile:cjs && cp -r protos build/protos"

packages/google-cloud-tasks/tsconfig.esm.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"esm/test/*.ts",
2121
"esm/test/**/*.ts",
2222
"esm/system-test/*.ts"
23+
],
24+
"exclude": [
25+
"esm/src/json-helper.cjs"
2326
]
2427
}

0 commit comments

Comments
 (0)