Skip to content

Commit 6675506

Browse files
bcomnesemilbayes
authored andcommitted
Add array of accepted synonym packages for sheetify (#165)
* Add array of accepted synonym packages for sheetify * Update travis config Array.prototype.includes is not defined in older nodes
1 parent 7c446d2 commit 6675506

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
node_js:
2-
- "4"
3-
- "5"
4-
- "6"
5-
- "8"
2+
- "lts/*"
63
- "node"
7-
sudo: false
4+
distro: xenial
85
language: node_js
96
script: "npm run test:cov"
107
after_script: "cat ./coverage/lcov.info | codecov"

lib/supported-synonyms.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
module.exports = [
4+
'sheetify',
5+
'hui/css'
6+
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"dependency-check": "^2.5.1",
5656
"domify": "^1.4.0",
5757
"from2-string": "^1.1.0",
58+
"hui": "^1.2.2",
5859
"jsdom": "^9.4.2",
5960
"nyc": "^11.9.0",
6061
"rimraf": "^2.5.1",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const sf = require('hui/css')
2+
3+
const prefix = sf`
4+
:host .hello, :host .world {
5+
transform: translate(0, 0);
6+
}
7+
`
8+
9+
var foo = {}
10+
foo.bar = sf`
11+
:host .hello, :host .world {
12+
transform: translate(0, 0);
13+
}
14+
`
15+
16+
console.log(prefix)

test/transform-package.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,35 @@ test('transform-package', function (t) {
3838
}
3939
})
4040
})
41+
42+
test('transform-package with a synonym for sheetify', function (t) {
43+
t.test('should transform CSS from package.json with options from a file with a synonym for sheetify ', function (t) {
44+
t.plan(1)
45+
46+
const expath = path.join(__dirname, 'fixtures/transform-package/expected.css')
47+
const expected = fs.readFileSync(expath, 'utf8').trim()
48+
49+
const ws = concat(function (buf) {
50+
const res = String(buf).trim()
51+
t.equal(res, expected, 'CSS was transformed')
52+
})
53+
54+
const bpath = path.join(__dirname, 'fixtures/transform-package/source-synonym.js')
55+
56+
browserify(bpath)
57+
.transform(sheetify)
58+
.transform(function (file) {
59+
return through(function (buf, enc, next) {
60+
const str = buf.toString('utf8')
61+
this.push(str.replace(/sheetify\/insert/g, 'insert-css'))
62+
next()
63+
})
64+
})
65+
.plugin('css-extract', { out: outFn })
66+
.bundle()
67+
68+
function outFn () {
69+
return ws
70+
}
71+
})
72+
})

transform.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const path = require('path')
1010
const fs = require('fs')
1111

1212
const sheetify = require('./index')
13+
const SUPPORTED_SYNONYMS = require('./lib/supported-synonyms')
1314

1415
module.exports = transform
1516

@@ -73,7 +74,8 @@ function transform (filename, options) {
7374
var mname = null
7475
var ast
7576

76-
if (src.indexOf('sheetify') === -1) {
77+
// Skip transforming any files that do not contain synonyms for sheetify
78+
if (!SUPPORTED_SYNONYMS.some(name => src.includes(name))) {
7779
self.push(src)
7880
self.push(null)
7981
return
@@ -110,7 +112,7 @@ function transform (filename, options) {
110112
if (node.type === 'CallExpression' &&
111113
node.callee && node.callee.name === 'require' &&
112114
node.arguments.length === 1 &&
113-
node.arguments[0].value === 'sheetify') {
115+
SUPPORTED_SYNONYMS.includes(node.arguments[0].value)) {
114116
node.update('0')
115117
mname = node.parent.id.name
116118
}

0 commit comments

Comments
 (0)