@walkeros/cli 4.0.0 → 4.0.1-next-1778183328892

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/CHANGELOG.md CHANGED
@@ -1,5 +1,107 @@
1
1
  # @walkeros/cli
2
2
 
3
+ ## 4.0.1-next-1778183328892
4
+
5
+ ### Patch Changes
6
+
7
+ - abfb0bb: @walkeros/cli: Server bundles now use @vercel/nft to trace
8
+ dependencies and copy only files actually used into dist/node_modules/. Pacote
9
+ remains the install layer (driven by flow.json's config.bundle.packages field;
10
+ users do not run npm install for step packages). The walkerOS.bundle.external
11
+ annotation field on package manifests is no longer recognized (deprecation
12
+ warning if seen). The flow.<name>.config.bundle.external sub-field on flow
13
+ configs is also no longer supported (warned and stripped during load). The
14
+ flow.<name>.config.bundle.traceInclude field is the escape hatch for cases nft
15
+ cannot statically trace. Server output is always a directory: dist/{flow.mjs,
16
+ package.json, node_modules/}. Default output filename changed from bundle.mjs
17
+ to flow.mjs. The runtime image expects /app/flow/flow.mjs. flow.json schema is
18
+ unchanged (still v4); only @walkeros/cli bumps. Migration: see
19
+ https://walkeros.io/docs/migrate/cli-4x.
20
+
21
+ @walkeros/server-destination-gcp: removed obsolete walkerOS.bundle.external
22
+ annotation from package manifest. nft handles externalization automatically.
23
+ No behavior change for consumers.
24
+
25
+ - ed304b4: Bundler honors `walkerOS.bundle.external` declared in step-package
26
+ package.json files. Listed packages are externalized from the ESM bundle and
27
+ the bundler always installs them (plus their full transitive deps) into
28
+ `<outputDir>/node_modules/` via pacote — no `npm install` shell-out, no manual
29
+ deploy step. When externals is empty, output remains a single `bundle.mjs`
30
+ (backward compatible). When non-empty, output is a self-contained directory:
31
+ `bundle.mjs`, `package.json`, `package-lock.json`, `node_modules/`.
32
+
33
+ The bundler reads npm config (registry, scope tokens) from `.npmrc`,
34
+ parallelizes manifest fetches with retry, atomically stages each package
35
+ extraction (no half-populated `node_modules/` on failure), and reuses the
36
+ closure resolution from the existing `collectAllSpecs` BFS so peerDependencies
37
+ are honored.
38
+
39
+ Hard-errors when:
40
+ - A package in the install closure declares a `pre/install/postinstall` script
41
+ (pacote.extract does not run them).
42
+ - A step package names an external in `walkerOS.bundle.external` but does not
43
+ list it in `dependencies` or `peerDependencies`.
44
+ - Two step packages declare the same external and the resolved version does
45
+ not satisfy all consumers' constraints.
46
+
47
+ Warns (not errors) when:
48
+ - Bundle output contains unresolved `__dirname` / `__filename` references
49
+ (with package attribution by hit count).
50
+ - A step package's `walkerOS.bundle.*` block contains unknown keys (typo
51
+ guard).
52
+
53
+ New sibling export `downloadPackagesWithResolution` returns both the package
54
+ paths and the full `ResolutionResult`. Existing `downloadPackages` keeps its
55
+ return shape unchanged.
56
+
57
+ - e4b6cf4: Fix `walkeros bundle` failing on Windows when stage 2 import paths
58
+ contained backslashes that JS parsed as escape sequences.
59
+ - 381dfe7: Add an optional `setup` lifecycle to destinations, sources, and
60
+ stores.
61
+
62
+ Each package may now implement `setup?: SetupFn` to provision external
63
+ resources (BigQuery datasets and tables, Pub/Sub topics and subscriptions,
64
+ SQLite tables, webhook registrations, etc.). Setup is triggered only by the
65
+ new `walkeros setup <kind>.<name>` CLI command, never automatically by the
66
+ runtime, push, or deploy. Idempotency, ordering, and error semantics are the
67
+ package's responsibility; the framework provides the type slot, the CLI
68
+ invocation, and a `resolveSetup(value, defaults)` helper.
69
+
70
+ `LifecycleContext<C, E>` is the new shared context type used by both `setup`
71
+ and `destroy`. `DestroyContext` remains as a deprecated type alias for one
72
+ minor cycle. The `Types` bundle on `Destination`, `Source`, and `Store` gains
73
+ a 5th/6th/4th positional slot for setup options; existing aliases compile
74
+ unchanged because the slot defaults to `unknown`.
75
+ `Config<T>.setup?: boolean | SetupOptions<T>` is added across all three kinds
76
+ and validated by the corresponding Zod `ConfigSchema` plus the flow component
77
+ schemas in `@walkeros/core/schemas/flow.ts`.
78
+
79
+ CLI:
80
+ - `walkeros setup <kind>.<name>` runs a single component's `setup()` function.
81
+ - `<kind>` is `source`, `destination`, or `store` (transformers have no
82
+ provisioning).
83
+ - `--config <path>` (default `./flow.json`), `--flow <name>` for multi-flow
84
+ configs, plus standard `--json` / `--verbose` / `--silent`.
85
+ - Exit 0 on success or skip; non-zero on failure. Skip narration covers three
86
+ cases: no `setup()` on the package, `config.setup === false`, or
87
+ `config.setup` unset.
88
+ - When the package's `setup()` returns a non-undefined value, the CLI emits it
89
+ as JSON on stdout for `jq` piping.
90
+
91
+ - 03d7055: Merge `definitions` into `variables`. Single concept, single syntax
92
+ `$var.name(.deep.path)?`. Whole-string references preserve native type; inline
93
+ interpolation requires scalars. Deep paths and recursive resolution with cycle
94
+ detection now supported. `Flow.Definitions`, `Flow.Primitive`, and the `$def.`
95
+ reference syntax are removed.
96
+ - Updated dependencies [cb265eb]
97
+ - Updated dependencies [381dfe7]
98
+ - Updated dependencies [1524275]
99
+ - Updated dependencies [03d7055]
100
+ - @walkeros/collector@4.0.1-next-1778183328892
101
+ - @walkeros/core@4.0.1-next-1778183328892
102
+ - @walkeros/server-core@4.0.1-next-1778183328892
103
+ - @walkeros/server-destination-api@4.0.1-next-1778183328892
104
+
3
105
  ## 4.0.0
