Extract system requirements into own package (#4511)

This commit is contained in:
Timothee Guerin 2022-04-12 08:17:23 -07:00 коммит произвёл GitHub
Родитель b7795182b6
Коммит f07c0303b7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
47 изменённых файлов: 351 добавлений и 45 удалений

3
.gitmodules поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
[submodule "perks"]
path = perks
url = https://github.com/azure/perks

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/extension-base",
"comment": "",
"type": "none"
}
],
"packageName": "@autorest/extension-base"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/system-requirements",
"comment": "",
"type": "none"
}
],
"packageName": "@autorest/system-requirements"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/codegen",
"comment": "",
"type": "none"
}
],
"packageName": "@azure-tools/codegen"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/datastore",
"comment": "",
"type": "none"
}
],
"packageName": "@azure-tools/datastore"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/deduplication",
"comment": "",
"type": "none"
}
],
"packageName": "@azure-tools/deduplication"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/extension",
"comment": "Extracted system-requirements into own package `@autorest/system-requirements`",
"type": "minor"
}
],
"packageName": "@azure-tools/extension"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/oai2-to-oai3",
"comment": "",
"type": "none"
}
],
"packageName": "@azure-tools/oai2-to-oai3"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/openapi",
"comment": "",
"type": "none"
}
],
"packageName": "@azure-tools/openapi"
}

Просмотреть файл

@ -27,6 +27,7 @@ specifiers:
'@rush-temp/oai2-to-oai3': file:./projects/oai2-to-oai3.tgz
'@rush-temp/openapi': file:./projects/openapi.tgz
'@rush-temp/schemas': file:./projects/schemas.tgz
'@rush-temp/system-requirements': file:./projects/system-requirements.tgz
'@rush-temp/test-public-packages': file:./projects/test-public-packages.tgz
'@rush-temp/test-utils': file:./projects/test-utils.tgz
'@rush-temp/yaml': file:./projects/yaml.tgz
@ -145,6 +146,7 @@ dependencies:
'@rush-temp/oai2-to-oai3': file:projects/oai2-to-oai3.tgz_prettier@2.3.2+ts-node@9.1.1
'@rush-temp/openapi': file:projects/openapi.tgz_prettier@2.3.2+ts-node@9.1.1
'@rush-temp/schemas': file:projects/schemas.tgz
'@rush-temp/system-requirements': file:projects/system-requirements.tgz_prettier@2.3.2+ts-node@9.1.1
'@rush-temp/test-public-packages': file:projects/test-public-packages.tgz_prettier@2.3.2
'@rush-temp/test-utils': file:projects/test-utils.tgz_5881cafc48bf8869a383fbba5699651c
'@rush-temp/yaml': file:projects/yaml.tgz_prettier@2.3.2+ts-node@9.1.1
@ -9064,7 +9066,7 @@ packages:
dev: false
file:projects/extension.tgz_prettier@2.3.2+ts-node@9.1.1:
resolution: {integrity: sha512-27HsZX4+i8G/kNsVCLExkFB3hFl9BQCUIapLbsyJ7BNaWz7YlcBlKN9mTigag96roCLpBQH9ZiNJn5bUOOxSJA==, tarball: file:projects/extension.tgz}
resolution: {integrity: sha512-lVBWs9omyZVv1+0mz8HeThSQFrDCDKrDdfV6ye4Bckyp/ctPSWVlWk9s8m42f/3k/ZMD0Qm3HFIgrhx1QlDI6w==, tarball: file:projects/extension.tgz}
id: file:projects/extension.tgz
name: '@rush-temp/extension'
version: 0.0.0
@ -9368,6 +9370,39 @@ packages:
version: 0.0.0
dev: false
file:projects/system-requirements.tgz_prettier@2.3.2+ts-node@9.1.1:
resolution: {integrity: sha512-W01jHZ9w5/U/zllacjXM8T+uewjMKIkSvoRveSN8Y9aBkKkmI/riD9ktjE0CqGrSQkjxHf72vZm+j6BL6hVRVw==, tarball: file:projects/system-requirements.tgz}
id: file:projects/system-requirements.tgz
name: '@rush-temp/system-requirements'
version: 0.0.0
dependencies:
'@azure/logger': 1.0.3
'@types/command-exists': 1.2.0
'@types/jest': 26.0.24
'@types/node': 14.14.45
'@types/semver': 5.5.0
'@typescript-eslint/eslint-plugin': 4.33.0_0c49e12669280545a7ea3f36dba6eb0a
'@typescript-eslint/parser': 4.33.0_eslint@7.32.0+typescript@4.6.3
command-exists: 1.2.9
eslint: 7.32.0
eslint-plugin-import: 2.24.2_eslint@7.32.0
eslint-plugin-jest: 24.3.7_012529635eb9b641f5155884af76fbb6
eslint-plugin-node: 11.1.0_eslint@7.32.0
eslint-plugin-prettier: 3.4.1_eslint@7.32.0+prettier@2.3.2
eslint-plugin-unicorn: 33.0.1_eslint@7.32.0
jest: 28.0.0-alpha.8_5076b77de2277d7bd3e529e70437d1c6
rimraf: 3.0.2
semver: 7.3.6
source-map-support: 0.5.21
typescript: 4.6.3
transitivePeerDependencies:
- eslint-config-prettier
- node-notifier
- prettier
- supports-color
- ts-node
dev: false
file:projects/test-public-packages.tgz_prettier@2.3.2:
resolution: {integrity: sha512-vCwScU2BKR9k6LmLkkRXP7GOS8qCYZEb7mtvDB77KBBdvD04hrAkOSu2Nw06xa497dlU3t+0r+mCPOc9cskGBw==, tarball: file:projects/test-public-packages.tgz}
id: file:projects/test-public-packages.tgz

