-
Notifications
You must be signed in to change notification settings - Fork 200
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
447bfa1
e427693
0df65eb
7425309
a562b11
5f2bc5a
2e618be
1d6f462
a75501c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Continuous Integration for vscode-css-languageservice | ||
| # Runs the TypeScript build & test suite on Node.js LTS versions | ||
|
|
||
| language: node_js | ||
|
|
||
| # Test against active LTS releases (adjust as project evolves) | ||
| node_js: | ||
| - "20" | ||
| - "18" | ||
|
|
||
| # Speed up by re‑using npm cache across builds | ||
| cache: | ||
| npm: true | ||
| directories: | ||
| - ~/.npm | ||
|
|
||
| install: | ||
| # Guaranteed clean, reproducible install | ||
| - npm ci | ||
|
|
||
| script: | ||
| # Compile the TypeScript (equivalent to `gulp compile` in the repo scripts) | ||
| - npm run compile | ||
| # Run the unit test suite (e.g. Jest / Mocha configured in package.json) | ||
| - npm test | ||
|
|
||
| # Only build push & PR branches; ignore tags unless they come from the repo owner | ||
| branches: | ||
| only: | ||
| - /.*/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,8 +399,8 @@ export class CSSNavigation { | |
| const documentFolderUri = dirname(documentUri); | ||
| const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri); | ||
| if (modulePath) { | ||
| const pathWithinModule = ref.substring(moduleName.length + 1); | ||
| return joinPath(modulePath, pathWithinModule); | ||
| const remainder = ref.length > moduleName.length ? ref.slice(moduleName.length + 1) : ''; // skip the '/', bare import | ||
| return remainder ? joinPath(modulePath, remainder) : modulePath; // e.g. "@import 'bootstrap';" | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -422,7 +422,20 @@ 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 isBareImport = !target.startsWith('.') // not ./ or ../ | ||
| && !target.startsWith('/') // not workspace-absolute | ||
| && target.indexOf(':') === -1; // not a scheme (file://) | ||
|
||
|
|
||
| if (isBareImport) { | ||
| const moduleRef = await this.mapReference( | ||
| await this.resolveModuleReference(target, documentUri, documentContext), | ||
| isRawLink); | ||
| if (moduleRef) { return moduleRef; } | ||
| } | ||
|
|
||
| const ref = await this.mapReference( | ||
| documentContext.resolveReference(target, documentUri), isRawLink); | ||
|
|
||
| // Following [less-loader](https://github.com/webpack-contrib/less-loader#imports) | ||
| // and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules) | ||
|
|
@@ -589,4 +602,4 @@ export function getModuleNameFromPath(path: string) { | |
| } | ||
| // Otherwise get until first instance of '/' | ||
| return path.substring(0, firstSlash); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { assert } from 'chai'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| import { getSCSSLanguageService } from '../../cssLanguageService'; | ||
| import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
| import { FileType, getNodeFSRequestService } from '../../nodeFs'; | ||
|
|
||
| const ls = getSCSSLanguageService(); | ||
| const mockFS = getNodeFSRequestService(); | ||
|
|
||
| describe('SCSS link navigation – node_modules', () => { | ||
| it('resolves bootstrap path on Windows', async () => { | ||
| 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, '/'); | ||
|
||
| assert.match(target, /node_modules\/bootstrap\/scss\/_variables\.scss$/); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build | ||
IsaacTian05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove that file