-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add environment awareness in order to use crypto/sha.js when appropriate
- Loading branch information
1 parent
b947a84
commit bfeb541
Showing
8 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ import "./polyfills"; | |
import "./typescript-utility-types"; | ||
|
||
export * from "../lib/fetch"; | ||
export * from "./utils"; |
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,10 @@ | ||
import { isNode } from "./isNode"; | ||
|
||
export function createHash(kind: string): import("crypto").Hash { | ||
if (isNode) { | ||
// Use module.require instead of just require to avoid bundling whatever | ||
// crypto polyfills a non-Node bundler might fall back to. | ||
return module.require("crypto").createHash(kind); | ||
} | ||
return require("sha.js")(kind); | ||
} |
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,2 @@ | ||
export * from "./createHash"; | ||
export * from "./isNode"; |
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,7 @@ | ||
export const isNode = | ||
typeof process === "object" && | ||
process && | ||
process.release && | ||
process.release.name === "node" && | ||
This comment has been minimized.
Sorry, something went wrong. |
||
process.versions && | ||
typeof process.versions.node === "string"; |
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
@trevor-scheer I learned in apollographql/apollo-server#2357 that we should drop this line. (Also, this should be shared logic, but don't let that distract you right now.)