Просмотреть файл

@ -22,7 +22,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"keywords": [
"AutoRest",
@ -31,10 +31,10 @@
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/perks/tree/master/codegen#readme",
"readme": "https://github.com/Azure/perks/tree/master/codegen/readme.md",
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/codegen#readme",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/codegen/readme.md",
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/js-yaml": "~4.0.0",

Просмотреть файл

@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"scripts": {
"watch": "tsc -p tsconfig.build.json --watch",
@ -31,7 +31,7 @@
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/datastore",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/datastore/readme.md",

Просмотреть файл

@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"scripts": {
"watch": "tsc -p tsconfig.build.json --watch",
@ -31,7 +31,7 @@
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/deduplication",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/deduplication/readme.md",

Просмотреть файл

@ -22,7 +22,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"keywords": [
"autorest",

Просмотреть файл

@ -23,7 +23,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"keywords": [
"perks",
@ -34,11 +34,12 @@
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/extension",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/extension/readme.md",
"dependencies": {
"@autorest/system-requirements": "~1.0.0",
"@azure-tools/async-io": "~3.0.0",
"@azure-tools/tasks": "~3.0.0",
"@azure/logger": "^1.0.2",

Просмотреть файл

@ -1,6 +1,5 @@
import { SystemRequirementError } from "@autorest/system-requirements";
import { Extension } from "./extension";
import { PackageManagerLogEntry } from "./package-manager";
import { SystemRequirementError } from "./system-requirements";
export class UnresolvedPackageException extends Error {
constructor(packageId: string) {

Просмотреть файл

@ -1,4 +1,3 @@
export * from "./exceptions";
export * from "./main";
export * from "./extension";
export * from "./system-requirements";

Просмотреть файл

@ -6,6 +6,12 @@
import { ChildProcess, spawn } from "child_process";
import { homedir, tmpdir } from "os";
import { basename, delimiter, dirname, extname, isAbsolute, join, normalize, resolve } from "path";
import {
patchPythonPath,
PythonCommandLine,
ExtensionSystemRequirements,
validateExtensionSystemRequirements,
} from "@autorest/system-requirements";
import { exists, isDirectory, isFile, mkdir, readdir, rmdir } from "@azure-tools/async-io";
import { Delay, Exception, Mutex, SharedLock } from "@azure-tools/tasks";
import { resolve as npmResolvePackage } from "npm-package-arg";
@ -24,12 +30,6 @@ import { AsyncLock } from "./locks/async-lock";
import { logger } from "./logger";
import { Npm } from "./npm";
import { PackageManager, PackageManagerLogEntry, PackageManagerProgress, PackageManagerType } from "./package-manager";
import {
patchPythonPath,
PythonCommandLine,
ExtensionSystemRequirements,
validateExtensionSystemRequirements,
} from "./system-requirements";
import { Yarn } from "./yarn";
export interface PackageInstallProgress extends PackageManagerProgress {

Просмотреть файл

@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"scripts": {
"watch": "tsc -p tsconfig.build.json --watch",
@ -31,7 +31,7 @@
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/oai2-to-oai3",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/oai2-to-oai3/readme.md",

Просмотреть файл

@ -27,7 +27,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/perks.git"
"url": "git+https://github.com/Azure/autorest.git"
},
"scripts": {
"watch": "tsc -p tsconfig.build.json --watch",
@ -49,7 +49,7 @@
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/perks/issues"
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/openapi",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/openapi/readme.md",

Просмотреть файл

@ -0,0 +1,3 @@
parser: "@typescript-eslint/parser"
extends:
- "../../../.default-eslintrc.yaml"

Просмотреть файл

@ -0,0 +1,22 @@
!dist/**/*
test/
dist/test/
package/
.npmignore
*.tsbuildinfo
tsconfig.json
*.ts
changelog.md
.eslint*
!*.d.ts
*.tgz
.vscode
.scripts
attic/
generated/
notes.md
Examples/
samples/
*.log
package-deps.json
tslint.json

Просмотреть файл

@ -0,0 +1,10 @@
// @ts-check
const defaultConfig = require("../../../jest.default.config");
const config = {
...defaultConfig,
testMatch: ["<rootDir>/src/**/*.test.ts", "<rootDir>/test/**/*.test.ts"],
};
module.exports = config;

Просмотреть файл

@ -0,0 +1,10 @@
// @ts-check
const defaultConfig = require("./jest.config");
const config = {
...defaultConfig,
testMatch: ["<rootDir>/test/**/*.e2e.ts"],
};
module.exports = config;

Просмотреть файл

@ -0,0 +1,60 @@
{
"name": "@autorest/system-requirements",
"version": "1.0.0",
"description": "System requirement validation and resolution for autorest",
"engines": {
"node": ">=12.0.0"
},
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"watch": "tsc -p tsconfig.build.json --watch",
"build": "tsc -p tsconfig.build.json",
"lint:fix": "eslint ./src --fix --ext .ts",
"lint": "eslint ./src --ext .ts --max-warnings=0",
"prepare": "npm run build",
"test": "jest --coverage=false --watch",
"test:ci": "jest --ci",
"clean": "rimraf ./dist ./temp"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/autorest.git"
},
"keywords": [
"perks",
"autorest",
"azure",
"typescript"
],
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/autorest/issues"
},
"homepage": "https://github.com/Azure/autorest/tree/main/packages/libs/system-requirements",
"readme": "https://github.com/Azure/autorest/tree/main/packages/libs/system-requirements/readme.md",
"dependencies": {
"@azure/logger": "^1.0.2",
"command-exists": "~1.2.9",
"semver": "^7.3.5"
},
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/command-exists": "~1.2.0",
"@types/node": "~14.14.20",
"@types/semver": "5.5.0",
"@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0",
"eslint-plugin-jest": "~24.3.2",
"eslint-plugin-node": "~11.1.0",
"eslint-plugin-prettier": "~3.4.0",
"eslint-plugin-unicorn": "~33.0.1",
"eslint-plugin-import": "~2.24.2",
"eslint": "^7.17.0",
"rimraf": "^3.0.2",
"jest": "^28.0.0-alpha.7",
"source-map-support": "^0.5.19",
"typescript": "~4.6.3"
}
}

Просмотреть файл

@ -0,0 +1,5 @@
# Project: @autorest/system-requirements
# Contributing
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

Просмотреть файл

@ -1,4 +1,4 @@
import { SystemRequirement, SystemRequirementResolution } from "./models";
import { SystemRequirement, SystemRequirementResolution } from "./types";
import { validateVersionRequirement } from "./version";
/**

Просмотреть файл

@ -1,7 +1,7 @@
import { execute } from "../exec-cmd";
import { resolveDotnetRequirement } from "./dotnet";
import { execute } from "./exec-cmd";
jest.mock("../exec-cmd");
jest.mock("./exec-cmd");
const mockExecute = execute as jest.Mock;

Просмотреть файл

@ -1,5 +1,5 @@
import { execute } from "../exec-cmd";
import { defineKnownRequirement } from "./common";
import { execute } from "./exec-cmd";
export const DotnetExeName = "dotnet";

Просмотреть файл

@ -0,0 +1,60 @@
import { SpawnOptions, ChildProcess, spawn } from "child_process";
interface MoreOptions extends SpawnOptions {
onCreate?(cp: ChildProcess): void;
onStdOutData?(chunk: any): void;
onStdErrData?(chunk: any): void;
}
export interface ExecResult {
stdout: string;
stderr: string;
/**
* Union of stdout and stderr.
*/
log: string;
error: Error | null;
code: number | null;
}
export const execute = (
command: string,
cmdlineargs: Array<string>,
options: MoreOptions = {},
): Promise<ExecResult> => {
return new Promise((resolve, reject) => {
const cp = spawn(command, cmdlineargs, { ...options, stdio: "pipe" });
if (options.onCreate) {
options.onCreate(cp);
}
options.onStdOutData ? cp.stdout.on("data", options.onStdOutData) : cp;
options.onStdErrData ? cp.stderr.on("data", options.onStdErrData) : cp;
let err = "";
let out = "";
let all = "";
cp.stderr.on("data", (chunk) => {
err += chunk;
all += chunk;
});
cp.stdout.on("data", (chunk) => {
out += chunk;
all += chunk;
});
cp.on("error", (err) => {
reject(err);
});
cp.on("close", (code, signal) =>
resolve({
stdout: out,
stderr: err,
log: all,
error: code ? new Error("Process Failed.") : null,
code,
}),
);
});
};

Просмотреть файл

@ -1,5 +1,5 @@
import commandExists from "command-exists";
import { SystemRequirementError, SystemRequirementResolution } from "./models";
import { SystemRequirementError, SystemRequirementResolution } from "./types";
export const resolveGenericSystemRequirement = async (
name: string,

Просмотреть файл

@ -1,5 +1,5 @@
export * from "./system-requirements";
export * from "./models";
export * from "./types";
export * from "./python";
export * from "./java";
export * from "./dotnet";

Просмотреть файл

@ -1,7 +1,7 @@
import { execute } from "../exec-cmd";
import { execute } from "./exec-cmd";
import { resolveJavaRequirement } from "./java";
jest.mock("../exec-cmd");
jest.mock("./exec-cmd");
const mockExecute = execute as jest.Mock;

Просмотреть файл

@ -1,5 +1,5 @@
import { execute } from "../exec-cmd";
import { defineKnownRequirement } from "./common";
import { execute } from "./exec-cmd";
export const JavaExeName = "java";

Просмотреть файл

@ -0,0 +1,3 @@
import { createClientLogger } from "@azure/logger";
export const logger = createClientLogger("@azure-tools/extension");

Просмотреть файл

@ -1,7 +1,7 @@
import { execute } from "../exec-cmd";
import { execute } from "./exec-cmd";
import { patchPythonPath, PythonCommandLine, resolvePythonRequirement, updatePythonPath } from "./python";
jest.mock("../exec-cmd");
jest.mock("./exec-cmd");
const mockExecute = execute as jest.Mock;

Просмотреть файл

@ -1,6 +1,6 @@
import { execute } from "../exec-cmd";
import { getExecutablePath } from "./common";
import { SystemRequirement, SystemRequirementError, SystemRequirementResolution } from "./models";
import { execute } from "./exec-cmd";
import { SystemRequirement, SystemRequirementError, SystemRequirementResolution } from "./types";
import { validateVersionRequirement } from "./version";
export const PythonRequirement = "python";

Просмотреть файл

@ -1,13 +1,13 @@
import { DotnetExeName, resolveDotnetRequirement } from "./dotnet";
import { resolveGenericSystemRequirement } from "./generic";
import { JavaExeName, resolveJavaRequirement } from "./java";
import { PythonRequirement, resolvePythonRequirement } from "./python";
import {
ExtensionSystemRequirements,
SystemRequirementError,
SystemRequirement,
SystemRequirementResolution,
} from "./models";
import { PythonRequirement, resolvePythonRequirement } from "./python";
} from "./types";
/**
* Resolve the extension requirements and returns a list of errors.

Просмотреть файл

@ -1,5 +1,5 @@
import semver from "semver";
import { SystemRequirement, SystemRequirementError, SystemRequirementResolution } from "./models";
import { SystemRequirement, SystemRequirementError, SystemRequirementResolution } from "./types";
/**
* Validate the provided system requirement resolution is satisfying the version requirement if applicable.

Просмотреть файл

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src"
},
"exclude": ["**/*.test.*", "test/**/*"]
}

Просмотреть файл

@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"tsBuildInfoFile": "temp/.tsbuildinfo"
},
"include": ["src/**/*.ts", "definitions/**/*.d.ts", "test/**/*.ts"]
}

Просмотреть файл

@ -117,6 +117,12 @@
"reviewCategory": "production",
"shouldPublish": false
},
{
"packageName": "@autorest/system-requirements",
"projectFolder": "packages/libs/system-requirements",
"reviewCategory": "production",
"shouldPublish": true
},
{
"packageName": "@azure-tools/extension",
"projectFolder": "packages/libs/extension",

Просмотреть файл

@ -12,12 +12,13 @@
{ "path": "packages/libs/configuration/tsconfig.build.json" },
{ "path": "packages/libs/datastore/tsconfig.build.json" },
{ "path": "packages/libs/deduplication/tsconfig.build.json" },
{ "path": "packages/libs/extension/tsconfig.build.json" },
{ "path": "packages/libs/extension-base/tsconfig.build.json" },
{ "path": "packages/libs/extension/tsconfig.build.json" },
{ "path": "packages/libs/json/tsconfig.build.json" },
{ "path": "packages/libs/jsonschema/tsconfig.build.json" },
{ "path": "packages/libs/oai2-to-oai3/tsconfig.build.json" },
{ "path": "packages/libs/openapi/tsconfig.build.json" },
{ "path": "packages/libs/system-requirements/tsconfig.build.json" },
{ "path": "packages/libs/yaml/tsconfig.build.json" }
],
"files": []