4
106
 
5
107
  ### Major Changes
package/README.md CHANGED
@@ -52,7 +52,7 @@ walkeros push flow.json --event '{"name":"product view"}' --simulate destination
52
52
  walkeros push flow.json --event '{"name":"product view"}'
53
53
 
54
54
  # Run a collection server locally
55
- walkeros run dist/bundle.mjs --port 3000
55
+ walkeros run dist/flow.mjs --port 3000
56
56
  ```
57
57
 
58
58
  ## Commands
@@ -79,7 +79,6 @@ walkeros bundle https://example.com/config.json # Remote URL
79
79
  - `--stats` - Show bundle statistics
80
80
  - `--json` - Output as JSON (implies --stats)
81
81
  - `--no-cache` - Disable package caching
82
- - `--dockerfile [file]` - Generate Dockerfile (or copy custom file) to dist/
83
82
  - `-v, --verbose` - Verbose output
84
83
  - `-s, --silent` - Suppress output
85
84
 
@@ -89,15 +88,31 @@ walkeros bundle https://example.com/config.json # Remote URL
89
88
  # Bundle with stats
90
89
  walkeros bundle examples/server-collect.json --stats
91
90
 
92
- # Bundle with auto-generated Dockerfile
93
- walkeros bundle flow.json --dockerfile
91
+ # Bundle to a custom output directory
92
+ walkeros bundle flow.json -o ./build/
93
+ ```
94
+
95
+ ### Server bundles use nft tracing
96
+
97
+ Server flows (`platform: "server"`) are bundled with `@vercel/nft`. The CLI
98
+ externalizes every step package, traces the entry to discover which files are
99
+ actually reachable at runtime, and copies only those files into
100
+ `dist/node_modules/`. Step packages are installed via pacote, driven by the
101
+ `config.bundle.packages` field in `flow.json`. **You do not need to run
102
+ `npm install` for step packages**: only `@walkeros/cli` belongs in your
103
+ `package.json` devDependencies.
94
104
 
95
- # Bundle with custom Dockerfile
96
- walkeros bundle flow.json --dockerfile Dockerfile.custom
105
+ The output is always a directory:
106
+
107
+ ```
108
+ dist/
109
+ ├── flow.mjs # ESM entry point
110
+ ├── package.json # informational sidecar
111
+ └── node_modules/ # only the files nft traced
97
112
  ```
98
113
 
