MCPcopy Create free account
hub / github.com/Snapchat/Valdi / computeTsCompilerOptions

Function computeTsCompilerOptions

npm_modules/cli/src/commands/projectsync.ts:231–292  ·  view source on GitHub ↗
(
  existingTsConfigFile: any,
  tsConfigDir: string,
  matchedTargets: readonly TsConfigMatchedTarget[],
  baseTsFiles: readonly string[],
)

Source from the content-addressed store, hash-verified

229}
230
231function computeTsCompilerOptions(
232 existingTsConfigFile: any,
233 tsConfigDir: string,
234 matchedTargets: readonly TsConfigMatchedTarget[],
235 baseTsFiles: readonly string[],
236): unknown {
237 let compilerOptions: any;
238 if (existingTsConfigFile) {
239 compilerOptions = { ...existingTsConfigFile };
240 } else {
241 compilerOptions = {};
242 }
243
244 compilerOptions.paths = {};
245 const rootDirs: string[] = [];
246 let valdiCoreTarget: TargetDescription | undefined;
247 for (const matchedTarget of matchedTargets) {
248 const targetRootDirs = matchedTarget.target.paths.map(p => relativePathTo(tsConfigDir, path.dirname(p)));
249
250 for (const targetRootDir of targetRootDirs) {
251 if (!rootDirs.includes(targetRootDir)) {
252 rootDirs.push(targetRootDir);
253 }
254 }
255
256 const selfName = matchedTarget.target.label.name ?? '';
257 const selfInclude = `${selfName}/*`;
258
259 const selfImportPaths = matchedTarget.target.paths.map(p => `${relativePathTo(tsConfigDir, p)}/*`);
260
261 compilerOptions.paths[selfInclude] = selfImportPaths;
262
263 for (const dependency of matchedTarget.dependencies) {
264 if (!dependency.label.name || compilerOptions.paths[dependency.label.name]) {
265 // Already present
266 continue;
267 }
268
269 if (dependency.label.name === 'valdi_core') {
270 valdiCoreTarget = dependency;
271 }
272
273 const importPaths = dependency.paths.map(p => `${relativePathTo(tsConfigDir, p)}/*`);
274
275 const key = `${dependency.label.name}/*`;
276 compilerOptions.paths[key] = importPaths;
277 }
278 }
279
280 if (valdiCoreTarget) {
281 // Add tslib dep
282 compilerOptions.paths['tslib'] = valdiCoreTarget.paths.map(p =>
283 relativePathTo(tsConfigDir, path.join(p, 'src/tslib')),
284 );
285 }
286
287 compilerOptions.types = baseTsFiles.map(p => relativePathTo(tsConfigDir, removeTsFileExtension(p)));
288

Callers 1

processTsConfigDirFunction · 0.85

Calls 5

relativePathToFunction · 0.90
removeTsFileExtensionFunction · 0.85
mapMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected