Skip to content

Commit

Permalink
fix: emit cts types (#3093)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Sep 14, 2024
1 parent 18ab2c7 commit 53ef42c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 23 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/apidocs/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { Project } from 'ts-morph';
export function getProject(options: Partial<ProjectOptions> = {}): Project {
return new Project({
...options,
tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.build.json',
tsConfigFilePath: options.tsConfigFilePath ?? 'tsconfig.json',
});
}
2 changes: 2 additions & 0 deletions test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 0 additions & 16 deletions tsconfig.build.json

This file was deleted.

5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 53ef42c

Please sign in to comment.