Skip to content

Commit d57e957

Browse files
committed
add cleanup step
1 parent dfe97a5 commit d57e957

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

bricks/dart_frog_prod_server/hooks/lib/dart_frog_prod_server_hooks.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ export 'src/exit_overrides.dart';
77
export 'src/get_internal_path_dependencies.dart';
88
export 'src/get_pubspec_lock.dart';
99
export 'src/uses_workspace_resolution.dart';
10+
11+
/// A void callback function (e.g. `void Function()`).
12+
typedef VoidCallback = void Function();

bricks/dart_frog_prod_server/hooks/lib/src/copy_workspace_pubspec_lock.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import 'dart:io';
2+
import 'package:dart_frog_prod_server_hooks/dart_frog_prod_server_hooks.dart';
23
import 'package:mason/mason.dart';
34
import 'package:path/path.dart' as path;
45
import 'package:yaml/yaml.dart';
56

67
/// Copies the pubspec.lock from the workspace root into the project directory
78
/// in order to ensure the production build uses the exact same versions of all
89
/// dependencies.
9-
void copyWorkspacePubspecLock(
10+
VoidCallback copyWorkspacePubspecLock(
1011
HookContext context, {
1112
required String projectDirectory,
1213
required void Function(int exitCode) exit,
@@ -16,17 +17,22 @@ void copyWorkspacePubspecLock(
1617
context.logger.err(
1718
'Unable to determine workspace root for $projectDirectory',
1819
);
19-
return exit(1);
20+
exit(1);
21+
return () {};
2022
}
2123

2224
final pubspecLockFile = File(path.join(workspaceRoot.path, 'pubspec.lock'));
23-
if (!pubspecLockFile.existsSync()) return;
25+
if (!pubspecLockFile.existsSync()) return () {};
2426

2527
try {
2628
pubspecLockFile.copySync(path.join(projectDirectory, 'pubspec.lock'));
29+
return () {
30+
File(path.join(projectDirectory, 'pubspec.lock')).delete().ignore();
31+
};
2732
} on Exception catch (error) {
2833
context.logger.err('$error');
29-
return exit(1);
34+
exit(1);
35+
return () {};
3036
}
3137
}
3238

bricks/dart_frog_prod_server/hooks/lib/src/disable_workspace_resolution.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import 'dart:io';
2+
import 'package:dart_frog_prod_server_hooks/dart_frog_prod_server_hooks.dart';
23
import 'package:mason/mason.dart';
34
import 'package:path/path.dart' as path;
45
import 'package:yaml/yaml.dart';
56
import 'package:yaml_edit/yaml_edit.dart';
67

7-
/// A void callback function (e.g. `void Function()`).
8-
typedef VoidCallback = void Function();
9-
108
/// Opts out of dart workspaces until we can generate per package lockfiles.
119
/// https://github.com/dart-lang/pub/issues/4594
1210
VoidCallback disableWorkspaceResolution(

bricks/dart_frog_prod_server/hooks/pre_gen.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Future<void> preGen(
3030
);
3131

3232
VoidCallback? restoreWorkspaceResolution;
33+
VoidCallback? revertPubspecLock;
3334

3435
if (usesWorkspaces) {
3536
// Disable workspace resolution until we can generate per-package lockfiles.
@@ -41,7 +42,7 @@ Future<void> preGen(
4142
);
4243
// Copy the pubspec.lock from the workspace root to ensure the same versions
4344
// of dependencies are used in the production build.
44-
copyWorkspacePubspecLock(
45+
revertPubspecLock = copyWorkspacePubspecLock(
4546
context,
4647
projectDirectory: projectDirectory.path,
4748
exit: exit,
@@ -101,10 +102,6 @@ Future<void> preGen(
101102
onViolationEnd: () => exit(1),
102103
);
103104

104-
final customDockerFile = io.File(
105-
path.join(projectDirectory.path, 'Dockerfile'),
106-
);
107-
108105
final internalPathDependencies = await getInternalPathDependencies(
109106
projectDirectory,
110107
);
@@ -115,6 +112,11 @@ Future<void> preGen(
115112
copyPath: copyPath,
116113
);
117114

115+
revertPubspecLock?.call();
116+
117+
final customDockerFile = io.File(
118+
path.join(projectDirectory.path, 'Dockerfile'),
119+
);
118120
final addDockerfile = !customDockerFile.existsSync();
119121

120122
context.vars = {

0 commit comments

Comments
 (0)