From 86e7be3c73847fd7a983c0f69837124eb5bb9407 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Fri, 16 Feb 2024 17:53:30 +0100 Subject: [PATCH] test: add fixture for pkg import syntax --- .gitignore | 1 + fixtures/pkg-import/.gitignore | 4 + fixtures/pkg-import/README.md | 3 + .../@my-scope/my-components/index.js | 1 + .../@my-scope/my-components/package.json | 15 ++ .../my-components/styles/colors.scss | 3 + .../@my-scope/my-components/styles/index.scss | 1 + .../node_modules/my-components/index.js | 1 + .../node_modules/my-components/package.json | 15 ++ .../my-components/styles/colors.scss | 3 + .../my-components/styles/index.scss | 1 + fixtures/pkg-import/package-lock.json | 230 ++++++++++++++++++ fixtures/pkg-import/package.json | 13 + fixtures/pkg-import/sass.test.js | 20 ++ fixtures/pkg-import/src/scoped.scss | 5 + fixtures/pkg-import/src/styles.scss | 5 + 16 files changed, 321 insertions(+) create mode 100644 fixtures/pkg-import/.gitignore create mode 100644 fixtures/pkg-import/README.md create mode 100644 fixtures/pkg-import/node_modules/@my-scope/my-components/index.js create mode 100644 fixtures/pkg-import/node_modules/@my-scope/my-components/package.json create mode 100644 fixtures/pkg-import/node_modules/@my-scope/my-components/styles/colors.scss create mode 100644 fixtures/pkg-import/node_modules/@my-scope/my-components/styles/index.scss create mode 100644 fixtures/pkg-import/node_modules/my-components/index.js create mode 100644 fixtures/pkg-import/node_modules/my-components/package.json create mode 100644 fixtures/pkg-import/node_modules/my-components/styles/colors.scss create mode 100644 fixtures/pkg-import/node_modules/my-components/styles/index.scss create mode 100644 fixtures/pkg-import/package-lock.json create mode 100644 fixtures/pkg-import/package.json create mode 100644 fixtures/pkg-import/sass.test.js create mode 100644 fixtures/pkg-import/src/scoped.scss create mode 100644 fixtures/pkg-import/src/styles.scss diff --git a/.gitignore b/.gitignore index f6191ccc..20a1575a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ npm-debug.log* node_modules/ !fixtures/e2e/node_modules !fixtures/e2e/completion/node_modules +!fixtures/pkg-import/node_modules # Compiled and temporary files dist/ diff --git a/fixtures/pkg-import/.gitignore b/fixtures/pkg-import/.gitignore new file mode 100644 index 00000000..9a51caed --- /dev/null +++ b/fixtures/pkg-import/.gitignore @@ -0,0 +1,4 @@ +dist/ +node_modules/* +!node_modules/my-components +!node_modules/@my-scope diff --git a/fixtures/pkg-import/README.md b/fixtures/pkg-import/README.md new file mode 100644 index 00000000..6039497f --- /dev/null +++ b/fixtures/pkg-import/README.md @@ -0,0 +1,3 @@ +# pkg-import + +https://sass-lang.com/blog/announcing-pkg-importers/ diff --git a/fixtures/pkg-import/node_modules/@my-scope/my-components/index.js b/fixtures/pkg-import/node_modules/@my-scope/my-components/index.js new file mode 100644 index 00000000..184dfcc9 --- /dev/null +++ b/fixtures/pkg-import/node_modules/@my-scope/my-components/index.js @@ -0,0 +1 @@ +console.log("Hello, World!"); diff --git a/fixtures/pkg-import/node_modules/@my-scope/my-components/package.json b/fixtures/pkg-import/node_modules/@my-scope/my-components/package.json new file mode 100644 index 00000000..7b879ee1 --- /dev/null +++ b/fixtures/pkg-import/node_modules/@my-scope/my-components/package.json @@ -0,0 +1,15 @@ +{ + "name": "@my-scope/my-components", + "version": "1.0.0", + "description": "", + "main": "index.js", + "exports": { + ".": { + "sass": "./styles/index.scss", + "default": "./index.js" + }, + "./*.scss": { + "sass": "./styles/*.scss" + } + } +} diff --git a/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/colors.scss b/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/colors.scss new file mode 100644 index 00000000..48b07207 --- /dev/null +++ b/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/colors.scss @@ -0,0 +1,3 @@ +/// Primary brand color +/// @type {Color} +$color-primary: green; diff --git a/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/index.scss b/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/index.scss new file mode 100644 index 00000000..8166996f --- /dev/null +++ b/fixtures/pkg-import/node_modules/@my-scope/my-components/styles/index.scss @@ -0,0 +1 @@ +@forward "./colors.scss"; diff --git a/fixtures/pkg-import/node_modules/my-components/index.js b/fixtures/pkg-import/node_modules/my-components/index.js new file mode 100644 index 00000000..184dfcc9 --- /dev/null +++ b/fixtures/pkg-import/node_modules/my-components/index.js @@ -0,0 +1 @@ +console.log("Hello, World!"); diff --git a/fixtures/pkg-import/node_modules/my-components/package.json b/fixtures/pkg-import/node_modules/my-components/package.json new file mode 100644 index 00000000..ce8f4c74 --- /dev/null +++ b/fixtures/pkg-import/node_modules/my-components/package.json @@ -0,0 +1,15 @@ +{ + "name": "my-components", + "version": "1.0.0", + "description": "", + "main": "index.js", + "exports": { + ".": { + "sass": "./styles/index.scss", + "default": "./index.js" + }, + "./*.scss": { + "sass": "./styles/*.scss" + } + } +} diff --git a/fixtures/pkg-import/node_modules/my-components/styles/colors.scss b/fixtures/pkg-import/node_modules/my-components/styles/colors.scss new file mode 100644 index 00000000..48b07207 --- /dev/null +++ b/fixtures/pkg-import/node_modules/my-components/styles/colors.scss @@ -0,0 +1,3 @@ +/// Primary brand color +/// @type {Color} +$color-primary: green; diff --git a/fixtures/pkg-import/node_modules/my-components/styles/index.scss b/fixtures/pkg-import/node_modules/my-components/styles/index.scss new file mode 100644 index 00000000..8166996f --- /dev/null +++ b/fixtures/pkg-import/node_modules/my-components/styles/index.scss @@ -0,0 +1 @@ +@forward "./colors.scss"; diff --git a/fixtures/pkg-import/package-lock.json b/fixtures/pkg-import/package-lock.json new file mode 100644 index 00000000..71dffaf1 --- /dev/null +++ b/fixtures/pkg-import/package-lock.json @@ -0,0 +1,230 @@ +{ + "name": "pkg-import", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "pkg-import", + "version": "1.0.0", + "devDependencies": { + "sass": "^1.71.0" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/immutable": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.5.tgz", + "integrity": "sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw==", + "dev": true + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/sass": { + "version": "1.71.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.71.0.tgz", + "integrity": "sha512-HKKIKf49Vkxlrav3F/w6qRuPcmImGVbIXJ2I3Kg0VMA+3Bav+8yE9G5XmP5lMj6nl4OlqbPftGAscNaNu28b8w==", + "dev": true, + "dependencies": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + }, + "bin": { + "sass": "sass.js" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + } + } +} diff --git a/fixtures/pkg-import/package.json b/fixtures/pkg-import/package.json new file mode 100644 index 00000000..3498ad09 --- /dev/null +++ b/fixtures/pkg-import/package.json @@ -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" + } +} diff --git a/fixtures/pkg-import/sass.test.js b/fixtures/pkg-import/sass.test.js new file mode 100644 index 00000000..b0da0b8a --- /dev/null +++ b/fixtures/pkg-import/sass.test.js @@ -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/); +}); diff --git a/fixtures/pkg-import/src/scoped.scss b/fixtures/pkg-import/src/scoped.scss new file mode 100644 index 00000000..2b244732 --- /dev/null +++ b/fixtures/pkg-import/src/scoped.scss @@ -0,0 +1,5 @@ +@use "pkg:@my-scope/my-components/colors"; + +button { + color: colors.$color-primary; +} diff --git a/fixtures/pkg-import/src/styles.scss b/fixtures/pkg-import/src/styles.scss new file mode 100644 index 00000000..eb301d10 --- /dev/null +++ b/fixtures/pkg-import/src/styles.scss @@ -0,0 +1,5 @@ +@use "pkg:my-components/colors"; + +button { + color: colors.$color-primary; +}