@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
|
@@ -3,144 +3,355 @@ import fs from 'node:fs'
|
|
|
3
3
|
import os from 'node:os'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import ts from 'typescript-js'
|
|
6
|
+
import { createResolver } from '../../resolver'
|
|
6
7
|
import type { PackageResolver } from '../../resolver'
|
|
7
|
-
import {
|
|
8
|
+
import { readChecksumRecord } from '../../utils'
|
|
9
|
+
import { generateWebResearchAdapters, getWebResearchAdapterWatchInputs } from '../web-research-adapters'
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function createMockResolver(): PackageResolver {
|
|
11
|
+
function createTestResolver(root: string): PackageResolver {
|
|
12
|
+
const appDir = path.join(root, 'apps', 'mercato')
|
|
13
|
+
const outputDir = path.join(appDir, '.mercato', 'generated')
|
|
14
|
+
fs.mkdirSync(outputDir, { recursive: true })
|
|
14
15
|
return {
|
|
16
|
+
isMonorepo: () => true,
|
|
17
|
+
getRootDir: () => root,
|
|
15
18
|
getAppDir: () => appDir,
|
|
16
19
|
getOutputDir: () => outputDir,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
adapterId: string,
|
|
24
|
-
source = `export const id = '${adapterId}'\n`,
|
|
25
|
-
): void {
|
|
26
|
-
fs.mkdirSync(packageDir, { recursive: true })
|
|
27
|
-
fs.writeFileSync(
|
|
28
|
-
path.join(packageDir, 'package.json'),
|
|
29
|
-
JSON.stringify({
|
|
30
|
-
name: packageName,
|
|
31
|
-
type: 'module',
|
|
32
|
-
exports: './index.js',
|
|
33
|
-
openMercato: { webResearchAdapter: { id: adapterId } },
|
|
20
|
+
getModulesConfigPath: () => path.join(appDir, 'src', 'modules.ts'),
|
|
21
|
+
discoverPackages: () => [],
|
|
22
|
+
loadEnabledModules: () => [],
|
|
23
|
+
getModulePaths: (entry) => ({
|
|
24
|
+
appBase: path.join(appDir, 'src', 'modules', entry.id),
|
|
25
|
+
pkgBase: path.join(root, 'packages', 'core', 'src', 'modules', entry.id),
|
|
34
26
|
}),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function writeInstalledAdapter(packageName: string, adapterId: string, source?: string): void {
|
|
44
|
-
writeAdapterPackage(path.join(tmpRoot, 'node_modules', ...packageName.split('/')), packageName, adapterId, source)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function generate(): Promise<string> {
|
|
48
|
-
await generateWebResearchAdapters({ resolver: createMockResolver(), quiet: true })
|
|
49
|
-
return fs.readFileSync(path.join(outputDir, 'web-research-adapters.generated.ts'), 'utf8')
|
|
27
|
+
getModuleImportBase: (entry) => ({
|
|
28
|
+
appBase: `@/modules/${entry.id}`,
|
|
29
|
+
pkgBase: `@open-mercato/core/modules/${entry.id}`,
|
|
30
|
+
}),
|
|
31
|
+
getPackageOutputDir: () => outputDir,
|
|
32
|
+
getPackageRoot: () => root,
|
|
33
|
+
}
|
|
50
34
|
}
|
|
51
35
|
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
].join('\n')
|
|
62
|
-
const result = spawnSync(process.execPath, ['--input-type=module', '-e', script], {
|
|
63
|
-
cwd: appDir,
|
|
64
|
-
encoding: 'utf8',
|
|
65
|
-
})
|
|
66
|
-
return { status: result.status, stdout: result.stdout.trim(), stderr: result.stderr }
|
|
36
|
+
function writeManifest(packageRoot: string, name: string, adapterId?: string): void {
|
|
37
|
+
fs.mkdirSync(packageRoot, { recursive: true })
|
|
38
|
+
fs.writeFileSync(path.join(packageRoot, 'package.json'), JSON.stringify({
|
|
39
|
+
name,
|
|
40
|
+
type: 'module',
|
|
41
|
+
exports: './index.js',
|
|
42
|
+
...(adapterId === undefined ? {} : { openMercato: { webResearchAdapter: { id: adapterId } } }),
|
|
43
|
+
}))
|
|
44
|
+
fs.writeFileSync(path.join(packageRoot, 'index.js'), `export const id = ${JSON.stringify(adapterId ?? '')}\n`)
|
|
67
45
|
}
|
|
68
46
|
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
tmpRoot = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'web-research-adapters-test-')))
|
|
71
|
-
appDir = path.join(tmpRoot, 'apps', 'mercato')
|
|
72
|
-
outputDir = path.join(appDir, '.mercato', 'generated')
|
|
73
|
-
fs.mkdirSync(outputDir, { recursive: true })
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
fs.rmSync(tmpRoot, { recursive: true, force: true })
|
|
78
|
-
})
|
|
79
|
-
|
|
80
47
|
describe('generateWebResearchAdapters', () => {
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
let root: string
|
|
49
|
+
let resolver: PackageResolver
|
|
50
|
+
let outFile: string
|
|
51
|
+
let checksumFile: string
|
|
83
52
|
|
|
84
|
-
|
|
85
|
-
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'web-research-adapters-test-')))
|
|
55
|
+
resolver = createTestResolver(root)
|
|
56
|
+
outFile = path.join(resolver.getOutputDir(), 'web-research-adapters.generated.ts')
|
|
57
|
+
checksumFile = path.join(resolver.getOutputDir(), 'web-research-adapters.checksum')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
jest.restoreAllMocks()
|
|
62
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
86
63
|
})
|
|
87
64
|
|
|
88
65
|
it('does not require @open-mercato/web-research to be installed in the app', async () => {
|
|
89
|
-
|
|
66
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
67
|
+
const content = fs.readFileSync(outFile, 'utf8')
|
|
90
68
|
|
|
91
69
|
expect(content).not.toContain("from '@open-mercato/web-research'")
|
|
92
70
|
expect(content).toContain('type AdapterRegistryEntry = {')
|
|
93
71
|
})
|
|
94
72
|
|
|
95
73
|
it('imports every discovered adapter with a literal specifier and no static import', async () => {
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
writeManifest(path.join(root, 'node_modules', '@acme', 'web-research-installed'), '@acme/web-research-installed', 'installed')
|
|
75
|
+
writeManifest(path.join(root, 'packages', 'web-research-workspace-only'), '@open-mercato/web-research-workspace-only', 'workspace-only')
|
|
98
76
|
|
|
99
|
-
|
|
77
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
78
|
+
const content = fs.readFileSync(outFile, 'utf8')
|
|
100
79
|
|
|
101
80
|
expect(content).toContain("import('@acme/web-research-installed')")
|
|
102
|
-
expect(content).toContain("import('@
|
|
81
|
+
expect(content).toContain("import('@open-mercato/web-research-workspace-only')")
|
|
103
82
|
expect(content).not.toMatch(/^import \* as /m)
|
|
104
83
|
})
|
|
105
84
|
|
|
106
|
-
it('
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
it('shares candidate manifests and shallow scan roots, including scope folders, with the watcher', async () => {
|
|
86
|
+
const workspaceRoot = path.join(root, 'packages')
|
|
87
|
+
const installedRoot = path.join(root, 'node_modules')
|
|
88
|
+
const appInstalledRoot = path.join(resolver.getAppDir(), 'node_modules')
|
|
89
|
+
const workspaceAdapter = path.join(workspaceRoot, 'adapter-only')
|
|
90
|
+
const scopedAdapter = path.join(installedRoot, '@third-party', 'adapter')
|
|
91
|
+
const missingManifestPackage = path.join(installedRoot, 'ordinary-package')
|
|
92
|
+
writeManifest(workspaceAdapter, 'workspace-adapter', 'workspace')
|
|
93
|
+
writeManifest(scopedAdapter, '@third-party/adapter', 'third-party')
|
|
94
|
+
fs.mkdirSync(missingManifestPackage, { recursive: true })
|
|
95
|
+
writeManifest(path.join(workspaceAdapter, 'nested'), 'nested-implementation', 'ignored')
|
|
96
|
+
writeManifest(path.join(installedRoot, '.cache'), 'cached-adapter', 'ignored')
|
|
97
|
+
writeManifest(path.join(installedRoot, '.bin'), 'bin-adapter', 'ignored')
|
|
98
|
+
|
|
99
|
+
const inputs = getWebResearchAdapterWatchInputs(resolver)
|
|
100
|
+
expect(inputs.manifestPaths.slice().sort()).toEqual([
|
|
101
|
+
path.join(workspaceAdapter, 'package.json'),
|
|
102
|
+
path.join(scopedAdapter, 'package.json'),
|
|
103
|
+
path.join(missingManifestPackage, 'package.json'),
|
|
104
|
+
].sort())
|
|
105
|
+
expect(inputs.directoryPaths).toEqual([
|
|
106
|
+
workspaceRoot, installedRoot, appInstalledRoot, path.join(installedRoot, '@third-party'),
|
|
107
|
+
])
|
|
108
|
+
expect(inputs.fullReasons).toEqual([])
|
|
109
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
110
|
+
expectRegistryEntries([['@third-party/adapter', 'third-party']])
|
|
109
111
|
|
|
110
|
-
const
|
|
112
|
+
const appAdapter = path.join(appInstalledRoot, '@another-vendor', 'adapter')
|
|
113
|
+
writeManifest(appAdapter, '@another-vendor/adapter', 'app')
|
|
114
|
+
const nextInputs = getWebResearchAdapterWatchInputs(resolver)
|
|
115
|
+
expect(nextInputs.manifestPaths).toContain(path.join(appAdapter, 'package.json'))
|
|
116
|
+
expect(nextInputs.directoryPaths).toEqual([
|
|
117
|
+
workspaceRoot, installedRoot, appInstalledRoot,
|
|
118
|
+
path.join(installedRoot, '@third-party'), path.join(appInstalledRoot, '@another-vendor'),
|
|
119
|
+
])
|
|
120
|
+
expect(nextInputs.fullReasons).toEqual([])
|
|
121
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
122
|
+
expectRegistryEntries([
|
|
123
|
+
['@another-vendor/adapter', 'app'],
|
|
124
|
+
['@third-party/adapter', 'third-party'],
|
|
125
|
+
])
|
|
126
|
+
})
|
|
111
127
|
|
|
128
|
+
it('keeps standalone discovery roots inside the standalone project', () => {
|
|
129
|
+
const project = path.join(root, 'standalone')
|
|
130
|
+
const installedAdapter = path.join(project, 'node_modules', '@example', 'adapter')
|
|
131
|
+
writeManifest(installedAdapter, '@example/adapter', 'adapter')
|
|
132
|
+
const standaloneResolver = createResolver(project)
|
|
133
|
+
|
|
134
|
+
const inputs = getWebResearchAdapterWatchInputs(standaloneResolver)
|
|
135
|
+
|
|
136
|
+
expect(inputs.directoryPaths).toEqual([
|
|
137
|
+
path.join(project, 'packages'),
|
|
138
|
+
path.join(project, 'node_modules'),
|
|
139
|
+
path.join(project, 'node_modules', '@example'),
|
|
140
|
+
])
|
|
141
|
+
expect(inputs.manifestPaths).toEqual([path.join(installedAdapter, 'package.json')])
|
|
142
|
+
expect(inputs.fullReasons).toEqual([])
|
|
143
|
+
expect(inputs.directoryPaths.every((directory) => {
|
|
144
|
+
const relative = path.relative(project, directory)
|
|
145
|
+
return relative === '' || (!path.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${path.sep}`))
|
|
146
|
+
})).toBe(true)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('reports scan failures deterministically and generation writes nothing', async () => {
|
|
150
|
+
const scanSpy = jest.spyOn(fs, 'readdirSync').mockImplementation(() => {
|
|
151
|
+
throw Object.assign(new Error('denied'), { code: 'EACCES' })
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const inputs = getWebResearchAdapterWatchInputs(resolver)
|
|
155
|
+
const expectedReasons = [
|
|
156
|
+
path.join(root, 'node_modules'),
|
|
157
|
+
path.join(root, 'packages'),
|
|
158
|
+
path.join(resolver.getAppDir(), 'node_modules'),
|
|
159
|
+
]
|
|
160
|
+
.map((directory) => `Cannot scan web-research adapter packages: ${directory}`)
|
|
161
|
+
.sort((left, right) => left.localeCompare(right))
|
|
162
|
+
expect(inputs.fullReasons).toEqual(expectedReasons)
|
|
163
|
+
await expect(generateWebResearchAdapters({ resolver, quiet: true }))
|
|
164
|
+
.rejects.toThrow(expectedReasons.join('\n'))
|
|
165
|
+
scanSpy.mockRestore()
|
|
166
|
+
expect(fs.existsSync(outFile)).toBe(false)
|
|
167
|
+
expect(fs.existsSync(checksumFile)).toBe(false)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('treats non-missing manifest read failures as uncertain and writes nothing', async () => {
|
|
171
|
+
writeManifest(path.join(root, 'packages', 'adapter'), '@example/adapter', 'adapter')
|
|
172
|
+
const readSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => {
|
|
173
|
+
throw Object.assign(new Error('denied'), { code: 'EACCES' })
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
await expect(generateWebResearchAdapters({ resolver, quiet: true }))
|
|
177
|
+
.rejects.toThrow(`Cannot read web-research adapter manifest: ${path.join(root, 'packages', 'adapter', 'package.json')}`)
|
|
178
|
+
readSpy.mockRestore()
|
|
179
|
+
expect(fs.existsSync(outFile)).toBe(false)
|
|
180
|
+
expect(fs.existsSync(checksumFile)).toBe(false)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('skips invalid JSON deterministically without treating it as I/O uncertainty', async () => {
|
|
184
|
+
const invalidManifest = path.join(root, 'packages', 'invalid', 'package.json')
|
|
185
|
+
fs.mkdirSync(path.dirname(invalidManifest), { recursive: true })
|
|
186
|
+
fs.writeFileSync(invalidManifest, '{"name":"invalid",')
|
|
187
|
+
|
|
188
|
+
expect(getWebResearchAdapterWatchInputs(resolver).fullReasons).toEqual([])
|
|
189
|
+
const first = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
190
|
+
const content = fs.readFileSync(outFile, 'utf8')
|
|
191
|
+
const second = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
192
|
+
|
|
193
|
+
expect(first.filesWritten).toEqual([outFile])
|
|
194
|
+
expectRegistryEntries([])
|
|
195
|
+
expect(second.filesWritten).toEqual([])
|
|
196
|
+
expect(second.filesUnchanged).toEqual([outFile])
|
|
197
|
+
expect(fs.readFileSync(outFile, 'utf8')).toBe(content)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('preserves output and checksum bytes and mtimes after unrelated implementation changes', async () => {
|
|
201
|
+
const packageRoot = path.join(root, 'packages', 'adapter')
|
|
202
|
+
writeManifest(packageRoot, '@example/adapter', 'adapter')
|
|
203
|
+
const implementationFile = path.join(packageRoot, 'index.ts')
|
|
204
|
+
fs.writeFileSync(implementationFile, 'export const adapter = 1\n')
|
|
205
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
206
|
+
const outputBefore = fs.readFileSync(outFile, 'utf8')
|
|
207
|
+
const checksumBefore = fs.readFileSync(checksumFile, 'utf8')
|
|
208
|
+
const pinnedTime = new Date(Date.now() - 60_000)
|
|
209
|
+
fs.utimesSync(outFile, pinnedTime, pinnedTime)
|
|
210
|
+
fs.utimesSync(checksumFile, pinnedTime, pinnedTime)
|
|
211
|
+
const outputMtimeBefore = fs.statSync(outFile).mtimeMs
|
|
212
|
+
const checksumMtimeBefore = fs.statSync(checksumFile).mtimeMs
|
|
213
|
+
|
|
214
|
+
fs.writeFileSync(implementationFile, 'export const adapter = 200\n')
|
|
215
|
+
fs.mkdirSync(path.join(packageRoot, 'dist', 'nested'), { recursive: true })
|
|
216
|
+
fs.writeFileSync(path.join(packageRoot, 'dist', 'nested', 'index.js'), 'export const adapter = 200\n')
|
|
217
|
+
const result = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
218
|
+
|
|
219
|
+
expect(result.filesWritten).toEqual([])
|
|
220
|
+
expect(result.filesUnchanged).toEqual([outFile])
|
|
221
|
+
expect(fs.readFileSync(outFile, 'utf8')).toBe(outputBefore)
|
|
222
|
+
expect(fs.readFileSync(checksumFile, 'utf8')).toBe(checksumBefore)
|
|
223
|
+
expect(fs.statSync(outFile).mtimeMs).toBe(outputMtimeBefore)
|
|
224
|
+
expect(fs.statSync(checksumFile).mtimeMs).toBe(checksumMtimeBefore)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it('discovers newly declared adapters and removes deleted or no-longer-valid declarations', async () => {
|
|
228
|
+
const workspacePackage = path.join(root, 'packages', 'z-adapter')
|
|
229
|
+
const installedPackage = path.join(root, 'node_modules', '@example', 'a-adapter')
|
|
230
|
+
writeManifest(workspacePackage, '@example/z-adapter', 'z')
|
|
231
|
+
writeManifest(installedPackage, '@example/a-adapter')
|
|
232
|
+
fs.symlinkSync(workspacePackage, path.join(root, 'node_modules', '@example', 'z-adapter'), 'dir')
|
|
233
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
234
|
+
const initialStructure = readChecksumRecord(checksumFile)?.structure
|
|
235
|
+
const initialOutput = fs.readFileSync(outFile, 'utf8')
|
|
236
|
+
expectRegistryEntries([['@example/z-adapter', 'z']])
|
|
237
|
+
|
|
238
|
+
writeManifest(installedPackage, '@example/a-adapter', 'a')
|
|
239
|
+
const added = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
240
|
+
const addedStructure = readChecksumRecord(checksumFile)?.structure
|
|
241
|
+
expect(added.filesWritten).toEqual([outFile])
|
|
242
|
+
expect(addedStructure).not.toBe(initialStructure)
|
|
243
|
+
expectRegistryEntries([
|
|
244
|
+
['@example/a-adapter', 'a'],
|
|
245
|
+
['@example/z-adapter', 'z'],
|
|
246
|
+
])
|
|
247
|
+
|
|
248
|
+
fs.rmSync(path.join(installedPackage, 'package.json'))
|
|
249
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
250
|
+
expect(fs.readFileSync(outFile, 'utf8')).toBe(initialOutput)
|
|
251
|
+
expect(readChecksumRecord(checksumFile)?.structure).toBe(initialStructure)
|
|
252
|
+
|
|
253
|
+
writeManifest(workspacePackage, '@example/z-adapter', '')
|
|
254
|
+
const removed = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
255
|
+
expect(removed.filesWritten).toEqual([outFile])
|
|
256
|
+
expectRegistryEntries([])
|
|
257
|
+
expect(readChecksumRecord(checksumFile)?.structure).not.toBe(initialStructure)
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it('tracks selected manifest identity and package precedence without rewriting identical imports', async () => {
|
|
261
|
+
const workspacePackage = path.join(root, 'packages', 'adapter')
|
|
262
|
+
const installedPackage = path.join(resolver.getAppDir(), 'node_modules', '@example', 'adapter')
|
|
263
|
+
writeManifest(workspacePackage, '@example/adapter', 'workspace')
|
|
264
|
+
writeManifest(installedPackage, '@example/adapter', 'installed')
|
|
265
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
266
|
+
const outputBefore = fs.readFileSync(outFile, 'utf8')
|
|
267
|
+
const initialStructure = readChecksumRecord(checksumFile)?.structure
|
|
268
|
+
const pinnedTime = new Date(Date.now() - 60_000)
|
|
269
|
+
fs.utimesSync(outFile, pinnedTime, pinnedTime)
|
|
270
|
+
const outputMtimeBefore = fs.statSync(outFile).mtimeMs
|
|
271
|
+
|
|
272
|
+
writeManifest(installedPackage, '@example/adapter', 'shadowed')
|
|
273
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
274
|
+
expect(readChecksumRecord(checksumFile)?.structure).toBe(initialStructure)
|
|
275
|
+
|
|
276
|
+
writeManifest(workspacePackage, '@example/adapter', 'workspace-updated')
|
|
277
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
278
|
+
const changedStructure = readChecksumRecord(checksumFile)?.structure
|
|
279
|
+
expect(changedStructure).not.toBe(initialStructure)
|
|
280
|
+
|
|
281
|
+
fs.rmSync(workspacePackage, { recursive: true })
|
|
282
|
+
const result = await generateWebResearchAdapters({ resolver, quiet: true })
|
|
283
|
+
expect(readChecksumRecord(checksumFile)?.structure).not.toBe(changedStructure)
|
|
284
|
+
expect(result.filesWritten).toEqual([])
|
|
285
|
+
expect(result.filesUnchanged).toEqual([outFile])
|
|
286
|
+
expect(fs.readFileSync(outFile, 'utf8')).toBe(outputBefore)
|
|
287
|
+
expect(fs.statSync(outFile).mtimeMs).toBe(outputMtimeBefore)
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
function runGeneratedRegistry(): { status: number | null; stdout: string; stderr: string } {
|
|
291
|
+
// Execute the generated registry's module-loading boundaries in a fresh Node process.
|
|
292
|
+
const compiled = ts.transpileModule(fs.readFileSync(outFile, 'utf8'), {
|
|
293
|
+
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
|
|
294
|
+
}).outputText
|
|
295
|
+
const registryFile = path.join(resolver.getOutputDir(), 'web-research-adapters.generated.mjs')
|
|
296
|
+
fs.writeFileSync(registryFile, compiled)
|
|
297
|
+
const script = [
|
|
298
|
+
`const { webResearchAdapterEntries } = await import(${JSON.stringify(registryFile)})`,
|
|
299
|
+
'console.log(JSON.stringify(webResearchAdapterEntries.map((entry) => [entry.packageName, entry.module.id])))',
|
|
300
|
+
].join('\n')
|
|
301
|
+
const result = spawnSync(process.execPath, ['--input-type=module', '-e', script], {
|
|
302
|
+
cwd: resolver.getAppDir(),
|
|
303
|
+
encoding: 'utf8',
|
|
304
|
+
})
|
|
305
|
+
return { status: result.status, stdout: result.stdout.trim(), stderr: result.stderr }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function expectRegistryEntries(entries: string[][]): void {
|
|
309
|
+
const result = runGeneratedRegistry()
|
|
112
310
|
expect(result.stderr).toBe('')
|
|
113
311
|
expect(result.status).toBe(0)
|
|
114
|
-
expect(JSON.parse(result.stdout)).toEqual(
|
|
312
|
+
expect(JSON.parse(result.stdout)).toEqual(entries)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
it('emits an empty registry when no adapter package is discovered', async () => {
|
|
316
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
317
|
+
|
|
318
|
+
expectRegistryEntries([])
|
|
115
319
|
})
|
|
116
320
|
|
|
117
321
|
it('still surfaces an installed adapter that fails while loading', async () => {
|
|
118
|
-
|
|
322
|
+
const packageRoot = path.join(root, 'node_modules', '@acme', 'web-research-broken')
|
|
323
|
+
writeManifest(packageRoot, '@acme/web-research-broken', 'broken')
|
|
324
|
+
fs.writeFileSync(path.join(packageRoot, 'index.js'), "throw new Error('adapter exploded')\n")
|
|
325
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
119
326
|
|
|
120
|
-
const result = runGeneratedRegistry(
|
|
327
|
+
const result = runGeneratedRegistry()
|
|
121
328
|
|
|
122
329
|
expect(result.status).not.toBe(0)
|
|
123
330
|
expect(result.stderr).toContain('adapter exploded')
|
|
124
331
|
})
|
|
125
332
|
|
|
126
333
|
it('still surfaces an installed adapter whose own dependency is missing', async () => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
334
|
+
const packageRoot = path.join(root, 'node_modules', '@acme', 'web-research-needs-dep')
|
|
335
|
+
writeManifest(packageRoot, '@acme/web-research-needs-dep', 'needs-dep')
|
|
336
|
+
fs.writeFileSync(
|
|
337
|
+
path.join(packageRoot, 'index.js'),
|
|
130
338
|
"import '@acme/missing-adapter-dependency'\nexport const id = 'needs-dep'\n",
|
|
131
339
|
)
|
|
340
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
132
341
|
|
|
133
|
-
const result = runGeneratedRegistry(
|
|
342
|
+
const result = runGeneratedRegistry()
|
|
134
343
|
|
|
135
344
|
expect(result.status).not.toBe(0)
|
|
136
345
|
expect(result.stderr).toContain('@acme/missing-adapter-dependency')
|
|
137
346
|
})
|
|
138
347
|
|
|
139
348
|
it('still surfaces an installed adapter whose entry file is missing', async () => {
|
|
140
|
-
|
|
141
|
-
|
|
349
|
+
const packageRoot = path.join(root, 'node_modules', '@acme', 'web-research-unbuilt')
|
|
350
|
+
writeManifest(packageRoot, '@acme/web-research-unbuilt', 'unbuilt')
|
|
351
|
+
fs.rmSync(path.join(packageRoot, 'index.js'))
|
|
352
|
+
await generateWebResearchAdapters({ resolver, quiet: true })
|
|
142
353
|
|
|
143
|
-
const result = runGeneratedRegistry(
|
|
354
|
+
const result = runGeneratedRegistry()
|
|
144
355
|
|
|
145
356
|
expect(result.status).not.toBe(0)
|
|
146
357
|
expect(result.stderr).toMatch(/Cannot find module/)
|
|
@@ -449,6 +449,7 @@ export function objectFromEntries(value: GeneratedValue): WriterFunction {
|
|
|
449
449
|
export function arrowFunction(options: {
|
|
450
450
|
async?: boolean
|
|
451
451
|
parameters?: string[]
|
|
452
|
+
returnType?: string
|
|
452
453
|
body: WriterFunction
|
|
453
454
|
}): WriterFunction {
|
|
454
455
|
return (writer) => {
|
|
@@ -457,7 +458,11 @@ export function arrowFunction(options: {
|
|
|
457
458
|
}
|
|
458
459
|
writer.write('(')
|
|
459
460
|
writeCommaSeparated(writer, options.parameters ?? [], (currentWriter, parameter) => currentWriter.write(parameter))
|
|
460
|
-
writer.write(')
|
|
461
|
+
writer.write(')')
|
|
462
|
+
if (options.returnType) {
|
|
463
|
+
writer.write(`: ${options.returnType}`)
|
|
464
|
+
}
|
|
465
|
+
writer.write(' => ')
|
|
461
466
|
options.body(writer)
|
|
462
467
|
}
|
|
463
468
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import type { PackageResolver } from '../resolver'
|
|
4
|
+
import { calculateStructureChecksum, createGeneratorResult, type GeneratorResult, writeGeneratedFile } from '../utils'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* App cache-provider manifest generator.
|
|
8
|
+
*
|
|
9
|
+
* An app opts into third-party cache providers with `<app root>/src/providers/cache.ts`
|
|
10
|
+
* (or `src/providers/cache.js`). The file must
|
|
11
|
+
* export a named array:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import type { CacheProviderRegistration } from '@open-mercato/cache/provider'
|
|
15
|
+
*
|
|
16
|
+
* export const cacheProviders: CacheProviderRegistration[] = [
|
|
17
|
+
* { id: 'acme/example', load: () => import('@acme/cache-example').then((mod) => mod.default), settings: () => ({}) },
|
|
18
|
+
* ]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The generator only checks that the file exists — it never evaluates it — and
|
|
22
|
+
* writes `cache-providers.generated.ts`, which re-exports `cacheProviders` through a
|
|
23
|
+
* literal relative import (so bundlers and Next build tracing follow it) or, when
|
|
24
|
+
* the app has no manifest, exports an empty list.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export const CACHE_PROVIDERS_GENERATED_FILE = 'cache-providers.generated.ts'
|
|
28
|
+
export const CACHE_PROVIDERS_CHECKSUM_FILE = 'cache-providers.generated.checksum'
|
|
29
|
+
const CACHE_MANIFEST_BASENAME = 'src/providers/cache'
|
|
30
|
+
|
|
31
|
+
const SUPPORTED_MANIFEST_EXTENSIONS = ['.ts', '.js'] as const
|
|
32
|
+
const UNSUPPORTED_MANIFEST_EXTENSIONS = ['.tsx', '.mts', '.cts', '.mjs', '.cjs'] as const
|
|
33
|
+
|
|
34
|
+
export interface CacheProvidersOptions {
|
|
35
|
+
resolver: PackageResolver
|
|
36
|
+
quiet?: boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function manifestPaths(appDir: string, extensions: readonly string[]): string[] {
|
|
40
|
+
return extensions.map((extension) => path.join(appDir, `${CACHE_MANIFEST_BASENAME}${extension}`))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getCacheProviderManifestPaths(appDir: string): string[] {
|
|
44
|
+
return manifestPaths(appDir, [...SUPPORTED_MANIFEST_EXTENSIONS, ...UNSUPPORTED_MANIFEST_EXTENSIONS])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function manifestCandidates(appDir: string, extensions: readonly string[]): string[] {
|
|
48
|
+
return manifestPaths(appDir, extensions)
|
|
49
|
+
.filter((candidate) => fs.existsSync(candidate) && fs.statSync(candidate).isFile())
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function findCacheProviderManifest(appDir: string): string | null {
|
|
53
|
+
const unsupported = manifestCandidates(appDir, UNSUPPORTED_MANIFEST_EXTENSIONS)
|
|
54
|
+
if (unsupported.length > 0) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`[internal] Unsupported cache provider manifest ${unsupported.map((file) => path.relative(appDir, file)).join(', ')}: ` +
|
|
57
|
+
`rename it to ${CACHE_MANIFEST_BASENAME}.ts (or ${CACHE_MANIFEST_BASENAME}.js).`,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
const supported = manifestCandidates(appDir, SUPPORTED_MANIFEST_EXTENSIONS)
|
|
61
|
+
if (supported.length > 1) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`[internal] Multiple cache provider manifests found (${supported.map((file) => path.relative(appDir, file)).join(', ')}): keep exactly one.`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
return supported[0] ?? null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function toImportSpecifier(fromDir: string, manifestFile: string): string {
|
|
70
|
+
const withoutExtension = manifestFile.slice(0, -path.extname(manifestFile).length)
|
|
71
|
+
const relative = path.relative(fromDir, withoutExtension).split(path.sep).join('/')
|
|
72
|
+
return relative.startsWith('.') ? relative : `./${relative}`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function renderCacheProvidersRegistry(outputDir: string, manifestFile: string | null): string {
|
|
76
|
+
const header = `// AUTO-GENERATED — do not edit by hand.
|
|
77
|
+
// Source: <app root>/${CACHE_MANIFEST_BASENAME}.ts (optional)
|
|
78
|
+
// Regenerate with: yarn generate
|
|
79
|
+
import type { CacheProviderRegistration } from '@open-mercato/cache/provider'
|
|
80
|
+
`
|
|
81
|
+
if (!manifestFile) {
|
|
82
|
+
return `${header}
|
|
83
|
+
export const cacheProviders: CacheProviderRegistration[] = []
|
|
84
|
+
`
|
|
85
|
+
}
|
|
86
|
+
return `${header}import { cacheProviders as appCacheProviders } from '${toImportSpecifier(outputDir, manifestFile)}'
|
|
87
|
+
|
|
88
|
+
export const cacheProviders: CacheProviderRegistration[] = appCacheProviders
|
|
89
|
+
`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function generateCacheProviders(options: CacheProvidersOptions): Promise<GeneratorResult> {
|
|
93
|
+
const { resolver, quiet } = options
|
|
94
|
+
const result = createGeneratorResult()
|
|
95
|
+
const outputDir = resolver.getOutputDir()
|
|
96
|
+
const appDir = resolver.getAppDir()
|
|
97
|
+
const manifestFile = findCacheProviderManifest(appDir)
|
|
98
|
+
|
|
99
|
+
writeGeneratedFile({
|
|
100
|
+
outFile: path.join(outputDir, CACHE_PROVIDERS_GENERATED_FILE),
|
|
101
|
+
checksumFile: path.join(outputDir, CACHE_PROVIDERS_CHECKSUM_FILE),
|
|
102
|
+
content: renderCacheProvidersRegistry(outputDir, manifestFile),
|
|
103
|
+
structureChecksum: calculateStructureChecksum(
|
|
104
|
+
manifestPaths(appDir, SUPPORTED_MANIFEST_EXTENSIONS),
|
|
105
|
+
),
|
|
106
|
+
result,
|
|
107
|
+
quiet,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return result
|
|
111
|
+
}
|
|
@@ -32,6 +32,8 @@ export interface ModuleScanContext {
|
|
|
32
32
|
export interface GeneratorExtension {
|
|
33
33
|
id: string
|
|
34
34
|
outputFiles: string[]
|
|
35
|
+
/** Defaults to true; false allows discovery to be skipped when this output is unselected. */
|
|
36
|
+
usesSharedImportIds?: boolean
|
|
35
37
|
scanModule(ctx: ModuleScanContext): void
|
|
36
38
|
generateOutput(): Map<string, string>
|
|
37
39
|
getModuleDeclContribution?(moduleId: string): string | null
|
|
@@ -1480,6 +1480,7 @@ export function createAgentFilesExtension(resolver?: AgentFilesResolver): Genera
|
|
|
1480
1480
|
return {
|
|
1481
1481
|
id: 'registry.agent-files',
|
|
1482
1482
|
outputFiles: [],
|
|
1483
|
+
usesSharedImportIds: false,
|
|
1483
1484
|
scanModule(ctx: ModuleScanContext) {
|
|
1484
1485
|
if (ctx.moduleId === ORCHESTRATOR_MODULE_ID) sawOrchestratorModule = true
|
|
1485
1486
|
if (!repoRoot) {
|