Skip to content

Commit

Permalink
Merge pull request #105 from elycruz/dev
Browse files Browse the repository at this point in the history
issue-#72 Tests, example fix/approach, and a patch to uncaught 'duplicate css' bug
  • Loading branch information
elycruz committed Sep 17, 2022
2 parents 6560c7c + e49b37a commit 195176c
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 21 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

.editorconfig
.gitignore
.node-version
.npmrc

CHANGELOG*
CODEOWNERS*
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=18
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.

6 changes: 4 additions & 2 deletions 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 @@ -37,7 +37,7 @@
],
"author": "BinRui.Guan <differui@gmail.com>",
"maintainers": [
"elycruz <elycruz@elycruz.com> (https://github.com/elycruz)"
"elycruz <elycruz-at-elycruz.com> (https://github.com/elycruz)"
],
"license": "MIT",
"bugs": {
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

0 comments on commit 195176c

Please sign in to comment.