| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 import "dart:convert" show JSON; | 7 import "dart:convert" show JSON; |
| 8 import "package:path/path.dart" as p; | 8 import "package:path/path.dart" as p; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 | 10 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // value of these, you can only change what value to expect. | 289 // value of these, you can only change what value to expect. |
| 290 // For values not included here (commented out), the result is not tested | 290 // For values not included here (commented out), the result is not tested |
| 291 // unless a value (maybe null) is provided. | 291 // unless a value (maybe null) is provided. |
| 292 fixPaths(expect); | 292 fixPaths(expect); |
| 293 | 293 |
| 294 expect = { | 294 expect = { |
| 295 "pconf": null, | 295 "pconf": null, |
| 296 "proot": null, | 296 "proot": null, |
| 297 "iconf": null, | 297 "iconf": null, |
| 298 "iroot": null, | 298 "iroot": null, |
| 299 // "foo": null, | 299 "foo": null, |
| 300 "foo/": null, | 300 "foo/": null, |
| 301 "foo/bar": null, | 301 "foo/bar": null, |
| 302 "foo.x": "qux", | 302 "foo.x": "qux", |
| 303 "bar/bar": null, | 303 "bar/bar": null, |
| 304 "relative": "relative/path", | 304 "relative": "relative/path", |
| 305 "nonpkg": "http://example.org/file" | 305 "nonpkg": "http://example.org/file" |
| 306 }..addAll(expect ?? const {}); | 306 }..addAll(expect ?? const {}); |
| 307 | 307 |
| 308 // Add http files to the http server. | 308 // Add http files to the http server. |
| 309 if (http.isNotEmpty) { | 309 if (http.isNotEmpty) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // No parameters, no .packages files or packages/ dir. | 346 // No parameters, no .packages files or packages/ dir. |
| 347 // A "file:" source realizes there is no configuration and can't resolve | 347 // A "file:" source realizes there is no configuration and can't resolve |
| 348 // any packages, but a "http:" source assumes a "packages/" directory. | 348 // any packages, but a "http:" source assumes a "packages/" directory. |
| 349 addScheme("no resolution", | 349 addScheme("no resolution", |
| 350 "%$scheme/", | 350 "%$scheme/", |
| 351 files: {}, | 351 files: {}, |
| 352 expect: (scheme == "file") ? { | 352 expect: (scheme == "file") ? { |
| 353 "foo.x": null | 353 "foo.x": null |
| 354 } : { | 354 } : { |
| 355 "iroot": "%http/packages/", | 355 "iroot": "%http/packages/", |
| 356 "foo": "%http/packages/foo", |
| 356 "foo/": "%http/packages/foo/", | 357 "foo/": "%http/packages/foo/", |
| 357 "foo/bar": "%http/packages/foo/bar", | 358 "foo/bar": "%http/packages/foo/bar", |
| 358 "foo.x": null, | 359 "foo.x": null, |
| 359 "bar/bar": "%http/packages/bar/bar", | 360 "bar/bar": "%http/packages/bar/bar", |
| 360 }); | 361 }); |
| 361 } | 362 } |
| 362 | 363 |
| 363 { | 364 { |
| 364 // No parameters, no .packages files, | 365 // No parameters, no .packages files, |
| 365 // packages/ dir exists and is detected. | 366 // packages/ dir exists and is detected. |
| 366 var files = {"packages": fooPackage}; | 367 var files = {"packages": fooPackage}; |
| 367 addScheme("implicit packages dir","%$scheme/", | 368 addScheme("implicit packages dir","%$scheme/", |
| 368 files: files, | 369 files: files, |
| 369 expect: { | 370 expect: { |
| 370 "iroot": "%$scheme/packages/", | 371 "iroot": "%$scheme/packages/", |
| 372 "foo": "%$scheme/packages/foo", |
| 371 "foo/": "%$scheme/packages/foo/", | 373 "foo/": "%$scheme/packages/foo/", |
| 372 "foo/bar": "%$scheme/packages/foo/bar", | 374 "foo/bar": "%$scheme/packages/foo/bar", |
| 373 "bar/bar": "%$scheme/packages/bar/bar", | 375 "bar/bar": "%$scheme/packages/bar/bar", |
| 374 }); | 376 }); |
| 375 } | 377 } |
| 376 | 378 |
| 377 { | 379 { |
| 378 // No parameters, no .packages files in current dir, but one in parent, | 380 // No parameters, no .packages files in current dir, but one in parent, |
| 379 // packages/ dir exists and is used. | 381 // packages/ dir exists and is used. |
| 380 // | 382 // |
| 381 // Should not detect the .packages file in parent directory. | 383 // Should not detect the .packages file in parent directory. |
| 382 // That file is empty, so if it is used, the system cannot resolve "foo". | 384 // That file is empty, so if it is used, the system cannot resolve "foo". |
| 383 var files = {"sub": {"packages": fooPackage}, | 385 var files = {"sub": {"packages": fooPackage}, |
| 384 ".packages": ""}; | 386 ".packages": ""}; |
| 385 addScheme("implicit packages dir overrides parent .packages", | 387 addScheme("implicit packages dir overrides parent .packages", |
| 386 "%$scheme/sub/", | 388 "%$scheme/sub/", |
| 387 files: files, | 389 files: files, |
| 388 expect: { | 390 expect: { |
| 389 "iroot": "%$scheme/sub/packages/", | 391 "iroot": "%$scheme/sub/packages/", |
| 392 "foo": "%$scheme/sub/packages/foo", |
| 390 "foo/": "%$scheme/sub/packages/foo/", | 393 "foo/": "%$scheme/sub/packages/foo/", |
| 391 "foo/bar": "%$scheme/sub/packages/foo/bar", | 394 "foo/bar": "%$scheme/sub/packages/foo/bar", |
| 392 // "foo.x": "qux", // Blocked by issue http://dartbug.com/26482 | 395 // "foo.x": "qux", // Blocked by issue http://dartbug.com/26482 |
| 393 "bar/bar": "%$scheme/sub/packages/bar/bar", | 396 "bar/bar": "%$scheme/sub/packages/bar/bar", |
| 394 }); | 397 }); |
| 395 } | 398 } |
| 396 | 399 |
| 397 { | 400 { |
| 398 // No parameters, a .packages file next to entry is found and used. | 401 // No parameters, a .packages file next to entry is found and used. |
| 399 // A packages/ directory is ignored. | 402 // A packages/ directory is ignored. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 417 ".packages": "foo:pkgs/foo/", | 420 ".packages": "foo:pkgs/foo/", |
| 418 "pkgs": fooPackage}; | 421 "pkgs": fooPackage}; |
| 419 addScheme(".packages file in parent", "%$scheme/sub/", | 422 addScheme(".packages file in parent", "%$scheme/sub/", |
| 420 files: files, | 423 files: files, |
| 421 expect: (scheme == "file") ? { | 424 expect: (scheme == "file") ? { |
| 422 "iconf": "%file/.packages", | 425 "iconf": "%file/.packages", |
| 423 "foo/": "%file/pkgs/foo/", | 426 "foo/": "%file/pkgs/foo/", |
| 424 "foo/bar": "%file/pkgs/foo/bar", | 427 "foo/bar": "%file/pkgs/foo/bar", |
| 425 } : { | 428 } : { |
| 426 "iroot": "%http/sub/packages/", | 429 "iroot": "%http/sub/packages/", |
| 430 "foo": "%http/sub/packages/foo", |
| 427 "foo/": "%http/sub/packages/foo/", | 431 "foo/": "%http/sub/packages/foo/", |
| 428 "foo/bar": "%http/sub/packages/foo/bar", | 432 "foo/bar": "%http/sub/packages/foo/bar", |
| 429 "foo.x": null, | 433 "foo.x": null, |
| 430 "bar/bar": "%http/sub/packages/bar/bar", | 434 "bar/bar": "%http/sub/packages/bar/bar", |
| 431 }); | 435 }); |
| 432 } | 436 } |
| 433 | 437 |
| 434 { | 438 { |
| 435 // Specified package root that doesn't exist. | 439 // Specified package root that doesn't exist. |
| 436 // Ignores existing .packages file and packages/ dir. | 440 // Ignores existing .packages file and packages/ dir. |
| 437 addScheme("explicit root not there", | 441 addScheme("explicit root not there", |
| 438 "%$scheme/", | 442 "%$scheme/", |
| 439 files: {"packages": fooPackage, | 443 files: {"packages": fooPackage, |
| 440 ".packages": "foo:%$scheme/packages/"}, | 444 ".packages": "foo:%$scheme/packages/"}, |
| 441 root: "%$scheme/notthere/", | 445 root: "%$scheme/notthere/", |
| 442 expect: { | 446 expect: { |
| 443 "proot": "%$scheme/notthere/", | 447 "proot": "%$scheme/notthere/", |
| 444 "iroot": "%$scheme/notthere/", | 448 "iroot": "%$scheme/notthere/", |
| 449 "foo": "%$scheme/notthere/foo", |
| 445 "foo/": "%$scheme/notthere/foo/", | 450 "foo/": "%$scheme/notthere/foo/", |
| 446 "foo/bar": "%$scheme/notthere/foo/bar", | 451 "foo/bar": "%$scheme/notthere/foo/bar", |
| 447 "foo.x": null, | 452 "foo.x": null, |
| 448 "bar/bar": "%$scheme/notthere/bar/bar", | 453 "bar/bar": "%$scheme/notthere/bar/bar", |
| 449 }); | 454 }); |
| 450 } | 455 } |
| 451 | 456 |
| 452 { | 457 { |
| 453 // Specified package config that doesn't exist. | 458 // Specified package config that doesn't exist. |
| 454 // Ignores existing .packages file and packages/ dir. | 459 // Ignores existing .packages file and packages/ dir. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 471 // The Platform.packageRoot and Isolate.packageRoot has a trailing slash. | 476 // The Platform.packageRoot and Isolate.packageRoot has a trailing slash. |
| 472 var files = {".packages": "foo:packages/foo/", | 477 var files = {".packages": "foo:packages/foo/", |
| 473 "packages": {}, | 478 "packages": {}, |
| 474 "pkgs": fooPackage}; | 479 "pkgs": fooPackage}; |
| 475 addScheme("explicit package root, no slash", "%$scheme/", | 480 addScheme("explicit package root, no slash", "%$scheme/", |
| 476 files: files, | 481 files: files, |
| 477 root: "%$scheme/pkgs", | 482 root: "%$scheme/pkgs", |
| 478 expect: { | 483 expect: { |
| 479 "proot": "%$scheme/pkgs/", | 484 "proot": "%$scheme/pkgs/", |
| 480 "iroot": "%$scheme/pkgs/", | 485 "iroot": "%$scheme/pkgs/", |
| 486 "foo": "%$scheme/pkgs/foo", |
| 481 "foo/": "%$scheme/pkgs/foo/", | 487 "foo/": "%$scheme/pkgs/foo/", |
| 482 "foo/bar": "%$scheme/pkgs/foo/bar", | 488 "foo/bar": "%$scheme/pkgs/foo/bar", |
| 483 "bar/bar": "%$scheme/pkgs/bar/bar", | 489 "bar/bar": "%$scheme/pkgs/bar/bar", |
| 484 }); | 490 }); |
| 485 } | 491 } |
| 486 | 492 |
| 487 { | 493 { |
| 488 // Specified package root with trailing slash. | 494 // Specified package root with trailing slash. |
| 489 var files = {".packages": "foo:packages/foo/", | 495 var files = {".packages": "foo:packages/foo/", |
| 490 "packages": {}, | 496 "packages": {}, |
| 491 "pkgs": fooPackage}; | 497 "pkgs": fooPackage}; |
| 492 addScheme("explicit package root, slash", "%$scheme/", | 498 addScheme("explicit package root, slash", "%$scheme/", |
| 493 files: files, | 499 files: files, |
| 494 root: "%$scheme/pkgs", | 500 root: "%$scheme/pkgs", |
| 495 expect: { | 501 expect: { |
| 496 "proot": "%$scheme/pkgs/", | 502 "proot": "%$scheme/pkgs/", |
| 497 "iroot": "%$scheme/pkgs/", | 503 "iroot": "%$scheme/pkgs/", |
| 504 "foo": "%$scheme/pkgs/foo", |
| 498 "foo/": "%$scheme/pkgs/foo/", | 505 "foo/": "%$scheme/pkgs/foo/", |
| 499 "foo/bar": "%$scheme/pkgs/foo/bar", | 506 "foo/bar": "%$scheme/pkgs/foo/bar", |
| 500 "bar/bar": "%$scheme/pkgs/bar/bar", | 507 "bar/bar": "%$scheme/pkgs/bar/bar", |
| 501 }); | 508 }); |
| 502 } | 509 } |
| 503 | 510 |
| 504 { | 511 { |
| 505 // Specified package config. | 512 // Specified package config. |
| 506 var files = {".packages": "foo:packages/foo/", | 513 var files = {".packages": "foo:packages/foo/", |
| 507 "packages": {}, | 514 "packages": {}, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 var files = {}; | 555 var files = {}; |
| 549 var https = {}; | 556 var https = {}; |
| 550 (entryScheme == "file" ? files : https)["main"] = testMain; | 557 (entryScheme == "file" ? files : https)["main"] = testMain; |
| 551 (pkgScheme == "file" ? files : https)["pkgs"] = fooPackage; | 558 (pkgScheme == "file" ? files : https)["pkgs"] = fooPackage; |
| 552 add("$pkgScheme pkg/$entryScheme main", "%$entryScheme/", | 559 add("$pkgScheme pkg/$entryScheme main", "%$entryScheme/", |
| 553 file: files, http: https, | 560 file: files, http: https, |
| 554 root: "%$pkgScheme/pkgs/", | 561 root: "%$pkgScheme/pkgs/", |
| 555 expect: { | 562 expect: { |
| 556 "proot": "%$pkgScheme/pkgs/", | 563 "proot": "%$pkgScheme/pkgs/", |
| 557 "iroot": "%$pkgScheme/pkgs/", | 564 "iroot": "%$pkgScheme/pkgs/", |
| 565 "foo": "%$pkgScheme/pkgs/foo", |
| 558 "foo/": "%$pkgScheme/pkgs/foo/", | 566 "foo/": "%$pkgScheme/pkgs/foo/", |
| 559 "foo/bar": "%$pkgScheme/pkgs/foo/bar", | 567 "foo/bar": "%$pkgScheme/pkgs/foo/bar", |
| 560 "bar/bar": "%$pkgScheme/pkgs/bar/bar", | 568 "bar/bar": "%$pkgScheme/pkgs/bar/bar", |
| 561 "foo.x": "qux", | 569 "foo.x": "qux", |
| 562 }); | 570 }); |
| 563 } | 571 } |
| 564 // Package config. The configuration file may also be on either source. | 572 // Package config. The configuration file may also be on either source. |
| 565 for (var configScheme in const ["file", "http"]) { | 573 for (var configScheme in const ["file", "http"]) { |
| 566 // Don't do the boring stuff! | 574 // Don't do the boring stuff! |
| 567 if (entryScheme == configScheme && entryScheme == pkgScheme) continue; | 575 if (entryScheme == configScheme && entryScheme == pkgScheme) continue; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 void insertFileAt(Map file, Map http, | 992 void insertFileAt(Map file, Map http, |
| 985 String path, String name, String content) { | 993 String path, String name, String content) { |
| 986 var parts = path.split('/').toList(); | 994 var parts = path.split('/').toList(); |
| 987 var dir = (parts[0] == "%file") ? file : http; | 995 var dir = (parts[0] == "%file") ? file : http; |
| 988 for (var i = 1; i < parts.length - 1; i++) { | 996 for (var i = 1; i < parts.length - 1; i++) { |
| 989 var entry = parts[i]; | 997 var entry = parts[i]; |
| 990 dir = dir[entry] ?? (dir[entry] = {}); | 998 dir = dir[entry] ?? (dir[entry] = {}); |
| 991 } | 999 } |
| 992 dir[name] = content; | 1000 dir[name] = content; |
| 993 } | 1001 } |
| OLD | NEW |