-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(signature-v4-multi-region): avoid require call on optional depend…
…ency
- Loading branch information
Showing
9 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
import { signatureV4CrtContainer } from "@aws-sdk/signature-v4-multi-region"; | ||
|
||
import { CrtSignerV4 } from "./CrtSignerV4"; | ||
|
||
signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4; | ||
|
||
export * from "./CrtSignerV4"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
* @internal | ||
*/ | ||
export * from "./SignatureV4MultiRegion"; | ||
export * from "./signature-v4-crt-container"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* @internal | ||
*/ | ||
export function loadCrt(): void {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { signatureV4CrtContainer } from "./signature-v4-crt-container"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function loadCrt(): void { | ||
if (signatureV4CrtContainer.CrtSignerV4) { | ||
return; | ||
} | ||
try { | ||
if (typeof require === "function") { | ||
// add some indirection to avoid static analysis. | ||
const __require = require; | ||
const moduleName = "@aws-sdk/signature-v4-crt"; | ||
__require.call(null, moduleName); | ||
} | ||
} catch (e) { | ||
// ignored. | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/signature-v4-multi-region/src/signature-v4-crt-container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { RequestPresigner, RequestSigner } from "@smithy/types"; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export type OptionalCrtSignerV4 = { | ||
/** | ||
* This constructor is not typed so as not to require a type import | ||
* from the signature-v4-crt package. | ||
* | ||
* The true type is CrtSignerV4 from \@aws-sdk/signature-v4-crt. | ||
*/ | ||
new (options: any): RequestPresigner & RequestSigner; | ||
}; | ||
|
||
/** | ||
* @public | ||
* | ||
* \@aws-sdk/signature-v4-crt will install the constructor in this | ||
* container if it is installed. | ||
* | ||
* This avoids a runtime-require being interpreted statically by bundlers. | ||
* | ||
*/ | ||
export const signatureV4CrtContainer: { | ||
CrtSignerV4: null | OptionalCrtSignerV4; | ||
} = { | ||
CrtSignerV4: null, | ||
}; |