Skip to content

Commit

Permalink
import: fix prefix issue
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshua Wuyts <i@yoshuawuyts.com>

Closes #46
  • Loading branch information
yoshuawuyts committed Feb 10, 2016
1 parent 666bc2a commit c8ab4d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"postcss": "^5.0.10",
"postcss-prefix": "^1.0.3",
"resolve": "^1.1.7",
"through2": "^2.0.0"
"through2": "^2.0.0",
"xtend": "^4.0.1"
},
"devDependencies": {
"browserify": "^13.0.0",
Expand Down
1 change: 0 additions & 1 deletion test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test('import', function (t) {
})
b.transform(sheetify, {
basedir: path.join(__dirname, 'plugins'),
use: [ [ 'sheetify-cssnext', { sourcemap: false } ] ],
out: concat(function (buf) {
const res = String(buf).trim()
t.equal(res, expected, 'package was imported')
Expand Down
8 changes: 8 additions & 0 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const falafel = require('falafel')
const resolve = require('resolve')
const assert = require('assert')
const mkdirp = require('mkdirp')
const xtend = require('xtend')
const path = require('path')
const fs = require('fs')

Expand All @@ -26,6 +27,8 @@ function transform (filename, opts) {
const nodes = []
var mname = null

opts = xtend(opts)

// argv parsing
if (opts.o) opts.out = opts.o
if (opts.out) {
Expand Down Expand Up @@ -123,9 +126,14 @@ function transform (filename, opts) {
if (node.type === 'CallExpression' &&
node.callee && node.callee.type === 'Identifier' &&
node.callee.name === mname) {
// determine path
// - check if module import
// - don't prefix by default if module import
// - check if local file
const resolvePath = cssResolve(node.arguments[0].value, opts.basedir)
const fnp = resolvePath ||
path.join(path.dirname(filename), node.arguments[0].value)
if (resolvePath) opts.global = true
const fnCss = fs.readFileSync(fnp, 'utf8').trim()

// read optional arguments passed in to node
Expand Down

0 comments on commit c8ab4d5

Please sign in to comment.