Skip to content

Commit

Permalink
Properly configure TypeScript
Browse files Browse the repository at this point in the history
The types of the language service are emitted to the `types` directory.
The base `tsconfig` is split off from the solution file. As a result the
`include` / `exclude` options are no longer needed. `declarationMap` is
enabled, so editors can use _Go to Source Definition_.
  • Loading branch information
remcohaszing committed Mar 5, 2024
1 parent 4bc1a86 commit 4b354bb
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.d.ts
*.d.mts
*.log
*.tgz
*.tsbuildinfo
Expand All @@ -8,3 +6,4 @@
dist/
node_modules/
out/
types/
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"prettier": true,
"rules": {
"max-params": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/naming-convention": "off",
"unicorn/prevent-abbreviations": "off"
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/language-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": "..",
"include": ["**/*.js", "package.json"],
"exclude": ["coverage/", "node_modules/"],
"extends": "../../tsconfig.base.json",
"references": [{"path": "../language-service"}],
"compilerOptions": {
"noEmit": true,
Expand Down
15 changes: 11 additions & 4 deletions packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
"author": "Remco Haszing <remcohaszing@gmail.com>",
"funding": "https://opencollective.com/unified",
"license": "MIT",
"exports": "./index.js",
"exports": {
".": {
"types": "./types/index.d.ts",
"default": "./index.js"
}
},
"files": [
"*.d.ts",
"*.js",
"lib"
"index.js",
"lib",
"types",
"!types/test",
"!*.tsbuildinfo"
],
"keywords": [
"IntelliSense",
Expand Down
7 changes: 3 additions & 4 deletions packages/language-service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "..",
"include": ["**/*.js", "./types.d.ts"],
"exclude": ["coverage/", "node_modules/"],
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"outDir": "types"
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/**
* @internal
*/
declare module 'estree' {
export interface BaseNode {
interface BaseNode {
start: number
end: number
}
}

/**
* @internal
*/
declare module 'mdast' {
export interface TOML extends Literal {
interface TOML extends Literal {
type: 'toml'
}

export interface RootContentMap {
interface RootContentMap {
toml: TOML
}
}

export {}
10 changes: 1 addition & 9 deletions packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@
{"path": "./language-server"},
{"path": "./language-service"},
{"path": "./vscode-mdx"}
],
"compilerOptions": {
"checkJs": true,
"composite": true,
"lib": ["es2021"],
"module": "node16",
"strict": true,
"target": "es2021"
}
]
}
8 changes: 4 additions & 4 deletions packages/vscode-mdx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "..",
"include": ["**/*.js"],
"exclude": ["coverage/", "node_modules/", "out/"],
"extends": "../../tsconfig.base.json",
"references": [{"path": "../language-service"}],
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"noEmit": true
"noEmit": true,
"skipLibCheck": true
}
}
12 changes: 12 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"checkJs": true,
"composite": true,
"lib": ["es2021"],
"module": "node16",
"moduleDetection": "force",
"strict": true,
"stripInternal": true,
"target": "es2021"
}
}

0 comments on commit 4b354bb

Please sign in to comment.