diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b1374e..d904c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # True Changelog +## Unreleased + +- FEATURE: If True `sass` option is not specified, True will automatically + attempt to use `embedded-sass`, then `sass`. + [#290](https://github.com/oddbird/true/issues/290) +- INTERNAL: Add `sass` and `sass-embedded` as optional peer-dependencies. +- INTERNAL: Update dependencies + ## 8.0.0 (02/23/24) - FEATURE: Add True `sass` option (`string` or Sass implementation instance, diff --git a/README.md b/README.md index 5cf3753..4216c60 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ In command line: npm install --save-dev sass-true ``` +True requires Dart Sass v1.45.0 or higher, so install it if you haven't already: + +```bash +npm install --save-dev sass-embedded # or `sass` +``` + Import in your test directory, like any other Sass file: @@ -155,11 +161,11 @@ when upgrading from an older version of True. npm install --save-dev sass-true ``` -2. [Optional] Install Dart Sass (`sass` or `sass-embedded`), if not already +2. [Optional] Install Dart Sass (`sass-embedded` or `sass`), if not already installed. ```bash - npm install --save-dev sass + npm install --save-dev sass-embedded # or `sass` ``` 3. Write some Sass tests in `test/test.scss` (see above). @@ -203,8 +209,8 @@ should be usable in the same way: just pass your test runner's `describe` and The `sass` option is an optional string name of a Dart Sass implementation installed in the current environment (e.g. `'embedded-sass'` or `'sass'`), or a -Dart Sass implementation instance itself. If none is provided, this defaults to -`'sass'`. +Dart Sass implementation instance itself. If none is provided, True will attempt +to detect which implementation is available, starting with `sass-embedded`. If True can't parse the CSS output, it'll give you some context lines of CSS as part of the error message. This context will likely be helpful in understanding diff --git a/package.json b/package.json index d7ec4f9..3308420 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,18 @@ "jest-diff": "^29.7.0", "lodash": "^4.17.21" }, + "peerDependencies": { + "sass": ">=1.45.0", + "sass-embedded": ">=1.45.0" + }, + "peerDependenciesMeta": { + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + } + }, "devDependencies": { "@babel/core": "^7.25.2", "@babel/preset-env": "^7.25.4", diff --git a/src/index.ts b/src/index.ts index d5a316a..97334c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,6 +66,16 @@ export type Rule = CssCommentAST | CssRuleAST | CssAtRuleAST; export type Parser = (rule: Rule, ctx: Context) => Parser; +const loadSass = function (sassPkg: string) { + try { + // eslint-disable-next-line global-require + return require(sassPkg); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (err) { + throw new Error(`Cannot find Dart Sass (\`${sassPkg}\`) dependency.`); + } +}; + export const runSass = function ( trueOptions: TrueOptions, src: string, @@ -103,14 +113,23 @@ export const runSass = function ( let compiler; if (trueOpts.sass && typeof trueOpts.sass !== 'string') { compiler = trueOpts.sass; + } else if (typeof trueOpts.sass === 'string') { + compiler = loadSass(trueOpts.sass); } else { - const sassPkg = trueOpts.sass ?? 'sass'; try { - // eslint-disable-next-line global-require - compiler = require(sassPkg); + // try sass-embedded before sass + compiler = loadSass('sass-embedded'); // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - throw new Error(`Cannot find Dart Sass (\`${sassPkg}\`) dependency.`); + } catch (e1) { + /* istanbul ignore next */ + try { + compiler = loadSass('sass'); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (e2) { + throw new Error( + 'Cannot find Dart Sass (`sass-embedded` or `sass`) dependency.', + ); + } } } diff --git a/yarn.lock b/yarn.lock index 024f672..0c63ab3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1458,9 +1458,9 @@ __metadata: linkType: hard "@eslint-community/regexpp@npm:^4.10.0, @eslint-community/regexpp@npm:^4.6.1": - version: 4.11.1 - resolution: "@eslint-community/regexpp@npm:4.11.1" - checksum: 10/934b6d3588c7f16b18d41efec4fdb89616c440b7e3256b8cb92cfd31ae12908600f2b986d6c1e61a84cbc10256b1dd3448cd1eec79904bd67ac365d0f1aba2e2 + version: 4.11.0 + resolution: "@eslint-community/regexpp@npm:4.11.0" + checksum: 10/f053f371c281ba173fe6ee16dbc4fe544c84870d58035ccca08dba7f6ce1830d895ce3237a0db89ba37616524775dca82f1c502066b58e2d5712d7f87f5ba17c languageName: node linkType: hard @@ -2038,11 +2038,11 @@ __metadata: linkType: hard "@types/node@npm:*": - version: 22.7.4 - resolution: "@types/node@npm:22.7.4" + version: 22.5.4 + resolution: "@types/node@npm:22.5.4" dependencies: undici-types: "npm:~6.19.2" - checksum: 10/19ddab80c4eba2253c855ed67c9bbc47417183049d01e59010a738bd80d47338bab79fd1f44ae51516bd63a1db4bf21ddb38b16bf6401a2e93252068ec52e88b + checksum: 10/d46e0abf437b36bdf89011287aa43873d68ea6f2521a11b5c9a033056fd0d07af36daf51439010e8d41c62c55d0b00e9b5e09ed00bb2617723f73f28a873903a languageName: node linkType: hard @@ -2345,9 +2345,9 @@ __metadata: linkType: hard "ansi-regex@npm:^6.0.1": - version: 6.1.0 - resolution: "ansi-regex@npm:6.1.0" - checksum: 10/495834a53b0856c02acd40446f7130cb0f8284f4a39afdab20d5dc42b2e198b1196119fe887beed8f9055c4ff2055e3b2f6d4641d0be018cdfb64fedf6fc1aac + version: 6.0.1 + resolution: "ansi-regex@npm:6.0.1" + checksum: 10/1ff8b7667cded1de4fa2c9ae283e979fc87036864317da86a2e546725f96406746411d0d85e87a2d12fa5abd715d90006de7fa4fa0477c92321ad3b4c7d4e169 languageName: node linkType: hard @@ -2578,9 +2578,9 @@ __metadata: linkType: hard "b4a@npm:^1.6.4": - version: 1.6.7 - resolution: "b4a@npm:1.6.7" - checksum: 10/1ac056e3bce378d4d3e570e57319360a9d3125ab6916a1921b95bea33d9ee646698ebc75467561fd6fcc80ff697612124c89bb9b95e80db94c6dc23fcb977705 + version: 1.6.6 + resolution: "b4a@npm:1.6.6" + checksum: 10/6154a36bd78b53ecd2843a829352532a1bf9fc8081dab339ba06ca3c9ffcf25d340c3b18fe4ba0fc17a546a54c1ed814cea92cd6b895f6bd2837ca4ee0fc9f52 languageName: node linkType: hard @@ -2724,9 +2724,9 @@ __metadata: linkType: hard "bare-events@npm:^2.2.0": - version: 2.5.0 - resolution: "bare-events@npm:2.5.0" - checksum: 10/a0830af0e1d47c74878109bd35cd9118305820c823d43bca2802e131ba7652bb5fdd94fb0c40a31313f440ed3964ab9b35394b3794437c238519bfbcaa52a8f8 + version: 2.4.2 + resolution: "bare-events@npm:2.4.2" + checksum: 10/c1006ad13b7e62a412466d4eac8466b4ceb46ce84a5e2fc164cd4b10edaaa5016adc684147134b67a6a3865aaf5aa007191647bdb5dbf859b1d5735d2a9ddf3b languageName: node linkType: hard @@ -2821,16 +2821,16 @@ __metadata: linkType: hard "browserslist@npm:^4.23.1, browserslist@npm:^4.23.3": - version: 4.24.0 - resolution: "browserslist@npm:4.24.0" + version: 4.23.3 + resolution: "browserslist@npm:4.23.3" dependencies: - caniuse-lite: "npm:^1.0.30001663" - electron-to-chromium: "npm:^1.5.28" + caniuse-lite: "npm:^1.0.30001646" + electron-to-chromium: "npm:^1.5.4" node-releases: "npm:^2.0.18" update-browserslist-db: "npm:^1.1.0" bin: browserslist: cli.js - checksum: 10/26c1b8ba257a0b51b102080ba9d42945af2abaa8c4cf6da21cd47b3f123fc1e81640203b293214356c2c17d9d265bb3a5ed428b6d302f383576dd6ce8fd5036c + checksum: 10/e266d18c6c6c5becf9a1a7aa264477677b9796387972e8fce34854bb33dc1666194dc28389780e5dc6566e68a95e87ece2ce222e1c4ca93c2b75b61dfebd5f1c languageName: node linkType: hard @@ -2953,10 +2953,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.30001663": - version: 1.0.30001664 - resolution: "caniuse-lite@npm:1.0.30001664" - checksum: 10/ff237f6bbb59564d2a7219fe9a799a59692403115500f7548a77f1f6b82e33fd136375003f80c8df88a64048f699f9f917292ca4cac0dd8a789d2d35fba6269b +"caniuse-lite@npm:^1.0.30001646": + version: 1.0.30001658 + resolution: "caniuse-lite@npm:1.0.30001658" + checksum: 10/e3baf3c68a4f00e3eab169e0952fde7100b3ab99491074a24b361a97054eed1bca3bfdfb0d9ae4b326bdb660a370032d9130a241608d484296f4b3bcebe540fb languageName: node linkType: hard @@ -3138,9 +3138,9 @@ __metadata: linkType: hard "cjs-module-lexer@npm:^1.0.0": - version: 1.4.1 - resolution: "cjs-module-lexer@npm:1.4.1" - checksum: 10/6e830a1e00a34d416949bbc1924f3e8da65cef4a6a09e2b7fa35722e2d1c34bf378d3baca987b698d1cbc3eb83e44b044039b4e82755c96f30e0f03d1d227637 + version: 1.4.0 + resolution: "cjs-module-lexer@npm:1.4.0" + checksum: 10/b041096749792526120d8b8756929f8ef5dd4596502a0e1013f857e3027acd6091915fea77037921d70ee1a99988a100d994d3d3c2e323b04dd4c5ffd516cf13 languageName: node linkType: hard @@ -3839,10 +3839,10 @@ __metadata: languageName: node linkType: hard -"electron-to-chromium@npm:^1.5.28": - version: 1.5.30 - resolution: "electron-to-chromium@npm:1.5.30" - checksum: 10/948d7931acd66a55edff9f6efe71235f26165cd780786e85cb7f6c8ace29d4784651fba791e0af8b386298261bf71fdbb4997d990b619c0a3610090348bf2234 +"electron-to-chromium@npm:^1.5.4": + version: 1.5.17 + resolution: "electron-to-chromium@npm:1.5.17" + checksum: 10/82b7b18e14652369a266540f6047a3777748230b9056dc536718235290d820e6129bd32b38571ae287cc3ba5703fc5020102601ba6f0821620028c8853a9c39d languageName: node linkType: hard @@ -4073,7 +4073,7 @@ __metadata: languageName: node linkType: hard -"escalade@npm:^3.1.1, escalade@npm:^3.2.0": +"escalade@npm:^3.1.1, escalade@npm:^3.1.2": version: 3.2.0 resolution: "escalade@npm:3.2.0" checksum: 10/9d7169e3965b2f9ae46971afa392f6e5a25545ea30f2e2dd99c9b0a95a3f52b5653681a84f5b2911a413ddad2d7a93d3514165072f349b5ffc59c75a899970d6 @@ -4156,14 +4156,14 @@ __metadata: linkType: hard "eslint-module-utils@npm:^2.8.1, eslint-module-utils@npm:^2.9.0": - version: 2.12.0 - resolution: "eslint-module-utils@npm:2.12.0" + version: 2.11.0 + resolution: "eslint-module-utils@npm:2.11.0" dependencies: debug: "npm:^3.2.7" peerDependenciesMeta: eslint: optional: true - checksum: 10/dd27791147eca17366afcb83f47d6825b6ce164abb256681e5de4ec1d7e87d8605641eb869298a0dbc70665e2446dbcc2f40d3e1631a9475dd64dd23d4ca5dee + checksum: 10/1ba42cf48c5f9ec3b76dfa42c16f1c24c10508313689425c05ccb1d0eaa34bdc5c5b9c0c033cd402e9c429666bd3eb8c6d0c66565b0c00949fae743ad3643c95 languageName: node linkType: hard @@ -4451,9 +4451,9 @@ __metadata: linkType: hard "fast-uri@npm:^3.0.1": - version: 3.0.2 - resolution: "fast-uri@npm:3.0.2" - checksum: 10/99224f0198e24a4072b9a8a25fc5fa553aa0153e00d29d41272096a6d97be417c9faa5978682868cbba46b09066dc9348563c7244057f3818067e7737db153b2 + version: 3.0.1 + resolution: "fast-uri@npm:3.0.1" + checksum: 10/e8ee4712270de0d29eb0fbf41ffad0ac80952e8797be760e8bb62c4707f08f50a86fe2d7829681ca133c07d6eb4b4a75389a5fc36674c5b254a3ac0891a68fc7 languageName: node linkType: hard @@ -4787,11 +4787,11 @@ __metadata: linkType: hard "get-tsconfig@npm:^4.7.5": - version: 4.8.1 - resolution: "get-tsconfig@npm:4.8.1" + version: 4.8.0 + resolution: "get-tsconfig@npm:4.8.0" dependencies: resolve-pkg-maps: "npm:^1.0.0" - checksum: 10/3fb5a8ad57b9633eaea085d81661e9e5c9f78b35d8f8689eaf8b8b45a2a3ebf3b3422266d4d7df765e308cc1e6231648d114803ab3d018332e29916f2c1de036 + checksum: 10/aac6d98894bdb8b9f320f5c4953f9a89d11b1cbb15cc95447abe00366dc5fcda6dbce214f2e4572b1b835ab55c4f35f004b219c3d17e07c5ddca44ef9e3858d2 languageName: node linkType: hard @@ -5425,11 +5425,11 @@ __metadata: linkType: hard "is-bun-module@npm:^1.0.2": - version: 1.2.1 - resolution: "is-bun-module@npm:1.2.1" + version: 1.1.0 + resolution: "is-bun-module@npm:1.1.0" dependencies: semver: "npm:^7.6.3" - checksum: 10/1c2cbcf1a76991add1b640d2d7fe09848e8697a76f96e1289dff44133a48c97f5dc601d4a66d3f3a86217a77178d72d33d10d0c9e14194e58e70ec8df3eae41a + checksum: 10/f6d2b16291ee7e31fdc9fb8fd267ac40b7caeef60c607bff0efb1f686fc7851d7c8266e33ff8d2fb9ce3e5d7a0ff6177c1d9ff3f5bfd9efd3db876ef4bb8fdea languageName: node linkType: hard @@ -7597,9 +7597,9 @@ __metadata: linkType: hard "package-json-from-dist@npm:^1.0.0": - version: 1.0.1 - resolution: "package-json-from-dist@npm:1.0.1" - checksum: 10/58ee9538f2f762988433da00e26acc788036914d57c71c246bf0be1b60cdbd77dd60b6a3e1a30465f0b248aeb80079e0b34cb6050b1dfa18c06953bb1cbc7602 + version: 1.0.0 + resolution: "package-json-from-dist@npm:1.0.0" + checksum: 10/ac706ec856a5a03f5261e4e48fa974f24feb044d51f84f8332e2af0af04fbdbdd5bbbfb9cbbe354190409bc8307c83a9e38c6672c3c8855f709afb0006a009ea languageName: node linkType: hard @@ -7837,7 +7837,7 @@ __metadata: languageName: node linkType: hard -"postcss-resolve-nested-selector@npm:^0.1.6": +"postcss-resolve-nested-selector@npm:^0.1.4, postcss-resolve-nested-selector@npm:^0.1.6": version: 0.1.6 resolution: "postcss-resolve-nested-selector@npm:0.1.6" checksum: 10/85453901afe2a4db497b4e0d2c9cf2a097a08fa5d45bc646547025176217050334e423475519a1e6c74a1f31ade819d16bb37a39914e5321e250695ee3feea14 @@ -7862,7 +7862,7 @@ __metadata: languageName: node linkType: hard -"postcss-selector-parser@npm:^6.1.2": +"postcss-selector-parser@npm:^6.1.1, postcss-selector-parser@npm:^6.1.2": version: 6.1.2 resolution: "postcss-selector-parser@npm:6.1.2" dependencies: @@ -7976,12 +7976,12 @@ __metadata: linkType: hard "pump@npm:^3.0.0": - version: 3.0.2 - resolution: "pump@npm:3.0.2" + version: 3.0.0 + resolution: "pump@npm:3.0.0" dependencies: end-of-stream: "npm:^1.1.0" once: "npm:^1.3.1" - checksum: 10/e0c4216874b96bd25ddf31a0b61a5613e26cc7afa32379217cf39d3915b0509def3565f5f6968fafdad2894c8bbdbd67d340e84f3634b2a29b950cffb6442d9f + checksum: 10/e42e9229fba14732593a718b04cb5e1cfef8254544870997e0ecd9732b189a48e1256e4e5478148ecb47c8511dca2b09eae56b4d0aad8009e6fac8072923cfc9 languageName: node linkType: hard @@ -8156,11 +8156,11 @@ __metadata: linkType: hard "regenerate-unicode-properties@npm:^10.1.0": - version: 10.2.0 - resolution: "regenerate-unicode-properties@npm:10.2.0" + version: 10.1.1 + resolution: "regenerate-unicode-properties@npm:10.1.1" dependencies: regenerate: "npm:^1.4.2" - checksum: 10/9150eae6fe04a8c4f2ff06077396a86a98e224c8afad8344b1b656448e89e84edcd527e4b03aa5476774129eb6ad328ed684f9c1459794a935ec0cc17ce14329 + checksum: 10/b855152efdcca0ecc37ceb0cb6647a544344555fc293af3b57191b918e1bc9c95ee404a9a64a1d692bf66d45850942c29d93f2740c0d1980d3a8ea2ca63b184e languageName: node linkType: hard @@ -8788,6 +8788,14 @@ __metadata: stylelint: "npm:^16.9.0" stylelint-config-standard-scss: "npm:^13.1.0" typescript: "npm:^5.6.2" + peerDependencies: + sass: ">=1.45.0" + sass-embedded: ">=1.45.0" + peerDependenciesMeta: + sass: + optional: true + sass-embedded: + optional: true languageName: unknown linkType: soft @@ -9218,8 +9226,8 @@ __metadata: linkType: hard "streamx@npm:^2.12.0, streamx@npm:^2.12.5, streamx@npm:^2.13.2, streamx@npm:^2.14.0": - version: 2.20.1 - resolution: "streamx@npm:2.20.1" + version: 2.20.0 + resolution: "streamx@npm:2.20.0" dependencies: bare-events: "npm:^2.2.0" fast-fifo: "npm:^1.3.2" @@ -9228,7 +9236,7 @@ __metadata: dependenciesMeta: bare-events: optional: true - checksum: 10/3c69a48c4f397fb8a9460d1a780ece352849a4719a8938a866879dd1773098121882c3c2b99b9c7f605a123461d8ab2e652fd22c13ccda18f79e234e78ec7ed7 + checksum: 10/635fe73c6cacc95a9932e338905781ce1aaa200b3a4935afaa873ff69be867f820e7e0dfe98d1b553b5ed1f5311a36e8158a6b748e41f3bd15a6a29ecc33b97d languageName: node linkType: hard @@ -9462,19 +9470,19 @@ __metadata: linkType: hard "stylelint-scss@npm:^6.4.0": - version: 6.7.0 - resolution: "stylelint-scss@npm:6.7.0" + version: 6.5.1 + resolution: "stylelint-scss@npm:6.5.1" dependencies: css-tree: "npm:2.3.1" is-plain-object: "npm:5.0.0" known-css-properties: "npm:^0.34.0" postcss-media-query-parser: "npm:^0.2.3" - postcss-resolve-nested-selector: "npm:^0.1.6" - postcss-selector-parser: "npm:^6.1.2" + postcss-resolve-nested-selector: "npm:^0.1.4" + postcss-selector-parser: "npm:^6.1.1" postcss-value-parser: "npm:^4.2.0" peerDependencies: stylelint: ^16.0.2 - checksum: 10/f2173a46f2db090b4444de9e9a00eb4e55d7b77c19d0e20a77923de0e16a25725115352be37e98c55780689f68625dd161dab310b6395d4efe5be4abec66557e + checksum: 10/a43d2231cc4dbd1fba5dfe8d1c26bb8cd95ad67396040ed00e5844141a8ae7fdefce6957c5fff6b2fb0091a5eb5f16d4ed6d33d4d02c623161d5f11c3c0bd57e languageName: node linkType: hard @@ -9640,11 +9648,11 @@ __metadata: linkType: hard "text-decoder@npm:^1.1.0": - version: 1.2.0 - resolution: "text-decoder@npm:1.2.0" + version: 1.1.1 + resolution: "text-decoder@npm:1.1.1" dependencies: b4a: "npm:^1.6.4" - checksum: 10/56e5b2f5278ef7dba29e5195f715c307819c523accab5d1470128566c5e5a0918b8d22cf7efc72ad34a537929f0b18d7588e287e94c0bb2affe171ec631f821f + checksum: 10/c6981b93850daeafc8bd1dbd8f984d4fb2d14632f450de0892692b5bbee2d2f4cbef8a807142527370649fd357f58491ede4915d43669eca624cb52b8dd247b6 languageName: node linkType: hard @@ -9987,9 +9995,9 @@ __metadata: linkType: hard "unicode-canonical-property-names-ecmascript@npm:^2.0.0": - version: 2.0.1 - resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.1" - checksum: 10/3c3dabdb1d22aef4904399f9e810d0b71c0b12b3815169d96fac97e56d5642840c6071cf709adcace2252bc6bb80242396c2ec74b37224eb015c5f7aca40bad7 + version: 2.0.0 + resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0" + checksum: 10/39be078afd014c14dcd957a7a46a60061bc37c4508ba146517f85f60361acf4c7539552645ece25de840e17e293baa5556268d091ca6762747fdd0c705001a45 languageName: node linkType: hard @@ -10004,9 +10012,9 @@ __metadata: linkType: hard "unicode-match-property-value-ecmascript@npm:^2.1.0": - version: 2.2.0 - resolution: "unicode-match-property-value-ecmascript@npm:2.2.0" - checksum: 10/9fd53c657aefe5d3cb8208931b4c34fbdb30bb5aa9a6c6bf744e2f3036f00b8889eeaf30cb55a873b76b6ee8b5801ea770e1c49b3352141309f58f0ebb3011d8 + version: 2.1.0 + resolution: "unicode-match-property-value-ecmascript@npm:2.1.0" + checksum: 10/06661bc8aba2a60c7733a7044f3e13085808939ad17924ffd4f5222a650f88009eb7c09481dc9c15cfc593d4ad99bd1cde8d54042733b335672591a81c52601c languageName: node linkType: hard @@ -10064,16 +10072,16 @@ __metadata: linkType: hard "update-browserslist-db@npm:^1.1.0": - version: 1.1.1 - resolution: "update-browserslist-db@npm:1.1.1" + version: 1.1.0 + resolution: "update-browserslist-db@npm:1.1.0" dependencies: - escalade: "npm:^3.2.0" - picocolors: "npm:^1.1.0" + escalade: "npm:^3.1.2" + picocolors: "npm:^1.0.1" peerDependencies: browserslist: ">= 4.21.0" bin: update-browserslist-db: cli.js - checksum: 10/7678dd8609750588d01aa7460e8eddf2ff9d16c2a52fb1811190e0d056390f1fdffd94db3cf8fb209cf634ab4fa9407886338711c71cc6ccade5eeb22b093734 + checksum: 10/d70b9efeaf4601aadb1a4f6456a7a5d9118e0063d995866b8e0c5e0cf559482671dab6ce7b079f9536b06758a344fbd83f974b965211e1c6e8d1958540b0c24c languageName: node linkType: hard