Skip to content

Commit 53ef42c

Browse files
authored
fix: emit cts types (#3093)
1 parent 18ab2c7 commit 53ef42c

8 files changed

Lines changed: 29 additions & 37 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
CYPRESS_INSTALL_BINARY: 0
175175

176176
- name: Build types
177-
run: pnpm run build:types
177+
run: pnpm run build
178178

179179
- name: Check scripts
180180
run: pnpm run ts-check

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This is a shorthand for running the following scripts in order:
2424
- `pnpm run lint` - runs [ESLint](https://github.com/eslint/eslint) to enforce project code standards
2525
- `pnpm run build:clean` - removes artifacts from previous builds
2626
- `pnpm run build:code` - builds the code, both CommonJS and ESM versions
27-
- `pnpm run build:types` - builds the TypeScript type definitions
2827
- `pnpm run test:update-snapshots` - runs all tests, and updates any snapshots if needed
2928
- `pnpm run ts-check` - checks that there are no TypeScript errors in any files
3029

package.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"clean": "rimraf coverage .eslintcache dist docs/.vitepress/cache docs/.vitepress/dist node_modules",
77
"build:clean": "rimraf dist",
88
"build:code": "tsup-node",
9-
"build:types": "tsc --project tsconfig.build.json",
10-
"build": "run-s build:clean build:code build:types",
9+
"build": "run-s build:clean build:code",
1110
"generate": "run-s generate:locales generate:api-docs",
1211
"generate:api-docs": "tsx ./scripts/apidocs.ts",
1312
"generate:locales": "tsx ./scripts/generate-locales.ts",
@@ -65,26 +64,37 @@
6564
"type": "module",
6665
"exports": {
6766
".": {
68-
"types": "./dist/types/index.d.ts",
69-
"import": "./dist/index.js",
70-
"require": "./dist/index.cjs",
71-
"default": "./dist/index.js"
67+
"require": {
68+
"types": "./dist/index.d.cts",
69+
"default": "./dist/index.cjs"
70+
},
71+
"default": {
72+
"types": "./dist/index.d.ts",
73+
"default": "./dist/index.js"
74+
}
7275
},
7376
"./locale/*": {
74-
"types": "./dist/types/locale/*.d.ts",
75-
"import": "./dist/locale/*.js",
76-
"require": "./dist/locale/*.cjs",
77-
"default": "./dist/locale/*.js"
77+
"require": {
78+
"types": "./dist/locale/*.d.cts",
79+
"default": "./dist/locale/*.cjs"
80+
},
81+
"default": {
82+
"types": "./dist/locale/*.d.ts",
83+
"default": "./dist/locale/*.js"
84+
}
7885
},
7986
"./package.json": "./package.json"
8087
},
8188
"main": "dist/index.cjs",
8289
"module": "dist/index.js",
83-
"types": "index.d.ts",
90+
"types": "dist/index.d.ts",
8491
"typesVersions": {
8592
">=5.0": {
86-
"*": [
87-
"dist/types/*"
93+
".": [
94+
"./dist/index.d.ts"
95+
],
96+
"locale/*": [
97+
"./dist/locale/*.d.ts"
8898
]
8999
}
90100
},

scripts/apidocs/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { Project } from 'ts-morph';
44
export function getProject(options: Partial<ProjectOptions> = {}): Project {
55
return new Project({
66
...options,
7-
tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.build.json',
7+
tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.json',
88
});
99
}

test/faker.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe('faker', () => {
1818
.filter((key) => typeof console[key] === 'function')
1919
.map((methodName) => vi.spyOn(console, methodName));
2020

21+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22+
// @ts-ignore: Types may or may not exist, depending on whether the project was built first.
2123
const file: unknown = await import('..');
2224
expect(file).toBeDefined();
2325

tsconfig.build.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
22
"compilerOptions": {
33
"target": "ESNext",
4-
"moduleResolution": "node",
4+
"moduleResolution": "Bundler",
55
"module": "ESNext",
66
"strict": true,
77
"noEmit": true,
8-
"declaration": true,
98
"stripInternal": true,
109
"verbatimModuleSyntax": true,
11-
12-
// These are configs specifically for !build and have to be reverted in the tsconfig.build.json
1310
"skipLibCheck": true,
1411
"allowSyntheticDefaultImports": true,
1512
"resolveJsonModule": true

tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
clean: true,
1111
format: ['esm', 'cjs'],
1212
target: ['es2022', 'node18'],
13-
dts: false, // will be generated with the "build:types" script
13+
dts: true,
1414
minify: true,
1515
sourcemap: false,
1616
splitting: true,

0 commit comments

Comments
 (0)