@@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
44import 'package:pub_semver/pub_semver.dart' ;
55import 'package:pubspec_parse/pubspec_parse.dart' ;
66import 'package:args/args.dart' ;
7+ import 'package:path/path.dart' as p;
78
89Future <void > downloadWebAssets (List <String > arguments,
910 {bool encryption = false }) async {
@@ -46,6 +47,11 @@ Future<void> downloadWebAssets(List<String> arguments,
4647 exit (1 );
4748 }
4849
50+ if (Platform .environment.containsKey ('IS_IN_POWERSYNC_CI' )) {
51+ print ('IS_IN_POWERSYNC_CI env variable is set, copying from local build' );
52+ return _copyPrecompiled (Directory .current, wasmFileName);
53+ }
54+
4955 try {
5056 final httpClient = HttpClient ();
5157
@@ -177,3 +183,25 @@ Future<void> downloadFile(
177183 'Failed to download file: ${response .statusCode } ${response .reasonPhrase }' );
178184 }
179185}
186+
187+ Future <void > _copyPrecompiled (Directory project, String wasmFile) async {
188+ // Keep going up until we see the melos.yaml file indicating the workspace
189+ // root.
190+ var dir = project;
191+ while (! await File (p.join (dir.path, 'melos.yaml' )).exists ()) {
192+ print ('Looking for melos workspace in $dir ' );
193+ final parent = dir.parent;
194+ if (p.equals (parent.path, dir.path)) {
195+ throw 'Melos workspace not found' ;
196+ }
197+
198+ dir = parent;
199+ }
200+
201+ // In the CI, an earlier step will have put these files into the prepared
202+ // sqlite3_wasm_build package.
203+ final destination = p.join (project.path, 'web' );
204+ final wasmSource = p.join (dir.path, 'packages' , 'sqlite3_wasm_build' , 'dist' );
205+ print ('Copying $wasmFile from $wasmSource to $destination ' );
206+ await File (p.join (wasmSource, wasmFile)).copy (p.join (destination, wasmFile));
207+ }
0 commit comments