-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
307 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ ecmaFeatures: | |
env: | ||
browser: true | ||
node: true | ||
es6: true | ||
|
||
rules: | ||
comma-dangle: [2, "always-multiline"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.DS_Store | ||
npm-debug.log | ||
build/ | ||
/coverage/ | ||
coverage/ | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
npm-debug.log | ||
changelog.md | ||
coverage/ | ||
example/ | ||
test/ | ||
.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "4.1" | ||
- "4.0" | ||
- "stable" | ||
- "4" | ||
- "0.12" | ||
- "0.11" | ||
- "iojs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@import "color"; | ||
.button { | ||
background-color: $blue; | ||
background-image: url(button.png); | ||
background-image: url(bin.jpg); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,184 @@ | ||
require('babel-core/register')() | ||
module.exports = require('./lib/main') | ||
var EventEmitter = require('events') | ||
var mix = require('util-mix') | ||
var MDeps = require('css-module-deps') | ||
var thr = require('through2') | ||
var resolve = require('resolve') | ||
var readonly = require('read-only-stream') | ||
var topoSort = require('deps-topo-sort') | ||
var path = require('path') | ||
var splicer = require('labeled-stream-splicer') | ||
var sink = require('sink-transform') | ||
|
||
var inherits = require('util').inherits | ||
inherits(Depsify, EventEmitter) | ||
|
||
module.exports = Depsify | ||
|
||
function Depsify(entries, opts) { | ||
if (!(this instanceof Depsify)) { | ||
return new Depsify(entries, opts) | ||
} | ||
if (typeof entries === 'string' || Array.isArray(entries)) { | ||
opts = mix({}, opts, { | ||
entries: [].concat(opts.entries || [], entries), | ||
}) | ||
} else { | ||
opts = mix({}, entries, opts) | ||
} | ||
this._options = opts | ||
opts.basedir = opts.basedir || process.cwd() | ||
|
||
this.pipeline = this._createPipeline(opts) | ||
|
||
;[].concat(opts.entries).filter(Boolean).forEach(function (file) { | ||
this.add(file, { basedir: opts.basedir }) | ||
}, this) | ||
;[].concat(opts.plugin).filter(Boolean).forEach(function (p) { | ||
this.plugin(p, { basedir: opts.basedir }) | ||
}, this) | ||
} | ||
|
||
Depsify.prototype._createPipeline = function (opts) { | ||
var self = this | ||
this._mdeps = new MDeps(Object.create(opts)) | ||
this._mdeps.on('file', function (file) { | ||
pipeline.emit('file', file) | ||
self.emit('file', file) | ||
}) | ||
this._mdeps.on('package', function (pkg) { | ||
pipeline.emit('package', pkg) | ||
self.emit('package', pkg) | ||
}) | ||
this._mdeps.on('transform', function (tr, file) { | ||
pipeline.emit('transform', tr, file) | ||
self.emit('transform', tr, file) | ||
}) | ||
|
||
if (opts.pack) { | ||
this.pack = opts.pack | ||
} | ||
// for factor-bundle | ||
this._bpack = this.pack(opts) | ||
|
||
var pipeline = splicer.obj([ | ||
'record', [ this._recorder() ], | ||
'deps', [ this._mdeps ], | ||
'unbom', [ this._unbom() ], | ||
'syntax', [], | ||
'sort', [], | ||
'dedupe', [], | ||
'label', [], | ||
'emit-deps', [ this._emitDeps() ], | ||
'debug', [], | ||
'pack', [ this._bpack ], | ||
'wrap', [], | ||
]) | ||
|
||
return pipeline | ||
} | ||
|
||
Depsify.prototype._unbom = function() { | ||
return thr.obj(function (row, enc, next) { | ||
if (/^\ufeff/.test(row.source)) { | ||
row.source = row.source.replace(/^\ufeff/, '') | ||
} | ||
this.push(row) | ||
next() | ||
}) | ||
} | ||
|
||
Depsify.prototype._emitDeps = function() { | ||
var self = this | ||
return thr.obj(function (row, enc, next) { | ||
self.emit('dep', row) | ||
this.push(row) | ||
next() | ||
}) | ||
} | ||
|
||
Depsify.prototype._recorder = function() { | ||
var recorded = this._recorded = [] | ||
return thr.obj(function (row, _, next) { | ||
recorded.push(row) | ||
next(null, row) | ||
}) | ||
} | ||
|
||
Depsify.prototype.pack = function() { | ||
return [ | ||
sink.obj(function (rows, done) { | ||
rows.sort(function (a, b) { | ||
return a.file < b.file ? -1 : 1 | ||
}) | ||
.forEach(function (row) { | ||
// to use toposort | ||
row.id = row.file | ||
this.push(row) | ||
}, this) | ||
done() | ||
}), | ||
topoSort(), | ||
thr.obj(function (row, _, next) { | ||
next(null, row.source) | ||
}), | ||
] | ||
} | ||
|
||
Depsify.prototype.add = function(file, opts) { | ||
opts = opts || {} | ||
if (Array.isArray(file)) { | ||
file.forEach(function (f) { | ||
this.add(f, opts) | ||
}, this) | ||
} else if (typeof file === 'string') { | ||
file = path.resolve(opts.basedir || this._options.basedir, file) | ||
this.pipeline.write({ file: file }) | ||
} else { | ||
this.pipeline.write(mix({ basedir: this._options.basedir }, file, opts)) | ||
} | ||
return this | ||
} | ||
|
||
Depsify.prototype.processor = function(p) { | ||
this.pipeline.write({ processor: p }) | ||
return this | ||
} | ||
|
||
Depsify.prototype.reset = function() { | ||
this.pipeline = this._createPipeline(this._options) | ||
this._bundled = false | ||
this.emit('reset') | ||
} | ||
|
||
Depsify.prototype.plugin = function(p, opts) { | ||
if (Array.isArray(p)) { | ||
opts = p[1] | ||
p = p[0] | ||
} | ||
var basedir = opts && opts.basedir || this._options.basedir | ||
if (typeof p === 'function') { | ||
p(this, opts) | ||
} else { | ||
var pfile = resolve.sync(p, { basedir: basedir }) | ||
var f = require(pfile) | ||
f(this, opts) | ||
} | ||
return this | ||
} | ||
|
||
Depsify.prototype.bundle = function() { | ||
if (this._bundled) { | ||
var recorded = this._recorded | ||
this.reset() | ||
recorded.forEach(function (x) { | ||
this.pipeline.write(x) | ||
}, this) | ||
} | ||
var output = readonly(this.pipeline) | ||
this.emit('bundle', output) | ||
this.pipeline.end() | ||
this._bundled = true | ||
|
||
return output | ||
} | ||
|
Oops, something went wrong.