MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / extractFlutterSdkPathFromPackagesFile

Function extractFlutterSdkPathFromPackagesFile

src/shared/utils/fs.ts:279–322  ·  view source on GitHub ↗
(projectFolder: string)

Source from the content-addressed store, hash-verified

277}
278
279export function extractFlutterSdkPathFromPackagesFile(projectFolder: string): string | undefined {
280 if (!fs.existsSync(projectFolder))
281 return undefined;
282
283 const packageMap = PackageMap.loadForProject(nullLogger, projectFolder);
284 const flutterRootPath = packageMap.flutterRootPath;
285 let packagePath = flutterRootPath ?? packageMap.getPackagePath("flutter");
286
287 if (!packagePath)
288 return undefined;
289
290 // Set windows slashes to / while manipulating.
291 if (isWin) {
292 packagePath = packagePath.replace(/\\/g, "/");
293 }
294
295 // Make sure ends with a slash.
296 if (!packagePath.endsWith("/"))
297 packagePath = packagePath + "/";
298
299 // Trim suffix we don't need.
300 const pathSuffix = "/packages/flutter/lib/";
301 if (!flutterRootPath && packagePath.endsWith(pathSuffix)) {
302 packagePath = packagePath.substr(0, packagePath.length - pathSuffix.length);
303 }
304
305 // Make sure ends with a slash.
306 if (!packagePath.endsWith("/"))
307 packagePath = packagePath + "/";
308
309 // Append bin if required.
310 if (!packagePath.endsWith("/bin/")) {
311 packagePath = packagePath + "bin/";
312 }
313
314 // Set windows paths back.
315 if (isWin) {
316 packagePath = packagePath.replace(/\//g, "\\");
317 if (packagePath.startsWith("\\"))
318 packagePath = packagePath.substring(1);
319 }
320
321 return fs.existsSync(packagePath) ? packagePath : undefined;
322}
323
324
325export function resolveTildePaths<T extends string | undefined>(p: T): string | (undefined extends T ? undefined : never) {

Callers 2

fs.test.tsFile · 0.90
scanWorkspaceMethod · 0.90

Calls 2

loadForProjectMethod · 0.80
getPackagePathMethod · 0.45

Tested by

no test coverage detected