local-plugin-loader-hooks.ts 863 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Node module customization hook for project-local plugin package names.
  3. *
  4. * @module @deepseek-ai/dsh-scripts/local-plugin-loader-hooks
  5. */
  6. import type { ResolveHookContext, ResolveFnOutput } from 'node:module'
  7. interface HookData {
  8. mappings: Readonly<Record<string, string>>
  9. }
  10. let mappings: Readonly<Record<string, string>> = {}
  11. /** Receive the package-name to source-URL map from the launcher thread. */
  12. export function initialize(data: HookData): void {
  13. mappings = { ...data.mappings }
  14. }
  15. /** Resolve exact local workspace package names to their TypeScript entry source. */
  16. export async function resolve(
  17. specifier: string,
  18. context: ResolveHookContext,
  19. nextResolve: (specifier: string, context: ResolveHookContext) => Promise<ResolveFnOutput>,
  20. ): Promise<ResolveFnOutput> {
  21. return nextResolve(mappings[specifier] ?? specifier, context)
  22. }