Skip to content

Commit

Permalink
Sugarss support (#1941)
Browse files Browse the repository at this point in the history
* Add PostCSS's SugarSS recognition by default

* Update postcss.js

* Update SSSAsset.js

* Update Ast.js

* Update SSSAsset.js

* Update SSSAsset.js

* cleanup a lil

* remove parse step and fix sugarss fail
  • Loading branch information
DeMoorJasper committed Aug 27, 2018
1 parent 41d8759 commit 4208bc8
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/package.json
Expand Up @@ -104,6 +104,7 @@
"sinon": "^5.0.1",
"sourcemap-validator": "^1.0.6",
"stylus": "^0.54.5",
"sugarss": "^2.0.0",
"typescript": "^3.0.0",
"vue": "^2.5.16",
"vue-template-compiler": "^2.5.16"
Expand Down
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/src/Parser.js
Expand Up @@ -29,6 +29,7 @@ class Parser {
this.registerExtension('css', './assets/CSSAsset');
this.registerExtension('pcss', './assets/CSSAsset');
this.registerExtension('postcss', './assets/CSSAsset');
this.registerExtension('sss', './assets/SSSAsset');
this.registerExtension('styl', './assets/StylusAsset');
this.registerExtension('stylus', './assets/StylusAsset');
this.registerExtension('less', './assets/LESSAsset');
Expand Down
31 changes: 31 additions & 0 deletions packages/core/parcel-bundler/src/assets/SSSAsset.js
@@ -0,0 +1,31 @@
const postcss = require('postcss');
const localRequire = require('../utils/localRequire');
const Asset = require('../Asset');

class SSSAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'css';
}

async generate() {
let sugarss = await localRequire('sugarss', this.name);

await this.loadIfNeeded();

let {css} = await postcss().process(this.contents, {
from: this.name,
to: this.name,
parser: sugarss
});

return [
{
type: 'css',
value: css
}
];
}
}

module.exports = SSSAsset;
@@ -0,0 +1,5 @@
input.spoiler-input
display: none

.spoiler_link
cursor: pointer
21 changes: 21 additions & 0 deletions packages/core/parcel-bundler/test/sugarss.js
@@ -0,0 +1,21 @@
const assert = require('assert');
const {bundle, assertBundleTree} = require('./utils');
const fs = require('../src/utils/fs');
const path = require('path');

describe('sugarss', function() {
it('should correctly parse SugarSS asset', async function() {
let b = await bundle(__dirname + '/integration/sugarss/index.sss');

await assertBundleTree(b, {
name: 'index.css',
assets: ['index.sss']
});

let cssContent = await fs.readFile(
path.join(__dirname, '/dist/index.css'),
'utf8'
);
assert(cssContent.includes('{'));
});
});
14 changes: 14 additions & 0 deletions yarn.lock
Expand Up @@ -5577,6 +5577,14 @@ postcss@^6.0.1, postcss@^6.0.19, postcss@^6.0.20:
source-map "^0.6.1"
supports-color "^5.4.0"

postcss@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.2.tgz#7b5a109de356804e27f95a960bef0e4d5bc9bb18"
dependencies:
chalk "^2.4.1"
source-map "^0.6.1"
supports-color "^5.4.0"

posthtml-extend@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/posthtml-extend/-/posthtml-extend-0.2.1.tgz#d023ce7ce4dd6071071b50e315dfefa87da8a979"
Expand Down Expand Up @@ -6666,6 +6674,12 @@ stylus@0.54.5, stylus@^0.54.5:
sax "0.5.x"
source-map "0.1.x"

sugarss@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/sugarss/-/sugarss-2.0.0.tgz#ddd76e0124b297d40bf3cca31c8b22ecb43bc61d"
dependencies:
postcss "^7.0.2"

supports-color@4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e"
Expand Down

0 comments on commit 4208bc8

Please sign in to comment.