@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8593.1.50784dae35
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/.turbo/turbo-build.log +1 -1
- package/AGENTS.md +1 -0
- package/dist/agentic/guides/module-facts.json +164 -164
- package/dist/agentic/guides/module-facts.v2.json +164 -164
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/lib/generate-child-process.js +21 -3
- package/dist/lib/generate-child-process.js.map +2 -2
- package/dist/lib/generate-watch-events.js +135 -19
- package/dist/lib/generate-watch-events.js.map +2 -2
- package/dist/lib/generate-watch-plan.js +166 -0
- package/dist/lib/generate-watch-plan.js.map +7 -0
- package/dist/lib/generate-watch-runner.js +53 -0
- package/dist/lib/generate-watch-runner.js.map +7 -0
- package/dist/lib/generate-watch-structure.js +576 -203
- package/dist/lib/generate-watch-structure.js.map +3 -3
- package/dist/lib/generators/extensions/agent-files.js +1 -0
- package/dist/lib/generators/extensions/agent-files.js.map +2 -2
- package/dist/lib/generators/module-registry.js +148 -191
- package/dist/lib/generators/module-registry.js.map +3 -3
- package/dist/lib/generators/openapi.js +24 -1
- package/dist/lib/generators/openapi.js.map +2 -2
- package/dist/lib/generators/web-research-adapters.js +54 -22
- package/dist/lib/generators/web-research-adapters.js.map +2 -2
- package/dist/lib/in-process-generate-watcher.js +98 -75
- package/dist/lib/in-process-generate-watcher.js.map +2 -2
- package/dist/mercato.js +74 -46
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/lib/__tests__/generate-child-process.test.ts +30 -0
- package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
- package/src/lib/__tests__/generate-watch-plan.test.ts +98 -0
- package/src/lib/__tests__/generate-watch-runner.test.ts +126 -0
- package/src/lib/__tests__/generate-watch-structure.test.ts +522 -1
- package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
- package/src/lib/__tests__/module-inspection.test.ts +17 -11
- package/src/lib/generate-child-process.ts +26 -3
- package/src/lib/generate-watch-events.ts +189 -17
- package/src/lib/generate-watch-plan.ts +177 -0
- package/src/lib/generate-watch-runner.ts +62 -0
- package/src/lib/generate-watch-structure.ts +666 -227
- package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
- package/src/lib/generators/__tests__/openapi.test.ts +91 -1
- package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
- package/src/lib/generators/extension.ts +2 -0
- package/src/lib/generators/extensions/agent-files.ts +1 -0
- package/src/lib/generators/module-registry.ts +168 -200
- package/src/lib/generators/openapi.ts +34 -0
- package/src/lib/generators/web-research-adapters.ts +76 -21
- package/src/lib/in-process-generate-watcher.ts +151 -96
- package/src/mercato.ts +85 -53
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import type { GenerateWatcherChangeSignal } from './in-process-generate-watcher'
|
|
4
|
+
import type { GenerateWatchSnapshot } from './generate-watch-plan'
|
|
4
5
|
|
|
5
6
|
export type GenerateWatchTarget = {
|
|
6
7
|
directory: string
|
|
7
8
|
recursive: boolean
|
|
8
9
|
fileName?: string
|
|
10
|
+
/** Generator-owned directories whose attributed events must not trigger this recursive watch. */
|
|
11
|
+
excludedDirectories?: readonly string[]
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
type WatchHandle = {
|
|
@@ -29,31 +32,184 @@ export type GenerateWatchModuleTarget = {
|
|
|
29
32
|
appBase: string
|
|
30
33
|
pkgBase: string
|
|
31
34
|
watchPackageBase: boolean
|
|
35
|
+
/** Both installed source/runtime roots, including roots not present yet. */
|
|
36
|
+
additionalModuleBases?: readonly string[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function comparePaths(left: string, right: string): number {
|
|
40
|
+
return left < right ? -1 : left > right ? 1 : 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isWithinDirectory(candidate: string, directory: string): boolean {
|
|
44
|
+
const relative = path.relative(directory, candidate)
|
|
45
|
+
return relative === '' || (!path.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${path.sep}`))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function normalizeExcludedDirectories(
|
|
49
|
+
target: Pick<GenerateWatchTarget, 'directory' | 'recursive' | 'excludedDirectories'>,
|
|
50
|
+
): string[] {
|
|
51
|
+
if (!target.recursive) return []
|
|
52
|
+
return [...new Set(
|
|
53
|
+
(target.excludedDirectories ?? [])
|
|
54
|
+
.map((directory) => path.resolve(directory))
|
|
55
|
+
.filter((directory) => isWithinDirectory(directory, target.directory)),
|
|
56
|
+
)].sort(comparePaths)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function normalizeGenerateWatchTargets(targets: readonly GenerateWatchTarget[]): GenerateWatchTarget[] {
|
|
60
|
+
const unique = new Map<string, GenerateWatchTarget>()
|
|
61
|
+
for (const target of targets) {
|
|
62
|
+
const directory = path.resolve(target.directory)
|
|
63
|
+
const excludedDirectories = normalizeExcludedDirectories({ ...target, directory })
|
|
64
|
+
const normalized: GenerateWatchTarget = {
|
|
65
|
+
directory,
|
|
66
|
+
recursive: target.recursive,
|
|
67
|
+
...(target.fileName === undefined ? {} : { fileName: target.fileName }),
|
|
68
|
+
...(excludedDirectories.length > 0 ? { excludedDirectories } : {}),
|
|
69
|
+
}
|
|
70
|
+
unique.set(targetKey(normalized), normalized)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const recursiveDirectories = new Set(
|
|
74
|
+
[...unique.values()].filter((target) => target.recursive).map((target) => target.directory),
|
|
75
|
+
)
|
|
76
|
+
const allExcludedDirectories = [...new Set(
|
|
77
|
+
[...unique.values()].flatMap((target) => target.excludedDirectories ?? []),
|
|
78
|
+
)].sort(comparePaths)
|
|
79
|
+
const recursiveRoots = [...recursiveDirectories]
|
|
80
|
+
.filter((directory) => {
|
|
81
|
+
let ancestor = path.dirname(directory)
|
|
82
|
+
while (ancestor !== directory) {
|
|
83
|
+
if (recursiveDirectories.has(ancestor)) return false
|
|
84
|
+
const parent = path.dirname(ancestor)
|
|
85
|
+
if (parent === ancestor) break
|
|
86
|
+
ancestor = parent
|
|
87
|
+
}
|
|
88
|
+
return true
|
|
89
|
+
})
|
|
90
|
+
.sort(comparePaths)
|
|
91
|
+
.map((directory): GenerateWatchTarget => {
|
|
92
|
+
const excludedDirectories = allExcludedDirectories.filter((excluded) => (
|
|
93
|
+
isWithinDirectory(excluded, directory)
|
|
94
|
+
))
|
|
95
|
+
return {
|
|
96
|
+
directory,
|
|
97
|
+
recursive: true,
|
|
98
|
+
...(excludedDirectories.length > 0 ? { excludedDirectories } : {}),
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
const collapsed = [...recursiveRoots]
|
|
102
|
+
for (const target of unique.values()) {
|
|
103
|
+
if (target.recursive) continue
|
|
104
|
+
if (!target.fileName && recursiveRoots.some((root) => isWithinDirectory(target.directory, root.directory))) continue
|
|
105
|
+
collapsed.push(target)
|
|
106
|
+
}
|
|
107
|
+
return collapsed.sort((left, right) => (
|
|
108
|
+
comparePaths(left.directory, right.directory)
|
|
109
|
+
|| Number(left.recursive) - Number(right.recursive)
|
|
110
|
+
|| comparePaths(left.fileName ?? '', right.fileName ?? '')
|
|
111
|
+
|| comparePaths(
|
|
112
|
+
JSON.stringify(left.excludedDirectories ?? []),
|
|
113
|
+
JSON.stringify(right.excludedDirectories ?? []),
|
|
114
|
+
)
|
|
115
|
+
))
|
|
32
116
|
}
|
|
33
117
|
|
|
34
118
|
export function resolveGenerateWatchTargets(options: {
|
|
35
119
|
modulesFile: string
|
|
36
120
|
moduleRoots: GenerateWatchModuleTarget[]
|
|
37
121
|
resolveSourceMirrorBase: (packageBase: string) => string | null
|
|
122
|
+
additionalInputs?: readonly string[]
|
|
123
|
+
/** Watched without recursion; their per-file snapshot records are covered by these entries. */
|
|
124
|
+
shallowDirectories?: readonly string[]
|
|
125
|
+
appSourceDir?: string
|
|
126
|
+
outputDir?: string
|
|
127
|
+
outputDirectories?: readonly string[]
|
|
128
|
+
snapshot?: GenerateWatchSnapshot
|
|
38
129
|
}): GenerateWatchTarget[] {
|
|
39
|
-
const targets: GenerateWatchTarget[] = [{
|
|
40
|
-
directory: path.dirname(
|
|
130
|
+
const targets: GenerateWatchTarget[] = [options.modulesFile, ...(options.additionalInputs ?? [])].map((filePath) => ({
|
|
131
|
+
directory: path.dirname(filePath),
|
|
41
132
|
recursive: false,
|
|
42
|
-
fileName: path.basename(
|
|
43
|
-
}
|
|
133
|
+
fileName: path.basename(filePath),
|
|
134
|
+
}))
|
|
135
|
+
if (options.appSourceDir) targets.push({ directory: options.appSourceDir, recursive: true })
|
|
136
|
+
for (const directory of options.shallowDirectories ?? []) {
|
|
137
|
+
targets.push({ directory, recursive: false })
|
|
138
|
+
}
|
|
44
139
|
|
|
45
140
|
for (const roots of options.moduleRoots) {
|
|
46
141
|
targets.push({ directory: path.dirname(roots.appBase), recursive: true })
|
|
47
142
|
if (!roots.watchPackageBase) continue
|
|
48
143
|
|
|
49
144
|
targets.push({ directory: path.dirname(roots.pkgBase), recursive: true })
|
|
145
|
+
for (const base of roots.additionalModuleBases ?? []) {
|
|
146
|
+
targets.push({ directory: path.dirname(base), recursive: true })
|
|
147
|
+
}
|
|
148
|
+
const distMarker = `${path.sep}dist${path.sep}modules${path.sep}`
|
|
149
|
+
const distIndex = roots.pkgBase.lastIndexOf(distMarker)
|
|
50
150
|
const sourceMirror = options.resolveSourceMirrorBase(roots.pkgBase)
|
|
151
|
+
?? (distIndex < 0 ? null : `${roots.pkgBase.slice(0, distIndex)}${path.sep}src${path.sep}modules${path.sep}${roots.pkgBase.slice(distIndex + distMarker.length)}`)
|
|
51
152
|
if (sourceMirror) {
|
|
52
153
|
targets.push({ directory: path.dirname(sourceMirror), recursive: true })
|
|
53
154
|
}
|
|
54
155
|
}
|
|
55
156
|
|
|
56
|
-
|
|
157
|
+
const outputRoots = [...new Set(
|
|
158
|
+
[options.outputDir, ...(options.outputDirectories ?? [])]
|
|
159
|
+
.filter((directory): directory is string => Boolean(directory))
|
|
160
|
+
.map((directory) => path.resolve(directory)),
|
|
161
|
+
)].sort(comparePaths)
|
|
162
|
+
const baseRecursiveRoots = normalizeGenerateWatchTargets(targets)
|
|
163
|
+
.filter((target) => target.recursive)
|
|
164
|
+
.map((target) => target.directory)
|
|
165
|
+
const snapshotInputs = [...new Set(
|
|
166
|
+
[...(options.snapshot?.records.values() ?? [])]
|
|
167
|
+
// Adapter manifests change through installs (watched lockfiles) or by appearing
|
|
168
|
+
// in a shallow scan directory; one watcher per installed package would not scale.
|
|
169
|
+
.filter((record) => !(options.shallowDirectories?.length && record.category === 'web-research-adapters'))
|
|
170
|
+
.map((record) => path.resolve(record.path)),
|
|
171
|
+
)]
|
|
172
|
+
.filter((input) => !outputRoots.some((outputRoot) => isWithinDirectory(input, outputRoot)))
|
|
173
|
+
.filter((input) => !baseRecursiveRoots.some((root) => isWithinDirectory(input, root)))
|
|
174
|
+
.sort(comparePaths)
|
|
175
|
+
const snapshotStats = snapshotInputs.map((input) => {
|
|
176
|
+
try {
|
|
177
|
+
return { input, stat: fs.statSync(input) }
|
|
178
|
+
} catch {
|
|
179
|
+
return { input, stat: undefined }
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
for (const { input, stat } of snapshotStats) {
|
|
184
|
+
if (stat?.isDirectory()) targets.push({ directory: input, recursive: true })
|
|
185
|
+
}
|
|
186
|
+
const recursiveRoots = normalizeGenerateWatchTargets(targets)
|
|
187
|
+
.filter((target) => target.recursive)
|
|
188
|
+
.map((target) => target.directory)
|
|
189
|
+
|
|
190
|
+
for (const { input, stat } of snapshotStats) {
|
|
191
|
+
if (stat?.isDirectory() || recursiveRoots.some((root) => isWithinDirectory(input, root))) continue
|
|
192
|
+
const parent = path.dirname(input)
|
|
193
|
+
targets.push({
|
|
194
|
+
directory: parent,
|
|
195
|
+
recursive: false,
|
|
196
|
+
// A missing extensionless import can become foo.ts or foo/index.ts.
|
|
197
|
+
...(!stat && !path.extname(input) ? {} : { fileName: path.basename(input) }),
|
|
198
|
+
})
|
|
199
|
+
if (!fs.existsSync(parent)) {
|
|
200
|
+
let ancestor = path.dirname(parent)
|
|
201
|
+
while (!fs.existsSync(ancestor) && path.dirname(ancestor) !== ancestor) ancestor = path.dirname(ancestor)
|
|
202
|
+
targets.push({ directory: ancestor, recursive: false })
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return normalizeGenerateWatchTargets(targets.map((target) => {
|
|
207
|
+
if (!target.recursive) return target
|
|
208
|
+
const excludedDirectories = outputRoots.filter((outputRoot) => (
|
|
209
|
+
isWithinDirectory(outputRoot, path.resolve(target.directory))
|
|
210
|
+
))
|
|
211
|
+
return excludedDirectories.length > 0 ? { ...target, excludedDirectories } : target
|
|
212
|
+
}))
|
|
57
213
|
}
|
|
58
214
|
|
|
59
215
|
function targetKey(target: GenerateWatchTarget): string {
|
|
@@ -61,6 +217,7 @@ function targetKey(target: GenerateWatchTarget): string {
|
|
|
61
217
|
path.resolve(target.directory),
|
|
62
218
|
target.recursive,
|
|
63
219
|
target.fileName ?? '',
|
|
220
|
+
target.excludedDirectories ?? [],
|
|
64
221
|
])
|
|
65
222
|
}
|
|
66
223
|
|
|
@@ -88,6 +245,8 @@ export function createGenerateWatchChangeSignal(
|
|
|
88
245
|
let version = 0
|
|
89
246
|
let pollingFallback = false
|
|
90
247
|
let closed = false
|
|
248
|
+
let lastUnknownVersion = -1
|
|
249
|
+
let initialized = false
|
|
91
250
|
|
|
92
251
|
const closeWatchers = () => {
|
|
93
252
|
for (const watcher of watchers.values()) {
|
|
@@ -97,7 +256,7 @@ export function createGenerateWatchChangeSignal(
|
|
|
97
256
|
}
|
|
98
257
|
|
|
99
258
|
const enterPollingFallback = () => {
|
|
100
|
-
if (pollingFallback) return
|
|
259
|
+
if (closed || pollingFallback) return
|
|
101
260
|
pollingFallback = true
|
|
102
261
|
version += 1
|
|
103
262
|
closeWatchers()
|
|
@@ -105,6 +264,9 @@ export function createGenerateWatchChangeSignal(
|
|
|
105
264
|
|
|
106
265
|
return {
|
|
107
266
|
currentVersion: () => version,
|
|
267
|
+
fullGenerationReasonSince: (capturedVersion) => lastUnknownVersion > capturedVersion
|
|
268
|
+
? 'filesystem event did not identify a path'
|
|
269
|
+
: undefined,
|
|
108
270
|
hasSkippedTargets: () => skippedDirectories.size > 0,
|
|
109
271
|
usesPollingFallback: () => pollingFallback,
|
|
110
272
|
refresh: async () => {
|
|
@@ -117,22 +279,19 @@ export function createGenerateWatchChangeSignal(
|
|
|
117
279
|
enterPollingFallback()
|
|
118
280
|
return
|
|
119
281
|
}
|
|
282
|
+
if (closed || pollingFallback) return
|
|
120
283
|
|
|
121
284
|
const normalizedTargets = new Map<string, GenerateWatchTarget>()
|
|
122
285
|
const nextSkippedDirectories = new Set<string>()
|
|
123
|
-
for (const target of targets) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!directoryExists(normalized.directory)) {
|
|
129
|
-
nextSkippedDirectories.add(normalized.directory)
|
|
130
|
-
if (!skippedDirectories.has(normalized.directory)) {
|
|
131
|
-
try { options.onSkippedDirectory?.(normalized.directory) } catch {}
|
|
286
|
+
for (const target of normalizeGenerateWatchTargets(targets)) {
|
|
287
|
+
if (!directoryExists(target.directory)) {
|
|
288
|
+
nextSkippedDirectories.add(target.directory)
|
|
289
|
+
if (!skippedDirectories.has(target.directory)) {
|
|
290
|
+
try { options.onSkippedDirectory?.(target.directory) } catch {}
|
|
132
291
|
}
|
|
133
292
|
continue
|
|
134
293
|
}
|
|
135
|
-
normalizedTargets.set(targetKey(
|
|
294
|
+
normalizedTargets.set(targetKey(target), target)
|
|
136
295
|
}
|
|
137
296
|
skippedDirectories = nextSkippedDirectories
|
|
138
297
|
|
|
@@ -140,6 +299,7 @@ export function createGenerateWatchChangeSignal(
|
|
|
140
299
|
if (normalizedTargets.has(key)) continue
|
|
141
300
|
try { watcher.close() } catch {}
|
|
142
301
|
watchers.delete(key)
|
|
302
|
+
version += 1
|
|
143
303
|
}
|
|
144
304
|
|
|
145
305
|
for (const [key, target] of normalizedTargets) {
|
|
@@ -147,7 +307,17 @@ export function createGenerateWatchChangeSignal(
|
|
|
147
307
|
try {
|
|
148
308
|
const watcher = watchDirectory(
|
|
149
309
|
target,
|
|
150
|
-
() => {
|
|
310
|
+
(fileName) => {
|
|
311
|
+
if (closed || pollingFallback) return
|
|
312
|
+
if (fileName && target.recursive && target.excludedDirectories?.length) {
|
|
313
|
+
const changedPath = path.resolve(target.directory, fileName)
|
|
314
|
+
if (target.excludedDirectories.some((directory) => (
|
|
315
|
+
isWithinDirectory(changedPath, directory)
|
|
316
|
+
))) return
|
|
317
|
+
}
|
|
318
|
+
version += 1
|
|
319
|
+
if (!fileName) lastUnknownVersion = version
|
|
320
|
+
},
|
|
151
321
|
enterPollingFallback,
|
|
152
322
|
)
|
|
153
323
|
if (closed || pollingFallback) {
|
|
@@ -155,11 +325,13 @@ export function createGenerateWatchChangeSignal(
|
|
|
155
325
|
continue
|
|
156
326
|
}
|
|
157
327
|
watchers.set(key, watcher)
|
|
328
|
+
if (initialized) version += 1
|
|
158
329
|
} catch {
|
|
159
330
|
enterPollingFallback()
|
|
160
331
|
return
|
|
161
332
|
}
|
|
162
333
|
}
|
|
334
|
+
initialized = true
|
|
163
335
|
},
|
|
164
336
|
close: () => {
|
|
165
337
|
if (closed) return
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export type GenerateWatchCategory =
|
|
2
|
+
| 'api-route' | 'frontend-page' | 'backend-page' | 'commands' | 'di' | 'entities'
|
|
3
|
+
| 'search' | 'events' | 'subscribers' | 'workers' | 'dashboard-widgets'
|
|
4
|
+
| 'injection-widgets' | 'cli' | 'i18n' | 'registry-convention' | 'extension'
|
|
5
|
+
| 'openapi' | 'web-research-adapters' | 'generator-plugin' | 'configuration' | 'unknown'
|
|
6
|
+
|
|
7
|
+
export type GenerateWatchRecord = {
|
|
8
|
+
key: string
|
|
9
|
+
category: GenerateWatchCategory
|
|
10
|
+
fingerprint: string
|
|
11
|
+
path: string
|
|
12
|
+
extensionId?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type GenerateWatchSnapshot = {
|
|
16
|
+
checksum: string
|
|
17
|
+
records: ReadonlyMap<string, GenerateWatchRecord>
|
|
18
|
+
/** Capture validity failures only; unsupported but readable inputs use full-fallback records. */
|
|
19
|
+
fullReasons: readonly string[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type GenerateWatchChange = {
|
|
23
|
+
kind: 'add' | 'change' | 'delete'
|
|
24
|
+
key: string
|
|
25
|
+
category: GenerateWatchCategory
|
|
26
|
+
path: string
|
|
27
|
+
extensionId?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type GenerateWatchGroup =
|
|
31
|
+
| 'entity-ids' | 'registry' | 'entities' | 'di' | 'package-sources'
|
|
32
|
+
| 'web-research-adapters' | 'openapi'
|
|
33
|
+
|
|
34
|
+
export type GenerateWatchPlan = {
|
|
35
|
+
mode: 'full' | 'incremental' | 'none'
|
|
36
|
+
groups: readonly GenerateWatchGroup[]
|
|
37
|
+
registryOutputs: readonly string[]
|
|
38
|
+
changes: readonly GenerateWatchChange[]
|
|
39
|
+
reasons: readonly string[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const GROUP_ORDER: readonly GenerateWatchGroup[] = [
|
|
43
|
+
'entity-ids', 'registry', 'entities', 'di', 'package-sources', 'web-research-adapters', 'openapi',
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const REGISTRY_ORDER = [
|
|
47
|
+
'main', 'runtime', 'app', 'bootstrap', 'cli', 'frontend-routes', 'backend-routes',
|
|
48
|
+
'api-routes', 'commands', 'i18n', 'supervisor', 'enabled-ids', 'bootstrap-registrations', 'plugins',
|
|
49
|
+
'registry.search', 'registry.notifications', 'registry.messages', 'registry.ai-tools',
|
|
50
|
+
'registry.ai-agents', 'registry.agent-files', 'registry.events', 'registry.analytics',
|
|
51
|
+
'registry.translatable-fields', 'registry.enrichers', 'registry.interceptors',
|
|
52
|
+
'registry.component-overrides', 'registry.inbox-actions', 'registry.guards',
|
|
53
|
+
'registry.command-interceptors', 'registry.page-middleware', 'registry.dashboard-widgets',
|
|
54
|
+
'registry.injection-widgets', 'registry.workflows',
|
|
55
|
+
] as const
|
|
56
|
+
|
|
57
|
+
const EXTENSION_IDS: readonly string[] = REGISTRY_ORDER.filter((id) => id.startsWith('registry.'))
|
|
58
|
+
const MAIN_IMPORT_EXTENSIONS: Readonly<Record<string, true>> = {
|
|
59
|
+
'registry.events': true, 'registry.analytics': true, 'registry.translatable-fields': true, 'registry.workflows': true,
|
|
60
|
+
}
|
|
61
|
+
const ALL_MODULE_REGISTRIES = ['main', 'runtime', 'app', 'bootstrap', 'cli'] as const
|
|
62
|
+
|
|
63
|
+
/** Select aggregate consumers, never just the changed module within an aggregate. */
|
|
64
|
+
export function planGenerateWatchChanges(
|
|
65
|
+
changes: readonly GenerateWatchChange[],
|
|
66
|
+
fullReasons: readonly string[] = [],
|
|
67
|
+
): GenerateWatchPlan {
|
|
68
|
+
const orderedChanges = [...changes].sort((left, right) =>
|
|
69
|
+
left.key.localeCompare(right.key) || left.kind.localeCompare(right.kind),
|
|
70
|
+
)
|
|
71
|
+
const reasons = new Set(fullReasons)
|
|
72
|
+
const groups = new Set<GenerateWatchGroup>()
|
|
73
|
+
const outputs = new Set<string>()
|
|
74
|
+
const registry = (...selected: readonly string[]) => {
|
|
75
|
+
groups.add('registry')
|
|
76
|
+
for (const output of selected) outputs.add(output)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const change of orderedChanges) {
|
|
80
|
+
switch (change.category) {
|
|
81
|
+
case 'api-route':
|
|
82
|
+
registry('main', 'runtime', 'api-routes')
|
|
83
|
+
groups.add('openapi')
|
|
84
|
+
break
|
|
85
|
+
case 'openapi':
|
|
86
|
+
groups.add('openapi')
|
|
87
|
+
break
|
|
88
|
+
case 'web-research-adapters':
|
|
89
|
+
groups.add('web-research-adapters')
|
|
90
|
+
break
|
|
91
|
+
case 'frontend-page':
|
|
92
|
+
registry('main', 'runtime', 'app', 'frontend-routes')
|
|
93
|
+
break
|
|
94
|
+
case 'backend-page':
|
|
95
|
+
registry('main', 'runtime', 'app', 'backend-routes')
|
|
96
|
+
break
|
|
97
|
+
case 'entities':
|
|
98
|
+
groups.add('entity-ids')
|
|
99
|
+
groups.add('entities')
|
|
100
|
+
break
|
|
101
|
+
case 'di':
|
|
102
|
+
groups.add('di')
|
|
103
|
+
break
|
|
104
|
+
case 'commands':
|
|
105
|
+
registry('commands')
|
|
106
|
+
break
|
|
107
|
+
case 'search':
|
|
108
|
+
registry('registry.search')
|
|
109
|
+
break
|
|
110
|
+
case 'events':
|
|
111
|
+
registry('main', 'registry.events')
|
|
112
|
+
break
|
|
113
|
+
case 'subscribers':
|
|
114
|
+
registry(...ALL_MODULE_REGISTRIES)
|
|
115
|
+
break
|
|
116
|
+
case 'workers':
|
|
117
|
+
// The existing i18n renderer also emits the worker abandon-hook helper import.
|
|
118
|
+
registry(...ALL_MODULE_REGISTRIES, 'supervisor', 'i18n')
|
|
119
|
+
break
|
|
120
|
+
case 'dashboard-widgets':
|
|
121
|
+
registry('main', 'app', 'bootstrap', 'cli', 'registry.dashboard-widgets')
|
|
122
|
+
break
|
|
123
|
+
case 'injection-widgets':
|
|
124
|
+
registry('registry.injection-widgets')
|
|
125
|
+
break
|
|
126
|
+
case 'cli':
|
|
127
|
+
registry('main', 'cli')
|
|
128
|
+
if (/(?:^|[/\\])scheduler[/\\]cli\.[jt]sx?$/.test(change.path) || change.key.includes(':scheduler:')) registry('supervisor')
|
|
129
|
+
break
|
|
130
|
+
case 'i18n':
|
|
131
|
+
registry('main', 'runtime', 'app', 'cli', 'i18n')
|
|
132
|
+
break
|
|
133
|
+
case 'registry-convention':
|
|
134
|
+
if (change.extensionId === 'supervisor') registry('supervisor')
|
|
135
|
+
else if (/(?:^|[/\\])vector\.[jt]sx?$/.test(change.path)) registry('cli')
|
|
136
|
+
else registry(...ALL_MODULE_REGISTRIES)
|
|
137
|
+
break
|
|
138
|
+
case 'extension': {
|
|
139
|
+
const id = change.extensionId
|
|
140
|
+
if (!id || !EXTENSION_IDS.includes(id)) {
|
|
141
|
+
reasons.add(`Unknown generator extension dependency: ${change.path}`)
|
|
142
|
+
break
|
|
143
|
+
}
|
|
144
|
+
registry(id)
|
|
145
|
+
if (MAIN_IMPORT_EXTENSIONS[id]) registry('main')
|
|
146
|
+
// This convention is also discovered as an ordinary command loader.
|
|
147
|
+
if (id === 'registry.command-interceptors') registry('commands')
|
|
148
|
+
break
|
|
149
|
+
}
|
|
150
|
+
case 'generator-plugin':
|
|
151
|
+
reasons.add(`Generator plugin dependency changed: ${change.path}`)
|
|
152
|
+
break
|
|
153
|
+
case 'configuration':
|
|
154
|
+
reasons.add(`Generator configuration or module authority changed: ${change.path}`)
|
|
155
|
+
break
|
|
156
|
+
case 'unknown':
|
|
157
|
+
reasons.add(`Unclassified generator dependency changed: ${change.path}`)
|
|
158
|
+
break
|
|
159
|
+
default:
|
|
160
|
+
reasons.add(`Unsupported generator dependency: ${change.path}`)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (reasons.size > 0) {
|
|
165
|
+
return {
|
|
166
|
+
mode: 'full', groups: [...GROUP_ORDER], registryOutputs: [],
|
|
167
|
+
changes: orderedChanges, reasons: [...reasons].sort((left, right) => left < right ? -1 : left > right ? 1 : 0),
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
mode: groups.size > 0 ? 'incremental' : 'none',
|
|
172
|
+
groups: GROUP_ORDER.filter((group) => groups.has(group)),
|
|
173
|
+
registryOutputs: REGISTRY_ORDER.filter((output) => outputs.has(output)),
|
|
174
|
+
changes: orderedChanges,
|
|
175
|
+
reasons: [],
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import type { GenerateWatchPlan } from './generate-watch-plan'
|
|
3
|
+
import type { PackageResolver } from './resolver'
|
|
4
|
+
import type { GeneratorResult } from './utils'
|
|
5
|
+
import { createResolver } from './resolver'
|
|
6
|
+
import * as generators from './generators'
|
|
7
|
+
import { getOpenApiGeneratorDependencies } from './generators/openapi'
|
|
8
|
+
|
|
9
|
+
/** Run selected generators in the same dependency order as explicit full generation. */
|
|
10
|
+
export async function runGenerateWatchSuite(
|
|
11
|
+
quiet: boolean,
|
|
12
|
+
plan?: GenerateWatchPlan,
|
|
13
|
+
providedResolver?: PackageResolver,
|
|
14
|
+
onOpenApiCascade?: (reason: string) => void,
|
|
15
|
+
): Promise<boolean> {
|
|
16
|
+
if (plan?.mode === 'none') return false
|
|
17
|
+
const resolver = providedResolver ?? createResolver()
|
|
18
|
+
const selected = (group: GenerateWatchPlan['groups'][number]) =>
|
|
19
|
+
plan?.mode !== 'incremental' || plan.groups.includes(group)
|
|
20
|
+
const openApiSelected = selected('openapi')
|
|
21
|
+
const openApiDependencies = openApiSelected ? undefined : getOpenApiGeneratorDependencies(resolver)
|
|
22
|
+
let cascadeReason: string | undefined
|
|
23
|
+
let changed = false
|
|
24
|
+
const record = (result: GeneratorResult | undefined) => {
|
|
25
|
+
if (result?.errors.length) throw new Error(result.errors.join('\n'))
|
|
26
|
+
if (result?.filesWritten.length) changed = true
|
|
27
|
+
if (openApiSelected || cascadeReason || !result?.filesWritten.length) return
|
|
28
|
+
if (openApiDependencies === null) {
|
|
29
|
+
cascadeReason = 'generated bytes changed but the OpenAPI dependency manifest is unavailable'
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
for (const changedPath of result.filesWritten) {
|
|
33
|
+
const absolutePath = path.resolve(changedPath)
|
|
34
|
+
const dependentPath = openApiDependencies?.find((inputPath) =>
|
|
35
|
+
inputPath === absolutePath || inputPath.startsWith(`${absolutePath}${path.sep}`))
|
|
36
|
+
if (dependentPath) {
|
|
37
|
+
cascadeReason = `generated OpenAPI dependency changed: ${dependentPath}`
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (selected('entity-ids')) record(await generators.generateEntityIds({ resolver, quiet }))
|
|
44
|
+
if (selected('registry')) {
|
|
45
|
+
const results = await generators.generateModuleRegistries({
|
|
46
|
+
resolver,
|
|
47
|
+
quiet,
|
|
48
|
+
...(plan?.mode === 'incremental' ? { outputGroups: plan.registryOutputs } : {}),
|
|
49
|
+
})
|
|
50
|
+
for (const result of results) record(result)
|
|
51
|
+
}
|
|
52
|
+
if (selected('entities')) record(await generators.generateModuleEntities({ resolver, quiet }))
|
|
53
|
+
if (selected('di')) record(await generators.generateModuleDi({ resolver, quiet }))
|
|
54
|
+
if (selected('package-sources')) record(await generators.generateModulePackageSources({ resolver, quiet }))
|
|
55
|
+
if (selected('web-research-adapters')) record(await generators.generateWebResearchAdapters({ resolver, quiet }))
|
|
56
|
+
if (cascadeReason) {
|
|
57
|
+
if (onOpenApiCascade) onOpenApiCascade(cascadeReason)
|
|
58
|
+
else if (!quiet) console.log(`[generate:watch] Cascading; groups=openapi; reason=${cascadeReason}`)
|
|
59
|
+
}
|
|
60
|
+
if (openApiSelected || cascadeReason) record(await generators.generateOpenApi({ resolver, quiet }))
|
|
61
|
+
return changed
|
|
62
|
+
}
|