99
- The output path uses convention-based defaults: `./dist/bundle.mjs` for server,
100
- `./dist/walker.js` for web.
114
+ For web flows the output stays a single self-contained file (default
115
+ `dist/walker.js`).
101
116
 
102
117
  ### push
103
118
 
@@ -162,23 +177,85 @@ walkeros push flow.json -e event.json --mock destination.ga4='{"status":"ok"}'
162
177
 
163
178
  ```bash
164
179
  # Push with pre-built bundle
165
- walkeros push dist/bundle.mjs --event '{"name":"order complete"}'
180
+ walkeros push dist/flow.mjs --event '{"name":"order complete"}'
166
181
 
167
182
  # Override platform detection
168
- walkeros push dist/bundle.js --platform server --event '{"name":"order complete"}'
183
+ walkeros push dist/walker.js --platform web --event '{"name":"order complete"}'
169
184
  ```
170
185
 
171
186
  **Push modes:**
172
187
 
173
- | Mode | Flag | API Calls | Use Case |
174
- | ---- | ---- | --------- | -------- |
175
- | Real | (none) | Real HTTP requests | Integration testing |
176
- | Simulate | `--simulate` | Mocked (captured) | Safe local testing |
177
- | Mock | `--mock` | Returns mock value | Controlled testing |
188
+ | Mode | Flag | API Calls | Use Case |
189
+ | -------- | ------------ | ------------------ | ------------------- |
190
+ | Real | (none) | Real HTTP requests | Integration testing |
191
+ | Simulate | `--simulate` | Mocked (captured) | Safe local testing |
192
+ | Mock | `--mock` | Returns mock value | Controlled testing |
178
193
 
179
194
  Use `--simulate` first to validate safely, then push without flags for real
180
195
  integrations.
181
196
 
197
+ ### setup
198
+
199
+ Run the optional `setup()` lifecycle on a single component to provision external
200
+ resources (BigQuery datasets, Pub/Sub topics, SQLite tables, webhook
201
+ registrations).
202
+
203
+ ```bash
204
+ walkeros setup <target> [options]
205
+ ```
206
+
207
+ **Target format:** `<kind>.<name>` matching `walkeros push --simulate`. Valid
208
+ kinds: `source`, `destination`, `store`. Transformers are pure functions and
209
+ have no setup.
210
+
211
+ **Options:**
212
+
213
+ - `-c, --config <path>` - Flow config file (default: `./flow.json`)
214
+ - `-f, --flow <name>` - Flow name for multi-flow configs
215
+ - `--json` - Output as JSON
216
+ - `-v, --verbose` - Verbose output
217
+ - `-s, --silent` - Suppress output
218
+
219
+ **Behavior:**
220
+
221
+ - Loads the flow config, resolves the named component, imports its package, and
222
+ calls `setup({ id, config, env, logger })`. No collector boot, no event
223
+ pipeline, no destinations are pushed to.
224
+ - Skips with an explanatory message in three cases: the package has no `setup`
225
+ function, `config.setup === false`, or `config.setup` is unset.
226
+ - When `setup()` returns a non-undefined value, the CLI emits it as JSON on
227
+ stdout for `jq`-style scripting.
228
+ - Exit code `0` on success or skip, non-zero on failure.
229
+
230
+ **Operator-time, never automatic.** Setup is explicit only. It is never
231
+ triggered by `push`, `simulate`, `deploy`, or the long-running runtime.
232
+ Operators run it once when provisioning, and again only when external resources
233
+ need to be re-provisioned.
234
+
235
+ **IAM note:** Setup typically needs higher permissions than runtime push (for
236
+ example, "create dataset" vs "write rows"). Operators commonly run setup with a
237
+ separate service account or different credentials than the runtime uses.
238
+
239
+ **Examples:**
240
+
241
+ ```bash
242
+ # Provision the BigQuery dataset and table for the destination named "bigquery"
243
+ # in the default flow file.
244
+ walkeros setup destination.bigquery
245
+
246
+ # Same but pointing to a specific flow in a multi-flow config.
247
+ walkeros setup destination.bigquery --flow analytics
248
+
249
+ # Custom config path.
250
+ walkeros setup destination.bigquery --config ./flows/prod.json
251
+
252
+ # Pipe the structured result to jq.
253
+ walkeros setup destination.bigquery --json | jq .datasetCreated
254
+
255
+ # Provision a Pub/Sub source's subscription.
256
+ walkeros setup source.events-in
257
+ ```
258
+
182
259
  ### run
