Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error #3863

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/node_binding/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
}
}
1 change: 1 addition & 0 deletions examples/arco-pro/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"esnext"
],
"allowJs": true,
// TODO: Remove skipLibCheck when fix upstream type bug
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
Expand Down
1 change: 1 addition & 0 deletions examples/react-storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
// TODO: Remove skipLibCheck when fix upstream type bug
"skipLibCheck": true,
"jsx": "react-jsx",
"moduleResolution": "node"
Expand Down
1 change: 1 addition & 0 deletions packages/create-rspack/template-react-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "ES6",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
// TODO: Remove skipLibCheck when fix upstream type bug
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
Expand Down
9 changes: 7 additions & 2 deletions packages/rspack-cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
const config = {
preset: "ts-jest",
testEnvironment: "../../scripts/test/patch-node-env.cjs",
testTimeout: process.env.CI ? 200000 : 30000,
testMatch: ["<rootDir>/tests/**/*.test.ts", "<rootDir>/tests/**/*.test.js"],
watchPathIgnorePatterns: ["<rootDir>/tests/.*/dist"],
extensionsToTreatAsEsm: [".mts"]
extensionsToTreatAsEsm: [".mts"],
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tests/tsconfig.json"
}
}
};

module.exports = config;
11 changes: 9 additions & 2 deletions packages/rspack-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export class BuildCommand implements RspackCommand {
}),
async options => {
const logger = cli.getLogger();
// @ts-expect-error
let createJsonStringifyStream;
if (options.json) {
const jsonExt = await import("@discoveryjs/json-ext");
createJsonStringifyStream = jsonExt.default.stringifyStream;
}

// @ts-expect-error
const callback = (error, stats: Stats | MultiStats) => {
if (error) {
logger.error(error);
Expand All @@ -45,10 +47,14 @@ export class BuildCommand implements RspackCommand {
compiler.options ? compiler.options.stats : undefined
)
}
: compiler.options
? compiler.options.stats
: // @ts-expect-error
compiler.options
? // @ts-expect-error
compiler.options.stats
: undefined;
// @ts-expect-error
if (options.json && createJsonStringifyStream) {
// @ts-expect-error
const handleWriteError = error => {
logger.error(error);
process.exit(2);
Expand Down Expand Up @@ -84,6 +90,7 @@ export class BuildCommand implements RspackCommand {

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

// @ts-expect-error
const errorHandler = (err, Stats) => {
callback(err, Stats);
};
Expand Down
1 change: 1 addition & 0 deletions packages/rspack-cli/src/rspack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class RspackCLI {
? (config as MultiRspackOptions).some(i => i.watch)
: (config as RspackOptions).watch;

// @ts-expect-error
return rspack(config, isWatch ? callback : undefined);
}
createColors(useColor?: boolean): RspackCLIColors {
Expand Down
3 changes: 3 additions & 0 deletions packages/rspack-cli/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ export const previewOptions = (yargs: yargs.Argv) => {
});
};

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

let prevRef = previous;

// @ts-expect-error
splitKeys.forEach((someKey, index) => {
// https://github.com/webpack/webpack-cli/issues/3284
if (someKey.endsWith("=")) {
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack-cli/src/utils/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ function resolveLoggingOptions(value: string): LoggingOptions {
class RspackProfileJSCPUProfilePlugin {
constructor(private output: string) {}

// @ts-expect-error
apply(compiler) {
const session = new inspector.Session();
session.connect();
session.post("Profiler.enable");
session.post("Profiler.start");
compiler.hooks.done.tapAsync(
RspackProfileJSCPUProfilePlugin.name,
// @ts-expect-error
(stats, callback) => {
if (compiler.watchMode) return callback();
session.post("Profiler.stop", (error, param) => {
Expand All @@ -192,9 +194,11 @@ class RspackProfileJSCPUProfilePlugin {
class RspackProfileLoggingPlugin {
constructor(private output: string) {}

// @ts-expect-error
apply(compiler) {
compiler.hooks.done.tapAsync(
RspackProfileLoggingPlugin.name,
// @ts-expect-error
(stats, callback) => {
if (compiler.watchMode) return callback();
const logging = stats.toJson({
Expand Down
10 changes: 10 additions & 0 deletions packages/rspack-cli/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"strict": false,
"checkJs": false,
"rootDir": "."
},
"include": ["."],
"references": []
}
6 changes: 3 additions & 3 deletions packages/rspack-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"strictNullChecks": true,
// TODO: Remove skipLibCheck when fix upstream type bug
"skipLibCheck": true,
"outDir": "dist",
"rootDir": "src",
"moduleResolution": "nodenext"
"rootDir": "src"
},
"references": [
{
Expand Down
9 changes: 7 additions & 2 deletions packages/rspack-dev-server/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
const config = {
preset: "ts-jest",
testEnvironmentOptions: {
url: "http://localhost/"
},
testMatch: ["<rootDir>/tests/*.test.ts", "<rootDir>/tests/e2e/*.test.ts"],
cache: false,
testTimeout: process.env.CI ? 120000 : 30000
testTimeout: process.env.CI ? 120000 : 30000,
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tests/tsconfig.json"
}
}
};

module.exports = config;
1 change: 0 additions & 1 deletion packages/rspack-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
Expand Down
9 changes: 7 additions & 2 deletions packages/rspack-dev-server/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ export function getRspackMemoryAssets(
}

// css hmr will append query string, so here need to remove query string
// @ts-expect-error
const path = parse(url).pathname;
// asset name is not start with /, so path need to slice 1
// @ts-expect-error
const filename = path.startsWith(publicPath)
? path.slice(publicPath.length)
: path.slice(1);
? // @ts-expect-error
path.slice(publicPath.length)
: // @ts-expect-error
path.slice(1);
const buffer =
compiler.getAsset(filename) ??
(() => {
Expand All @@ -50,6 +54,7 @@ export function getRspackMemoryAssets(
contentType = "text/html; charset=utf-8";
} else {
contentType =
// @ts-expect-error
mime.contentType(extname(path)) || "text/plain; charset=utf-8";
}

Expand Down
1 change: 1 addition & 0 deletions packages/rspack-dev-server/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function applyDevServerPatch() {

// @ts-expect-error private API
WebpackDevServer.prototype.sendStats = function sendStats__rspack_patched(
// @ts-expect-error
...args
) {
let stats = args[1];
Expand Down
13 changes: 13 additions & 0 deletions packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export class RspackDevServer extends WebpackDevServer {
/**
* resolved after `normalizedOptions`
*/
// @ts-expect-error
options: ResolvedDevServer;
// @ts-expect-error
staticWatchers: FSWatcher[];
// @ts-expect-error
sockets: Socket[];
// @ts-expect-error
server: Server;
// @ts-expect-error
public compiler: Compiler | MultiCompiler;
webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;

constructor(options: DevServer, compiler: Compiler | MultiCompiler) {
super(
// @ts-expect-error
{
...options,
setupMiddlewares: (middlewares, devServer) => {
Expand All @@ -54,6 +59,7 @@ export class RspackDevServer extends WebpackDevServer {
path: publicPath,
middleware: getRspackMemoryAssets(
compiler,
// @ts-expect-error
this.middleware
)
};
Expand All @@ -69,6 +75,7 @@ export class RspackDevServer extends WebpackDevServer {
}
}

// @ts-expect-error
options.setupMiddlewares?.call(this, middlewares, devServer);
return middlewares;
}
Expand Down Expand Up @@ -136,6 +143,7 @@ export class RspackDevServer extends WebpackDevServer {
);
}

// @ts-expect-error
return clientImplementation;
}

Expand All @@ -158,6 +166,7 @@ export class RspackDevServer extends WebpackDevServer {
compiler.options.devServer ??= {};
compiler.options.devServer.hot = true;
if (
// @ts-expect-error
!compiler.options.experiments.rspackFuture.disableTransformByDefault
) {
compiler.options.builtins.react ??= {};
Expand Down Expand Up @@ -298,6 +307,7 @@ export class RspackDevServer extends WebpackDevServer {
compilers.forEach(compiler => {
if (compiler.options.experiments.lazyCompilation) {
middlewares.push({
// @ts-expect-error
middleware: (req, res) => {
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
const path = req.url.replace("/lazy-compilation-web/", "");
Expand All @@ -319,10 +329,13 @@ export class RspackDevServer extends WebpackDevServer {

middlewares.forEach(middleware => {
if (typeof middleware === "function") {
// @ts-expect-error
this.app.use(middleware);
} else if (typeof middleware.path !== "undefined") {
// @ts-expect-error
this.app.use(middleware.path, middleware.middleware);
} else {
// @ts-expect-error
this.app.use(middleware.middleware);
}
});
Expand Down
5 changes: 5 additions & 0 deletions packages/rspack-dev-server/tests/normalizeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RspackOptions, rspack } from "@rspack/core";
import { RspackDevServer, Configuration } from "@rspack/dev-server";
import { createCompiler } from "@rspack/core";
import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
// @ts-expect-error
import serializer from "jest-serializer-path";
expect.addSnapshotSerializer(serializer);

Expand Down Expand Up @@ -174,16 +175,20 @@ async function getAdditionEntries(
.reduce<Object>((acc, cur: any) => {
const name = cur.options.name;
const request = cur.entry;
// @ts-expect-error
if (acc[name]) {
// @ts-expect-error
acc[name].import.push(request);
} else {
// @ts-expect-error
acc[name] = { import: [request] };
}
return acc;
}, {});
// some hack for snapshot
const value = Object.fromEntries(
Object.entries(entries).map(([key, item]) => {
// @ts-expect-error
const replaced = item.import?.map(entry => {
const array = entry
.replace(/\\/g, "/")
Expand Down
9 changes: 9 additions & 0 deletions packages/rspack-dev-server/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"checkJs": false,
"rootDir": "."
},
"include": ["."],
"references": []
}
2 changes: 2 additions & 0 deletions packages/rspack-dev-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"src"
],
"compilerOptions": {
// TODO: Remove skipLibCheck when fix upstream type bug
"skipLibCheck": true,
"outDir": "dist",
"rootDir": "src"
}
Expand Down
3 changes: 1 addition & 2 deletions packages/rspack-plugin-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"typings": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
Expand All @@ -34,7 +33,6 @@
"directory": "packages/rspack-plugin-html"
},
"dependencies": {
"@types/html-minifier-terser": "7.0.0",
"html-minifier-terser": "7.0.0",
"lodash.template": "^4.5.0",
"parse5": "7.1.1",
Expand All @@ -50,6 +48,7 @@
},
"devDependencies": {
"@rspack/core": "workspace:*",
"@types/html-minifier-terser": "7.0.0",
"@types/lodash.template": "^4.5.1",
"@types/pug": "^2.0.6",
"html-loader": "^4.2.0",
Expand Down
Loading
Loading