Skip to content

Commit

Permalink
Add offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Oct 7, 2024
1 parent a5ac4ac commit e1105ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
16 changes: 14 additions & 2 deletions webdev/lib/src/command/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const nullSafetyAuto = 'auto';
const disableDdsFlag = 'disable-dds';
const enableExperimentOption = 'enable-experiment';
const canaryFeaturesFlag = 'canary';
const offlineFlag = 'offline';

ReloadConfiguration _parseReloadConfiguration(ArgResults argResults) {
var auto = argResults.options.contains(autoOption)
Expand Down Expand Up @@ -107,6 +108,7 @@ class Configuration {
final String? _nullSafety;
final List<String>? _experiments;
final bool? _canaryFeatures;
final bool? _offline;

Configuration({
bool? autoRun,
Expand All @@ -133,6 +135,7 @@ class Configuration {
String? nullSafety,
List<String>? experiments,
bool? canaryFeatures,
bool? offline,
}) : _autoRun = autoRun,
_chromeDebugPort = chromeDebugPort,
_debugExtension = debugExtension,
Expand All @@ -154,7 +157,8 @@ class Configuration {
_verbose = verbose,
_nullSafety = nullSafety,
_experiments = experiments,
_canaryFeatures = canaryFeatures {
_canaryFeatures = canaryFeatures,
_offline = offline {
_validateConfiguration();
}

Expand Down Expand Up @@ -229,7 +233,8 @@ class Configuration {
verbose: other._verbose ?? _verbose,
nullSafety: other._nullSafety ?? _nullSafety,
experiments: other._experiments ?? _experiments,
canaryFeatures: other._canaryFeatures ?? _canaryFeatures);
canaryFeatures: other._canaryFeatures ?? _canaryFeatures,
offline: other._offline ?? _offline);

factory Configuration.noInjectedClientDefaults() =>
Configuration(autoRun: false, debug: false, debugExtension: false);
Expand Down Expand Up @@ -284,6 +289,8 @@ class Configuration {

bool get canaryFeatures => _canaryFeatures ?? false;

bool get offline => _offline ?? false;

/// Returns a new configuration with values updated from the parsed args.
static Configuration fromArgs(ArgResults? argResults,
{Configuration? defaultConfiguration}) {
Expand Down Expand Up @@ -408,6 +415,10 @@ class Configuration {
? argResults[canaryFeaturesFlag] as bool?
: defaultConfiguration.canaryFeatures;

var offline = argResults.options.contains(offlineFlag)
? argResults[offlineFlag] as bool?
: defaultConfiguration.verbose;

return Configuration(
autoRun: defaultConfiguration.autoRun,
chromeDebugPort: chromeDebugPort,
Expand All @@ -433,6 +444,7 @@ class Configuration {
nullSafety: nullSafety,
experiments: experiments,
canaryFeatures: canaryFeatures,
offline: offline,
);
}
}
Expand Down
10 changes: 8 additions & 2 deletions webdev/lib/src/command/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ void addSharedArgs(ArgParser argParser,
abbr: 'v',
defaultsTo: false,
negatable: false,
help: 'Enables verbose logging.');
help: 'Enables verbose logging.')
..addFlag(offlineFlag,
defaultsTo: false,
negatable: false,
help: 'Disable feching from pub.dev.');
}

/// Parses the provided [Configuration] to return a list of
Expand Down Expand Up @@ -103,7 +107,9 @@ List<String> buildRunnerArgs(Configuration configuration) {
}

Future<void> validatePubspecLock(Configuration configuration) async {
final pubspecLock = await PubspecLock.read();
final pubspecLock = await PubspecLock.read(
offline: configuration.offline
);
await checkPubspecLock(pubspecLock,
requireBuildWebCompilers: configuration.requireBuildWebCompilers);
}
Expand Down
8 changes: 6 additions & 2 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ class PubspecLock {

PubspecLock(this._packages);

static Future<PubspecLock> read() async {
await _runPubDeps();
static Future<PubspecLock> read({
bool offline = false
}) async {
if (!offline) {
await _runPubDeps();
}
var dir = p.absolute(p.current);
while (true) {
final candidate = p.join(
Expand Down

0 comments on commit e1105ac

Please sign in to comment.