Skip to content

Commit

Permalink
fix: Update tsc to 2.x (#735)
Browse files Browse the repository at this point in the history
Update to latest version of tslib
  • Loading branch information
seebees authored Sep 19, 2023
1 parent 00fb851 commit 782e0de
Show file tree
Hide file tree
Showing 17 changed files with 2,289 additions and 1,524 deletions.
3,609 changes: 2,242 additions & 1,367 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"nyc": "^15.1.0",
"prettier": "^2.1.0",
"rimraf": "^3.0.2",
"sinon": "^15.0.1",
"sinon": "^16.0.0",
"tmp": "^0.2.1",
"ts-node": "^10.9.1",
"tslib": "^1.13.0",
"tslib": "^2.6.2",
"typescript": "^4.1.3",
"verdaccio": "^5.13.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@aws-crypto/util": "file:../util",
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32c/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@aws-crypto/util": "file:../util",
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/random-source-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@aws-crypto/supports-web-crypto": "file:../supports-web-crypto",
"@aws-sdk/util-locate-window": "^3.0.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"main": "./build/index.js",
"types": "./build/index.d.ts"
Expand Down
32 changes: 14 additions & 18 deletions packages/random-source-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ import {
} from "@aws-crypto/supports-web-crypto";
import { locateWindow } from "@aws-sdk/util-locate-window";

export function randomValues(byteLength: number): Promise<Uint8Array> {
// Find the global scope for this runtime
const globalScope = locateWindow();

if (supportsWebCrypto(globalScope)) {
return webCryptoRandomValues(byteLength);
export function testableRandomValues(
supports: typeof supportsWebCrypto
) {
return function randomValues(byteLength: number): Promise<Uint8Array> {
// Find the global scope for this runtime
const globalScope = locateWindow();

if (supports(globalScope)) {
return webCryptoRandomValues(byteLength);
}

return Promise.reject(new Error(`Unable to locate a secure random source.`));
}

return Promise.reject(new Error(`Unable to locate a secure random source.`));
}

export function randomValuesOnly(byteLength: number): Promise<Uint8Array> {
// Find the global scope for this runtime
const globalScope = locateWindow();

if (supportsSecureRandom(globalScope)) {
return webCryptoRandomValues(byteLength);
}

return Promise.reject(new Error(`Unable to locate a secure random source.`));
}
export const randomValues = testableRandomValues(supportsWebCrypto);
export const randomValuesOnly = testableRandomValues(supportsSecureRandom);
36 changes: 20 additions & 16 deletions packages/random-source-browser/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { expect } from "chai";
import "mocha";
import { randomValues } from "../src/";
import { testableRandomValues } from "../src/";
import * as sinon from "sinon";

import * as webCrypto from "@aws-crypto/supports-web-crypto";
import * as webCryptoRandom from "../src/webCryptoRandomValues";
declare var global: any;

describe("implementation selection", () => {
beforeEach(() => {
sinon.stub(webCryptoRandom, "randomValues");
sinon.stub(webCrypto, "supportsWebCrypto");
beforeEach(() => {
sinon.stub(webCryptoRandom, "randomValues");
});

afterEach(() => {
(<sinon.SinonStub>webCryptoRandom.randomValues).restore();
// @ts-ignore
(<sinon.SinonStub>webCrypto.supportsWebCrypto).restore();
});

it("should use WebCrypto when available", async () => {
(<sinon.SinonStub>webCrypto.supportsWebCrypto).returns(true);
const supports = sinon.stub()
supports.returns(true)

await randomValues(1);
await testableRandomValues(supports)(1);

sinon.assert.calledOnce(<sinon.SinonStub>webCryptoRandom.randomValues);
});

it("should throw if WebCrypto is not available", async () => {
const doesNotSupport = sinon.stub()
doesNotSupport.returns(false)

try {
await randomValues(1);
await testableRandomValues(doesNotSupport)(1);
} catch (ex) {
expect(ex).to.be.instanceof(Error);
}
Expand All @@ -41,12 +41,10 @@ describe("implementation selection", () => {
describe("global detection", () => {
beforeEach(() => {
sinon.stub(webCryptoRandom, "randomValues");
sinon.stub(webCrypto, "supportsWebCrypto");
});

afterEach(() => {
(<sinon.SinonStub>webCryptoRandom.randomValues).restore();
(<sinon.SinonStub>webCrypto.supportsWebCrypto).restore();
});

const _window = (global as any).window || {};
Expand All @@ -63,8 +61,11 @@ describe("global detection", () => {
});

it("should throw if neither window nor self is defined", async () => {
const doesNotSupport = sinon.stub()
doesNotSupport.returns(false)

try {
await randomValues(1);
await testableRandomValues(doesNotSupport)(1);
} catch (ex) {
expect(ex).to.be.instanceof(Error);
sinon.assert.notCalled(<sinon.SinonStub>webCryptoRandom.randomValues);
Expand All @@ -76,13 +77,16 @@ describe("global detection", () => {
it("should use `self` if window is not defined", async () => {
(global as any).self = _self;

const supports = sinon.stub()
supports.returns(true)

try {
await randomValues(1);
await testableRandomValues(supports)(1);
} catch {}

sinon.assert.calledOnce(<sinon.SinonStub>webCrypto.supportsWebCrypto);
sinon.assert.calledOnce(<sinon.SinonStub>supports);
expect(
(<sinon.SinonStub>webCrypto.supportsWebCrypto).firstCall.args[0]
(<sinon.SinonStub>supports).firstCall.args[0]
).to.eql(_self);
});
});
2 changes: 1 addition & 1 deletion packages/random-source-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"types": "./build/index.d.ts",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/random-source-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@aws-crypto/random-source-browser": "file:../random-source-browser",
"@aws-crypto/random-source-node": "file:../random-source-node",
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"browser": {
"@aws/crypto-random-source-node": false
Expand Down
2 changes: 1 addition & 1 deletion packages/sha1-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-locate-window": "^3.0.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
55 changes: 0 additions & 55 deletions packages/sha1-browser/test/crossPlatformSha1.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sha256-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-locate-window": "^3.0.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"main": "./build/index.js",
"types": "./build/index.d.ts"
Expand Down
55 changes: 0 additions & 55 deletions packages/sha256-browser/test/crossPlatformSha256.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sha256-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@aws-crypto/util": "file:../util",
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/sha256-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@aws-crypto/sha256-browser": "file:../sha256-browser",
"@aws-sdk/hash-node": "^3.110.0",
"@aws-sdk/types": "^3.222.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/supports-web-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"main": "./build/index.js",
"types": "./build/index.d.ts",
"dependencies": {
"tslib": "^1.11.1"
"tslib": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@aws-sdk/types": "^3.222.0",
"@smithy/util-utf8": "^2.0.0",
"tslib": "^1.11.1"
"tslib": "^2.6.2"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 782e0de

Please sign in to comment.