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

feat: support pkg: imports #110

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm-debug.log*
node_modules/
!fixtures/e2e/node_modules
!fixtures/e2e/completion/node_modules
!fixtures/e2e/pkg-import/node_modules

# Compiled and temporary files
dist/
Expand Down
19 changes: 19 additions & 0 deletions e2e/src/suite/definition/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ describe("SCSS Definition Test", function () {
const vueDocUri = getDocUri("definition/AppButton.vue");
const svelteDocUri = getDocUri("definition/AppButton.svelte");
const astroDocUri = getDocUri("definition/AppButton.astro");
const pkgImportUri = getDocUri("pkg-import/src/styles.scss");
const scopedPkgImportUri = getDocUri("pkg-import/src/scoped.scss");

before(async () => {
await showFile(docUri);
await showFile(vueDocUri);
await showFile(svelteDocUri);
await showFile(astroDocUri);
await showFile(pkgImportUri);
await sleepCI();
});

Expand Down Expand Up @@ -77,4 +80,20 @@ describe("SCSS Definition Test", function () {
await testDefinition(svelteDocUri, position(18, 17), expectedLocation);
await testDefinition(astroDocUri, position(21, 17), expectedLocation);
});

it("finds symbol from pkg: import", async () => {
const expectedDocumentUri = getDocUri(
"pkg-import/node_modules/my-components/styles/colors.scss",
);
const expectedLocation = sameLineLocation(expectedDocumentUri, 3, 1, 15);
await testDefinition(pkgImportUri, position(4, 19), expectedLocation);
});

it("finds symbol from scoped pkg: import", async () => {
const expectedDocumentUri = getDocUri(
"pkg-import/node_modules/@my-scope/my-components/styles/colors.scss",
);
const expectedLocation = sameLineLocation(expectedDocumentUri, 3, 1, 15);
await testDefinition(scopedPkgImportUri, position(4, 19), expectedLocation);
});
});
9 changes: 9 additions & 0 deletions e2e/src/suite/hover/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ describe("SCSS Hover Test", function () {
const vueDocUri = getDocUri("hover/AppButton.vue");
const svelteDocUri = getDocUri("hover/AppButton.svelte");
const astroDocUri = getDocUri("hover/AppButton.astro");
const pkgImportUri = getDocUri("pkg-import/src/styles.scss");

before(async () => {
await showFile(docUri);
await showFile(collisionUri);
await showFile(vueDocUri);
await showFile(svelteDocUri);
await showFile(astroDocUri);
await showFile(pkgImportUri);
await sleepCI();
});

Expand Down Expand Up @@ -129,4 +131,11 @@ describe("SCSS Hover Test", function () {

await testHover(collisionUri, position(5, 20), expectedContents);
});

it("shows hover for symbols from pkg: import", async () => {
const expectedContents = {
contents: ["Primary brand color"],
};
await testHover(pkgImportUri, position(4, 19), expectedContents);
});
});
4 changes: 4 additions & 0 deletions fixtures/e2e/pkg-import/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/*
!node_modules/my-components
!node_modules/@my-scope
3 changes: 3 additions & 0 deletions fixtures/e2e/pkg-import/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pkg-import

https://sass-lang.com/blog/announcing-pkg-importers/

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

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

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

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

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

15 changes: 15 additions & 0 deletions fixtures/e2e/pkg-import/node_modules/my-components/package.json

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

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

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

230 changes: 230 additions & 0 deletions fixtures/e2e/pkg-import/package-lock.json

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

13 changes: 13 additions & 0 deletions fixtures/e2e/pkg-import/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "pkg-import",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"description": "Test using the pgk import from a module",
"scripts": {
"test": "node --test sass.test.js"
},
"devDependencies": {
"sass": "^1.71.0"
}
}
20 changes: 20 additions & 0 deletions fixtures/e2e/pkg-import/sass.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const assert = require("node:assert");
const { test } = require("node:test");
const sass = require("sass");

test("noscope", () => {
const css = sass.compile("src/styles.scss", {
importers: [new sass.NodePackageImporter()],
});
assert.ok(css);
assert.match(css.css, /color: green/);
});

test("scope", () => {
const css = sass.compile("src/scoped.scss", {
importers: [new sass.NodePackageImporter()],
});
assert.ok(css);
assert.match(css.css, /color: green/);
});
Loading
Loading