From 247cb3d8167986c3d19e2efd50770adb93c5d807 Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Tue, 9 Mar 2021 14:36:48 -0800 Subject: [PATCH] Update dependencies to null-safe versions This also replaces package_resolver with package_config, since package_resolver is archived and is incompatible with null-safe Dart packages. --- lib/sass.dart | 38 ++++++--------- lib/src/async_compile.dart | 2 - lib/src/async_import_cache.dart | 20 ++++---- lib/src/compile.dart | 4 +- lib/src/import_cache.dart | 22 ++++----- lib/src/importer/package.dart | 16 +++--- lib/src/sync_package_resolver.dart | 2 - lib/src/sync_package_resolver/node.dart | 15 ------ pubspec.yaml | 65 +++++++++++++------------ test/cli/dart_test.dart | 4 +- test/cli/node_test.dart | 7 ++- test/dart_api_test.dart | 30 ++++++------ test/double_check_test.dart | 2 +- 13 files changed, 101 insertions(+), 126 deletions(-) delete mode 100644 lib/src/sync_package_resolver.dart delete mode 100644 lib/src/sync_package_resolver/node.dart diff --git a/lib/sass.dart b/lib/sass.dart index e45a610d..855f20f7 100644 --- a/lib/sass.dart +++ b/lib/sass.dart @@ -5,6 +5,7 @@ /// We strongly recommend importing this library with the prefix `sass`. library sass; +import 'package:package_config/package_config_types.dart'; import 'package:source_maps/source_maps.dart'; import 'src/async_import_cache.dart'; @@ -14,7 +15,6 @@ import 'src/exception.dart'; import 'src/import_cache.dart'; import 'src/importer.dart'; import 'src/logger.dart'; -import 'src/sync_package_resolver.dart'; import 'src/syntax.dart'; import 'src/visitor/serialize.dart'; @@ -48,11 +48,11 @@ export 'src/warn.dart' show warn; /// * Each load path specified in the `SASS_PATH` environment variable, which /// should be semicolon-separated on Windows and colon-separated elsewhere. /// -/// * `package:` resolution using [packageResolver], which is a -/// [`SyncPackageResolver`][] from the `package_resolver` package. Note that +/// * `package:` resolution using [packageConfig], which is a +/// [`PackageConfig`][] from the `package_resolver` package. Note that /// this is a shorthand for adding a [PackageImporter] to [importers]. /// -/// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html +/// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html /// /// Dart functions that can be called from Sass may be passed using [functions]. /// Each [Callable] defines a top-level function that will be invoked when the @@ -90,7 +90,7 @@ String compile(String path, Logger logger, Iterable importers, Iterable loadPaths, - SyncPackageResolver packageResolver, + PackageConfig packageConfig, Iterable functions, OutputStyle style, void sourceMap(SingleMapping map), @@ -99,9 +99,7 @@ String compile(String path, var result = c.compile(path, logger: logger, importCache: ImportCache(importers, - logger: logger, - loadPaths: loadPaths, - packageResolver: packageResolver), + logger: logger, loadPaths: loadPaths, packageConfig: packageConfig), functions: functions, style: style, sourceMap: sourceMap != null, @@ -132,11 +130,11 @@ String compile(String path, /// * Each load path specified in the `SASS_PATH` environment variable, which /// should be semicolon-separated on Windows and colon-separated elsewhere. /// -/// * `package:` resolution using [packageResolver], which is a -/// [`SyncPackageResolver`][] from the `package_resolver` package. Note that +/// * `package:` resolution using [packageConfig], which is a +/// [`PackageConfig`][] from the `package_resolver` package. Note that /// this is a shorthand for adding a [PackageImporter] to [importers]. /// -/// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html +/// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html /// /// Dart functions that can be called from Sass may be passed using [functions]. /// Each [Callable] defines a top-level function that will be invoked when the @@ -178,7 +176,7 @@ String compileString(String source, bool color = false, Logger logger, Iterable importers, - SyncPackageResolver packageResolver, + PackageConfig packageConfig, Iterable loadPaths, Iterable functions, OutputStyle style, @@ -192,9 +190,7 @@ String compileString(String source, syntax: syntax ?? (indented ? Syntax.sass : Syntax.scss), logger: logger, importCache: ImportCache(importers, - logger: logger, - packageResolver: packageResolver, - loadPaths: loadPaths), + logger: logger, packageConfig: packageConfig, loadPaths: loadPaths), functions: functions, style: style, importer: importer, @@ -214,7 +210,7 @@ Future compileAsync(String path, {bool color = false, Logger logger, Iterable importers, - SyncPackageResolver packageResolver, + PackageConfig packageConfig, Iterable loadPaths, Iterable functions, OutputStyle style, @@ -223,9 +219,7 @@ Future compileAsync(String path, var result = await c.compileAsync(path, logger: logger, importCache: AsyncImportCache(importers, - logger: logger, - loadPaths: loadPaths, - packageResolver: packageResolver), + logger: logger, loadPaths: loadPaths, packageConfig: packageConfig), functions: functions, style: style, sourceMap: sourceMap != null); @@ -243,7 +237,7 @@ Future compileStringAsync(String source, bool color = false, Logger logger, Iterable importers, - SyncPackageResolver packageResolver, + PackageConfig packageConfig, Iterable loadPaths, Iterable functions, OutputStyle style, @@ -257,9 +251,7 @@ Future compileStringAsync(String source, syntax: syntax ?? (indented ? Syntax.sass : Syntax.scss), logger: logger, importCache: AsyncImportCache(importers, - logger: logger, - packageResolver: packageResolver, - loadPaths: loadPaths), + logger: logger, packageConfig: packageConfig, loadPaths: loadPaths), functions: functions, style: style, importer: importer, diff --git a/lib/src/async_compile.dart b/lib/src/async_compile.dart index b1996b64..64d4fe15 100644 --- a/lib/src/async_compile.dart +++ b/lib/src/async_compile.dart @@ -15,7 +15,6 @@ import 'importer.dart'; import 'importer/node.dart'; import 'io.dart'; import 'logger.dart'; -import 'sync_package_resolver.dart'; import 'syntax.dart'; import 'utils.dart'; import 'visitor/async_evaluate.dart'; @@ -77,7 +76,6 @@ Future compileStringAsync(String source, NodeImporter nodeImporter, Iterable importers, Iterable loadPaths, - SyncPackageResolver packageResolver, AsyncImporter importer, Iterable functions, OutputStyle style, diff --git a/lib/src/async_import_cache.dart b/lib/src/async_import_cache.dart index 58e5a1b6..d26c685a 100644 --- a/lib/src/async_import_cache.dart +++ b/lib/src/async_import_cache.dart @@ -3,6 +3,7 @@ // https://opensource.org/licenses/MIT. import 'package:collection/collection.dart'; +import 'package:package_config/package_config_types.dart'; import 'package:path/path.dart' as p; import 'package:tuple/tuple.dart'; @@ -11,7 +12,6 @@ import 'importer.dart'; import 'importer/utils.dart'; import 'io.dart'; import 'logger.dart'; -import 'sync_package_resolver.dart'; import 'utils.dart'; // ignore: unused_import /// An in-memory cache of parsed stylesheets that have been imported by Sass. @@ -52,16 +52,14 @@ class AsyncImportCache { /// * Each load path specified in the `SASS_PATH` environment variable, which /// should be semicolon-separated on Windows and colon-separated elsewhere. /// - /// * `package:` resolution using [packageResolver], which is a - /// [`SyncPackageResolver`][] from the `package_resolver` package. Note that + /// * `package:` resolution using [packageConfig], which is a + /// [`PackageConfig`][] from the `package_config` package. Note that /// this is a shorthand for adding a [PackageImporter] to [importers]. /// - /// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html + /// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html AsyncImportCache(Iterable importers, - {Iterable loadPaths, - SyncPackageResolver packageResolver, - Logger logger}) - : _importers = _toImporters(importers, loadPaths, packageResolver), + {Iterable loadPaths, PackageConfig packageConfig, Logger logger}) + : _importers = _toImporters(importers, loadPaths, packageConfig), _logger = logger ?? const Logger.stderr(), _canonicalizeCache = {}, _importCache = {}, @@ -75,10 +73,10 @@ class AsyncImportCache { _importCache = {}, _resultsCache = {}; - /// Converts the user's [importers], [loadPaths], and [packageResolver] + /// Converts the user's [importers], [loadPaths], and [packageConfig] /// options into a single list of importers. static List _toImporters(Iterable importers, - Iterable loadPaths, SyncPackageResolver packageResolver) { + Iterable loadPaths, PackageConfig packageConfig) { var sassPath = getEnvironmentVariable('SASS_PATH'); return [ ...?importers, @@ -87,7 +85,7 @@ class AsyncImportCache { if (sassPath != null) for (var path in sassPath.split(isWindows ? ';' : ':')) FilesystemImporter(path), - if (packageResolver != null) PackageImporter(packageResolver) + if (packageConfig != null) PackageImporter(packageConfig) ]; } diff --git a/lib/src/compile.dart b/lib/src/compile.dart index d2b49565..72e2655d 100644 --- a/lib/src/compile.dart +++ b/lib/src/compile.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_compile.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: b2cd6037efa37e300daa45ebed20cb4b61526161 +// Checksum: ef27d750f1d5305373fe9e712cf99697a21e0689 // // ignore_for_file: unused_import @@ -25,7 +25,6 @@ import 'importer.dart'; import 'importer/node.dart'; import 'io.dart'; import 'logger.dart'; -import 'sync_package_resolver.dart'; import 'syntax.dart'; import 'utils.dart'; import 'visitor/evaluate.dart'; @@ -87,7 +86,6 @@ CompileResult compileString(String source, NodeImporter nodeImporter, Iterable importers, Iterable loadPaths, - SyncPackageResolver packageResolver, Importer importer, Iterable functions, OutputStyle style, diff --git a/lib/src/import_cache.dart b/lib/src/import_cache.dart index 96c5d628..57b726ab 100644 --- a/lib/src/import_cache.dart +++ b/lib/src/import_cache.dart @@ -5,11 +5,12 @@ // DO NOT EDIT. This file was generated from async_import_cache.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: 6ac1ee07d6b46134f1616d82782180f1cc3b6d81 +// Checksum: 31432610e32afefcc7adcda592b811ec50e9b47f // // ignore_for_file: unused_import import 'package:collection/collection.dart'; +import 'package:package_config/package_config_types.dart'; import 'package:path/path.dart' as p; import 'package:tuple/tuple.dart'; @@ -18,7 +19,6 @@ import 'importer.dart'; import 'importer/utils.dart'; import 'io.dart'; import 'logger.dart'; -import 'sync_package_resolver.dart'; import 'utils.dart'; // ignore: unused_import /// An in-memory cache of parsed stylesheets that have been imported by Sass. @@ -58,16 +58,14 @@ class ImportCache { /// * Each load path specified in the `SASS_PATH` environment variable, which /// should be semicolon-separated on Windows and colon-separated elsewhere. /// - /// * `package:` resolution using [packageResolver], which is a - /// [`SyncPackageResolver`][] from the `package_resolver` package. Note that + /// * `package:` resolution using [packageConfig], which is a + /// [`PackageConfig`][] from the `package_config` package. Note that /// this is a shorthand for adding a [PackageImporter] to [importers]. /// - /// [`SyncPackageResolver`]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html + /// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html ImportCache(Iterable importers, - {Iterable loadPaths, - SyncPackageResolver packageResolver, - Logger logger}) - : _importers = _toImporters(importers, loadPaths, packageResolver), + {Iterable loadPaths, PackageConfig packageConfig, Logger logger}) + : _importers = _toImporters(importers, loadPaths, packageConfig), _logger = logger ?? const Logger.stderr(), _canonicalizeCache = {}, _importCache = {}, @@ -81,10 +79,10 @@ class ImportCache { _importCache = {}, _resultsCache = {}; - /// Converts the user's [importers], [loadPaths], and [packageResolver] + /// Converts the user's [importers], [loadPaths], and [packageConfig] /// options into a single list of importers. static List _toImporters(Iterable importers, - Iterable loadPaths, SyncPackageResolver packageResolver) { + Iterable loadPaths, PackageConfig packageConfig) { var sassPath = getEnvironmentVariable('SASS_PATH'); return [ ...?importers, @@ -93,7 +91,7 @@ class ImportCache { if (sassPath != null) for (var path in sassPath.split(isWindows ? ';' : ':')) FilesystemImporter(path), - if (packageResolver != null) PackageImporter(packageResolver) + if (packageConfig != null) PackageImporter(packageConfig) ]; } diff --git a/lib/src/importer/package.dart b/lib/src/importer/package.dart index 79eded47..77096875 100644 --- a/lib/src/importer/package.dart +++ b/lib/src/importer/package.dart @@ -3,9 +3,9 @@ // https://opensource.org/licenses/MIT. import 'package:meta/meta.dart'; +import 'package:package_config/package_config_types.dart'; import '../importer.dart'; -import '../sync_package_resolver.dart'; /// A filesystem importer to use when resolving the results of `package:` URLs. /// @@ -17,24 +17,24 @@ final _filesystemImporter = FilesystemImporter('.'); @sealed class PackageImporter extends Importer { /// The resolver that converts `package:` imports to `file:`. - final SyncPackageResolver _packageResolver; + final PackageConfig _packageConfig; /// Creates an importer that loads stylesheets from `package:` URLs according - /// to [packageResolver], which is a [SyncPackageResolver][] from the - /// `package_resolver` package. + /// to [packageConfig], which is a [PackageConfig][] from the `package_config` + /// package. /// - /// [SyncPackageResolver]: https://www.dartdocs.org/documentation/package_resolver/latest/package_resolver/SyncPackageResolver-class.html - PackageImporter(this._packageResolver); + /// [`PackageConfig`]: https://pub.dev/documentation/package_config/latest/package_config.package_config/PackageConfig-class.html + PackageImporter(this._packageConfig); Uri canonicalize(Uri url) { if (url.scheme == 'file') return _filesystemImporter.canonicalize(url); if (url.scheme != 'package') return null; - var resolved = _packageResolver.resolveUri(url); + var resolved = _packageConfig.resolve(url); if (resolved == null) throw "Unknown package."; if (resolved.scheme.isNotEmpty && resolved.scheme != 'file') { - throw "Unsupported URL ${resolved}."; + throw "Unsupported URL $resolved."; } return _filesystemImporter.canonicalize(resolved); diff --git a/lib/src/sync_package_resolver.dart b/lib/src/sync_package_resolver.dart deleted file mode 100644 index f61ae7be..00000000 --- a/lib/src/sync_package_resolver.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'package:package_resolver/package_resolver.dart' - if (dart.library.js) 'sync_package_resolver/node.dart'; diff --git a/lib/src/sync_package_resolver/node.dart b/lib/src/sync_package_resolver/node.dart deleted file mode 100644 index c0984dce..00000000 --- a/lib/src/sync_package_resolver/node.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -class SyncPackageResolver { - static final _error = - UnsupportedError('SyncPackageResolver is not supported in JS.'); - - static Future get current => throw _error; - - Uri resolveUri(Object packageUri) => throw _error; - - factory SyncPackageResolver.config(Map configMap) => - throw _error; -} diff --git a/pubspec.yaml b/pubspec.yaml index edd4de45..a76c7a9e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,37 +12,38 @@ environment: sdk: '>=2.6.0 <3.0.0' dependencies: - args: ">=1.4.0 <3.0.0" - async: ">=1.10.0 <3.0.0" - charcode: "^1.1.0" - cli_repl: ">=0.1.3 <0.3.0" - collection: "^1.8.0" - meta: "^1.1.7" - node_interop: "^1.1.0" - js: "^0.6.0" - package_resolver: "^1.0.0" - path: "^1.6.0" - source_maps: "^0.10.5" - source_span: "^1.6.0" - stack_trace: ">=0.9.0 <2.0.0" - stream_transform: ">=0.0.20 <3.0.0" - string_scanner: ">=0.1.5 <2.0.0" - term_glyph: "^1.0.0" - tuple: "^1.0.0" - watcher: ">=0.9.6 <2.0.0" + args: ^2.0.0 + async: ^2.5.0 + charcode: ^1.2.0 + cli_repl: ^0.2.1-nullsafety + collection: ^1.15.0 + meta: ^1.3.0 + node_interop: ^2.0.0 + js: ^0.6.3 + path: ^1.8.0 + source_maps: ^0.10.10 + source_span: ^1.8.1 + stack_trace: ^1.10.0 + stream_transform: ^2.0.0 + string_scanner: ^1.1.0 + term_glyph: ^1.2.0 + tuple: ^2.0.0-nullsafety.0 + watcher: ^1.0.0 + +publish_to: none dev_dependencies: - archive: ">=1.0.0 <3.0.0" - analyzer: "^0.40.0" - cli_pkg: "^1.1.0" - crypto: ">=0.9.2 <3.0.0" - dart_style: "^1.2.0" - grinder: "^0.8.0" - node_preamble: "^1.1.0" - pedantic: "^1.0.0" - pub_semver: "^1.0.0" - stream_channel: ">=1.0.0 <3.0.0" - test_descriptor: "^1.1.0" - test_process: "^1.0.0-rc.1" - test: ">=0.12.42 <2.0.0" - yaml: "^2.0.0" + archive: ^3.1.2 + analyzer: ^1.1.0 + cli_pkg: ^1.3.0 + crypto: ^3.0.0 + dart_style: ^2.0.0 + grinder: ^0.9.0-nullsafety.0 + node_preamble: ^2.0.0 + pedantic: ^1.11.0 + pub_semver: ^2.0.0 + stream_channel: ^2.1.0 + test_descriptor: ^2.0.0 + test_process: ^2.0.0 + test: ^1.16.7 + yaml: ^3.1.0 diff --git a/test/cli/dart_test.dart b/test/cli/dart_test.dart index 639d0886..5e1f654d 100644 --- a/test/cli/dart_test.dart +++ b/test/cli/dart_test.dart @@ -4,6 +4,8 @@ @TestOn('vm') +import 'dart:convert'; + import 'package:cli_pkg/testing.dart' as pkg; import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; @@ -30,4 +32,4 @@ void ensureSnapshotUpToDate() => pkg.ensureExecutableUpToDate("sass"); Future runSass(Iterable arguments, {Map environment}) => pkg.start("sass", arguments, - environment: environment, workingDirectory: d.sandbox); + environment: environment, workingDirectory: d.sandbox, encoding: utf8); diff --git a/test/cli/node_test.dart b/test/cli/node_test.dart index e27bb4fc..7d1e4f75 100644 --- a/test/cli/node_test.dart +++ b/test/cli/node_test.dart @@ -5,6 +5,8 @@ @TestOn('vm') @Tags(['node']) +import 'dart:convert'; + import 'package:cli_pkg/testing.dart' as pkg; import 'package:test_process/test_process.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; @@ -31,4 +33,7 @@ void main() { Future runSass(Iterable arguments, {Map environment}) => pkg.start("sass", arguments, - environment: environment, workingDirectory: d.sandbox, node: true); + environment: environment, + workingDirectory: d.sandbox, + encoding: utf8, + node: true); diff --git a/test/dart_api_test.dart b/test/dart_api_test.dart index 7d628b4f..5ccb3696 100644 --- a/test/dart_api_test.dart +++ b/test/dart_api_test.dart @@ -4,7 +4,7 @@ @TestOn('vm') -import 'package:package_resolver/package_resolver.dart'; +import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; @@ -93,10 +93,10 @@ void main() { await d .file("test.scss", '@import "package:fake_package/test";') .create(); - var resolver = SyncPackageResolver.config( - {"fake_package": p.toUri(d.path('subdir'))}); + var config = + PackageConfig([Package('fake_package', p.toUri(d.path('subdir/')))]); - var css = compile(d.path("test.scss"), packageResolver: resolver); + var css = compile(d.path("test.scss"), packageConfig: config); expect(css, equals("a {\n b: 3;\n}")); }); @@ -109,10 +109,10 @@ void main() { await d .file("test.scss", '@import "package:fake_package/test";') .create(); - var resolver = SyncPackageResolver.config( - {"fake_package": p.toUri(d.path('subdir'))}); + var config = + PackageConfig([Package('fake_package', p.toUri(d.path('subdir/')))]); - var css = compile(d.path("test.scss"), packageResolver: resolver); + var css = compile(d.path("test.scss"), packageConfig: config); expect(css, equals("a {\n b: 3;\n}")); }); @@ -120,9 +120,9 @@ void main() { await d .file("test.scss", '@import "package:fake_package/test_aux";') .create(); - var resolver = SyncPackageResolver.config({}); - expect(() => compile(d.path("test.scss"), packageResolver: resolver), + expect( + () => compile(d.path("test.scss"), packageConfig: PackageConfig([])), throwsA(const TypeMatcher())); }); }); @@ -166,9 +166,9 @@ void main() { expect(css, equals("a {\n b: from-importer;\n}")); }); - test("importers take precedence over packageResolver", () async { + test("importers take precedence over packageConfig", () async { await d.dir("package", - [d.file("other.scss", "a {b: from-package-resolver}")]).create(); + [d.file("other.scss", "a {b: from-package-config}")]).create(); await d.dir( "importer", [d.file("other.scss", "a {b: from-importer}")]).create(); await d @@ -177,11 +177,11 @@ void main() { var css = compile(d.path("test.scss"), importers: [ - PackageImporter(SyncPackageResolver.config( - {"fake_package": p.toUri(d.path('importer'))})) + PackageImporter(PackageConfig( + [Package('fake_package', p.toUri(d.path('importer/')))])) ], - packageResolver: SyncPackageResolver.config( - {"fake_package": p.toUri(d.path('package'))})); + packageConfig: PackageConfig( + [Package('fake_package', p.toUri(d.path('package/')))])); expect(css, equals("a {\n b: from-importer;\n}")); }); }); diff --git a/test/double_check_test.dart b/test/double_check_test.dart index b18502cd..23983a27 100644 --- a/test/double_check_test.dart +++ b/test/double_check_test.dart @@ -44,7 +44,7 @@ void main() { var changelogVersion = firstLine.substring(3); var pubspec = loadYaml(File("pubspec.yaml").readAsStringSync(), - sourceUrl: "pubspec.yaml") as Map; + sourceUrl: Uri(path: "pubspec.yaml")) as Map; expect(pubspec, containsPair("version", isA())); var pubspecVersion = pubspec["version"] as String;