From e4438d6226a888803fe011e93370a4022d934b88 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 11 Oct 2024 12:34:18 +0800 Subject: [PATCH 1/2] fix: should transpile ansiHTML to es5 --- .gitignore | 2 ++ {client => client-src}/index.js | 1 + {src => client-src/utils}/ansiHTML.ts | 0 {client => client-src}/utils/reloadApp.js | 2 ++ package.json | 4 +++- src/server.ts | 4 +--- tests/ansiHTML.test.ts | 2 +- tests/tsconfig.json | 2 +- tsconfig.build.json | 6 ++++-- tsconfig.client.json | 14 ++++++++++++++ 10 files changed, 29 insertions(+), 8 deletions(-) rename {client => client-src}/index.js (99%) rename {src => client-src/utils}/ansiHTML.ts (100%) rename {client => client-src}/utils/reloadApp.js (99%) create mode 100644 tsconfig.client.json diff --git a/.gitignore b/.gitignore index 6e66ac5..0216fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,12 @@ .DS_Store *.local *.log* +*.tsbuildinfo # Dist node_modules dist/ +client/ test-results # Test diff --git a/client/index.js b/client-src/index.js similarity index 99% rename from client/index.js rename to client-src/index.js index 96ef2ae..5c4ce0a 100644 --- a/client/index.js +++ b/client-src/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { diff --git a/src/ansiHTML.ts b/client-src/utils/ansiHTML.ts similarity index 100% rename from src/ansiHTML.ts rename to client-src/utils/ansiHTML.ts diff --git a/client/utils/reloadApp.js b/client-src/utils/reloadApp.js similarity index 99% rename from client/utils/reloadApp.js rename to client-src/utils/reloadApp.js index 2c0fd85..3bd51f3 100644 --- a/client/utils/reloadApp.js +++ b/client-src/utils/reloadApp.js @@ -1,3 +1,5 @@ +// @ts-nocheck + import hotEmitter from "@rspack/core/hot/emitter.js"; import { log } from "webpack-dev-server/client/utils/log.js"; diff --git a/package.json b/package.json index c7fa9d1..f4ad6e0 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,9 @@ "./package.json": "./package.json" }, "scripts": { - "build": "tsc -b ./tsconfig.build.json", + "build": "pnpm run build:server && pnpm run build:client", + "build:server": "tsc -b ./tsconfig.build.json", + "build:client": "tsc -b ./tsconfig.client.json", "dev": "tsc -b -w", "lint": "biome check .", "lint:write": "biome check . --write", diff --git a/src/server.ts b/src/server.ts index e027a3d..bcd5ab9 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,8 +7,6 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/LICENSE */ -import path from "node:path"; - import type { Server } from "node:http"; import type { Socket } from "node:net"; import { type Compiler, MultiCompiler } from "@rspack/core"; @@ -91,7 +89,7 @@ export class RspackDevServer extends WebpackDevServer { } compiler.options.resolve.alias = { - "ansi-html-community": path.resolve(__dirname, "./ansiHTML"), + "ansi-html-community": require.resolve("@rspack/dev-server/client/utils/ansiHTML"), ...compiler.options.resolve.alias }; } diff --git a/tests/ansiHTML.test.ts b/tests/ansiHTML.test.ts index 079523d..9a7a15c 100644 --- a/tests/ansiHTML.test.ts +++ b/tests/ansiHTML.test.ts @@ -1,4 +1,4 @@ -import ansiHTML from "../src/ansiHTML"; +import ansiHTML from "../client-src/utils/ansiHTML"; describe("ansi-html", () => { it("should transform 24-bit rgb ansi colors", () => { diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 767ff2d..09037e0 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -5,6 +5,6 @@ "checkJs": false, "rootDir": "../" }, - "include": ["../src", "../tests"], + "include": ["../src", "../tests", "../client-src"], "references": [] } diff --git a/tsconfig.build.json b/tsconfig.build.json index 7973b10..8b0aaa1 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,6 +2,8 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "declarationMap": false - } + "declarationMap": false, + "rootDir": "src" + }, + "include": ["src"] } diff --git a/tsconfig.client.json b/tsconfig.client.json new file mode 100644 index 0000000..48a2109 --- /dev/null +++ b/tsconfig.client.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2020", + "target": "ES5", + "outDir": "client", + "rootDir": "client-src", + "composite": false, + "sourceMap": false, + "declarationMap": false, + "declaration": false + }, + "include": ["client-src"] +} From 59dfce7ff433ec722c0f622cdc373e5b9f72a000 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 11 Oct 2024 12:55:52 +0800 Subject: [PATCH 2/2] fix: should transpile ansiHTML to es5 --- tsconfig.build.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tsconfig.build.json b/tsconfig.build.json index 8b0aaa1..7973b10 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,8 +2,6 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "declarationMap": false, - "rootDir": "src" - }, - "include": ["src"] + "declarationMap": false + } }