Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support for conditional exports in sass's pkg #400

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading