@mongez/pkgist 1.0.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.
Files changed (49) hide show
  1. package/.prettierignore +4 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +320 -0
  4. package/builder.ts +183 -0
  5. package/dist/cli.d.ts +1 -0
  6. package/dist/cli.js +1125 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/index.d.ts +202 -0
  9. package/dist/index.js +824 -0
  10. package/dist/index.js.map +1 -0
  11. package/eslint.config.js +98 -0
  12. package/package.json +49 -0
  13. package/src/build/family-builder.ts +76 -0
  14. package/src/build/index.ts +4 -0
  15. package/src/build/package-builder.ts +155 -0
  16. package/src/build/parallel-builder.ts +36 -0
  17. package/src/cli.ts +51 -0
  18. package/src/commands/build-all.ts +88 -0
  19. package/src/commands/build-family.ts +55 -0
  20. package/src/commands/build.ts +84 -0
  21. package/src/commands/index.ts +5 -0
  22. package/src/commands/list.ts +74 -0
  23. package/src/commands/validate.ts +125 -0
  24. package/src/compile/index.ts +1 -0
  25. package/src/compile/tsdown-compiler.ts +344 -0
  26. package/src/config/define-config.ts +9 -0
  27. package/src/config/index.ts +3 -0
  28. package/src/config/load-config.ts +103 -0
  29. package/src/files/clone-files.ts +45 -0
  30. package/src/files/file-manager.ts +109 -0
  31. package/src/files/index.ts +3 -0
  32. package/src/files/package-json.ts +191 -0
  33. package/src/git/index.ts +1 -0
  34. package/src/git/operations.ts +87 -0
  35. package/src/index.ts +26 -0
  36. package/src/publish/index.ts +1 -0
  37. package/src/publish/npm-publisher.ts +36 -0
  38. package/src/types/config.ts +33 -0
  39. package/src/types/index.ts +2 -0
  40. package/src/types/package.ts +81 -0
  41. package/src/utils/errors.ts +40 -0
  42. package/src/utils/exec.ts +58 -0
  43. package/src/utils/index.ts +4 -0
  44. package/src/utils/logger.ts +44 -0
  45. package/src/utils/paths.ts +48 -0
  46. package/src/version/increment.ts +51 -0
  47. package/src/version/index.ts +1 -0
  48. package/tsconfig.json +20 -0
  49. package/tsup.config.ts +34 -0
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+
4
+
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": false,
4
+ "trailingComma": "all",
5
+ "printWidth": 100,
6
+ "plugins": ["prettier-plugin-organize-imports"]
7
+ }
8
+
package/README.md ADDED
@@ -0,0 +1,320 @@
1
+ # @mongez/pkgist
2
+
3
+ A build, version, and publish tool for TypeScript/React npm packages. Powered by [tsdown](https://tsdown.dev) (Rolldown/Rust-based bundler).
4
+
5
+ ## Features
6
+
7
+ - **Two versioning strategies** — standalone packages version independently; family packages share one synchronized version
8
+ - **tsdown engine** — Rust-based Rolldown bundler; fast, reliable, modern
9
+ - **Dual output** — ESM + CJS with proper `exports` map and separate `.d.ts` files per format
10
+ - **File cloning** — copy `README.md`, `skills/`, `llms.txt`, or any file/folder into the build
11
+ - **Source snapshots** — archives a clean copy of the source before each build (`.git` and `node_modules` excluded)
12
+ - **Git integration** — `git add → commit → push → tag v<x.y.z> → push tags`
13
+ - **npm publish** — publishes from the build directory, not the source
14
+ - **Dry-run mode** — prints every step without touching disk, git, or npm
15
+ - **Concurrency** — builds multiple packages in parallel
16
+ - **TypeScript config** — `builder.ts` with full type safety via `defineConfig`
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ cd /path/to/compiler-v2
24
+ npm install
25
+ npm run build
26
+ npm link # makes `pkgist` available globally
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Configuration
32
+
33
+ Create a `builder.ts` in your project root (the bundler auto-discovers it):
34
+
35
+ ```ts
36
+ import { defineConfig } from "@mongez/pkgist";
37
+
38
+ export default defineConfig({
39
+ settings: {
40
+ concurrency: 8, // parallel build limit (default: 4)
41
+ buildDir: "../builds", // where compiled packages are written
42
+ sourcesDir: "../sources", // where source snapshots are archived
43
+ },
44
+
45
+ // Standalone: each package versions independently
46
+ standalone: [
47
+ {
48
+ name: "@my-scope/utils",
49
+ root: "../utils",
50
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
51
+ },
52
+ ],
53
+
54
+ // Families: all packages in a group share one version
55
+ families: [
56
+ {
57
+ name: "state",
58
+ packages: [
59
+ { name: "@my-scope/atom", root: "../atom", clone: ["README.md"] },
60
+ { name: "@my-scope/react-atom", root: "../react-atom", type: "react", clone: ["README.md"] },
61
+ ],
62
+ },
63
+ ],
64
+ });
65
+ ```
66
+
67
+ The config file is loaded at runtime via dynamic import — it can use `import` syntax freely.
68
+
69
+ ---
70
+
71
+ ## Package options
72
+
73
+ Every entry in `standalone[]` and `families[].packages[]` accepts:
74
+
75
+ | Option | Type | Default | Description |
76
+ |---|---|---|---|
77
+ | `name` | `string` | **required** | npm package name |
78
+ | `root` | `string` | **required** | Path to package root, relative to `builder.ts` |
79
+ | `type` | `"typescript" \| "react"` | `"typescript"` | React packages get JSX support |
80
+ | `formats` | `("esm" \| "cjs")[]` | `["esm", "cjs"]` | Output formats |
81
+ | `mainType` | `"cjs" \| "esm"` | `"cjs"` | Primary format (affects `main` field in package.json) |
82
+ | `entries` | `string \| string[]` | `["index.ts"]` | Entry files inside `src/` |
83
+ | `srcDir` | `string` | `"src"` | Source directory name |
84
+ | `dts` | `boolean` | `true` | Generate TypeScript declarations |
85
+ | `sourcemap` | `boolean` | `true` | Generate sourcemaps |
86
+ | `minify` | `boolean` | `false` | Minify output |
87
+ | `preserveModules` | `boolean` | `true` | Keep one file per source module instead of bundling everything into a single `index.js`. Produces meaningful stack traces (`array/chunk.mjs:4` vs `index.js:1027`). Set to `false` only for tiny single-file packages where a flat bundle is preferred. |
88
+ | `clone` | `(string \| [string, string])[]` | `[]` | Files/dirs to copy into build. Strings copy as-is; `["src", "dest"]` renames |
89
+ | `publish` | `boolean` | `true` | Publish to npm |
90
+ | `access` | `"public" \| "restricted"` | `"public"` | npm access level |
91
+ | `commit` | `string` | — | Git commit message. Git is skipped entirely when not set |
92
+ | `branch` | `string` | current branch | Git branch to push to |
93
+
94
+ ### Standalone-only option
95
+
96
+ | Option | Type | Default | Description |
97
+ |---|---|---|---|
98
+ | `version` | `"auto" \| string` | `"auto"` | `"auto"` = patch bump; explicit string = use that version |
99
+
100
+ ### Family-level options
101
+
102
+ | Option | Type | Default | Description |
103
+ |---|---|---|---|
104
+ | `version` | `"auto" \| string` | `"auto"` | Version strategy for the whole family |
105
+ | `commit` | `string` | — | Commit message applied to all packages (overrides per-package) |
106
+
107
+ ---
108
+
109
+ ## Versioning
110
+
111
+ ### Standalone packages
112
+
113
+ ```
114
+ current: 2.1.0
115
+ version: "auto" → 2.1.1 (patch bump)
116
+ version: "3.0.0" → 3.0.0 (explicit)
117
+ ```
118
+
119
+ ### Family packages
120
+
121
+ The family picks the **highest current version** across all members, then bumps it:
122
+
123
+ ```
124
+ atom 1.0.5
125
+ react-atom 5.1.3 ← highest
126
+ atomic-query 0.1.0
127
+
128
+ family version: "auto" → 5.1.4 (all three land on 5.1.4)
129
+ ```
130
+
131
+ This means if you add a new package to a family at `0.1.0`, it jumps to match the family on first build — which is intentional. The family version is the compatibility contract.
132
+
133
+ ---
134
+
135
+ ## CLI reference
136
+
137
+ ### `build`
138
+
139
+ Build one or more standalone packages.
140
+
141
+ ```sh
142
+ pkgist build @my-scope/utils
143
+ pkgist build @my-scope/utils @my-scope/cache
144
+ pkgist build --all # all standalone packages
145
+ ```
146
+
147
+ ### `build:family`
148
+
149
+ Build all packages in a family with a shared version.
150
+
151
+ ```sh
152
+ pkgist build:family atom
153
+ pkgist build:family localization
154
+ ```
155
+
156
+ ### `build:all`
157
+
158
+ Build every standalone package and every family.
159
+
160
+ ```sh
161
+ pkgist build:all
162
+ ```
163
+
164
+ ### `list`
165
+
166
+ Show all registered packages and families with their current versions.
167
+
168
+ ```sh
169
+ pkgist list
170
+ ```
171
+
172
+ ```
173
+ === Standalone Packages ===
174
+ @my-scope/utils v2.1.0 [typescript] [esm, cjs]
175
+ root: /path/to/utils
176
+
177
+ === Families ===
178
+ Family: state
179
+ @my-scope/atom v5.1.3 [typescript] [esm, cjs]
180
+ @my-scope/react-atom v5.1.3 [react] [esm, cjs]
181
+ ```
182
+
183
+ ### `validate`
184
+
185
+ Check that the config is valid and all package roots exist on disk.
186
+
187
+ ```sh
188
+ pkgist validate
189
+ ```
190
+
191
+ ---
192
+
193
+ ## Common flags
194
+
195
+ Available on all `build` commands:
196
+
197
+ | Flag | Description |
198
+ |---|---|
199
+ | `--dry-run` | Print every step without writing to disk, git, or npm |
200
+ | `--no-publish` | Skip `npm publish` |
201
+ | `--no-git` | Skip git add / commit / push / tag |
202
+ | `--concurrency <n>` | Override the parallel build limit |
203
+ | `--config <path>` | Path to config file (default: `builder.ts` in cwd) |
204
+ | `--verbose` | Show debug-level log lines |
205
+
206
+ ---
207
+
208
+ ## Build output structure
209
+
210
+ ### With `preserveModules: true` (default)
211
+
212
+ Each source file becomes its own output file, mirroring the source tree. Stack traces show file names instead of opaque line numbers.
213
+
214
+ ```
215
+ builds/
216
+ └── utils/
217
+ └── 2.1.1/
218
+ ├── package.json ← clean: no devDeps, no scripts
219
+ ├── README.md ← cloned
220
+ ├── skills/ ← cloned (directory)
221
+ ├── esm/
222
+ │ ├── index.mjs
223
+ │ ├── index.mjs.map
224
+ │ ├── index.d.mts
225
+ │ ├── array/
226
+ │ │ ├── chunk.mjs
227
+ │ │ └── chunk.d.mts
228
+ │ └── string/
229
+ │ └── trim.mjs
230
+ └── cjs/
231
+ ├── index.cjs
232
+ ├── index.cjs.map
233
+ ├── index.d.cts
234
+ └── array/
235
+ └── chunk.cjs
236
+ ```
237
+
238
+ The generated `package.json` sets:
239
+
240
+ ```json
241
+ {
242
+ "main": "./cjs/index.cjs",
243
+ "module": "./esm/index.mjs",
244
+ "types": "./esm/index.d.mts",
245
+ "exports": {
246
+ ".": {
247
+ "import": { "types": "./esm/index.d.mts", "default": "./esm/index.mjs" },
248
+ "require": { "types": "./cjs/index.d.cts", "default": "./cjs/index.cjs" }
249
+ }
250
+ }
251
+ }
252
+ ```
253
+
254
+ ### With `preserveModules: false`
255
+
256
+ Everything is bundled into a single file per format. Useful for tiny single-file packages.
257
+
258
+ ```
259
+ esm/
260
+ index.js / index.js.map / index.d.ts
261
+ cjs/
262
+ index.js / index.js.map / index.d.ts
263
+ ```
264
+
265
+ ```json
266
+ {
267
+ "main": "./cjs/index.js",
268
+ "module": "./esm/index.js",
269
+ "types": "./esm/index.d.ts"
270
+ }
271
+ ```
272
+
273
+ ESM-only packages (`mainType: "esm"` or `formats: ["esm"]`) get `"type": "module"` and omit the `require` condition in both modes.
274
+
275
+ ---
276
+
277
+ ## Build pipeline (per package)
278
+
279
+ 1. Load source `package.json` → read current version
280
+ 2. Resolve new version (auto-bump or explicit)
281
+ 3. Create build output directory
282
+ 4. Snapshot source to `sourcesDir/` — full copy excluding `.git`, `node_modules`, `dist`
283
+ 5. Compile with **tsdown** → `esm/` and `cjs/` subdirectories
284
+ 6. Clone extra files/directories listed in `clone`
285
+ 7. Write clean `package.json` for the build
286
+ 8. Update source `package.json` version in-place
287
+ 9. Git: `add .` → `commit` → `push` → `tag v<version>` → `push tags` *(if `commit` is set)*
288
+ 10. `npm publish --access <public|restricted>` from build directory *(if `publish !== false`)*
289
+
290
+ ---
291
+
292
+ ## Git workflow
293
+
294
+ Git operations only run when `commit` is set on the package. Set it per-package in standalone, or once at the family level:
295
+
296
+ ```ts
297
+ // Standalone — per-package
298
+ { name: "@my-scope/utils", root: "../utils", commit: "chore: release" }
299
+
300
+ // Family — one message for all members
301
+ {
302
+ name: "state",
303
+ commit: "feat: improved actions API",
304
+ packages: [ ... ],
305
+ }
306
+ ```
307
+
308
+ The builder tags each package with `v<version>` and pushes tags automatically.
309
+ Remove `commit` to skip git entirely (useful for local test builds).
310
+
311
+ ---
312
+
313
+ ## Developing the bundler itself
314
+
315
+ ```sh
316
+ yarn build # compile src/ → dist/ once
317
+ yarn dev # watch mode — recompiles on change
318
+ ```
319
+
320
+ After any change to `src/`, run `yarn build` before the next `pkgist` invocation.
package/builder.ts ADDED
@@ -0,0 +1,183 @@
1
+ import { defineConfig } from "@mongez/pkgist";
2
+
3
+ const RELEASE_COMMIT = "Added skills and improved build output";
4
+
5
+ export default defineConfig({
6
+ settings: {
7
+ concurrency: 8,
8
+ buildDir: "../builds",
9
+ sourcesDir: "../sources",
10
+ },
11
+
12
+ standalone: [
13
+ {
14
+ name: "@mongez/reinforcements",
15
+ root: "../@mongez/reinforcements",
16
+ version: "auto",
17
+ commit: RELEASE_COMMIT,
18
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
19
+ },
20
+ {
21
+ name: "@mongez/agent-kit",
22
+ root: "../@mongez/agent-kit",
23
+ commit: "Fixed imported cli bin",
24
+ entries: ["index.ts", "cli/index.ts"],
25
+ clone: ["README.md", "bin", "skills", "llms.txt", "llms-full.txt"],
26
+ },
27
+ {
28
+ name: "@mongez/supportive-is",
29
+ root: "../@mongez/supportive-is",
30
+ version: "minor",
31
+ commit: RELEASE_COMMIT,
32
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
33
+ },
34
+ {
35
+ name: "@mongez/cache",
36
+ root: "../@mongez/cache",
37
+ version: "minor",
38
+ commit: RELEASE_COMMIT,
39
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
40
+ },
41
+ {
42
+ name: "@mongez/events",
43
+ root: "../@mongez/events",
44
+ version: "auto",
45
+ commit: RELEASE_COMMIT,
46
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
47
+ },
48
+ {
49
+ name: "@mongez/collection",
50
+ root: "../@mongez/collection",
51
+ version: "minor",
52
+ commit: RELEASE_COMMIT,
53
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
54
+ },
55
+ {
56
+ name: "@mongez/concat-route",
57
+ root: "../@mongez/concat-route",
58
+ version: "minor",
59
+ commit: RELEASE_COMMIT,
60
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
61
+ },
62
+ {
63
+ name: "@mongez/query-string",
64
+ root: "../@mongez/query-string",
65
+ version: "minor",
66
+ commit: RELEASE_COMMIT,
67
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
68
+ },
69
+ {
70
+ name: "@mongez/dotenv",
71
+ root: "../@mongez/dotenv",
72
+ version: "minor",
73
+ commit: RELEASE_COMMIT,
74
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
75
+ },
76
+ {
77
+ name: "@mongez/encryption",
78
+ root: "../@mongez/encryption",
79
+ version: "minor",
80
+ commit: RELEASE_COMMIT,
81
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
82
+ },
83
+ {
84
+ name: "@mongez/config",
85
+ root: "../@mongez/config",
86
+ version: "minor",
87
+ commit: RELEASE_COMMIT,
88
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
89
+ },
90
+ {
91
+ name: "@mongez/dom",
92
+ root: "../@mongez/dom",
93
+ version: "minor",
94
+ commit: RELEASE_COMMIT,
95
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
96
+ },
97
+ {
98
+ name: "@mongez/user",
99
+ root: "../@mongez/user",
100
+ version: "minor",
101
+ commit: RELEASE_COMMIT,
102
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
103
+ },
104
+ {
105
+ name: "@mongez/react-router",
106
+ root: "../@mongez/react-router",
107
+ type: "react",
108
+ version: "minor",
109
+ commit: RELEASE_COMMIT,
110
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
111
+ },
112
+ {
113
+ name: "@mongez/react-helmet",
114
+ root: "../@mongez/react-helmet",
115
+ type: "react",
116
+ version: "minor",
117
+ commit: RELEASE_COMMIT,
118
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
119
+ },
120
+ {
121
+ name: "@mongez/react-form",
122
+ root: "../@mongez/react-form",
123
+ type: "react",
124
+ version: "minor",
125
+ commit: RELEASE_COMMIT,
126
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
127
+ },
128
+ {
129
+ name: "@mongez/vite",
130
+ root: "../@mongez/vite",
131
+ mainType: "esm",
132
+ formats: ["esm"],
133
+ version: "minor",
134
+ commit: RELEASE_COMMIT,
135
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
136
+ },
137
+ ],
138
+
139
+ families: [
140
+ {
141
+ name: "atom",
142
+ version: "6.0.0",
143
+ commit: RELEASE_COMMIT,
144
+ packages: [
145
+ {
146
+ name: "@mongez/atom",
147
+ root: "../@mongez/atom",
148
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
149
+ },
150
+ {
151
+ name: "@mongez/react-atom",
152
+ root: "../@mongez/react-atom",
153
+ type: "react",
154
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
155
+ },
156
+ {
157
+ name: "@mongez/atomic-query",
158
+ root: "../@mongez/atomic-query",
159
+ type: "react",
160
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
161
+ },
162
+ ],
163
+ },
164
+ {
165
+ name: "localization",
166
+ version: "minor",
167
+ commit: RELEASE_COMMIT,
168
+ packages: [
169
+ {
170
+ name: "@mongez/localization",
171
+ root: "../@mongez/localization",
172
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
173
+ },
174
+ {
175
+ name: "@mongez/react-localization",
176
+ root: "../@mongez/react-localization",
177
+ type: "react",
178
+ clone: ["README.md", "skills", "llms.txt", "llms-full.txt"],
179
+ },
180
+ ],
181
+ },
182
+ ],
183
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node