[Pkg-javascript-commits] [node-coffeeify] 01/14: Imported Upstream version 1.0.0

Ross Gammon ross-guest at moszumanska.debian.org
Thu Apr 2 17:10:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

ross-guest pushed a commit to branch master
in repository node-coffeeify.

commit 61b9681f5bae3ebb624090a86b9e3702f76216f6
Author: Ross Gammon <rossgammon at mail.dk>
Date:   Thu Apr 2 15:30:42 2015 +0200

    Imported Upstream version 1.0.0
---
 .gitignore                     |  1 +
 .travis.yml                    |  4 ++
 LICENSE                        | 18 ++++++++
 example/bar.js                 |  1 +
 example/bat.js                 |  1 +
 example/baz.coffee             |  1 +
 example/baz.litcoffee          |  3 ++
 example/error.coffee           |  5 +++
 example/foo.coffee             |  1 +
 example/foo.litcoffee          |  3 ++
 example/multiline_error.coffee |  7 +++
 index.js                       | 99 ++++++++++++++++++++++++++++++++++++++++++
 no-debug.js                    |  3 ++
 package.json                   | 44 +++++++++++++++++++
 readme.markdown                | 67 ++++++++++++++++++++++++++++
 test/bundle.js                 | 45 +++++++++++++++++++
 test/error.js                  | 33 ++++++++++++++
 test/no-debug.js               | 14 ++++++
 test/transform.js              | 55 +++++++++++++++++++++++
 19 files changed, 405 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..09d3ef3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - 0.8
