@open-mercato/cli 0.10.1-develop.7983.1.fd91207efe → 0.10.1-develop.7994.1.c9f31972aa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/agentic/guides/module-facts.json +162 -162
- package/dist/agentic/guides/module-facts.v2.json +162 -162
- package/dist/agentic/guides/module-tool.md +21 -0
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/agentic/shared/ai/harness/cases.json +23 -9
- package/dist/agentic/shared/ai/harness/source-link-inventory.json +90 -4
- package/dist/lib/__integration__/TC-INT-007.spec.js +207 -19
- package/dist/lib/__integration__/TC-INT-007.spec.js.map +2 -2
- package/dist/lib/__integration__/TC-INT-009.spec.js +267 -0
- package/dist/lib/__integration__/TC-INT-009.spec.js.map +7 -0
- package/dist/lib/eject.js +25 -9
- package/dist/lib/eject.js.map +2 -2
- package/dist/lib/generators/entity-ids.js +2 -0
- package/dist/lib/generators/entity-ids.js.map +2 -2
- package/dist/lib/generators/module-di.js +2 -0
- package/dist/lib/generators/module-di.js.map +2 -2
- package/dist/lib/generators/module-entities.js +2 -0
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-package-sources.js +6 -4
- package/dist/lib/generators/module-package-sources.js.map +2 -2
- package/dist/lib/generators/module-registry.js +32 -86
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/generators/openapi.js +2 -0
- package/dist/lib/generators/openapi.js.map +2 -2
- package/dist/lib/generators/source-exports.js +73 -0
- package/dist/lib/generators/source-exports.js.map +7 -0
- package/dist/lib/init-summary.js +44 -0
- package/dist/lib/init-summary.js.map +7 -0
- package/dist/lib/module-github.js +98 -0
- package/dist/lib/module-github.js.map +7 -0
- package/dist/lib/module-identity.js +131 -0
- package/dist/lib/module-identity.js.map +7 -0
- package/dist/lib/module-inspection.js +124 -0
- package/dist/lib/module-inspection.js.map +7 -0
- package/dist/lib/module-install.js +150 -21
- package/dist/lib/module-install.js.map +3 -3
- package/dist/lib/module-package.js +205 -15
- package/dist/lib/module-package.js.map +2 -2
- package/dist/lib/modules-config.js +69 -30
- package/dist/lib/modules-config.js.map +2 -2
- package/dist/lib/resolver.js +33 -34
- package/dist/lib/resolver.js.map +2 -2
- package/dist/mercato.js +14 -23
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +14 -4
- package/src/lib/__fixtures__/official-module-package/dist/modules/test_package/widgets/injection/test/widget.js +1 -0
- package/src/lib/__integration__/TC-INT-007.spec.ts +219 -19
- package/src/lib/__integration__/TC-INT-009.spec.ts +279 -0
- package/src/lib/__tests__/eject.test.ts +98 -4
- package/src/lib/__tests__/init-summary.test.ts +50 -0
- package/src/lib/__tests__/module-github.test.ts +108 -0
- package/src/lib/__tests__/module-identity.test.ts +144 -0
- package/src/lib/__tests__/module-inspection.test.ts +195 -0
- package/src/lib/__tests__/module-install.test.ts +399 -10
- package/src/lib/__tests__/module-package.test.ts +154 -0
- package/src/lib/__tests__/modules-config.test.ts +55 -0
- package/src/lib/__tests__/resolver.packages.test.ts +29 -0
- package/src/lib/eject.ts +28 -10
- package/src/lib/generators/__tests__/module-id-collisions.test.ts +146 -0
- package/src/lib/generators/__tests__/module-package-sources.test.ts +19 -2
- package/src/lib/generators/__tests__/module-requirements.test.ts +56 -0
- package/src/lib/generators/entity-ids.ts +2 -0
- package/src/lib/generators/module-di.ts +2 -0
- package/src/lib/generators/module-entities.ts +2 -0
- package/src/lib/generators/module-package-sources.ts +7 -5
- package/src/lib/generators/module-registry.ts +33 -115
- package/src/lib/generators/openapi.ts +3 -0
- package/src/lib/generators/source-exports.ts +93 -0
- package/src/lib/init-summary.ts +54 -0
- package/src/lib/module-github.ts +109 -0
- package/src/lib/module-identity.ts +145 -0
- package/src/lib/module-inspection.ts +133 -0
- package/src/lib/module-install.ts +170 -22
- package/src/lib/module-package.ts +243 -16
- package/src/lib/modules-config.ts +80 -32
- package/src/lib/resolver.ts +35 -39
- package/src/mercato.ts +14 -24
- package/src/types/cross-spawn.d.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/module-install.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport spawn from 'cross-spawn'\nimport { copyDirRecursive, rewriteCrossModuleImports } from './eject'\nimport {\n parsePackageNameFromSpec,\n resolveInstalledOfficialModulePackage,\n validateEjectBoundaries,\n type ValidatedOfficialModulePackage,\n} from './module-package'\nimport { assertModuleNotGatedOff, ensureModuleRegistration } from './modules-config'\nimport type { PackageResolver } from './resolver'\nimport { resolveSpawnCommand } from './spawn'\n\nexport type ModuleCommandResult = {\n moduleId: string\n packageName: string\n from: string\n registrationChanged: boolean\n}\n\ntype InstallTarget = {\n cwd: string\n args: string[]\n}\n\nconst OFFICIAL_PACKAGE_SCOPE = '@open-mercato/'\nconst SAFE_PACKAGE_SPEC_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*(?:@.+)?$/i\nconst SAFE_PACKAGE_TAG_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/\nconst SAFE_PACKAGE_FILE_LOCATOR_PATTERN = /^file:[A-Za-z0-9_./: \\\\-]+$/\n\nfunction resolveYarnBinary(): string {\n return process.platform === 'win32' ? 'yarn.cmd' : 'yarn'\n}\n\nfunction readAppPackageName(appDir: string): string {\n const packageJsonPath = path.join(appDir, 'package.json')\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`App package.json not found at ${packageJsonPath}.`)\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string }\n if (!packageJson.name) {\n throw new Error(`App package.json at ${packageJsonPath} is missing the \"name\" field.`)\n }\n\n return packageJson.name\n}\n\nfunction resolveInstallTarget(resolver: PackageResolver): InstallTarget {\n if (!resolver.isMonorepo()) {\n return {\n cwd: resolver.getAppDir(),\n args: ['add'],\n }\n }\n\n return {\n cwd: resolver.getRootDir(),\n args: ['workspace', readAppPackageName(resolver.getAppDir()), 'add'],\n }\n}\n\nfunction runCommand(\n command: string,\n args: string[],\n cwd: string,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const resolvedSpawn = resolveSpawnCommand(command, args)\n const child = spawn(resolvedSpawn.command, resolvedSpawn.args, {\n cwd,\n env: process.env,\n stdio: 'inherit',\n ...resolvedSpawn.spawnOptions,\n })\n\n child.on('error', reject)\n child.on('exit', (code) => {\n if (code === 0) {\n resolve()\n return\n }\n\n reject(new Error(`Command failed: ${command} ${args.join(' ')} (exit ${code ?? 'unknown'}).`))\n })\n })\n}\n\nfunction readFileIfExists(filePath: string): string | null {\n return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null\n}\n\nfunction isDeclaredAppDependency(appDir: string, packageName: string): boolean {\n const packageJsonContent = readFileIfExists(path.join(appDir, 'package.json'))\n if (!packageJsonContent) {\n return false\n }\n\n let packageJson: Record<string, unknown>\n try {\n packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`App package.json at ${path.join(appDir, 'package.json')} is not valid JSON. ${message}`)\n }\n\n return ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'].some((field) => {\n const dependencies = packageJson[field]\n return typeof dependencies === 'object' && dependencies !== null && packageName in dependencies\n })\n}\n\nfunction isGatedOffError(error: unknown): boolean {\n return error instanceof Error && (error as { code?: unknown }).code === 'MODULE_GATED_OFF'\n}\n\nfunction withLeftoverPackageHint(error: unknown, resolver: PackageResolver, packageName: string): Error {\n const message = error instanceof Error ? error.message : String(error)\n const removeArgs = [...resolveInstallTarget(resolver).args.slice(0, -1), 'remove', packageName]\n return new Error(\n `${message} The package \"${packageName}\" stayed in package.json. To remove it, run: yarn ${removeArgs.join(' ')}`,\n )\n}\n\nasync function installPackageSpec(\n resolver: PackageResolver,\n packageSpec: string,\n): Promise<void> {\n const target = resolveInstallTarget(resolver)\n await runCommand(resolveYarnBinary(), [...target.args, packageSpec], target.cwd)\n}\n\nexport async function runModuleGenerators(\n resolver: PackageResolver,\n quiet = true,\n): Promise<void> {\n const {\n generateEntityIds,\n generateModuleDi,\n generateModuleEntities,\n generateModulePackageSources,\n generateModuleRegistries,\n generateOpenApi,\n } = await import('./generators')\n\n await generateEntityIds({ resolver, quiet })\n await generateModuleRegistries({ resolver, quiet })\n await generateModuleEntities({ resolver, quiet })\n await generateModuleDi({ resolver, quiet })\n await generateModulePackageSources({ resolver, quiet })\n await generateOpenApi({ resolver, quiet })\n}\n\nasync function runGeneratorsWithRegistrationNotice(\n resolver: PackageResolver,\n moduleId: string,\n): Promise<void> {\n try {\n await runModuleGenerators(resolver)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(\n `Module \"${moduleId}\" is enabled, but generated artifacts are stale because generation failed. Rerun \"yarn mercato generate\" after fixing the underlying error. ${message}`,\n )\n }\n}\n\nfunction isOfficialPackage(packageName: string): boolean {\n return packageName.startsWith(OFFICIAL_PACKAGE_SCOPE)\n}\n\nfunction assertPackageName(packageName: string | null): asserts packageName is string {\n if (!packageName) {\n throw new Error('Could not determine a package name from the provided spec.')\n }\n}\n\nfunction assertThirdPartyAllowed(packageName: string, allowThirdParty: boolean): void {\n if (isOfficialPackage(packageName) || allowThirdParty) {\n return\n }\n\n throw new Error(\n `Package \"${packageName}\" is outside the ${OFFICIAL_PACKAGE_SCOPE}* scope. Re-run with --allow-third-party to install third-party module packages.`,\n )\n}\n\nfunction assertSupportedPackageSpec(packageSpec: string, allowThirdParty: boolean): string {\n const trimmed = packageSpec.trim()\n\n if (!SAFE_PACKAGE_SPEC_PATTERN.test(trimmed)) {\n throw new Error('Unsupported package spec. Provide a valid npm package name with an optional tag/version or file: locator.')\n }\n\n const packageName = parsePackageNameFromSpec(trimmed)\n assertPackageName(packageName)\n assertThirdPartyAllowed(packageName, allowThirdParty)\n\n if (trimmed === packageName) {\n return trimmed\n }\n\n const suffix = trimmed.slice(packageName.length + 1)\n if (SAFE_PACKAGE_TAG_PATTERN.test(suffix) || SAFE_PACKAGE_FILE_LOCATOR_PATTERN.test(suffix)) {\n return trimmed\n }\n\n throw new Error('Unsupported package spec suffix. Use a tag/version token or a file: locator.')\n}\n\nfunction validateBeforeRegistration(\n modulePackage: ValidatedOfficialModulePackage,\n resolver: PackageResolver,\n eject: boolean,\n): string {\n const appModuleDir = path.join(resolver.getAppDir(), 'src', 'modules', modulePackage.metadata.moduleId)\n\n if (eject && fs.existsSync(appModuleDir)) {\n throw new Error(`Destination directory already exists: ${appModuleDir}. Remove it first or rerun without --eject.`)\n }\n\n return appModuleDir\n}\n\nfunction prepareRegistrationSource(\n modulePackage: ValidatedOfficialModulePackage,\n resolver: PackageResolver,\n packageName: string,\n eject: boolean,\n): string {\n const appModuleDir = validateBeforeRegistration(modulePackage, resolver, eject)\n\n if (!eject) {\n return packageName\n }\n\n if (!modulePackage.metadata.ejectable) {\n throw new Error(`Package \"${packageName}\" is not ejectable. --eject requires open-mercato.ejectable === true.`)\n }\n\n validateEjectBoundaries(modulePackage)\n copyDirRecursive(modulePackage.sourceModuleDir, appModuleDir)\n rewriteCrossModuleImports(\n modulePackage.sourceModuleDir,\n appModuleDir,\n modulePackage.metadata.moduleId,\n packageName,\n )\n\n return '@app'\n}\n\nasync function registerResolvedOfficialModule(\n resolver: PackageResolver,\n modulePackage: ValidatedOfficialModulePackage,\n packageName: string,\n eject: boolean,\n): Promise<ModuleCommandResult> {\n assertModuleNotGatedOff(resolver.getModulesConfigPath(), modulePackage.metadata.moduleId)\n const from = prepareRegistrationSource(modulePackage, resolver, packageName, eject)\n\n const registration = ensureModuleRegistration(\n resolver.getModulesConfigPath(),\n {\n id: modulePackage.metadata.moduleId,\n from,\n },\n )\n\n if (registration.changed) {\n await runGeneratorsWithRegistrationNotice(resolver, modulePackage.metadata.moduleId)\n }\n\n return {\n moduleId: modulePackage.metadata.moduleId,\n packageName,\n from,\n registrationChanged: registration.changed,\n }\n}\n\nexport async function addOfficialModule(\n resolver: PackageResolver,\n packageSpec: string,\n eject: boolean,\n moduleId?: string,\n allowThirdParty = false,\n): Promise<ModuleCommandResult> {\n const safePackageSpec = assertSupportedPackageSpec(packageSpec, allowThirdParty)\n const packageName = parsePackageNameFromSpec(safePackageSpec)\n assertPackageName(packageName)\n\n const wasDeclaredBefore = isDeclaredAppDependency(resolver.getAppDir(), packageName)\n const modulesConfigBefore = readFileIfExists(resolver.getModulesConfigPath())\n\n await installPackageSpec(resolver, safePackageSpec)\n\n try {\n const modulePackage = resolveInstalledOfficialModulePackage(resolver, packageName, moduleId)\n return await registerResolvedOfficialModule(resolver, modulePackage, packageName, eject)\n } catch (error) {\n const moduleWasRegistered = readFileIfExists(resolver.getModulesConfigPath()) !== modulesConfigBefore\n if (wasDeclaredBefore || moduleWasRegistered || isGatedOffError(error)) {\n throw error\n }\n throw withLeftoverPackageHint(error, resolver, packageName)\n }\n}\n\nexport async function enableOfficialModule(\n resolver: PackageResolver,\n packageName: string,\n moduleId?: string,\n eject = false,\n allowThirdParty = false,\n): Promise<ModuleCommandResult> {\n assertThirdPartyAllowed(packageName, allowThirdParty)\n\n const modulePackage = resolveInstalledOfficialModulePackage(resolver, packageName, moduleId)\n return registerResolvedOfficialModule(resolver, modulePackage, packageName, eject)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,WAAW;AAClB,SAAS,kBAAkB,iCAAiC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB,gCAAgC;AAElE,SAAS,2BAA2B;AAcpC,MAAM,yBAAyB;AAC/B,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;AACjC,MAAM,oCAAoC;AAE1C,SAAS,oBAA4B;AACnC,SAAO,QAAQ,aAAa,UAAU,aAAa;AACrD;AAEA,SAAS,mBAAmB,QAAwB;AAClD,QAAM,kBAAkB,KAAK,KAAK,QAAQ,cAAc;AACxD,MAAI,CAAC,GAAG,WAAW,eAAe,GAAG;AACnC,UAAM,IAAI,MAAM,iCAAiC,eAAe,GAAG;AAAA,EACrE;AAEA,QAAM,cAAc,KAAK,MAAM,GAAG,aAAa,iBAAiB,MAAM,CAAC;AACvE,MAAI,CAAC,YAAY,MAAM;AACrB,UAAM,IAAI,MAAM,uBAAuB,eAAe,+BAA+B;AAAA,EACvF;AAEA,SAAO,YAAY;AACrB;AAEA,SAAS,qBAAqB,UAA0C;AACtE,MAAI,CAAC,SAAS,WAAW,GAAG;AAC1B,WAAO;AAAA,MACL,KAAK,SAAS,UAAU;AAAA,MACxB,MAAM,CAAC,KAAK;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AAAA,IACL,KAAK,SAAS,WAAW;AAAA,IACzB,MAAM,CAAC,aAAa,mBAAmB,SAAS,UAAU,CAAC,GAAG,KAAK;AAAA,EACrE;AACF;AAEA,SAAS,WACP,SACA,MACA,KACe;AACf,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,gBAAgB,oBAAo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6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport spawn from 'cross-spawn'\nimport { copyDirRecursive, rewriteCrossModuleImports } from './eject'\nimport {\n parsePackageNameFromSpec,\n resolveInstalledOfficialModulePackage,\n validateEjectBoundaries,\n type ValidatedOfficialModulePackage,\n} from './module-package'\nimport { assertModuleNotGatedOff, prepareModuleRegistration, prepareModuleRegistrationSource } from './modules-config'\nimport type { PackageResolver } from './resolver'\nimport { resolveSpawnCommand } from './spawn'\nimport { parseModuleLocator, resolveModuleRequirement } from '@open-mercato/shared/modules/module-locators'\nimport { getEnabledModuleIdentities, getModuleLocators } from './module-identity'\nimport { resolveGithubModuleTarget } from './module-github'\nimport { inspectNpmModuleTarget, type InspectedModuleTarget } from './module-inspection'\n\nexport type ModuleCommandResult = {\n moduleId: string\n packageName: string\n from: string\n registrationChanged: boolean\n}\n\ntype InstallTarget = {\n cwd: string\n args: string[]\n}\n\nconst OFFICIAL_PACKAGE_SCOPE = '@open-mercato/'\nconst SAFE_PACKAGE_SPEC_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*(?:@.+)?$/i\nconst SAFE_PACKAGE_TAG_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/\nconst SAFE_PACKAGE_FILE_LOCATOR_PATTERN = /^file:[A-Za-z0-9_./: \\\\-]+$/\n\nfunction resolveYarnBinary(): string {\n return process.platform === 'win32' ? 'yarn.cmd' : 'yarn'\n}\n\nfunction readAppPackageName(appDir: string): string {\n const packageJsonPath = path.join(appDir, 'package.json')\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`App package.json not found at ${packageJsonPath}.`)\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string }\n if (!packageJson.name) {\n throw new Error(`App package.json at ${packageJsonPath} is missing the \"name\" field.`)\n }\n\n return packageJson.name\n}\n\nfunction resolveInstallTarget(resolver: PackageResolver): InstallTarget {\n if (!resolver.isMonorepo()) {\n return {\n cwd: resolver.getAppDir(),\n args: ['add'],\n }\n }\n\n return {\n cwd: resolver.getRootDir(),\n args: ['workspace', readAppPackageName(resolver.getAppDir()), 'add'],\n }\n}\n\nfunction runCommand(\n command: string,\n args: string[],\n cwd: string,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const resolvedSpawn = resolveSpawnCommand(command, args)\n const child = spawn(resolvedSpawn.command, resolvedSpawn.args, {\n cwd,\n env: process.env,\n stdio: 'inherit',\n ...resolvedSpawn.spawnOptions,\n })\n\n child.on('error', reject)\n child.on('exit', (code) => {\n if (code === 0) {\n resolve()\n return\n }\n\n reject(new Error(`Command failed: ${command} ${args.join(' ')} (exit ${code ?? 'unknown'}).`))\n })\n })\n}\n\nfunction readFileIfExists(filePath: string): string | null {\n return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null\n}\n\nfunction isDeclaredAppDependency(appDir: string, packageName: string, packageSpecifier?: string): boolean {\n const packageJsonContent = readFileIfExists(path.join(appDir, 'package.json'))\n if (!packageJsonContent) {\n return false\n }\n\n let packageJson: Record<string, unknown>\n try {\n packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`App package.json at ${path.join(appDir, 'package.json')} is not valid JSON. ${message}`)\n }\n\n const declarations = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'].flatMap((field) => {\n const dependencies = packageJson[field]\n return typeof dependencies === 'object' && dependencies !== null && packageName in dependencies\n ? [(dependencies as Record<string, unknown>)[packageName]]\n : []\n })\n return declarations.length > 0 && (packageSpecifier === undefined || declarations.every((declaration) => declaration === packageSpecifier))\n}\n\nfunction isGatedOffError(error: unknown): boolean {\n return error instanceof Error && (error as { code?: unknown }).code === 'MODULE_GATED_OFF'\n}\n\nfunction withLeftoverPackageHint(error: unknown, resolver: PackageResolver, packageName: string): Error {\n const message = error instanceof Error ? error.message : String(error)\n const removeArgs = [...resolveInstallTarget(resolver).args.slice(0, -1), 'remove', packageName]\n return new Error(\n `${message} The package \"${packageName}\" stayed in package.json. To remove it, run: yarn ${removeArgs.join(' ')}`,\n )\n}\n\nasync function installPackageSpec(\n resolver: PackageResolver,\n packageSpec: string,\n): Promise<void> {\n const target = resolveInstallTarget(resolver)\n await runCommand(resolveYarnBinary(), [...target.args, packageSpec], target.cwd)\n}\n\nexport async function runModuleGenerators(\n resolver: PackageResolver,\n quiet = true,\n): Promise<void> {\n const {\n generateEntityIds,\n generateModuleDi,\n generateModuleEntities,\n generateModulePackageSources,\n generateModuleRegistries,\n generateOpenApi,\n } = await import('./generators')\n\n await generateEntityIds({ resolver, quiet })\n await generateModuleRegistries({ resolver, quiet })\n await generateModuleEntities({ resolver, quiet })\n await generateModuleDi({ resolver, quiet })\n await generateModulePackageSources({ resolver, quiet })\n await generateOpenApi({ resolver, quiet })\n}\n\nasync function runGeneratorsWithRegistrationNotice(\n resolver: PackageResolver,\n moduleId: string,\n): Promise<void> {\n try {\n await runModuleGenerators(resolver)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(\n `Module \"${moduleId}\" is enabled, but generated artifacts are stale because generation failed. Rerun \"yarn mercato generate\" after fixing the underlying error. ${message}`,\n )\n }\n}\n\nfunction isOfficialPackage(packageName: string): boolean {\n return packageName.startsWith(OFFICIAL_PACKAGE_SCOPE)\n}\n\nfunction assertPackageName(packageName: string | null): asserts packageName is string {\n if (!packageName) {\n throw new Error('Could not determine a package name from the provided spec.')\n }\n}\n\nfunction assertThirdPartyAllowed(packageName: string, allowThirdParty: boolean): void {\n if (isOfficialPackage(packageName) || allowThirdParty) {\n return\n }\n\n throw new Error(\n `Package \"${packageName}\" is outside the ${OFFICIAL_PACKAGE_SCOPE}* scope. Re-run with --allow-third-party to install third-party module packages.`,\n )\n}\n\nfunction assertSupportedPackageSpec(packageSpec: string, allowThirdParty: boolean): string {\n const trimmed = packageSpec.trim().replace(/^npm:/, '')\n\n if (!SAFE_PACKAGE_SPEC_PATTERN.test(trimmed)) {\n throw new Error('Unsupported package spec. Provide a valid npm package name with an optional tag/version or file: locator.')\n }\n\n const packageName = parsePackageNameFromSpec(trimmed)\n assertPackageName(packageName)\n assertThirdPartyAllowed(packageName, allowThirdParty)\n\n if (trimmed === packageName) {\n return trimmed\n }\n\n const suffix = trimmed.slice(packageName.length + 1)\n if (SAFE_PACKAGE_TAG_PATTERN.test(suffix) || SAFE_PACKAGE_FILE_LOCATOR_PATTERN.test(suffix)) {\n return trimmed\n }\n\n throw new Error('Unsupported package spec suffix. Use a tag/version token or a file: locator.')\n}\n\nfunction validateBeforeRegistration(\n modulePackage: ValidatedOfficialModulePackage,\n resolver: PackageResolver,\n eject: boolean,\n): string {\n const appModuleDir = path.join(resolver.getAppDir(), 'src', 'modules', modulePackage.metadata.moduleId)\n\n if (eject && fs.existsSync(appModuleDir)) {\n throw new Error(`Destination directory already exists: ${appModuleDir}. Preserve local source and choose a different destination or resolve the conflict manually.`)\n }\n\n return appModuleDir\n}\n\nfunction assertRequiredModulesEnabled(\n modulePackage: ValidatedOfficialModulePackage,\n resolver: PackageResolver,\n): void {\n const enabledModules = getEnabledModuleIdentities(resolver)\n const missingModuleIds = Array.from(new Set(modulePackage.moduleInfo.requires ?? [])).filter(\n (requirement) => !resolveModuleRequirement(requirement, enabledModules),\n )\n if (missingModuleIds.length === 0) return\n\n throw new Error(\n [\n `Module \"${modulePackage.metadata.moduleId}\" requires module(s) that are not enabled: ${missingModuleIds.join(', ')}.`,\n 'Enable the missing module(s) in src/modules.ts first, then rerun this command.',\n ...missingModuleIds.filter((requirement) => parseModuleLocator(requirement)?.kind !== 'module').map(\n (requirement) => `Install ${requirement}: npx create-mercato-module install ${shellQuote(requirement)}`,\n ),\n ].join('\\n'),\n )\n}\n\nfunction shellQuote(value: string): string {\n return \"'\" + value.replace(/'/g, \"'\\\\''\") + \"'\"\n}\n\nfunction assertNoModuleCollision(\n resolver: PackageResolver,\n moduleId: string,\n packageName: string,\n locator?: string,\n): void {\n const registrations = resolver.loadEnabledModules().filter((entry) => entry.id === moduleId)\n if (registrations.length > 1) {\n throw new Error(`Module name collision: \"${moduleId}\" is registered multiple times from ${registrations.map((entry) => entry.locator ?? entry.from ?? '@open-mercato/core').join(', ')}. Resolve duplicate registrations before retrying.`)\n }\n const existing = registrations[0]\n if (existing && (existing.from ?? '@open-mercato/core') !== packageName) {\n throw new Error(`Module name collision: \"${moduleId}\" is already registered from \"${existing.locator ?? existing.from ?? '@open-mercato/core'}\"; requested source is \"${locator ?? packageName}\". Two sources cannot share one module id. Remove or rename the conflicting module explicitly before retrying.`)\n }\n const existingGithub = existing ? getModuleLocators(existing, resolver).find((value) => value.startsWith('github:')) : undefined\n const requestedIdentity = locator ? parseModuleLocator(locator)?.identity : undefined\n if (existingGithub && requestedIdentity && existingGithub !== requestedIdentity) {\n throw new Error(`Module name collision: \"${moduleId}\" is already registered from \"${existingGithub}\"; requested source is \"${locator}\". Remove or rename the conflicting module explicitly before retrying.`)\n }\n if (!existing && fs.existsSync(path.join(resolver.getAppDir(), 'src', 'modules', moduleId))) {\n throw new Error(`Module name collision: local src/modules/${moduleId} already exists; requested source is \"${locator ?? packageName}\". Remove or rename the conflicting module explicitly before retrying.`)\n }\n}\n\nfunction assertBindingPreserved(resolver: PackageResolver, target: InspectedModuleTarget): void {\n const consumers = resolver.loadEnabledModules().filter((entry) => (entry.from ?? '@open-mercato/core') === target.packageName)\n for (const entry of consumers) {\n const locators = getModuleLocators(entry, resolver)\n if (!target.locator || !locators.includes(target.locator) || !target.moduleIds.includes(entry.id)) {\n throw new Error(`Package binding collision: \"${target.packageName}\" supplies enabled module \"${entry.id}\" from \"${locators.join(', ') || 'unknown origin'}\". Requested \"${target.locator ?? 'unknown origin'}\" must preserve its source and module layout. Disable affected entries explicitly before replacing this binding. No package was installed.`)\n }\n }\n}\n\nfunction prepareRegistrationSource(\n modulePackage: ValidatedOfficialModulePackage,\n resolver: PackageResolver,\n packageName: string,\n eject: boolean,\n): string {\n const appModuleDir = validateBeforeRegistration(modulePackage, resolver, eject)\n\n if (!eject) {\n return packageName\n }\n\n if (!modulePackage.metadata.ejectable) {\n throw new Error(`Package \"${packageName}\" is not ejectable. --eject requires open-mercato.ejectable === true.`)\n }\n\n validateEjectBoundaries(modulePackage)\n copyDirRecursive(modulePackage.sourceModuleDir, appModuleDir)\n rewriteCrossModuleImports(\n modulePackage.sourceModuleDir,\n appModuleDir,\n modulePackage.metadata.moduleId,\n packageName,\n )\n\n return '@app'\n}\n\nasync function registerResolvedOfficialModule(\n resolver: PackageResolver,\n modulePackage: ValidatedOfficialModulePackage,\n packageName: string,\n eject: boolean,\n requestedLocator?: string,\n): Promise<ModuleCommandResult> {\n assertModuleNotGatedOff(resolver.getModulesConfigPath(), modulePackage.metadata.moduleId)\n const locators = getModuleLocators({ id: modulePackage.metadata.moduleId, from: packageName }, resolver)\n if (requestedLocator && locators.length > 0 && !locators.includes(requestedLocator)) {\n throw new Error(`Installed package \"${packageName}\" disagrees with inspected origin \"${requestedLocator}\". It is installed but not enabled. Restore the binding and lockfile through your package manager before retrying.`)\n }\n const locator = requestedLocator ?? locators[0]\n assertNoModuleCollision(resolver, modulePackage.metadata.moduleId, packageName, locator)\n assertRequiredModulesEnabled(modulePackage, resolver)\n const existing = resolver.loadEnabledModules().find((entry) => entry.id === modulePackage.metadata.moduleId)\n const from = eject ? '@app' : packageName\n const provenance = {\n ...(locator ? { locator } : {}),\n ...(eject || modulePackage.packageName !== packageName ? { packageName: modulePackage.packageName } : {}),\n }\n const modulesPath = resolver.getModulesConfigPath()\n const modulesSource = fs.readFileSync(modulesPath, 'utf8')\n const registration = existing && eject\n ? { changed: true, source: prepareModuleRegistrationSource(modulesSource, modulePackage.metadata.moduleId, from, provenance) }\n : prepareModuleRegistration(\n modulesSource,\n {\n id: modulePackage.metadata.moduleId,\n from,\n ...(locator || eject || modulePackage.packageName !== packageName ? provenance : {}),\n },\n )\n\n prepareRegistrationSource(modulePackage, resolver, packageName, eject)\n if (registration.changed) {\n fs.writeFileSync(modulesPath, registration.source)\n await runGeneratorsWithRegistrationNotice(resolver, modulePackage.metadata.moduleId)\n }\n\n return {\n moduleId: modulePackage.metadata.moduleId,\n packageName,\n from,\n registrationChanged: registration.changed,\n }\n}\n\nexport async function addOfficialModule(\n resolver: PackageResolver,\n packageSpec: string,\n eject: boolean,\n moduleId?: string,\n allowThirdParty = false,\n): Promise<ModuleCommandResult> {\n const input = packageSpec.trim()\n getEnabledModuleIdentities(resolver)\n const isGithub = !input.startsWith('@') && !input.startsWith('npm:') && (\n input.includes('/') && !input.includes('@file:') || /^(?:github:|git@|(?:git\\+)?ssh:)/i.test(input)\n )\n let safePackageSpec: string\n let packageName: string\n let target: InspectedModuleTarget\n if (isGithub) {\n if (!allowThirdParty) {\n throw new Error('GitHub repository installs require --allow-third-party, independently of the declared npm package scope.')\n }\n target = resolveGithubModuleTarget(input, resolver.getAppDir(), { moduleId, enabledModules: resolver.loadEnabledModules() })\n assertThirdPartyAllowed(target.packageName, allowThirdParty)\n const selectedModuleId = moduleId ?? (target.moduleIds.length === 1 ? target.moduleIds[0] : undefined)\n if (!selectedModuleId || !target.moduleIds.includes(selectedModuleId)) {\n throw new Error(`Select a module with --module <moduleId>. Available in ${target.locator ?? target.packageName}: ${target.moduleIds.join(', ')}. No package was installed.`)\n }\n assertNoModuleCollision(resolver, selectedModuleId, target.packageName, target.locator)\n safePackageSpec = target.packageSpec\n packageName = target.packageName\n } else {\n safePackageSpec = assertSupportedPackageSpec(input, allowThirdParty)\n const parsedName = parsePackageNameFromSpec(safePackageSpec)\n assertPackageName(parsedName)\n packageName = parsedName\n if (moduleId) assertNoModuleCollision(resolver, moduleId, packageName, safePackageSpec.startsWith(`${packageName}@file:`) ? undefined : `npm:${packageName}`)\n const requiredModuleIds = resolver.loadEnabledModules().filter((entry) => (entry.from ?? '@open-mercato/core') === packageName).map((entry) => entry.id)\n target = inspectNpmModuleTarget(safePackageSpec, packageName, resolver.getAppDir(), [...new Set([...(moduleId ? [moduleId] : []), ...requiredModuleIds])])\n }\n const selectedModuleId = moduleId ?? (target.moduleIds.length === 1 ? target.moduleIds[0] : undefined)\n if (!selectedModuleId || !target.moduleIds.includes(selectedModuleId)) {\n throw new Error(`Select a module with --module <moduleId>. Available in ${target.locator ?? target.packageName}: ${target.moduleIds.join(', ')}. No package was installed.`)\n }\n assertNoModuleCollision(resolver, selectedModuleId, packageName, target.locator)\n const existing = resolver.loadEnabledModules().find((entry) => entry.id === selectedModuleId)\n if (!eject && existing && !target.locator\n && target.packageSpec.startsWith(`${packageName}@file:`)\n && getModuleLocators(existing, resolver).length === 0\n && isDeclaredAppDependency(resolver.getAppDir(), packageName, target.packageSpec.slice(packageName.length + 1))) {\n return enableOfficialModule(resolver, packageName, selectedModuleId, false, allowThirdParty)\n }\n assertBindingPreserved(resolver, target)\n const modulesSource = fs.readFileSync(resolver.getModulesConfigPath(), 'utf8')\n const from = eject ? '@app' : packageName\n if (existing && eject) prepareModuleRegistrationSource(modulesSource, selectedModuleId, from, { locator: target.locator, packageName })\n else prepareModuleRegistration(modulesSource, { id: selectedModuleId, from, locator: target.locator })\n if (eject && fs.existsSync(path.join(resolver.getAppDir(), 'src', 'modules', selectedModuleId))) {\n throw new Error(`Destination directory already exists for \"${selectedModuleId}\". Preserve local source and resolve the conflict manually. No package was installed.`)\n }\n safePackageSpec = target.packageSpec\n assertModuleNotGatedOff(resolver.getModulesConfigPath(), selectedModuleId)\n const wasDeclaredBefore = isDeclaredAppDependency(resolver.getAppDir(), packageName)\n const modulesConfigBefore = readFileIfExists(resolver.getModulesConfigPath())\n await installPackageSpec(resolver, safePackageSpec)\n\n try {\n const modulePackage = resolveInstalledOfficialModulePackage(resolver, packageName, selectedModuleId)\n if (modulePackage.packageName !== packageName) throw new Error('Installed manifest differs from inspected package name.')\n if (target.version && modulePackage.packageJson.version !== target.version) {\n throw new Error(`Installed version \"${modulePackage.packageJson.version ?? 'unknown'}\" differs from inspected version \"${target.version}\". No registration or source edits were made.`)\n }\n for (const entry of resolver.loadEnabledModules().filter((entry) => (entry.from ?? '@open-mercato/core') === packageName)) {\n resolveInstalledOfficialModulePackage(resolver, packageName, entry.id)\n }\n return await registerResolvedOfficialModule(resolver, modulePackage, packageName, eject, target.locator)\n } catch (error) {\n const moduleWasRegistered = readFileIfExists(resolver.getModulesConfigPath()) !== modulesConfigBefore\n if (wasDeclaredBefore || moduleWasRegistered || isGatedOffError(error)) throw error\n const message = error instanceof Error ? error.message : String(error)\n throw withLeftoverPackageHint(\n new Error(`Package \"${packageName}\" is installed; enablement did not complete. Review src/modules.ts and restore the package binding/lockfile through the package manager if needed. ${message}`),\n resolver,\n packageName,\n )\n }\n}\n\nexport async function enableOfficialModule(\n resolver: PackageResolver,\n packageName: string,\n moduleId?: string,\n eject = false,\n allowThirdParty = false,\n): Promise<ModuleCommandResult> {\n if (!SAFE_PACKAGE_SPEC_PATTERN.test(packageName) || parsePackageNameFromSpec(packageName) !== packageName) {\n throw new Error('Unsupported installed package binding. Use the installed npm package name or alias, without a locator, path or version selector.')\n }\n getEnabledModuleIdentities(resolver)\n const modulePackage = resolveInstalledOfficialModulePackage(resolver, packageName, moduleId)\n assertThirdPartyAllowed(modulePackage.packageName, allowThirdParty)\n if (!allowThirdParty && getModuleLocators({ id: modulePackage.metadata.moduleId, from: packageName }, resolver).some((locator) => locator.startsWith('github:'))) {\n throw new Error('GitHub repository installs require --allow-third-party, independently of the declared npm package scope.')\n }\n return registerResolvedOfficialModule(resolver, modulePackage, packageName, eject)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,WAAW;AAClB,SAAS,kBAAkB,iCAAiC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB,2BAA2B,uCAAuC;AAEpG,SAAS,2BAA2B;AACpC,SAAS,oBAAoB,gCAAgC;AAC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2
2
|
import path from "node:path";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
+
import ts from "typescript-js";
|
|
5
|
+
import { normalizeModuleLocator } from "@open-mercato/shared/modules/module-locators";
|
|
6
|
+
import { sourceHasDefaultExport, sourceExportedHttpMethods } from "./generators/source-exports.js";
|
|
7
|
+
import { MODULE_CODE_EXTENSIONS, SCAN_CONFIGS, stripModuleCodeExtension } from "./generators/scanner.js";
|
|
4
8
|
const SOURCE_FILE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
5
9
|
const SKIP_DIRS = /* @__PURE__ */ new Set(["__tests__", "__mocks__", "node_modules"]);
|
|
6
10
|
const MODULE_ID_PATTERN = /^[a-z0-9]+(?:_[a-z0-9]+)*$/;
|
|
@@ -17,16 +21,69 @@ function readPackageJson(packageJsonPath) {
|
|
|
17
21
|
throw new Error(`Failed to read package manifest at ${packageJsonPath}: ${message}`);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
|
-
function
|
|
21
|
-
if (!
|
|
24
|
+
function readPropertyName(property) {
|
|
25
|
+
if (!("name" in property) || !property.name) return null;
|
|
26
|
+
return ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name) ? property.name.text : null;
|
|
27
|
+
}
|
|
28
|
+
function unwrapExpression(expression) {
|
|
29
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression) || ts.isSatisfiesExpression(expression)) {
|
|
30
|
+
return unwrapExpression(expression.expression);
|
|
31
|
+
}
|
|
32
|
+
return expression;
|
|
33
|
+
}
|
|
34
|
+
function findMetadataLiteral(source, indexPath) {
|
|
35
|
+
const sourceFile = ts.createSourceFile(indexPath, source, ts.ScriptTarget.Latest, true);
|
|
36
|
+
for (const statement of sourceFile.statements) {
|
|
37
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
38
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
39
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== "metadata" || !declaration.initializer) continue;
|
|
40
|
+
const initializer = unwrapExpression(declaration.initializer);
|
|
41
|
+
if (ts.isObjectLiteralExpression(initializer)) return initializer;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function parseModuleInfo(indexPath, validateRequires = false) {
|
|
47
|
+
if (!fs.existsSync(indexPath)) return { requires: [] };
|
|
22
48
|
const source = fs.readFileSync(indexPath, "utf8");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
|
|
49
|
+
const metadata = findMetadataLiteral(source, indexPath);
|
|
50
|
+
const result = {
|
|
51
|
+
requires: []
|
|
52
|
+
};
|
|
53
|
+
if (!metadata) return result;
|
|
54
|
+
for (const property of metadata.properties) {
|
|
55
|
+
const propertyName = readPropertyName(property);
|
|
56
|
+
if (!ts.isPropertyAssignment(property)) {
|
|
57
|
+
if (validateRequires && propertyName === "requires") {
|
|
58
|
+
throw new Error(`Module descriptor at ${indexPath} must declare "requires" as a static string array.`);
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const initializer = unwrapExpression(property.initializer);
|
|
63
|
+
if ((propertyName === "title" || propertyName === "description" || propertyName === "locator") && ts.isStringLiteralLike(initializer)) {
|
|
64
|
+
result[propertyName] = initializer.text;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (propertyName === "ejectable") {
|
|
68
|
+
if (initializer.kind === ts.SyntaxKind.TrueKeyword) result.ejectable = true;
|
|
69
|
+
if (initializer.kind === ts.SyntaxKind.FalseKeyword) result.ejectable = false;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (propertyName !== "requires") continue;
|
|
73
|
+
if (!ts.isArrayLiteralExpression(initializer)) {
|
|
74
|
+
if (validateRequires) {
|
|
75
|
+
throw new Error(`Module descriptor at ${indexPath} must declare "requires" as a static string array.`);
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (initializer.elements.some((element) => !ts.isStringLiteralLike(element))) {
|
|
80
|
+
if (validateRequires) {
|
|
81
|
+
throw new Error(`Module descriptor at ${indexPath} must contain only string module ids in "requires".`);
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
result.requires = initializer.elements.map((element) => element.text);
|
|
86
|
+
}
|
|
30
87
|
return result;
|
|
31
88
|
}
|
|
32
89
|
function discoverModulesInPackage(packageRoot) {
|
|
@@ -103,13 +160,13 @@ function collectBoundaryViolations(moduleDir) {
|
|
|
103
160
|
}
|
|
104
161
|
return Array.from(violations).sort((left, right) => left.localeCompare(right));
|
|
105
162
|
}
|
|
106
|
-
function findResolvedPackageRoot(resolvedPath
|
|
163
|
+
function findResolvedPackageRoot(resolvedPath) {
|
|
107
164
|
let currentPath = fs.statSync(resolvedPath).isDirectory() ? resolvedPath : path.dirname(resolvedPath);
|
|
108
165
|
while (currentPath !== path.dirname(currentPath)) {
|
|
109
166
|
const packageJsonPath = path.join(currentPath, "package.json");
|
|
110
167
|
if (fs.existsSync(packageJsonPath)) {
|
|
111
168
|
const packageJson = readPackageJson(packageJsonPath);
|
|
112
|
-
if (packageJson.name ===
|
|
169
|
+
if (typeof packageJson.name === "string" && normalizeModuleLocator(`npm:${packageJson.name}`) === `npm:${packageJson.name}`) {
|
|
113
170
|
return currentPath;
|
|
114
171
|
}
|
|
115
172
|
}
|
|
@@ -124,7 +181,7 @@ function resolveInstalledPackageRootWithRequire(packageName, appDir) {
|
|
|
124
181
|
const resolvedPath = requireFromCli.resolve(specifier, {
|
|
125
182
|
paths: [appDir]
|
|
126
183
|
});
|
|
127
|
-
const packageRoot = specifier === packageName ? findResolvedPackageRoot(resolvedPath
|
|
184
|
+
const packageRoot = specifier === packageName ? findResolvedPackageRoot(resolvedPath) : path.dirname(resolvedPath);
|
|
128
185
|
if (packageRoot) {
|
|
129
186
|
return packageRoot;
|
|
130
187
|
}
|
|
@@ -161,6 +218,115 @@ function resolveInstalledPackageRoot(resolver, packageName) {
|
|
|
161
218
|
}
|
|
162
219
|
throw new Error(`Package "${packageName}" is not installed in ${resolver.getAppDir()}.`);
|
|
163
220
|
}
|
|
221
|
+
function resolveEsmExportTarget(value, substitution) {
|
|
222
|
+
if (typeof value === "string") {
|
|
223
|
+
const target = substitution === void 0 ? value : value.replaceAll("*", substitution);
|
|
224
|
+
if (!target.startsWith("./") || target.slice(2).split("/").some((segment) => ["..", ".", "node_modules"].includes(segment))) return void 0;
|
|
225
|
+
return target;
|
|
226
|
+
}
|
|
227
|
+
if (value === null) return null;
|
|
228
|
+
if (Array.isArray(value)) {
|
|
229
|
+
for (const candidate of value) {
|
|
230
|
+
const target = resolveEsmExportTarget(candidate, substitution);
|
|
231
|
+
if (target !== void 0 && target !== null) return target;
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
if (value && typeof value === "object") {
|
|
236
|
+
for (const [condition, candidate] of Object.entries(value)) {
|
|
237
|
+
if (!["import", "node", "node-addons", "module-sync", "default"].includes(condition)) continue;
|
|
238
|
+
const target = resolveEsmExportTarget(candidate, substitution);
|
|
239
|
+
if (target !== void 0) return target;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
function resolvePackageSubpathExport(exports, subpath) {
|
|
245
|
+
if (!exports || typeof exports !== "object" || Array.isArray(exports)) return void 0;
|
|
246
|
+
const entries = Object.entries(exports);
|
|
247
|
+
const direct = entries.find(([key]) => key === subpath);
|
|
248
|
+
if (direct) return resolveEsmExportTarget(direct[1]);
|
|
249
|
+
const patterns = entries.filter(([key]) => key.startsWith("./") && key.includes("*")).sort(([left], [right]) => right.indexOf("*") - left.indexOf("*") || right.length - left.length);
|
|
250
|
+
for (const [pattern, target] of patterns) {
|
|
251
|
+
const wildcard = pattern.indexOf("*");
|
|
252
|
+
const prefix = pattern.slice(0, wildcard);
|
|
253
|
+
const suffix = pattern.slice(wildcard + 1);
|
|
254
|
+
if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) {
|
|
255
|
+
return resolveEsmExportTarget(target, subpath.slice(prefix.length, subpath.length - suffix.length));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
function isGeneratedModuleImport(relativePath, moduleFiles, readSource) {
|
|
261
|
+
const segments = relativePath.split("/");
|
|
262
|
+
if (segments.some((segment) => segment === "__tests__" || segment === "__mocks__")) return false;
|
|
263
|
+
const fileName = segments[segments.length - 1];
|
|
264
|
+
if (fileName.endsWith(".d.ts") || /\.(?:test|spec)\.[jt]sx?$/.test(fileName)) return false;
|
|
265
|
+
const basename = stripModuleCodeExtension(fileName);
|
|
266
|
+
if (segments.length === 1) {
|
|
267
|
+
return (/* @__PURE__ */ new Set(["index", "acl", "setup", "cli", "runtime", "ce", "search", "events", "notifications", "notifications.client", "notifications.handlers", "translations", "encryption", "ai-tools", "ai-agents", "di", "integration", "vector"])).has(basename);
|
|
268
|
+
}
|
|
269
|
+
if (["widgets/components", "widgets/injection-table", "api/interceptors", "data/extensions", "data/fields"].includes(stripModuleCodeExtension(relativePath))) return true;
|
|
270
|
+
if (/^commands\//.test(relativePath)) {
|
|
271
|
+
return MODULE_CODE_EXTENSIONS.some((extension) => fileName.endsWith(extension)) && !["index", "shared", "factory"].includes(basename);
|
|
272
|
+
}
|
|
273
|
+
const scanConfigs = Object.values(SCAN_CONFIGS);
|
|
274
|
+
for (const config of scanConfigs) {
|
|
275
|
+
if (!relativePath.startsWith(`${config.folder}/`)) continue;
|
|
276
|
+
const relativeSegments = relativePath.slice(config.folder.length + 1).split("/");
|
|
277
|
+
if (relativeSegments.slice(0, -1).some((segment) => config.skipDirs?.(segment))) continue;
|
|
278
|
+
if (!config.include(fileName)) continue;
|
|
279
|
+
if (config.folder === "frontend" || config.folder === "backend") return readSource ? sourceHasDefaultExport(relativePath, readSource(relativePath)) : false;
|
|
280
|
+
if (config.folder === "api") return readSource ? sourceExportedHttpMethods(readSource(relativePath)).length > 0 : false;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
if (/^(?:frontend|backend)\//.test(relativePath) && (basename === "meta" || basename.endsWith(".meta"))) {
|
|
284
|
+
const folder = segments.slice(0, -1).join("/");
|
|
285
|
+
const pageConfig = segments[0] === "frontend" ? SCAN_CONFIGS.frontendPages : SCAN_CONFIGS.backendPages;
|
|
286
|
+
const candidates = moduleFiles.filter((file) => file.startsWith(`${folder}/`) && !file.slice(folder.length + 1).includes("/") && pageConfig.include(path.posix.basename(file)));
|
|
287
|
+
return candidates.some((candidate) => (basename === "meta" || basename === `${stripModuleCodeExtension(path.posix.basename(candidate))}.meta`) && Boolean(readSource && sourceHasDefaultExport(candidate, readSource(candidate))));
|
|
288
|
+
}
|
|
289
|
+
if (/^(?:data|db)\/(?:entities\.override|entities|schema)\.[jt]sx?$/.test(relativePath)) {
|
|
290
|
+
const selected = ["data", "db"].flatMap((folder) => ["entities.override", "entities", "schema"].flatMap((candidate) => MODULE_CODE_EXTENSIONS.map((extension) => `${folder}/${candidate}${extension}`))).find((candidate) => moduleFiles.includes(candidate));
|
|
291
|
+
return relativePath === selected;
|
|
292
|
+
}
|
|
293
|
+
return /^i18n\/[^/]+\.json$/.test(relativePath);
|
|
294
|
+
}
|
|
295
|
+
function isModulePackageExportError(error) {
|
|
296
|
+
return error instanceof Error && "code" in error && error.code === "MODULE_PACKAGE_EXPORT_UNAVAILABLE";
|
|
297
|
+
}
|
|
298
|
+
function assertModulePackageExports(manifest, binding, moduleId, packageFiles, readSource) {
|
|
299
|
+
const normalizedFiles = new Set(packageFiles.map((file) => file.replaceAll("\\", "/").replace(/^\.\//, "")));
|
|
300
|
+
const sourcePrefix = `src/modules/${moduleId}/`;
|
|
301
|
+
const distPrefix = `dist/modules/${moduleId}/`;
|
|
302
|
+
const sourceFiles = [...normalizedFiles].filter((file) => file.startsWith(sourcePrefix)).map((file) => file.slice(sourcePrefix.length));
|
|
303
|
+
const distFiles = [...normalizedFiles].filter((file) => file.startsWith(distPrefix)).map((file) => file.slice(distPrefix.length));
|
|
304
|
+
const moduleFiles = sourceFiles.length > 0 ? sourceFiles : distFiles;
|
|
305
|
+
const cachedSources = /* @__PURE__ */ new Map();
|
|
306
|
+
const readModuleSource = readSource ? (relativePath) => {
|
|
307
|
+
let source = cachedSources.get(relativePath);
|
|
308
|
+
if (source === void 0) {
|
|
309
|
+
source = readSource(`${sourceFiles.length > 0 ? sourcePrefix : distPrefix}${relativePath}`);
|
|
310
|
+
cachedSources.set(relativePath, source);
|
|
311
|
+
}
|
|
312
|
+
return source;
|
|
313
|
+
} : void 0;
|
|
314
|
+
const generatedCandidates = sourceFiles.length > 0 ? sourceFiles : distFiles;
|
|
315
|
+
for (const sourcePath of generatedCandidates) {
|
|
316
|
+
if (!isGeneratedModuleImport(sourcePath, moduleFiles, readModuleSource)) continue;
|
|
317
|
+
const isCode = /\.[jt]sx?$/.test(sourcePath);
|
|
318
|
+
const runtimePath = sourceFiles.length > 0 && isCode ? distFiles.find((file) => /\.jsx?$/.test(file) && stripModuleCodeExtension(file) === stripModuleCodeExtension(sourcePath)) : sourcePath;
|
|
319
|
+
const publicPath = `./modules/${moduleId}/${stripModuleCodeExtension(sourcePath)}`;
|
|
320
|
+
if (!runtimePath) {
|
|
321
|
+
throw Object.assign(new Error(`Package binding "${binding}" cannot import "${binding}/${publicPath.slice(2)}": the package artifact is missing the compiled runtime entrypoint. Build the package before enabling it.`), { code: "MODULE_PACKAGE_EXPORT_UNAVAILABLE" });
|
|
322
|
+
}
|
|
323
|
+
if (manifest.exports === void 0) continue;
|
|
324
|
+
const target = resolvePackageSubpathExport(manifest.exports, publicPath);
|
|
325
|
+
if (!target || !normalizedFiles.has(target.slice(2))) {
|
|
326
|
+
throw Object.assign(new Error(`Package binding "${binding}" cannot import "${binding}/${publicPath.slice(2)}": the package exports do not provide an available ESM target. Keep the current provider and use a package exposing this module subpath before enabling it.`), { code: "MODULE_PACKAGE_EXPORT_UNAVAILABLE" });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
164
330
|
function readOfficialModulePackageFromRoot(packageRoot, expectedPackageName, targetModuleId) {
|
|
165
331
|
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
166
332
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -171,6 +337,9 @@ function readOfficialModulePackageFromRoot(packageRoot, expectedPackageName, tar
|
|
|
171
337
|
if (!packageName) {
|
|
172
338
|
throw new Error(`Package manifest at ${packageJsonPath} is missing the "name" field.`);
|
|
173
339
|
}
|
|
340
|
+
if (typeof packageName !== "string" || normalizeModuleLocator(`npm:${packageName}`) !== `npm:${packageName}`) {
|
|
341
|
+
throw new Error(`Package manifest at ${packageJsonPath} has an invalid "name" field.`);
|
|
342
|
+
}
|
|
174
343
|
if (expectedPackageName && packageName !== expectedPackageName) {
|
|
175
344
|
throw new Error(`Resolved package "${packageName}" does not match requested package "${expectedPackageName}".`);
|
|
176
345
|
}
|
|
@@ -206,20 +375,38 @@ function readOfficialModulePackageFromRoot(packageRoot, expectedPackageName, tar
|
|
|
206
375
|
if (!fs.existsSync(distModuleDir)) {
|
|
207
376
|
throw new Error(`Package "${packageName}" is missing dist/modules/${moduleId}.`);
|
|
208
377
|
}
|
|
209
|
-
const info = parseModuleInfo(path.join(sourceModuleDir, "index.ts"));
|
|
378
|
+
const info = parseModuleInfo(path.join(sourceModuleDir, "index.ts"), true);
|
|
210
379
|
return {
|
|
211
380
|
packageName,
|
|
212
381
|
packageRoot,
|
|
213
382
|
packageJson,
|
|
214
383
|
metadata: { moduleId, ejectable: selected.ejectable },
|
|
215
|
-
moduleInfo: { title: info.title, description: info.description },
|
|
384
|
+
moduleInfo: { title: info.title, description: info.description, requires: info.requires, ...info.locator ? { locator: info.locator } : {} },
|
|
216
385
|
sourceModuleDir,
|
|
217
386
|
distModuleDir
|
|
218
387
|
};
|
|
219
388
|
}
|
|
389
|
+
function listPackageFiles(packageRoot, directory = packageRoot) {
|
|
390
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
391
|
+
if (shouldSkipEntryName(entry.name)) return [];
|
|
392
|
+
const fullPath = path.join(directory, entry.name);
|
|
393
|
+
return entry.isDirectory() ? listPackageFiles(packageRoot, fullPath) : [path.relative(packageRoot, fullPath)];
|
|
394
|
+
});
|
|
395
|
+
}
|
|
220
396
|
function resolveInstalledOfficialModulePackage(resolver, packageName, moduleId) {
|
|
221
397
|
const packageRoot = resolveInstalledPackageRoot(resolver, packageName);
|
|
222
|
-
|
|
398
|
+
const modulePackage = readOfficialModulePackageFromRoot(packageRoot, void 0, moduleId);
|
|
399
|
+
const packageFiles = listPackageFiles(packageRoot);
|
|
400
|
+
assertModulePackageExports(modulePackage.packageJson, packageName, modulePackage.metadata.moduleId, packageFiles, (relativePath) => fs.readFileSync(path.join(packageRoot, relativePath), "utf8"));
|
|
401
|
+
if (modulePackage.packageName !== packageName) {
|
|
402
|
+
const resolvedBindingRoot = resolveInstalledPackageRootWithRequire(packageName, resolver.getAppDir());
|
|
403
|
+
const installedBindingPath = path.join("node_modules", packageName);
|
|
404
|
+
const matchesBindingPath = path.normalize(packageRoot).endsWith(`${path.sep}${installedBindingPath}`);
|
|
405
|
+
if (!matchesBindingPath && (!resolvedBindingRoot || fs.realpathSync(resolvedBindingRoot) !== fs.realpathSync(packageRoot))) {
|
|
406
|
+
throw new Error(`Resolved package "${modulePackage.packageName}" does not match requested package binding "${packageName}".`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return modulePackage;
|
|
223
410
|
}
|
|
224
411
|
function validateEjectBoundaries(modulePackage) {
|
|
225
412
|
const violations = collectBoundaryViolations(modulePackage.sourceModuleDir);
|
|
@@ -235,11 +422,14 @@ function validateEjectBoundaries(modulePackage) {
|
|
|
235
422
|
);
|
|
236
423
|
}
|
|
237
424
|
export {
|
|
425
|
+
assertModulePackageExports,
|
|
238
426
|
discoverModulesInPackage,
|
|
427
|
+
isModulePackageExportError,
|
|
239
428
|
parsePackageNameFromSpec,
|
|
240
429
|
readOfficialModulePackageFromRoot,
|
|
241
430
|
resolveInstalledOfficialModulePackage,
|
|
242
431
|
resolveInstalledPackageRoot,
|
|
432
|
+
resolveInstalledPackageRootWithRequire,
|
|
243
433
|
validateEjectBoundaries
|
|
244
434
|
};
|
|
245
435
|
//# sourceMappingURL=module-package.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/module-package.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { createRequire } from 'node:module'\nimport type { PackageResolver } from './resolver'\n\ntype PackageJsonRecord = {\n name?: string\n version?: string\n dependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n}\n\nexport type ModulePackageMetadata = {\n moduleId: string\n ejectable: boolean\n}\n\nexport type ModuleInfoSnapshot = {\n title?: string\n description?: string\n}\n\nexport type ValidatedOfficialModulePackage = {\n packageName: string\n packageRoot: string\n packageJson: PackageJsonRecord\n metadata: ModulePackageMetadata\n moduleInfo: ModuleInfoSnapshot\n sourceModuleDir: string\n distModuleDir: string\n}\n\ntype DiscoveredModule = {\n moduleId: string\n ejectable: boolean\n}\n\nconst SOURCE_FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs']\nconst SKIP_DIRS = new Set(['__tests__', '__mocks__', 'node_modules'])\nconst MODULE_ID_PATTERN = /^[a-z0-9]+(?:_[a-z0-9]+)*$/\nconst requireFromCli = createRequire(path.join(process.cwd(), 'package.json'))\n\nfunction shouldSkipEntryName(name: string): boolean {\n return SKIP_DIRS.has(name) || name === '.DS_Store' || name.startsWith('._')\n}\n\nfunction readPackageJson(packageJsonPath: string): PackageJsonRecord {\n try {\n const raw = fs.readFileSync(packageJsonPath, 'utf8')\n return JSON.parse(raw) as PackageJsonRecord\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to read package manifest at ${packageJsonPath}: ${message}`)\n }\n}\n\nfunction parseModuleInfo(indexPath: string): { title?: string; description?: string; ejectable?: boolean } {\n if (!fs.existsSync(indexPath)) return {}\n\n const source = fs.readFileSync(indexPath, 'utf8')\n const result: { title?: string; description?: string; ejectable?: boolean } = {}\n\n const titleMatch = source.match(/\\btitle\\s*:\\s*['\"]([^'\"]+)['\"]/)\n if (titleMatch) result.title = titleMatch[1]\n\n const descriptionMatch = source.match(/\\bdescription\\s*:\\s*['\"]([^'\"]+)['\"]/)\n if (descriptionMatch) result.description = descriptionMatch[1]\n\n const ejectableMatch = source.match(/\\bejectable\\s*:\\s*(true|false)/)\n if (ejectableMatch) result.ejectable = ejectableMatch[1] === 'true'\n\n return result\n}\n\nexport function discoverModulesInPackage(packageRoot: string): DiscoveredModule[] {\n const srcModulesDir = path.join(packageRoot, 'src', 'modules')\n const distModulesDir = path.join(packageRoot, 'dist', 'modules')\n\n const enumerationDir = fs.existsSync(srcModulesDir)\n ? srcModulesDir\n : fs.existsSync(distModulesDir)\n ? distModulesDir\n : null\n\n if (!enumerationDir) return []\n\n const modules: DiscoveredModule[] = []\n\n for (const entry of fs.readdirSync(enumerationDir, { withFileTypes: true })) {\n if (!entry.isDirectory() || shouldSkipEntryName(entry.name) || !MODULE_ID_PATTERN.test(entry.name)) continue\n\n const moduleId = entry.name\n const srcIndexPath = path.join(packageRoot, 'src', 'modules', moduleId, 'index.ts')\n const distIndexPath = path.join(packageRoot, 'dist', 'modules', moduleId, 'index.js')\n const indexPath = fs.existsSync(srcIndexPath) ? srcIndexPath : distIndexPath\n\n const info = parseModuleInfo(indexPath)\n modules.push({ moduleId, ejectable: info.ejectable ?? false })\n }\n\n return modules\n}\n\nfunction resolveRelativeImportTarget(sourceFile: string, importPath: string): string | null {\n if (!importPath.startsWith('.')) return null\n\n const basePath = path.resolve(path.dirname(sourceFile), importPath)\n const candidates = [basePath]\n\n for (const ext of SOURCE_FILE_EXTENSIONS) {\n candidates.push(`${basePath}${ext}`)\n candidates.push(path.join(basePath, `index${ext}`))\n }\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n return candidate\n }\n }\n\n return null\n}\n\nfunction collectSourceFiles(dir: string): string[] {\n const files: string[] = []\n const entries = fs.readdirSync(dir, { withFileTypes: true })\n\n for (const entry of entries) {\n if (shouldSkipEntryName(entry.name)) continue\n\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n files.push(...collectSourceFiles(fullPath))\n continue\n }\n\n const ext = path.extname(entry.name)\n if (!SOURCE_FILE_EXTENSIONS.includes(ext)) continue\n files.push(fullPath)\n }\n\n return files\n}\n\nfunction collectBoundaryViolations(moduleDir: string): string[] {\n const modulesRoot = path.resolve(moduleDir, '..')\n const modulePrefix = `${moduleDir}${path.sep}`\n const modulesPrefix = `${modulesRoot}${path.sep}`\n const files = collectSourceFiles(moduleDir)\n const violations = new Set<string>()\n\n for (const filePath of files) {\n const content = fs.readFileSync(filePath, 'utf8')\n const matches = [\n ...content.matchAll(/\\bfrom\\s*['\"]([^'\"]+)['\"]/g),\n ...content.matchAll(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g),\n ]\n\n for (const match of matches) {\n const specifier = match[1]\n if (!specifier) continue\n const resolvedTarget = resolveRelativeImportTarget(filePath, specifier)\n if (!resolvedTarget) continue\n if (resolvedTarget.startsWith(modulePrefix)) continue\n if (resolvedTarget.startsWith(modulesPrefix)) continue\n\n const relativeSource = path.relative(moduleDir, filePath).split(path.sep).join('/')\n const relativeTarget = path.relative(path.dirname(filePath), resolvedTarget).split(path.sep).join('/')\n violations.add(`${relativeSource} -> ${relativeTarget}`)\n }\n }\n\n return Array.from(violations).sort((left, right) => left.localeCompare(right))\n}\n\nfunction findResolvedPackageRoot(\n resolvedPath: string,\n packageName: string,\n): string | null {\n let currentPath = fs.statSync(resolvedPath).isDirectory()\n ? resolvedPath\n : path.dirname(resolvedPath)\n\n while (currentPath !== path.dirname(currentPath)) {\n const packageJsonPath = path.join(currentPath, 'package.json')\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = readPackageJson(packageJsonPath)\n if (packageJson.name === packageName) {\n return currentPath\n }\n }\n currentPath = path.dirname(currentPath)\n }\n\n return null\n}\n\nfunction resolveInstalledPackageRootWithRequire(packageName: string, appDir: string): string | null {\n const specifiers = [`${packageName}/package.json`, packageName]\n\n for (const specifier of specifiers) {\n try {\n const resolvedPath = requireFromCli.resolve(specifier, {\n paths: [appDir],\n })\n const packageRoot =\n specifier === packageName\n ? findResolvedPackageRoot(resolvedPath, packageName)\n : path.dirname(resolvedPath)\n\n if (packageRoot) {\n return packageRoot\n }\n } catch {\n continue\n }\n }\n\n return null\n}\n\nexport function parsePackageNameFromSpec(packageSpec: string): string | null {\n const trimmed = packageSpec.trim()\n if (!trimmed) return null\n\n if (trimmed.startsWith('@')) {\n const slashIndex = trimmed.indexOf('/')\n if (slashIndex < 0) return null\n const versionSeparator = trimmed.indexOf('@', slashIndex + 1)\n return versionSeparator < 0 ? trimmed : trimmed.slice(0, versionSeparator)\n }\n\n const versionSeparator = trimmed.indexOf('@')\n return versionSeparator < 0 ? trimmed : trimmed.slice(0, versionSeparator)\n}\n\nexport function resolveInstalledPackageRoot(\n resolver: PackageResolver,\n packageName: string,\n): string {\n const resolvedWithRequire = resolveInstalledPackageRootWithRequire(packageName, resolver.getAppDir())\n if (resolvedWithRequire) {\n return resolvedWithRequire\n }\n\n const fallback = resolver.getPackageRoot(packageName)\n if (fs.existsSync(path.join(fallback, 'package.json'))) {\n return fallback\n }\n\n // In monorepo mode, getPackageRoot resolves to packages/<name> (workspace convention),\n // but externally installed packages land in root node_modules \u2014 check there too.\n const nodeModulesFallback = path.join(resolver.getRootDir(), 'node_modules', packageName)\n if (fs.existsSync(path.join(nodeModulesFallback, 'package.json'))) {\n return nodeModulesFallback\n }\n\n throw new Error(`Package \"${packageName}\" is not installed in ${resolver.getAppDir()}.`)\n}\n\nexport function readOfficialModulePackageFromRoot(\n packageRoot: string,\n expectedPackageName?: string,\n targetModuleId?: string,\n): ValidatedOfficialModulePackage {\n const packageJsonPath = path.join(packageRoot, 'package.json')\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`Package manifest not found at ${packageJsonPath}.`)\n }\n\n const packageJson = readPackageJson(packageJsonPath)\n const packageName = packageJson.name\n if (!packageName) {\n throw new Error(`Package manifest at ${packageJsonPath} is missing the \"name\" field.`)\n }\n\n if (expectedPackageName && packageName !== expectedPackageName) {\n throw new Error(`Resolved package \"${packageName}\" does not match requested package \"${expectedPackageName}\".`)\n }\n\n const discoveredModules = discoverModulesInPackage(packageRoot)\n\n if (discoveredModules.length === 0) {\n throw new Error(`Package \"${packageName}\" has no modules in src/modules/ or dist/modules/.`)\n }\n\n let selected: DiscoveredModule\n\n if (targetModuleId) {\n const found = discoveredModules.find((m) => m.moduleId === targetModuleId)\n if (!found) {\n const available = discoveredModules.map((m) => m.moduleId).join(', ')\n throw new Error(\n `Package \"${packageName}\" does not contain module \"${targetModuleId}\". Available: ${available}`,\n )\n }\n selected = found\n } else {\n if (discoveredModules.length > 1) {\n const available = discoveredModules.map((m) => m.moduleId).join(', ')\n throw new Error(\n `Package \"${packageName}\" contains multiple modules (${available}). Specify one with --module <moduleId>.`,\n )\n }\n selected = discoveredModules[0]\n }\n\n const { moduleId } = selected\n const sourceModuleDir = path.join(packageRoot, 'src', 'modules', moduleId)\n const distModuleDir = path.join(packageRoot, 'dist', 'modules', moduleId)\n\n if (!fs.existsSync(sourceModuleDir)) {\n throw new Error(`Package \"${packageName}\" is missing src/modules/${moduleId}.`)\n }\n\n if (!fs.existsSync(distModuleDir)) {\n throw new Error(`Package \"${packageName}\" is missing dist/modules/${moduleId}.`)\n }\n\n const info = parseModuleInfo(path.join(sourceModuleDir, 'index.ts'))\n\n return {\n packageName,\n packageRoot,\n packageJson,\n metadata: { moduleId, ejectable: selected.ejectable },\n moduleInfo: { title: info.title, description: info.description },\n sourceModuleDir,\n distModuleDir,\n }\n}\n\nexport function resolveInstalledOfficialModulePackage(\n resolver: PackageResolver,\n packageName: string,\n moduleId?: string,\n): ValidatedOfficialModulePackage {\n const packageRoot = resolveInstalledPackageRoot(resolver, packageName)\n return readOfficialModulePackageFromRoot(packageRoot, packageName, moduleId)\n}\n\nexport function validateEjectBoundaries(modulePackage: ValidatedOfficialModulePackage): void {\n const violations = collectBoundaryViolations(modulePackage.sourceModuleDir)\n if (violations.length === 0) {\n return\n }\n\n throw new Error(\n [\n `Package \"${modulePackage.packageName}\" cannot be added with --eject because it imports files outside src/modules/${modulePackage.metadata.moduleId}.`,\n 'Invalid imports:',\n ...violations.map((violation) => `- ${violation}`),\n ].join('\\n'),\n )\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAmC9B,MAAM,yBAAyB,CAAC,OAAO,QAAQ,OAAO,QAAQ,QAAQ,MAAM;AAC5E,MAAM,YAAY,oBAAI,IAAI,CAAC,aAAa,aAAa,cAAc,CAAC;AACpE,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB,cAAc,KAAK,KAAK,QAAQ,IAAI,GAAG,cAAc,CAAC;AAE7E,SAAS,oBAAoB,MAAuB;AAClD,SAAO,UAAU,IAAI,IAAI,KAAK,SAAS,eAAe,KAAK,WAAW,IAAI;AAC5E;AAEA,SAAS,gBAAgB,iBAA4C;AACnE,MAAI;AACF,UAAM,MAAM,GAAG,aAAa,iBAAiB,MAAM;AACnD,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAM,IAAI,MAAM,sCAAsC,eAAe,KAAK,OAAO,EAAE;AAAA,EACrF;AACF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,GAAG,WAAW,aAAa,GAAG;AACjC,UAAM,IAAI,MAAM,YAAY,WAAW,6BAA6B,QAAQ,GAAG;AAAA,EACjF;AAEA,QAAM,OAAO,gBAAgB,KAAK,KAAK,iBAAiB,UAAU,CAAC;AAEnE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,EAAE,UAAU,WAAW,SAAS,UAAU;AAAA,IACpD,YAAY,EAAE,OAAO,KAAK,OAAO,aAAa,KAAK,YAAY;AAAA,IAC/D;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,sCACd,UACA,aACA,UACgC;AAChC,QAAM,cAAc,4BAA4B,UAAU,WAAW;AACrE,SAAO,kCAAkC,aAAa,aAAa,QAAQ;AAC7E;AAEO,SAAS,wBAAwB,eAAqD;AAC3F,QAAM,aAAa,0BAA0B,cAAc,eAAe;AAC1E,MAAI,WAAW,WAAW,GAAG;AAC3B;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,MACE,YAAY,cAAc,WAAW,+EAA+E,cAAc,SAAS,QAAQ;AAAA,MACnJ;AAAA,MACA,GAAG,WAAW,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE;AAAA,IACnD,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { createRequire } from 'node:module'\nimport ts from 'typescript-js'\nimport type { PackageResolver } from './resolver'\nimport { normalizeModuleLocator } from '@open-mercato/shared/modules/module-locators'\nimport { sourceHasDefaultExport, sourceExportedHttpMethods } from './generators/source-exports'\nimport { MODULE_CODE_EXTENSIONS, SCAN_CONFIGS, stripModuleCodeExtension, type ScanConfig } from './generators/scanner'\n\ntype PackageJsonRecord = {\n name?: string\n version?: string\n dependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n exports?: unknown\n}\n\nexport type ModulePackageMetadata = {\n moduleId: string\n ejectable: boolean\n}\n\nexport type ModuleInfoSnapshot = {\n title?: string\n description?: string\n requires?: string[]\n locator?: string\n}\n\nexport type ValidatedOfficialModulePackage = {\n packageName: string\n packageRoot: string\n packageJson: PackageJsonRecord\n metadata: ModulePackageMetadata\n moduleInfo: ModuleInfoSnapshot\n sourceModuleDir: string\n distModuleDir: string\n}\n\ntype DiscoveredModule = {\n moduleId: string\n ejectable: boolean\n}\n\nconst SOURCE_FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs']\nconst SKIP_DIRS = new Set(['__tests__', '__mocks__', 'node_modules'])\nconst MODULE_ID_PATTERN = /^[a-z0-9]+(?:_[a-z0-9]+)*$/\nconst requireFromCli = createRequire(path.join(process.cwd(), 'package.json'))\n\nfunction shouldSkipEntryName(name: string): boolean {\n return SKIP_DIRS.has(name) || name === '.DS_Store' || name.startsWith('._')\n}\n\nfunction readPackageJson(packageJsonPath: string): PackageJsonRecord {\n try {\n const raw = fs.readFileSync(packageJsonPath, 'utf8')\n return JSON.parse(raw) as PackageJsonRecord\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to read package manifest at ${packageJsonPath}: ${message}`)\n }\n}\n\nfunction readPropertyName(property: ts.ObjectLiteralElementLike): string | null {\n if (!('name' in property) || !property.name) return null\n return ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)\n ? property.name.text\n : null\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n if (\n ts.isAsExpression(expression)\n || ts.isTypeAssertionExpression(expression)\n || ts.isParenthesizedExpression(expression)\n || ts.isSatisfiesExpression(expression)\n ) {\n return unwrapExpression(expression.expression)\n }\n return expression\n}\n\nfunction findMetadataLiteral(source: string, indexPath: string): ts.ObjectLiteralExpression | null {\n const sourceFile = ts.createSourceFile(indexPath, source, ts.ScriptTarget.Latest, true)\n for (const statement of sourceFile.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (\n !ts.isIdentifier(declaration.name)\n || declaration.name.text !== 'metadata'\n || !declaration.initializer\n ) continue\n const initializer = unwrapExpression(declaration.initializer)\n if (ts.isObjectLiteralExpression(initializer)) return initializer\n }\n }\n return null\n}\n\nfunction parseModuleInfo(indexPath: string, validateRequires = false): {\n title?: string\n description?: string\n ejectable?: boolean\n locator?: string\n requires: string[]\n} {\n if (!fs.existsSync(indexPath)) return { requires: [] }\n\n const source = fs.readFileSync(indexPath, 'utf8')\n const metadata = findMetadataLiteral(source, indexPath)\n const result: { title?: string; description?: string; ejectable?: boolean; locator?: string; requires: string[] } = {\n requires: [],\n }\n if (!metadata) return result\n\n for (const property of metadata.properties) {\n const propertyName = readPropertyName(property)\n if (!ts.isPropertyAssignment(property)) {\n if (validateRequires && propertyName === 'requires') {\n throw new Error(`Module descriptor at ${indexPath} must declare \"requires\" as a static string array.`)\n }\n continue\n }\n const initializer = unwrapExpression(property.initializer)\n\n if ((propertyName === 'title' || propertyName === 'description' || propertyName === 'locator') && ts.isStringLiteralLike(initializer)) {\n result[propertyName] = initializer.text\n continue\n }\n\n if (propertyName === 'ejectable') {\n if (initializer.kind === ts.SyntaxKind.TrueKeyword) result.ejectable = true\n if (initializer.kind === ts.SyntaxKind.FalseKeyword) result.ejectable = false\n continue\n }\n\n if (propertyName !== 'requires') continue\n if (!ts.isArrayLiteralExpression(initializer)) {\n if (validateRequires) {\n throw new Error(`Module descriptor at ${indexPath} must declare \"requires\" as a static string array.`)\n }\n continue\n }\n if (initializer.elements.some((element) => !ts.isStringLiteralLike(element))) {\n if (validateRequires) {\n throw new Error(`Module descriptor at ${indexPath} must contain only string module ids in \"requires\".`)\n }\n continue\n }\n result.requires = initializer.elements.map((element) => (element as ts.StringLiteralLike).text)\n }\n\n return result\n}\n\nexport function discoverModulesInPackage(packageRoot: string): DiscoveredModule[] {\n const srcModulesDir = path.join(packageRoot, 'src', 'modules')\n const distModulesDir = path.join(packageRoot, 'dist', 'modules')\n\n const enumerationDir = fs.existsSync(srcModulesDir)\n ? srcModulesDir\n : fs.existsSync(distModulesDir)\n ? distModulesDir\n : null\n\n if (!enumerationDir) return []\n\n const modules: DiscoveredModule[] = []\n\n for (const entry of fs.readdirSync(enumerationDir, { withFileTypes: true })) {\n if (!entry.isDirectory() || shouldSkipEntryName(entry.name) || !MODULE_ID_PATTERN.test(entry.name)) continue\n\n const moduleId = entry.name\n const srcIndexPath = path.join(packageRoot, 'src', 'modules', moduleId, 'index.ts')\n const distIndexPath = path.join(packageRoot, 'dist', 'modules', moduleId, 'index.js')\n const indexPath = fs.existsSync(srcIndexPath) ? srcIndexPath : distIndexPath\n\n const info = parseModuleInfo(indexPath)\n modules.push({ moduleId, ejectable: info.ejectable ?? false })\n }\n\n return modules\n}\n\nfunction resolveRelativeImportTarget(sourceFile: string, importPath: string): string | null {\n if (!importPath.startsWith('.')) return null\n\n const basePath = path.resolve(path.dirname(sourceFile), importPath)\n const candidates = [basePath]\n\n for (const ext of SOURCE_FILE_EXTENSIONS) {\n candidates.push(`${basePath}${ext}`)\n candidates.push(path.join(basePath, `index${ext}`))\n }\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n return candidate\n }\n }\n\n return null\n}\n\nfunction collectSourceFiles(dir: string): string[] {\n const files: string[] = []\n const entries = fs.readdirSync(dir, { withFileTypes: true })\n\n for (const entry of entries) {\n if (shouldSkipEntryName(entry.name)) continue\n\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n files.push(...collectSourceFiles(fullPath))\n continue\n }\n\n const ext = path.extname(entry.name)\n if (!SOURCE_FILE_EXTENSIONS.includes(ext)) continue\n files.push(fullPath)\n }\n\n return files\n}\n\nfunction collectBoundaryViolations(moduleDir: string): string[] {\n const modulesRoot = path.resolve(moduleDir, '..')\n const modulePrefix = `${moduleDir}${path.sep}`\n const modulesPrefix = `${modulesRoot}${path.sep}`\n const files = collectSourceFiles(moduleDir)\n const violations = new Set<string>()\n\n for (const filePath of files) {\n const content = fs.readFileSync(filePath, 'utf8')\n const matches = [\n ...content.matchAll(/\\bfrom\\s*['\"]([^'\"]+)['\"]/g),\n ...content.matchAll(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g),\n ]\n\n for (const match of matches) {\n const specifier = match[1]\n if (!specifier) continue\n const resolvedTarget = resolveRelativeImportTarget(filePath, specifier)\n if (!resolvedTarget) continue\n if (resolvedTarget.startsWith(modulePrefix)) continue\n if (resolvedTarget.startsWith(modulesPrefix)) continue\n\n const relativeSource = path.relative(moduleDir, filePath).split(path.sep).join('/')\n const relativeTarget = path.relative(path.dirname(filePath), resolvedTarget).split(path.sep).join('/')\n violations.add(`${relativeSource} -> ${relativeTarget}`)\n }\n }\n\n return Array.from(violations).sort((left, right) => left.localeCompare(right))\n}\n\nfunction findResolvedPackageRoot(\n resolvedPath: string,\n): string | null {\n let currentPath = fs.statSync(resolvedPath).isDirectory()\n ? resolvedPath\n : path.dirname(resolvedPath)\n\n while (currentPath !== path.dirname(currentPath)) {\n const packageJsonPath = path.join(currentPath, 'package.json')\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = readPackageJson(packageJsonPath)\n if (typeof packageJson.name === 'string' && normalizeModuleLocator(`npm:${packageJson.name}`) === `npm:${packageJson.name}`) {\n return currentPath\n }\n }\n currentPath = path.dirname(currentPath)\n }\n\n return null\n}\n\nexport function resolveInstalledPackageRootWithRequire(packageName: string, appDir: string): string | null {\n const specifiers = [`${packageName}/package.json`, packageName]\n\n for (const specifier of specifiers) {\n try {\n const resolvedPath = requireFromCli.resolve(specifier, {\n paths: [appDir],\n })\n const packageRoot =\n specifier === packageName\n ? findResolvedPackageRoot(resolvedPath)\n : path.dirname(resolvedPath)\n\n if (packageRoot) {\n return packageRoot\n }\n } catch {\n continue\n }\n }\n\n return null\n}\n\nexport function parsePackageNameFromSpec(packageSpec: string): string | null {\n const trimmed = packageSpec.trim()\n if (!trimmed) return null\n\n if (trimmed.startsWith('@')) {\n const slashIndex = trimmed.indexOf('/')\n if (slashIndex < 0) return null\n const versionSeparator = trimmed.indexOf('@', slashIndex + 1)\n return versionSeparator < 0 ? trimmed : trimmed.slice(0, versionSeparator)\n }\n\n const versionSeparator = trimmed.indexOf('@')\n return versionSeparator < 0 ? trimmed : trimmed.slice(0, versionSeparator)\n}\n\nexport function resolveInstalledPackageRoot(\n resolver: PackageResolver,\n packageName: string,\n): string {\n const resolvedWithRequire = resolveInstalledPackageRootWithRequire(packageName, resolver.getAppDir())\n if (resolvedWithRequire) {\n return resolvedWithRequire\n }\n\n const fallback = resolver.getPackageRoot(packageName)\n if (fs.existsSync(path.join(fallback, 'package.json'))) {\n return fallback\n }\n\n // In monorepo mode, getPackageRoot resolves to packages/<name> (workspace convention),\n // but externally installed packages land in root node_modules \u2014 check there too.\n const nodeModulesFallback = path.join(resolver.getRootDir(), 'node_modules', packageName)\n if (fs.existsSync(path.join(nodeModulesFallback, 'package.json'))) {\n return nodeModulesFallback\n }\n\n throw new Error(`Package \"${packageName}\" is not installed in ${resolver.getAppDir()}.`)\n}\n\nfunction resolveEsmExportTarget(value: unknown, substitution?: string): string | null | undefined {\n if (typeof value === 'string') {\n const target = substitution === undefined ? value : value.replaceAll('*', substitution)\n if (!target.startsWith('./') || target.slice(2).split('/').some((segment) => ['..', '.', 'node_modules'].includes(segment))) return undefined\n return target\n }\n if (value === null) return null\n if (Array.isArray(value)) {\n for (const candidate of value) {\n const target = resolveEsmExportTarget(candidate, substitution)\n if (target !== undefined && target !== null) return target\n }\n return null\n }\n if (value && typeof value === 'object') {\n for (const [condition, candidate] of Object.entries(value)) {\n if (!['import', 'node', 'node-addons', 'module-sync', 'default'].includes(condition)) continue\n const target = resolveEsmExportTarget(candidate, substitution)\n if (target !== undefined) return target\n }\n }\n return undefined\n}\n\nfunction resolvePackageSubpathExport(exports: unknown, subpath: string): string | null | undefined {\n if (!exports || typeof exports !== 'object' || Array.isArray(exports)) return undefined\n const entries = Object.entries(exports)\n const direct = entries.find(([key]) => key === subpath)\n if (direct) return resolveEsmExportTarget(direct[1])\n const patterns = entries.filter(([key]) => key.startsWith('./') && key.includes('*'))\n .sort(([left], [right]) => right.indexOf('*') - left.indexOf('*') || right.length - left.length)\n for (const [pattern, target] of patterns) {\n const wildcard = pattern.indexOf('*')\n const prefix = pattern.slice(0, wildcard)\n const suffix = pattern.slice(wildcard + 1)\n if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) {\n return resolveEsmExportTarget(target, subpath.slice(prefix.length, subpath.length - suffix.length))\n }\n }\n return undefined\n}\n\nfunction isGeneratedModuleImport(relativePath: string, moduleFiles: readonly string[], readSource?: (relativePath: string) => string): boolean {\n const segments = relativePath.split('/')\n if (segments.some((segment) => segment === '__tests__' || segment === '__mocks__')) return false\n const fileName = segments[segments.length - 1]\n if (fileName.endsWith('.d.ts') || /\\.(?:test|spec)\\.[jt]sx?$/.test(fileName)) return false\n const basename = stripModuleCodeExtension(fileName)\n if (segments.length === 1) {\n return new Set(['index', 'acl', 'setup', 'cli', 'runtime', 'ce', 'search', 'events', 'notifications', 'notifications.client', 'notifications.handlers', 'translations', 'encryption', 'ai-tools', 'ai-agents', 'di', 'integration', 'vector']).has(basename)\n }\n if (['widgets/components', 'widgets/injection-table', 'api/interceptors', 'data/extensions', 'data/fields'].includes(stripModuleCodeExtension(relativePath))) return true\n if (/^commands\\//.test(relativePath)) {\n return MODULE_CODE_EXTENSIONS.some((extension) => fileName.endsWith(extension)) && !['index', 'shared', 'factory'].includes(basename)\n }\n const scanConfigs: readonly ScanConfig[] = Object.values(SCAN_CONFIGS)\n for (const config of scanConfigs) {\n if (!relativePath.startsWith(`${config.folder}/`)) continue\n const relativeSegments = relativePath.slice(config.folder.length + 1).split('/')\n if (relativeSegments.slice(0, -1).some((segment) => config.skipDirs?.(segment))) continue\n if (!config.include(fileName)) continue\n if (config.folder === 'frontend' || config.folder === 'backend') return readSource ? sourceHasDefaultExport(relativePath, readSource(relativePath)) : false\n if (config.folder === 'api') return readSource ? sourceExportedHttpMethods(readSource(relativePath)).length > 0 : false\n return true\n }\n if (/^(?:frontend|backend)\\//.test(relativePath) && (basename === 'meta' || basename.endsWith('.meta'))) {\n const folder = segments.slice(0, -1).join('/')\n const pageConfig = segments[0] === 'frontend' ? SCAN_CONFIGS.frontendPages : SCAN_CONFIGS.backendPages\n const candidates = moduleFiles.filter((file) => file.startsWith(`${folder}/`) && !file.slice(folder.length + 1).includes('/') && pageConfig.include(path.posix.basename(file)))\n return candidates.some((candidate) => (basename === 'meta' || basename === `${stripModuleCodeExtension(path.posix.basename(candidate))}.meta`) && Boolean(readSource && sourceHasDefaultExport(candidate, readSource(candidate))))\n }\n if (/^(?:data|db)\\/(?:entities\\.override|entities|schema)\\.[jt]sx?$/.test(relativePath)) {\n const selected = ['data', 'db'].flatMap((folder) => ['entities.override', 'entities', 'schema'].flatMap((candidate) => MODULE_CODE_EXTENSIONS.map((extension) => `${folder}/${candidate}${extension}`)))\n .find((candidate) => moduleFiles.includes(candidate))\n return relativePath === selected\n }\n return /^i18n\\/[^/]+\\.json$/.test(relativePath)\n}\n\nexport function isModulePackageExportError(error: unknown): boolean {\n return error instanceof Error && 'code' in error && error.code === 'MODULE_PACKAGE_EXPORT_UNAVAILABLE'\n}\n\nexport function assertModulePackageExports(\n manifest: { exports?: unknown },\n binding: string,\n moduleId: string,\n packageFiles: readonly string[],\n readSource?: (relativePath: string) => string,\n): void {\n const normalizedFiles = new Set(packageFiles.map((file) => file.replaceAll('\\\\', '/').replace(/^\\.\\//, '')))\n const sourcePrefix = `src/modules/${moduleId}/`\n const distPrefix = `dist/modules/${moduleId}/`\n const sourceFiles = [...normalizedFiles].filter((file) => file.startsWith(sourcePrefix)).map((file) => file.slice(sourcePrefix.length))\n const distFiles = [...normalizedFiles].filter((file) => file.startsWith(distPrefix)).map((file) => file.slice(distPrefix.length))\n const moduleFiles = sourceFiles.length > 0 ? sourceFiles : distFiles\n const cachedSources = new Map<string, string>()\n const readModuleSource = readSource ? (relativePath: string): string => {\n let source = cachedSources.get(relativePath)\n if (source === undefined) {\n source = readSource(`${sourceFiles.length > 0 ? sourcePrefix : distPrefix}${relativePath}`)\n cachedSources.set(relativePath, source)\n }\n return source\n } : undefined\n const generatedCandidates = sourceFiles.length > 0 ? sourceFiles : distFiles\n for (const sourcePath of generatedCandidates) {\n if (!isGeneratedModuleImport(sourcePath, moduleFiles, readModuleSource)) continue\n const isCode = /\\.[jt]sx?$/.test(sourcePath)\n const runtimePath = sourceFiles.length > 0 && isCode\n ? distFiles.find((file) => /\\.jsx?$/.test(file) && stripModuleCodeExtension(file) === stripModuleCodeExtension(sourcePath))\n : sourcePath\n const publicPath = `./modules/${moduleId}/${stripModuleCodeExtension(sourcePath)}`\n if (!runtimePath) {\n throw Object.assign(new Error(`Package binding \"${binding}\" cannot import \"${binding}/${publicPath.slice(2)}\": the package artifact is missing the compiled runtime entrypoint. Build the package before enabling it.`), { code: 'MODULE_PACKAGE_EXPORT_UNAVAILABLE' })\n }\n if (manifest.exports === undefined) continue\n const target = resolvePackageSubpathExport(manifest.exports, publicPath)\n if (!target || !normalizedFiles.has(target.slice(2))) {\n throw Object.assign(new Error(`Package binding \"${binding}\" cannot import \"${binding}/${publicPath.slice(2)}\": the package exports do not provide an available ESM target. Keep the current provider and use a package exposing this module subpath before enabling it.`), { code: 'MODULE_PACKAGE_EXPORT_UNAVAILABLE' })\n }\n }\n}\n\nexport function readOfficialModulePackageFromRoot(\n packageRoot: string,\n expectedPackageName?: string,\n targetModuleId?: string,\n): ValidatedOfficialModulePackage {\n const packageJsonPath = path.join(packageRoot, 'package.json')\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`Package manifest not found at ${packageJsonPath}.`)\n }\n\n const packageJson = readPackageJson(packageJsonPath)\n const packageName = packageJson.name\n if (!packageName) {\n throw new Error(`Package manifest at ${packageJsonPath} is missing the \"name\" field.`)\n }\n\n if (typeof packageName !== 'string' || normalizeModuleLocator(`npm:${packageName}`) !== `npm:${packageName}`) {\n throw new Error(`Package manifest at ${packageJsonPath} has an invalid \"name\" field.`)\n }\n\n if (expectedPackageName && packageName !== expectedPackageName) {\n throw new Error(`Resolved package \"${packageName}\" does not match requested package \"${expectedPackageName}\".`)\n }\n\n const discoveredModules = discoverModulesInPackage(packageRoot)\n\n if (discoveredModules.length === 0) {\n throw new Error(`Package \"${packageName}\" has no modules in src/modules/ or dist/modules/.`)\n }\n\n let selected: DiscoveredModule\n\n if (targetModuleId) {\n const found = discoveredModules.find((m) => m.moduleId === targetModuleId)\n if (!found) {\n const available = discoveredModules.map((m) => m.moduleId).join(', ')\n throw new Error(\n `Package \"${packageName}\" does not contain module \"${targetModuleId}\". Available: ${available}`,\n )\n }\n selected = found\n } else {\n if (discoveredModules.length > 1) {\n const available = discoveredModules.map((m) => m.moduleId).join(', ')\n throw new Error(\n `Package \"${packageName}\" contains multiple modules (${available}). Specify one with --module <moduleId>.`,\n )\n }\n selected = discoveredModules[0]\n }\n\n const { moduleId } = selected\n const sourceModuleDir = path.join(packageRoot, 'src', 'modules', moduleId)\n const distModuleDir = path.join(packageRoot, 'dist', 'modules', moduleId)\n\n if (!fs.existsSync(sourceModuleDir)) {\n throw new Error(`Package \"${packageName}\" is missing src/modules/${moduleId}.`)\n }\n\n if (!fs.existsSync(distModuleDir)) {\n throw new Error(`Package \"${packageName}\" is missing dist/modules/${moduleId}.`)\n }\n\n const info = parseModuleInfo(path.join(sourceModuleDir, 'index.ts'), true)\n\n return {\n packageName,\n packageRoot,\n packageJson,\n metadata: { moduleId, ejectable: selected.ejectable },\n moduleInfo: { title: info.title, description: info.description, requires: info.requires, ...(info.locator ? { locator: info.locator } : {}) },\n sourceModuleDir,\n distModuleDir,\n }\n}\n\nfunction listPackageFiles(packageRoot: string, directory = packageRoot): string[] {\n return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {\n if (shouldSkipEntryName(entry.name)) return []\n const fullPath = path.join(directory, entry.name)\n return entry.isDirectory() ? listPackageFiles(packageRoot, fullPath) : [path.relative(packageRoot, fullPath)]\n })\n}\n\nexport function resolveInstalledOfficialModulePackage(\n resolver: PackageResolver,\n packageName: string,\n moduleId?: string,\n): ValidatedOfficialModulePackage {\n const packageRoot = resolveInstalledPackageRoot(resolver, packageName)\n const modulePackage = readOfficialModulePackageFromRoot(packageRoot, undefined, moduleId)\n const packageFiles = listPackageFiles(packageRoot)\n assertModulePackageExports(modulePackage.packageJson, packageName, modulePackage.metadata.moduleId, packageFiles, (relativePath) => fs.readFileSync(path.join(packageRoot, relativePath), 'utf8'))\n if (modulePackage.packageName !== packageName) {\n const resolvedBindingRoot = resolveInstalledPackageRootWithRequire(packageName, resolver.getAppDir())\n const installedBindingPath = path.join('node_modules', packageName)\n const matchesBindingPath = path.normalize(packageRoot).endsWith(`${path.sep}${installedBindingPath}`)\n if (!matchesBindingPath && (!resolvedBindingRoot || fs.realpathSync(resolvedBindingRoot) !== fs.realpathSync(packageRoot))) {\n throw new Error(`Resolved package \"${modulePackage.packageName}\" does not match requested package binding \"${packageName}\".`)\n }\n }\n return modulePackage\n}\n\nexport function validateEjectBoundaries(modulePackage: ValidatedOfficialModulePackage): void {\n const violations = collectBoundaryViolations(modulePackage.sourceModuleDir)\n if (violations.length === 0) {\n return\n }\n\n throw new Error(\n [\n `Package \"${modulePackage.packageName}\" cannot be added with --eject because it imports files outside src/modules/${modulePackage.metadata.moduleId}.`,\n 'Invalid imports:',\n ...violations.map((violation) => `- ${violation}`),\n ].join('\\n'),\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AAEf,SAAS,8BAA8B;AACvC,SAAS,wBAAwB,iCAAiC;AAClE,SAAS,wBAAwB,cAAc,gCAAiD;AAqChG,MAAM,yBAAyB,CAAC,OAAO,QAAQ,OAAO,QAAQ,QAAQ,MAAM;AAC5E,MAAM,YAAY,oBAAI,IAAI,CAAC,aAAa,aAAa,cAAc,CAAC;AACpE,MAAM,oBAAoB;AAC1B,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