Skip to content

Commit

Permalink
fixes for RegExp in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 21, 2018
1 parent 44955b7 commit 8c31f2a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 79 deletions.
54 changes: 10 additions & 44 deletions declarations/WebpackOptions.d.ts
Expand Up @@ -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".
Expand All @@ -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
Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -399,28 +391,15 @@ 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
*/
exprContextRequest?: string;
/**
* 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.
*/
Expand All @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -856,9 +829,7 @@ export interface OptimizationSplitChunksOptions {
| false
| Function
| string
| {
[k: string]: any;
}
| RegExp
| {
/**
* Sets the name delimiter for created chunks
Expand Down Expand Up @@ -915,12 +886,7 @@ export interface OptimizationSplitChunksOptions {
/**
* Assign modules to a cache group
*/
test?:
| Function
| string
| {
[k: string]: any;
};
test?: Function | string | RegExp;
};
};
/**
Expand Down
6 changes: 1 addition & 5 deletions declarations/plugins/BannerPlugin.d.ts
Expand Up @@ -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 {
/**
Expand Down
8 changes: 2 additions & 6 deletions declarations/plugins/IgnorePlugin.d.ts
Expand Up @@ -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;
}
| {
/**
Expand Down
6 changes: 1 addition & 5 deletions declarations/plugins/SourceMapDevToolPlugin.d.ts
Expand Up @@ -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 {
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
30 changes: 20 additions & 10 deletions schemas/WebpackOptions.json
Expand Up @@ -122,7 +122,8 @@
},
{
"description": "Every matched dependency becomes external.",
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
}
]
},
Expand Down Expand Up @@ -157,7 +158,8 @@
"FilterItemTypes": {
"anyOf": [
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string"
Expand Down Expand Up @@ -238,7 +240,8 @@
"type": "boolean"
},
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
}
]
},
Expand All @@ -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",
Expand Down Expand Up @@ -310,7 +315,8 @@
"type": "boolean"
},
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
}
]
},
Expand Down Expand Up @@ -340,7 +346,8 @@
},
"wrappedContextRegExp": {
"description": "Set the inner regular expression for partial dynamic dependencies",
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
}
}
},
Expand Down Expand Up @@ -562,7 +569,8 @@
"type": "string"
},
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "object",
Expand Down Expand Up @@ -657,7 +665,8 @@
"type": "string"
},
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
}
]
}
Expand Down Expand Up @@ -1204,7 +1213,8 @@
"RuleSetCondition": {
"anyOf": [
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion schemas/plugins/BannerPlugin.json
Expand Up @@ -8,7 +8,8 @@
"Rule": {
"oneOf": [
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
Expand Down
6 changes: 4 additions & 2 deletions schemas/plugins/IgnorePlugin.json
Expand Up @@ -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"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion schemas/plugins/SourceMapDevToolPlugin.json
Expand Up @@ -3,7 +3,8 @@
"rule": {
"oneOf": [
{
"instanceof": "RegExp"
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
Expand Down
10 changes: 9 additions & 1 deletion test/Schemas.lint.js
Expand Up @@ -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"
Expand All @@ -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, () => {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit 8c31f2a

Please sign in to comment.