@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8665.1.2455b2503c
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 +4 -2
- package/AGENTS.md +3 -0
- package/dist/agentic/guides/architecture.md +2 -2
- package/dist/agentic/guides/extensions.md +7 -2
- package/dist/agentic/guides/framework-extension-points.md +1 -0
- package/dist/agentic/guides/infrastructure-providers.md +20 -0
- package/dist/agentic/guides/integrations.md +2 -2
- package/dist/agentic/guides/module-facts.json +2564 -265
- package/dist/agentic/guides/module-facts.v2.json +2580 -265
- 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/assisted_selling/acl-features.md +16 -0
- package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
- package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
- package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/workers.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/di-registrations-rich.md +11 -0
- package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
- package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
- package/dist/agentic/guides/modules/backups/index.md +5 -2
- 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/acl-features.md +2 -1
- package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
- package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
- package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
- package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
- package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
- package/dist/agentic/guides/modules/catalog/entities.md +1 -0
- package/dist/agentic/guides/modules/catalog/events.md +4 -1
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
- package/dist/agentic/guides/modules/catalog/index.md +9 -9
- package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
- package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
- package/dist/agentic/guides/modules/catalog/workers.md +1 -0
- 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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
- package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
- package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
- package/dist/agentic/guides/modules/customers/index.md +3 -3
- package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
- package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
- package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/dashboards/index.md +2 -3
- 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/di-registrations-rich.md +8 -8
- package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
- package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
- package/dist/agentic/guides/modules/integrations/index.md +2 -2
- package/dist/agentic/guides/modules/integrations/setup.md +1 -1
- package/dist/agentic/guides/modules/integrations/workers.md +3 -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/exact-override-targets.md +3 -3
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/resources/setup.md +1 -1
- package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
- package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/sales/index.md +3 -3
- package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
- 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/contribution-resolutions.md +1 -1
- package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/staff/workers.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 +811 -21
- package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
- package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
- package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
- package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
- package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
- package/dist/agentic/guides/reference-modules/example/events.md +2 -1
- package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
- package/dist/agentic/guides/reference-modules/example/index.md +7 -7
- package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
- package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
- package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
- package/dist/agentic/guides/upstream/AGENTS.md +5 -4
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
- package/dist/agentic/guides/upstream/manifest.json +3 -3
- package/dist/agentic/shared/AGENTS.md.template +11 -15
- package/dist/agentic/shared/ai/harness/README.md +4 -2
- package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
- package/dist/agentic/shared/ai/harness/cases.json +1420 -41
- package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
- package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
- package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
- package/dist/agentic/shared/ai/harness/validators.json +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
- package/dist/lib/cache-provider-manifest.js +9 -0
- package/dist/lib/cache-provider-manifest.js.map +7 -0
- 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 +170 -0
- package/dist/lib/generate-watch-plan.js.map +7 -0
- package/dist/lib/generate-watch-runner.js +54 -0
- package/dist/lib/generate-watch-runner.js.map +7 -0
- package/dist/lib/generate-watch-structure.js +578 -203
- package/dist/lib/generate-watch-structure.js.map +3 -3
- package/dist/lib/generators/ast/writers.js +5 -1
- package/dist/lib/generators/ast/writers.js.map +2 -2
- package/dist/lib/generators/cache-providers.js +80 -0
- package/dist/lib/generators/cache-providers.js.map +7 -0
- 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/form-section-ast.js +156 -0
- package/dist/lib/generators/form-section-ast.js.map +7 -0
- package/dist/lib/generators/form-section-extension-compiler.js +568 -0
- package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
- package/dist/lib/generators/form-section-extension-source.js +245 -0
- package/dist/lib/generators/form-section-extension-source.js.map +7 -0
- package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
- package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
- package/dist/lib/generators/form-sections.js +773 -0
- package/dist/lib/generators/form-sections.js.map +7 -0
- package/dist/lib/generators/index.js +2 -0
- package/dist/lib/generators/index.js.map +2 -2
- package/dist/lib/generators/module-entities.js +21 -2
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +2 -1
- package/dist/lib/generators/module-extension-facts.js.map +2 -2
- package/dist/lib/generators/module-facts.js +30 -1
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-override-targets.js +24 -2
- package/dist/lib/generators/module-override-targets.js.map +2 -2
- package/dist/lib/generators/module-registry.js +223 -194
- package/dist/lib/generators/module-registry.js.map +3 -3
- package/dist/lib/generators/openapi.js +51 -18
- 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/lib/post-generate-invalidation.js +20 -1
- package/dist/lib/post-generate-invalidation.js.map +2 -2
- package/dist/lib/resolver.js +195 -1
- package/dist/lib/resolver.js.map +3 -3
- package/dist/lib/single-instance-strategy-guard.js +26 -3
- package/dist/lib/single-instance-strategy-guard.js.map +2 -2
- package/dist/mercato.js +106 -50
- package/dist/mercato.js.map +2 -2
- package/jest.config.cjs +2 -0
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +18 -0
- package/src/__tests__/rotation-json-output.test.ts +52 -0
- package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
- 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 +99 -0
- package/src/lib/__tests__/generate-watch-runner.test.ts +138 -0
- package/src/lib/__tests__/generate-watch-structure.test.ts +556 -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/__tests__/post-generate-invalidation.test.ts +108 -0
- package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
- package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
- package/src/lib/cache-provider-manifest.ts +8 -0
- 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 +180 -0
- package/src/lib/generate-watch-runner.ts +63 -0
- package/src/lib/generate-watch-structure.ts +670 -227
- package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
- package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
- package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
- package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
- package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
- package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
- package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
- package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
- package/src/lib/generators/__tests__/openapi.test.ts +147 -10
- package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
- package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
- package/src/lib/generators/ast/writers.ts +6 -1
- package/src/lib/generators/cache-providers.ts +111 -0
- package/src/lib/generators/extension.ts +2 -0
- package/src/lib/generators/extensions/agent-files.ts +1 -0
- package/src/lib/generators/form-section-ast.ts +166 -0
- package/src/lib/generators/form-section-extension-compiler.ts +632 -0
- package/src/lib/generators/form-section-extension-source.ts +308 -0
- package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
- package/src/lib/generators/form-sections.ts +896 -0
- package/src/lib/generators/index.ts +1 -0
- package/src/lib/generators/module-entities.ts +22 -4
- package/src/lib/generators/module-extension-facts.ts +1 -0
- package/src/lib/generators/module-facts.ts +40 -0
- package/src/lib/generators/module-override-targets.ts +19 -0
- package/src/lib/generators/module-registry.ts +246 -202
- package/src/lib/generators/openapi.ts +65 -20
- package/src/lib/generators/web-research-adapters.ts +76 -21
- package/src/lib/in-process-generate-watcher.ts +151 -96
- package/src/lib/post-generate-invalidation.ts +28 -1
- package/src/lib/resolver.ts +218 -0
- package/src/lib/single-instance-strategy-guard.ts +51 -1
- package/src/mercato.ts +117 -57
- package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { readEnabledModulesFromConfig } from '../resolver'
|
|
5
|
+
|
|
6
|
+
const entry = "{ id: 'example', overrides: { forms: { sections: { 'example.todo/default/update/details': null } } } }"
|
|
7
|
+
const original = process.env.NEXT_PUBLIC_OM_CUSTOM_FORM
|
|
8
|
+
|
|
9
|
+
let directory: string
|
|
10
|
+
|
|
11
|
+
function configure(source: string) {
|
|
12
|
+
const filename = path.join(directory, 'modules.ts')
|
|
13
|
+
fs.writeFileSync(filename, source)
|
|
14
|
+
return readEnabledModulesFromConfig(filename)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
directory = fs.mkdtempSync(path.join(os.tmpdir(), 'crudform-gating-'))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
fs.rmSync(directory, { recursive: true, force: true })
|
|
23
|
+
if (original === undefined) delete process.env.NEXT_PUBLIC_OM_CUSTOM_FORM
|
|
24
|
+
else process.env.NEXT_PUBLIC_OM_CUSTOM_FORM = original
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('honors both public branches and accepts ungated form section overrides', () => {
|
|
28
|
+
expect(configure(`export const enabledModules = [${entry}]`).map(({ id }) => id)).toEqual(['example'])
|
|
29
|
+
const source = `
|
|
30
|
+
export const enabledModules = [];
|
|
31
|
+
if (process.env.NEXT_PUBLIC_OM_CUSTOM_FORM) enabledModules.push(${entry});
|
|
32
|
+
`
|
|
33
|
+
delete process.env.NEXT_PUBLIC_OM_CUSTOM_FORM
|
|
34
|
+
expect(configure(source)).toEqual([])
|
|
35
|
+
process.env.NEXT_PUBLIC_OM_CUSTOM_FORM = 'yes'
|
|
36
|
+
expect(configure(source).map(({ id }) => id)).toEqual(['example'])
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it.each([
|
|
40
|
+
`if (process.env.OM_PRIVATE_FORM) enabledModules.push(${entry});`,
|
|
41
|
+
`if (process.env.OM_PRIVATE_FORM) enabledModules.push({id:'normal'}); else enabledModules.push(${entry});`,
|
|
42
|
+
`const gated = process.env['OM_PRIVATE_FORM']; if (gated) { enabledModules.push(${entry}); }`,
|
|
43
|
+
`const definition = ${entry}; if (process.env.OM_PRIVATE_FORM) enabledModules.push(definition);`,
|
|
44
|
+
`process.env.OM_PRIVATE_FORM && enabledModules.push(${entry});`,
|
|
45
|
+
])('rejects a server-only form gate even when the branch is inactive (%s)', (branch) => {
|
|
46
|
+
expect(() => configure(`export const enabledModules = []; ${branch}`)).toThrow(/forms\.sections.*OM_PRIVATE_FORM/)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('rejects a gate derived from a dynamically read environment object', () => {
|
|
50
|
+
expect(() => configure(`
|
|
51
|
+
const { OM_PRIVATE_FORM } = process.env;
|
|
52
|
+
export const enabledModules = [];
|
|
53
|
+
if (OM_PRIVATE_FORM) enabledModules.push(${entry});
|
|
54
|
+
`)).toThrow(/forms\.sections.*dynamic process\.env/)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('leaves other override domains and legacy server-only gated modules alone', () => {
|
|
58
|
+
expect(configure(`
|
|
59
|
+
export const enabledModules = [{ id: 'example', overrides: {
|
|
60
|
+
forms: { sections: {} },
|
|
61
|
+
nav: process.env.OM_PRIVATE_FORM ? { groupOrder: [] } : undefined,
|
|
62
|
+
}}];
|
|
63
|
+
if (process.env.OM_PRIVATE_FORM) enabledModules.push({ id: 'normal' });
|
|
64
|
+
`).map(({ id }) => id)).toEqual(['example'])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('retains a literal forms selector through a local alias, including the shared placement enum', () => {
|
|
68
|
+
expect(configure(`
|
|
69
|
+
const sections = { 'example.todo/default/update/extra': {
|
|
70
|
+
operation: 'add', contributionId: 'example.patch.extra',
|
|
71
|
+
placement: { position: InjectionPosition.After, relativeTo: 'details' },
|
|
72
|
+
} } as const;
|
|
73
|
+
const forms = { sections };
|
|
74
|
+
const overrides = { forms };
|
|
75
|
+
export const enabledModules = [{ id: 'example', overrides }];
|
|
76
|
+
`)[0].formSectionOverrides).toEqual({
|
|
77
|
+
'example.todo/default/update/extra': {
|
|
78
|
+
operation: 'add', contributionId: 'example.patch.extra',
|
|
79
|
+
placement: { position: 'after', relativeTo: 'details' },
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCacheProvider,
|
|
3
|
+
defineCacheProviderRegistration,
|
|
4
|
+
resetCacheProviderSelectionForTests,
|
|
5
|
+
setCacheProviderRegistrations,
|
|
6
|
+
type CacheProviderPlacement,
|
|
7
|
+
} from '@open-mercato/cache/provider'
|
|
8
|
+
import { loadCacheProviderManifest } from '../cache-provider-manifest'
|
|
1
9
|
import {
|
|
2
10
|
assertSingleInstanceStrategies,
|
|
3
11
|
evaluateSingleInstanceGuard,
|
|
12
|
+
readInfraStrategySnapshot,
|
|
13
|
+
resolveEffectiveCacheProviderSnapshot,
|
|
4
14
|
SingleInstanceStrategyError,
|
|
5
15
|
type InfraStrategySnapshot,
|
|
6
16
|
} from '../single-instance-strategy-guard'
|
|
7
17
|
|
|
18
|
+
jest.mock('../cache-provider-manifest', () => ({ loadCacheProviderManifest: jest.fn() }))
|
|
19
|
+
|
|
20
|
+
const loadManifestMock = jest.mocked(loadCacheProviderManifest)
|
|
21
|
+
|
|
8
22
|
const singleInstanceSnapshot: InfraStrategySnapshot = {
|
|
9
23
|
cacheStrategy: 'memory',
|
|
10
24
|
queueStrategy: 'local',
|
|
@@ -94,6 +108,37 @@ describe('evaluateSingleInstanceGuard', () => {
|
|
|
94
108
|
})
|
|
95
109
|
})
|
|
96
110
|
|
|
111
|
+
describe('stock cache strategy characterization', () => {
|
|
112
|
+
it('reads CACHE_STRATEGY into the snapshot and defaults to memory', () => {
|
|
113
|
+
expect(readInfraStrategySnapshot({ CACHE_STRATEGY: 'redis' }).cacheStrategy).toBe('redis')
|
|
114
|
+
expect(readInfraStrategySnapshot({ CACHE_STRATEGY: ' sqlite ' }).cacheStrategy).toBe('sqlite')
|
|
115
|
+
expect(readInfraStrategySnapshot({}).cacheStrategy).toBe('memory')
|
|
116
|
+
expect(readInfraStrategySnapshot({ CACHE_STRATEGY: '' }).cacheStrategy).toBe('memory')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('treats a redis cache as multi-instance safe', () => {
|
|
120
|
+
const result = evaluateSingleInstanceGuard(
|
|
121
|
+
{ ...multiInstanceSafeSnapshot, cacheStrategy: 'redis' },
|
|
122
|
+
{ NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' },
|
|
123
|
+
)
|
|
124
|
+
expect(result.offenders.find((offender) => offender.component === 'cache')).toBeUndefined()
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it.each([['memory'], ['sqlite'], ['jsonfile']])(
|
|
128
|
+
'reports a %s cache as a CACHE_STRATEGY offender',
|
|
129
|
+
(cacheStrategy) => {
|
|
130
|
+
const result = evaluateSingleInstanceGuard(
|
|
131
|
+
{ ...multiInstanceSafeSnapshot, cacheStrategy },
|
|
132
|
+
{ NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' },
|
|
133
|
+
)
|
|
134
|
+
expect(result.action).toBe('fail')
|
|
135
|
+
expect(result.offenders).toEqual([
|
|
136
|
+
{ component: 'cache', envVar: 'CACHE_STRATEGY', configured: cacheStrategy, safeValues: ['redis'] },
|
|
137
|
+
])
|
|
138
|
+
},
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
|
|
97
142
|
describe('assertSingleInstanceStrategies', () => {
|
|
98
143
|
function createLogger() {
|
|
99
144
|
return {
|
|
@@ -136,3 +181,87 @@ describe('assertSingleInstanceStrategies', () => {
|
|
|
136
181
|
expect(logger.error).not.toHaveBeenCalled()
|
|
137
182
|
})
|
|
138
183
|
})
|
|
184
|
+
|
|
185
|
+
describe('single-instance guard with a registered cache provider', () => {
|
|
186
|
+
const productionMultiInstance = { NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' }
|
|
187
|
+
|
|
188
|
+
it('treats a provider with shared placement as multi-instance safe regardless of CACHE_STRATEGY', () => {
|
|
189
|
+
const result = evaluateSingleInstanceGuard(
|
|
190
|
+
{ ...multiInstanceSafeSnapshot, cacheStrategy: 'memory', cacheProvider: { id: 'acme/shared', placement: 'shared' } },
|
|
191
|
+
productionMultiInstance,
|
|
192
|
+
)
|
|
193
|
+
expect(result.action).toBe('ok')
|
|
194
|
+
expect(result.offenders).toHaveLength(0)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('reports a local provider as a CACHE_PROVIDER offender even when CACHE_STRATEGY=redis', () => {
|
|
198
|
+
const result = evaluateSingleInstanceGuard(
|
|
199
|
+
{ ...multiInstanceSafeSnapshot, cacheProvider: { id: 'acme/local', placement: 'local' } },
|
|
200
|
+
productionMultiInstance,
|
|
201
|
+
)
|
|
202
|
+
expect(result.action).toBe('fail')
|
|
203
|
+
expect(result.offenders).toEqual([
|
|
204
|
+
expect.objectContaining({ component: 'cache', envVar: 'CACHE_PROVIDER', configured: 'acme/local' }),
|
|
205
|
+
])
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('carries the provider snapshot through readInfraStrategySnapshot only when one is resolved', () => {
|
|
209
|
+
expect(readInfraStrategySnapshot({}, { cacheProvider: null })).not.toHaveProperty('cacheProvider')
|
|
210
|
+
expect(readInfraStrategySnapshot({}, { cacheProvider: { id: 'acme/x', placement: 'shared' } }).cacheProvider)
|
|
211
|
+
.toEqual({ id: 'acme/x', placement: 'shared' })
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
describe('resolveEffectiveCacheProviderSnapshot', () => {
|
|
216
|
+
function registerProvider(placement: CacheProviderPlacement) {
|
|
217
|
+
const definition = defineCacheProvider<Record<string, never>>({
|
|
218
|
+
id: 'acme/fake',
|
|
219
|
+
settings: { safeParse: () => ({ success: true, data: {} }) },
|
|
220
|
+
capability: () => ({ placement }),
|
|
221
|
+
create: () => { throw new Error('must not connect during the guard') },
|
|
222
|
+
})
|
|
223
|
+
setCacheProviderRegistrations([
|
|
224
|
+
defineCacheProviderRegistration({ id: 'acme/fake', load: async () => definition, settings: () => ({}) }),
|
|
225
|
+
])
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
beforeEach(() => {
|
|
229
|
+
resetCacheProviderSelectionForTests()
|
|
230
|
+
loadManifestMock.mockReset()
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
afterAll(() => {
|
|
234
|
+
resetCacheProviderSelectionForTests()
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('returns null without loading the manifest for stock deployments', async () => {
|
|
238
|
+
await expect(resolveEffectiveCacheProviderSnapshot('/app', { CACHE_STRATEGY: 'redis' })).resolves.toBeNull()
|
|
239
|
+
expect(loadManifestMock).not.toHaveBeenCalled()
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it.each([['shared'], ['local']] as const)('loads the manifest and reports the %s placement', async (placement) => {
|
|
243
|
+
loadManifestMock.mockImplementation(async () => {
|
|
244
|
+
registerProvider(placement)
|
|
245
|
+
return []
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
const snapshot = await resolveEffectiveCacheProviderSnapshot('/app', {
|
|
249
|
+
CACHE_PROVIDER: 'acme/fake',
|
|
250
|
+
CACHE_PROVIDER_NAMESPACE: 'guard-ns',
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
expect(loadManifestMock).toHaveBeenCalledWith('/app')
|
|
254
|
+
expect(snapshot).toEqual({ id: 'acme/fake', placement })
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('propagates a provider selection error so the start aborts', async () => {
|
|
258
|
+
loadManifestMock.mockImplementation(async () => {
|
|
259
|
+
setCacheProviderRegistrations([])
|
|
260
|
+
return []
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
await expect(
|
|
264
|
+
resolveEffectiveCacheProviderSnapshot('/app', { CACHE_PROVIDER: 'acme/fake', CACHE_PROVIDER_NAMESPACE: 'guard-ns' }),
|
|
265
|
+
).rejects.toMatchObject({ name: 'CacheProviderError', code: 'not_registered' })
|
|
266
|
+
})
|
|
267
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CacheProviderRegistration } from '@open-mercato/shared/lib/cache/providers'
|
|
2
|
+
|
|
3
|
+
/** Load app provider registrations for CLI commands that do not bootstrap the full app. */
|
|
4
|
+
export async function loadCacheProviderManifest(appDir: string): Promise<CacheProviderRegistration[]> {
|
|
5
|
+
const { loadCacheProviderManifestFromAppRoot } = await import('@open-mercato/shared/lib/bootstrap/dynamicLoader')
|
|
6
|
+
const format = typeof process.env.JEST_WORKER_ID === 'string' ? 'cjs' : 'esm'
|
|
7
|
+
return loadCacheProviderManifestFromAppRoot(appDir, { format })
|
|
8
|
+
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import type { GenerateWatchPlan } from './generate-watch-plan'
|
|
4
|
+
|
|
5
|
+
type GenerateWatchRequest = {
|
|
6
|
+
plan?: GenerateWatchPlan
|
|
7
|
+
logCascade: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function readGenerateWatchRequest(): GenerateWatchRequest | undefined {
|
|
11
|
+
if (process.env.OM_INTERNAL_GENERATE_WATCH_REQUEST !== '1') return undefined
|
|
12
|
+
delete process.env.OM_INTERNAL_GENERATE_WATCH_REQUEST
|
|
13
|
+
return JSON.parse(fs.readFileSync(0, 'utf8')) as GenerateWatchRequest
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* Evaluate application modules in a disposable process, never in the watcher.
|
|
@@ -10,21 +23,31 @@ export async function runGenerateChildProcess(options: {
|
|
|
10
23
|
cwd: string
|
|
11
24
|
env?: NodeJS.ProcessEnv
|
|
12
25
|
quiet?: boolean
|
|
26
|
+
watchRequest?: GenerateWatchRequest
|
|
13
27
|
}): Promise<void> {
|
|
14
28
|
const args = [options.mercatoBin, 'generate', 'all']
|
|
15
29
|
if (options.quiet) args.push('--quiet')
|
|
16
30
|
|
|
17
31
|
await new Promise<void>((resolve, reject) => {
|
|
32
|
+
let inputError: Error | undefined
|
|
18
33
|
const child = spawn(process.execPath, args, {
|
|
19
34
|
cwd: options.cwd,
|
|
20
|
-
env:
|
|
21
|
-
|
|
35
|
+
env: {
|
|
36
|
+
...(options.env ?? process.env),
|
|
37
|
+
OM_INTERNAL_GENERATE_WATCH_REQUEST: options.watchRequest ? '1' : undefined,
|
|
38
|
+
},
|
|
39
|
+
stdio: [options.watchRequest ? 'pipe' : 'ignore', 'inherit', 'inherit'],
|
|
22
40
|
})
|
|
23
41
|
child.once('error', reject)
|
|
42
|
+
if (options.watchRequest) {
|
|
43
|
+
child.stdin?.on('error', (error: Error) => { inputError = error })
|
|
44
|
+
child.stdin?.end(JSON.stringify(options.watchRequest))
|
|
45
|
+
}
|
|
24
46
|
// Wait for close, not just exit: generation and inherited stream cleanup
|
|
25
47
|
// must finish before another cycle or supervisor restart can proceed.
|
|
26
48
|
child.once('close', (code, signal) => {
|
|
27
|
-
if (
|
|
49
|
+
if (inputError) reject(inputError)
|
|
50
|
+
else if (code === 0) resolve()
|
|
28
51
|
else reject(new Error(
|
|
29
52
|
signal
|
|
30
53
|
? `Generator process terminated by ${signal}`
|
|
@@ -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
|