Switch to a solution-style TypeScript configuration
Switch to a solution-style TypeScript configuration in the root
directory and add TypeScript configurations to the individual packages.
This change brings a few benefits:
- Each package emits its own type declarations into its path.
- The TypeScript compiler can do incremental builds of the declarations.
- Automatic imports between packages resolve correcly as package imports
rather than deep imports.
diff --git a/.gitignore b/.gitignore
index c159859..95c3670 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
+*.d.ts
+*.d.ts.map
.nyc_output
coverage
node_modules
+tsconfig.tsbuildinfo
/web/dist
/packages/*/LICENSE
/packages/*/NOTICE
diff --git a/package.json b/package.json
index a9496ae..ebc7380 100644
--- a/package.json
+++ b/package.json
@@ -15,11 +15,12 @@
]
},
"scripts": {
- "build": "yarn run build:cjs && yarn run build:esm && yarn run build:misc",
+ "build": "yarn run build:cjs && yarn run build:esm && yarn run build:misc && yarn run build:types",
"build:babel": "lerna exec --parallel -- babel --extensions '.js,.ts' --root-mode upward",
"build:cjs": "cross-env BABEL_ENV=cjs yarn build:babel -d lib src",
"build:esm": "cross-env BABEL_ENV=esm yarn build:babel -d esm src",
"build:misc": "lerna exec -- cp ../../LICENSE ../../NOTICE .",
+ "build:types": "tsc --build",
"clean": "lerna exec -- rimraf LICENSE NOTICE esm lib",
"lint": "eslint .",
"prepare": "lerna run prepare",
diff --git a/packages/dom/package.json b/packages/dom/package.json
index c64f7ce..be12524 100644
--- a/packages/dom/package.json
+++ b/packages/dom/package.json
@@ -9,8 +9,9 @@
},
"license": "Apache-2.0",
"author": "Apache Software Foundation",
- "main": "lib/index.js",
- "module": "esm/index.js",
+ "main": "./lib/index.js",
+ "module": "./esm/index.js",
+ "types": "./src/types.d.ts",
"dependencies": {
"@babel/runtime-corejs3": "^7.8.7",
"cartesian": "^1.0.1",
diff --git a/@types/cartesian/index.d.ts b/packages/dom/src/types/cartesian.d.ts
similarity index 100%
rename from @types/cartesian/index.d.ts
rename to packages/dom/src/types/cartesian.d.ts
diff --git a/@types/dom-seek/index.d.ts b/packages/dom/src/types/dom-seek.d.ts
similarity index 100%
rename from @types/dom-seek/index.d.ts
rename to packages/dom/src/types/dom-seek.d.ts
diff --git a/packages/dom/tsconfig.json b/packages/dom/tsconfig.json
new file mode 100644
index 0000000..afffb53
--- /dev/null
+++ b/packages/dom/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.base.json",
+ "compilerOptions": {
+ "lib": ["dom", "dom.iterable", "esnext"]
+ }
+}
diff --git a/packages/selector/package.json b/packages/selector/package.json
index 2617dad..fc32323 100644
--- a/packages/selector/package.json
+++ b/packages/selector/package.json
@@ -9,8 +9,9 @@
},
"license": "Apache-2.0",
"author": "Apache Software Foundation",
- "main": "lib/index.js",
- "module": "esm/index.js",
+ "main": "./lib/index.js",
+ "module": "./esm/index.js",
+ "types": "./src/index.d.ts",
"dependencies": {
"@babel/runtime-corejs3": "^7.8.7",
"core-js": "^3.6.4"
diff --git a/packages/selector/tsconfig.json b/packages/selector/tsconfig.json
new file mode 100644
index 0000000..9536a0f
--- /dev/null
+++ b/packages/selector/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.base.json"
+}
diff --git a/tsconfig.base.json b/tsconfig.base.json
new file mode 100644
index 0000000..b8b3d12
--- /dev/null
+++ b/tsconfig.base.json
@@ -0,0 +1,16 @@
+{
+ "compilerOptions": {
+ "allowSyntheticDefaultImports": true,
+ "baseUrl": "./",
+ "composite": true,
+ "declaration": true,
+ "declarationMap": true,
+ "downlevelIteration": true,
+ "emitDeclarationOnly": true,
+ "isolatedModules": true,
+ "lib": ["esnext"],
+ "moduleResolution": "node",
+ "strict": true,
+ "target": "es2017"
+ }
+}
diff --git a/tsconfig.json b/tsconfig.json
index 78ff87a..9a05b84 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,30 +1,11 @@
{
- "compilerOptions": {
- "allowSyntheticDefaultImports": true,
- "baseUrl": ".",
- "downlevelIteration": true,
- "isolatedModules": true,
- "lib": [
- "dom",
- "dom.iterable",
- "esnext",
- ],
- "moduleResolution": "node",
- "noEmit": true,
- "paths": {
- "@annotator/*": ["packages/*/src"]
+ "files": [],
+ "references": [
+ {
+ "path": "./packages/dom/tsconfig.json"
},
- "strict": true,
- "target": "es2017",
- "typeRoots": [
- "@types",
- "node_modules/@types"
- ]
- },
- "include": [
- "@types",
- "packages/*/src",
- "packages/*/test",
- "test"
- ]
+ {
+ "path": "./packages/selector/tsconfig.json"
+ }
+ ],
}