Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: publish gax-nodejs in dual format (CJS and ESM) #1679

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d65013f
working compilation
sofisl Nov 21, 2024
287271b
save for now
sofisl Dec 3, 2024
24b6195
save for now
sofisl Dec 5, 2024
3566f28
go back to no esm
sofisl Dec 5, 2024
955896c
check what is going on
sofisl Dec 5, 2024
237abba
try pushing tests up
sofisl Dec 5, 2024
8e57aea
Merge branch 'main' into migrateToEsm
sofisl Dec 5, 2024
a17f484
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 5, 2024
e702960
Merge branch 'migrateToEsm' of https://github.com/googleapis/gax-node…
gcf-owl-bot[bot] Dec 5, 2024
57acad4
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 5, 2024
53d9f3f
Merge branch 'migrateToEsm' of https://github.com/googleapis/gax-node…
gcf-owl-bot[bot] Dec 5, 2024
882a1d9
run 18+ tests
sofisl Dec 6, 2024
1a66338
Merge branch 'migrateToEsm' of github.com:googleapis/gax-nodejs into …
sofisl Dec 6, 2024
1656a87
fix broken error
sofisl Dec 6, 2024
7f68430
rerun lint and fix test in tools
sofisl Dec 6, 2024
200d304
skip test
sofisl Dec 6, 2024
9a34cbd
fix broken linter
sofisl Dec 6, 2024
d27baf9
chore: update post processor
sofisl Dec 6, 2024
c8d0d22
migrate to node 18
sofisl Dec 6, 2024
10837c3
restart tests
sofisl Dec 6, 2024
28ae15b
retry
sofisl Dec 6, 2024
82f62bd
rerun lint
sofisl Dec 6, 2024
82ed56e
fix missing types
sofisl Dec 6, 2024
520e4d8
Update package.json
sofisl Dec 6, 2024
32fd81e
fix system tests
sofisl Dec 6, 2024
2a0dd66
Merge branch 'migrateToEsm' of github.com:googleapis/gax-nodejs into …
sofisl Dec 6, 2024
0f0c1b6
retry
sofisl Dec 6, 2024
be673ee
retry
sofisl Dec 6, 2024
c298e08
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 6, 2024
1aede4a
reruntests
sofisl Dec 7, 2024
4c93886
Merge branch 'migrateToEsm' of github.com:googleapis/gax-nodejs into …
sofisl Dec 7, 2024
f1be309
chore: also export protobuf.js as esm
sofisl Dec 9, 2024
ed5055a
run lint and fix test
sofisl Dec 9, 2024
5c212dc
retry system tests
sofisl Dec 9, 2024
97ab9b9
fix path to test-application
sofisl Dec 9, 2024
901b20f
retry system test
sofisl Dec 10, 2024
fd44396
see difference in browser-test
sofisl Dec 10, 2024
7df63e0
rename assert assertion
sofisl Dec 10, 2024
a98c2d5
fix system test
sofisl Dec 10, 2024
6f306ec
clean up RP
sofisl Dec 10, 2024
14ca692
chore: clean tests
sofisl Dec 10, 2024
98d9366
fix broken test and rerun lint
sofisl Dec 10, 2024
76f5565
fix browser test
sofisl Dec 10, 2024
048e05b
clean up extensions and use node-fetch
sofisl Dec 11, 2024
ccf8a34
run lint
sofisl Dec 11, 2024
896679f
fix node-fetch
sofisl Dec 11, 2024
f4926a7
retry dynamically importing node-fetch
sofisl Dec 11, 2024
2d5e67f
chore: update how we import node-fetch
sofisl Dec 11, 2024
2a2bce1
fix babel to compile dynamic imports correctly
sofisl Dec 11, 2024
00e2472
run lint
sofisl Dec 11, 2024
f07c571
fix path of importing node-fetch dynamically
sofisl Dec 11, 2024
a1b539e
retry using dynamic import
sofisl Dec 12, 2024
fdb98ae
try importing default version of node-fetch
sofisl Dec 12, 2024
f78fcd9
attempt to get browser tests to work with separate browser entrypoint…
sofisl Dec 12, 2024
dc5c20d
get system tests to work
sofisl Dec 12, 2024
7d4f877
add node 22 tests
sofisl Dec 12, 2024
8ebae3c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 12, 2024
7c9dbe7
chore: remove `allowSyntheticDefaultImports`
d-goog Dec 13, 2024
a8bca8a
fix: protobuf.js types
d-goog Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gax/.babelrc
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"
]
}
3 changes: 3 additions & 0 deletions gax/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build/
docs/
protos/
samples/generated/
**/*.d.ts
*.d.ts
**/**.d.ts
3 changes: 3 additions & 0 deletions gax/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ dist/
*.tgz
**/*.tgz
test/showcase-echo-client/protos/protos.*
**/*.d.ts
*.d.ts
**/**.d.ts
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions gax/add-cjs-extension.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@sofisl sofisl Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for changing the extension in proxyquire calls, so it wouldn't be affected by a package.json, although I see your larger point that we wouldn't even have to do that if we didn't rename the files at all. It seems slightly cleaner/safer to me to have the .cjs and .js distinguishing the files, easier to see at a glance what's going on, but that's just my perspective!

const path = require('path');

function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);

arrayOfFiles = arrayOfFiles || [];

files.forEach(file => {
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, file));
}
});

return arrayOfFiles;
}

function getAllFullFilePaths(dirname, filenames) {
// const files = fs.readdirSync(dirPath);

const arrayOfFiles = [];

filenames.forEach(file => {
arrayOfFiles.push(path.join(dirname, file));
});

return arrayOfFiles;
}

function main(directoryOrFilenames) {
let fileNames;
if (
fs.statSync(path.join(__dirname, directoryOrFilenames[0])).isDirectory()
) {
fileNames = getAllFiles(directoryOrFilenames[0]);
} else {
fileNames = getAllFullFilePaths(__dirname, directoryOrFilenames);
}
for (const file of fileNames) {
let contents = fs.readFileSync(file, 'utf8');
if (contents.includes('proxyquire')) {
contents = contents.replace(/\.js'/g, ".cjs'");
fs.writeFileSync(file, contents);
}
}
}

main(process.argv.slice(2));
14 changes: 7 additions & 7 deletions gax/src/apiCaller.ts → gax/esm/src/apiCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
GRPCCall,
ResultTuple,
SimpleCallbackFunction,
} from './apitypes';
import {CancellablePromise, OngoingCall, OngoingCallPromise} from './call';
import {Descriptor} from './descriptor';
import {CallSettings} from './gax';
import {GoogleError} from './googleError';
import {NormalApiCaller} from './normalCalls/normalApiCaller';
import {StreamProxy} from './streamingCalls/streaming';
} from './apitypes.js';
import {CancellablePromise, OngoingCall, OngoingCallPromise} from './call.js';
import {Descriptor} from './descriptor.js';
import {CallSettings} from './gax.js';
import {GoogleError} from './googleError.js';
import {NormalApiCaller} from './normalCalls/normalApiCaller.js';
import {StreamProxy} from './streamingCalls/streaming.js';

/**
* An interface for all kinds of API callers (normal, that just calls API, and
Expand Down
8 changes: 4 additions & 4 deletions gax/src/apitypes.ts → gax/esm/src/apitypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import {Duplex} from 'stream';

import {CancellablePromise} from './call';
import {CallOptions} from './gax';
import {GoogleError} from './googleError';
import {Operation} from './longRunningCalls/longrunning';
import {CancellablePromise} from './call.js';
import {CallOptions} from './gax.js';
import {GoogleError} from './googleError.js';
import {Operation} from './longRunningCalls/longrunning.js';

// gRPC functions return object with `.cancel()` method that can be used for
// canceling the ongoing call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import {APICaller} from '../apiCaller';
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes';
import {OngoingCall, OngoingCallPromise} from '../call';
import {CallSettings} from '../gax';
import {GoogleError} from '../googleError';
import {APICaller} from '../apiCaller.js';
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes.js';
import {OngoingCall, OngoingCallPromise} from '../call.js';
import {CallSettings} from '../gax.js';
import {GoogleError} from '../googleError.js';

import {BundleExecutor} from './bundleExecutor';
import {TaskCallback} from './task';
import {BundleExecutor} from './bundleExecutor.js';
import {TaskCallback} from './task.js';

/**
* An implementation of APICaller for bundled calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import {Descriptor} from '../descriptor';
import {CallSettings} from '../gax';
import {NormalApiCaller} from '../normalCalls/normalApiCaller';
import {Descriptor} from '../descriptor.js';
import {CallSettings} from '../gax.js';
import {NormalApiCaller} from '../normalCalls/normalApiCaller.js';

import {BundleApiCaller} from './bundleApiCaller';
import {BundleExecutor} from './bundleExecutor';
import {toCamelCase as snakeToCamelCase} from '../util';
import {BundleApiCaller} from './bundleApiCaller.js';
import {BundleExecutor} from './bundleExecutor.js';
import {toCamelCase as snakeToCamelCase} from '../util.js';

/**
* A descriptor for calls that can be bundled into one call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import {Status} from '../status';
import {Status} from '../status.js';

import {SimpleCallbackFunction} from '../apitypes';
import {GoogleError} from '../googleError';
import {warn} from '../warnings';
import {SimpleCallbackFunction} from '../apitypes.js';
import {GoogleError} from '../googleError.js';
import {warn} from '../warnings.js';

import {BundleDescriptor} from './bundleDescriptor';
import {computeBundleId} from './bundlingUtils';
import {Task, TaskCallback} from './task';
import {BundleDescriptor} from './bundleDescriptor.js';
import {computeBundleId} from './bundlingUtils.js';
import {Task, TaskCallback} from './task.js';

function noop() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Provides behavior that supports request bundling.
*/

