Skip to content

Commit

Permalink
Merge pull request #400 from wkillerud/pkg-root-case
Browse files Browse the repository at this point in the history
fix: support for conditional exports in sass's pkg
  • Loading branch information
aeschli authored Aug 26, 2024
2 parents f6e7034 + 39185cf commit e18433a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/services/scssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ export class SCSSNavigation extends CSSNavigation {
const subpath = bareTarget.substring(moduleName.length + 1);
if (packageJson.exports) {
if (!subpath) {
const dotExport = packageJson.exports['.'];
// exports may look like { "sass": "./_index.scss" } or { ".": { "sass": "./_index.scss" } }
const rootExport = packageJson.exports["."] || packageJson.exports;
// look for the default/index export
// @ts-expect-error If ['.'] is a string this just produces undefined
const entry = dotExport && (dotExport['sass'] || dotExport['style'] || dotExport['default']);
const entry = rootExport && (rootExport['sass'] || rootExport['style'] || rootExport['default']);
// the 'default' entry can be whatever, typically .js – confirm it looks like `scss`
if (entry && entry.endsWith('.scss')) {
const entryPath = joinPath(modulePath, entry);
Expand Down
3 changes: 3 additions & 0 deletions src/test/scss/scssNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ suite('SCSS - Navigation', () => {
await assertLinks(ls, `@use "pkg:bar-pattern/theme/dark.scss"`,
[{ range: newRange(5, 38), target: getTestResource('node_modules/bar-pattern/styles/theme/dark.scss')}], 'scss', testUri, workspaceFolder
);
await assertLinks(ls, `@use "pkg:conditional"`,
[{ range: newRange(5, 22), target: getTestResource('node_modules/conditional/_index.scss')}], 'scss', testUri, workspaceFolder
);
});

});
Expand Down
6 changes: 6 additions & 0 deletions test/linksTestFixtures/node_modules/conditional/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e18433a

Please sign in to comment.