HotFix: Remove all extension methods on string and array causing weird behaviors (#4341)

This commit is contained in:
Timothee Guerin 2021-10-15 08:27:34 -07:00 коммит произвёл GitHub
Родитель 5bb7288f84
Коммит 55efe04ed6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
36 изменённых файлов: 199 добавлений и 90 удалений

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

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/core",
"comment": "**Internal** Remove use of extension method `.last`",
"type": "patch"
}
],
"packageName": "@autorest/core",
"email": "tiguerin@microsoft.com"
}

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

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/modelerfour",
"comment": "**Internal",
"type": "patch"
}
],
"packageName": "@autorest/modelerfour",
"email": "tiguerin@microsoft.com"
}

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

@ -141,12 +141,11 @@ Those flags are temporary and will be removed in the future. Those flags are her
## Go flags
| Flag | Description |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--module=NAME` | The name of the module. This is the name your module will be published under. |
| `--file-prefix=PREFIX` | Optional prefix to file names. For example, if you set your file prefix to "zzz", all generated code files will begin with "zzz". |
| `--openapi-type=arm\|data-plane` | Specify if you want to generate `data-plane` code or `arm` code. |
| `--armcore-connection` | If set to `true`, we output the code with the `Connection` type specified in [`armcore`][armcore_connection]. If not, we output a new `Connection` constructor with the generated code. Defaults to `false`. |
| Flag | Description |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `--module=NAME` | The name of the module. This is the name your module will be published under. |
| `--file-prefix=PREFIX` | Optional prefix to file names. For example, if you set your file prefix to "zzz", all generated code files will begin with "zzz". |
| `--openapi-type=arm\|data-plane` | Specify if you want to generate `data-plane` code or `arm` code. |
## Swift flags

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

@ -43,7 +43,7 @@
},
"typings": "./dist/exports.d.ts",
"devDependencies": {
"@autorest/configuration": "~1.7.2",
"@autorest/configuration": "~1.7.3",
"@autorest/core": "~3.6.6",
"@autorest/common": "~1.3.0",
"@azure-tools/async-io": "~3.0.0",

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

@ -62,6 +62,6 @@
},
"dependencies": {
"@cadl-lang/compiler": "~0.19.0 ",
"@autorest/extension-base": "~3.3.1"
"@autorest/extension-base": "~3.3.2"
}
}

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

@ -43,12 +43,12 @@
"typings": "./dist/exports.d.ts",
"devDependencies": {
"@autorest/common": "~1.3.0",
"@autorest/configuration": "~1.7.2",
"@autorest/configuration": "~1.7.3",
"@autorest/schemas": "~1.3.1",
"@autorest/test-utils": "~0.4.0",
"@azure-tools/async-io": "~3.0.0",
"@azure-tools/codegen": "~2.7.0",
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/codegen": "~2.8.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/deduplication": "~3.1.1",
"@azure-tools/extension": "~3.3.1",
"@azure-tools/json": "~1.2.0",

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

@ -17,6 +17,7 @@ import {
import { CachingFileSystem, IFileSystem, LazyPromise, RealFileSystem } from "@azure-tools/datastore";
import { Extension, ExtensionManager } from "@azure-tools/extension";
import { createFileOrFolderUri, createFolderUri, resolveUri } from "@azure-tools/uri";
import { last } from "lodash";
import { AppRoot } from "../constants";
import { AutoRestExtension } from "../pipeline/plugin-endpoint";
import { StatsCollector } from "../stats";
@ -115,7 +116,8 @@ export class AutorestContextLoader {
private setupExtensions(config: AutorestConfiguration, extensions: ResolvedExtension[]) {
for (const { extension, definition } of extensions) {
if (!loadedExtensions[definition.fullyQualified]) {
const shortname = definition.name.split("/").last.replace(/^autorest\./gi, "");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const shortname = last(definition.name.split("/"))!.replace(/^autorest\./gi, "");
const nestedConfig = [...getNestedConfiguration(config, shortname)][0];
const enableDebugger = nestedConfig?.["debugger"];

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

@ -18,7 +18,7 @@ import {
PipeState,
mergePipeStates,
} from "@azure-tools/datastore";
import { mapValues, omitBy } from "lodash";
import { last, mapValues, omitBy } from "lodash";
import { AutorestContext } from "../context";
import { OutstandingTaskAwaiter } from "../outstanding-task-awaiter";
import { CORE_PLUGIN_MAP } from "../plugins";
@ -274,7 +274,8 @@ export async function runPipeline(configView: AutorestContext, fileSystem: IFile
// you can have --pass-thru:FOO on the command line
// or add pass-thru: true in a pipline configuration step.
const configEntry = context.GetEntry(node.configScope.last.toString());
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const configEntry = context.GetEntry(last(node.configScope)!.toString());
const passthru =
configEntry?.["pass-thru"] === true || configView.config["pass-thru"]?.find((x) => x === pluginName);
const usenull =

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

@ -54,7 +54,7 @@ export function createGraphTransformerPlugin(): PipelinePlugin {
documentPath: inputHandle.key,
});
parent[path.last] = output;
parent[path[path.length - 1]] = output;
// assuming this for now.
modified = true;

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

@ -40,11 +40,11 @@
"readme": "https://github.com/Azure/autorest/tree/main/packages/extensions/modelerfour/readme.md",
"devDependencies": {
"@autorest/codemodel": "~4.17.0",
"@autorest/extension-base": "~3.3.1",
"@autorest/extension-base": "~3.3.2",
"@autorest/test-utils": "~0.4.0",
"@azure-tools/async-io": "~3.0.0",
"@azure-tools/codegen": "~2.7.0",
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/codegen": "~2.8.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/openapi": "~3.2.1",
"@azure-tools/tasks": "~3.0.0",
"@azure-tools/uri": "~3.1.1",

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

@ -1,6 +1,7 @@
import { Languages } from "@autorest/codemodel";
import { Session } from "@autorest/extension-base";
import { removeSequentialDuplicates, fixLeadingNumber, deconstruct, Style, Styler } from "@azure-tools/codegen";
import { last } from "lodash";
export function getNameOptions(typeName: string, components: Array<string>) {
const result = new Set<string>();
@ -14,7 +15,8 @@ export function getNameOptions(typeName: string, components: Array<string>) {
// add a second-to-last-ditch option as <typename>.<name>
result.add(
Style.pascal([
...removeSequentialDuplicates([...fixLeadingNumber(deconstruct(typeName)), ...deconstruct(components.last)]),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...removeSequentialDuplicates([...fixLeadingNumber(deconstruct(typeName)), ...deconstruct(last(components)!)]),
]),
);
return [...result.values()];

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

@ -1,6 +1,18 @@
{
"name": "@azure-tools/codegen",
"entries": [
{
"version": "2.8.0",
"tag": "@azure-tools/codegen_v2.8.0",
"date": "Thu, 14 Oct 2021 23:03:29 GMT",
"comments": {
"minor": [
{
"comment": "**Removed** Array and String extension methods(`.last`, `.captialize`, etc.) causing polution and conflicts."
}
]
}
},
{
"version": "2.7.0",
"tag": "@azure-tools/codegen_v2.7.0",

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

@ -1,6 +1,13 @@
# Change Log - @azure-tools/codegen
This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:29 GMT and should not be manually modified.
## 2.8.0
Thu, 14 Oct 2021 23:03:29 GMT
### Minor changes
- **Removed** Array and String extension methods(`.last`, `.captialize`, etc.) causing polution and conflicts.
## 2.7.0
Wed, 08 Sep 2021 15:39:22 GMT

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

@ -1,6 +1,6 @@
{
"name": "@azure-tools/codegen",
"version": "2.7.0",
"version": "2.8.0",
"description": "Autorest Code generator common and base classes",
"directories": {
"doc": "docs"

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

@ -941,7 +941,7 @@ export class EnglishPluralizationService {
const de = deconstruct(word);
// singularize the last word only
de[de.length - 1] = this.capitalize(de.last, (w) => this.internalSingularize(w));
de[de.length - 1] = this.capitalize(de[de.length - 1], (w) => this.internalSingularize(w));
// return the pascal cased whole thing.
return pascalCase(de);

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

@ -19,53 +19,17 @@ const acronyms = new Set([
"vm", // 'ssl', 'https', 'http', ''
]);
declare global {
interface Array<T> {
joinWith(selector: (t: T) => string, separator?: string): string;
last: T;
}
interface String {
capitalize(): string;
uncapitalize(): string;
slim(): string;
export function capitalize(str: string): string {
if (acronyms.has(str)) {
return str.toUpperCase();
}
return str ? `${str.charAt(0).toUpperCase()}${str.substr(1)}` : str;
}
/** joins an array by passing thru a selector and uses the separator string (defaults to comma) */
Array.prototype.joinWith = function <T>(selector: (t: T) => string, separator?: string): string {
return (<Array<T>>this)
.map(selector)
.filter((v) => (v ? true : false))
.join(separator || CommaChar);
};
/** todo: can we remove this? */
/* eslint-disable */
if (!Array.prototype.hasOwnProperty("last")) {
Object.defineProperty(Array.prototype, "last", {
get() {
return this[this.length - 1];
},
});
export function uncapitalize(str: string): string {
return str ? `${str.charAt(0).toLowerCase()}${str.substr(1)}` : str;
}
String.prototype.capitalize = function (): string {
const result = <string>this;
if (acronyms.has(result)) {
return result.toUpperCase();
}
return result ? `${result.charAt(0).toUpperCase()}${result.substr(1)}` : result;
};
String.prototype.uncapitalize = function (): string {
const result = <string>this;
return result ? `${result.charAt(0).toLowerCase()}${result.substr(1)}` : result;
};
/** Trims the string and removes multi leading spaces? */
String.prototype.slim = function (): string {
return this.trim().replace(/([^ ]) +/g, "$1 ");
};
export function join<T>(items: Array<T>, separator: string) {
return items.filter((v) => (v ? true : false)).join(separator);
}
@ -109,7 +73,7 @@ export function fixEOL(content: string) {
return content.replace(/\r\n/g, EOL);
}
export function indent(content: string, factor: number = 1): string {
export function indent(content: string, factor = 1): string {
const i = indentation.repeat(factor);
content = i + fixEOL(content.trim());
return content.split(/\n/g).join(`${EOL}${i}`);
@ -303,7 +267,7 @@ export function removeProhibitedPrefix(
return identifier;
}
newIdentifier = isCapitalized(identifier) ? newIdentifier.capitalize() : newIdentifier.uncapitalize();
newIdentifier = isCapitalized(identifier) ? capitalize(newIdentifier) : uncapitalize(newIdentifier);
return skipIdentifiers !== undefined
? skipIdentifiers.includes(newIdentifier)
? identifier
@ -340,7 +304,7 @@ export function pascalCase(identifier: string | Array<string>, removeDuplicates
: typeof identifier === "string"
? pascalCase(fixLeadingNumber(deconstruct(identifier)), removeDuplicates)
: (removeDuplicates ? [...removeSequentialDuplicates(identifier)] : identifier)
.map((each) => each.capitalize())
.map((each) => capitalize(each))
.join("");
}
@ -352,9 +316,9 @@ export function camelCase(identifier: string | Array<string>): string {
case 0:
return "";
case 1:
return identifier[0].uncapitalize();
return uncapitalize(identifier[0]);
}
return `${identifier[0].uncapitalize()}${pascalCase(identifier.slice(1))}`;
return `${uncapitalize(identifier[0])}${pascalCase(identifier.slice(1))}`;
}
export function getPascalIdentifier(name: string): string {
@ -377,7 +341,7 @@ export function nameof(text: string): string {
return `nameof(${text})`;
}
export function* getRegions(source: string, prefix: string = "#", postfix: string = "") {
export function* getRegions(source: string, prefix = "#", postfix = "") {
source = source.replace(/\r?\n|\r/g, "«");
const rx = new RegExp(

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

@ -1,6 +1,18 @@
{
"name": "@autorest/codemodel",
"entries": [
{
"version": "4.17.1",
"tag": "@autorest/codemodel_v4.17.1",
"date": "Thu, 14 Oct 2021 23:03:29 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@azure-tools/codegen\" from `~2.7.0` to `~2.8.0`"
}
]
}
},
{
"version": "4.17.0",
"tag": "@autorest/codemodel_v4.17.0",

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

@ -1,6 +1,11 @@
# Change Log - @autorest/codemodel
This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:29 GMT and should not be manually modified.
## 4.17.1
Thu, 14 Oct 2021 23:03:29 GMT
_Version update only_
## 4.17.0
Wed, 08 Sep 2021 15:39:22 GMT

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

@ -1,6 +1,6 @@
{
"name": "@autorest/codemodel",
"version": "4.17.0",
"version": "4.17.1",
"description": "AutoRest code model library",
"directories": {
"doc": "docs"
@ -53,7 +53,7 @@
"typescript": "~4.4.2"
},
"dependencies": {
"@azure-tools/codegen": "~2.7.0",
"@azure-tools/codegen": "~2.8.0",
"js-yaml": "~4.0.0"
},
"publishConfig": {

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

@ -43,7 +43,7 @@
"typescript": "~4.4.2"
},
"dependencies": {
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/yaml": "~1.0.0",
"@azure-tools/json": "~1.2.0",
"@azure/logger": "^1.0.2",

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

@ -1,6 +1,23 @@
{
"name": "@autorest/configuration",
"entries": [
{
"version": "1.7.3",
"tag": "@autorest/configuration_v1.7.3",
"date": "Thu, 14 Oct 2021 23:03:28 GMT",
"comments": {
"patch": [
{
"comment": "**Fix** Issue with undefined properties"
}
],
"dependency": [
{
"comment": "Updating dependency \"@azure-tools/datastore\" from `~4.5.0` to `~4.5.1`"
}
]
}
},
{
"version": "1.7.2",
"tag": "@autorest/configuration_v1.7.2",

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

@ -1,6 +1,13 @@
# Change Log - @autorest/configuration
This log was last generated on Thu, 23 Sep 2021 19:51:32 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:28 GMT and should not be manually modified.
## 1.7.3
Thu, 14 Oct 2021 23:03:28 GMT
### Patches
- **Fix** Issue with undefined properties
## 1.7.2
Thu, 23 Sep 2021 19:51:32 GMT

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

@ -1,6 +1,6 @@
{
"name": "@autorest/configuration",
"version": "1.7.2",
"version": "1.7.3",
"description": "Autorest configuration",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -48,7 +48,7 @@
},
"dependencies": {
"@autorest/common": "~1.3.0",
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/extension": "~3.3.1",
"@azure-tools/uri": "~3.1.1",
"@azure-tools/async-io": "~3.0.0",

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

@ -3,6 +3,7 @@ import { exists, filePath } from "@azure-tools/async-io";
import { DataStore, IFileSystem, RealFileSystem, CachingFileSystem } from "@azure-tools/datastore";
import { Extension, ExtensionManager, LocalExtension } from "@azure-tools/extension";
import { createFileUri, resolveUri, simplifyUri, fileUriToPath } from "@azure-tools/uri";
import { last } from "lodash";
import untildify from "untildify";
import { AutorestConfiguration } from "../autorest-configuration";
import { AutorestNormalizedConfiguration } from "../autorest-normalized-configuration";
@ -251,7 +252,8 @@ export class ConfigurationLoader {
}
// trim off the '@org' and 'autorest.' from the name.
const shortname = extensionDef.name.split("/").last.replace(/^autorest\./gi, "");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const shortname = last(extensionDef.name.split("/"))!.replace(/^autorest\./gi, "");
// Add a hint here to make legacy users to be aware that the default version has been bumped to 3.0+.
if (shortname === "powershell") {

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

@ -157,6 +157,9 @@ function processProperty<T extends ConfigurationProperty>(
return { value: result };
} else {
if (value === undefined) {
return { value: undefined as any };
}
return processPrimitiveProperty(schema, path, value as InferredRawPrimitiveType<T>, options) as any;
}
}

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

@ -1,6 +1,18 @@
{
"name": "@azure-tools/datastore",
"entries": [
{
"version": "4.5.1",
"tag": "@azure-tools/datastore_v4.5.1",
"date": "Thu, 14 Oct 2021 23:03:29 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@azure-tools/codegen\" from `~2.7.0` to `~2.8.0`"
}
]
}
},
{
"version": "4.5.0",
"tag": "@azure-tools/datastore_v4.5.0",

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

@ -1,6 +1,11 @@
# Change Log - @azure-tools/datastore
This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:29 GMT and should not be manually modified.
## 4.5.1
Thu, 14 Oct 2021 23:03:29 GMT
_Version update only_
## 4.5.0
Wed, 08 Sep 2021 15:39:22 GMT

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

@ -1,6 +1,6 @@
{
"name": "@azure-tools/datastore",
"version": "4.5.0",
"version": "4.5.1",
"description": "Virtualized Filesystem with parsing and sourcemaps (AutoRest)",
"main": "./dist/main.js",
"typings": "./dist/main.d.ts",
@ -54,7 +54,7 @@
"typescript": "~4.4.2"
},
"dependencies": {
"@azure-tools/codegen": "~2.7.0",
"@azure-tools/codegen": "~2.8.0",
"@azure-tools/json": "~1.2.0",
"@azure-tools/tasks": "~3.0.0",
"@azure-tools/uri": "~3.1.1",

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

@ -1,6 +1,21 @@
{
"name": "@azure-tools/deduplication",
"entries": [
{
"version": "3.1.2",
"tag": "@azure-tools/deduplication_v3.1.2",
"date": "Thu, 14 Oct 2021 23:03:29 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@azure-tools/codegen\" from `~2.7.0` to `~2.8.0`"
},
{
"comment": "Updating dependency \"@azure-tools/datastore\" from `~4.5.0` to `~4.5.1`"
}
]
}
},
{
"version": "3.1.1",
"tag": "@azure-tools/deduplication_v3.1.1",

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

@ -1,6 +1,11 @@
# Change Log - @azure-tools/deduplication
This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:29 GMT and should not be manually modified.
## 3.1.2
Thu, 14 Oct 2021 23:03:29 GMT
_Version update only_
## 3.1.1
Wed, 08 Sep 2021 15:39:22 GMT

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

@ -1,6 +1,6 @@
{
"name": "@azure-tools/deduplication",
"version": "3.1.1",
"version": "3.1.2",
"description": "Deduplication of elements in OpenAPI 3 documents",
"main": "./dist/main.js",
"typings": "./dist/main.d.ts",
@ -52,8 +52,8 @@
"typescript": "~4.4.2"
},
"dependencies": {
"@azure-tools/codegen": "~2.7.0",
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/codegen": "~2.8.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/object-comparison": "~3.0.0",
"@azure-tools/tasks": "~3.0.0",
"compare-versions": "^3.4.0",

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

@ -1,6 +1,18 @@
{
"name": "@autorest/extension-base",
"entries": [
{
"version": "3.3.2",
"tag": "@autorest/extension-base_v3.3.2",
"date": "Thu, 14 Oct 2021 23:03:29 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@azure-tools/codegen\" from `~2.7.0` to `~2.8.0`"
}
]
}
},
{
"version": "3.3.1",
"tag": "@autorest/extension-base_v3.3.1",

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

@ -1,6 +1,11 @@
# Change Log - @autorest/extension-base
This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified.
This log was last generated on Thu, 14 Oct 2021 23:03:29 GMT and should not be manually modified.
## 3.3.2
Thu, 14 Oct 2021 23:03:29 GMT
_Version update only_
## 3.3.1
Wed, 08 Sep 2021 15:39:22 GMT

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

@ -1,6 +1,6 @@
{
"name": "@autorest/extension-base",
"version": "3.3.1",
"version": "3.3.2",
"description": "Library for creating AutoRest extensions",
"main": "dist/exports.js",
"typings": "./dist/exports.d.ts",
@ -43,6 +43,6 @@
"dependencies": {
"js-yaml": "~4.0.0",
"vscode-jsonrpc": "^3.5.0",
"@azure-tools/codegen": "~2.7.0"
"@azure-tools/codegen": "~2.8.0"
}
}

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

@ -55,7 +55,7 @@
"typescript": "~4.4.2"
},
"dependencies": {
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/openapi": "~3.2.1",
"@azure-tools/json": "~1.2.0",
"source-map": "0.7.3"

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

@ -31,7 +31,7 @@
"homepage": "https://github.com/Azure/autorest#readme",
"dependencies": {
"@autorest/common": "~1.3.0",
"@azure-tools/datastore": "~4.5.0",
"@azure-tools/datastore": "~4.5.1",
"@azure-tools/tasks": "~3.0.0",
"expect": "~26.6.2",
"jest-snapshot": "~26.6.2",