From 53ef42cc192996a0e09bba9d5f5f8a70a7932275 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sat, 14 Sep 2024 21:44:33 +0200 Subject: [PATCH] fix: emit cts types (#3093) --- .github/workflows/ci.yml | 2 +- CONTRIBUTING.md | 1 - package.json | 36 +++++++++++++++++++++++------------- scripts/apidocs/project.ts | 2 +- test/faker.spec.ts | 2 ++ tsconfig.build.json | 16 ---------------- tsconfig.json | 5 +---- tsup.config.ts | 2 +- 8 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 tsconfig.build.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be5496da023..a5463975b38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,7 +174,7 @@ jobs: CYPRESS_INSTALL_BINARY: 0 - name: Build types - run: pnpm run build:types + run: pnpm run build - name: Check scripts run: pnpm run ts-check diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 487c99e0b03..c3982b27215 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,6 @@ This is a shorthand for running the following scripts in order: - `pnpm run lint` - runs [ESLint](https://github.com/eslint/eslint) to enforce project code standards - `pnpm run build:clean` - removes artifacts from previous builds - `pnpm run build:code` - builds the code, both CommonJS and ESM versions -- `pnpm run build:types` - builds the TypeScript type definitions - `pnpm run test:update-snapshots` - runs all tests, and updates any snapshots if needed - `pnpm run ts-check` - checks that there are no TypeScript errors in any files diff --git a/package.json b/package.json index cc3011e66b8..41b1da55a6a 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "clean": "rimraf coverage .eslintcache dist docs/.vitepress/cache docs/.vitepress/dist node_modules", "build:clean": "rimraf dist", "build:code": "tsup-node", - "build:types": "tsc --project tsconfig.build.json", - "build": "run-s build:clean build:code build:types", + "build": "run-s build:clean build:code", "generate": "run-s generate:locales generate:api-docs", "generate:api-docs": "tsx ./scripts/apidocs.ts", "generate:locales": "tsx ./scripts/generate-locales.ts", @@ -65,26 +64,37 @@ "type": "module", "exports": { ".": { - "types": "./dist/types/index.d.ts", - "import": "./dist/index.js", - "require": "./dist/index.cjs", - "default": "./dist/index.js" + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./locale/*": { - "types": "./dist/types/locale/*.d.ts", - "import": "./dist/locale/*.js", - "require": "./dist/locale/*.cjs", - "default": "./dist/locale/*.js" + "require": { + "types": "./dist/locale/*.d.cts", + "default": "./dist/locale/*.cjs" + }, + "default": { + "types": "./dist/locale/*.d.ts", + "default": "./dist/locale/*.js" + } }, "./package.json": "./package.json" }, "main": "dist/index.cjs", "module": "dist/index.js", - "types": "index.d.ts", + "types": "dist/index.d.ts", "typesVersions": { ">=5.0": { - "*": [ - "dist/types/*" + ".": [ + "./dist/index.d.ts" + ], + "locale/*": [ + "./dist/locale/*.d.ts" ] } }, diff --git a/scripts/apidocs/project.ts b/scripts/apidocs/project.ts index c63bad8e2d6..9cf5ce10844 100644 --- a/scripts/apidocs/project.ts +++ b/scripts/apidocs/project.ts @@ -4,6 +4,6 @@ import { Project } from 'ts-morph'; export function getProject(options: Partial = {}): Project { return new Project({ ...options, - tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.build.json', + tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.json', }); } diff --git a/test/faker.spec.ts b/test/faker.spec.ts index 749e850110d..6d928d63652 100644 --- a/test/faker.spec.ts +++ b/test/faker.spec.ts @@ -18,6 +18,8 @@ describe('faker', () => { .filter((key) => typeof console[key] === 'function') .map((methodName) => vi.spyOn(console, methodName)); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: Types may or may not exist, depending on whether the project was built first. const file: unknown = await import('..'); expect(file).toBeDefined(); diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 0d07a4fc569..00000000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "target": "ES2022", - "noEmit": false, - "emitDeclarationOnly": true, - "rootDir": "src", - "outDir": "dist/types", - - // This negates what is set in the extended tsconfig.json - "skipLibCheck": false, - "allowSyntheticDefaultImports": false, - "resolveJsonModule": false - }, - "include": ["src"] -} diff --git a/tsconfig.json b/tsconfig.json index cc4809dab5d..c8ffb862324 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,12 @@ { "compilerOptions": { "target": "ESNext", - "moduleResolution": "node", + "moduleResolution": "Bundler", "module": "ESNext", "strict": true, "noEmit": true, - "declaration": true, "stripInternal": true, "verbatimModuleSyntax": true, - - // These are configs specifically for !build and have to be reverted in the tsconfig.build.json "skipLibCheck": true, "allowSyntheticDefaultImports": true, "resolveJsonModule": true diff --git a/tsup.config.ts b/tsup.config.ts index d9b3970f0a0..214eb718644 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig({ clean: true, format: ['esm', 'cjs'], target: ['es2022', 'node18'], - dts: false, // will be generated with the "build:types" script + dts: true, minify: true, sourcemap: false, splitting: true,