MCPcopy Create free account
hub / github.com/angular/angular / resolveTsGoPath

Function resolveTsGoPath

ngp-vscode-ng-language-service/client/src/extension.ts:271–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

269 );
270
271async function resolveTsGoPath(): Promise<string | null> {
272 if (process.env.TSGO_BINARY_PATH) {
273 return process.env.TSGO_BINARY_PATH;
274 }
275
276 const extensionRoot = path.resolve(__dirname, '../..');
277 const workspaceRoot = path.resolve(__dirname, '../../..');
278 const ext = process.platform === 'win32' ? '.exe' : '';
279 const tsPlatformName = `@typescript/typescript-${process.platform}-${process.arch}`;
280 const previewPlatformName = `@typescript/native-preview-${process.platform}-${process.arch}`;
281
282 try {
283 const req = createRequire(path.join(extensionRoot, 'package.json'));
284 const previewPkg = req.resolve('@typescript/native-preview/package.json');
285 const previewReq = createRequire(previewPkg);
286 const platformTargets = [
287 {pkg: tsPlatformName, bin: `tsc${ext}`},
288 {pkg: previewPlatformName, bin: `tsgo${ext}`},
289 ];
290 for (const target of platformTargets) {
291 try {
292 const platPkg = previewReq.resolve(`${target.pkg}/package.json`);
293 const exe = path.join(path.dirname(platPkg), 'lib', target.bin);
294 if (await pathExists(exe)) {
295 return exe;
296 }
297 } catch {}
298 }
299 } catch {}
300
301 const localCandidates = [extensionRoot, workspaceRoot].flatMap((root) => [
302 path.join(root, 'node_modules', tsPlatformName, 'lib', `tsc${ext}`),
303 path.join(root, 'node_modules', '@typescript', 'native-preview', 'lib', 'tsc.js'),
304 path.join(root, 'node_modules', '@typescript', 'native-preview', 'bin', 'tsc'),
305 path.join(root, 'node_modules', previewPlatformName, 'lib', `tsgo${ext}`),
306 path.join(root, 'node_modules', '@typescript', 'native-preview', 'bin', 'tsgo'),
307 path.join(root, 'node_modules', '@typescript', 'native-preview', 'bin', 'tsgo.js'),
308 ]);
309
310 const localResults = await Promise.all(
311 localCandidates.map(async (candidate) => ((await pathExists(candidate)) ? candidate : null)),
312 );
313 const foundLocal = localResults.find((c): c is string => c !== null);
314 if (foundLocal) {
315 return foundLocal;
316 }
317
318 const tsGoExtension = vscode.extensions.getExtension('typescriptteam.native-preview');
319 if (tsGoExtension) {
320 const extensionPath = tsGoExtension.extensionPath;
321 const candidates = [
322 path.join(extensionPath, 'lib', 'tsc'),
323 path.join(extensionPath, 'lib', 'tsc.exe'),
324 path.join(extensionPath, 'bin', 'tsc'),
325 path.join(extensionPath, 'bin', 'tsc.exe'),
326 path.join(extensionPath, 'tsc'),
327 path.join(extensionPath, 'tsc.exe'),
328 path.join(extensionPath, 'bin', 'tsgo'),

Callers 1

activateFunction · 0.70

Calls 7

mapMethod · 0.80
pathExistsFunction · 0.70
resolveMethod · 0.65
joinMethod · 0.65
dirnameMethod · 0.65
allMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected