Skip to content

Commit 385be65

Browse files
authored
refactor(dart_frog_prod_server): remove pubspec lock dependency (#1277)
1 parent 50b9dae commit 385be65

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ Future<List<String>> createExternalPackagesFolder({
2020

2121
final externalPathDependencies = pubspecLock.packages
2222
.map(
23-
(p) => p.iswitch(
24-
sdk: (_) => null,
25-
hosted: (_) => null,
26-
git: (_) => null,
27-
path: (d) {
28-
final isExternal = !pathResolver.isWithin('', d.path);
29-
if (!isExternal) return null;
23+
(dependency) {
24+
final pathDescription = dependency.pathDescription;
25+
if (pathDescription == null) {
26+
return null;
27+
}
3028

31-
return _ExternalPathDependency(
32-
name: p.package(),
33-
path: path.join(projectDirectory.path, d.path),
34-
);
35-
},
36-
),
29+
final isExternal = !pathResolver.isWithin('', pathDescription.path);
30+
if (!isExternal) return null;
31+
32+
return _ExternalPathDependency(
33+
name: dependency.name,
34+
path: path.join(projectDirectory.path, pathDescription.path),
35+
);
36+
},
3737
)
3838
.whereType<_ExternalPathDependency>()
3939
.toList();

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import 'package:path/path.dart' as path;
55

66
Future<List<String>> getInternalPathDependencies(io.Directory directory) async {
77
final pubspecLock = await getPubspecLock(directory.path);
8-
return pubspecLock.packages
9-
.map(
10-
(p) => p.iswitch(
11-
sdk: (_) => null,
12-
hosted: (_) => null,
13-
git: (_) => null,
14-
path: (d) => d.path,
15-
),
16-
)
17-
.whereType<String>()
18-
.where((dependencyPath) {
19-
return path.isWithin('', dependencyPath);
20-
}).toList();
8+
9+
final internalPathDependencies = pubspecLock.packages.where(
10+
(dependency) {
11+
final pathDescription = dependency.pathDescription;
12+
if (pathDescription == null) {
13+
return false;
14+
}
15+
16+
return path.isWithin('', pathDescription.path);
17+
},
18+
);
19+
20+
return internalPathDependencies
21+
.map((dependency) => dependency.pathDescription!.path)
22+
.toList();
2123
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:io';
22

3+
import 'package:dart_frog_prod_server_hooks/src/pubspec_lock/pubspec_lock.dart';
34
import 'package:path/path.dart' as path;
4-
import 'package:pubspec_lock/pubspec_lock.dart';
55

66
Future<PubspecLock> getPubspecLock(
77
String workingDirectory, {
@@ -15,5 +15,5 @@ Future<PubspecLock> getPubspecLock(
1515
);
1616

1717
final content = await pubspecLockFile.readAsString();
18-
return content.loadPubspecLockFromYaml();
18+
return PubspecLock.fromString(content);
1919
}

bricks/dart_frog_prod_server/hooks/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies:
1010
io: ^1.0.3
1111
mason: ^0.1.0-dev.39
1212
path: ^1.8.1
13-
pubspec_lock: ^3.0.2
1413
yaml: ^3.1.2
1514

1615
dev_dependencies:

bricks/dart_frog_prod_server/hooks/test/pubspec_locks.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ library pubspec_locks;
1010
/// directory and has a different package name than the directory name.
1111
/// * A direct main dependency that is hosted.
1212
/// * A direct dev main dependency that is hosted.
13+
/// * A direct overridden dependency from git.
1314
const fooPath = '''
1415
packages:
1516
args:
@@ -34,10 +35,10 @@ packages:
3435
relative: true
3536
source: path
3637
version: "0.0.0"
37-
mason:
38+
direct_main:
3839
dependency: "direct main"
3940
description:
40-
name: mason
41+
name: direct_main
4142
sha256: fdc9ea905e7c690fe39d2f9946b7aead86fd976f8edf97d2521a65d260bbf509
4243
url: "https://pub.dev"
4344
source: hosted
@@ -50,6 +51,15 @@ packages:
5051
url: "https://pub.dev"
5152
source: hosted
5253
version: "1.24.6"
54+
direct_overridden:
55+
dependency: "direct overridden"
56+
description:
57+
path: "packages/mason"
58+
ref: "72c306a8d8abf306b5d024f95aac29ba5fd96577"
59+
resolved-ref: "72c306a8d8abf306b5d024f95aac29ba5fd96577"
60+
url: "https://github.com/alestiago/mason"
61+
source: git
62+
version: "0.1.0-dev.52"
5363
sdks:
5464
dart: ">=3.0.0 <4.0.0"
5565
''';

0 commit comments

Comments
 (0)