Skip to content

Commit b3e380c

Browse files
authored
Eliminate workarounds for @types/z-schema
We submitted an [upstream fix](DefinitelyTyped/DefinitelyTyped#14005) to DefinitelyTyped that adds the definitions that we rely on for schema validation. This PR updates **web-build-tools** to use it.
2 parents 20da9af + eca1c07 commit b3e380c

20 files changed

Lines changed: 87 additions & 109 deletions

File tree

api-extractor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@types/es6-collections": "^0.5.29",
2323
"@types/fs-extra": "~0.0.34",
2424
"@types/node": ">=6.0.51 <6.9.1",
25-
"@types/z-schema": "3.16.20-alpha",
25+
"@types/z-schema": "~3.16.31",
2626
"fs-extra": "~0.26.0",
2727
"jju": "~1.3.0",
2828
"typescript": "~2.1.0",

api-extractor/src/JsonFile.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@ import * as os from 'os';
33
import * as jju from 'jju';
44
import Validator = require('z-schema');
55

6-
export type ValidateErrorCallback = (errorDetail: string) => void;
7-
8-
interface ISchemaError extends ZSchema.SchemaError {
9-
// Ex. "z-schema validation error"
10-
name: string;
11-
details: Array<IErrorDetail>;
12-
}
13-
14-
interface IErrorDetail extends ZSchema.SchemaError {
15-
inner?: IErrorDetail[];
16-
}
6+
export type ValidateErrorCallback = (errorDescription: string) => void;
177

188
/**
199
* Utilities for reading/writing JSON files.
@@ -30,18 +20,18 @@ export default class JsonFile {
3020
// tslint:disable-next-line:no-string-literal
3121
delete jsonSchemaObject['$schema'];
3222

33-
const validator: ZSchema.Validator = new Validator({
23+
const validator: Validator = new Validator({
3424
breakOnFirstError: false,
3525
noTypeless: true
3626
});
3727

3828
if (!validator.validate(jsonObject, jsonSchemaObject)) {
39-
const error: ISchemaError = validator.getLastError() as ISchemaError;
29+
const errorDetails: Validator.SchemaErrorDetail[] = validator.getLastErrors();
4030

41-
let errorDetail: string = 'JSON schema validation failed:';
31+
let buffer: string = 'JSON schema validation failed:';
4232

43-
errorDetail = JsonFile._formatErrorDetails(error.details, ' ', errorDetail);
44-
errorCallback(errorDetail);
33+
buffer = JsonFile._formatErrorDetails(errorDetails, ' ', buffer);
34+
errorCallback(buffer);
4535
}
4636
}
4737

@@ -87,18 +77,17 @@ export default class JsonFile {
8777

8878
}
8979

90-
private static _formatErrorDetails(errorDetails: IErrorDetail[], indent: string,
91-
result: string): string {
92-
for (const detail of errorDetails) {
93-
result += os.EOL + indent + `Error: ${detail.path}`;
94-
// result += os.EOL + indent + ` ${detail.code}`;
95-
result += os.EOL + indent + ` ${detail.message}`;
80+
private static _formatErrorDetails(errorDetails: Validator.SchemaErrorDetail[], indent: string,
81+
buffer: string): string {
82+
for (const errorDetail of errorDetails) {
83+
buffer += os.EOL + indent + `Error: ${errorDetail.path}`;
84+
buffer += os.EOL + indent + ` ${errorDetail.message}`;
9685

97-
if (detail.inner) {
98-
result = JsonFile._formatErrorDetails(detail.inner, indent + ' ', result);
86+
if (errorDetail.inner) {
87+
buffer = JsonFile._formatErrorDetails(errorDetail.inner, indent + ' ', buffer);
9988
}
10089
}
101-
return result;
90+
return buffer;
10291
}
10392

10493
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "",
5+
"packageName": "@microsoft/gulp-core-build",
6+
"type": "none"
7+
},
8+
{
9+
"comment": "",
10+
"packageName": "@microsoft/api-extractor",
11+
"type": "none"
12+
}
13+
],
14+
"email": "pgonzal"
15+
}

common/npm-shrinkwrap.json

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

common/reviews/api/gulp-core-build.api.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ interface IExecutable {
120120

121121
export function initialize(gulp: gulp.Gulp): void;
122122

123-
// (undocumented)
124-
interface ISchemaValidatorResult {
125-
// (undocumented)
126-
details?: ZSchema.SchemaError[];
127-
// (undocumented)
128-
message?: string;
129-
// (undocumented)
130-
name?: string;
131-
}
132-
133123
export function logSummary(value: string): void;
134124

135125
export function mergeConfig(config: IBuildConfig): void;
@@ -143,7 +133,7 @@ export function reset(): void;
143133

144134
class SchemaValidator {
145135
// (undocumented)
146-
public static getFormattedErrorMessage(error: ISchemaValidatorResult, dataFilePath?: string): string;
136+
public static getFormattedErrorMessage(errors: Validator.SchemaErrorDetail[], dataFilePath?: string): string;
147137
public static readAndValidateJson < TResult >(dataFilePath: string, schemaFilePath: string): TResult;
148138
// (undocumented)
149139
public static readCommentedJsonFile < TResult >(filename: string): TResult;

common/reviews/api/node-library-build.api.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,6 @@ interface IExecutable {
129129

130130
export declare function initialize(gulp: gulp.Gulp): void;
131131

132-
// (undocumented)
133-
interface ISchemaValidatorResult {
134-
// (undocumented)
135-
details?: ZSchema.SchemaError[];
136-
// (undocumented)
137-
message?: string;
138-
// (undocumented)
139-
name?: string;
140-
}
141-
142132
// (undocumented)
143133
interface ITsConfigFile<T> {
144134
// (undocumented)
@@ -158,7 +148,7 @@ export declare function reset(): void;
158148

159149
class SchemaValidator {
160150
// (undocumented)
161-
static getFormattedErrorMessage(error: ISchemaValidatorResult, dataFilePath?: string): string;
151+
static getFormattedErrorMessage(errors: Validator.SchemaErrorDetail[], dataFilePath?: string): string;
162152
static readAndValidateJson < TResult >(dataFilePath: string, schemaFilePath: string): TResult;
163153
// (undocumented)
164154
static readCommentedJsonFile < TResult >(filename: string): TResult;

common/reviews/api/web-library-build.api.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,6 @@ interface IExecutable {
129129

130130
export declare function initialize(gulp: gulp.Gulp): void;
131131

132-
// (undocumented)
133-
interface ISchemaValidatorResult {
134-
// (undocumented)
135-
details?: ZSchema.SchemaError[];
136-
// (undocumented)
137-
message?: string;
138-
// (undocumented)
139-
name?: string;
140-
}
141-
142132
// (undocumented)
143133
interface ITsConfigFile<T> {
144134
// (undocumented)
@@ -166,7 +156,7 @@ export declare function reset(): void;
166156

167157
class SchemaValidator {
168158
// (undocumented)
169-
static getFormattedErrorMessage(error: ISchemaValidatorResult, dataFilePath?: string): string;
159+
static getFormattedErrorMessage(errors: Validator.SchemaErrorDetail[], dataFilePath?: string): string;
170160
static readAndValidateJson < TResult >(dataFilePath: string, schemaFilePath: string): TResult;
171161
// (undocumented)
172162
static readCommentedJsonFile < TResult >(filename: string): TResult;

common/temp_modules/rush-api-extractor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"chai": "~3.5.0",
99
"gulp": "~3.9.1",
1010
"mocha": "~2.5.3",
11-
"@microsoft/node-library-build": "~2.1.0",
11+
"@microsoft/node-library-build": "~2.2.0",
1212
"@types/es6-collections": "^0.5.29",
1313
"@types/fs-extra": "~0.0.34",
1414
"@types/node": ">=6.0.51 <6.9.1",
15-
"@types/z-schema": "3.16.20-alpha",
15+
"@types/z-schema": "~3.16.31",
1616
"fs-extra": "~0.26.0",
1717
"jju": "~1.3.0",
1818
"typescript": "~2.1.0",

common/temp_modules/rush-gulp-core-build-karma/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"private": true,
55
"dependencies": {
6-
"@microsoft/node-library-build": ">=2.1.0 <3.0.0",
6+
"@microsoft/node-library-build": ">=2.2.0 <3.0.0",
77
"@types/chalk": "^0.4.31",
88
"@types/es6-promise": "0.0.32",
99
"@types/gulp": "^3.8.32",

common/temp_modules/rush-gulp-core-build-mocha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"private": true,
55
"dependencies": {
6-
"@microsoft/node-library-build": ">=2.1.0 <3.0.0",
6+
"@microsoft/node-library-build": ">=2.2.0 <3.0.0",
77
"@types/chalk": "^0.4.31",
88
"@types/gulp": "^3.8.32",
99
"@types/gulp-istanbul": "^0.9.30",

0 commit comments

Comments
 (0)