Skip to content

Commit 3f9e6d5

Browse files
committed
move tooling into separate repo, add type generation and test types
1 parent 04e43c0 commit 3f9e6d5

File tree

36 files changed

+10143
-1323
lines changed

36 files changed

+10143
-1323
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package.json
2+
13
# Ignore test fixtures
24
test/*.*
35
!test/*.js

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ module.exports = {
88
{
99
files: "*.json",
1010
options: {
11+
parser: "json",
1112
useTabs: false
1213
}
14+
},
15+
{
16+
files: "*.ts",
17+
options: {
18+
parser: "typescript"
19+
}
1320
}
1421
]
1522
};

declarations.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,8 @@ declare module "enhanced-resolve" {
385385
}
386386

387387
type TODO = any;
388+
389+
type RecursiveArrayOrRecord<T> =
390+
| { [index: string]: RecursiveArrayOrRecord<T> }
391+
| Array<RecursiveArrayOrRecord<T>>
392+
| T;

declarations/WebpackOptions.d.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ export type Bail = boolean;
1919
/**
2020
* Cache generated modules and chunks to improve performance for multiple incremental builds.
2121
*/
22-
export type Cache = true | CacheNormalized;
22+
export type CacheOptions = true | CacheOptionsNormalized;
2323
/**
2424
* Cache generated modules and chunks to improve performance for multiple incremental builds.
2525
*/
26-
export type CacheNormalized = false | MemoryCacheOptions | FileCacheOptions;
26+
export type CacheOptionsNormalized =
27+
| false
28+
| MemoryCacheOptions
29+
| FileCacheOptions;
2730
/**
2831
* The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.
2932
*/
@@ -489,7 +492,7 @@ export type ResolveLoader = ResolveOptions;
489492
/**
490493
* Stats options object or preset name.
491494
*/
492-
export type Stats =
495+
export type StatsValue =
493496
| (
494497
| "none"
495498
| "errors-only"
@@ -555,7 +558,7 @@ export interface WebpackOptions {
555558
/**
556559
* Cache generated modules and chunks to improve performance for multiple incremental builds.
557560
*/
558-
cache?: Cache;
561+
cache?: CacheOptions;
559562
/**
560563
* The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.
561564
*/
@@ -603,7 +606,7 @@ export interface WebpackOptions {
603606
/**
604607
* Options affecting the normal modules (`NormalModuleFactory`).
605608
*/
606-
module?: Module;
609+
module?: ModuleOptions;
607610
/**
608611
* Name of the configuration. Used when loading multiple configurations.
609612
*/
@@ -659,7 +662,7 @@ export interface WebpackOptions {
659662
/**
660663
* Stats options object or preset name.
661664
*/
662-
stats?: Stats;
665+
stats?: StatsValue;
663666
/**
664667
* Environment to build for.
665668
*/
@@ -906,7 +909,7 @@ export interface Loader {
906909
/**
907910
* Options affecting the normal modules (`NormalModuleFactory`).
908911
*/
909-
export interface Module {
912+
export interface ModuleOptions {
910913
/**
911914
* An array of rules applied by default for modules.
912915
*/
@@ -2096,7 +2099,7 @@ export interface WebpackOptionsNormalized {
20962099
/**
20972100
* Cache generated modules and chunks to improve performance for multiple incremental builds.
20982101
*/
2099-
cache: CacheNormalized;
2102+
cache: CacheOptionsNormalized;
21002103
/**
21012104
* The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.
21022105
*/
@@ -2144,7 +2147,7 @@ export interface WebpackOptionsNormalized {
21442147
/**
21452148
* Options affecting the normal modules (`NormalModuleFactory`).
21462149
*/
2147-
module: Module;
2150+
module: ModuleOptions;
21482151
/**
21492152
* Name of the configuration. Used when loading multiple configurations.
21502153
*/
@@ -2196,7 +2199,7 @@ export interface WebpackOptionsNormalized {
21962199
/**
21972200
* Stats options object or preset name.
21982201
*/
2199-
stats: Stats;
2202+
stats: StatsValue;
22002203
/**
22012204
* Environment to build for.
22022205
*/

generate-types-config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
nameMapping: {
3+
FsStats: /^Stats Import fs/
4+
}
5+
};

lib/DefinePlugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const {
1616

1717
/** @typedef {import("./Compiler")} Compiler */
1818
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19-
/** @typedef {null|undefined|RegExp|Function|string|number} CodeValuePrimitive */
20-
/** @typedef {CodeValuePrimitive|Record<string, CodeValuePrimitive>|RuntimeValue} CodeValue */
19+
/** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */
20+
/** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive|RuntimeValue>} CodeValue */
2121

2222
class RuntimeValue {
2323
constructor(fn, fileDependencies) {

lib/cli.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
1515
* @property {string} path the path in the config
1616
*/
1717

18+
/** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "multiple-values-unexpected" | "invalid-value"} ProblemType */
19+
1820
/**
1921
* @typedef {Object} Problem
20-
* @property {string} type
22+
* @property {ProblemType} type
2123
* @property {string} path
2224
* @property {string} argument
2325
* @property {any=} value
@@ -27,7 +29,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
2729

2830
/**
2931
* @typedef {Object} LocalProblem
30-
* @property {string} type
32+
* @property {ProblemType} type
3133
* @property {string} path
3234
* @property {string=} expected
3335
*/
@@ -563,7 +565,7 @@ const parseValueForArgumentConfig = (argConfig, value) => {
563565
/**
564566
* @param {Record<string, Argument>} args object of arguments
565567
* @param {any} config configuration
566-
* @param {Record<string, string | number | boolean | RegExp>} values object with values
568+
* @param {Record<string, string | number | boolean | RegExp | (string | number | boolean | RegExp)[]>} values object with values
567569
* @returns {Problem[] | null} problems or null for success
568570
*/
569571
const processArguments = (args, config, values) => {

lib/config/defaults.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
const path = require("path");
99
const Template = require("../Template");
1010

11-
/** @typedef {import("../../declarations/WebpackOptions").CacheNormalized} WebpackCache */
11+
/** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
1212
/** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
1313
/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
1414
/** @typedef {import("../../declarations/WebpackOptions").Library} Library */
1515
/** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
1616
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
17-
/** @typedef {import("../../declarations/WebpackOptions").Module} WebpackModule */
17+
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
1818
/** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
1919
/** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
2020
/** @typedef {import("../../declarations/WebpackOptions").Output} Output */
@@ -178,7 +178,7 @@ const applyExperimentsDefaults = experiments => {
178178
};
179179

180180
/**
181-
* @param {WebpackCache} cache options
181+
* @param {CacheOptions} cache options
182182
* @param {Object} options options
183183
* @param {string} options.name name
184184
* @param {string} options.mode mode
@@ -256,7 +256,7 @@ const applyCacheDefaults = (cache, { name, mode }) => {
256256
};
257257

258258
/**
259-
* @param {WebpackModule} module options
259+
* @param {ModuleOptions} module options
260260
* @param {Object} options options
261261
* @param {boolean} options.cache is caching enabled
262262
* @param {boolean} options.mjs is mjs enabled

lib/dependencies/AMDPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const ConstDependency = require("./ConstDependency");
2828
const LocalModuleDependency = require("./LocalModuleDependency");
2929
const UnsupportedDependency = require("./UnsupportedDependency");
3030

31-
/** @typedef {import("../../declarations/WebpackOptions").Module} ModuleOptions */
31+
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
3232
/** @typedef {import("../Compiler")} Compiler */
3333

3434
class AMDPlugin {

0 commit comments

Comments
 (0)