Skip to content

Commit

Permalink
feat: [tasks] publish cloud tasks in esm and cjs (#4720)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Nov 17, 2023
1 parent fe7dc9e commit 6773a05
Show file tree
Hide file tree
Showing 40 changed files with 106,555 additions and 49,837 deletions.
2 changes: 1 addition & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs-mono-repo:latest
digest: sha256:353f74808df01ad8a4af996cac8acffcd9c087590743340bda440874cf55d566
digest: sha256:2bd6069d367ef0365b62f767340e701c9ffc542c8a771bb5acc25372b43e2e15
19 changes: 19 additions & 0 deletions packages/google-cloud-tasks/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
"@babel/preset-typescript",
"@babel/env"
],
"plugins": [
[
"replace-import-extension",
{
"extMapping": {
".js": ".cjs"
}
}
],
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js",
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js",
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js"
]
}
6 changes: 5 additions & 1 deletion packages/google-cloud-tasks/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ test/fixtures
build/
docs/
protos/
samples/generated/
samples/
esm/src/**/*.d.ts
esm/test/**/*.d.ts
esm/system-test/**/*.d.ts
esm/system-test/fixtures/sample/src/*.ts
1 change: 1 addition & 0 deletions packages/google-cloud-tasks/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ system-test/*key.json
.DS_Store
package-lock.json
__pycache__
esm/**/*.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

module.exports = {
opts: {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
// ** https://github.com/googleapis/synthtool **
// ** All changes to this file may be overwritten. **

import * as v2 from './v2';
import * as v2beta2 from './v2beta2';
import * as v2beta3 from './v2beta3';
import * as v2 from './v2/index.js';
import * as v2beta2 from './v2beta2/index.js';
import * as v2beta3 from './v2beta3/index.js';

const CloudTasksClient = v2.CloudTasksClient;
type CloudTasksClient = v2.CloudTasksClient;

export {v2, v2beta2, v2beta3, CloudTasksClient};
export default {v2, v2beta2, v2beta3, CloudTasksClient};
import * as protos from '../protos/protos';
import * as protos from '../../protos/protos.js';
export {protos};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// ** All changes to this file may be overwritten. **

/* global window */
import type * as gax from 'google-gax';
import * as gax from 'google-gax';
import type {
Callback,
CallOptions,
Expand All @@ -29,15 +29,35 @@ import type {
LocationProtos,
} from 'google-gax';
import {Transform} from 'stream';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
// @ts-ignore
import type * as protos from '../../../protos/protos.js';
import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
// @ts-ignore
const dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* Client JSON configuration object, loaded from
* `src/v2/cloud_tasks_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './cloud_tasks_client_config.json';
const version = require('../../../package.json').version;
const gapicConfig = JSON.parse(
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
);
const jsonProtos = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
'utf8'
)
);
const version = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', '..', 'package.json'),
'utf8'
)
).version;

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

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
gaxInstance = gax as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
Expand Down Expand Up @@ -172,14 +193,24 @@ export class CloudTasksClient {
}
if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
} else {
} else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
}
if (opts.libName && opts.libVersion) {
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
}
// Add ESM headers
const isEsm = true;
if (opts.libVersion && isEsm) {
clientHeader.push(`${opts.libVersion}-esm`);
} else if (opts.libVersion && !isEsm) {
clientHeader.push(`${opts.libVersion}-cjs`);
}

// Load the applicable protos.
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
this._protos = this._gaxGrpc.loadProtoJSON(
jsonProtos as gax.protobuf.INamespace
);

// This API contains "path templates"; forward-slash-separated
// identifiers to uniquely identify resources within the API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

export {CloudTasksClient} from './cloud_tasks_client';
export {CloudTasksClient} from './cloud_tasks_client.js';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// ** All changes to this file may be overwritten. **

/* global window */
import type * as gax from 'google-gax';
import * as gax from 'google-gax';
import type {
Callback,
CallOptions,
Expand All @@ -29,15 +29,35 @@ import type {
LocationProtos,
} from 'google-gax';
import {Transform} from 'stream';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
// @ts-ignore
import type * as protos from '../../../protos/protos.js';
import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
// @ts-ignore
const dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* Client JSON configuration object, loaded from
* `src/v2beta2/cloud_tasks_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './cloud_tasks_client_config.json';
const version = require('../../../package.json').version;
const gapicConfig = JSON.parse(
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
);
const jsonProtos = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
'utf8'
)
);
const version = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', '..', 'package.json'),
'utf8'
)
).version;

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

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
gaxInstance = gax as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
Expand Down Expand Up @@ -172,14 +193,24 @@ export class CloudTasksClient {
}
if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
} else {
} else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
}
if (opts.libName && opts.libVersion) {
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
}
// Add ESM headers
const isEsm = true;
if (opts.libVersion && isEsm) {
clientHeader.push(`${opts.libVersion}-esm`);
} else if (opts.libVersion && !isEsm) {
clientHeader.push(`${opts.libVersion}-cjs`);
}

// Load the applicable protos.
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
this._protos = this._gaxGrpc.loadProtoJSON(
jsonProtos as gax.protobuf.INamespace
);

// This API contains "path templates"; forward-slash-separated
// identifiers to uniquely identify resources within the API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

export {CloudTasksClient} from './cloud_tasks_client';
export {CloudTasksClient} from './cloud_tasks_client.js';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// ** All changes to this file may be overwritten. **

/* global window */
import type * as gax from 'google-gax';
import * as gax from 'google-gax';
import type {
Callback,
CallOptions,
Expand All @@ -29,15 +29,35 @@ import type {
LocationProtos,
} from 'google-gax';
import {Transform} from 'stream';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
// @ts-ignore
import type * as protos from '../../../protos/protos.js';
import * as cloud_tasks_client_config from './cloud_tasks_client_config.json';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
// @ts-ignore
const dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* Client JSON configuration object, loaded from
* `src/v2beta3/cloud_tasks_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './cloud_tasks_client_config.json';
const version = require('../../../package.json').version;
const gapicConfig = JSON.parse(
fs.readFileSync(path.join(dirname, 'cloud_tasks_client_config.json'), 'utf8')
);
const jsonProtos = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', 'protos/protos.json'),
'utf8'
)
);
const version = JSON.parse(
fs.readFileSync(
path.join(dirname, '..', '..', '..', '..', 'package.json'),
'utf8'
)
).version;

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

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
gaxInstance = gax as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
Expand Down Expand Up @@ -172,14 +193,24 @@ export class CloudTasksClient {
}
if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
} else {
} else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
}
if (opts.libName && opts.libVersion) {
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
}
// Add ESM headers
const isEsm = true;
if (opts.libVersion && isEsm) {
clientHeader.push(`${opts.libVersion}-esm`);
} else if (opts.libVersion && !isEsm) {
clientHeader.push(`${opts.libVersion}-cjs`);
}

// Load the applicable protos.
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
this._protos = this._gaxGrpc.loadProtoJSON(
jsonProtos as gax.protobuf.INamespace
);

// This API contains "path templates"; forward-slash-separated
// identifiers to uniquely identify resources within the API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

export {CloudTasksClient} from './cloud_tasks_client';
export {CloudTasksClient} from './cloud_tasks_client.js';
Loading

0 comments on commit 6773a05

Please sign in to comment.