Skip to content

Commit a32684c

Browse files
Setup CircleCI/Lerna/npm to compile and publish @apollo/query-planner-wasm (#181)
* Setup CircleCI/Lerna/npm to compile and publish `@apollo/query-planner-wasm` This allows us to compile and depend upon the local version of the WASM query planner package and get the tarballs that are packed with the right version. Additionally, this allows Lerna to handle the version bumping and publishing for `@apollo/query-planner-wasm`, since it is uniquely positioned to do that best in a monorepo orchestration that involves multiple npm packages with relative `file:` dependencies on each other and coupled with our existing needs for Lerna and publishing workflows we have built. Technically speaking, this relieves the `Cargo.toml` from its responsibility of managing the `version` and shifts that responsibility to `lerna` and other npm-specific tooling we have connected to that. In fact, this change completely eliminates the need for the `wasm-pack` generated `package.json` that is derived from the Cargo.toml (and rendered into the "out-dir", previously `pkg/`). While I would believe that there are some advanced `wasm-pack` cases where this above change might be undesirable, for now, the constraint incurred by that transposition is unblocking in other ways. For example, rather than necessitating parallel metadata support in the `Cargo.toml` for every `package.json` property (think about npm specific properties like "labels", "bugs", "private"), we can simply change our `package.json` as we see fit. I am claiming that this side-stepping of version control defined within `Cargo.toml` is acceptable since we do not have any intention of publishing the `query-planner-wasm` package to crates.io on its own. Instead, we will continue to publish the `wasm-pack`'d-from-this-crate `@apollo/query-planner-wasm` package directly to npm's registry. To reflect that desire, I've marked the `query-planner-wasm` package as "private" using the `private = true` property in its `Cargo.toml`. In theory, this change could de-stabilize the work that `wasm-pack` does and that's worth calling out. For example, by not allowing it to generate the `files` property (which indicates which artifacts are emitted into the `npm pack`'d bundle), we might be not allowing it to add other (Future? Unexpected?) important emitted files. I've instead put those `files` directly into the new `package.json` source of truth, along with other appropriate properties, like `types` and `main`. The largest risk here - based on our intended use of the package - seems to be relevant only if we were to rename the host Crate. To demitigate that risk, I've explicitly wired up the `package.json` with `--out-dir` and `--out-file` flags to ensure that it always emits `index`-prefixed files. Furthermore, they are now emitted into the `dist` directory, to be parallel with all our other npm package patterns which do the same. I will note that, `wasm-pack` may address some of the work-arounds here in the future, but best I can tell, they will be roughly compatible with what we're doing here. I am basing this outstanding issues, PRs, RFCs and documentation on the `wasm-pack` project, referenced below. Ref: https://rustwasm.github.io/rfcs/008-npm-dependencies.html#unresolved-questions (See last section) Ref: https://rustwasm.github.io/docs/wasm-pack/commands/build.html#extra-options (See footnote) Ref: rustwasm/wasm-pack#606 Ref: rustwasm/wasm-pack#840 * Update query-planner-wasm/package.json Co-authored-by: Trevor Scheer <[email protected]> Co-authored-by: Trevor Scheer <[email protected]>
1 parent 6b65b6a commit a32684c

File tree

8 files changed

+67
-9
lines changed

8 files changed

+67
-9
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ commands:
1616
common_test_steps:
1717
description: "Commands to run on every Node.js environment"
1818
steps:
19+
- run:
20+
# rustup must be installed prior to installing `wasm-pack`.
21+
# If rustup isn't already in our environment, install it.
22+
# On the `circleci/rust:*-node` images, it's already installed, so
23+
# it's marginally faster to skip this when not necessary.
24+
name: Ensure / Install rustup
25+
command: |
26+
which rustup > /dev/null 2>&1 ||
27+
(
28+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
29+
bash -s -- -y &&
30+
echo 'source $HOME/.cargo/env' >> $BASH_ENV
31+
# This last line here is for subsequent "run" steps.
32+
)
33+
- run:
34+
name: Install wasm-pack
35+
command: |
36+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf |
37+
sh
1938
- oss/install_specific_npm_version
2039
- checkout
2140
- oss/npm_clean_install_with_caching

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gateway-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@apollo/federation": "file:../federation-js",
29-
"@apollo/query-planner-wasm": "0.0.4",
29+
"@apollo/query-planner-wasm": "file:../query-planner-wasm",
3030
"@types/node-fetch": "2.5.4",
3131
"apollo-engine-reporting-protobuf": "^0.5.2",
3232
"apollo-graphql": "^0.6.0",

lerna.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"packages": ["federation-js", "federation-integration-testsuite-js", "gateway-js"],
2+
"packages": [
3+
"federation-js",
4+
"federation-integration-testsuite-js",
5+
"gateway-js",
6+
"query-planner-wasm"
7+
],
38
"version": "independent",
49
"command": {
510
"version": {

package-lock.json

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"repository": "github:apollographql/federation",
66
"scripts": {
7-
"clean": "git clean -dfqX -- ./node_modules **/{dist,node_modules}/ ./*/tsconfig*tsbuildinfo",
7+
"clean": "git clean -dfqX -- ./target ./node_modules **/{dist,node_modules}/ ./*/tsconfig*tsbuildinfo",
88
"compile": "tsc --build tsconfig.build.json",
99
"compile:clean": "tsc --build tsconfig.build.json --clean",
1010
"watch": "tsc --build tsconfig.build.json --watch",
@@ -26,6 +26,7 @@
2626
"@apollographql/apollo-tools": "0.4.8",
2727
"@apollo/federation": "file:federation-js",
2828
"@apollo/gateway": "file:gateway-js",
29+
"@apollo/query-planner-wasm": "file:query-planner-wasm",
2930
"apollo-federation-integration-testsuite": "file:federation-integration-testsuite-js"
3031
},
3132
"devDependencies": {

query-planner-wasm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "query-planner-wasm" # this ends up being the name in the published npm package.
3-
version = "0.0.4"
3+
version = "0.0.0-DO.NOT.CHANGE" # The version is managed in the package.json, by Lerna.
4+
private = true
45
authors = ["Apollo <[email protected]>"]
56
homepage = "https://github.com/apollographql/federation"
67
description = "Bridge code written in Rust to Javascript/Typescript, to be internally used by Apollo Gateway. This package is not meant to be independently consumed."

query-planner-wasm/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@apollo/query-planner-wasm",
3+
"version": "0.0.4",
4+
"description": "Bridge code written in Rust to Javascript/Typescript, to be internally used by Apollo Gateway. This package is not meant to be independently consumed.",
5+
"scripts": {
6+
"wasm-pack": "wasm-pack build --target nodejs --out-dir dist --out-name index --scope apollo",
7+
"preinstall": "npm run wasm-pack"
8+
},
9+
"author": "[email protected]",
10+
"license": "MIT",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/apollographql/federation.git",
14+
"directory": "query-planner-wasm/"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/apollographql/federation/issues"
18+
},
19+
"homepage": "https://github.com/apollographql/federation#readme",
20+
"keywords": [
21+
"GraphQL",
22+
"rust",
23+
"wasm",
24+
"apollo"
25+
],
26+
"files": [
27+
"dist/index_bg.wasm",
28+
"dist/index.js",
29+
"dist/index_bg.js",
30+
"dist/index.d.ts"
31+
],
32+
"main": "dist/index.js",
33+
"types": "dist/index.d.ts"
34+
}

0 commit comments

Comments
 (0)