diff --git a/LICENSE b/LICENSE index 2c4f2c4..66b6e05 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 rollup-plugin-sass maintainers (see './MAINTAINERS' file) +Copyright (c) 2016 rollup-plugin-sass maintainers (see './humans.txt') Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 243110c..aaee89c 100644 --- a/README.md +++ b/README.md @@ -155,11 +155,7 @@ sass({ }) ``` -## Maintainers - -- [ElyCruz](https://github.com/elycruz) - ## License -[MIT](./LICENSE) © 2022 [elycruz](https://github.com/elycruz), -© 2016 [BinRui.Guan](mailto:differui@gmail.com) +[MIT](./LICENSE) [elycruz](https://github.com/elycruz), +[BinRui.Guan](mailto:differui@gmail.com) diff --git a/MAINTAINERS b/humans.txt similarity index 81% rename from MAINTAINERS rename to humans.txt index 4633d31..14daa02 100644 --- a/MAINTAINERS +++ b/humans.txt @@ -1,8 +1,5 @@ -# Maintainers +# Maintainers/Authors 2022 Ely De La Cruz (https://github.com/elycruz) - -# Legacy - 2016 BinRui.Guan - Author 2016 Thomas Ghysels (https://github.com/thgh) diff --git a/package-lock.json b/package-lock.json index b3d6b4e..7ebfd41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup-plugin-sass", - "version": "1.2.13", + "version": "1.2.14", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rollup-plugin-sass", - "version": "1.2.13", + "version": "1.2.14", "license": "MIT", "dependencies": { "@rollup/pluginutils": "^3.1.0", @@ -23,8 +23,10 @@ "coveralls": "^3.1.1", "downlevel-dts": "^0.10.0", "eslint": "^7.32.0", + "icss-utils": "^5.1.0", "jsdom": "^17.0.0", "nyc": "^15.1.0", + "postcss": "^8.4.16", "rollup": "^1.32.1", "sinon": "^7.2.2", "ts-node": "^10.9.1", @@ -3016,6 +3018,18 @@ "node": ">=0.10.0" } }, + "node_modules/icss-utils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz", + "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==", + "dev": true, + "engines": { + "node": "^10 || ^12 || >= 14" + }, + "peerDependencies": { + "postcss": "^8.1.0" + } + }, "node_modules/ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -3821,6 +3835,18 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "node_modules/nanoid": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -4492,6 +4518,30 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/postcss": { + "version": "8.4.16", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", + "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + } + ], + "dependencies": { + "nanoid": "^3.3.4", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -5037,6 +5087,15 @@ "node": ">=0.10.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/spawn-wrap": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", @@ -8110,6 +8169,13 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "icss-utils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz", + "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==", + "dev": true, + "requires": {} + }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -8719,6 +8785,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "nanoid": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "dev": true + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -9217,6 +9289,17 @@ "irregular-plurals": "^3.3.0" } }, + "postcss": { + "version": "8.4.16", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", + "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", + "dev": true, + "requires": { + "nanoid": "^3.3.4", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" + } + }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -9600,6 +9683,12 @@ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, + "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 + }, "spawn-wrap": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", diff --git a/package.json b/package.json index 784a3b1..6f2c90d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-sass", - "version": "1.2.13", + "version": "1.2.14", "description": "Rollup Sass files.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -70,8 +70,10 @@ "coveralls": "^3.1.1", "downlevel-dts": "^0.10.0", "eslint": "^7.32.0", + "icss-utils": "^5.1.0", "jsdom": "^17.0.0", "nyc": "^15.1.0", + "postcss": "^8.4.16", "rollup": "^1.32.1", "sinon": "^7.2.2", "ts-node": "^10.9.1", diff --git a/src/index.ts b/src/index.ts index a77089d..3095179 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,10 +88,9 @@ const MATCH_SASS_FILENAME_RE = /\.sass$/, 'See https://github.com/differui/rollup-plugin-sass#processor'); } const outCss = result.css; + delete result.css; const restExports = Object.keys(result).reduce((agg, name) => - name === 'css' ? agg : agg + `export const ${name} = ${JSON.stringify(result[name])};\n` - , '' - ); + agg + `export const ${name} = ${JSON.stringify(result[name])};\n`, ''); return [outCss, restExports]; }) .then(([resolvedCss, restExports]) => { diff --git a/test/assets/actual_a--with-icss-exports.scss b/test/assets/actual_a--with-icss-exports.scss new file mode 100644 index 0000000..467dcf3 --- /dev/null +++ b/test/assets/actual_a--with-icss-exports.scss @@ -0,0 +1,12 @@ +$color_red: red; +$color_blue: blue; + +body { + color: $color_red; + background: $color_blue; +} + +:export { + color: $color_red; + color2: $color_blue; +} diff --git a/test/assets/expect_a--with-icss-exports.css b/test/assets/expect_a--with-icss-exports.css new file mode 100644 index 0000000..f480c91 --- /dev/null +++ b/test/assets/expect_a--with-icss-exports.css @@ -0,0 +1 @@ +body{color:red;background:blue} diff --git a/test/fixtures/processor-promise/with-icss-exports.js b/test/fixtures/processor-promise/with-icss-exports.js new file mode 100644 index 0000000..2cf74a5 --- /dev/null +++ b/test/fixtures/processor-promise/with-icss-exports.js @@ -0,0 +1,6 @@ +import actualA2, {color, color2} from '../../assets/actual_a--with-icss-exports.scss'; +import actualB from '../../assets/actual_b.scss'; + +export {color, color2}; + +export default actualA2 + actualB; diff --git a/test/index.test.ts b/test/index.test.ts index 52999dc..2aa7fd1 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -7,6 +7,8 @@ import * as sassJs from 'sass'; import sass from '../src/index'; import {SassOptions} from "../src/types"; import {error} from "../src/utils"; +import postcss from "postcss"; +import {extractICSS} from "icss-utils"; const repoRoot = path.join(__dirname, '../'), @@ -39,7 +41,7 @@ const repoRoot = path.join(__dirname, '../'), unwrap = output => output[0].code; -let expectA, expectB, expectC, expectD, expectE; +let expectA, expectA2, expectB, expectC, expectD, expectE; test.before(async () => { const mkDir = () => fs.mkdir(tmpDir); @@ -48,6 +50,7 @@ test.before(async () => { .then(mkDir, mkDir) .then(() => Promise.all([ 'test/assets/expect_a.css', + 'test/assets/expect_a--with-icss-exports.css', 'test/assets/expect_b.css', 'test/assets/expect_c.css', 'test/assets/expect_d.css', @@ -55,8 +58,9 @@ test.before(async () => { ] .map(xs => fs.readFile(xs).then(buff => buff.toString())) )) - .then(([a, b, c, d, e]) => { + .then(([a, a2, b, c, d, e]) => { expectA = squash(a); + expectA2 = squash(a2); expectB = squash(b); expectC = squash(c); expectD = squash(d); @@ -266,7 +270,7 @@ test('should processor return as object', async t => { t.true(squash(unwrap(output)).indexOf('bar') > -1); }); -test('should processor return as promise', async t => { +test('should support processor return type `Promise`', async t => { const outputBundle = await rollup({ input: 'test/fixtures/processor-promise/index.js', plugins: [ @@ -283,6 +287,33 @@ test('should processor return as promise', async t => { t.true(squash(unwrap(output)).indexOf(expectB) > -1); }); +test('should support processor return type `Promise<{css: string, icssExport: {}, icssImport: {}}}>', async t => { + const outputBundle = await rollup({ + input: 'test/fixtures/processor-promise/with-icss-exports.js', + plugins: [ + sass({ + processor: (css) => new Promise((resolve, reject) => { + const pcssRootNodeRslt = postcss.parse(css), + extractedIcss = extractICSS(pcssRootNodeRslt, true), + cleanedCss = pcssRootNodeRslt.toString(), + out = Object.assign({}, extractedIcss.icssExports, { + css: cleanedCss, + }); + // console.table(extractedIcss); + // console.log(out); + resolve(out); + }), + options: sassOptions, + }), + ], + }), + {output} = await outputBundle.generate(generateOptions), + rslt = squash(unwrap(output)); + + t.true(rslt.includes(expectA2)); + t.true(rslt.includes(expectB)); +}); + test('should processor throw error', async t => { await t.throwsAsync(async () => rollup({ input: 'test/fixtures/processor-error/index.js',