@infinitetoken/tsconfig 0.2.0 → 0.3.0

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 CHANGED
@@ -1,6 +1,6 @@
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). Also ships an opt-in `tsup` build config factory (`@infinitetoken/tsconfig/tsup`) — see [tsup config](#tsup-config) below.
3
+ Shared base `tsconfig.json` for InfiniteToken TypeScript packages. Holds the compiler flags every repo agrees on (strictness, declaration output, consistent casing). Also ships opt-in `tsup` build config factories for a library, a CLI, or both — see [tsup config](#tsup-config) below.
4
4
 
5
5
  ## Presets
6
6
 
@@ -32,18 +32,48 @@ That's the whole file for a typical Node/kit package — every other compiler op
32
32
 
33
33
  ## tsup config
34
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 — same shape as `@infinitetoken/jest-config`'s presets, a bare function you call, nothing invoked by name off an object. Use a `tsup.config.cjs` (not `.ts`) so it loads directly with `require()` instead of going through tsup's ESM-bundling loader.
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 these are plain factory functions — same shape as `@infinitetoken/jest-config`'s presets, a bare function you call, nothing invoked by name off an object. Use a `tsup.config.cjs` (not `.ts`) so it loads directly with `require()` instead of going through tsup's ESM-bundling loader. Pick the export that matches what the package actually ships:
36
+
37
+ | Export | Use for |
38
+ | --- | --- |
39
+ | `@infinitetoken/tsconfig/tsup/lib` | A library with no CLI — one entry, cjs+esm, declarations, cleans `dist/` |
40
+ | `@infinitetoken/tsconfig/tsup/cli` | A CLI with no separate library export (`main`/`exports` point straight at the built bin) — one entry, esm-only, Node shebang banner, no declarations |
41
+ | `@infinitetoken/tsconfig/tsup/lib-cli` | A package that ships both — a real, separately-importable library **and** a CLI bin — the library entry (cjs+esm, declarations, cleans `dist/`) plus the CLI entry (esm-only, shebang, no declarations) |
42
+
43
+ The plain library case — one entry point, nothing else:
44
+
45
+ ```js
46
+ // tsup.config.cjs
47
+ module.exports = require('@infinitetoken/tsconfig/tsup/lib')()
48
+ ```
49
+
50
+ Pass a different entry or override anything tsup accepts: `require('@infinitetoken/tsconfig/tsup/lib')('src/main.ts', { minify: true })`.
51
+
52
+ A CLI-only package:
36
53
 
37
54
  ```js
38
55
  // tsup.config.cjs
39
- module.exports = require('@infinitetoken/tsconfig/tsup')()
56
+ module.exports = require('@infinitetoken/tsconfig/tsup/cli')()
40
57
  ```
41
58
 
42
- That's the whole file for one library entry point — cjs+esm, with declarations, cleaning `dist/` first. Pass a different entry or override anything tsup accepts: `require('@infinitetoken/tsconfig/tsup')('src/main.ts', { minify: true })`.
59
+ A package with both a library and a CLI:
43
60
 
44
- A package with more than one entry point (a library plus a CLI bin, say) isn't covered by this factory yet — write `tsup.config.cjs` by hand with `tsup`'s own `defineConfig([...])` for that case, same as before this package existed.
61
+ ```js
62
+ // tsup.config.cjs
63
+ module.exports = require('@infinitetoken/tsconfig/tsup/lib-cli')()
64
+ ```
65
+
66
+ That returns the full two-entry array (`createTsupLibCliConfig(libEntry?, cliEntry?, { lib?, cli? })` — defaults to `src/index.ts` / `src/cli.ts`). A package with an extra entry beyond those two (e.g. a separate subpath export) can spread it and append its own:
67
+
68
+ ```js
69
+ // tsup.config.cjs
70
+ const { defineConfig } = require('tsup')
71
+ const createTsupLibCliConfig = require('@infinitetoken/tsconfig/tsup/lib-cli')
72
+
73
+ module.exports = defineConfig([...createTsupLibCliConfig(), { entry: ['src/shapes.ts'], format: ['esm', 'cjs'], dts: true }])
74
+ ```
45
75
 
46
- `createTsupConfig` defaults `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.
76
+ All three default `dts: true` on every entry that represents real importable code (never on a CLI entry nobody imports a bin as a typed library) — 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.
47
77
 
48
78
  ## Release
49
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infinitetoken/tsconfig",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared base tsconfig for InfiniteToken TypeScript packages, with an opt-in tsup build config",
5
5
  "keywords": [
6
6
  "config",
@@ -21,20 +21,18 @@
21
21
  "sideEffects": false,
22
22
  "type": "commonjs",
23
23
  "exports": {
24
- ".": "./tsconfig.json",
25
- "./node": "./node.json",
24
+ ".": "./src/tsconfig.json",
25
+ "./node": "./src/node.json",
26
26
  "./package.json": "./package.json",
27
- "./react-native": "./react-native.json",
28
- "./server": "./server.json",
29
- "./tsconfig.json": "./tsconfig.json",
30
- "./tsup": "./tsup.cjs"
27
+ "./react-native": "./src/react-native.json",
28
+ "./server": "./src/server.json",
29
+ "./tsconfig.json": "./src/tsconfig.json",
30
+ "./tsup/cli": "./src/tsup/cli.cjs",
31
+ "./tsup/lib": "./src/tsup/lib.cjs",
32
+ "./tsup/lib-cli": "./src/tsup/lib-cli.cjs"
31
33
  },
32
34
  "files": [
33
- "tsconfig.json",
34
- "node.json",
35
- "react-native.json",
36
- "server.json",
37
- "tsup.cjs"
35
+ "src"
38
36
  ],
39
37
  "scripts": {
40
38
  "fix": "eslint . --fix",
@@ -0,0 +1,24 @@
1
+ const { defineConfig } = require('tsup')
2
+
3
+ /**
4
+ * A CLI-only package with no separate library export — the bin IS the package
5
+ * (no `dts`: there's no typed API for anyone to import). ESM-only with a Node
6
+ * shebang banner. Modeled on the CLI half of the fleet's package+CLI packages,
7
+ * not on any existing CLI-only package — those still need aligning onto this
8
+ * shape, not the other way around.
9
+ *
10
+ * @param {string|string[]} [entry]
11
+ * @param {import('tsup').Options} [overrides]
12
+ * @returns {import('tsup').Options}
13
+ */
14
+ function createTsupCliConfig(entry = 'src/cli.ts', overrides = {}) {
15
+ return defineConfig({
16
+ entry: Array.isArray(entry) ? entry : [entry],
17
+ format: ['esm'],
18
+ banner: { js: '#!/usr/bin/env node' },
19
+ clean: true,
20
+ ...overrides
21
+ })
22
+ }
23
+
24
+ module.exports = createTsupCliConfig
@@ -0,0 +1,33 @@
1
+ const { defineConfig } = require('tsup')
2
+
3
+ /**
4
+ * A package that also ships a CLI bin: one library entry (cjs+esm, declarations,
5
+ * cleans dist/ first) plus one CLI entry (esm-only, Node shebang banner, no
6
+ * declarations — nobody imports a bin as a typed library). Returns the full
7
+ * two-entry array; a package with more entries than this (e.g. an extra
8
+ * subpath) can spread it and append its own: `[...createTsupLibCliConfig(), extraEntry]`.
9
+ *
10
+ * @param {string|string[]} [libEntry]
11
+ * @param {string|string[]} [cliEntry]
12
+ * @param {{ lib?: import('tsup').Options, cli?: import('tsup').Options }} [overrides]
13
+ * @returns {import('tsup').Options[]}
14
+ */
15
+ function createTsupLibCliConfig(libEntry = 'src/index.ts', cliEntry = 'src/cli.ts', overrides = {}) {
16
+ return defineConfig([
17
+ {
18
+ entry: Array.isArray(libEntry) ? libEntry : [libEntry],
19
+ format: ['cjs', 'esm'],
20
+ dts: true,
21
+ clean: true,
22
+ ...overrides.lib
23
+ },
24
+ {
25
+ entry: Array.isArray(cliEntry) ? cliEntry : [cliEntry],
26
+ format: ['esm'],
27
+ banner: { js: '#!/usr/bin/env node' },
28
+ ...overrides.cli
29
+ }
30
+ ])
31
+ }
32
+
33
+ module.exports = createTsupLibCliConfig
File without changes
File without changes
File without changes
File without changes
File without changes