Skip to content

Commit e1105ac

Browse files
Add offline mode
1 parent a5ac4ac commit e1105ac

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

webdev/lib/src/command/configuration.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const nullSafetyAuto = 'auto';
3737
const disableDdsFlag = 'disable-dds';
3838
const enableExperimentOption = 'enable-experiment';
3939
const canaryFeaturesFlag = 'canary';
40+
const offlineFlag = 'offline';
4041

4142
ReloadConfiguration _parseReloadConfiguration(ArgResults argResults) {
4243
var auto = argResults.options.contains(autoOption)
@@ -107,6 +108,7 @@ class Configuration {
107108
final String? _nullSafety;
108109
final List<String>? _experiments;
109110
final bool? _canaryFeatures;
111+
final bool? _offline;
110112

111113
Configuration({
112114
bool? autoRun,
@@ -133,6 +135,7 @@ class Configuration {
133135
String? nullSafety,
134136
List<String>? experiments,
135137
bool? canaryFeatures,
138+
bool? offline,
136139
}) : _autoRun = autoRun,
137140
_chromeDebugPort = chromeDebugPort,
138141
_debugExtension = debugExtension,
@@ -154,7 +157,8 @@ class Configuration {
154157
_verbose = verbose,
155158
_nullSafety = nullSafety,
156159
_experiments = experiments,
157-
_canaryFeatures = canaryFeatures {
160+
_canaryFeatures = canaryFeatures,
161+
_offline = offline {
158162
_validateConfiguration();
159163
}
160164

@@ -229,7 +233,8 @@ class Configuration {
229233
verbose: other._verbose ?? _verbose,
230234
nullSafety: other._nullSafety ?? _nullSafety,
231235
experiments: other._experiments ?? _experiments,
232-
canaryFeatures: other._canaryFeatures ?? _canaryFeatures);
236+
canaryFeatures: other._canaryFeatures ?? _canaryFeatures,
237+
offline: other._offline ?? _offline);
233238

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

285290
bool get canaryFeatures => _canaryFeatures ?? false;
286291

292+
bool get offline => _offline ?? false;
293+
287294
/// Returns a new configuration with values updated from the parsed args.
288295
static Configuration fromArgs(ArgResults? argResults,
289296
{Configuration? defaultConfiguration}) {
@@ -408,6 +415,10 @@ class Configuration {
408415
? argResults[canaryFeaturesFlag] as bool?
409416
: defaultConfiguration.canaryFeatures;
410417

418+
var offline = argResults.options.contains(offlineFlag)
419+
? argResults[offlineFlag] as bool?
420+
: defaultConfiguration.verbose;
421+
411422
return Configuration(
412423
autoRun: defaultConfiguration.autoRun,
413424
chromeDebugPort: chromeDebugPort,
@@ -433,6 +444,7 @@ class Configuration {
433444
nullSafety: nullSafety,
434445
experiments: experiments,
435446
canaryFeatures: canaryFeatures,
447+
offline: offline,
436448
);
437449
}
438450
}

webdev/lib/src/command/shared.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ void addSharedArgs(ArgParser argParser,
7474
abbr: 'v',
7575
defaultsTo: false,
7676
negatable: false,
77-
help: 'Enables verbose logging.');
77+
help: 'Enables verbose logging.')
78+
..addFlag(offlineFlag,
79+
defaultsTo: false,
80+
negatable: false,
81+
help: 'Disable feching from pub.dev.');
7882
}
7983

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

105109
Future<void> validatePubspecLock(Configuration configuration) async {
106-
final pubspecLock = await PubspecLock.read();
110+
final pubspecLock = await PubspecLock.read(
111+
offline: configuration.offline
112+
);
107113
await checkPubspecLock(pubspecLock,
108114
requireBuildWebCompilers: configuration.requireBuildWebCompilers);
109115
}

webdev/lib/src/pubspec.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ class PubspecLock {
6868

6969
PubspecLock(this._packages);
7070

71-
static Future<PubspecLock> read() async {
72-
await _runPubDeps();
71+
static Future<PubspecLock> read({
72+
bool offline = false
73+
}) async {
74+
if (!offline) {
75+
await _runPubDeps();
76+
}
7377
var dir = p.absolute(p.current);
7478
while (true) {
7579
final candidate = p.join(

0 commit comments

Comments
 (0)