From 8c31f2a7080fc7b07c4743ba6784e7f57f207c2f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 21 Sep 2018 08:39:15 +0200 Subject: [PATCH] fixes for RegExp in schema --- declarations/WebpackOptions.d.ts | 54 ++++--------------- declarations/plugins/BannerPlugin.d.ts | 6 +-- declarations/plugins/IgnorePlugin.d.ts | 8 +-- .../plugins/SourceMapDevToolPlugin.d.ts | 6 +-- package.json | 2 +- schemas/WebpackOptions.json | 30 +++++++---- schemas/plugins/BannerPlugin.json | 3 +- schemas/plugins/IgnorePlugin.json | 6 ++- schemas/plugins/SourceMapDevToolPlugin.json | 3 +- test/Schemas.lint.js | 10 +++- yarn.lock | 6 +-- 11 files changed, 55 insertions(+), 79 deletions(-) diff --git a/declarations/WebpackOptions.d.ts b/declarations/WebpackOptions.d.ts index 7ad48adb9c4..4e218ee2741 100644 --- a/declarations/WebpackOptions.d.ts +++ b/declarations/WebpackOptions.d.ts @@ -67,9 +67,7 @@ export type ExternalItem = | ArrayOfStringValues | boolean; } - | { - [k: string]: any; - }; + | RegExp; /** * This interface was referenced by `WebpackOptions`'s JSON-Schema * via the `definition` "ArrayOfStringValues". @@ -87,11 +85,10 @@ export type RuleSetConditionOrConditions = RuleSetCondition | RuleSetConditions; * via the `definition` "RuleSetCondition". */ export type RuleSetCondition = - | { - [k: string]: any; - } + | RegExp | string | Function + | RuleSetConditions | { /** * Logical AND @@ -195,12 +192,7 @@ export type FilterTypes = FilterItemTypes | FilterItemTypes[]; * This interface was referenced by `WebpackOptions`'s JSON-Schema * via the `definition` "FilterItemTypes". */ -export type FilterItemTypes = - | { - [k: string]: any; - } - | string - | Function; +export type FilterItemTypes = RegExp | string | Function; export interface WebpackOptions { /** @@ -399,11 +391,7 @@ export interface ModuleOptions { /** * Sets the default regular expression for full dynamic dependencies */ - exprContextRegExp?: - | boolean - | { - [k: string]: any; - }; + exprContextRegExp?: boolean | RegExp; /** * Set the default request for full dynamic dependencies */ @@ -411,16 +399,7 @@ export interface ModuleOptions { /** * Don't parse files matching. It's matched against the full resolved request. */ - noParse?: - | { - [k: string]: any; - }[] - | { - [k: string]: any; - } - | Function - | string[] - | string; + noParse?: RegExp[] | RegExp | Function | string[] | string; /** * An array of rules applied for modules. */ @@ -444,11 +423,7 @@ export interface ModuleOptions { /** * Sets the regular expression when using the require function in a not statically analyse-able way */ - unknownContextRegExp?: - | boolean - | { - [k: string]: any; - }; + unknownContextRegExp?: boolean | RegExp; /** * Sets the request when using the require function in a not statically analyse-able way */ @@ -468,9 +443,7 @@ export interface ModuleOptions { /** * Set the inner regular expression for partial dynamic dependencies */ - wrappedContextRegExp?: { - [k: string]: any; - }; + wrappedContextRegExp?: RegExp; } /** * This interface was referenced by `WebpackOptions`'s JSON-Schema @@ -856,9 +829,7 @@ export interface OptimizationSplitChunksOptions { | false | Function | string - | { - [k: string]: any; - } + | RegExp | { /** * Sets the name delimiter for created chunks @@ -915,12 +886,7 @@ export interface OptimizationSplitChunksOptions { /** * Assign modules to a cache group */ - test?: - | Function - | string - | { - [k: string]: any; - }; + test?: Function | string | RegExp; }; }; /** diff --git a/declarations/plugins/BannerPlugin.d.ts b/declarations/plugins/BannerPlugin.d.ts index d27bd6230e0..4b3810596e4 100644 --- a/declarations/plugins/BannerPlugin.d.ts +++ b/declarations/plugins/BannerPlugin.d.ts @@ -21,11 +21,7 @@ export type BannerFunction = ( } ) => string; export type Rules = Rule[] | Rule; -export type Rule = - | { - [k: string]: any; - } - | string; +export type Rule = RegExp | string; export interface BannerPluginOptions { /** diff --git a/declarations/plugins/IgnorePlugin.d.ts b/declarations/plugins/IgnorePlugin.d.ts index 2aaf5061ce6..01ac08139fb 100644 --- a/declarations/plugins/IgnorePlugin.d.ts +++ b/declarations/plugins/IgnorePlugin.d.ts @@ -9,15 +9,11 @@ export type IgnorePluginOptions = /** * A RegExp to test the context (directory) against */ - contextRegExp?: { - [k: string]: any; - }; + contextRegExp?: RegExp; /** * A RegExp to test the request against */ - resourceRegExp?: { - [k: string]: any; - }; + resourceRegExp?: RegExp; } | { /** diff --git a/declarations/plugins/SourceMapDevToolPlugin.d.ts b/declarations/plugins/SourceMapDevToolPlugin.d.ts index cff6446ca95..76421b508e5 100644 --- a/declarations/plugins/SourceMapDevToolPlugin.d.ts +++ b/declarations/plugins/SourceMapDevToolPlugin.d.ts @@ -13,11 +13,7 @@ export type Rules = Rule[] | Rule; * This interface was referenced by `SourceMapDevToolPluginOptions`'s JSON-Schema * via the `definition` "rule". */ -export type Rule = - | { - [k: string]: any; - } - | string; +export type Rule = RegExp | string; export interface SourceMapDevToolPluginOptions { /** diff --git a/package.json b/package.json index f91dab30812..bf0d35c0724 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "enhanced-resolve": "^4.1.0", "eslint-scope": "^4.0.0", "json-parse-better-errors": "^1.0.2", - "json-schema-to-typescript": "^5.7.0", + "json-schema-to-typescript": "^6.0.1", "loader-runner": "^2.3.0", "loader-utils": "^1.1.0", "memory-fs": "~0.4.1", diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index 1c7c376c9b5..0aa38261fae 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -122,7 +122,8 @@ }, { "description": "Every matched dependency becomes external.", - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } ] }, @@ -157,7 +158,8 @@ "FilterItemTypes": { "anyOf": [ { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "type": "string" @@ -238,7 +240,8 @@ "type": "boolean" }, { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } ] }, @@ -253,12 +256,14 @@ "type": "array", "items": { "description": "A regular expression, when matched the module is not parsed", - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, "minItems": 1 }, { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "instanceof": "Function", @@ -310,7 +315,8 @@ "type": "boolean" }, { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } ] }, @@ -340,7 +346,8 @@ }, "wrappedContextRegExp": { "description": "Set the inner regular expression for partial dynamic dependencies", - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } } }, @@ -562,7 +569,8 @@ "type": "string" }, { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "type": "object", @@ -657,7 +665,8 @@ "type": "string" }, { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } ] } @@ -1204,7 +1213,8 @@ "RuleSetCondition": { "anyOf": [ { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "type": "string", diff --git a/schemas/plugins/BannerPlugin.json b/schemas/plugins/BannerPlugin.json index 555e29ed7a2..af313b90dee 100644 --- a/schemas/plugins/BannerPlugin.json +++ b/schemas/plugins/BannerPlugin.json @@ -8,7 +8,8 @@ "Rule": { "oneOf": [ { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "type": "string", diff --git a/schemas/plugins/IgnorePlugin.json b/schemas/plugins/IgnorePlugin.json index 924073868dd..83cd78ad8f1 100644 --- a/schemas/plugins/IgnorePlugin.json +++ b/schemas/plugins/IgnorePlugin.json @@ -7,11 +7,13 @@ "properties": { "contextRegExp": { "description": "A RegExp to test the context (directory) against", - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, "resourceRegExp": { "description": "A RegExp to test the request against", - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" } } }, diff --git a/schemas/plugins/SourceMapDevToolPlugin.json b/schemas/plugins/SourceMapDevToolPlugin.json index 49ca38cf41c..dd9d3109009 100644 --- a/schemas/plugins/SourceMapDevToolPlugin.json +++ b/schemas/plugins/SourceMapDevToolPlugin.json @@ -3,7 +3,8 @@ "rule": { "oneOf": [ { - "instanceof": "RegExp" + "instanceof": "RegExp", + "tsType": "RegExp" }, { "type": "string", diff --git a/test/Schemas.lint.js b/test/Schemas.lint.js index 66503cd00e1..30fc1b52fcd 100644 --- a/test/Schemas.lint.js +++ b/test/Schemas.lint.js @@ -76,7 +76,7 @@ describe("Schemas", () => { } }); - if (Object.keys(item).indexOf("$ref") >= 0) { + if ("$ref" in item) { it("should not have other properties next to $ref", () => { const otherProperties = Object.keys(item).filter( p => p !== "$ref" @@ -91,6 +91,14 @@ describe("Schemas", () => { }); } + if ("instanceof" in item) { + it("should have tsType specified when using instanceof", () => { + if (!("tsType" in item)) { + throw new Error("When using instanceof, tsType is required"); + } + }); + } + arrayProperties.forEach(prop => { if (prop in item) { describe(prop, () => { diff --git a/yarn.lock b/yarn.lock index aa7cddfd842..3c148e95e89 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3811,9 +3811,9 @@ json-schema-ref-parser@^5.1.3: js-yaml "^3.12.0" ono "^4.0.6" -json-schema-to-typescript@^5.7.0: - version "5.7.0" - resolved "https://registry.yarnpkg.com/json-schema-to-typescript/-/json-schema-to-typescript-5.7.0.tgz#8a22356896abcf6148a4e99bacd93f0d8792befe" +json-schema-to-typescript@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/json-schema-to-typescript/-/json-schema-to-typescript-6.0.1.tgz#31baac45a124b586d4021d12a5ea0ec07fddf294" dependencies: "@types/cli-color" "^0.3.29" "@types/json-schema" "^7.0.0"