Skip to content

Commit 78fac29

Browse files
committed
fix: type error
1 parent 3c08253 commit 78fac29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+371
-91
lines changed

examples/arco-pro/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"esnext"
99
],
1010
"allowJs": true,
11+
// TODO: Remove skipLibCheck when fix upstream type bug
1112
"skipLibCheck": true,
1213
"esModuleInterop": true,
1314
"allowSyntheticDefaultImports": true,

examples/react-storybook/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"strict": true,
5+
// TODO: Remove skipLibCheck when fix upstream type bug
56
"skipLibCheck": true,
67
"jsx": "react-jsx",
78
"moduleResolution": "node"

packages/create-rspack/template-react-ts/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "ES6",
44
"lib": ["DOM", "DOM.Iterable", "ESNext"],
55
"module": "ESNext",
6+
// TODO: Remove skipLibCheck when fix upstream type bug
67
"skipLibCheck": true,
78
"moduleResolution": "bundler",
89
"allowImportingTsExtensions": true,

packages/rspack-cli/src/commands/build.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export class BuildCommand implements RspackCommand {
2222
}),
2323
async options => {
2424
const logger = cli.getLogger();
25+
// @ts-expect-error
2526
let createJsonStringifyStream;
2627
if (options.json) {
2728
const jsonExt = await import("@discoveryjs/json-ext");
2829
createJsonStringifyStream = jsonExt.default.stringifyStream;
2930
}
3031

32+
// @ts-expect-error
3133
const callback = (error, stats: Stats | MultiStats) => {
3234
if (error) {
3335
logger.error(error);
@@ -45,10 +47,14 @@ export class BuildCommand implements RspackCommand {
4547
compiler.options ? compiler.options.stats : undefined
4648
)
4749
}
48-
: compiler.options
49-
? compiler.options.stats
50+
: // @ts-expect-error
51+
compiler.options
52+
? // @ts-expect-error
53+
compiler.options.stats
5054
: undefined;
55+
// @ts-expect-error
5156
if (options.json && createJsonStringifyStream) {
57+
// @ts-expect-error
5258
const handleWriteError = error => {
5359
logger.error(error);
5460
process.exit(2);
@@ -84,6 +90,7 @@ export class BuildCommand implements RspackCommand {
8490

8591
const rspackOptions = { ...options, argv: { ...options } };
8692

93+
// @ts-expect-error
8794
const errorHandler = (err, Stats) => {
8895
callback(err, Stats);
8996
};

packages/rspack-cli/src/rspack-cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class RspackCLI {
5858
? (config as MultiRspackOptions).some(i => i.watch)
5959
: (config as RspackOptions).watch;
6060

61+
// @ts-expect-error
6162
return rspack(config, isWatch ? callback : undefined);
6263
}
6364
createColors(useColor?: boolean): RspackCLIColors {

packages/rspack-cli/src/utils/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ export const previewOptions = (yargs: yargs.Argv) => {
8282
});
8383
};
8484

85+
// @ts-expect-error
8586
export function normalizeEnv(argv) {
87+
// @ts-expect-error
8688
function parseValue(previous, value) {
8789
const [allKeys, val] = value.split(/=(.+)/, 2);
8890
const splitKeys = allKeys.split(/\.(?!$)/);
8991

9092
let prevRef = previous;
9193

94+
// @ts-expect-error
9295
splitKeys.forEach((someKey, index) => {
9396
// https://github.com/webpack/webpack-cli/issues/3284
9497
if (someKey.endsWith("=")) {

packages/rspack-cli/src/utils/profile.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,15 @@ function resolveLoggingOptions(value: string): LoggingOptions {
167167
class RspackProfileJSCPUProfilePlugin {
168168
constructor(private output: string) {}
169169

170+
// @ts-expect-error
170171
apply(compiler) {
171172
const session = new inspector.Session();
172173
session.connect();
173174
session.post("Profiler.enable");
174175
session.post("Profiler.start");
175176
compiler.hooks.done.tapAsync(
176177
RspackProfileJSCPUProfilePlugin.name,
178+
// @ts-expect-error
177179
(stats, callback) => {
178180
if (compiler.watchMode) return callback();
179181
session.post("Profiler.stop", (error, param) => {
@@ -192,9 +194,11 @@ class RspackProfileJSCPUProfilePlugin {
192194
class RspackProfileLoggingPlugin {
193195
constructor(private output: string) {}
194196

197+
// @ts-expect-error
195198
apply(compiler) {
196199
compiler.hooks.done.tapAsync(
197200
RspackProfileLoggingPlugin.name,
201+
// @ts-expect-error
198202
(stats, callback) => {
199203
if (compiler.watchMode) return callback();
200204
const logging = stats.toJson({

packages/rspack-cli/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"extends": "../../tsconfig.base.json",
33
"include": ["src"],
44
"compilerOptions": {
5-
"strictNullChecks": true,
5+
// TODO: Remove skipLibCheck when fix upstream type bug
6+
"skipLibCheck": true,
67
"outDir": "dist",
7-
"rootDir": "src",
8-
"moduleResolution": "nodenext"
8+
"rootDir": "src"
99
},
1010
"references": [
1111
{

packages/rspack-dev-server/src/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getRspackMemoryAssets(
2727
}
2828

2929
// css hmr will append query string, so here need to remove query string
30-
const path = parse(url).pathname;
30+
const path = parse(url!).pathname!;
3131
// asset name is not start with /, so path need to slice 1
3232
const filename = path.startsWith(publicPath)
3333
? path.slice(publicPath.length)

packages/rspack-dev-server/src/patch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function applyDevServerPatch() {
1717

1818
// @ts-expect-error private API
1919
WebpackDevServer.prototype.sendStats = function sendStats__rspack_patched(
20+
// @ts-expect-error
2021
...args
2122
) {
2223
let stats = args[1];

packages/rspack-dev-server/src/server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ export class RspackDevServer extends WebpackDevServer {
2525
/**
2626
* resolved after `normalizedOptions`
2727
*/
28+
// @ts-expect-error
2829
options: ResolvedDevServer;
30+
// @ts-expect-error
2931
staticWatchers: FSWatcher[];
32+
// @ts-expect-error
3033
sockets: Socket[];
34+
// @ts-expect-error
3135
server: Server;
3236
// @ts-expect-error
3337
public compiler: Compiler | MultiCompiler;
3438
webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
3539

3640
constructor(options: DevServer, compiler: Compiler | MultiCompiler) {
3741
super(
42+
// @ts-expect-error
3843
{
3944
...options,
4045
setupMiddlewares: (middlewares, devServer) => {
@@ -54,6 +59,7 @@ export class RspackDevServer extends WebpackDevServer {
5459
path: publicPath,
5560
middleware: getRspackMemoryAssets(
5661
compiler,
62+
// @ts-expect-error
5763
this.middleware
5864
)
5965
};
@@ -69,6 +75,7 @@ export class RspackDevServer extends WebpackDevServer {
6975
}
7076
}
7177

78+
// @ts-expect-error
7279
options.setupMiddlewares?.call(this, middlewares, devServer);
7380
return middlewares;
7481
}
@@ -136,6 +143,7 @@ export class RspackDevServer extends WebpackDevServer {
136143
);
137144
}
138145

146+
// @ts-expect-error
139147
return clientImplementation;
140148
}
141149

@@ -158,6 +166,7 @@ export class RspackDevServer extends WebpackDevServer {
158166
compiler.options.devServer ??= {};
159167
compiler.options.devServer.hot = true;
160168
if (
169+
// @ts-expect-error
161170
!compiler.options.experiments.rspackFuture.disableTransformByDefault
162171
) {
163172
compiler.options.builtins.react ??= {};
@@ -298,6 +307,7 @@ export class RspackDevServer extends WebpackDevServer {
298307
compilers.forEach(compiler => {
299308
if (compiler.options.experiments.lazyCompilation) {
300309
middlewares.push({
310+
// @ts-expect-error
301311
middleware: (req, res) => {
302312
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
303313
const path = req.url.replace("/lazy-compilation-web/", "");
@@ -319,10 +329,13 @@ export class RspackDevServer extends WebpackDevServer {
319329

320330
middlewares.forEach(middleware => {
321331
if (typeof middleware === "function") {
332+
// @ts-expect-error
322333
this.app.use(middleware);
323334
} else if (typeof middleware.path !== "undefined") {
335+
// @ts-expect-error
324336
this.app.use(middleware.path, middleware.middleware);
325337
} else {
338+
// @ts-expect-error
326339
this.app.use(middleware.middleware);
327340
}
328341
});

packages/rspack-dev-server/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"src"
55
],
66
"compilerOptions": {
7+
// TODO: Remove skipLibCheck when fix upstream type bug
8+
"skipLibCheck": true,
79
"outDir": "dist",
810
"rootDir": "src"
911
}

packages/rspack-plugin-html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"directory": "packages/rspack-plugin-html"
3535
},
3636
"dependencies": {
37-
"@types/html-minifier-terser": "7.0.0",
3837
"html-minifier-terser": "7.0.0",
3938
"lodash.template": "^4.5.0",
4039
"parse5": "7.1.1",
@@ -50,6 +49,7 @@
5049
},
5150
"devDependencies": {
5251
"@rspack/core": "workspace:*",
52+
"@types/html-minifier-terser": "7.0.0",
5353
"@types/lodash.template": "^4.5.1",
5454
"@types/pug": "^2.0.6",
5555
"html-loader": "^4.2.0",

packages/rspack-plugin-html/src/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* https://github.com/jantimon/html-webpack-plugin/blob/d5ce5a8f2d12a2450a65ec51c285dd54e36cd921/LICENSE
99
*/
1010
import type { Compiler, Compilation, RspackPluginInstance } from "@rspack/core";
11+
// @ts-ignore
1112
import type { Options as MinifyOptions } from "html-minifier-terser";
1213
import assert from "assert";
1314
import path from "path";
@@ -253,6 +254,7 @@ export default class HtmlRspackPlugin implements RspackPluginInstance {
253254
name = "HtmlRspackPlugin";
254255

255256
userOptions: Options;
257+
// @ts-expect-error
256258
options: ProcessedOptions;
257259

258260
constructor(options?: Options) {
@@ -395,6 +397,7 @@ function hookIntoCompiler(
395397
const filename = options.filename;
396398
if (path.resolve(filename) === path.normalize(filename)) {
397399
const outputPath = compiler.options.output.path;
400+
// @ts-expect-error
398401
options.filename = path.relative(outputPath, filename);
399402
}
400403

@@ -631,6 +634,7 @@ function hookIntoCompiler(
631634
const compilationHash = compilation.hash;
632635

633636
const rspackPublicPath = compilation.getAssetPath(
637+
// @ts-expect-error
634638
compilation.outputOptions.publicPath,
635639
{ hash: compilationHash }
636640
);
@@ -649,9 +653,11 @@ function hookIntoCompiler(
649653
path
650654
.relative(
651655
path.resolve(
656+
// @ts-expect-error
652657
compilation.options.output.path,
653658
path.dirname(filename)
654659
),
660+
// @ts-expect-error
655661
compilation.options.output.path
656662
)
657663
.split(path.sep)
@@ -687,6 +693,7 @@ function hookIntoCompiler(
687693

688694
// Append a hash for cache busting
689695
if (options.hash && assets.manifest) {
696+
// @ts-expect-error
690697
assets.manifest = appendHash(assets.manifest, compilationHash);
691698
}
692699

@@ -696,6 +703,7 @@ function hookIntoCompiler(
696703
for (let i = 0; i < entryNames.length; i++) {
697704
const entryName = entryNames[i];
698705
/** entryPointUnfilteredFiles - also includes hot module update files */
706+
// @ts-expect-error
699707
const entryPointUnfilteredFiles = compilation.entrypoints
700708
.get(entryName)
701709
.getFiles();
@@ -719,7 +727,8 @@ function hookIntoCompiler(
719727
const entryPointPublicPaths = entryPointFiles.map(chunkFile => {
720728
const entryPointPublicPath = publicPath + urlencodePath(chunkFile);
721729
return options.hash
722-
? appendHash(entryPointPublicPath, compilationHash)
730+
? // @ts-expect-error
731+
appendHash(entryPointPublicPath, compilationHash)
723732
: entryPointPublicPath;
724733
});
725734

@@ -731,12 +740,15 @@ function hookIntoCompiler(
731740
}
732741
// Skip if this file is already known
733742
// (e.g. because of common chunk optimizations)
743+
// @ts-expect-error
734744
if (entryPointPublicPathMap[entryPointPublicPath]) {
735745
return;
736746
}
747+
// @ts-expect-error
737748
entryPointPublicPathMap[entryPointPublicPath] = true;
738749
// ext will contain .js or .css, because .mjs recognizes as .js
739750
const ext = extMatch[1] === "mjs" ? "js" : extMatch[1];
751+
// @ts-expect-error
740752
assets[ext].push(entryPointPublicPath);
741753
});
742754
}
@@ -761,7 +773,9 @@ function hookIntoCompiler(
761773
return entryNames.sort(sortMode);
762774
}
763775
// Check if the given sort mode is a valid chunkSorter sort mode
776+
// @ts-expect-error
764777
if (typeof chunkSorter[sortMode] !== "undefined") {
778+
// @ts-expect-error
765779
return chunkSorter[sortMode](entryNames, compilation, options);
766780
}
767781
throw new Error('"' + sortMode + '" is not a valid chunk sort mode');
@@ -842,6 +856,7 @@ function hookIntoCompiler(
842856
return addFileToAssets(faviconFilePath, compilation).then(faviconName => {
843857
const faviconPath = publicPath + faviconName;
844858
if (options.hash) {
859+
// @ts-expect-error
845860
return appendHash(faviconPath, compilation.hash);
846861
}
847862
return faviconPath;
@@ -1014,6 +1029,7 @@ function hookIntoCompiler(
10141029
// Add script tags to head or body depending on
10151030
// the htmlPluginOptions
10161031
if (scriptTarget === "body") {
1032+
// @ts-expect-error
10171033
result.bodyTags.push(...assetTags.scripts);
10181034
} else {
10191035
// If script loading is blocking add the scripts to the end of the head
@@ -1204,9 +1220,12 @@ function hookIntoCompiler(
12041220
try {
12051221
return require("html-minifier-terser").minify(html, options.minify);
12061222
} catch (e) {
1223+
// @ts-expect-error
12071224
const isParseError = String(e.message).indexOf("Parse Error") === 0;
12081225
if (isParseError) {
1226+
// @ts-expect-error
12091227
e.message = "html-minifier-terser error:";
1228+
// @ts-expect-error
12101229
"\n" + e.message;
12111230
}
12121231
throw e;

packages/rspack-plugin-html/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4+
// TODO: Remove skipLibCheck when fix upstream type bug
5+
"skipLibCheck": true,
46
"outDir": "dist",
57
"rootDir": "src"
68
},

packages/rspack-plugin-react-refresh/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class ReactRefreshRspackPlugin {
4848
}).apply(compiler);
4949

5050
compiler.options.module.rules.unshift({
51+
// @ts-expect-error
5152
include: this.options.include,
53+
// @ts-expect-error
5254
exclude: {
5355
or: [this.options.exclude, [...runtimePaths]].filter(Boolean)
5456
},

0 commit comments

Comments
 (0)