183
260
 
184
261
  Run flows locally (no Docker daemon required).
@@ -201,8 +278,8 @@ walkeros run <config-file> [options]
201
278
  # Run collection server (auto-bundles JSON)
202
279
  walkeros run examples/server-collect.json --port 3000
203
280
 
204
- # Run with pre-built bundle
205
- walkeros run examples/server-collect.mjs --port 3000
281
+ # Run with a pre-built server bundle
282
+ walkeros run dist/flow.mjs --port 3000
206
283
  ```
207
284
 
208
285
  **How it works:**
@@ -328,18 +405,22 @@ walkeros bundle flow.json --no-cache
328
405
 
329
406
  ## Flow Configuration
330
407
 
331
- Flow configs use the `Flow.Config` format with `version` and `flows`:
408
+ Flow configs use the `Flow.Json` format with `version` and `flows`:
332
409
 
333
410
  ```json
334
411
  {
335
- "version": 3,
412
+ "version": 4,
336
413
  "flows": {
337
414
  "default": {
338
- "server": {},
339
- "packages": {
340
- "@walkeros/collector": { "imports": ["startFlow"] },
341
- "@walkeros/server-source-express": {},
342
- "@walkeros/destination-demo": {}
415
+ "config": {
416
+ "platform": "server",
417
+ "bundle": {
418
+ "packages": {
419
+ "@walkeros/collector": { "imports": ["startFlow"] },
420
+ "@walkeros/server-source-express": {},
421
+ "@walkeros/destination-demo": {}
422
+ }
423
+ }
343
424
  },
344
425
  "sources": {
345
426
  "http": {
@@ -363,7 +444,9 @@ Flow configs use the `Flow.Config` format with `version` and `flows`:
363
444
  }
364
445
  ```
365
446
 
366
- Platform is determined by the `web: {}` or `server: {}` key presence.
447
+ Platform is set via `config.platform` (`"web"` or `"server"`). The
448
+ `config.bundle.packages` field declares what pacote should install.
449
+ `config.bundle.overrides` pins transitive dependency versions when needed.
367
450
 
368
451
  ### Package Configuration Patterns
369
452
 
@@ -509,10 +592,7 @@ const result = await push(
509
592
  // result.usage = API call tracking data
510
593
 
511
594
  // Push for real
512
- await push(
513
- './flow.json',
514
- { name: 'page view', data: { title: 'Test' } },
515
- );
595
+ await push('./flow.json', { name: 'page view', data: { title: 'Test' } });
516
596
 
517
597
  // Run
518
598
  await runCommand({
@@ -566,7 +646,7 @@ walkeros push \
566
646
  walkeros bundle my-flow.json --stats
567
647
 
568
648
  # 4. Run locally
569
- walkeros run dist/bundle.mjs --port 3000
649
+ walkeros run dist/flow.mjs --port 3000
570
650
 
571
651
  # 5. In another terminal, test it
572
652
  curl -X POST http://localhost:3000/collect \
@@ -577,13 +657,16 @@ curl -X POST http://localhost:3000/collect \
577
657
  ## Architecture
578
658
 
579
659
  ```
580
- CLI (downloads packages + bundles with esbuild)
581
- ├─ Bundle optimized .mjs file
582
- ├─ Push execute bundle (with optional --simulate for testing)
583
- └─ Run execute bundle with built-in runtime
660
+ CLI
661
+ ├─ Pacote installs flow.json packages (no user-side npm install)
662
+ ├─ esbuild externalizes step packages, emits ESM entry
663
+ ├─ @vercel/nft traces entry, copies only used files
664
+ └─ Output: dist/{flow.mjs, package.json, node_modules/} (server)
665
+ dist/walker.js (web)
584
666
  ```
585
667
 
586
- **Key principle**: CLI handles both build-time and runtime operations.
668
+ **Key principle**: CLI handles both build-time install/trace/bundle and runtime
669
+ execution.
587
670
 
588
671
  ## Runner (Docker)
589
672
 
@@ -625,7 +708,7 @@ Run the bundle directly with the CLI:
625
708
  walkeros bundle flow.json
626
709
 
627
710
  # Run in production
628
- walkeros run dist/bundle.mjs --port 8080
711
+ walkeros run dist/flow.mjs --port 8080
629
712
  ```
630
713
 
631
714
  This runs the flow in the current Node.js process, suitable for deployment on