Skip to content

Commit

Permalink
feat: add typescript config
Browse files Browse the repository at this point in the history
  • Loading branch information
rellafella committed Feb 17, 2025
1 parent 89a67dd commit b66f095
Show file tree
Hide file tree
Showing 12 changed files with 1,834 additions and 75 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ publish-branch=main
# Required for using @envsa/shared-config with pnpm
public-hoist-pattern[]=@envsa/browserslist-config
public-hoist-pattern[]=@envsa/repo-config
public-hoist-pattern[]=@envsa/typescript-config
public-hoist-pattern[]=*cspell*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*mdat*
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@
"typescript": "~5.7.3",
"vitest": "^3.0.5",
"yargs": "^17.7.2"
},
"pnpm": {
"overrides": {
"eslint-plugin-markdown": "^5.1.0"
}
}
}
23 changes: 23 additions & 0 deletions packages/typescript-config/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2024 Liam Rella

Based on the MIT-licensed "@kitschpatrol/shared-config" project by Eric Mika

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions packages/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@envsa/typescript-config",
"version": "8.2.0",
"type": "module",
"description": "TypeScript configuration for @envsa/shared-config.",
"repository": {
"type": "git",
"url": "[email protected]:envsa/shared-config.git",
"directory": "packages/typescript-config"
},
"homepage": "https://github.com/envsa/shared-config/packages/typescript-config",
"bugs": {
"url": "https://github.com/envsa/shared-config/issues",
"email": "[email protected]"
},
"author": {
"name": "Liam Rella",
"email": "[email protected]",
"url": "https://github.com/rellafella"
},
"license": "MIT",
"engines": {
"node": ">=22.0.0",
"pnpm": ">=10.0.0"
},
"bin": {
"envsa-typescript": "bin/cli.js"
},
"exports": {
".": "./tsconfigs/base.json"
},
"files": [
"bin/*",
"init/*",
"tsconfigs/*"
],
"keywords": [
"shared-config",
"typescript",
"tsconfig",
"envsa",
"envsa-typescript",
"cli"
],
"scripts": {
"build": "../../scripts/build.ts",
"cli": "node ./bin/cli.js",
"prepublishOnly": "pnpm run build"
},
"peerDependencies": {
"typescript": "~5.7.3"
},
"dependencies": {
"@pinojs/json-colorizer": "^4.0.0",
"cosmiconfig": "^9.0.0",
"execa": "^9.5.2",
"find-workspaces": "^0.3.1",
"fs-extra": "^11.2.0",
"prettier": "^3.5.0"
},
"publishConfig": {
"access": "public"
}
}
98 changes: 98 additions & 0 deletions packages/typescript-config/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!-- title -->

<!-- badges -->

<!-- description -->

## Overview

It's a shared [TypeScript](https://www.typescriptlang.org/) `tsconfig.json` config, plus a command-line tool envsa-typescript to perform TypesScript-related validation and linting.

<!-- recommendation -->

## Setup

> [!NOTE]
>
> The package treats `typescript` as a peer dependency - it expects you to have `typescript` installed in your project.
To use just this TypeScript config in isolation:

1. Install the `.npmrc` in your project root. This is required for correct PNPM behavior:

```sh
pnpm dlx @envsa/repo-config init
```

2. Add the package:

```sh
pnpm add -D @envsa/typescript-config
```

3. Add the starter `tsconfig.json` and `tsconfig.build.json` files to your project root, and add any customizations you'd like:

```sh
pnpm exec envsa-typescript init
```

## Usage

You can call `envsa-typescript` directly, or use the script bundled with the config.
Integrate wih your `package.json` script as you see fit, for example:

```json
{
"scripts": {
"lint": "envsa-typescript lint"
}
}
```

### Ignoring files

See the `tsconfig.json` [`exclude`](https://www.typescriptlang.org/tsconfig/#exclude) key.
`.gitignore` files are not ignored.

### Ignoring code

See [the TypeScript directive comments documentation](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#improved-checking-for-js-files) for more details.

Entire files (at top):

`/* @ts-nocheck */`

Next line:

`/* @ts-ignore */`

or

`/* @ts-expect-error - reason */`

### CLI

<!-- cli-help -->

## Notes

### General

- [tsconfig Cheat Sheet](https://www.totaltypescript.com/tsconfig-cheat-sheet)

### Other shared tsconfig projects

- [tsconfig/bases](https://github.com/tsconfig/bases)
- [sindresorhus/tsconfig](https://github.com/sindresorhus/tsconfig)
- [total-typescript/tsconfig](https://github.com/total-typescript/tsconfig)

### Future integrations

- [Are The Types Wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io),\
e.g. `attw --format ascii --no-summary --profile esm-only --pack .`

## Credits

[Eric Mika](https://github.com/kitschpatrol) is the author of the original [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) project on which this is based.

<!-- license -->
5 changes: 5 additions & 0 deletions packages/typescript-config/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
import { buildCommands } from '../../../src/command-builder.js';
import { commandDefinition } from './command.js';

await buildCommands(commandDefinition);
38 changes: 38 additions & 0 deletions packages/typescript-config/src/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { type CommandDefinition, DESCRIPTION } from '../../../src/command-builder.js';

export const commandDefinition: CommandDefinition = {
commands: {
init: {
locationOptionFlag: false,
},
lint: {
commands: [
{
cwdOverride: 'package-dir',
name: 'tsc',
optionFlags: ['--noEmit'],
},
],
// TODO confirm monorepo behavior
description: `Run type checking on your project. ${DESCRIPTION.packageRun} ${DESCRIPTION.monorepoRun}`,
positionalArgumentMode: 'none',
},
printConfig: {
commands: [
{
name: 'tsc',
optionFlags: ['--showConfig'],
prettyJsonOutput: true,
},
],
// TODO confirm monorepo behaviour
description: `Print the TypeScript configuration for the project. ${DESCRIPTION.packageSearch} ${DESCRIPTION.monorepoSearch}`,
positionalArgumentMode: 'none',
},
},
description: "Envsa's TypeScript shared configuration tools.",
logColor: 'blueBright',
logPrefix: '[TypeScript Config]',
name: 'Envsa-typescript',
order: 3,
};
22 changes: 22 additions & 0 deletions packages/typescript-config/tsconfigs/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2023",
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"allowJs": true,
"checkJs": true,
"strict": true,
"allowUnreachableCode": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,
"noErrorTruncation": true
}
}
Loading

0 comments on commit b66f095

Please sign in to comment.