Skip to content

Commit 5019cef

Browse files
authored
fix: support TypeScript 6 declaration builds (#31)
1 parent 7d0788f commit 5019cef

12 files changed

Lines changed: 53 additions & 41 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"range-parser": "^1.2.1",
6262
"router": "^2.2.0",
6363
"supertest": "^7.0.0",
64-
"typescript": "^5.3.3"
64+
"typescript": "^6.0.2"
6565
},
6666
"peerDependencies": {
6767
"@rspack/core": "^2.0.0-0"

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const noop = () => {};
139139
* @returns {Promise<void>}
140140
*/
141141

142-
/** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
142+
/** @typedef {import("./utils/getFilenameFromUrl.js").Extra} Extra */
143143

144144
/**
145145
* @callback GetFilenameFromUrl
@@ -396,7 +396,7 @@ function koaWrapper(compiler, options) {
396396
const devMiddleware = rdm(compiler, options);
397397

398398
/**
399-
* @param {{ req: RequestInternal, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | { message: string }, state: object }} ctx context
399+
* @param {{ req: RequestInternal, res: ResponseInternal & import("./utils/compatibleAPI.js").ExpectedServerResponse, status: number, body: string | Buffer | import("fs").ReadStream | { message: string }, state: object }} ctx context
400400
* @param {EXPECTED_FUNCTION} next next
401401
* @returns {Promise<void>}
402402
*/
@@ -509,7 +509,7 @@ function honoWrapper(compiler, options) {
509509
const devMiddleware = rdm(compiler, options);
510510

511511
/**
512-
* @param {{ env: EXPECTED_ANY, body: EXPECTED_ANY, json: EXPECTED_ANY, status: EXPECTED_ANY, set: EXPECTED_ANY, req: RequestInternal & import("./utils/compatibleAPI").ExpectedIncomingMessage & { header: (name: string) => string }, res: ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY } }} context context
512+
* @param {{ env: EXPECTED_ANY, body: EXPECTED_ANY, json: EXPECTED_ANY, status: EXPECTED_ANY, set: EXPECTED_ANY, req: RequestInternal & import("./utils/compatibleAPI.js").ExpectedIncomingMessage & { header: (name: string) => string }, res: ResponseInternal & import("./utils/compatibleAPI.js").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY } }} context context
513513
* @param {EXPECTED_FUNCTION} next next function
514514
* @returns {Promise<void>}
515515
*/
@@ -558,7 +558,7 @@ function honoWrapper(compiler, options) {
558558
/**
559559
* @param {string} name header name
560560
* @param {string | number | Readonly<string[]>} value value
561-
* @returns {ResponseInternal & import("./utils/compatibleAPI").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY }} response
561+
* @returns {ResponseInternal & import("./utils/compatibleAPI.js").ExpectedServerResponse & { headers: EXPECTED_ANY, status: EXPECTED_ANY }} response
562562
*/
563563
res.setHeader = (name, value) => {
564564
context.res.headers.append(name, value);

src/middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const MAX_MAX_AGE = 31536000000;
158158
* @template {ServerResponse} Response
159159
* @typedef {object} SendErrorOptions send error options
160160
* @property {Record<string, number | string | string[] | undefined>=} headers headers
161-
* @property {import("./index").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
161+
* @property {import("./index.js").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
162162
*/
163163

164164
/**
@@ -532,7 +532,7 @@ function wrapper(context) {
532532
*/
533533
async function processRequest() {
534534
// Pipe and SendFile
535-
/** @type {import("./utils/getFilenameFromUrl").Extra} */
535+
/** @type {import("./utils/getFilenameFromUrl.js").Extra} */
536536
const extra = {};
537537
const filename = getFilenameFromUrl(
538538
context,

src/utils/compatibleAPI.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/** @typedef {import("../index").IncomingMessage} IncomingMessage */
2-
/** @typedef {import("../index").ServerResponse} ServerResponse */
3-
/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */
4-
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
1+
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
2+
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
3+
/** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */
4+
/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */
55

66
/**
77
* @typedef {object} ExpectedIncomingMessage
@@ -226,7 +226,7 @@ function createReadStreamOrReadFileSync(
226226
start,
227227
end,
228228
) {
229-
/** @type {string | Buffer | import("fs").ReadStream} */
229+
/** @type {Buffer | import("fs").ReadStream} */
230230
let bufferOrStream;
231231
/** @type {number} */
232232
let byteLength;

src/utils/memorize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
1+
/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */
22

33
const cacheStore = new WeakMap();
44

src/utils/setupWriteToDisk.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function setupWriteToDisk(context) {
3737

3838
compiler.hooks.assetEmitted.tapAsync(
3939
"DevMiddleware",
40+
/**
41+
* @param {string} file asset file name
42+
* @param {{ targetPath: string, content: Buffer }} info emitted asset info
43+
* @param {(err?: NodeJS.ErrnoException | null) => void} callback completion callback
44+
*/
4045
(file, info, callback) => {
4146
const { targetPath, content } = info;
4247
const { writeToDisk: filter } = context.options;

tsconfig.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"compilerOptions": {
3-
"target": "esnext",
4-
"moduleResolution": "node",
3+
"rootDir": "./src",
4+
"outDir": "./dist",
5+
"target": "ES2023",
6+
"types": ["node"],
7+
"lib": ["DOM", "ESNext"],
8+
"declaration": true,
9+
"isolatedModules": true,
10+
"skipLibCheck": true,
11+
"module": "nodenext",
12+
"moduleResolution": "nodenext",
513
"allowJs": true,
614
"checkJs": true,
715
"strict": true,
8-
"types": ["node"],
916
"allowSyntheticDefaultImports": true
1017
},
11-
"include": ["./src/**/*"]
18+
"include": ["src"]
1219
}

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
* @param {NextFunction} next
107107
* @returns {Promise<void>}
108108
*/
109-
/** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
109+
/** @typedef {import("./utils/getFilenameFromUrl.js").Extra} Extra */
110110
/**
111111
* @callback GetFilenameFromUrl
112112
* @param {string} url
@@ -376,7 +376,7 @@ export type Middleware<
376376
res: ResponseInternal,
377377
next: NextFunction,
378378
) => Promise<void>;
379-
export type Extra = import("./utils/getFilenameFromUrl").Extra;
379+
export type Extra = import("./utils/getFilenameFromUrl.js").Extra;
380380
export type GetFilenameFromUrl = (
381381
url: string,
382382
extra?: Extra | undefined,

types/middleware.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type SendErrorOptions<
1414
* modify response data callback
1515
*/
1616
modifyResponseData?:
17-
| import("./index").ModifyResponseData<Request, Response>
17+
| import("./index.js").ModifyResponseData<Request, Response>
1818
| undefined;
1919
};
2020
export type NextFunction = import("./index.js").NextFunction;
@@ -27,7 +27,7 @@ export type ReadStream = import("fs").ReadStream;
2727
* @template {ServerResponse} Response
2828
* @typedef {object} SendErrorOptions send error options
2929
* @property {Record<string, number | string | string[] | undefined>=} headers headers
30-
* @property {import("./index").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
30+
* @property {import("./index.js").ModifyResponseData<Request, Response>=} modifyResponseData modify response data callback
3131
*/
3232
/**
3333
* @template {IncomingMessage} Request

0 commit comments

Comments
 (0)