Skip to content

Commit

Permalink
fix: remove onSuccess tsup thing and add custom script instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tefkah committed Jun 22, 2023
1 parent 62ba1cc commit 84ec822
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 22 deletions.
23 changes: 23 additions & 0 deletions fix-dts.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { copyFile } from 'fs/promises'
import readdirp from 'readdirp'

console.log('Fixing .d.ts files...')

const dir = await readdirp.promise(new URL('./dist', import.meta.url).pathname)
// copy each .d.ts file to a .d.cts file
await Promise.all(
dir

.filter((file) => file.path.endsWith('.d.ts'))
.map(async (file) => {
await copyFile(
new URL(`./dist/${file.path}`, import.meta.url).pathname,
new URL(`./dist/${file.path.replace('.ts', '')}.cts`, import.meta.url)
.pathname
)
console.log(`Copied ${file.path} to ${file.path.replace('.ts', '')}.cts`)
})
)

console.log(`✅ Fixed .d.ts files`)
process.exit(0)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"build": "tsup && tsx fix-dts.mts",
"lint": "tsc",
"ci": "rm -rf dist && pnpm run build && pnpm run lint && pnpm run test",
"ci": "rm -rf dist && pnpm run lint && pnpm run test && pnpm run build ",
"prepublish": "pnpm run ci",
"test": "vitest run",
"dev": "vitest",
Expand Down Expand Up @@ -69,6 +69,7 @@
"readdirp": "^3.6.0",
"svelte": "^3.57.0",
"tsup": "^6.6.3",
"tsx": "^3.12.7",
"typescript": "^4.9.5",
"vite": "^4.1.4",
"vitest": "^0.29.2",
Expand Down
56 changes: 56 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ const config = defineConfig({
clean: true,
bundle: false,
entry: ['src'],
onSuccess: async () => {
const dir = await readdirp.promise(
new URL('./dist', import.meta.url).pathname
)
// copy each .d.ts file to a .d.cts file
await Promise.all(
dir

.filter((file) => file.path.endsWith('.d.ts'))
.map(async (file) => {
await copyFile(
new URL(`./dist/${file.path}`, import.meta.url).pathname,
new URL(
`./dist/${file.path.replace('.ts', '')}.cts`,
import.meta.url
).pathname
)
})
)
},
})

export default config

0 comments on commit 84ec822

Please sign in to comment.