()
| 75 | } |
| 76 | |
| 77 | async function rewriteWorkspaceSpecifiers() { |
| 78 | const files = await findDtsFiles(dtsRoot); |
| 79 | const emittedFiles = new Set(files.map((file) => path.resolve(file))); |
| 80 | |
| 81 | await Promise.all( |
| 82 | files.map(async (file) => { |
| 83 | const packageDir = packageDirForFile(file); |
| 84 | if (packageDir === undefined) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | const text = await readFile(file, 'utf8'); |
| 89 | const providerClientSpecifier = relativeSpecifier(file, providerClientShimPath); |
| 90 | const providerClientText = text |
| 91 | .replaceAll( |
| 92 | "import Anthropic from '@anthropic-ai/sdk';", |
| 93 | `import { Anthropic } from '${providerClientSpecifier}';`, |
| 94 | ) |
| 95 | .replaceAll( |
| 96 | "import OpenAI from 'openai';", |
| 97 | `import { OpenAI } from '${providerClientSpecifier}';`, |
| 98 | ) |
| 99 | .replaceAll( |
| 100 | "import type OpenAI from 'openai';", |
| 101 | `import type { OpenAI } from '${providerClientSpecifier}';`, |
| 102 | ) |
| 103 | .replaceAll( |
| 104 | "import { GoogleGenAI as GenAIClient } from '@google/genai';", |
| 105 | `import { GoogleGenAI as GenAIClient } from '${providerClientSpecifier}';`, |
| 106 | ); |
| 107 | const updated = providerClientText.replaceAll( |
| 108 | /(["'])(#\/[^"']+|@moonshot-ai\/(?:agent-core|kaos|kimi-code-oauth|kosong)(?:\/[^"']+)?)\1/g, |
| 109 | (_match, quote, specifier) => { |
| 110 | const resolved = resolveSpecifier({ |
| 111 | currentFile: file, |
| 112 | emittedFiles, |
| 113 | packageDir, |
| 114 | specifier, |
| 115 | }); |
| 116 | |
| 117 | return `${quote}${relativeSpecifier(file, resolved)}${quote}`; |
| 118 | }, |
| 119 | ); |
| 120 | |
| 121 | if (updated !== text) { |
| 122 | await writeFile(file, updated); |
| 123 | } |
| 124 | }), |
| 125 | ); |
| 126 | } |
| 127 | |
| 128 | async function findDtsFiles(dir) { |
| 129 | const entries = await readdir(dir, { withFileTypes: true }); |
no test coverage detected