Skip to content

Commit e18433a

Browse files
authored
Merge pull request #400 from wkillerud/pkg-root-case
fix: support for conditional exports in sass's pkg
2 parents f6e7034 + 39185cf commit e18433a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/services/scssNavigation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ export class SCSSNavigation extends CSSNavigation {
7979
const subpath = bareTarget.substring(moduleName.length + 1);
8080
if (packageJson.exports) {
8181
if (!subpath) {
82-
const dotExport = packageJson.exports['.'];
82+
// exports may look like { "sass": "./_index.scss" } or { ".": { "sass": "./_index.scss" } }
83+
const rootExport = packageJson.exports["."] || packageJson.exports;
8384
// look for the default/index export
8485
// @ts-expect-error If ['.'] is a string this just produces undefined
85-
const entry = dotExport && (dotExport['sass'] || dotExport['style'] || dotExport['default']);
86+
const entry = rootExport && (rootExport['sass'] || rootExport['style'] || rootExport['default']);
8687
// the 'default' entry can be whatever, typically .js – confirm it looks like `scss`
8788
if (entry && entry.endsWith('.scss')) {
8889
const entryPath = joinPath(modulePath, entry);

src/test/scss/scssNavigation.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ suite('SCSS - Navigation', () => {
326326
await assertLinks(ls, `@use "pkg:bar-pattern/theme/dark.scss"`,
327327
[{ range: newRange(5, 38), target: getTestResource('node_modules/bar-pattern/styles/theme/dark.scss')}], 'scss', testUri, workspaceFolder
328328
);
329+
await assertLinks(ls, `@use "pkg:conditional"`,
330+
[{ range: newRange(5, 22), target: getTestResource('node_modules/conditional/_index.scss')}], 'scss', testUri, workspaceFolder
331+
);
329332
});
330333

331334
});

test/linksTestFixtures/node_modules/conditional/package.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)