55import 'package:path/path.dart' as p;
66import 'package:test/test.dart' ;
77
8+ import 'package:pub/src/io.dart' ;
9+
810import '../descriptor.dart' as d;
911import '../serve/utils.dart' ;
1012import '../test_pub.dart' ;
@@ -115,7 +117,7 @@ main() {
115117 await pubGet (output: contains ("Precompiled foo." ));
116118
117119 await d.dir (appPath, [
118- d.dir (".pub/deps/debug/foo/lib" ,
120+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
119121 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
120122 ]).validate ();
121123 });
@@ -146,7 +148,7 @@ main() {
146148 await pubGet (output: contains ("Precompiled foo." ));
147149
148150 await d.dir (appPath, [
149- d.dir (".pub/deps/debug/foo/lib" ,
151+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
150152 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
151153 ]).validate ();
152154 });
@@ -164,7 +166,7 @@ main() {
164166
165167 await pubGet (output: isNot (contains ("Precompiled foo." )));
166168
167- await d.dir (appPath, [d.nothing (".pub/deps" )]).validate ();
169+ await d.dir (appPath, [d.nothing (".dart_tool/ pub/deps" )]).validate ();
168170 });
169171
170172 test ("recaches when the dependency is updated" , () async {
@@ -199,7 +201,7 @@ main() {
199201 await pubGet (output: contains ("Precompiled foo." ));
200202
201203 await d.dir (appPath, [
202- d.dir (".pub/deps/debug/foo/lib" ,
204+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
203205 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
204206 ]).validate ();
205207
@@ -209,7 +211,7 @@ main() {
209211 await pubGet (output: contains ("Precompiled foo." ));
210212
211213 await d.dir (appPath, [
212- d.dir (".pub/deps/debug/foo/lib" ,
214+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
213215 [d.file ("foo.dart" , "final message = 'See ya!';" )])
214216 ]).validate ();
215217 });
@@ -286,7 +288,7 @@ main() {
286288 await pubGet (output: contains ("Precompiled foo." ));
287289
288290 await d.dir (appPath, [
289- d.dir (".pub/deps/debug/foo/lib" ,
291+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
290292 [d.file ("foo.dart" , "final mode = 'debug';" )])
291293 ]).validate ();
292294 });
@@ -320,7 +322,7 @@ main() {
320322 await pubGet (output: contains ("Precompiled foo." ));
321323
322324 await d.dir (appPath, [
323- d.dir (".pub/deps/debug/foo/lib" ,
325+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
324326 [d.file ("foo.dart" , "final message = 'Modified!';" )])
325327 ]).create ();
326328
@@ -357,6 +359,51 @@ main() {
357359
358360 await pubGet (output: contains ("Precompiled foo." ));
359361
362+ // Manually reset the cache to its original state to prove that the
363+ // transformer won't be run again on it.
364+ await d.dir (appPath, [
365+ d.dir (".dart_tool/pub/deps/debug/foo/lib" ,
366+ [d.file ("foo.dart" , "final message = 'Hello!';" )])
367+ ]).create ();
368+
369+ var pub = await pubRun (args: ["bin/script" ]);
370+ expect (pub.stdout, emits ("Hello!" ));
371+ await pub.shouldExit ();
372+ });
373+
374+ test ("reads cached packages from the old-style cache" , () async {
375+ await servePackages ((builder) {
376+ builder.serveRealPackage ('barback' );
377+
378+ builder.serve ("foo" , "1.2.3" , deps: {
379+ 'barback' : 'any'
380+ }, pubspec: {
381+ 'transformers' : ['foo' ]
382+ }, contents: [
383+ d.dir ("lib" , [
384+ d.file ("transformer.dart" , replaceTransformer ("Hello" , "Goodbye" )),
385+ d.file ("foo.dart" , "final message = 'Hello!';" )
386+ ])
387+ ]);
388+ });
389+
390+ await d.dir (appPath, [
391+ d.appPubspec ({"foo" : "1.2.3" }),
392+ d.dir ('bin' , [
393+ d.file ('script.dart' , """
394+ import 'package:foo/foo.dart';
395+
396+ void main() => print(message);""" )
397+ ])
398+ ]).create ();
399+
400+ await pubGet (output: contains ("Precompiled foo." ));
401+
402+ // Move the directory to the old location to simulate it being created by an
403+ // older version of pub.
404+ renameDir (p.join (d.sandbox, appPath, '.dart_tool' , 'pub' ),
405+ p.join (d.sandbox, appPath, '.pub' ));
406+
360407 // Manually reset the cache to its original state to prove that the
361408 // transformer won't be run again on it.
362409 await d.dir (appPath, [
@@ -369,6 +416,42 @@ main() {
369416 await pub.shouldExit ();
370417 });
371418
419+ test ("migrates the old-style cache" , () async {
420+ await servePackages ((builder) {
421+ builder.serveRealPackage ('barback' );
422+
423+ builder.serve ("foo" , "1.2.3" , deps: {
424+ 'barback' : 'any'
425+ }, pubspec: {
426+ 'transformers' : ['foo' ]
427+ }, contents: [
428+ d.dir ("lib" , [
429+ d.file ("transformer.dart" , replaceTransformer ("Hello" , "Goodbye" )),
430+ d.file ("foo.dart" , "final message = 'Hello!';" )
431+ ])
432+ ]);
433+ });
434+
435+ await d.dir (appPath, [
436+ d.appPubspec ({"foo" : "1.2.3" }),
437+
438+ // Simulate an old-style cache directory.
439+ d.dir (".pub" , [d.file ("junk" , "junk" )])
440+ ]).create ();
441+
442+ await pubGet (output: contains ("Precompiled foo." ));
443+
444+ await d.dir (appPath, [d.nothing (".pub" )]).validate ();
445+
446+ await d.dir (appPath, [
447+ d.dir (".dart_tool/pub" , [
448+ d.file ("junk" , "junk" ),
449+ d.dir ("deps/debug/foo/lib" ,
450+ [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
451+ ])
452+ ]).validate ();
453+ });
454+
372455 // Regression test for issue 21087.
373456 test ("hasInput works for static packages" , () async {
374457 await servePackages ((builder) {
@@ -436,7 +519,7 @@ main() {
436519 await pubGet (output: contains ("Precompiled foo." ));
437520
438521 await d.dir (appPath, [
439- d.dir (".pub/deps/debug/foo/lib" ,
522+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
440523 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
441524 ]).validate ();
442525
@@ -445,7 +528,8 @@ main() {
445528
446529 await pubGet (output: isNot (contains ("Precompiled foo." )));
447530
448- await d.dir (appPath, [d.nothing (".pub/deps/debug/foo" )]).validate ();
531+ await d
532+ .dir (appPath, [d.nothing (".dart_tool/pub/deps/debug/foo" )]).validate ();
449533 });
450534
451535 // Regression test for https://github.com/dart-lang/pub/issues/1586.
@@ -472,7 +556,8 @@ main() {
472556 await pubGet (output: contains ("Precompiled foo" ));
473557
474558 await d.dir (appPath, [
475- d.file (".pub/deps/debug/foo/lib/inputs.txt" , contains ('hello.dart.copy' ))
559+ d.file (".dart_tool/pub/deps/debug/foo/lib/inputs.txt" ,
560+ contains ('hello.dart.copy' ))
476561 ]).validate ();
477562
478563 await pubServe ();
@@ -508,7 +593,7 @@ foo|lib/list_transformer.dart.copy""");
508593 await pubGet (
509594 args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
510595
511- await d.nothing (p.join (appPath, ".pub" )).validate ();
596+ await d.nothing (p.join (appPath, ".dart_tool/ pub" )).validate ();
512597 });
513598
514599 test ("deletes the cache when the dependency is updated" , () async {
@@ -543,7 +628,7 @@ foo|lib/list_transformer.dart.copy""");
543628 await pubGet (output: contains ("Precompiled foo." ));
544629
545630 await d.dir (appPath, [
546- d.dir (".pub/deps/debug/foo/lib" ,
631+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
547632 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
548633 ]).validate ();
549634
@@ -553,7 +638,9 @@ foo|lib/list_transformer.dart.copy""");
553638 await pubGet (
554639 args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
555640
556- await d.nothing (p.join (appPath, ".pub/deps/debug/foo" )).validate ();
641+ await d
642+ .nothing (p.join (appPath, ".dart_tool/pub/deps/debug/foo" ))
643+ .validate ();
557644 });
558645
559646 test (
@@ -580,7 +667,7 @@ foo|lib/list_transformer.dart.copy""");
580667 await pubGet (output: contains ("Precompiled foo." ));
581668
582669 await d.dir (appPath, [
583- d.dir (".pub/deps/debug/foo/lib" ,
670+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
584671 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
585672 ]).validate ();
586673
@@ -589,7 +676,7 @@ foo|lib/list_transformer.dart.copy""");
589676 args: ["--no-precompile" ], output: isNot (contains ("Precompiled" )));
590677
591678 await d.dir (appPath, [
592- d.dir (".pub/deps/debug/foo/lib" ,
679+ d.dir (".dart_tool/ pub/deps/debug/foo/lib" ,
593680 [d.file ("foo.dart" , "final message = 'Goodbye!';" )])
594681 ]).validate ();
595682 });
0 commit comments