Skip to content

Commit 00571ec

Browse files
authored
Add a --pkg-importer flag (#2169)
See sass/sass#2739
1 parent 84f31f0 commit 00571ec

File tree

8 files changed

+35
-5
lines changed

8 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ announcement][pkg-importers] on the Sass blog.
55

66
[pkg-importers]: https://sass-lang.com/blog/announcing-pkg-importers
77

8+
### Command-Line Interface
9+
10+
* Add a `--pkg-importer` flag to enable built-in `pkg:` importers. Currently
11+
this only supports the Node.js package resolution algorithm, via
12+
`--pkg-importer=node`. For example, `@use "pkg:bootstrap"` will load
13+
`node_modules/bootstrap/scss/bootstrap.scss`.
14+
815
### JavaScript API
916

1017
* Add a `NodePackageImporter` importer that can be passed to the `importers`

bin/sass.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Future<void> main(List<String> args) async {
4545
}
4646

4747
var graph = StylesheetGraph(ImportCache(
48+
importers: options.pkgImporters,
4849
loadPaths: options.loadPaths,
4950
// This logger is only used for handling fatal/future deprecations
5051
// during parsing, and is re-used across parses, so we don't want to

lib/src/executable/compile_stylesheet.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
9595
try {
9696
if (options.asynchronous) {
9797
var importCache = AsyncImportCache(
98-
loadPaths: options.loadPaths, logger: options.logger);
98+
importers: options.pkgImporters,
99+
loadPaths: options.loadPaths,
100+
logger: options.logger);
99101

100102
result = source == null
101103
? await compileStringAsync(await readStdin(),

lib/src/executable/options.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart';
1010
import 'package:term_glyph/term_glyph.dart' as term_glyph;
1111

1212
import '../../sass.dart';
13+
import '../importer/node_package.dart';
1314
import '../io.dart';
1415
import '../util/character.dart';
1516

@@ -47,6 +48,12 @@ final class ExecutableOptions {
4748
help: 'A path to use when resolving imports.\n'
4849
'May be passed multiple times.',
4950
splitCommas: false)
51+
..addMultiOption('pkg-importer',
52+
abbr: 'p',
53+
valueHelp: 'TYPE',
54+
allowed: ['node'],
55+
help: 'Built-in importer(s) to use for pkg: URLs.',
56+
allowedHelp: {'node': 'Load files like Node.js package resolution.'})
5057
..addOption('style',
5158
abbr: 's',
5259
valueHelp: 'NAME',
@@ -218,6 +225,12 @@ final class ExecutableOptions {
218225
/// The set of paths Sass in which should look for imported files.
219226
List<String> get loadPaths => _options['load-path'] as List<String>;
220227

228+
/// The list of built-in importers to use to load `pkg:` URLs.
229+
List<Importer> get pkgImporters => [
230+
for (var _ in _options['pkg-importer'] as List<String>)
231+
NodePackageImporter('.')
232+
];
233+
221234
/// Whether to run the evaluator in asynchronous mode, for debugging purposes.
222235
bool get asynchronous => _options['async'] as bool;
223236

lib/src/executable/repl.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ Future<void> repl(ExecutableOptions options) async {
2323
var logger = TrackingLogger(options.logger);
2424
var evaluator = Evaluator(
2525
importer: FilesystemImporter.cwd,
26-
importCache: ImportCache(loadPaths: options.loadPaths, logger: logger),
26+
importCache: ImportCache(
27+
importers: options.pkgImporters,
28+
loadPaths: options.loadPaths,
29+
logger: logger),
2730
logger: logger);
2831
await for (String line in repl.runAsync()) {
2932
if (line.trim().isEmpty) continue;

pkg/sass_api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 9.4.0
2+
3+
* No user-visible changes.
4+
15
## 9.3.0
26

37
* No user-visible changes.

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 9.3.0
5+
version: 9.4.0
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.0.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.70.0
13+
sass: 1.71.0
1414

1515
dev_dependencies:
1616
dartdoc: ^6.0.0

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.71.0-dev
2+
version: 1.71.0
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)