diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a033cb43..bb67ee905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ announcement][pkg-importers] on the Sass blog. [pkg-importers]: https://sass-lang.com/blog/announcing-pkg-importers +### Command-Line Interface + +* Add a `--pkg-importer` flag to enable built-in `pkg:` importers. Currently + this only supports the Node.js package resolution algorithm, via + `--pkg-importer=node`. For example, `@use "pkg:bootstrap"` will load + `node_modules/bootstrap/scss/bootstrap.scss`. + ### JavaScript API * Add a `NodePackageImporter` importer that can be passed to the `importers` diff --git a/bin/sass.dart b/bin/sass.dart index ad23649d4..67b1782ed 100644 --- a/bin/sass.dart +++ b/bin/sass.dart @@ -45,6 +45,7 @@ Future main(List args) async { } var graph = StylesheetGraph(ImportCache( + importers: options.pkgImporters, loadPaths: options.loadPaths, // This logger is only used for handling fatal/future deprecations // during parsing, and is re-used across parses, so we don't want to diff --git a/lib/src/executable/compile_stylesheet.dart b/lib/src/executable/compile_stylesheet.dart index ba85610af..160a01d9a 100644 --- a/lib/src/executable/compile_stylesheet.dart +++ b/lib/src/executable/compile_stylesheet.dart @@ -95,7 +95,9 @@ Future _compileStylesheetWithoutErrorHandling(ExecutableOptions options, try { if (options.asynchronous) { var importCache = AsyncImportCache( - loadPaths: options.loadPaths, logger: options.logger); + importers: options.pkgImporters, + loadPaths: options.loadPaths, + logger: options.logger); result = source == null ? await compileStringAsync(await readStdin(), diff --git a/lib/src/executable/options.dart b/lib/src/executable/options.dart index 504999c49..876b55814 100644 --- a/lib/src/executable/options.dart +++ b/lib/src/executable/options.dart @@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart'; import 'package:term_glyph/term_glyph.dart' as term_glyph; import '../../sass.dart'; +import '../importer/node_package.dart'; import '../io.dart'; import '../util/character.dart'; @@ -47,6 +48,12 @@ final class ExecutableOptions { help: 'A path to use when resolving imports.\n' 'May be passed multiple times.', splitCommas: false) + ..addMultiOption('pkg-importer', + abbr: 'p', + valueHelp: 'TYPE', + allowed: ['node'], + help: 'Built-in importer(s) to use for pkg: URLs.', + allowedHelp: {'node': 'Load files like Node.js package resolution.'}) ..addOption('style', abbr: 's', valueHelp: 'NAME', @@ -218,6 +225,12 @@ final class ExecutableOptions { /// The set of paths Sass in which should look for imported files. List get loadPaths => _options['load-path'] as List; + /// The list of built-in importers to use to load `pkg:` URLs. + List get pkgImporters => [ + for (var _ in _options['pkg-importer'] as List) + NodePackageImporter('.') + ]; + /// Whether to run the evaluator in asynchronous mode, for debugging purposes. bool get asynchronous => _options['async'] as bool; diff --git a/lib/src/executable/repl.dart b/lib/src/executable/repl.dart index 6e0124bde..e2e858a26 100644 --- a/lib/src/executable/repl.dart +++ b/lib/src/executable/repl.dart @@ -23,7 +23,10 @@ Future repl(ExecutableOptions options) async { var logger = TrackingLogger(options.logger); var evaluator = Evaluator( importer: FilesystemImporter.cwd, - importCache: ImportCache(loadPaths: options.loadPaths, logger: logger), + importCache: ImportCache( + importers: options.pkgImporters, + loadPaths: options.loadPaths, + logger: logger), logger: logger); await for (String line in repl.runAsync()) { if (line.trim().isEmpty) continue; diff --git a/pkg/sass_api/CHANGELOG.md b/pkg/sass_api/CHANGELOG.md index 99a7689e4..a0a629ba1 100644 --- a/pkg/sass_api/CHANGELOG.md +++ b/pkg/sass_api/CHANGELOG.md @@ -1,3 +1,7 @@ +## 9.4.0 + +* No user-visible changes. + ## 9.3.0 * No user-visible changes. diff --git a/pkg/sass_api/pubspec.yaml b/pkg/sass_api/pubspec.yaml index 5158fc4e4..ce05d56df 100644 --- a/pkg/sass_api/pubspec.yaml +++ b/pkg/sass_api/pubspec.yaml @@ -2,7 +2,7 @@ name: sass_api # Note: Every time we add a new Sass AST node, we need to bump the *major* # version because it's a breaking change for anyone who's implementing the # visitor interface(s). -version: 9.3.0 +version: 9.4.0 description: Additional APIs for Dart Sass. homepage: https://github.com/sass/dart-sass @@ -10,7 +10,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - sass: 1.70.0 + sass: 1.71.0 dev_dependencies: dartdoc: ^6.0.0 diff --git a/pubspec.yaml b/pubspec.yaml index 296270dfc..13edc951c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.71.0-dev +version: 1.71.0 description: A Sass implementation in Dart. homepage: https://github.com/sass/dart-sass