WordPress/gutenberg

Typescript - introduce new @wordpress/ts-config package for outside usage

Open

#48954 opened on Mar 9, 2023

View on GitHub
 (4 comments) (23 reactions) (0 assignees)JavaScript (9,607 stars) (3,893 forks)batch import
Developer ExperienceGood First IssueNeeds Dev[Type] Enhancementnpm Packages

Description

What problem does this address?

Right now Gutenberg has ~30 @wordpress/*-packages which make use of the tsconfig.base.json by loading it via relative path:

{
	"extends": "../../tsconfig.base.json",
}

See also: https://github.com/search?q=repo%3AWordPress%2Fgutenberg+tsconfig.base.json+language%3A%22JSON+with+Comments%22&type=code&l=JSON+with+Comments

While all other technologies used in wordpress/scripts are having it's own package, Typescript in Gutenberg is still not at a stage where it can be even re-used from other Plugin/Theme/Package-Developers.

For example we have own packages for:

  • @wordpress/babel-preset-default
  • @wordpress/browserslist-config
  • @wordpress/eslint-plugin
  • @wordpress/jest-preset-default
  • @wordpress/npm-package-json-lint-config
  • @wordpress/postcss-plugins-preset
  • @wordpress/prettier-config
  • @wordpress/stylelint-config

What is your proposed solution?

I would suggest to introduce a new @wordpress/ts-config (or @wordpress/typescript-preset - naming is not consistent currently, it's either config, preset, default or plugin?!), which in first step contains the tsconfig.base.json.

This way we could achieve following:

  1. Update all Gutenberg packages to replace relative path packages: https://github.com/search?q=repo%3AWordPress%2Fgutenberg+tsconfig.base.json+language%3A%22JSON+with+Comments%22&type=code&l=JSON+with+Comments
  2. Allow external packages/plugins/themes to load this config via package.json and extend it locally to share the same rules as Gutenberg.
  3. Similar to the @wordpress/eslint-plugin we could also introduce later on recommended and strict variations.

tsconfig.json:

{
	"extends": "@wordpress/ts-config/tsconfig.base.json",
}

Links/Resources

Contributor guide