Skip to content

Commit

Permalink
Switch to the sass_api package (#223)
Browse files Browse the repository at this point in the history
Fixes #209.
  • Loading branch information
jathak authored Jun 15, 2022
1 parent 4616db5 commit 6bd6ad6
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 92 deletions.
2 changes: 1 addition & 1 deletion lib/src/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions lib/src/migration_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
11 changes: 2 additions & 9 deletions lib/src/migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions lib/src/migrators/division.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 2 additions & 9 deletions lib/src/migrators/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions lib/src/migrators/module/member_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
9 changes: 3 additions & 6 deletions lib/src/migrators/module/reference_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 1 addition & 9 deletions lib/src/migrators/module/references.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 1 addition & 4 deletions lib/src/migrators/module/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 1 addition & 4 deletions lib/src/migrators/module/unreferencable_members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 1 addition & 5 deletions lib/src/migrators/module/unreferencable_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
11 changes: 2 additions & 9 deletions lib/src/migrators/namespace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/node_modules_importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 1 addition & 6 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/migrators/namespace/conflict_no_force.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ 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";
| ^^^^^^^^^^^^^^^^
2 | @use "library-b";
| ================
'
entrypoint.scss 1:1 root stylesheet
Migration failed!

0 comments on commit 6bd6ad6

Please sign in to comment.