Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit bf8d2db

Browse files
Move to npm run test in vscode launch config (#1013)
* Move to npm run test in vscode launch config * Fix dialog build for non-ES friendly packages AJV v7 beta has better support for ES style import but is not a trivial upgrade to make. This commit also upgrades `tslib` across all packages to maintain consistency with latest typescript version.
1 parent 18fba61 commit bf8d2db

File tree

15 files changed

+405
-539
lines changed

15 files changed

+405
-539
lines changed

.vscode/launch.json

Lines changed: 343 additions & 383 deletions
Large diffs are not rendered by default.

common/config/rush/pnpm-lock.yaml

Lines changed: 30 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/chatdown/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"node-fetch": "~2.6.0",
2222
"please-upgrade-node": "^3.0.1",
2323
"semver": "^5.5.1",
24-
"tslib": "^1.9.3",
24+
"tslib": "^2.0.3",
2525
"window-size": "^1.1.0"
2626
},
2727
"devDependencies": {

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"is-ci":"2.0.0",
7373
"latest-version": "^4.0.0",
7474
"semver": "^5.5.1",
75-
"tslib": "^1.9.3"
75+
"tslib": "^2.0.3"
7676
},
7777
"devDependencies": {
7878
"@oclif/dev-cli": "^1.22.0",

packages/command/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"cli-ux": "~4.9.3",
3737
"debug": "^4.1.1",
3838
"fs-extra": "^7.0.1",
39-
"tslib": "~1.10.0"
39+
"tslib": "^2.0.3"
4040
},
4141
"devDependencies": {
4242
"@oclif/plugin-help": "^2.1.6",

packages/config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@oclif/errors": "~1.2.2",
4444
"cli-ux": "^5.3.0",
4545
"fs-extra": "^7.0.1",
46-
"tslib": "^1.10.0"
46+
"tslib": "^2.0.3"
4747
},
4848
"devDependencies": {
4949
"@oclif/dev-cli": "^1.22.0",

packages/dialog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"os": "~0.1.1",
5454
"path": "^0.12.7",
5555
"seedrandom": "~3.0.5",
56-
"tslib": "^1.10.0",
56+
"tslib": "^2.0.3",
5757
"xml2js": "^0.4.19",
5858
"json-ptr": "~1.3.0",
5959
"json-schema-merge-allof": "~0.7.0",

packages/dialog/src/library/dialogTracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export * from './schemaTracker';
77
import * as fs from 'fs-extra';
88
import * as path from 'path';
99
import * as st from './schemaTracker';
10-
import glob from 'globby';
1110
import parser from '@apidevtools/json-schema-ref-parser'
1211

13-
let clone = require('clone')
12+
const clone = require('clone')
13+
const glob = require('globby');
1414

1515
// Top-level dialog definition that would be found in a file.
1616
export class Dialog {

packages/dialog/src/library/schemaMerger.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import * as nuget from '@snyk/nuget-semver'
99
import * as os from 'os'
1010
import * as ppath from 'path'
1111
import * as xp from 'xml2js'
12-
import Validator from 'ajv'
13-
import glob from 'globby'
12+
import Ajv = require('ajv');
1413
import parser from '@apidevtools/json-schema-ref-parser'
1514
import {JsonPointer as ptr} from 'json-ptr'
1615

17-
let allof: any = require('json-schema-merge-allof')
18-
let clone: any = require('clone')
19-
let getUri: any = require('get-uri')
20-
let util: any = require('util')
21-
let exec: any = util.promisify(require('child_process').exec)
16+
const allof = require('json-schema-merge-allof')
17+
const clone = require('clone')
18+
const getUri = require('get-uri')
19+
const glob = require('globby')
20+
const util = require('util')
21+
22+
const exec = util.promisify(require('child_process').exec)
2223

2324
// Walk over JSON object, stopping if true from walker.
2425
// Walker gets the current value, the parent object and full path to that object
@@ -280,7 +281,7 @@ export class SchemaMerger {
280281
private readonly files: Map<string, Map<string, PathComponent[]>> = new Map<string, Map<string, PathComponent[]>>()
281282

282283
// Validator for checking schema
283-
private readonly validator = new Validator()
284+
private readonly validator = new Ajv()
284285

285286
// $schema that defines allowed component .schema
286287
private metaSchemaId = ''
@@ -784,7 +785,7 @@ export class SchemaMerger {
784785
// Validate against component schema
785786
private validateSchema(schema: any): void {
786787
if (!this.validator.validate('componentSchema', schema)) {
787-
for (let error of this.validator.errors as Validator.ErrorObject[]) {
788+
for (let error of this.validator.errors as Ajv.ErrorObject[]) {
788789
this.schemaError(error)
789790
}
790791
this.validator.errors = undefined
@@ -794,7 +795,7 @@ export class SchemaMerger {
794795
// Validate against UI schema
795796
private validateUISchema(schema: any): void {
796797
if (!this.validator.validate('UISchema', schema)) {
797-
for (let error of this.validator.errors as Validator.ErrorObject[]) {
798+
for (let error of this.validator.errors as Ajv.ErrorObject[]) {
798799
this.schemaError(error)
799800
}
800801
this.validator.errors = undefined
@@ -1717,7 +1718,7 @@ export class SchemaMerger {
17171718
}
17181719

17191720
// Error in schema validity
1720-
private schemaError(err: Validator.ErrorObject): void {
1721+
private schemaError(err: Ajv.ErrorObject): void {
17211722
this.error(`${this.currentFile}: ${err.dataPath} error: ${err.message}`)
17221723
this.failed = true
17231724
}

packages/dialog/src/library/schemaTracker.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import ajv from 'ajv';
6+
import Ajv = require('ajv')
77
import parser from '@apidevtools/json-schema-ref-parser'
88

99
let getUri: any = require('get-uri')
@@ -28,16 +28,15 @@ export class SchemaTracker {
2828
// Map from dialog path to kind.
2929
pathToKind: Map<string, string>
3030

31-
private readonly validator: ajv.Ajv
31+
private readonly validator = new Ajv({logger: false});
3232

3333
constructor() {
3434
this.kindToKind = new Map<string, Kind>()
3535
this.pathToKind = new Map<string, string>()
3636
// NOTE: This is so that ajv doesn't complain about extra keywords around $ref
37-
this.validator = new ajv({logger: false})
3837
}
3938

40-
async getValidator(schemaPath: string): Promise<[ajv.ValidateFunction, boolean]> {
39+
async getValidator(schemaPath: string): Promise<[Ajv.ValidateFunction, boolean]> {
4140
let validator = this.validator.getSchema(schemaPath)
4241
let added = false
4342
if (!validator) {
@@ -82,11 +81,15 @@ export class SchemaTracker {
8281
this.validator.addSchema(metaSchema, metaSchemaName)
8382
}
8483
this.validator.addSchema(fullSchema, schemaPath)
85-
validator = this.validator.getSchema(schemaPath) as ajv.ValidateFunction
84+
validator = this.validator.getSchema(schemaPath)
85+
if (!validator) {
86+
throw new Error(`Could not get validator for schema ${schemaPath}`)
87+
}
8688
} catch (err) {
8789
throw new Error(`Could not use schema ${schemaPath}\n${err.message}`)
8890
}
8991
}
92+
9093
return [validator, added]
9194
}
9295

0 commit comments

Comments
 (0)