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

Issue #72 exports sass vars #104

Merged
merged 2 commits into from
Sep 17, 2022
Merged
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 1 addition & 4 deletions MAINTAINERS → humans.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Maintainers
# Maintainers/Authors

2022 Ely De La Cruz (https://github.com/elycruz)

# Legacy

2016 BinRui.Guan <differui@gmail.com> - Author
2016 Thomas Ghysels (https://github.com/thgh)
93 changes: 91 additions & 2 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
12 changes: 12 additions & 0 deletions test/assets/actual_a--with-icss-exports.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$color_red: red;
$color_blue: blue;

body {
color: $color_red;
background: $color_blue;
}

:export {
color: $color_red;
color2: $color_blue;
}
1 change: 1 addition & 0 deletions test/assets/expect_a--with-icss-exports.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{color:red;background:blue}
6 changes: 6 additions & 0 deletions test/fixtures/processor-promise/with-icss-exports.js
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 34 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '../'),

Expand Down Expand Up @@ -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);
Expand All @@ -48,15 +50,17 @@ 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',
'test/assets/expect_e.css'
]
.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);
Expand Down Expand Up @@ -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<string>`', async t => {
const outputBundle = await rollup({
input: 'test/fixtures/processor-promise/index.js',
plugins: [
Expand All @@ -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',
Expand Down