From b9435bb52608f7f8e28d53938cd00252cbf5dc58 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Wed, 5 Jul 2023 13:52:45 -0700 Subject: [PATCH 1/2] build!: remove arrify and fast-text-encoding --- browser-test/test.crypto.ts | 5 ----- browser-test/test.oauth2.ts | 5 ----- package.json | 2 -- src/auth/computeclient.ts | 6 +++++- src/crypto/browser/crypto.ts | 8 -------- test/test.crypto.ts | 6 ------ 6 files changed, 5 insertions(+), 27 deletions(-) diff --git a/browser-test/test.crypto.ts b/browser-test/test.crypto.ts index 5da17f98..37e2d5f2 100644 --- a/browser-test/test.crypto.ts +++ b/browser-test/test.crypto.ts @@ -19,11 +19,6 @@ import {BrowserCrypto} from '../src/crypto/browser/crypto'; import {privateKey, publicKey} from './fixtures/keys'; import {describe, it} from 'mocha'; -// Not all browsers support `TextEncoder`. The following `require` will -// provide a fast UTF8-only replacement for those browsers that don't support -// text encoding natively. -require('fast-text-encoding'); - describe('Browser crypto tests', () => { const crypto = createCrypto(); diff --git a/browser-test/test.oauth2.ts b/browser-test/test.oauth2.ts index ffcb79c9..5626575d 100644 --- a/browser-test/test.oauth2.ts +++ b/browser-test/test.oauth2.ts @@ -18,11 +18,6 @@ import * as sinon from 'sinon'; import {privateKey, publicKey} from './fixtures/keys'; import {it, describe, beforeEach} from 'mocha'; -// Not all browsers support `TextEncoder`. The following `require` will -// provide a fast UTF8-only replacement for those browsers that don't support -// text encoding natively. -require('fast-text-encoding'); - import {CodeChallengeMethod, OAuth2Client} from '../src'; import {CertificateFormat} from '../src/auth/oauth2client'; import {JwkCertificate} from '../src/crypto/crypto'; diff --git a/package.json b/package.json index 54168490..eb2846bb 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,8 @@ "client library" ], "dependencies": { - "arrify": "^2.0.0", "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", - "fast-text-encoding": "^1.0.0", "gaxios": "^5.0.0", "gcp-metadata": "^5.3.0", "gtoken": "^6.1.0", diff --git a/src/auth/computeclient.ts b/src/auth/computeclient.ts index db91df01..c2956669 100644 --- a/src/auth/computeclient.ts +++ b/src/auth/computeclient.ts @@ -49,7 +49,11 @@ export class Compute extends OAuth2Client { // refreshed before the first API call is made. this.credentials = {expiry_date: 1, refresh_token: 'compute-placeholder'}; this.serviceAccountEmail = options.serviceAccountEmail || 'default'; - this.scopes = arrify(options.scopes); + this.scopes = Array.isArray(options.scopes) + ? options.scopes + : options.scopes + ? [options.scopes] + : []; } /** diff --git a/src/crypto/browser/crypto.ts b/src/crypto/browser/crypto.ts index feba104a..e46096f7 100644 --- a/src/crypto/browser/crypto.ts +++ b/src/crypto/browser/crypto.ts @@ -18,14 +18,6 @@ import * as base64js from 'base64-js'; -// Not all browsers support `TextEncoder`. The following `require` will -// provide a fast UTF8-only replacement for those browsers that don't support -// text encoding natively. -// eslint-disable-next-line node/no-unsupported-features/node-builtins -if (typeof process === 'undefined' && typeof TextEncoder === 'undefined') { - require('fast-text-encoding'); -} - import {Crypto, JwkCertificate, fromArrayBufferToHex} from '../crypto'; export class BrowserCrypto implements Crypto { diff --git a/test/test.crypto.ts b/test/test.crypto.ts index 101d94c8..3488c732 100644 --- a/test/test.crypto.ts +++ b/test/test.crypto.ts @@ -104,12 +104,6 @@ describe('crypto', () => { assert.strictEqual(encodedString, base64String); }); - it('should not load fast-text-encoding while running in nodejs', () => { - const loadedModules = Object.keys(require('module')._cache); - const hits = loadedModules.filter(x => x.includes('fast-text-encoding')); - assert.strictEqual(hits.length, 0); - }); - it('should calculate SHA256 digest in hex encoding', async () => { const input = 'I can calculate SHA256'; const expectedHexDigest = From 44960d29b447c69fea626f5c614abd003e0af92c Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Fri, 7 Jul 2023 11:29:04 -0700 Subject: [PATCH 2/2] Update computeclient.ts --- src/auth/computeclient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/auth/computeclient.ts b/src/auth/computeclient.ts index c2956669..acc7aeb1 100644 --- a/src/auth/computeclient.ts +++ b/src/auth/computeclient.ts @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import arrify = require('arrify'); import {GaxiosError} from 'gaxios'; import * as gcpMetadata from 'gcp-metadata';