Skip to content

Commit

Permalink
fix: built types were wrong, causing inference issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Jul 9, 2024
1 parent ce4e323 commit 28e9247
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 11 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "vitest run",
"test:watch": "vitest",
"update": "yarn upgrade-interactive",
"build": "tsc -p src --noEmit && tsup",
"build": "tsc -p src --noEmit && yarn clean && tsup && tsc -p src --emitDeclarationOnly && tsx scripts/post-build.mts",
"clean": "node scripts/clean.mjs",
"typecheck": "tsc -p src --noEmit",
"bump": "cliff-jumper",
Expand All @@ -47,6 +47,7 @@
"@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",
Expand All @@ -58,6 +59,7 @@
"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",
Expand Down
15 changes: 15 additions & 0 deletions scripts/post-build.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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');
24 changes: 24 additions & 0 deletions tests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,27 @@ declare const t2: AsyncEventEmitter<Events>;
const l = t2.listeners('baz');
// ^?
}

enum EventsEnum {
Test1 = 'test1',
}

interface Events2 {
[EventsEnum.Test1]: [bar: string];
}

declare const emitterWithEnum: AsyncEventEmitter<Events2>;

emitterWithEnum.on(EventsEnum.Test1, (bar) => {
console.log(bar);
});

class Extension extends AsyncEventEmitter<Events2> {
public emitCustom() {
// this.emit();

// this.on();

this.emit(EventsEnum.Test1, 123);
}
}
18 changes: 9 additions & 9 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const sharedConfig: Options = {
terserOptions: {
mangle: false,
keep_classnames: true,
keep_fnames: true
keep_fnames: true,
},
splitting: false,
keepNames: true,
dts: true,
dts: false,
sourcemap: true,
treeshake: false,
outDir: 'dist',
Expand All @@ -44,23 +44,23 @@ const sharedConfig: Options = {

await writeFile(resolve(process.cwd(), file.name), newContent, 'utf-8');
}
}
}
]
},
},
],
};

export default [
defineConfig({
...sharedConfig,
format: 'cjs',
outExtension: () => ({ js: '.cjs' })
outExtension: () => ({ js: '.cjs' }),
}),
defineConfig({
...sharedConfig,
format: 'esm'
format: 'esm',
}),
defineConfig({
...sharedConfig,
format: 'iife'
})
format: 'iife',
}),
];
52 changes: 51 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,15 @@ __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"
Expand Down Expand Up @@ -1370,6 +1379,7 @@ __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"
Expand All @@ -1381,6 +1391,7 @@ __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"
Expand Down Expand Up @@ -2483,7 +2494,7 @@ __metadata:
languageName: node
linkType: hard

"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4":
"esbuild@npm:^0.21.3, esbuild@npm:^0.21.4, esbuild@npm:~0.21.5":
version: 0.21.5
resolution: "esbuild@npm:0.21.5"
dependencies:
Expand Down Expand Up @@ -3095,6 +3106,15 @@ __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"
Expand Down Expand Up @@ -5127,6 +5147,13 @@ __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"
Expand Down Expand Up @@ -5963,6 +5990,22 @@ __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"
Expand Down Expand Up @@ -6073,6 +6116,13 @@ __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"
Expand Down

0 comments on commit 28e9247

Please sign in to comment.