microsoft / vscode-css-languageservice

CSS, LESS & SCSS language service extracted from VSCode to be reused, e.g in the Monaco editor.
MIT License
312 stars 176 forks source link

Support Sass Node package importer #383

Closed jamesnw closed 2 months ago

jamesnw commented 6 months ago

As part of Sass 1.71, a new concept of "package importer" has been introduced, allowing authors to write @use "pkg:bootstrap" instead of @use "~bootstrap" or @use "../../node_modules/bootstrap". Sass 1.71 includes a built-in package importer that supports Node modules.

Current behavior CMD Clicking on a pkg: URL in a Sass file shows a "Unable to open 'pkg:..." modal, as the language service doesn't know how to resolve the files.

Expected behavior CMD Clicking on a pkg: URL would take you to the corresponding file.

The resolution is almost identical to ~, resolving partials and index files. In addition, it also resolves conditional exports, and resolves in the following order:

  1. sass, style, or default condition in package.json exports.
  2. If there is not a subpath, then find the root export:
    1. sass key at package.json root.
    2. style key at package.json root.
    3. index file at package root, resolved for file extensions and partials.
  3. If there is a subpath, resolve that path relative to the package root, and resolve for file extensions and partials.

Blog post Spec