@infinitetoken/tsconfig 0.1.4 → 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,29 +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, 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.
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
36
 
37
- The common case one library entry, cjs+esm, with declarations, cleaning `dist/` first:
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:
53
+
54
+ ```js
55
+ // tsup.config.cjs
56
+ module.exports = require('@infinitetoken/tsconfig/tsup/cli')()
57
+ ```
58
+
59
+ A package with both a library and a CLI:
38
60
 
39
61
  ```js
40
62
  // tsup.config.cjs
41
- module.exports = require('@infinitetoken/tsconfig/tsup').createTsupConfig()
63
+ module.exports = require('@infinitetoken/tsconfig/tsup/lib-cli')()
42
64
  ```
43
65
 
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:
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:
45
67
 
46
68
  ```js
47
69
  // tsup.config.cjs
48
- const { defineConfig, entryConfig, cliConfig } = require('@infinitetoken/tsconfig/tsup')
70
+ const { defineConfig } = require('tsup')
71
+ const createTsupLibCliConfig = require('@infinitetoken/tsconfig/tsup/lib-cli')
49
72
 
50
- module.exports = defineConfig([
51
- entryConfig('src/index.ts', { clean: true }),
52
- entryConfig('src/shapes.ts'),
53
- cliConfig('src/cli.ts')
54
- ])
73
+ module.exports = defineConfig([...createTsupLibCliConfig(), { entry: ['src/shapes.ts'], format: ['esm', 'cjs'], dts: true }])
55
74
  ```
56
75
 
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.
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.
58
77
 
59
78
  ## Release
60
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infinitetoken/tsconfig",
3
- "version": "0.1.4",
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
@@ -0,0 +1,21 @@
1
+ const { defineConfig } = require('tsup')
2
+
3
+ /**
4
+ * One library entry point, cjs+esm, with declarations and a clean build.
5
+ * Covers the common case fleet-wide.
6
+ *
7
+ * @param {string|string[]} [entry]
8
+ * @param {import('tsup').Options} [overrides]
9
+ * @returns {import('tsup').Options}
10
+ */
11
+ function createTsupConfig(entry = 'src/index.ts', overrides = {}) {
12
+ return defineConfig({
13
+ entry: Array.isArray(entry) ? entry : [entry],
14
+ format: ['cjs', 'esm'],
15
+ dts: true,
16
+ clean: true,
17
+ ...overrides
18
+ })
19
+ }
20
+
21
+ module.exports = createTsupConfig
package/tsup.cjs DELETED
@@ -1,61 +0,0 @@
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 }
File without changes
File without changes
File without changes
File without changes