-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: Output package type declarations (#18942)
Output TypeScript declaration files (`.d.ts`) from package sources and expose them with published packages. - Upgrade to `typescript@3.8`. - Add bin for typechecking changed packages. - Remove `lint-types` script, replaced by `build:package-types`. - Restructure TypeScript configuration: - One base `tsconfig.base.json` that packages extend. This is not a project, it's only for extension. - A root `tsconfig.json` that references all typed packages. - Typed packages output their types at `build-types` and expose them in the published package. - Use _project references_ to work within the monorepo. See https://www.typescriptlang.org/docs/handbook/project-references.html - Fix/improve some type issues. TypeScript declaration files will be managed via `tsc --build`, the TypeScript compiler build tool for composite projects. `tsc` will manage determine the correct order to build packages so that dependencies are satisfied and rebuild only when necessary. Additional packages can opt-in to typing by (this is documented in a new section in `packages/README.md`): - Adding `tsconfig.json` in their package directory. - Updating their `package.json` to point to the types: `{ "types": "build-types" }`. - Adding a reference to the root `tsconfig.json`.
- Loading branch information
Showing
52 changed files
with
472 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const _ = require( 'lodash' ); | ||
const path = require( 'path' ); | ||
const fs = require( 'fs' ); | ||
const execa = require( 'execa' ); | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const repoRoot = path.join( __dirname, '..', '..' ); | ||
const tscPath = path.join( repoRoot, 'node_modules', '.bin', 'tsc' ); | ||
|
||
// lint-staged passes full paths to staged changes | ||
const changedFiles = process.argv.slice( 2 ); | ||
|
||
// Transform changed files to package directories containing tsconfig.json | ||
const changedPackages = _.uniq( | ||
changedFiles.map( ( fullPath ) => { | ||
const relativePath = path.relative( repoRoot, fullPath ); | ||
return path.join( ...relativePath.split( path.sep ).slice( 0, 2 ) ); | ||
} ) | ||
).filter( ( packageRoot ) => | ||
fs.existsSync( path.join( packageRoot, 'tsconfig.json' ) ) | ||
); | ||
|
||
try { | ||
execa.sync( tscPath, [ '--build', ...changedPackages ] ); | ||
} catch ( err ) { | ||
console.error( err.stdout ); | ||
process.exitCode = 1; | ||
} | ||
|
||
/* eslint-enable no-console */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"target": "ES6", | ||
"lib": [ "ES6", "ES2020.string" ], | ||
"rootDir": ".", | ||
"declarationMap": false, | ||
|
||
// We're not interested in the output, but we must generate | ||
// something as part of a composite project. Use the | ||
// ignored `.cache` file to hide tsbuildinfo and d.ts files. | ||
"outDir": ".cache" | ||
}, | ||
"files": [ "./api-docs/update-api-docs.js" ] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.