Skip to content

Commit

Permalink
fix empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Sep 19, 2014
1 parent fc5dc13 commit 8602787
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = CSS
CSS.db = db
CSS.transform = db.transform
CSS.transforms = db.transforms
CSS.type =
CSS.prototype.type = 'css'

function CSS(options) {
if (!(this instanceof CSS)) return new CSS(options)
Expand Down
24 changes: 14 additions & 10 deletions lib/ecstacy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

var os = require('os')
var fs = require('mz/fs')
var path = require('path')
var assert = require('assert')
Expand All @@ -12,16 +13,23 @@ var convert = require('convert-source-map')
var Promise = require('native-or-bluebird')
var debug = require('debug')('ecstacy:ecstacy')

var tmpdir = os.tmpdir
? os.tmpdir()
: os.tmpDir()

module.exports = Ecstacy

// set the folder
Ecstacy.folder = path.resolve('cache/ecstacy')
require('mkdirp').sync(Ecstacy.folder)
var folder =
Ecstacy.folder =
Ecstacy.prototype.folder = path.resolve(tmpdir, 'ecstacy')
require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))

// clean the cache folder
Ecstacy.clean = function () {
require('rimraf').sync(Ecstacy.folder)
require('mkdirp').sync(Ecstacy.folder)
require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))
}

function Ecstacy() {}
Expand Down Expand Up @@ -112,7 +120,7 @@ Ecstacy.prototype.calculate = function (string) {

Ecstacy.filename =
Ecstacy.prototype.filename = function (name, ext) {
return path.join(Ecstacy.folder, name + ext)
return path.join(this.folder, this.type, name + ext)
}

// read a cached file's name and extension
Expand All @@ -129,14 +137,10 @@ Ecstacy.prototype.read = function (name, ext, encoding) {
// .read() except it doesn't throw if the file does not exist
Ecstacy.readSafely =
Ecstacy.prototype.readSafely = function (name, ext, encoding) {
return Ecstacy.read(name, ext, encoding).catch(reject)
return this.read(name, ext, encoding).catch(reject)
}

function reject(err) {
// XXX: bluebird wraps the Error in its own class, for some reason
// see https://github.com/petkaantonov/bluebird#expected-and-unexpected-errors
if (err.name === 'OperationalError' && err.cause)
err = err.cause
debug('read error: "%s"', err.stack)
if (err.code !== 'ENOENT') throw err
}
Expand Down
2 changes: 2 additions & 0 deletions lib/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module.exports = JS
JS.db = db
JS.transform = db.transform
JS.transforms = db.transforms
JS.type =
JS.prototype.type = 'js'

function JS(options) {
if (!(this instanceof JS)) return new JS(options)
Expand Down
19 changes: 19 additions & 0 deletions test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ var transforms = require('polyfills-db').postcss.transform

describe('Ecstacy.css(code, map)', function () {
describe('.build()', function () {
describe('an empty file', function () {
// postcss adds a space - whatever
var ecstacy

it('should still build', function () {
ecstacy = Ecstacy.css({
name: 'fleempty',
code: fixture('empty'),
transforms: true,
})

return ecstacy.build()
})

it('should build again', function () {
return ecstacy.build()
})
})

describe('with no transforms', function () {
var ecstacy

Expand Down
Empty file added test/fixtures/empty.css
Empty file.
Empty file added test/fixtures/empty.js
Empty file.
22 changes: 22 additions & 0 deletions test/js.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@

describe('Ecstacy.js(code, map)', function () {
describe('.build()', function () {
describe('with an empty file', function () {
var ecstacy

it('should still build', function () {
ecstacy = Ecstacy.js({
name: 'empty',
code: fixture('empty'),
transforms: true,
})

return ecstacy.build().then(function (data) {
assert.equal(data.hash, ecstacy.hash)
})
})

it('should build again', function () {
return ecstacy.build().then(function (data) {
assert.equal(data.hash, ecstacy.hash)
})
})
})

describe('with no transforms', function () {
var ecstacy

Expand Down

0 comments on commit 8602787

Please sign in to comment.