import {RequestType} from '../apitypes';
import {RequestType} from '../apitypes.js';

/**
* Compute the identifier of the `obj`. The objects of the same ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
* limitations under the License.
*/

import {Status} from '../status';
import {Status} from '../status.js';

import {APICallback, GRPCCallResult, SimpleCallbackFunction} from '../apitypes';
import {GoogleError} from '../googleError';
import {
APICallback,
GRPCCallResult,
SimpleCallbackFunction,
} from '../apitypes.js';
import {GoogleError} from '../googleError.js';

export interface SubResponseInfo {
field: string;
Expand Down
6 changes: 3 additions & 3 deletions gax/src/call.ts → gax/esm/src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Status} from './status';
import {Status} from './status.js';

import {
APICallback,
Expand All @@ -24,8 +24,8 @@ import {
ResponseType,
ResultTuple,
SimpleCallbackFunction,
} from './apitypes';
import {GoogleError} from './googleError';
} from './apitypes.js';
import {GoogleError} from './googleError.js';

export class OngoingCall {
callback: APICallback;
Expand Down
10 changes: 5 additions & 5 deletions gax/src/clientInterface.ts → gax/esm/src/clientInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import {GrpcClientOptions, ClientStubOptions} from './grpc';
import * as gax from './gax';
import {GrpcClientOptions, ClientStubOptions} from './grpc.js';
import * as gax from './gax.js';
import {GoogleAuthOptions} from 'google-auth-library';
import {
BundleDescriptor,
LongrunningDescriptor,
PageDescriptor,
StreamDescriptor,
} from './descriptor';
import * as longrunning from './longRunningCalls/longrunning';
import * as operationProtos from '../protos/operations';
} from './descriptor.js';
import * as longrunning from './longRunningCalls/longrunning.js';
import * as operationProtos from '../../protos/operations.js';

