From e22bdfa98ec5b8453a26c2a841aeb781f9cfbd62 Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:09:36 -0300 Subject: [PATCH] feat: Add TS 5.6 and ESNext target support (#4763) * Add TS 5.6 and ESNext target support * Fix compat --- libraries/adaptive-expressions/.gitignore | 3 ++- .../etc/adaptive-expressions.api.md | 8 ++++---- libraries/adaptive-expressions/package.json | 15 +++++++++------ .../adaptive-expressions/src/functionTable.ts | 8 ++++---- .../adaptive-expressions/src/functionUtils.ts | 3 +-- .../adaptive-expressions/tests/tsconfig.json | 5 ++++- libraries/adaptive-expressions/tsconfig.json | 3 ++- .../types/ts5.6/lib/index.d.ts | 14 ++++++++++++++ testing/consumer-test/run.ts | 15 ++++++++++----- yarn.lock | 12 ------------ 10 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 libraries/adaptive-expressions/types/ts5.6/lib/index.d.ts diff --git a/libraries/adaptive-expressions/.gitignore b/libraries/adaptive-expressions/.gitignore index 6d2d6c869c..8f26681ee3 100644 --- a/libraries/adaptive-expressions/.gitignore +++ b/libraries/adaptive-expressions/.gitignore @@ -5,4 +5,5 @@ coverage .nyc_output /**/.antlr /**/*.interp -tests/expressionProperty.test.js \ No newline at end of file +tests/expressionProperty.test.js +!types/** \ No newline at end of file diff --git a/libraries/adaptive-expressions/etc/adaptive-expressions.api.md b/libraries/adaptive-expressions/etc/adaptive-expressions.api.md index be34938095..bcfe10fdf5 100644 --- a/libraries/adaptive-expressions/etc/adaptive-expressions.api.md +++ b/libraries/adaptive-expressions/etc/adaptive-expressions.api.md @@ -1927,7 +1927,7 @@ export class FuncInvokeExpContext extends PrimaryExpressionContext { // @public export class FunctionTable implements Map { - get [Symbol.iterator](): () => IterableIterator<[string, ExpressionEvaluator]>; + get [Symbol.iterator](): () => MapIterator<[string, ExpressionEvaluator]>; get [Symbol.toStringTag](): string; // (undocumented) add(item: { @@ -1942,15 +1942,15 @@ export class FunctionTable implements Map { add(key: string, value: customFunction): void; clear(): void; delete(key: string): boolean; - entries(): IterableIterator<[string, ExpressionEvaluator]>; + entries(): MapIterator<[string, ExpressionEvaluator]>; forEach(_callbackfn: (value: ExpressionEvaluator, key: string, map: Map) => void, _thisArg?: any): void; get(key: string): ExpressionEvaluator; has(key: string): boolean; get isReadOnly(): boolean; - keys(): IterableIterator; + keys(): MapIterator; set(key: string, value: ExpressionEvaluator): this; get size(): number; - values(): IterableIterator; + values(): MapIterator; } // @public diff --git a/libraries/adaptive-expressions/package.json b/libraries/adaptive-expressions/package.json index dae6c3acf0..200ec8928d 100644 --- a/libraries/adaptive-expressions/package.json +++ b/libraries/adaptive-expressions/package.json @@ -16,14 +16,16 @@ "type": "git", "url": "https://github.com/Microsoft/botbuilder-js.git" }, - "main": "./lib/index.js", - "browser": "./lib/browser.js", - "typings": "./lib/index.d.ts", + "main": "lib/index.js", + "browser": "lib/browser.js", + "types": "lib/index.d.ts", + "typesVersions": { + "<5.6": { "*": [ "types/ts5.6/*" ] } + }, "dependencies": { "@microsoft/recognizers-text-data-types-timex-expression": "~1.3.1", "@types/atob-lite": "^2.0.2", "@types/btoa-lite": "^1.0.2", - "@types/lodash.isequal": "^4.5.8", "@types/lru-cache": "^5.1.1", "antlr4ts": "0.5.0-alpha.4", "atob-lite": "^2.0.0", @@ -33,7 +35,7 @@ "d3-format": "^2.0.0", "dayjs": "^1.11.13", "jspath": "^0.4.0", - "lodash.isequal": "^4.5.0", + "lodash": "^4.17.21", "lru-cache": "^5.1.1", "uuid": "^10.0.0", "fast-xml-parser": "^4.4.1", @@ -62,6 +64,7 @@ }, "files": [ "lib", - "src" + "src", + "types" ] } diff --git a/libraries/adaptive-expressions/src/functionTable.ts b/libraries/adaptive-expressions/src/functionTable.ts index d86059598c..ee789e45a3 100644 --- a/libraries/adaptive-expressions/src/functionTable.ts +++ b/libraries/adaptive-expressions/src/functionTable.ts @@ -23,7 +23,7 @@ export class FunctionTable implements Map { * * @returns A list of string values. */ - keys(): IterableIterator { + keys(): MapIterator { const keysOfAllFunctions = Array.from(ExpressionFunctions.standardFunctions.keys()).concat( Array.from(this.customFunctions.keys()) ); @@ -35,7 +35,7 @@ export class FunctionTable implements Map { * * @returns A list of [ExpressionEvaluator](xref:adaptive-expressions.ExpressionEvaluator). */ - values(): IterableIterator { + values(): MapIterator { const valuesOfAllFunctions = Array.from(ExpressionFunctions.standardFunctions.values()).concat( Array.from(this.customFunctions.values()) ); @@ -168,7 +168,7 @@ export class FunctionTable implements Map { * Returns an iterable of key, value pairs for every entry in the map. * Not implemented. */ - entries(): IterableIterator<[string, ExpressionEvaluator]> { + entries(): MapIterator<[string, ExpressionEvaluator]> { throw Error('entries function not implemented'); } @@ -176,7 +176,7 @@ export class FunctionTable implements Map { * Returns an iterable of key, value pairs. * Not implemented. */ - get [Symbol.iterator](): () => IterableIterator<[string, ExpressionEvaluator]> { + get [Symbol.iterator](): () => MapIterator<[string, ExpressionEvaluator]> { throw Error('Symbol.iterator function not implemented'); } diff --git a/libraries/adaptive-expressions/src/functionUtils.ts b/libraries/adaptive-expressions/src/functionUtils.ts index 9213f064a4..c2a6090652 100644 --- a/libraries/adaptive-expressions/src/functionUtils.ts +++ b/libraries/adaptive-expressions/src/functionUtils.ts @@ -14,8 +14,7 @@ import { ExpressionType } from './expressionType'; import { MemoryInterface } from './memory'; import { Options } from './options'; import { ReturnType } from './returnType'; -// eslint-disable-next-line lodash/import-scope -import isEqual from 'lodash.isequal'; +import isEqual from 'lodash/isEqual'; /** * Verify the result of an expression is of the appropriate type and return a string if not. diff --git a/libraries/adaptive-expressions/tests/tsconfig.json b/libraries/adaptive-expressions/tests/tsconfig.json index 4d27d04e42..6b87cb9d93 100644 --- a/libraries/adaptive-expressions/tests/tsconfig.json +++ b/libraries/adaptive-expressions/tests/tsconfig.json @@ -6,5 +6,8 @@ "declarationMap": false, "sourceMap": false }, - "include": ["*.ts"] + "include": [ + "*.ts", + "../types/**/*" + ] } \ No newline at end of file diff --git a/libraries/adaptive-expressions/tsconfig.json b/libraries/adaptive-expressions/tsconfig.json index 5e771ebffe..8bde469752 100644 --- a/libraries/adaptive-expressions/tsconfig.json +++ b/libraries/adaptive-expressions/tsconfig.json @@ -8,6 +8,7 @@ "rootDir": "src" }, "include": [ - "src/**/*" + "src/**/*", + "types/**/*" ] } \ No newline at end of file diff --git a/libraries/adaptive-expressions/types/ts5.6/lib/index.d.ts b/libraries/adaptive-expressions/types/ts5.6/lib/index.d.ts new file mode 100644 index 0000000000..8e6d4c5f51 --- /dev/null +++ b/libraries/adaptive-expressions/types/ts5.6/lib/index.d.ts @@ -0,0 +1,14 @@ +/** + * @module adaptive-expressions + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +declare global { + interface MapIterator extends IterableIterator {} +} + +// @ts-ignore - the following export is only required for projects referencing adaptive-expressions, otherwise it will fail at build time. +export * from '../../../lib'; diff --git a/testing/consumer-test/run.ts b/testing/consumer-test/run.ts index 1b7f4926a0..52a915a3ff 100644 --- a/testing/consumer-test/run.ts +++ b/testing/consumer-test/run.ts @@ -5,23 +5,28 @@ import { promisify } from 'util'; const execp = promisify(exec); -const versions = ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5']; +const versions = ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6']; (async () => { const flags = minimist(process.argv.slice(2), { - boolean: ['versbose'], + boolean: ['verbose'], alias: { v: 'verbose' }, }); try { - console.log(`Running typescript consumer test against ["${versions.join('", "')}"]`); + const [minTarget, maxTarget] = ['es6', 'esnext']; + console.log( + `Running typescript consumer test against ["${versions.join( + '", "' + )}"] with '${minTarget}' and '${maxTarget}' targets.` + ); const results = await pmap( versions, (version) => Promise.all([ - execp(`npx -p typescript@${version} tsc -p tsconfig-test.json`), - execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --lib es2018`), + execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --target ${minTarget}`), + execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --target ${maxTarget}`), ]) .then(() => ({ err: null, version, success: true })) .catch((err) => ({ err, version, success: false })), diff --git a/yarn.lock b/yarn.lock index cc673fa241..484bdd7974 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3050,18 +3050,6 @@ resolved "https://registry.yarnpkg.com/@types/jspath/-/jspath-0.4.2.tgz#c51f930d5428a786da9c12a6e0077b1f9d148c3c" integrity sha512-NltGdfyWyW36ZToRhwuQhzRRKuw29NSaMEwTZ4eGFlS49ZzbZ4fDXTC+JfTpSVSUy6ru+fR+nXypWSkKVE5zMQ== -"@types/lodash.isequal@^4.5.8": - version "4.5.8" - resolved "https://registry.yarnpkg.com/@types/lodash.isequal/-/lodash.isequal-4.5.8.tgz#b30bb6ff6a5f6c19b3daf389d649ac7f7a250499" - integrity sha512-uput6pg4E/tj2LGxCZo9+y27JNyB2OZuuI/T5F+ylVDYuqICLG2/ktjxx0v6GvVntAf8TvEzeQLcV0ffRirXuA== - dependencies: - "@types/lodash" "*" - -"@types/lodash@*": - version "4.14.168" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008" - integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q== - "@types/lodash@^4.17.7": version "4.17.7" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.7.tgz#2f776bcb53adc9e13b2c0dfd493dfcbd7de43612"