pax_global_header00006660000000000000000000000064130216025470014512gustar00rootroot0000000000000052 comment=f2c99868d76e4ccf9cd1ef856d4c72f9a9026642 coffeeify-2.1.0/000077500000000000000000000000001302160254700134515ustar00rootroot00000000000000coffeeify-2.1.0/.gitignore000066400000000000000000000000161302160254700154360ustar00rootroot00000000000000node_modules/ coffeeify-2.1.0/.travis.yml000066400000000000000000000000721302160254700155610ustar00rootroot00000000000000language: node_js node_js: - 0.10 - 0.12 - 4 - 5 coffeeify-2.1.0/LICENSE000066400000000000000000000020611302160254700144550ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. coffeeify-2.1.0/README.md000066400000000000000000000042111302160254700147260ustar00rootroot00000000000000# coffeeify [![Build Status](https://travis-ci.org/jnordberg/coffeeify.svg?branch=master)](https://travis-ci.org/jnordberg/coffeeify) CoffeeScript browserify transform. Mix and match `.coffee` and `.js` files in the same project. ## Example Given some files written in a mix of `js` and `coffee`: foo.coffee: ```coffee console.log require './bar.js' ``` bar.js: ```javascript module.exports = require('./baz.coffee')(5) ``` baz.coffee: ```coffee module.exports = (n) -> n ** n ``` Install coffeeify into your app: ``` $ npm install coffeeify ``` When you compile your app, just pass `-t coffeeify` to browserify: ```shell $ browserify -t coffeeify foo.coffee > bundle.js $ node bundle.js 3125 ``` You can omit the `.coffee` extension from your requires if you add the extension to browserify's module extensions: ```javascript module.exports = require('./baz')(5) ``` ``` $ browserify -t coffeeify --extension=".coffee" foo.coffee > bundle.js $ node bundle.js 3125 ``` You can also pass options to the CoffeeScript compiler: ``` $ browserify -t [ coffeeify --bare false --header true ] --extension=".coffee" foo.coffee .. // Generated by CoffeeScript 1.10.0 (function() { console.log(require('./bar.js')); }).call(this); .. ``` ## Options Name | Default | Description -----------|-----------|------------------------------------------------------------------------------------------- sourceMap | `null` | Generate source maps, deteremined from browserify's `--debug` option if not set. bare | `true` | Omit the `(function(){ .. }).call(this);` wrapper. header | `false` | Include the `// Generated by CoffeeScript ` header in every file processed. When using browserify programatically options can be passed as an object, example: ```coffee browserify = require 'browserify' coffeeify = require 'coffeeify' bundle = browserify extensions: ['.coffee'] bundle.transform coffeeify, bare: false header: true bundle.add 'foo.coffee' bundle.bundle (error, result) -> throw error if error? process.stdout.write result ``` ## Install With [npm](https://npmjs.org) do: ``` npm install coffeeify ``` ## License MIT coffeeify-2.1.0/example/000077500000000000000000000000001302160254700151045ustar00rootroot00000000000000coffeeify-2.1.0/example/bar.js000066400000000000000000000000541302160254700162050ustar00rootroot00000000000000module.exports = require('./baz.coffee')(5) coffeeify-2.1.0/example/bat.js000066400000000000000000000000571302160254700162120ustar00rootroot00000000000000module.exports = require('./baz.litcoffee')(5) coffeeify-2.1.0/example/baz.coffee000066400000000000000000000000401302160254700170230ustar00rootroot00000000000000module.exports = (n) -> n * 111 coffeeify-2.1.0/example/baz.litcoffee000066400000000000000000000001061302160254700175370ustar00rootroot00000000000000Multiply all the things with 111 module.exports = (n) -> n * 111 coffeeify-2.1.0/example/error.coffee000066400000000000000000000002121302160254700174010ustar00rootroot00000000000000#----------------------------------# # hello, my name is: SµNTtaX E®Rör # #----------------------------------# thisIsWrong = , 'waaa' coffeeify-2.1.0/example/foo.coffee000066400000000000000000000000401302160254700170320ustar00rootroot00000000000000console.log(require './bar.js') coffeeify-2.1.0/example/foo.litcoffee000066400000000000000000000000631302160254700175500ustar00rootroot00000000000000Here is a bat console.log(require './bat.js') coffeeify-2.1.0/example/multiline_error.coffee000066400000000000000000000002601302160254700214660ustar00rootroot00000000000000#----------------------------------# # hello, my name is: SµNTtaX E®Rör # #----------------------------------# 'this is very wrong. notice that the first line is'' longer'coffeeify-2.1.0/index.js000066400000000000000000000067021302160254700151230ustar00rootroot00000000000000var coffee = require('coffee-script'); var convert = require('convert-source-map'); var path = require('path'); var through = require('through2'); var filePattern = /\.((lit)?coffee|coffee\.md)$/; function isCoffee (file) { return filePattern.test(file); } function isLiterate (file) { return (/\.(litcoffee|coffee\.md)$/).test(file); } function ParseError(error, src, file) { /* Creates a ParseError from a CoffeeScript SyntaxError modeled after substack's syntax-error module */ SyntaxError.call(this); this.message = error.message; this.line = error.location.first_line + 1; // cs linenums are 0-indexed this.column = error.location.first_column + 1; // same with columns var markerLen = 2; if(error.location.first_line === error.location.last_line) { markerLen += error.location.last_column - error.location.first_column; } this.annotated = [ file + ':' + this.line, src.split('\n')[this.line - 1], Array(this.column).join(' ') + Array(markerLen).join('^'), 'ParseError: ' + this.message ].join('\n'); } ParseError.prototype = Object.create(SyntaxError.prototype); ParseError.prototype.toString = function () { return this.annotated; }; ParseError.prototype.inspect = function () { return this.annotated; }; function compile(filename, source, options, callback) { var compiled; try { compiled = coffee.compile(source, { sourceMap: options.sourceMap, inline: true, bare: options.bare, header: options.header, literate: isLiterate(filename) }); } catch (e) { var error = e; if (e.location) { error = new ParseError(e, source, filename); } callback(error); return; } if (options.sourceMap) { var map = convert.fromJSON(compiled.v3SourceMap); var basename = path.basename(filename); map.setProperty('file', basename.replace(filePattern, '.js')); map.setProperty('sources', [basename]); map.setProperty('sourcesContent', [source]); callback(null, compiled.js + '\n' + map.toComment() + '\n'); } else { callback(null, compiled + '\n'); } } function coffeeify(filename, options) { if (!isCoffee(filename)) return through(); if (typeof options === 'undefined' || options === null) options = {}; var compileOptions = { sourceMap: (options._flags && options._flags.debug), bare: true, header: false }; for (var i = 0, keys = Object.keys(compileOptions); i < keys.length; i++) { var key = keys[i], option = options[key]; if (typeof option !== 'undefined' && option !== null) { if (option === 'false' || option === 'no' || option === '0') { option = false; } compileOptions[key] = !!option; } } var chunks = []; function transform(chunk, encoding, callback) { chunks.push(chunk); callback(); } function flush(callback) { var stream = this; var source = Buffer.concat(chunks).toString(); compile(filename, source, compileOptions, function(error, result) { if (!error) stream.push(result); callback(error); }); } return through(transform, flush); } coffeeify.compile = compile; coffeeify.isCoffee = isCoffee; coffeeify.isLiterate = isLiterate; module.exports = coffeeify; coffeeify-2.1.0/package.json000066400000000000000000000017351302160254700157450ustar00rootroot00000000000000{ "name": "coffeeify", "version": "2.1.0", "description": "browserify plugin for coffee-script with support for mixed .js and .coffee files", "main": "index.js", "dependencies": { "coffee-script": "^1.12.0", "convert-source-map": "^1.3.0", "through2": "^2.0.0" }, "devDependencies": { "browserify": "^13.1.1", "tap": "^8.0.1", "through": "^2.3.8" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/jnordberg/coffeeify.git" }, "homepage": "https://github.com/jnordberg/coffeeify", "keywords": [ "coffee-script", "browserify", "v2", "js", "plugin", "transform" ], "contributors": [ { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, { "name": "Johan Nordberg", "email": "code@johan-nordberg.com", "url": "http://johan-nordberg.com" } ], "license": "MIT" } coffeeify-2.1.0/test/000077500000000000000000000000001302160254700144305ustar00rootroot00000000000000coffeeify-2.1.0/test/bundle.js000066400000000000000000000034761302160254700162510ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var convert = require('convert-source-map'); var path = require('path'); var fs = require('fs'); function bundle (file) { test('bundle transform', function (t) { t.plan(2); var bundle = browserify(); var sourcepath = path.join(__dirname, file); bundle.add(sourcepath); bundle.transform(path.join(__dirname, '..')); bundle.bundle(function (error, src) { if (error) t.fail(error); vm.runInNewContext(src, {console: {log: log}}); var map = convert.fromSource(String(src)); t.ok(map == null, 'should not have a map when debug is off'); }); function log (msg) { t.equal(msg, 555); } }); test('bundle transform includes sourcemaps with debug on', function (t) { t.plan(3); var bundle = browserify({debug: true}); var sourcepath = path.join(__dirname, file); bundle.add(sourcepath); bundle.transform(path.join(__dirname, '..')); bundle.bundle(function (error, src) { if (error) t.fail(error); vm.runInNewContext(src, {console: {log: log}}); var map = convert.fromSource(String(src)); var relpath = path.relative(process.cwd(), sourcepath); var sourceIdx = map.sourcemap.sources.indexOf(relpath); t.ok(sourceIdx !== -1, 'should have source filename in map') var filesrc = fs.readFileSync(sourcepath).toString() t.equal(filesrc, map.sourcemap.sourcesContent[sourceIdx], 'should have source content in map') }); function log (msg) { t.equal(msg, 555); } }); } bundle('../example/foo.coffee'); bundle('../example/foo.litcoffee'); coffeeify-2.1.0/test/error.js000066400000000000000000000020701302160254700161160ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var path = require('path'); var fs = require('fs'); var file = path.resolve(__dirname, '../example/error.coffee'); var multilineFile = path.resolve(__dirname, '../example/multiline_error.coffee'); var transform = path.join(__dirname, '..'); test('transform error', function (t) { t.plan(5); var b = browserify([file]); b.transform(transform); b.bundle(function (error) { t.ok(error !== undefined, "bundle should callback with an error"); t.ok(error.line !== undefined, "error.line should be defined"); t.ok(error.column !== undefined, "error.column should be defined"); t.equal(error.line, 5, "error should be on line 5"); t.equal(error.column, 15, "error should be on column 15"); }); }); test('multiline transform error', function (t) { t.plan(1); var b = browserify([multilineFile]); b.transform(transform); b.bundle(function (error) { t.ok(error !== undefined, "bundle should callback with an error"); }); }); coffeeify-2.1.0/test/transform.js000066400000000000000000000027401302160254700170040ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var path = require('path'); var through = require('through'); var convert = require('convert-source-map'); var transform = require('..'); test('transform adds sourcemap comment when sourceMap option is true', function (t) { t.plan(1); var data = ''; var file = path.join(__dirname, '../example/foo.coffee'); fs.createReadStream(file) .pipe(transform(file, {sourceMap: true})) .pipe(through(write, end)); function write (buf) { data += buf } function end () { var sourceMap = convert.fromSource(data).toObject(); t.deepEqual( sourceMap, { version: 3, file: 'foo.js', sourceRoot: '', sources: [ 'foo.coffee' ], names: [], mappings: 'AAAA,OAAO,CAAC,GAAR,CAAY,OAAA,CAAQ,UAAR,CAAZ', sourcesContent: [ 'console.log(require \'./bar.js\')\n' ] }, 'adds sourcemap comment including original source' ); } }); test('transform does not add sourcemap when sourceMap option is false', function (t) { t.plan(1); var data = ''; var file = path.join(__dirname, '../example/foo.coffee'); fs.createReadStream(file) .pipe(transform(file, {sourceMap: false})) .pipe(through(write, end)); function write (buf) { data += buf } function end () { var sourceMap = convert.fromSource(data); t.equal(sourceMap, null); } });