@infinitetoken/tsconfig 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -8
- package/node.json +9 -0
- package/package.json +35 -8
- package/react-native.json +12 -0
- package/server.json +15 -0
- package/tsup.cjs +61 -0
package/README.md
CHANGED
|
@@ -1,24 +1,61 @@
|
|
|
1
1
|
# @infinitetoken/tsconfig
|
|
2
2
|
|
|
3
|
-
Shared base `tsconfig.json` for InfiniteToken TypeScript packages. Holds the compiler flags every repo agrees on (strictness, declaration output, consistent casing).
|
|
3
|
+
Shared base `tsconfig.json` for InfiniteToken TypeScript packages. Holds the compiler flags every repo agrees on (strictness, declaration output, consistent casing). Also ships an opt-in `tsup` build config factory (`@infinitetoken/tsconfig/tsup`) — see [tsup config](#tsup-config) below.
|
|
4
|
+
|
|
5
|
+
## Presets
|
|
6
|
+
|
|
7
|
+
| Export | Use for |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `@infinitetoken/tsconfig` / `@infinitetoken/tsconfig/tsconfig.json` | Universal core — strictness-only flags (`strict`, `declaration`, `noUnusedLocals`, etc). Rarely used directly; every variant below extends it. |
|
|
10
|
+
| `@infinitetoken/tsconfig/node` | Node/kit packages, RN library packages (via `/react-native`, below) — `target: esnext`, `module: preserve`, `moduleResolution: bundler`, `types: [jest, node]` |
|
|
11
|
+
| `@infinitetoken/tsconfig/server` | Express/server apps (unpublished) — `module: commonjs`, `resolveJsonModule: true`, `types: [jest, node]`, and relaxes six strictness flags (`declaration`, `declarationMap`, `noUnusedLocals`, `noUnusedParameters`, `noImplicitReturns`, `noFallthroughCasesInSwitch`) back to `false` |
|
|
12
|
+
| `@infinitetoken/tsconfig/react-native` | React Native packages — extends `/node`, adds `target: ES2020`, `lib: [ES2020, DOM]`, `jsx: react-jsx`, `module: ESNext`, `sourceMap: true`, `allowSyntheticDefaultImports: true`, `resolveJsonModule: true` |
|
|
4
13
|
|
|
5
14
|
## Usage
|
|
6
15
|
|
|
7
16
|
```json
|
|
8
17
|
{
|
|
9
|
-
"extends": "@infinitetoken/tsconfig/
|
|
18
|
+
"extends": "@infinitetoken/tsconfig/node",
|
|
10
19
|
"compilerOptions": {
|
|
11
|
-
"target": "esnext",
|
|
12
|
-
"module": "preserve",
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
20
|
"rootDir": "./src",
|
|
15
|
-
"
|
|
21
|
+
"outDir": "./dist"
|
|
16
22
|
},
|
|
17
|
-
"include": ["src/**/*"]
|
|
18
|
-
"exclude": ["node_modules", "dist"]
|
|
23
|
+
"include": ["src/**/*"]
|
|
19
24
|
}
|
|
20
25
|
```
|
|
21
26
|
|
|
27
|
+
That's the whole file for a typical Node/kit package — every other compiler option now comes from the preset. `rootDir`, `outDir`, `include` (and `exclude`, if you actually need one — see below) are the only things that ever need to be local, because of a real TypeScript limitation: an inherited path-valued `compilerOptions` entry, or an inherited `include`/`exclude`, resolves relative to the file that *declared* it, not the file that extends it. If this package tried to ship `rootDir`/`include`/`exclude` itself, an unoverridden consumer would have TypeScript looking for source files inside `node_modules/@infinitetoken/tsconfig/`. `target`/`module`/`moduleResolution`/`types`/`lib`/etc. don't have this problem — plain `compilerOptions` values merge normally through `extends`, which is exactly why the presets above can carry them for you.
|
|
28
|
+
|
|
29
|
+
**You very likely don't need an `exclude` array at all.** `include: ["src/**/*"]` already scopes the whole program to `src/` — anything living outside it (`node_modules`, `dist`, `.claude/worktrees`, `examples`, etc.) was never going to be included in the first place, so excluding it again is redundant. Only add `exclude` if you have something that genuinely lives *inside* `src/` that you need to keep out of the program.
|
|
30
|
+
|
|
31
|
+
`rootDir` specifically can't be dropped even though `include` looks like it should imply it: without it, `tsc`'s declaration-emit output layout breaks (`TS5011`), so it has to stay explicit whenever you're emitting declarations.
|
|
32
|
+
|
|
33
|
+
## tsup config
|
|
34
|
+
|
|
35
|
+
Opt-in — only relevant if the package builds with `tsup`. Unlike `tsconfig.json`, a `tsup.config` file is executable code with no path-resolution sharing limitation, so this is a plain factory function, not a JSON preset. Use a `tsup.config.cjs` (not `.ts`) so it loads directly with `require()` instead of going through tsup's ESM-bundling loader.
|
|
36
|
+
|
|
37
|
+
The common case — one library entry, cjs+esm, with declarations, cleaning `dist/` first:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// tsup.config.cjs
|
|
41
|
+
module.exports = require('@infinitetoken/tsconfig/tsup').createTsupConfig()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For a package with more than one entry point (e.g. a library plus a CLI bin), compose `entryConfig`/`cliConfig` yourself. Only the first entry should set `clean: true` — later entries with `clean: true` would wipe out what the earlier ones just wrote:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// tsup.config.cjs
|
|
48
|
+
const { defineConfig, entryConfig, cliConfig } = require('@infinitetoken/tsconfig/tsup')
|
|
49
|
+
|
|
50
|
+
module.exports = defineConfig([
|
|
51
|
+
entryConfig('src/index.ts', { clean: true }),
|
|
52
|
+
entryConfig('src/shapes.ts'),
|
|
53
|
+
cliConfig('src/cli.ts')
|
|
54
|
+
])
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`createTsupConfig(entry?, overrides?)` and `entryConfig` both default `dts: true` — a package doing `tsup && tsc --emitDeclarationOnly` as two separate steps (rather than letting tsup's own entry-scoped `dts` option handle it) will end up shipping declarations for every file `tsconfig.json`'s `include` matches, `__tests__` included, not just the real entry point.
|
|
58
|
+
|
|
22
59
|
## Release
|
|
23
60
|
|
|
24
61
|
Tag-based, using npm trusted publishing (OIDC, no token required):
|
package/node.json
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infinitetoken/tsconfig",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Shared base tsconfig for InfiniteToken TypeScript packages",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Shared base tsconfig for InfiniteToken TypeScript packages, with an opt-in tsup build config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
7
7
|
"tsconfig",
|
|
8
|
-
"typescript"
|
|
8
|
+
"typescript",
|
|
9
|
+
"tsup"
|
|
9
10
|
],
|
|
10
11
|
"homepage": "https://github.com/infinitetoken/tsconfig#readme",
|
|
11
12
|
"bugs": {
|
|
@@ -21,24 +22,50 @@
|
|
|
21
22
|
"type": "commonjs",
|
|
22
23
|
"exports": {
|
|
23
24
|
".": "./tsconfig.json",
|
|
25
|
+
"./node": "./node.json",
|
|
24
26
|
"./package.json": "./package.json",
|
|
25
|
-
"./
|
|
27
|
+
"./react-native": "./react-native.json",
|
|
28
|
+
"./server": "./server.json",
|
|
29
|
+
"./tsconfig.json": "./tsconfig.json",
|
|
30
|
+
"./tsup": "./tsup.cjs"
|
|
26
31
|
},
|
|
27
32
|
"files": [
|
|
28
|
-
"tsconfig.json"
|
|
33
|
+
"tsconfig.json",
|
|
34
|
+
"node.json",
|
|
35
|
+
"react-native.json",
|
|
36
|
+
"server.json",
|
|
37
|
+
"tsup.cjs"
|
|
29
38
|
],
|
|
30
39
|
"scripts": {
|
|
31
|
-
"
|
|
40
|
+
"fix": "eslint . --fix",
|
|
41
|
+
"lint": "eslint .",
|
|
32
42
|
"release": "git push --follow-tags",
|
|
33
43
|
"release:major": "npm version major && npm run release",
|
|
34
44
|
"release:minor": "npm version minor && npm run release",
|
|
35
45
|
"release:patch": "npm version patch && npm run release",
|
|
36
|
-
"test": "
|
|
37
|
-
"
|
|
46
|
+
"test": "node scripts/verify-presets.cjs && node scripts/verify-tsup.cjs",
|
|
47
|
+
"verify": "npm run lint && npm test",
|
|
48
|
+
"preversion": "npm run verify"
|
|
38
49
|
},
|
|
50
|
+
"prettier": "@infinitetoken/eslint-config/prettier",
|
|
39
51
|
"devDependencies": {
|
|
52
|
+
"@infinitetoken/eslint-config": "^0.1.4",
|
|
53
|
+
"@types/jest": "^30.0.0",
|
|
54
|
+
"@types/node": "^26.4.0",
|
|
55
|
+
"@types/react": "^19.2.18",
|
|
56
|
+
"eslint": "^9.39.4",
|
|
57
|
+
"react": "^19.2.8",
|
|
58
|
+
"tsup": "^8.5.1",
|
|
40
59
|
"typescript": "^6.0.3"
|
|
41
60
|
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"tsup": "^8.0.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"tsup": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
42
69
|
"publishConfig": {
|
|
43
70
|
"access": "public"
|
|
44
71
|
}
|
package/server.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"resolveJsonModule": true,
|
|
6
|
+
"types": ["jest", "node"],
|
|
7
|
+
"declaration": false,
|
|
8
|
+
"declarationMap": false,
|
|
9
|
+
"noUnusedLocals": false,
|
|
10
|
+
"noUnusedParameters": false,
|
|
11
|
+
"noImplicitReturns": false,
|
|
12
|
+
"noFallthroughCasesInSwitch": false,
|
|
13
|
+
"preserveConstEnums": false
|
|
14
|
+
}
|
|
15
|
+
}
|
package/tsup.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { defineConfig } = require('tsup')
|
|
2
|
+
|
|
3
|
+
const BASE_DEFAULTS = {
|
|
4
|
+
format: ['cjs', 'esm'],
|
|
5
|
+
dts: true
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const CLI_DEFAULTS = {
|
|
9
|
+
format: ['esm'],
|
|
10
|
+
banner: { js: '#!/usr/bin/env node' }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A single tsup build-entry object, for composing a multi-entry array yourself
|
|
15
|
+
* (e.g. a library entry plus a separate subpath entry). `clean` is deliberately
|
|
16
|
+
* NOT defaulted here — with multiple entries in one array, only the first should
|
|
17
|
+
* clean `dist/`, or later entries wipe out earlier ones' output.
|
|
18
|
+
*
|
|
19
|
+
* @param {string|string[]} entry
|
|
20
|
+
* @param {import('tsup').Options} [overrides]
|
|
21
|
+
* @returns {import('tsup').Options}
|
|
22
|
+
*/
|
|
23
|
+
function entryConfig(entry, overrides = {}) {
|
|
24
|
+
return {
|
|
25
|
+
entry: Array.isArray(entry) ? entry : [entry],
|
|
26
|
+
...BASE_DEFAULTS,
|
|
27
|
+
...overrides
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A CLI bin entry: ESM-only with a Node shebang banner, no declarations.
|
|
33
|
+
*
|
|
34
|
+
* @param {string|string[]} entry
|
|
35
|
+
* @param {import('tsup').Options} [overrides]
|
|
36
|
+
* @returns {import('tsup').Options}
|
|
37
|
+
*/
|
|
38
|
+
function cliConfig(entry, overrides = {}) {
|
|
39
|
+
return {
|
|
40
|
+
entry: Array.isArray(entry) ? entry : [entry],
|
|
41
|
+
...CLI_DEFAULTS,
|
|
42
|
+
...overrides
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The common case: one library entry point, cjs+esm, with declarations and a
|
|
48
|
+
* clean build. Covers most packages in the fleet outright.
|
|
49
|
+
*
|
|
50
|
+
* For a package with multiple entries (e.g. a CLI bin alongside the library),
|
|
51
|
+
* skip this and compose `entryConfig`/`cliConfig` yourself under `defineConfig([...])`.
|
|
52
|
+
*
|
|
53
|
+
* @param {string|string[]} [entry]
|
|
54
|
+
* @param {import('tsup').Options} [overrides]
|
|
55
|
+
* @returns {import('tsup').Options}
|
|
56
|
+
*/
|
|
57
|
+
function createTsupConfig(entry = 'src/index.ts', overrides = {}) {
|
|
58
|
+
return defineConfig(entryConfig(entry, { clean: true, ...overrides }))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { createTsupConfig, entryConfig, cliConfig, defineConfig }
|