Skip to content

Commit dde3676

Browse files
committed
fix: type error
1 parent dd0cdc1 commit dde3676

26 files changed

+212
-63
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
"tokio",
4545
"ukey",
4646
"Ukey"
47-
]
47+
],
48+
"typescript.tsdk": "node_modules/typescript/lib"
4849
}

packages/playground/cases/context/delete-file/index.test.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
import { test, expect } from "@/fixtures";
22

3-
4-
test("delete file should work", async ({ page, request, fileAction, rspack }) => {
5-
// asset page status
6-
const statusText = await page.textContent("#root");
7-
expect(statusText).toBe('__PAGE_RENDER__');
8-
// asset script content
9-
const response = await request.get(`http://localhost:${rspack.devServer.options.port}/main.js`);
10-
const bodyResponse = (await response.body()).toString();
11-
expect(bodyResponse).toContain('this is mod1');
12-
expect(bodyResponse).toContain('this is mod2');
13-
// mock file delete action
14-
fileAction.deleteFile("src/mod1.js");
15-
await rspack.waitingForHmr(async () => {
16-
// ensure page status changed
17-
const statusText = await page.textContent("#root");
18-
return statusText === "__HMR_UPDATED__";
19-
});
20-
// asset new script content
21-
const responseAfterDelete = await request.get(`http://localhost:${rspack.devServer.options.port}/main.js`);
22-
const bodyResponseAfterDelete = (await responseAfterDelete.body()).toString();
23-
expect(bodyResponseAfterDelete).not.toContain('this is mod1');
24-
expect(bodyResponseAfterDelete).toContain('this is mod2');
3+
test("delete file should work", async ({
4+
page,
5+
request,
6+
fileAction,
7+
rspack
8+
}) => {
9+
// asset page status
10+
const statusText = await page.textContent("#root");
11+
expect(statusText).toBe("__PAGE_RENDER__");
12+
// asset script content
13+
const response = await request.get(
14+
`http://localhost:${rspack.devServer.options.port}/main.js`
15+
);
16+
const bodyResponse = (await response.body()).toString();
17+
expect(bodyResponse).toContain("this is mod1");
18+
expect(bodyResponse).toContain("this is mod2");
19+
// mock file delete action
20+
fileAction.deleteFile("src/mod1.js");
21+
await rspack.waitingForHmr(async () => {
22+
// ensure page status changed
23+
const statusText = await page.textContent("#root");
24+
return statusText === "__HMR_UPDATED__";
25+
});
26+
// asset new script content
27+
const responseAfterDelete = await request.get(
28+
`http://localhost:${rspack.devServer.options.port}/main.js`
29+
);
30+
const bodyResponseAfterDelete = (await responseAfterDelete.body()).toString();
31+
expect(bodyResponseAfterDelete).not.toContain("this is mod1");
32+
expect(bodyResponseAfterDelete).toContain("this is mod2");
2533
});
26-

packages/rspack/src/ErrorHelpers.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const loaderFlag = "LOADER_EXECUTION";
1414

1515
const webpackOptionsFlag = "WEBPACK_OPTIONS";
1616

17+
// @ts-expect-error
1718
exports.cutOffByFlag = (stack, flag) => {
1819
stack = stack.split("\n");
1920
for (let i = 0; i < stack.length; i++) {
@@ -23,26 +24,31 @@ exports.cutOffByFlag = (stack, flag) => {
2324
}
2425
return stack.join("\n");
2526
};
27+
// @ts-expect-error
2628

2729
exports.cutOffLoaderExecution = stack =>
2830
exports.cutOffByFlag(stack, loaderFlag);
29-
31+
// @ts-expect-error
3032
exports.cutOffWebpackOptions = stack =>
3133
exports.cutOffByFlag(stack, webpackOptionsFlag);
3234

35+
// @ts-expect-error
3336
exports.cutOffMultilineMessage = (stack, message) => {
3437
stack = stack.split("\n");
3538
message = message.split("\n");
36-
39+
// @ts-expect-error
3740
const result = [];
3841

42+
// @ts-expect-error
3943
stack.forEach((line, idx) => {
4044
if (!line.includes(message[idx])) result.push(line);
4145
});
4246

47+
// @ts-expect-error
4348
return result.join("\n");
4449
};
4550

51+
// @ts-expect-error
4652
exports.cutOffMessage = (stack, message) => {
4753
const nextLine = stack.indexOf("\n");
4854
if (nextLine === -1) {
@@ -53,12 +59,14 @@ exports.cutOffMessage = (stack, message) => {
5359
}
5460
};
5561

62+
// @ts-expect-error
5663
exports.cleanUp = (stack, message) => {
5764
stack = exports.cutOffLoaderExecution(stack);
5865
stack = exports.cutOffMessage(stack, message);
5966
return stack;
6067
};
6168

69+
// @ts-expect-error
6270
exports.cleanUpWebpackOptions = (stack, message) => {
6371
stack = exports.cutOffWebpackOptions(stack);
6472
stack = exports.cutOffMultilineMessage(stack, message);

packages/rspack/src/ResolverFactory.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ const {
2020

2121
/** @typedef {import("enhanced-resolve").ResolveOptions} ResolveOptions */
2222
/** @typedef {import("enhanced-resolve").Resolver} Resolver */
23-
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} WebpackResolveOptions */
24-
/** @typedef {import("../declarations/WebpackOptions").ResolvePluginInstance} ResolvePluginInstance */
23+
// /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} WebpackResolveOptions */
24+
// /** @typedef {import("../declarations/WebpackOptions").ResolvePluginInstance} ResolvePluginInstance */
25+
/** @typedef {any} WebpackResolveOptions */
26+
/** @typedef {any} ResolvePluginInstance */
2527

2628
/** @typedef {WebpackResolveOptions & {dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
2729
/**
@@ -48,6 +50,7 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
4850
plugins:
4951
plugins &&
5052
/** @type {ResolvePluginInstance[]} */ (
53+
// @ts-expect-error
5154
plugins.filter(item => item !== "...")
5255
)
5356
};
@@ -63,6 +66,7 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
6366
partialOptions
6467
);
6568

69+
// @ts-expect-error
6670
return removeOperations(
6771
resolveByProperty(options, "byDependency", dependencyType)
6872
);

packages/rspack/src/config/browserslistTargetHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const parse = (input, context) => {
5454
/**
5555
* @param {string} input input string
5656
* @param {string} context the context directory
57-
* @returns {string[] | undefined} selected browsers
57+
* @returns {string[] | undefined | null} selected browsers
5858
*/
5959
const load = (input, context) => {
6060
const { configPath, env, query } = parse(input, context);

packages/rspack/src/config/target.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const getBrowserslistTargetHandler = memoize(() =>
1414
require("./browserslistTargetHandler")
1515
);
1616

17+
// @ts-expect-error
1718
const getDefaultTarget = context => {
1819
// TODO: align with webpack
1920
// const browsers = getBrowserslistTargetHandler().load(null, context);
@@ -69,10 +70,12 @@ const getDefaultTarget = context => {
6970
/** @template A @template B @typedef {(A & Never<B>) | (Never<A> & B) | (A & B)} Mix<A,B> */
7071
/** @typedef {Mix<Mix<PlatformTargetProperties, ElectronContextTargetProperties>, Mix<ApiTargetProperties, EcmaTargetProperties>>} TargetProperties */
7172

73+
// @ts-expect-error
7274
const versionDependent = (major, minor) => {
7375
if (!major) return () => /** @type {undefined} */ (undefined);
7476
major = +major;
7577
minor = minor ? +minor : 0;
78+
// @ts-expect-error
7679
return (vMajor, vMinor = 0) => {
7780
return major > vMajor || (major === vMajor && minor >= vMinor);
7881
};
@@ -87,6 +90,7 @@ const TARGETS = [
8790
(rest, context) => {
8891
const browserslistTargetHandler = getBrowserslistTargetHandler();
8992
const browsers = browserslistTargetHandler.load(
93+
// @ts-expect-error
9094
rest ? rest.trim() : null,
9195
context
9296
);
@@ -149,6 +153,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
149153
"[async-]node[X[.Y]]",
150154
"Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.",
151155
/^(async-)?node(\d+(?:\.(\d+))?)?$/,
156+
// @ts-expect-error
152157
(asyncFlag, major, minor) => {
153158
const v = versionDependent(major, minor);
154159
// see https://node.green/
@@ -186,6 +191,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
186191
"electron[X[.Y]]-main/preload/renderer",
187192
"Electron in version X.Y. Script is running in main, preload resp. renderer context.",
188193
/^electron(\d+(?:\.(\d+))?)?-(main|preload|renderer)$/,
194+
// @ts-expect-error
189195
(major, minor, context) => {
190196
const v = versionDependent(major, minor);
191197
// see https://node.green/ + https://github.com/electron/releases
@@ -227,6 +233,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
227233
"nwjs[X[.Y]] / node-webkit[X[.Y]]",
228234
"NW.js in version X.Y.",
229235
/^(?:nwjs|node-webkit)(\d+(?:\.(\d+))?)?$/,
236+
// @ts-expect-error
230237
(major, minor) => {
231238
const v = versionDependent(major, minor);
232239
// see https://node.green/ + https://github.com/nwjs/nw.js/blob/nw48/CHANGELOG.md
@@ -304,7 +311,7 @@ const getTargetProperties = (target, context) => {
304311
).join("\n")}`
305312
);
306313
};
307-
314+
// @ts-expect-error
308315
const mergeTargetProperties = targetProperties => {
309316
const keys = new Set();
310317
for (const tp of targetProperties) {
@@ -328,6 +335,7 @@ const mergeTargetProperties = targetProperties => {
328335
}
329336
}
330337
if (hasTrue || hasFalse)
338+
// @ts-expect-error
331339
result[key] = hasFalse && hasTrue ? null : hasTrue ? true : false;
332340
}
333341
return /** @type {TargetProperties} */ (result);

packages/rspack/src/lib/BannerPlugin.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
1111
const Template = require("./Template");
1212
const createSchemaValidation = require("./util/create-schema-validation");
1313

14-
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
15-
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
16-
/** @typedef {import("./Compiler")} Compiler */
14+
// /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
15+
// /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
16+
// /** @typedef {import("./Compiler")} Compiler */
17+
/** @typedef {any} BannerPluginArgument */
18+
/** @typedef {any} BannerPluginOptions */
19+
/** @typedef {any} Compiler */
1720

1821
const validate = createSchemaValidation(
1922
require("../schemas/plugins/BannerPlugin.check.js"),
23+
// @ts-expect-error
2024
() => require("../schemas/plugins/BannerPlugin.json"),
2125
{
2226
name: "Banner Plugin",
2327
baseDataPath: "options"
2428
}
2529
);
2630

31+
// @ts-expect-error
2732
const wrapComment = str => {
2833
if (!str.includes("\n")) {
2934
return Template.toComment(str);
@@ -56,7 +61,8 @@ class BannerPlugin {
5661
const getBanner = bannerOption;
5762
this.banner = this.options.raw
5863
? getBanner
59-
: data => wrapComment(getBanner(data));
64+
: // @ts-expect-error
65+
data => wrapComment(getBanner(data));
6066
} else {
6167
const banner = this.options.raw
6268
? bannerOption
@@ -79,10 +85,12 @@ class BannerPlugin {
7985
);
8086
const cache = new WeakMap();
8187

88+
// @ts-expect-error
8289
compiler.hooks.compilation.tap("BannerPlugin", compilation => {
8390
compilation.hooks.processAssets.tap(
8491
{
8592
name: "BannerPlugin",
93+
// @ts-expect-error
8694
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
8795
},
8896
() => {
@@ -105,6 +113,7 @@ class BannerPlugin {
105113
typeof banner === "function" ? banner({ chunk }) : banner;
106114
const comment = compilation.getPath(normalizedBanner, data);
107115

116+
// @ts-expect-error
108117
compilation.updateAsset(file, old => {
109118
let cached = cache.get(old);
110119
if (!cached || cached.comment !== comment) {

packages/rspack/src/lib/Cache.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const {
3333
* @returns {void}
3434
*/
3535

36+
// @ts-expect-error
3637
const needCalls = (times, callback) => {
38+
// @ts-expect-error
3739
return err => {
3840
if (--times === 0) {
3941
return callback(err);
@@ -71,7 +73,9 @@ class Cache {
7173
* @returns {void}
7274
*/
7375
get(identifier, etag, callback) {
76+
// @ts-expect-error
7477
const gotHandlers = [];
78+
// @ts-expect-error
7579
this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
7680
if (err) {
7781
callback(makeWebpackError(err, "Cache.hooks.get"));
@@ -84,10 +88,12 @@ class Cache {
8488
const innerCallback = needCalls(gotHandlers.length, () =>
8589
callback(null, result)
8690
);
91+
// @ts-expect-error
8792
for (const gotHandler of gotHandlers) {
8893
gotHandler(result, innerCallback);
8994
}
9095
} else if (gotHandlers.length === 1) {
96+
// @ts-expect-error
9197
gotHandlers[0](result, () => callback(null, result));
9298
} else {
9399
callback(null, result);
@@ -108,6 +114,7 @@ class Cache {
108114
identifier,
109115
etag,
110116
data,
117+
// @ts-expect-error
111118
makeWebpackErrorCallback(callback, "Cache.hooks.store")
112119
);
113120
}
@@ -121,6 +128,7 @@ class Cache {
121128
storeBuildDependencies(dependencies, callback) {
122129
this.hooks.storeBuildDependencies.callAsync(
123130
dependencies,
131+
// @ts-expect-error
124132
makeWebpackErrorCallback(callback, "Cache.hooks.storeBuildDependencies")
125133
);
126134
}
@@ -138,6 +146,7 @@ class Cache {
138146
*/
139147
endIdle(callback) {
140148
this.hooks.endIdle.callAsync(
149+
// @ts-expect-error
141150
makeWebpackErrorCallback(callback, "Cache.hooks.endIdle")
142151
);
143152
}
@@ -148,6 +157,7 @@ class Cache {
148157
*/
149158
shutdown(callback) {
150159
this.hooks.shutdown.callAsync(
160+
// @ts-expect-error
151161
makeWebpackErrorCallback(callback, "Cache.hooks.shutdown")
152162
);
153163
}

packages/rspack/src/lib/CacheFacade.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const mergeEtags = require("./cache/mergeEtags.js");
1414
/** @typedef {import("./Cache").Etag} Etag */
1515
/** @typedef {import("./WebpackError")} WebpackError */
1616
/** @typedef {import("./cache/getLazyHashedEtag").HashableObject} HashableObject */
17-
/** @typedef {typeof import("./util/Hash")} HashConstructor */
17+
// /** @typedef {typeof import("./util/Hash")} HashConstructor */
18+
/** @typedef {any} HashConstructor */
1819

1920
/**
2021
* @template T
@@ -47,6 +48,7 @@ class MultiItemCache {
4748
* @returns {void}
4849
*/
4950
get(callback) {
51+
// @ts-expect-error
5052
forEachBail(this._items, (item, callback) => item.get(callback), callback);
5153
}
5254

@@ -55,6 +57,7 @@ class MultiItemCache {
5557
* @returns {Promise<T>} promise with the data
5658
*/
5759
getPromise() {
60+
// @ts-expect-error
5861
const next = i => {
5962
return this._items[i].getPromise().then(result => {
6063
if (result !== undefined) return result;

0 commit comments

Comments
 (0)