export interface ClientOptions
extends GrpcClientOptions,
Expand Down
16 changes: 8 additions & 8 deletions gax/src/createApiCall.ts → gax/esm/src/createApiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
* Provides function wrappers that implement page streaming and retrying.
*/

import {createAPICaller} from './apiCaller';
import {createAPICaller} from './apiCaller.js';
import {
APICallback,
GaxCall,
GRPCCall,
GRPCCallOtherArgs,
RequestType,
SimpleCallbackFunction,
} from './apitypes';
import {Descriptor} from './descriptor';
import {CallOptions, CallSettings, convertRetryOptions} from './gax';
import {retryable} from './normalCalls/retries';
import {addTimeoutArg} from './normalCalls/timeout';
import {StreamingApiCaller} from './streamingCalls/streamingApiCaller';
import {warn} from './warnings';
} from './apitypes.js';
import {Descriptor} from './descriptor.js';
import {CallOptions, CallSettings, convertRetryOptions} from './gax.js';
import retryable from './normalCalls/retries.js';
import {addTimeoutArg} from './normalCalls/timeout.js';
import {StreamingApiCaller} from './streamingCalls/streamingApiCaller.js';
import {warn} from './warnings.js';

/**
* Converts an rpc call into an API call governed by the settings.
Expand Down
12 changes: 6 additions & 6 deletions gax/src/descriptor.ts → gax/esm/src/descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// can create its own apiCaller that will handle all the specifics for the given
// call type.

import {APICaller} from './apiCaller';
import {CallSettings} from './gax';
import {APICaller} from './apiCaller.js';
import {CallSettings} from './gax.js';

export interface Descriptor {
getApiCaller(settings: CallSettings): APICaller;
}

export {LongRunningDescriptor as LongrunningDescriptor} from './longRunningCalls/longRunningDescriptor';
export {PageDescriptor} from './paginationCalls/pageDescriptor';
export {StreamDescriptor} from './streamingCalls/streamDescriptor';
export {BundleDescriptor} from './bundlingCalls/bundleDescriptor';
export {LongRunningDescriptor as LongrunningDescriptor} from './longRunningCalls/longRunningDescriptor.js';
export {PageDescriptor} from './paginationCalls/pageDescriptor.js';
export {StreamDescriptor} from './streamingCalls/streamDescriptor.js';
export {BundleDescriptor} from './bundlingCalls/bundleDescriptor.js';
Loading
Loading