1
+ import 'dart:convert' ;
1
2
import 'dart:io' as io;
2
3
3
4
import 'package:analyzer/file_system/file_system.dart' ;
@@ -20,7 +21,12 @@ File createAnalysisOptions(String content) {
20
21
return PhysicalResourceProvider .INSTANCE .getFile (ioFile.path);
21
22
}
22
23
23
- Future <String > createTempProject (String projectName, String tempDirPath) async {
24
+ Future <String > createTempProject ({
25
+ required String tempDirPath,
26
+ required String projectName,
27
+ String ? packageConfig,
28
+ String ? workspaceRef,
29
+ }) async {
24
30
final projectPath = join (tempDirPath, projectName);
25
31
26
32
final dir = io.Directory (projectPath);
@@ -36,6 +42,28 @@ custom_lint:
36
42
- from_package
37
43
''' );
38
44
45
+ final projectDartToolPath = join (projectPath, '.dart_tool' );
46
+ await io.Directory (projectDartToolPath).create (recursive: true );
47
+
48
+ if (packageConfig != null ) {
49
+ final String packageConfigPath;
50
+ if (workspaceRef != null ) {
51
+ final workspaceDartToolPath = join (tempDirPath, '.dart_tool' );
52
+ await io.Directory (workspaceDartToolPath).create (recursive: true );
53
+ packageConfigPath = join (workspaceDartToolPath, 'package_config.json' );
54
+ } else {
55
+ packageConfigPath = join (projectDartToolPath, 'package_config.json' );
56
+ }
57
+ await io.File (packageConfigPath).writeAsString (packageConfig);
58
+ }
59
+
60
+ if (workspaceRef != null ) {
61
+ final pubPath = join (projectDartToolPath, 'pub' );
62
+ await io.Directory (pubPath).create (recursive: true );
63
+ final workspaceRefPath = join (pubPath, 'workspace_ref.json' );
64
+ await io.File (workspaceRefPath).writeAsString (workspaceRef);
65
+ }
66
+
39
67
return dir.path;
40
68
}
41
69
@@ -205,7 +233,10 @@ custom_lint:
205
233
include: package:$testPackageName /analysis_options.yaml
206
234
''' );
207
235
208
- final tempProjectDir = await createTempProject (dir.path, testPackageName);
236
+ final tempProjectDir = await createTempProject (
237
+ tempDirPath: dir.path,
238
+ projectName: testPackageName,
239
+ );
209
240
210
241
final patchedPackageConfig = patchPackageConfig (
211
242
packageConfig,
@@ -225,7 +256,10 @@ include: package:$testPackageName/$notExistingFileName
225
256
''' );
226
257
final dir = createDir ();
227
258
228
- final tempProjectDir = await createTempProject (dir.path, testPackageName);
259
+ final tempProjectDir = await createTempProject (
260
+ tempDirPath: dir.path,
261
+ projectName: testPackageName,
262
+ );
229
263
final patchedPackageConfig = patchPackageConfig (
230
264
packageConfig,
231
265
testPackageName,
@@ -243,7 +277,10 @@ include: package:$testPackageName/$notExistingFileName
243
277
include: package:$notExistingPackage /analysis_options.yaml
244
278
''' );
245
279
final dir = createDir ();
246
- final tempProjectDir = await createTempProject (dir.path, testPackageName);
280
+ final tempProjectDir = await createTempProject (
281
+ tempDirPath: dir.path,
282
+ projectName: testPackageName,
283
+ );
247
284
248
285
final patchedPackageConfig = patchPackageConfig (
249
286
packageConfig,
@@ -300,5 +337,33 @@ foo:
300
337
expect (configs, CustomLintConfigs .empty);
301
338
});
302
339
});
340
+
341
+ group ('package config' , () {
342
+ test ('single package' , () async {
343
+ final dir = createDir ();
344
+ final projectPath = await createTempProject (
345
+ tempDirPath: dir.path,
346
+ projectName: testPackageName,
347
+ packageConfig: jsonEncode (PackageConfig .toJson (packageConfig)),
348
+ );
349
+ final projectDir = io.Directory (projectPath);
350
+ final parsed = parsePackageConfig (projectDir);
351
+ expect (parsed, isNotNull);
352
+ });
353
+
354
+ test ('workspace' , () async {
355
+ final dir = createDir ();
356
+ print (dir);
357
+ final projectPath = await createTempProject (
358
+ tempDirPath: dir.path,
359
+ projectName: testPackageName,
360
+ packageConfig: jsonEncode (PackageConfig .toJson (packageConfig)),
361
+ workspaceRef: jsonEncode ({'workspaceRoot' : '../../..' }),
362
+ );
363
+ final projectDir = io.Directory (projectPath);
364
+ final parsed = parsePackageConfig (projectDir);
365
+ expect (parsed, isNotNull);
366
+ });
367
+ });
303
368
});
304
369
}
0 commit comments