From d9f6a9a1dd6277522df1d205d7db1f99b4c7fd25 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 5 Jul 2020 15:32:56 +0300 Subject: [PATCH] feat(jsii): API compatibility checks by default Adds an option `compat` (defaults to `true`) which automatically verifies API compatibility against the last published npm version. The `compatIgnore` option can control the name of the ignore file. --- API.md | 4 ++++ package.json | 4 ++-- src/jsii-project.ts | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 750a772ac65..8b985174463 100644 --- a/API.md +++ b/API.md @@ -393,6 +393,8 @@ new JsiiProject(options: JsiiProjectOptions) * **repository** (string) *No description* * **authorEmail** (string) *No description* *Optional* * **authorUrl** (string) *No description* *Optional* + * **compat** (boolean) Automatically run API compatibility test against the latest version published to npm after compilation. *Default*: true + * **compatIgnore** (string) Name of the ignore file for API compatibility tests. *Default*: .compatignore * **description** (string) *No description* *Optional* * **docgen** (boolean) Automatically generate API.md from jsii. *Default*: true * **dotnet** ([JsiiDotNetTarget](#projen-jsiidotnettarget)) *No description* *Optional* @@ -1187,6 +1189,8 @@ Name | Type | Description **bin**?🔹 | Map | Binary programs vended with your module.
*Optional* **buildWorkflow**?🔹 | boolean | Define a GitHub workflow for building PRs.
*Default*: true **bundledDependencies**?🔹 | Array | *Optional* +**compat**?🔹 | boolean | Automatically run API compatibility test against the latest version published to npm after compilation.
*Default*: true +**compatIgnore**?🔹 | string | Name of the ignore file for API compatibility tests.
*Default*: .compatignore **dependencies**?🔹 | Map | *Optional* **description**?🔹 | string | *Optional* **devDependencies**?🔹 | Map | *Optional* diff --git a/package.json b/package.json index 62c6efc22c4..6e9bb05b86b 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "test": "yarn eslint && rm -fr lib/ && jest --passWithNoTests", "bump": "standard-version", "release": "yarn bump && git push --follow-tags origin master", - "compile": "jsii --silence-warnings=reserved-word && jsii-docgen", + "compile": "jsii --silence-warnings=reserved-word && jsii-docgen && yarn compat", "watch": "jsii -w --silence-warnings=reserved-word", - "compat": "npx jsii-diff npm:$(node -p \"require('./package.json').name\")", + "compat": "npx jsii-diff npm:$(node -p \"require('./package.json').name\") -k --ignore-file .compatignore || (echo \"\nUNEXPECTED BREAKING CHANGES: add keys such as 'removed:constructs.Node.of' to .compatignore to skip.\n\" && exit 1)", "package": "jsii-pacmak", "build": "yarn test && yarn compile && yarn run package", "eslint": "eslint . --ext .ts", diff --git a/src/jsii-project.ts b/src/jsii-project.ts index aff84097581..c7eceb7992b 100644 --- a/src/jsii-project.ts +++ b/src/jsii-project.ts @@ -88,6 +88,23 @@ export interface JsiiProjectOptions extends CommonOptions { * @default "test" */ readonly testdir?: string; + + /** + * Automatically run API compatibility test against the latest version published to npm after compilation. + * + * - You can manually run compatbility tests using `yarn compat` if this feature is disabled. + * - You can ignore compatibility failures by adding lines to a ".compatignore" file. + * + * @default true + */ + readonly compat?: boolean; + + /** + * Name of the ignore file for API compatibility tests. + * + * @default .compatignore + */ + readonly compatIgnore?: string; } export enum Stability { @@ -143,10 +160,12 @@ export class JsiiProject extends NodeProject { // this is an unhelpful warning const jsiiFlags = '--silence-warnings=reserved-word'; + const compatIgnore = options.compatIgnore ?? '.compatignore'; + this.addScripts({ compile: Lazy.stringValue({ produce: () => this.renderCompileCommand() }), watch: `jsii -w ${jsiiFlags}`, - compat: 'npx jsii-diff npm:$(node -p "require(\'./package.json\').name")', + compat: `npx jsii-diff npm:$(node -p "require(\'./package.json\').name") -k --ignore-file ${compatIgnore} || (echo "\nUNEXPECTED BREAKING CHANGES: add keys such as \'removed:constructs.Node.of\' to ${compatIgnore} to skip.\n" && exit 1)`, package: 'jsii-pacmak', // we runn "test" first because it deletes "lib/" @@ -301,6 +320,11 @@ export class JsiiProject extends NodeProject { }, }); } + + const compat = options.compat ?? true; + if (compat) { + this.addCompileCommand('yarn compat'); + } } /**