From 28984d1314978da5fdc6dd5553c25582c4fba7b2 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Wed, 6 Jan 2021 13:54:06 -0800 Subject: [PATCH] Allow overriding node version in package.json --- common/config/rush/pnpm-lock.yaml | 11 ++++- .../ts-package-json-engine-is-present.md | 42 +++++++++++++++---- .../eslint-plugin-azure-sdk/package.json | 2 + .../ts-package-json-engine-is-present.ts | 28 +++++++++---- .../src/utils/metadata.ts | 6 ++- .../ts-package-json-engine-is-present.ts | 26 ++++++++++++ .../.eslintrc.json | 8 +++- .../README.md | 2 +- .../package.json | 2 +- 9 files changed, 106 insertions(+), 21 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e177e1606876..67e00376c810 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -4374,6 +4374,10 @@ packages: dev: false resolution: integrity: sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM= + /json-schema/0.3.0: + dev: false + resolution: + integrity: sha512-TYfxx36xfl52Rf1LU9HyWSLGPdYLL+SQ8/E/0yVyKG8wCCDaSrhPap0vEdlsZWRaS6tnKKLPGiEJGiREVC8kxQ== /json-stable-stringify-without-jsonify/1.0.1: dev: false resolution: @@ -9041,6 +9045,7 @@ packages: karma-remap-istanbul: 0.6.0_karma@5.2.3 mocha: 7.2.0 mocha-junit-reporter: 1.23.3_mocha@7.2.0 + nyc: 14.1.1 prettier: 1.19.1 rimraf: 3.0.2 rollup: 1.32.1 @@ -9056,7 +9061,7 @@ packages: dev: false name: '@rush-temp/data-tables' resolution: - integrity: sha512-q7N2kw0AD/INh87gkzzATH88kOQ6/qO78ipb8D0vRin+En7CUV1/fo7jZzl1dM5lGTWeneGYQ7aWOcXrw6pInA== + integrity: sha512-4Rw9bJONHF4b63GMcRXMMedfBfpmEfz/sXPYQrXZJuXm48X+kZp5TVYLxmgjAOUBozyCv7U9cGK2DWPBpesPyA== tarball: 'file:projects/data-tables.tgz' version: 0.0.0 'file:projects/dev-tool.tgz': @@ -9154,6 +9159,7 @@ packages: '@types/eslint': 7.2.6 '@types/estree': 0.0.45 '@types/glob': 7.1.3 + '@types/json-schema': 7.0.6 '@types/mocha': 7.0.2 '@types/node': 8.10.66 '@typescript-eslint/eslint-plugin': 4.10.0_6293af56a321af96e1696de9ab377ba5 @@ -9167,6 +9173,7 @@ packages: eslint-plugin-promise: 4.2.1 eslint-plugin-tsdoc: 0.2.10 glob: 7.1.6 + json-schema: 0.3.0 mocha: 7.2.0 mocha-junit-reporter: 1.23.3_mocha@7.2.0 prettier: 1.19.1 @@ -9178,7 +9185,7 @@ packages: dev: false name: '@rush-temp/eslint-plugin-azure-sdk' resolution: - integrity: sha512-NmCxr5BwG6llNiPN2tnOIOQ3s6yungwTUIrG79tJOKe+Z+FA2BZD933217k6pyyUfkAHB7LFn604ZKjpxRZkgg== + integrity: sha512-Gqr+hJ1efEQ00ZfMuHixctG31SOocfl9ENhDjzlebnDuNhYlcAb95K4XQDzhYU2mv7mv5ESwByaJoBbQM5+jQw== tarball: 'file:projects/eslint-plugin-azure-sdk.tgz' version: 0.0.0 'file:projects/event-hubs.tgz': diff --git a/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-engine-is-present.md b/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-engine-is-present.md index a342ef0800b0..a6225be3db8a 100644 --- a/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-engine-is-present.md +++ b/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-engine-is-present.md @@ -2,7 +2,7 @@ Requires support for all Node LTS version. -Currently, this requires `engine` in `package.json` to be set to `">=8.0.0"`. +Currently, this requires `engines` in `package.json` to contain an entry for `node` set to `">=8.0.0"` unless a `nodeVersionOverride` value is present. This rule is fixable using the `--fix` option. @@ -12,23 +12,33 @@ This rule is fixable using the `--fix` option. ```json { - "engine": ">=8.0.0" + "engines": { + "node": ">=8.0.0" + } } ``` ### Bad -````json +```json { - "engine": ">=6.0.0" + "engine": { + "node": ">=8.0.0" + } } -```' +``` ```json { - "engine": ">=10.0.0" + "engine": ">=6.0.0" } -```` +``` + +```json +{ + "engine": ">=10.0.0" +} +``` ```json {} @@ -38,6 +48,24 @@ This rule is fixable using the `--fix` option. Only if the rule breaks. +## Options + +This rule as an object option: + +- `"nodeVersionOverride"`: allow providing a custom supported node version if an external dependency enforces it + +### nodeVersionOverride + +Example of **correct** code for this rule with the `{ "nodeVersionOverride": ">=10.0.0" }` option: + +```json +{ + "engines": { + "node": ">=10.0.0" + } +} +``` + ## [Source](https://azure.github.io/azure-sdk/typescript_implementation.html#ts-package-json-engine-is-present) Also encompasses [ts-node-support](https://azure.github.io/azure-sdk/typescript_design.html#ts-node-support), as the rules are similar enough to not exist separately for linting purposes. diff --git a/common/tools/eslint-plugin-azure-sdk/package.json b/common/tools/eslint-plugin-azure-sdk/package.json index b4fb7fb4a54c..5eaa6716c903 100644 --- a/common/tools/eslint-plugin-azure-sdk/package.json +++ b/common/tools/eslint-plugin-azure-sdk/package.json @@ -72,12 +72,14 @@ "@types/estree": "^0.0.45", "eslint-config-prettier": "^7.0.0", "glob": "^7.1.2", + "json-schema": "^0.3.0", "typescript": "4.1.2", "tslib": "^2.0.0" }, "devDependencies": { "@types/chai": "^4.1.6", "@types/glob": "^7.1.1", + "@types/json-schema": "^7.0.6", "@types/mocha": "^7.0.2", "@types/node": "^8.0.0", "@typescript-eslint/eslint-plugin": "^4.9.0", diff --git a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-engine-is-present.ts b/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-engine-is-present.ts index 46ce0b458204..50aabaa89d8c 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-engine-is-present.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-engine-is-present.ts @@ -9,6 +9,12 @@ import { Rule } from "eslint"; import { getRuleMetaData, getVerifiers, stripPath } from "../utils"; +/** + * definition of LTS Node versions + * * needs updating as definitions change + */ +const LTS = ">=8.0.0"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ @@ -17,19 +23,27 @@ export = { meta: getRuleMetaData( "ts-package-json-engine-is-present", "force Node support for all LTS versions", - "code" + "code", + [ + { + type: "object", + properties: { + nodeVersionOverride: { + type: "string", + default: LTS, + description: "Allows specifying a different node version than the current default" + } + } + } + ] ), create: (context: Rule.RuleContext): Rule.RuleListener => { - /** - * definition of LTS Node versions - * * needs updating as definitions change - */ - const LTS = ">=8.0.0"; + const options = context.options[0] || {}; const verifiers = getVerifiers(context, { outer: "engines", inner: "node", - expected: LTS + expected: options.nodeVersionOverride || LTS }); return stripPath(context.getFilename()) === "package.json" ? ({ diff --git a/common/tools/eslint-plugin-azure-sdk/src/utils/metadata.ts b/common/tools/eslint-plugin-azure-sdk/src/utils/metadata.ts index e4e67fd677da..fa81e7302fb4 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/utils/metadata.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/utils/metadata.ts @@ -7,11 +7,13 @@ */ import { Rule } from "eslint"; +import { JSONSchema4 } from "json-schema"; export const getRuleMetaData = ( ruleName: string, ruleDescription: string, - fix?: "code" | "whitespace" + fix?: "code" | "whitespace", + schema?: JSONSchema4 | JSONSchema4[] ): Rule.RuleMetaData => { const required = { type: "suggestion", @@ -21,7 +23,7 @@ export const getRuleMetaData = ( recommended: true, url: `https://github.com/Azure/azure-sdk-for-js/tree/master/common/tools/eslint-plugin-azure-sdk/docs/rules/${ruleName}.md` }, - schema: [] + schema: schema || [] }; return (fix !== undefined ? { ...required, fixable: fix } : required) as Rule.RuleMetaData; }; diff --git a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-engine-is-present.ts b/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-engine-is-present.ts index 328a20da1d8d..8810059d534a 100644 --- a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-engine-is-present.ts +++ b/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-engine-is-present.ts @@ -269,6 +269,16 @@ ruleTester.run("ts-package-json-engine-is-present", rule, { // incorrect format but in a file we don't care about code: '{"engines": { "node": ">=6.0.0" }}', filename: "not_package.json" + }, + { + // different than the default but with an override + code: '{"engines": { "node": ">=8.5.0" }}', + filename: "package.json", + options: [ + { + nodeVersionOverride: ">=8.5.0" + } + ] } ], invalid: [ @@ -322,6 +332,22 @@ ruleTester.run("ts-package-json-engine-is-present", rule, { } ], output: examplePackageGood + }, + { + // override was provided but the version does not match + code: '{"engines": { "node": ">=8.0.0" }}', + filename: "package.json", + errors: [ + { + message: "engines.node is set to >=8.0.0 when it should be set to >=6.5.0" + } + ], + options: [ + { + nodeVersionOverride: ">=6.5.0" + } + ], + output: '{"engines": { "node": ">=6.5.0" }}' } ] }); diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/.eslintrc.json b/sdk/monitor/opentelemetry-exporter-azure-monitor/.eslintrc.json index c74136d13cf1..49ba262b614f 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/.eslintrc.json +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/.eslintrc.json @@ -12,6 +12,12 @@ ], "rules": { "no-underscore-dangle": ["error", { "allowAfterThis": true }], - "node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }] + "node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }], + // OpenTelemetry requires a minimum node version of 8.5.0 + // https://github.com/open-telemetry/opentelemetry-js#node-support + "@azure/azure-sdk/ts-package-json-engine-is-present": [ + "error", + { "nodeVersionOverride": ">=8.5.0" } + ] } } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/README.md b/sdk/monitor/opentelemetry-exporter-azure-monitor/README.md index 4a397a35bd06..5bdadffe332d 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/README.md +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/README.md @@ -14,7 +14,7 @@ This exporter package assumes your application is [already instrumented](https:/ You must have an [Azure subscription](https://azure.microsoft.com/free/) and a [Application Insights workspace](https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview/) to use this package. -If you are using this package in a Node.js application, then use Node.js 8.x or higher. +If you are using this package in a Node.js application, then use Node.js 8.5.0 or higher. ### Distributed Tracing diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json index 420184f96c2f..62931380e6e6 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json @@ -35,7 +35,7 @@ "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --mode file --out ./dist/docs ./src" }, "engines": { - "node": ">=8.0.0" + "node": ">=8.5.0" }, "files": [ "dist-esm/src/",