Skip to content

SCSS: resolve bare module imports on Windows (#245579) #440

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

IsaacTian05
Copy link

@IsaacTian05 IsaacTian05 commented Apr 26, 2025

Fix issue #432

@IsaacTian05
Copy link
Author

@microsoft-github-policy-service agree

.travis.yml Outdated
@@ -0,0 +1,30 @@
# Continuous Integration for vscode-css-languageservice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove that file

const doc = TextDocument.create('file:///c:/proj/app.scss', 'scss', 1,
"@import 'bootstrap/scss/variables';");
const links = await ls.findDocumentLinks2(doc, ls.parseStylesheet(doc), {}, mockFS);
const target = links[0].target!.replace(/\\/g, '/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target is a URI, it should not contain \

@IsaacTian05 IsaacTian05 requested a review from aeschli April 29, 2025 21:03
Copy link
Collaborator

@aeschli aeschli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. If you can add some more test cases that would be great

// Treat bare module names (“bootstrap/...”) like sass-loader does
const isBareImport = !target.startsWith('.') // not ./ or ../
&& !target.startsWith('/') // not workspace-absolute
&& target.indexOf(':') === -1; // not a scheme (file://)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a use a regex to make that check [
startsWithSchemeRegex = /^\w[\w\d+.-]:/

…solute

Adds `schemeImportLinks.test.ts` with four mocha cases covering
`http://`, `https://`, `file://`, and `vscode-resource://` URLs
@@ -422,7 +422,22 @@ export class CSSNavigation {
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
}

const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
// Treat bare module names (“bootstrap/...”) like sass-loader does
const startsWithSchemeRegex = /^\w[\w\d+.-]:/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node module resolving should only happen when this.resolveModuleReferences is true.
(only set for LESS and SCSS).

So this needs to go behind the if (this.resolveModuleReferences) {.
I looks like we already call resolveModuleReference there, so this code is not necessary?

@@ -0,0 +1,46 @@
import * as assert from 'assert';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move these into scssNavigation.test.ts, where we have all other tests for node module resolving.
Please use the already existing test framework and style (mocha with suite and test

@@ -0,0 +1,18 @@
import { assert } from 'chai';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move these into scssNavigation.test.ts, where we have all other tests for node module resolving.
Please use the already existing test framework and style (mocha with suite and test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants