MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / rewriteWorkspaceSpecifiers

Function rewriteWorkspaceSpecifiers

packages/node-sdk/scripts/build-dts.mjs:77–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75}
76
77async 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
128async function findDtsFiles(dir) {
129 const entries = await readdir(dir, { withFileTypes: true });

Callers 1

build-dts.mjsFile · 0.85

Calls 7

findDtsFilesFunction · 0.85
packageDirForFileFunction · 0.85
relativeSpecifierFunction · 0.85
resolveSpecifierFunction · 0.85
resolveMethod · 0.65
readFileFunction · 0.50
writeFileFunction · 0.50

Tested by

no test coverage detected