Skip to content

Commit

Permalink
Merge branch 'main' into release-3.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Dec 10, 2020
2 parents 4575e9f + dc715e0 commit 564708e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ TBD
### Documentation
TBD

## Apollo Client 3.3.5

### Improvements

- Restore `client.version` property, reflecting the current `@apollo/client` version from `package.json`. <br/>
[@benjamn](https://github.com/benjamn) in [#7448](https://github.com/apollographql/apollo-client/pull/7448)

## Apollo Client 3.3.4

### Improvements
Expand Down
66 changes: 66 additions & 0 deletions config/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const distRoot = path.join(__dirname, "..", "dist");
const versionPath = path.join(distRoot, "version.js");
const pkgJsonPath = path.join(__dirname, "..", "package.json");

const { version } = JSON.parse(fs.readFileSync(pkgJsonPath));
assert.strictEqual(
typeof version, "string",
'"version" field missing from package.json',
);

switch (process.argv[2]) {
case "update": {
const updated = fs
.readFileSync(versionPath, "utf8")
.replace(/\blocal\b/, version);

assert.notEqual(
updated.indexOf(version), -1,
"Failed to update dist/version.js with @apollo/client version",
);

fs.writeFileSync(versionPath, updated);

break;
}

case "verify": {
const {
ApolloClient,
InMemoryCache,
} = require(path.join(distRoot, "core", "core.cjs.js"));

// Though this may seem like overkill, verifying that ApolloClient is
// constructible in Node.js is actually pretty useful, too!
const client = new ApolloClient({
cache: new InMemoryCache,
});

// Probably not necessary, but it seems wise to clean up any resources
// the client might have acquired during its construction.
client.stop();

// The CommonJS dist/core/core.cjs.js file is generated from ESM modules
// generated by tsc, including dist/version.js, so verifying core.cjs.js
// exports an ApolloClient class that defines client.version also serves
// to verify that dist/version.js must have been correctly updated,
// which is convenient because dist/version.js uses ECMAScript module
// syntax, and is thus not importable in all versions of Node.js.
assert.strictEqual(
client.version, version,
"Failed to update dist/version.js and dist/core/core.cjs.js",
);

break;
}

default:
throw new Error(
"Pass either 'update' or 'verify' to config/version.js"
);
}

console.log("ok");

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

6 changes: 3 additions & 3 deletions examples/bundling/tree-shaking/rollup-ac2/package-lock.json

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

6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"scripts": {
"prebuild": "npm run clean",
"build": "tsc",
"postbuild": "npm run invariants && npm run sourcemaps && npm run rollup && npm run prepdist && npm run resolve",
"postbuild": "npm run update-version && npm run invariants && npm run sourcemaps && npm run rollup && npm run prepdist && npm run resolve && npm run verify-version",
"update-version": "node config/version.js update",
"verify-version": "node config/version.js verify",
"invariants": "ts-node-script config/processInvariants.ts",
"sourcemaps": "ts-node-script config/rewriteSourceMaps.ts",
"rollup": "rollup -c ./config/rollup.config.js",
Expand Down

0 comments on commit 564708e

Please sign in to comment.