+  - 0.10
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ee27ba4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+This 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.
diff --git a/example/bar.js b/example/bar.js
new file mode 100644
index 0000000..3761d10
--- /dev/null
+++ b/example/bar.js
@@ -0,0 +1 @@
+module.exports = require('./baz.coffee')(5)
diff --git a/example/bat.js b/example/bat.js
new file mode 100644
index 0000000..9ec5f2f
--- /dev/null
+++ b/example/bat.js
@@ -0,0 +1 @@
+module.exports = require('./baz.litcoffee')(5)
diff --git a/example/baz.coffee b/example/baz.coffee
new file mode 100644
index 0000000..9a1e51c
--- /dev/null
+++ b/example/baz.coffee
@@ -0,0 +1 @@
+module.exports = (n) -> n * 111
diff --git a/example/baz.litcoffee b/example/baz.litcoffee
new file mode 100644
index 0000000..3c5f962
--- /dev/null
+++ b/example/baz.litcoffee
@@ -0,0 +1,3 @@
+Multiply all the things with 111
+
+    module.exports = (n) -> n * 111
diff --git a/example/error.coffee b/example/error.coffee
new file mode 100644
index 0000000..ff7d1bc
--- /dev/null
+++ b/example/error.coffee
@@ -0,0 +1,5 @@
+#----------------------------------#
+# hello, my name is: SµNTtaX E®Rör #
+#----------------------------------#
+
+thisIsWrong = , 'waaa'
diff --git a/example/foo.coffee b/example/foo.coffee
new file mode 100644
index 0000000..7941a4b
--- /dev/null
+++ b/example/foo.coffee
@@ -0,0 +1 @@
+console.log(require './bar.js')
diff --git a/example/foo.litcoffee b/example/foo.litcoffee
new file mode 100644
index 0000000..db9da67
--- /dev/null
+++ b/example/foo.litcoffee
@@ -0,0 +1,3 @@
+Here is a bat
+
+    console.log(require './bat.js')
diff --git a/example/multiline_error.coffee b/example/multiline_error.coffee
new file mode 100644
index 0000000..ad6a087
--- /dev/null
+++ b/example/multiline_error.coffee
@@ -0,0 +1,7 @@
+#----------------------------------#
+# hello, my name is: SµNTtaX E®Rör #
+#----------------------------------#
+
+
+'this is very wrong. notice that the first line is''
+longer'
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..72024a8
--- /dev/null
+++ b/index.js
@@ -0,0 +1,99 @@
+var coffee = require('coffee-script');
+var through = require('through');
+var convert = require('convert-source-map');
+
+function isCoffee (file) {
+    return (/\.((lit)?coffee|coffee\.md)$/).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(file, data, callback) {
+    var compiled;
+    try {
+        compiled = coffee.compile(data, {
+            sourceMap: coffeeify.sourceMap,
+            generatedFile: file,
+            inline: true,
+            bare: true,
+            literate: isLiterate(file)
+        });
+    } catch (e) {
+        var error = e;
+        if (e.location) {
+            error = new ParseError(e, data, file);
+        }
+        callback(error);
+        return;
+    }
+
+    if (coffeeify.sourceMap) {
+        var map = convert.fromJSON(compiled.v3SourceMap);
+        map.setProperty('sources', [file]);
+        callback(null, compiled.js + '\n' + map.toComment() + '\n');
+    } else {
+        callback(null, compiled + '\n');
+    }
+    
+}
+
+function coffeeify(file) {
+    if (!isCoffee(file)) return through();
+
+    var data = '', stream = through(write, end);
+
+    return stream;
+
+    function write(buf) {
+        data += buf;
+    }
+
+    function end() {
+        compile(file, data, function(error, result) {
+            if (error) stream.emit('error', error);
+            stream.queue(result);
+            stream.queue(null);
+        });
+    }
+}
+
+coffeeify.compile = compile;
+coffeeify.isCoffee = isCoffee;
+coffeeify.isLiterate = isLiterate;
+coffeeify.sourceMap = true; // use source maps by default
+
+module.exports = coffeeify;
diff --git a/no-debug.js b/no-debug.js
new file mode 100644
index 0000000..80c0ace
--- /dev/null
+++ b/no-debug.js
@@ -0,0 +1,3 @@
+coffeeify = require('./index');
+coffeeify.sourceMap = false;
+module.exports = coffeeify;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b5eab0c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,44 @@
+{
+  "name": "coffeeify",
+  "version": "1.0.0",
+  "description": "browserify plugin for coffee-script with support for mixed .js and .coffee files",
+  "main": "index.js",
+  "dependencies": {
+    "coffee-script": "^1.8.0",
+    "convert-source-map": "^0.4.1",
+    "through": "^2.3.6"
+  },
+  "devDependencies": {
+    "browserify": "^6.3.2",
+    "tap": "^0.4.11"
+  },
+  "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 at substack.net",
+      "url": "http://substack.net"
+    },
+    {
+      "name": "Johan Nordberg",
+      "email": "code at johan-nordberg.com",
+      "url": "http://johan-nordberg.com"
+    }
+  ],
+  "license": "MIT"
+}
diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..62b944a
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,67 @@
+# coffeeify
+
+browserify v2 plugin for coffee-script
+
+mix and match `.coffee` and `.js` files in the same project
+
+[![Build Status](https://travis-ci.org/jnordberg/coffeeify.png?branch=master)](https://travis-ci.org/jnordberg/coffeeify)
+
+# example
+
+given some files written in a mix of `js` and `coffee`:
+
+foo.coffee:
+
+``` coffee
+console.log(require './bar.js')
+```
+
+bar.js:
+
+``` js
+module.exports = require('./baz.coffee')(5)
+```
+
+baz.coffee:
+
+``` js
+module.exports = (n) -> n * 111
+```
+
+install coffeeify into your app:
+
+```
+$ npm install coffeeify
+```
+
+when you compile your app, just pass `-t coffeeify` to browserify:
+
+```
+$ browserify -t coffeeify foo.coffee > bundle.js
+$ node bundle.js
+555
+```
+
+you can omit the `.coffee` extension from your requires if you add the extension to browserify's module extensions:
+
+``` js
+module.exports = require('./baz')(5)
+```
+
+```
+$ browserify -t coffeeify --extension=".coffee" foo.coffee > bundle.js
+$ node bundle.js
+555
+```
+
+# install
+
+With [npm](https://npmjs.org) do:
+
+```
+npm install coffeeify
+```
+
+# license
+
+MIT
diff --git a/test/bundle.js b/test/bundle.js
new file mode 100644
index 0000000..26ab95e
--- /dev/null
+++ b/test/bundle.js
@@ -0,0 +1,45 @@
+var test = require('tap').test;
+var browserify = require('browserify');
+var vm = require('vm');
+
+function bundle (file) {
+    test('bundle transform', function (t) {
+        t.plan(1);
+
+        var b = browserify();
+        b.add(__dirname + file);
+        b.transform(__dirname + '/..');
+        b.bundle(function (err, src) {
+            if (err) t.fail(err);
+            vm.runInNewContext(src, {
+                console: { log: log }
+            });
+        });
+
+        function log (msg) {
+            t.equal(msg, 555);
+        }
+    });
+    
+    test('bundle transform (no-debug)', function (t) {
+      t.plan(1);
+
+      var b = browserify();
+      b.add(__dirname + file);
+      b.transform(__dirname + '/../no-debug');
+      b.bundle(function (err, src) {
+        if (err) t.fail(err);
+        vm.runInNewContext(src, {
+          console: { log: log }
+        });
+      });
+
+      function log (msg) {
+        t.equal(msg, 555);
+      }
+    });
+    
+}
+
+bundle('/../example/foo.coffee');
+bundle('/../example/foo.litcoffee');
diff --git a/test/error.js b/test/error.js
new file mode 100644
index 0000000..04daee9
--- /dev/null
+++ b/test/error.js
@@ -0,0 +1,33 @@
+var 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");
+    });
+});
diff --git a/test/no-debug.js b/test/no-debug.js
new file mode 100644
index 0000000..36d0b29
--- /dev/null
+++ b/test/no-debug.js
@@ -0,0 +1,14 @@
+var test = require('tap').test;
+
+test('sourceMap use', function (t) {
+
+  t.plan(2);
+
+  defaultCoffeeify = require(__dirname + '/..');
+  t.equal(defaultCoffeeify.sourceMap, true, "sourceMap is true by default");
+
+  noDebugCoffeeify = require(__dirname + '/../no-debug');
+  t.equal(noDebugCoffeeify.sourceMap, false, "sourceMap is false for no-debug");
+
+});
+
diff --git a/test/transform.js b/test/transform.js
new file mode 100644
index 0000000..b7e910b
--- /dev/null
+++ b/test/transform.js
@@ -0,0 +1,55 @@
+var 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 is true', function (t) {
+    t.plan(1);
+    var data = '';
+    
+    transform.sourceMap = true;
+
+    var file = path.join(__dirname, '../example/foo.coffee');
+    fs.createReadStream(file)
+        .pipe(transform(file))
+        .pipe(through(write, end));
+
+    function write (buf) { data += buf }
+    function end () {
+        var sourceMap = convert.fromSource(data).toObject();
+
+        t.deepEqual(
+            sourceMap,
+            { version: 3,
+              file: file,
+              sourceRoot: '',
+              sources: [ file ],
+              names: [],
+              mappings: 'AAAA,OAAO,CAAC,GAAR,CAAY,OAAA,CAAQ,UAAR,CAAZ,CAAA,CAAA',
+              sourcesContent: [ 'console.log(require \'./bar.js\')\n' ] },
+            'adds sourcemap comment including original source'
+      );
+    }
+});
+
+test('transform does not add sourcemap when sourceMap is false', function (t) {
+
+  t.plan(1);
+  var data = '';
+
+  transform.sourceMap = false;
+
+  var file = path.join(__dirname, '../example/foo.coffee');
+  fs.createReadStream(file)
+    .pipe(transform(file))
+    .pipe(through(write, end));
+
+  function write (buf) { data += buf }
+  function end () {
+    var sourceMap = convert.fromSource(data);
+    t.equal(sourceMap, null);
+  }
+
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coffeeify.git



More information about the Pkg-javascript-commits mailing list