Skip to content

Commit 6773a05

Browse files
feat: [tasks] publish cloud tasks in esm and cjs (#4720)
* build: publish cloud tasks in dual-format (ESM) PiperOrigin-RevId: 568908853 Source-Link: googleapis/googleapis@a7e2f4f Source-Link: googleapis/googleapis-gen@e64b67d Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRhc2tzLy5Pd2xCb3QueWFtbCIsImgiOiJlNjRiNjdkMjc1ZDE4YTMwZDRiZjQ2NDI4YmZkNzBiOGIxMmZhOTA5In0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update owlbot.py * save for now * chore: update index.ts * add long dependency * remove templates * run lint * fix tests * fix lint * update samples and system tests * Update gapic_cloud_tasks_v2.ts * chore: remove comments * remove .d.ts files * update post processor * 🦉 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 * Owl Bot copied code from googleapis/googleapis-gen@e64b67d * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update index.ts * Update owlbot.py * 🦉 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 owlbot.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update index.ts * Rename index.js to index.cjs * Update install.ts * Create index.js * Update install.ts * Update package.json * Update package.json * Update package.json * chore: get system tests working * update test * fix async tests --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: sofisl <[email protected]> Co-authored-by: Sofia Leon <[email protected]>
1 parent fe7dc9e commit 6773a05

40 files changed

Lines changed: 106555 additions & 49837 deletions

.github/.OwlBot.lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs-mono-repo:latest
16-
digest: sha256:353f74808df01ad8a4af996cac8acffcd9c087590743340bda440874cf55d566
16+
digest: sha256:2bd6069d367ef0365b62f767340e701c9ffc542c8a771bb5acc25372b43e2e15
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"presets": [
3+
"@babel/preset-typescript",
4+
"@babel/env"
5+
],
6+
"plugins": [
7+
[
8+
"replace-import-extension",
9+
{
10+
"extMapping": {
11+
".js": ".cjs"
12+
}
13+
}
14+
],
15+
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js",
16+
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js",
17+
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js"
18+
]
19+
}

packages/google-cloud-tasks/.eslintignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ test/fixtures
44
build/
55
docs/
66
protos/
7-
samples/generated/
7+
samples/
8+
esm/src/**/*.d.ts
9+
esm/test/**/*.d.ts
10+
esm/system-test/**/*.d.ts
11+
esm/system-test/fixtures/sample/src/*.ts

packages/google-cloud-tasks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ system-test/*key.json
1212
.DS_Store
1313
package-lock.json
1414
__pycache__
15+
esm/**/*.d.ts
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// ** https://github.com/googleapis/gapic-generator-typescript **
1717
// ** All changes to this file may be overwritten. **
1818

19-
'use strict';
2019

2120
module.exports = {
2221
opts: {
File renamed without changes.

packages/google-cloud-tasks/src/index.ts renamed to packages/google-cloud-tasks/esm/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
// ** https://github.com/googleapis/synthtool **
1717
// ** All changes to this file may be overwritten. **
1818

19-
import * as v2 from './v2';
20-
import * as v2beta2 from './v2beta2';
21-
import * as v2beta3 from './v2beta3';
19+
import * as v2 from './v2/index.js';
20+
import * as v2beta2 from './v2beta2/index.js';
21+
import * as v2beta3 from './v2beta3/index.js';
2222

2323
const CloudTasksClient = v2.CloudTasksClient;
2424
type CloudTasksClient = v2.CloudTasksClient;
2525

2626
export {v2, v2beta2, v2beta3, CloudTasksClient};
2727
export default {v2, v2beta2, v2beta3, CloudTasksClient};
28-
import * as protos from '../protos/protos';
28+
import * as protos from '../../protos/protos.js';
2929
export {protos};

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// ** All changes to this file may be overwritten. **
1818

1919
/* global window */
20-
import type * as gax from 'google-gax';
20+
import * as gax from 'google-gax';
2121
import type {
2222
Callback,
2323
CallOptions,
@@ -29,15 +29,35 @@ import type {
2929
LocationProtos,
3030
} from 'google-gax';
3131
import {Transform} from 'stream';
32-
import * as protos from '../../protos/protos';
33-
import jsonProtos = require('../../protos/protos.json');
32+
// @ts-ignore
33+
import type * as protos from '../../../protos/protos.js';
34+
import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
35+
import fs from 'fs';
36+
import path from 'path';
37+
import {fileURLToPath} from 'url';
38+
// @ts-ignore
39+
const dirname = path.dirname(fileURLToPath(import.meta.url));
40+
3441
/**
3542
* Client JSON configuration object, loaded from
3643
* `src/v2/cloud_tasks_client_config.json`.
3744
* This file defines retry strategy and timeouts for all API methods in this library.
3845
*/
39-
import * as gapicConfig from './cloud_tasks_client_config.json';
40-
const version = require('../../../package.json').version;
46+
const gapicConfig = JSON.parse(
47+
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
48+
);
49+
const jsonProtos = JSON.parse(
50+
fs.readFileSync(
51+
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
52+
'utf8'
53+
)
54+
);
55+
const version = JSON.parse(
56+
fs.readFileSync(
57+
path.join(dirname, '..', '..', '..', '..', 'package.json'),
58+
'utf8'
59+
)
60+
).version;
4161

4262
/**
4363
* Cloud Tasks allows developers to manage the execution of background
@@ -94,15 +114,16 @@ export class CloudTasksClient {
94114
* API remote host.
95115
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
96116
* Follows the structure of {@link gapicConfig}.
97-
* @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
117+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
118+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
98119
* For more information, please check the
99120
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
100121
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
101122
* need to avoid loading the default gRPC version and want to use the fallback
102123
* HTTP implementation. Load only fallback version and pass it to the constructor:
103124
* ```
104125
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
105-
* const client = new CloudTasksClient({fallback: true}, gax);
126+
* const client = new CloudTasksClient({fallback: 'rest'}, gax);
106127
* ```
107128
*/
108129
constructor(
@@ -133,7 +154,7 @@ export class CloudTasksClient {
133154

134155
// Load google-gax module synchronously if needed
135156
if (!gaxInstance) {
136-
gaxInstance = require('google-gax') as typeof gax;
157+
gaxInstance = gax as typeof gax;
137158
}
138159

139160
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
@@ -172,14 +193,24 @@ export class CloudTasksClient {
172193
}
173194
if (!opts.fallback) {
174195
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
175-
} else {
196+
} else if (opts.fallback === 'rest') {
176197
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
177198
}
178199
if (opts.libName && opts.libVersion) {
179200
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
180201
}
202+
// Add ESM headers
203+
const isEsm = true;
204+
if (opts.libVersion && isEsm) {
205+
clientHeader.push(`${opts.libVersion}-esm`);
206+
} else if (opts.libVersion && !isEsm) {
207+
clientHeader.push(`${opts.libVersion}-cjs`);
208+
}
209+
181210
// Load the applicable protos.
182-
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
211+
this._protos = this._gaxGrpc.loadProtoJSON(
212+
jsonProtos as gax.protobuf.INamespace
213+
);
183214

184215
// This API contains "path templates"; forward-slash-separated
185216
// identifiers to uniquely identify resources within the API.

packages/google-cloud-tasks/src/v2/cloud_tasks_client_config.json renamed to packages/google-cloud-tasks/esm/src/v2/cloud_tasks_client_config.json

File renamed without changes.

0 commit comments

Comments
 (0)