From 19cd9c4033035916ddf9a7e67fb23b92d499085e Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Fri, 6 Sep 2024 14:26:20 +0200 Subject: [PATCH 1/5] fix: emit cts types --- .github/workflows/ci.yml | 3 --- CONTRIBUTING.md | 1 - package.json | 34 ++++++++++++++++++++++------------ scripts/apidocs/project.ts | 2 +- tsconfig.json | 2 +- tsup.config.ts | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be5496da023..317e98facce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,9 +173,6 @@ jobs: env: CYPRESS_INSTALL_BINARY: 0 - - name: Build types - run: pnpm run build:types - - 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..7c90864b22c 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,16 +64,24 @@ "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" }, @@ -83,8 +90,11 @@ "types": "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/tsconfig.json b/tsconfig.json index cc4809dab5d..8ad6af63fbe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ESNext", - "moduleResolution": "node", + "moduleResolution": "Node", "module": "ESNext", "strict": true, "noEmit": 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, From ecf9ff2b8cde374c1bd9de7f4b513140d4037120 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 7 Sep 2024 18:09:10 +0200 Subject: [PATCH 2/5] revert types creation --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 317e98facce..a5463975b38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,6 +173,9 @@ jobs: env: CYPRESS_INSTALL_BINARY: 0 + - name: Build types + run: pnpm run build + - name: Check scripts run: pnpm run ts-check From 49745a6cea203a45387c45a8c7dec684635ba881 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Mon, 9 Sep 2024 22:42:25 +0200 Subject: [PATCH 3/5] remove tsconfig.build --- test/faker.spec.ts | 2 ++ tsconfig.build.json | 16 ---------------- tsconfig.json | 5 +---- 3 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 tsconfig.build.json diff --git a/test/faker.spec.ts b/test/faker.spec.ts index 749e850110d..2d2458d1cb5 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 might or might not exist, depending on the runned scripts 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 8ad6af63fbe..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 From 69614a2a309dab799cf04a08d4329dd20ec967a4 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Tue, 10 Sep 2024 16:48:09 +0200 Subject: [PATCH 4/5] fix types field --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7c90864b22c..41b1da55a6a 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ }, "main": "dist/index.cjs", "module": "dist/index.js", - "types": "index.d.ts", + "types": "dist/index.d.ts", "typesVersions": { ">=5.0": { ".": [ From e07f248df8815b54a23ee36d1bb527cbe3cae052 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 12 Sep 2024 16:35:54 +0200 Subject: [PATCH 5/5] Update test/faker.spec.ts Co-authored-by: ST-DDT --- test/faker.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/faker.spec.ts b/test/faker.spec.ts index 2d2458d1cb5..6d928d63652 100644 --- a/test/faker.spec.ts +++ b/test/faker.spec.ts @@ -19,7 +19,7 @@ describe('faker', () => { .map((methodName) => vi.spyOn(console, methodName)); // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: Types might or might not exist, depending on the runned scripts + // @ts-ignore: Types may or may not exist, depending on whether the project was built first. const file: unknown = await import('..'); expect(file).toBeDefined();