Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit cts types #3093

Merged
merged 7 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
".": {
"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",
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
"typesVersions": {
">=5.0": {
"*": [
"dist/types/*"
".": [
"./dist/index.d.ts"
],
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
"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',
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
});
}
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 might or might not exist, depending on the runned scripts
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
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