Skip to content

Commit

Permalink
Add environment-aware createHash function to apollo-env (#1110)
Browse files Browse the repository at this point in the history
Add environment awareness in order to use crypto/sha.js when appropriate
  • Loading branch information
trevor-scheer authored Mar 13, 2019
1 parent 0cec057 commit 190fabd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- apollo
- JSON flag for service:check output [#1079](https://github.com/apollographql/apollo-tooling/pull/1079)
- apollo-env
- Add environment-aware createHash function to apollo-env [#1110](https://github.com/apollographql/apollo-tooling/pull/1110)

## `apollo@2.6.0`, `apollo-env@0.3.4`, `apollo-language-server@1.5.3`, `apollo-codegen-flow@0.32.9`, `apollo-codegen-scala@0.33.5`, `apollo-codegen-swift@0.32.9`, `apollo-codegen-typescript@0.32.10`, `apollo-graphql@0.1.2`

Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/apollo-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"core-js": "3.0.0-beta.13",
"node-fetch": "^2.2.0"
"node-fetch": "^2.2.0",
"sha.js": "^2.4.11"
}
}
1 change: 1 addition & 0 deletions packages/apollo-env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import "./polyfills";

export * from "./typescript-utility-types";
export * from "../lib/fetch";
export * from "./utils";
10 changes: 10 additions & 0 deletions packages/apollo-env/src/utils/createHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { isNodeLike } from "./isNodeLike";

export function createHash(kind: string): import("crypto").Hash {
if (isNodeLike) {
// 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);
}
2 changes: 2 additions & 0 deletions packages/apollo-env/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./createHash";
export * from "./isNodeLike";
6 changes: 6 additions & 0 deletions packages/apollo-env/src/utils/isNodeLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isNodeLike =
typeof process === "object" &&
process &&
process.release &&
process.versions &&
typeof process.versions.node === "string";
1 change: 1 addition & 0 deletions packages/apollo-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"node": ">=6"
},
"dependencies": {
"apollo-env": "file:../apollo-env",
"lodash.sortby": "^4.7.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-graphql/src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// the server no longer needs to parse the signature or run its own signature
// algorithm on it, and the details of the signature algorithm are now up to the
// reporting agent.

import { DocumentNode } from "graphql";
import { createHash } from "apollo-env";
import {
printWithReducedWhitespace,
dropUnusedDefinitions,
Expand Down

0 comments on commit 190fabd

Please sign in to comment.