-
Notifications
You must be signed in to change notification settings - Fork 591
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-crt): remove dynamic imports (!)
- Loading branch information
Showing
7 changed files
with
66 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const pkg = path.join(__dirname, ".."); | ||
|
||
function rm(file) { | ||
if (fs.existsSync(file)) { | ||
fs.rmSync(file); | ||
} | ||
} | ||
|
||
if (fs.existsSync(path.join(pkg, "dist-es", "is-crt-available.esm.js"))) { | ||
rm(path.join(pkg, "dist-es", "is-crt-available.js")); | ||
fs.renameSync(path.join(pkg, "dist-es", "is-crt-available.esm.js"), path.join(pkg, "dist-es", "is-crt-available.js")); | ||
} |
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,9 @@ | ||
/** | ||
* @internal | ||
* | ||
* If \@aws-sdk/signature-v4-crt is installed and loaded, it will register | ||
* this value to true. | ||
*/ | ||
export const crtAvailability = { | ||
isCrtAvailable: false, | ||
}; |
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,30 @@ | ||
import { UserAgentPair } from "@smithy/types"; | ||
|
||
let isAvailable = false; | ||
|
||
import("aws-crt") | ||
.then((result) => (isAvailable = !!result)) | ||
.catch(() => { | ||
isAvailable = false; | ||
}); | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const isCrtAvailable = (): UserAgentPair | null => { | ||
try { | ||
// Attempt to load ambient package aws-crt to verify if it exists. | ||
// We cannot use dynamic import(https://github.com/tc39/proposal-dynamic-import) here because bundlers | ||
// (WebPack, Rollup) will try to bundle this optional dependency and fail to build if not exist. | ||
// Thus this user agent key will only available in Node.js runtime. | ||
if (isAvailable) { | ||
// Validate `module` to make sure this is not in a `require.js` scope. | ||
// TODO: load package version. | ||
return ["md/crt-avail"]; | ||
} | ||
return null; | ||
} catch (e) { | ||
// No aws-crt package available in the runtime. | ||
return null; | ||
} | ||
}; |
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