From 84ec82231906554b3412be5ad7fd739da1b193c9 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Thu, 22 Jun 2023 13:10:44 +0200 Subject: [PATCH] fix: remove onSuccess tsup thing and add custom script instead --- fix-dts.mts | 23 +++++++++++++++++++++ package.json | 5 +++-- pnpm-lock.yaml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ tsup.config.ts | 20 ------------------ 4 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 fix-dts.mts diff --git a/fix-dts.mts b/fix-dts.mts new file mode 100644 index 0000000..3f3a7e1 --- /dev/null +++ b/fix-dts.mts @@ -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) diff --git a/package.json b/package.json index 235625d..ca6005d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d681ec4..4963d99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ devDependencies: tsup: specifier: ^6.6.3 version: 6.6.3(ts-node@10.9.1)(typescript@4.9.5) + tsx: + specifier: ^3.12.7 + version: 3.12.7 typescript: specifier: ^4.9.5 version: 4.9.5 @@ -471,6 +474,27 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true + /@esbuild-kit/cjs-loader@2.4.2: + resolution: {integrity: sha512-BDXFbYOJzT/NBEtp71cvsrGPwGAMGRB/349rwKuoxNSiKjPraNNnlK6MIIabViCjqZugu6j+xeMDlEkWdHHJSg==} + dependencies: + '@esbuild-kit/core-utils': 3.1.0 + get-tsconfig: 4.6.0 + dev: true + + /@esbuild-kit/core-utils@3.1.0: + resolution: {integrity: sha512-Uuk8RpCg/7fdHSceR1M6XbSZFSuMrxcePFuGgyvsBn+u339dk5OeL4jv2EojwTN2st/unJGsVm4qHWjWNmJ/tw==} + dependencies: + esbuild: 0.17.12 + source-map-support: 0.5.21 + dev: true + + /@esbuild-kit/esm-loader@2.5.5: + resolution: {integrity: sha512-Qwfvj/qoPbClxCRNuac1Du01r9gvNOT+pMYtJDapfB1eoGN1YlJ1BixLyL9WVENRx5RXgNLdfYdx/CuswlGhMw==} + dependencies: + '@esbuild-kit/core-utils': 3.1.0 + get-tsconfig: 4.6.0 + dev: true + /@esbuild/android-arm64@0.17.12: resolution: {integrity: sha512-WQ9p5oiXXYJ33F2EkE3r0FRDFVpEdcDiwNX3u7Xaibxfx6vQE0Sb8ytrfQsA5WO6kDn6mDfKLh6KrPBjvkk7xA==} engines: {node: '>=12'} @@ -1511,6 +1535,10 @@ packages: wcwidth: 1.0.1 dev: true + /buffer-from@1.1.2: + resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + dev: true + /bundle-require@4.0.1(esbuild@0.17.12): resolution: {integrity: sha512-9NQkRHlNdNpDBGmLpngF3EFDcwodhMUuLz9PaWYciVcQF9SE4LFjM2DB/xV1Li5JiuDMv7ZUWuC3rGbqR0MAXQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -2209,6 +2237,12 @@ packages: get-intrinsic: 1.2.0 dev: true + /get-tsconfig@4.6.0: + resolution: {integrity: sha512-lgbo68hHTQnFddybKbbs/RDRJnJT5YyGy2kQzVwbq+g67X73i+5MVTval34QxGkOe9X5Ujf1UYpCaphLyltjEg==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: true + /git-raw-commits@2.0.11: resolution: {integrity: sha512-VnctFhw+xfj8Va1xtfEqCUD2XDrbAPSJx+hSrE5K7fGdjZruW7XV+QOrN7LF/RJyvspRiD2I0asWsxFp0ya26A==} engines: {node: '>=10'} @@ -3455,6 +3489,10 @@ packages: global-dirs: 0.1.1 dev: true + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: true + /resolve@1.22.1: resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} hasBin: true @@ -3586,6 +3624,13 @@ packages: engines: {node: '>=0.10.0'} dev: true + /source-map-support@0.5.21: + resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} + dependencies: + buffer-from: 1.1.2 + source-map: 0.6.1 + dev: true + /source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} @@ -3928,6 +3973,17 @@ packages: - ts-node dev: true + /tsx@3.12.7: + resolution: {integrity: sha512-C2Ip+jPmqKd1GWVQDvz/Eyc6QJbGfE7NrR3fx5BpEHMZsEHoIxHL1j+lKdGobr8ovEyqeNkPLSKp6SCSOt7gmw==} + hasBin: true + dependencies: + '@esbuild-kit/cjs-loader': 2.4.2 + '@esbuild-kit/core-utils': 3.1.0 + '@esbuild-kit/esm-loader': 2.5.5 + optionalDependencies: + fsevents: 2.3.2 + dev: true + /tty-table@4.1.6: resolution: {integrity: sha512-kRj5CBzOrakV4VRRY5kUWbNYvo/FpOsz65DzI5op9P+cHov3+IqPbo1JE1ZnQGkHdZgNFDsrEjrfqqy/Ply9fw==} engines: {node: '>=8.0.0'} diff --git a/tsup.config.ts b/tsup.config.ts index 0bf2d3e..5e4af43 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -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