diff --git a/package.json b/package.json index e2c153b..2244d93 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "test": "vitest run", "test:watch": "vitest", "update": "yarn upgrade-interactive", - "build": "tsc -p src --noEmit && yarn clean && tsup && tsc -p src --emitDeclarationOnly && tsx scripts/post-build.mts", + "prepack": "yarn build", + "build": "tsc -p src --noEmit && yarn clean && tsup", "clean": "node scripts/clean.mjs", "typecheck": "tsc -p src --noEmit", "bump": "cliff-jumper", @@ -47,7 +48,6 @@ "@sapphire/eslint-config": "^5.0.5", "@sapphire/prettier-config": "^2.0.0", "@sapphire/ts-config": "^5.0.1", - "@types/node": "^20.14.10", "@typescript-eslint/eslint-plugin": "^7.14.1", "@typescript-eslint/parser": "^7.14.1", "@vitest/coverage-c8": "^0.33.0", @@ -59,7 +59,6 @@ "lint-staged": "^15.2.7", "prettier": "^3.3.2", "tsup": "^8.1.0", - "tsx": "^4.16.2", "typedoc": "^0.26.2", "typedoc-plugin-mdn-links": "^3.2.1", "typescript": "^5.5.2", diff --git a/scripts/post-build.mts b/scripts/post-build.mts deleted file mode 100644 index a616f4c..0000000 --- a/scripts/post-build.mts +++ /dev/null @@ -1,15 +0,0 @@ -import { copyFile, readFile, writeFile } from 'node:fs/promises'; - -const originalDTS = new URL('../dist/index.d.ts', import.meta.url); -const originalDTSMap = new URL('../dist/index.d.ts.map', import.meta.url); - -const esmDTS = new URL('../dist/index.d.mts', import.meta.url); -const esmDTSMap = new URL('../dist/index.d.mts.map', import.meta.url); - -await copyFile(originalDTS, esmDTS); - -const readMap = await readFile(originalDTSMap, 'utf-8'); -const parsedMap = JSON.parse(readMap); -parsedMap.file = 'index.d.mts'; - -await writeFile(esmDTSMap, JSON.stringify(parsedMap), 'utf-8'); diff --git a/src/index.ts b/src/index.ts index 83c35b4..5e3da46 100644 --- a/src/index.ts +++ b/src/index.ts @@ -220,7 +220,10 @@ export class AsyncEventEmitter< listener: AsyncEventEmitterListenerForEvent, K>, ): this; - public removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this { + public removeListener( + eventName: K, + listener: AsyncEventEmitterListenerForEvent, K>, + ): this { validateListener(listener); const events = this._events; @@ -448,7 +451,10 @@ export class AsyncEventEmitter< ...args: GetAsyncEventEmitterEventParameters, K> ): boolean; - public emit(eventName: string | symbol, ...args: any[]): boolean { + public emit( + eventName: K, + ...args: GetAsyncEventEmitterEventParameters, K> + ): boolean { let doError = eventName === 'error'; const events = this._events; @@ -1003,7 +1009,10 @@ function handleMaybeAsync(emitter: AsyncEventEmitter, result: any) { if (typeof the === 'function') { the.call(result, undefined, (error: any) => { - emitter.emit('error', error); + // Emit on next tick + setTimeout(() => { + emitter.emit('error', error); + }, 0); }); } diff --git a/tsup.config.ts b/tsup.config.ts index 67ded95..2654ed1 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -20,7 +20,7 @@ const sharedConfig: Options = { }, splitting: false, keepNames: true, - dts: false, + dts: true, sourcemap: true, treeshake: false, outDir: 'dist', diff --git a/yarn.lock b/yarn.lock index ee33d68..9c996da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1135,15 +1135,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.14.10": - version: 20.14.10 - resolution: "@types/node@npm:20.14.10" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/672892cf94d0d95cf052f11271990686a0fd204cd1e5fe7a4ef240e5315e06711765dc47b9ec98627d3adac18b8c92bb7e2d8db21d18faa20bc3e3203a143e79 - languageName: node - linkType: hard - "@types/parse-json@npm:^4.0.0": version: 4.0.0 resolution: "@types/parse-json@npm:4.0.0" @@ -1379,7 +1370,6 @@ __metadata: "@sapphire/eslint-config": "npm:^5.0.5" "@sapphire/prettier-config": "npm:^2.0.0" "@sapphire/ts-config": "npm:^5.0.1" - "@types/node": "npm:^20.14.10" "@typescript-eslint/eslint-plugin": "npm:^7.14.1" "@typescript-eslint/parser": "npm:^7.14.1" "@vitest/coverage-c8": "npm:^0.33.0" @@ -1391,7 +1381,6 @@ __metadata: lint-staged: "npm:^15.2.7" prettier: "npm:^3.3.2" tsup: "npm:^8.1.0" - tsx: "npm:^4.16.2" typedoc: "npm:^0.26.2" typedoc-plugin-mdn-links: "npm:^3.2.1" typescript: "npm:^5.5.2" @@ -2494,7 +2483,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4, esbuild@npm:~0.21.5": +"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4": version: 0.21.5 resolution: "esbuild@npm:0.21.5" dependencies: @@ -3106,15 +3095,6 @@ __metadata: languageName: node linkType: hard -"get-tsconfig@npm:^4.7.5": - version: 4.7.5 - resolution: "get-tsconfig@npm:4.7.5" - dependencies: - resolve-pkg-maps: "npm:^1.0.0" - checksum: 10/de7de5e4978354e8e6d9985baf40ea32f908a13560f793bc989930c229cc8d5c3f7b6b2896d8e43eb1a9b4e9e30018ef4b506752fd2a4b4d0dfee4af6841b119 - languageName: node - linkType: hard - "git-cliff-darwin-arm64@npm:1.4.0": version: 1.4.0 resolution: "git-cliff-darwin-arm64@npm:1.4.0" @@ -5147,13 +5127,6 @@ __metadata: languageName: node linkType: hard -"resolve-pkg-maps@npm:^1.0.0": - version: 1.0.0 - resolution: "resolve-pkg-maps@npm:1.0.0" - checksum: 10/0763150adf303040c304009231314d1e84c6e5ebfa2d82b7d94e96a6e82bacd1dcc0b58ae257315f3c8adb89a91d8d0f12928241cba2df1680fbe6f60bf99b0e - languageName: node - linkType: hard - "restore-cursor@npm:^2.0.0": version: 2.0.0 resolution: "restore-cursor@npm:2.0.0" @@ -5990,22 +5963,6 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.16.2": - version: 4.16.2 - resolution: "tsx@npm:4.16.2" - dependencies: - esbuild: "npm:~0.21.5" - fsevents: "npm:~2.3.3" - get-tsconfig: "npm:^4.7.5" - dependenciesMeta: - fsevents: - optional: true - bin: - tsx: dist/cli.mjs - checksum: 10/841ccbace3dc0c42704bb5c4cea47e1f4cd313aa4719fd4531e5ed40bb862b02349c76f7c56c53b64207eebbb1c2ac2e117482aabfbf197a30fbc0b2584b60be - languageName: node - linkType: hard - "type-check@npm:^0.4.0, type-check@npm:~0.4.0": version: 0.4.0 resolution: "type-check@npm:0.4.0" @@ -6116,13 +6073,6 @@ __metadata: languageName: node linkType: hard -"undici-types@npm:~5.26.4": - version: 5.26.5 - resolution: "undici-types@npm:5.26.5" - checksum: 10/0097779d94bc0fd26f0418b3a05472410408877279141ded2bd449167be1aed7ea5b76f756562cb3586a07f251b90799bab22d9019ceba49c037c76445f7cddd - languageName: node - linkType: hard - "unicorn-magic@npm:^0.1.0": version: 0.1.0 resolution: "unicorn-magic@npm:0.1.0"