From 6bd6ad6edee343a624928abc732c8132e2d61c8f Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Tue, 14 Jun 2022 17:14:12 -0700 Subject: [PATCH] Switch to the `sass_api` package (#223) Fixes #209. --- lib/src/exception.dart | 2 +- lib/src/migration_visitor.dart | 9 +-------- lib/src/migrator.dart | 11 ++--------- lib/src/migrators/division.dart | 18 ++++++------------ lib/src/migrators/module.dart | 11 ++--------- .../migrators/module/member_declaration.dart | 6 +----- lib/src/migrators/module/reference_source.dart | 9 +++------ lib/src/migrators/module/references.dart | 10 +--------- lib/src/migrators/module/scope.dart | 5 +---- .../module/unreferencable_members.dart | 5 +---- .../migrators/module/unreferencable_type.dart | 6 +----- lib/src/migrators/namespace.dart | 11 ++--------- lib/src/util/node_modules_importer.dart | 2 +- lib/src/utils.dart | 7 +------ pubspec.yaml | 4 ++-- test/migrators/namespace/conflict_no_force.hrx | 3 +-- 16 files changed, 27 insertions(+), 92 deletions(-) diff --git a/lib/src/exception.dart b/lib/src/exception.dart index 4bad158..98bf253 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -import 'package:sass/sass.dart'; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; /// An exception thrown by a migrator. diff --git a/lib/src/migration_visitor.dart b/lib/src/migration_visitor.dart index 528a303..9421d0a 100644 --- a/lib/src/migration_visitor.dart +++ b/lib/src/migration_visitor.dart @@ -8,16 +8,9 @@ import 'dart:collection'; import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/importer.dart'; -import 'package:sass/src/import_cache.dart'; -import 'package:sass/src/visitor/recursive_ast.dart'; - import 'exception.dart'; import 'patch.dart'; diff --git a/lib/src/migrator.dart b/lib/src/migrator.dart index ab450c7..fef8f6f 100644 --- a/lib/src/migrator.dart +++ b/lib/src/migrator.dart @@ -4,23 +4,16 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/sass.dart'; -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/importer.dart'; -import 'package:sass/src/import_cache.dart'; - import 'package:args/command_runner.dart'; import 'package:glob/glob.dart'; import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; -import 'package:sass_migrator/src/util/node_modules_importer.dart'; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; import 'exception.dart'; import 'io.dart'; +import 'util/node_modules_importer.dart'; import 'utils.dart'; /// A migrator is a command that migrates the entrypoints provided to it and diff --git a/lib/src/migrators/division.dart b/lib/src/migrators/division.dart index 8c2ae59..abedbca 100644 --- a/lib/src/migrators/division.dart +++ b/lib/src/migrators/division.dart @@ -5,18 +5,12 @@ // https://opensource.org/licenses/MIT. import 'package:args/args.dart'; -import 'package:sass/sass.dart'; - -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/import_cache.dart'; - -import 'package:sass_migrator/src/migration_visitor.dart'; -import 'package:sass_migrator/src/migrator.dart'; -import 'package:sass_migrator/src/patch.dart'; -import 'package:sass_migrator/src/utils.dart'; +import 'package:sass_api/sass_api.dart'; + +import '../migration_visitor.dart'; +import '../migrator.dart'; +import '../patch.dart'; +import '../utils.dart'; /// Migrates stylesheets that use the `/` operator for division to use the /// `divide` function instead. diff --git a/lib/src/migrators/module.dart b/lib/src/migrators/module.dart index d7721ca..76d1513 100644 --- a/lib/src/migrators/module.dart +++ b/lib/src/migrators/module.dart @@ -4,17 +4,10 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/importer.dart'; -import 'package:sass/src/import_cache.dart'; -import 'package:sass/src/parse/parser.dart'; - import 'package:args/args.dart'; import 'package:collection/collection.dart'; import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; import 'package:tuple/tuple.dart'; @@ -1320,7 +1313,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor { prefixesToRemove.where((prefix) => prefix.length < identifier.length && identifier.startsWith(prefix) && - Parser.isIdentifier(identifier.substring(prefix.length))), + isIdentifier(identifier.substring(prefix.length))), (prefix) => prefix.length); /// Disallows `@use` after `@at-root` rules. diff --git a/lib/src/migrators/module/member_declaration.dart b/lib/src/migrators/module/member_declaration.dart index 733afc3..e744794 100644 --- a/lib/src/migrators/module/member_declaration.dart +++ b/lib/src/migrators/module/member_declaration.dart @@ -4,12 +4,8 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; - import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; import '../../utils.dart'; diff --git a/lib/src/migrators/module/reference_source.dart b/lib/src/migrators/module/reference_source.dart index a4efbc8..51c5ee7 100644 --- a/lib/src/migrators/module/reference_source.dart +++ b/lib/src/migrators/module/reference_source.dart @@ -4,13 +4,10 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass_migrator/src/utils.dart'; - import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; + +import '../../utils.dart'; /// A [ReferenceSource] is used to track where a referenced member came from. abstract class ReferenceSource { diff --git a/lib/src/migrators/module/references.dart b/lib/src/migrators/module/references.dart index aaf7f25..026bb3c 100644 --- a/lib/src/migrators/module/references.dart +++ b/lib/src/migrators/module/references.dart @@ -4,17 +4,9 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/node.dart'; -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/importer.dart'; -import 'package:sass/src/import_cache.dart'; -import 'package:sass/src/visitor/recursive_ast.dart'; - import 'package:collection/collection.dart'; import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; import '../../exception.dart'; import '../../util/bidirectional_map.dart'; diff --git a/lib/src/migrators/module/scope.dart b/lib/src/migrators/module/scope.dart index 159799d..4f89e7f 100644 --- a/lib/src/migrators/module/scope.dart +++ b/lib/src/migrators/module/scope.dart @@ -4,10 +4,7 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; +import 'package:sass_api/sass_api.dart'; import 'member_declaration.dart'; diff --git a/lib/src/migrators/module/unreferencable_members.dart b/lib/src/migrators/module/unreferencable_members.dart index 27c814b..2c0d190 100644 --- a/lib/src/migrators/module/unreferencable_members.dart +++ b/lib/src/migrators/module/unreferencable_members.dart @@ -4,10 +4,7 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; +import 'package:sass_api/sass_api.dart'; import 'member_declaration.dart'; import 'unreferencable_type.dart'; diff --git a/lib/src/migrators/module/unreferencable_type.dart b/lib/src/migrators/module/unreferencable_type.dart index e4c7a90..369b428 100644 --- a/lib/src/migrators/module/unreferencable_type.dart +++ b/lib/src/migrators/module/unreferencable_type.dart @@ -4,13 +4,9 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; - import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; +import 'package:sass_api/sass_api.dart'; import '../../exception.dart'; diff --git a/lib/src/migrators/namespace.dart b/lib/src/migrators/namespace.dart index 9fe9866..39c1efd 100644 --- a/lib/src/migrators/namespace.dart +++ b/lib/src/migrators/namespace.dart @@ -5,16 +5,9 @@ // https://opensource.org/licenses/MIT. import 'package:args/args.dart'; -import 'package:sass/sass.dart'; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/exception.dart'; -import 'package:sass/src/import_cache.dart'; - import '../migration_visitor.dart'; import '../migrator.dart'; import '../patch.dart'; @@ -107,7 +100,7 @@ class _NamespaceMigrationVisitor extends MigrationVisitor { // If there's still a conflict, fail unless --force is passed. if (!forceRename) { - throw MultiSpanSassException( + throw MultiSourceSpanException( 'Rename failed. ${rules.length} rules would use namespace ' '"$newNamespace".\n' 'Run with --force to rename with numerical suffixes.', diff --git a/lib/src/util/node_modules_importer.dart b/lib/src/util/node_modules_importer.dart index 694d2a8..c969ef9 100644 --- a/lib/src/util/node_modules_importer.dart +++ b/lib/src/util/node_modules_importer.dart @@ -5,7 +5,7 @@ // https://opensource.org/licenses/MIT. import 'package:path/path.dart' as p; -import 'package:sass/sass.dart'; +import 'package:sass_api/sass_api.dart'; import '../io.dart'; diff --git a/lib/src/utils.dart b/lib/src/utils.dart index b559bbc..feba634 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -5,15 +5,10 @@ // https://opensource.org/licenses/MIT. import 'package:charcode/charcode.dart'; +import 'package:sass_api/sass_api.dart'; import 'package:source_span/source_span.dart'; import 'package:tuple/tuple.dart'; -// The sass package's API is not necessarily stable. It is being imported with -// the Sass team's explicit knowledge and approval. See -// https://github.com/sass/dart-sass/issues/236. -import 'package:sass/src/ast/sass.dart'; -import 'package:sass/src/ast/node.dart'; - import 'io.dart'; import 'patch.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 45e9691..ea3e596 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass_migrator -version: 1.5.5-dev +version: 1.5.5 description: A tool for running migrations on Sass files homepage: https://github.com/sass/migrator @@ -17,7 +17,7 @@ dependencies: node_interop: ^2.0.2 node_io: ^2.1.0 path: ^1.8.0 - sass: ^1.44.0 + sass_api: ^1.0.0-beta.48 source_span: ^1.8.1 string_scanner: ^1.1.0 term_glyph: ^1.2.0 diff --git a/test/migrators/namespace/conflict_no_force.hrx b/test/migrators/namespace/conflict_no_force.hrx index 11e8ac4..498386a 100644 --- a/test/migrators/namespace/conflict_no_force.hrx +++ b/test/migrators/namespace/conflict_no_force.hrx @@ -11,7 +11,7 @@ a { } <==> error.txt -Error: Rename failed. 2 rules would use namespace "library". +Error on line 1, column 1 of entrypoint.scss: Rename failed. 2 rules would use namespace "library". Run with --force to rename with numerical suffixes. , 1 | @use "library-a"; @@ -19,5 +19,4 @@ Run with --force to rename with numerical suffixes. 2 | @use "library-b"; | ================ ' - entrypoint.scss 1:1 root stylesheet Migration failed!