Skip to content

Commit 0300111

Browse files
committed
refactor, rename, extend, fix, add tests
1 parent e095f51 commit 0300111

9 files changed

+247
-166
lines changed

client-types/hot.ts

-72
This file was deleted.

client-types/index.d.ts

-65
This file was deleted.

module.d.ts

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
declare namespace webpack {
2+
type HotEvent =
3+
| {
4+
type: "disposed";
5+
/** The module in question. */
6+
moduleId: number;
7+
}
8+
| {
9+
type: "self-declined" | "unaccepted";
10+
/** The module in question. */
11+
moduleId: number;
12+
/** the chain from where the update was propagated. */
13+
chain: number[];
14+
}
15+
| {
16+
type: "declined";
17+
/** The module in question. */
18+
moduleId: number;
19+
/** the chain from where the update was propagated. */
20+
chain: number[];
21+
/** the module id of the declining parent */
22+
parentId: number;
23+
}
24+
| {
25+
type: "accepted";
26+
/** The module in question. */
27+
moduleId: number;
28+
/** the chain from where the update was propagated. */
29+
chain: number[];
30+
/** the modules that are outdated and will be disposed */
31+
outdatedModules: number[];
32+
/** the accepted dependencies that are outdated */
33+
outdatedDependencies: {
34+
[id: number]: number[];
35+
};
36+
}
37+
| {
38+
type: "accept-error-handler-errored";
39+
/** The module in question. */
40+
moduleId: number;
41+
/** the module id owning the accept handler. */
42+
dependencyId: number;
43+
/** the thrown error */
44+
error: Error;
45+
/** the error thrown by the module before the error handler tried to handle it. */
46+
originalError: Error;
47+
}
48+
| {
49+
type: "self-accept-error-handler-errored";
50+
/** The module in question. */
51+
moduleId: number;
52+
/** the thrown error */
53+
error: Error;
54+
/** the error thrown by the module before the error handler tried to handle it. */
55+
originalError: Error;
56+
}
57+
| {
58+
type: "accept-errored";
59+
/** The module in question. */
60+
moduleId: number;
61+
/** the module id owning the accept handler. */
62+
dependencyId: number;
63+
/** the thrown error */
64+
error: Error;
65+
}
66+
| {
67+
type: "self-accept-errored";
68+
/** The module in question. */
69+
moduleId: number;
70+
/** the thrown error */
71+
error: Error;
72+
};
73+
74+
interface ApplyOptions {
75+
ignoreUnaccepted?: boolean;
76+
ignoreDeclined?: boolean;
77+
ignoreErrored?: boolean;
78+
onDeclined?(callback: (info: HotEvent) => void): void;
79+
onUnaccepted?(callback: (info: HotEvent) => void): void;
80+
onAccepted?(callback: (info: HotEvent) => void): void;
81+
onDisposed?(callback: (info: HotEvent) => void): void;
82+
onErrored?(callback: (info: HotEvent) => void): void;
83+
}
84+
85+
const enum HotUpdateStatus {
86+
idle = "idle",
87+
check = "check",
88+
prepare = "prepare",
89+
ready = "ready",
90+
dispose = "dispose",
91+
apply = "apply",
92+
abort = "abort",
93+
fail = "fail"
94+
}
95+
96+
interface Hot {
97+
accept: {
98+
(
99+
modules: string | string[],
100+
callback?: (outdatedDependencies: string[]) => void,
101+
errorHandler?: (
102+
err: Error,
103+
context: { moduleId: string | number; dependencyId: string | number }
104+
) => void
105+
): void;
106+
(
107+
errorHandler: (
108+
err: Error,
109+
ids: { moduleId: string | number; module: NodeJS.Module }
110+
) => void
111+
): void;
112+
};
113+
status(): HotUpdateStatus;
114+
decline(module?: string | string[]): void;
115+
dispose(callback: (data: object) => void): void;
116+
addDisposeHandler(callback: (data: object) => void): void;
117+
removeDisposeHandler(callback: (data: object) => void): void;
118+
invalidate(): void;
119+
addStatusHandler(callback: (status: HotUpdateStatus) => void): void;
120+
removeStatusHandler(callback: (status: HotUpdateStatus) => void): void;
121+
data: object;
122+
check(
123+
autoApply?: boolean | ApplyOptions
124+
): Promise<(string | number)[] | null>;
125+
apply(options?: ApplyOptions): Promise<(string | number)[] | null>;
126+
}
127+
128+
interface ExportInfo {
129+
used: boolean;
130+
provideInfo: boolean | null | undefined;
131+
useInfo: boolean | null | undefined;
132+
}
133+
134+
interface ExportsInfo {
135+
[k: string]: ExportInfo & ExportsInfo;
136+
}
137+
138+
interface Context {
139+
resolve(dependency: string): string | number;
140+
keys(): Array<string>;
141+
id: string | number;
142+
(dependency: string): unknown;
143+
}
144+
}
145+
146+
interface ImportMeta {
147+
url: string;
148+
webpack: number;
149+
webpackHot: webpack.Hot;
150+
}
151+
152+
declare const __resourceQuery: string;
153+
declare var __webpack_public_path__: string;
154+
declare var __webpack_nonce__: string;
155+
declare const __webpack_chunkname__: string;
156+
declare var __webpack_base_uri__: string;
157+
declare var __webpack_runtime_id__: string;
158+
declare const __webpack_hash__: string;
159+
declare const __webpack_modules__: Record<string | number, NodeJS.Module>;
160+
declare const __webpack_require__: (id: string | number) => unknown;
161+
declare var __webpack_chunk_load__: (chunkId: string | number) => Promise<void>;
162+
declare var __webpack_get_script_filename__: (
163+
chunkId: string | number
164+
) => string;
165+
declare var __webpack_is_included__: (request: string) => boolean;
166+
declare var __webpack_exports_info__: webpack.ExportsInfo;
167+
declare const __webpack_share_scopes__: Record<
168+
string,
169+
Record<
170+
string,
171+
{ loaded?: 1; get: () => Promise<unknown>; from: string; eager: boolean }
172+
>
173+
>;
174+
declare var __webpack_init_sharing__: (scope: string) => Promise<void>;
175+
declare var __non_webpack_require__: (id: any) => unknown;
176+
declare const __system_context__: object;
177+
178+
declare namespace NodeJS {
179+
interface Module {
180+
hot: webpack.Hot;
181+
}
182+
183+
interface Require {
184+
ensure(
185+
dependencies: string[],
186+
callback: (require: (module: string) => void) => void,
187+
errorCallback?: (error: Error) => void,
188+
chunkName?: string
189+
): void;
190+
context(
191+
request: string,
192+
includeSubdirectories?: boolean,
193+
filter?: RegExp,
194+
mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once"
195+
): webpack.Context;
196+
include(dependency: string): void;
197+
resolveWeak(dependency: string): void;
198+
onError?: (error: Error) => void;
199+
}
200+
}

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
"bin/",
132132
"hot/",
133133
"schemas/",
134-
"client-types/",
135134
"SECURITY.md",
135+
"module.d.ts",
136136
"types.d.ts"
137137
],
138138
"scripts": {
@@ -154,17 +154,18 @@
154154
"type-report": "rimraf coverage && yarn cover:types && yarn cover:report && open-cli coverage/lcov-report/index.html",
155155
"pretest": "yarn lint",
156156
"prelint": "yarn setup",
157-
"lint": "yarn code-lint && yarn special-lint && yarn type-lint && yarn typings-lint && yarn yarn-lint && yarn pretty-lint && yarn spellcheck",
157+
"lint": "yarn code-lint && yarn special-lint && yarn type-lint && yarn typings-test && yarn module-typings-test && yarn yarn-lint && yarn pretty-lint && yarn spellcheck",
158158
"code-lint": "eslint . --ext '.js' --cache",
159159
"type-lint": "tsc",
160-
"typings-lint": "tsc -p tsconfig.test.json && tsc -p tsconfig.test.esm.json",
160+
"typings-test": "tsc -p tsconfig.types.test.json",
161+
"module-typings-test": "tsc -p tsconfig.module.test.json",
161162
"spellcheck": "cspell \"{.github,benchmark,bin,examples,hot,lib,schemas,setup,tooling}/**/*.{md,yml,yaml,js,json}\" \"*.md\"",
162163
"special-lint": "node node_modules/tooling/lockfile-lint && node node_modules/tooling/schemas-lint && node node_modules/tooling/inherit-types && node node_modules/tooling/format-schemas && node tooling/generate-runtime-code.js && node tooling/generate-wasm-code.js && node node_modules/tooling/format-file-header && node node_modules/tooling/compile-to-definitions && node node_modules/tooling/precompile-schemas && node node_modules/tooling/generate-types --no-template-literals",
163164
"special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-schemas --write && node tooling/generate-runtime-code.js --write && node tooling/generate-wasm-code.js --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/compile-to-definitions --write && node node_modules/tooling/precompile-schemas --write && node node_modules/tooling/generate-types --no-template-literals --write",
164165
"fix": "yarn code-lint --fix && yarn special-lint-fix && yarn pretty-lint-fix",
165166
"prepare": "husky install",
166167
"pretty-lint-base": "prettier \"*.{ts,json,yml,yaml,md}\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.json\" \"examples/*.md\"",
167-
"pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"client-types/*.ts\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
168+
"pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"module.d.ts\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
168169
"pretty-lint-fix": "yarn pretty-lint-base-all --loglevel warn --write",
169170
"pretty-lint": "yarn pretty-lint-base --check",
170171
"yarn-lint": "yarn-deduplicate --fail --list -s highest yarn.lock",

0 commit comments

Comments
 (0)