-
Notifications
You must be signed in to change notification settings - Fork 86
Added method findPackageConfigFilePath to find the package_config.json file #2587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
ccb5514
720b74b
adc54a6
2d7800d
3d837f5
4361530
0bb1a44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||
// for details. All rights reserved. Use of this source code is governed by a | ||||
// BSD-style license that can be found in the LICENSE file. | ||||
|
||||
import 'dart:io'; | ||||
import 'dart:typed_data'; | ||||
|
||||
import 'package:dwds/src/debugging/dart_runtime_debugger.dart'; | ||||
|
@@ -20,7 +21,7 @@ abstract class LoadStrategy { | |||
LoadStrategy( | ||||
this._assetReader, { | ||||
String? packageConfigPath, | ||||
}) : _packageConfigPath = packageConfigPath; | ||||
}) : _packageConfigPath = packageConfigPath ?? _findPackageConfigFilePath(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should instead provide this as an optional named parameter (optional named to avoid a breaking change) to each of the
Flutter already calculates this, so we'd end up calculating it again. Flutter may also choose to configure the locations differently in tests for example. I'd then imagine webdev calculating this separately and passing it to the provider (I guess in its case it'd use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about this approach and it makes sense to update each of the providers to allow passing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My original thought was maybe webdev should calculate it separately and then pass it to DWDS, but maybe it doesn't matter. I do like the idea of our default being a bit more robust for the case of monorepos, so I think your plan makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a similar method in Webdev to find the package config path and pass to DWDS and I also kept the default method in the load strategy class in case the value is not being passed. |
||||
|
||||
/// The ID for this strategy. | ||||
/// | ||||
|
@@ -83,6 +84,30 @@ abstract class LoadStrategy { | |||
'package_config.json', | ||||
); | ||||
|
||||
/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool` | ||||
/// directory, searching recursively from the current directory hierarchy. | ||||
/// If `_packageConfigPath` is already set, it returns the cached value immediately. | ||||
static String? _findPackageConfigFilePath() { | ||||
var candidateDir = Directory(DartUri.currentDirectory).absolute; | ||||
|
||||
while (true) { | ||||
final candidatePackageConfigFile = | ||||
File(p.join(candidateDir.path, '.dart_tool', 'package_config.json')); | ||||
|
||||
if (candidatePackageConfigFile.existsSync()) { | ||||
return candidatePackageConfigFile.path; | ||||
} | ||||
|
||||
final parentDir = candidateDir.parent; | ||||
if (parentDir.path == candidateDir.path) { | ||||
// We've reached the root directory | ||||
return null; | ||||
} | ||||
|
||||
candidateDir = parentDir; | ||||
} | ||||
} | ||||
|
||||
/// Returns the bootstrap required for this [LoadStrategy]. | ||||
/// | ||||
/// The bootstrap is appended to the end of the entry point module. | ||||
|
Uh oh!
There was an error while loading. Please reload this page.