@risd/grunt-es6-module-transpiler 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jshintrc ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "curly": true,
3
+ "eqeqeq": true,
4
+ "immed": true,
5
+ "latedef": true,
6
+ "newcap": true,
7
+ "noarg": true,
8
+ "sub": true,
9
+ "undef": true,
10
+ "boss": true,
11
+ "eqnull": true,
12
+ "node": true,
13
+ "es5": true
14
+ }
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v20.14.0
package/Gruntfile.js ADDED
@@ -0,0 +1,160 @@
1
+ /*
2
+ * grunt-es6-module-transpiler
3
+ * https://github.com/joefiorini/grunt-es6-module-transpiler
4
+ *
5
+ * Copyright (c) 2013 Joe Fiorini
6
+ * Licensed under the MIT license.
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ module.exports = function(grunt) {
12
+
13
+ // Project configuration.
14
+ grunt.initConfig({
15
+ jshint: {
16
+ all: [
17
+ 'Gruntfile.js',
18
+ 'tasks/*.js',
19
+ '<%= nodeunit.tests %>',
20
+ ],
21
+ options: {
22
+ jshintrc: '.jshintrc',
23
+ },
24
+ },
25
+
26
+ // Before generating any new files, remove any previously-created files.
27
+ clean: {
28
+ tests: ['tmp'],
29
+ },
30
+
31
+ release: {
32
+ options: {
33
+ tagName: 'v<%= version %>',
34
+ commitMessage: 'Release v<%= version %> :tada:',
35
+ tagMessage: 'Release v<%= version %>'
36
+ }
37
+ },
38
+
39
+ // Configuration to be run (and then tested).
40
+ transpile: {
41
+ toCJS: {
42
+ type: "cjs",
43
+ files: {
44
+ 'tmp/cjs.js': ['test/fixtures/input.js'],
45
+ 'tmp/cjs-bar.js': ['test/fixtures/bar.js']
46
+ },
47
+ },
48
+ toAMD: {
49
+ type: "amd",
50
+ files: {
51
+ 'tmp/amd.js': ['test/fixtures/input.js'],
52
+ 'tmp/amd-bar.js': ['test/fixtures/bar.js']
53
+ }
54
+ },
55
+ toYUI: {
56
+ type: "yui",
57
+ files: {
58
+ 'tmp/yui.js': ['test/fixtures/input.js'],
59
+ 'tmp/yui-bar.js': ['test/fixtures/bar.js']
60
+ }
61
+ },
62
+ toGlobals: {
63
+ type: "globals",
64
+ imports: { bar: "Bar" },
65
+ files: {
66
+ 'tmp/globals.js': ['test/fixtures/input.js'],
67
+ 'tmp/globals-bar.js': ['test/fixtures/bar.js']
68
+ }
69
+ },
70
+ moduleName: {
71
+ type: 'amd',
72
+ moduleName: 'namedModule',
73
+ files: {
74
+ 'tmp/name.js': ['test/fixtures/name.js'],
75
+ }
76
+ },
77
+ moduleNameCallback: {
78
+ type: 'amd',
79
+ moduleName: function(srcWithoutExt, file){
80
+ return 'my_app/' + srcWithoutExt.replace(/^test\/fixtures\//, '');
81
+ },
82
+ files: {
83
+ 'tmp/name_callback.js': ['test/fixtures/name_callback.js'],
84
+ }
85
+ },
86
+ moduleNameCallbackWithCwd: {
87
+ type: 'amd',
88
+ moduleName: function(srcWithoutExt, file){
89
+ return 'my_app/' + srcWithoutExt;
90
+ },
91
+ files: [
92
+ {
93
+ expand: true, // Enable dynamic expansion.
94
+ cwd: 'test/fixtures/lib/', // Src matches are relative to this path.
95
+ src: ['**/*.js'], // Actual pattern(s) to match.
96
+ dest: 'tmp/' // Destination path prefix.
97
+ }
98
+ ]
99
+ },
100
+ anonymous: {
101
+ type: 'amd',
102
+ anonymous: true,
103
+ files: {
104
+ 'tmp/anonymous.js': ['test/fixtures/anonymous.js'],
105
+ }
106
+ },
107
+ coffeeSrc: {
108
+ type: 'amd',
109
+ files: {
110
+ 'tmp/coffee.js': ['test/fixtures/coffee.coffee'],
111
+ }
112
+ },
113
+ mixedCoffeeAndJS: {
114
+ type: 'amd',
115
+ anonymous: true,
116
+ files: {
117
+ 'tmp/anonymous.coffee': ['test/fixtures/anonymous.coffee'],
118
+ 'tmp/anonymous.js': ['test/fixtures/anonymous.js'],
119
+ }
120
+ }
121
+ // importError: {
122
+ // type: 'amd',
123
+ // anonymous: true,
124
+ // files: {
125
+ // 'tmp/import-error.js': ['test/fixtures/import-error.js']
126
+ // }
127
+ // },
128
+ // exportError: {
129
+ // type: 'amd',
130
+ // anonymous: true,
131
+ // files: {
132
+ // 'tmp/export-error.js': ['test/fixtures/export-error.js']
133
+ // }
134
+ // }
135
+ },
136
+
137
+ // Unit tests.
138
+ nodeunit: {
139
+ tests: ['test/*_test.js'],
140
+ },
141
+
142
+ });
143
+
144
+ // Actually load this plugin's task(s).
145
+ grunt.loadTasks('tasks');
146
+
147
+ // These plugins provide necessary tasks.
148
+ grunt.loadNpmTasks('grunt-contrib-jshint');
149
+ grunt.loadNpmTasks('grunt-contrib-clean');
150
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
151
+ grunt.loadNpmTasks('grunt-release');
152
+
153
+ // Whenever the "test" task is run, first clean the "tmp" dir, then run this
154
+ // plugin's task(s), then test the result.
155
+ grunt.registerTask('test', ['clean', 'transpile', 'nodeunit']);
156
+
157
+ // By default, lint and run all tests.
158
+ grunt.registerTask('default', ['jshint', 'test']);
159
+
160
+ };
package/LICENSE-MIT ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Fiorini
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # grunt-es6-module-transpiler
2
+
3
+ > A Grunt task for processing ES6 module import/export syntax into one of AMD, CommonJS, YUI or globals using the es6-module-transpiler. Also allows you to temporarily enable ES6 modules for other tasks.
4
+
5
+ ## Getting Started
6
+ This plugin requires Grunt `~0.4.1`
7
+
8
+ If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
9
+
10
+ ```shell
11
+ npm install grunt-es6-module-transpiler --save-dev
12
+ ```
13
+
14
+ To use add the `transpile` task to your Grunt configuration.
15
+
16
+ ### Using with RequireJS/CommonJS:
17
+
18
+ ```js
19
+ grunt.loadNpmTasks('grunt-es6-module-transpiler');
20
+
21
+ grunt.initConfig({
22
+ transpile: {
23
+ main: {
24
+ type: "cjs", // or "amd" or "yui"
25
+ files: [{
26
+ expand: true,
27
+ cwd: 'lib/',
28
+ src: ['**/*.js'],
29
+ dest: 'tmp/'
30
+ }]
31
+ }
32
+ }
33
+ });
34
+ ```
35
+
36
+ ### Using with Globals
37
+
38
+ ```js
39
+ grunt.loadNpmTasks('grunt-es6-module-transpiler');
40
+
41
+ grunt.initConfig({
42
+ transpile: {
43
+ main: {
44
+ type: "globals",
45
+ imports: { bar: "Bar" },
46
+ files: {
47
+ 'tmp/globals.js': ['test/fixtures/input.js'],
48
+ 'tmp/globals-bar.js': ['test/fixtures/bar.js']
49
+ }
50
+ }
51
+ }
52
+ });
53
+ ```
54
+
55
+ ### Transpiling your files
56
+
57
+ Manually run the task with `grunt transpile` or include it as part of your build task:
58
+
59
+ ```js
60
+ grunt.registerTask('build', ['clean', 'transpile', '...']);
61
+ ```
62
+
63
+ ### Resources
64
+
65
+ - [Using Grunt & the ES6 Module Transpiler](http://www.thomasboyt.com/2013/06/21/es6-module-transpiler) by Thomas Boyt
66
+
67
+ ### Caveat
68
+
69
+ The module transpiler forces strict mode; there is no option to turn this off. If, like me, you typically use Mocha with [Chai](http://chaijs.com), this can cause a problem because Chai attempts to access `arguments.callee`, which violates strict mode. I switched to using [expect.js](https://github.com/LearnBoost/expect.js/) and it works great.
70
+
71
+ ## Contributing
72
+ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
73
+
74
+ ## Release History
75
+ 10/07/2013 v0.5.0 - Support for v0.3.0 of es6-module-transpiler; removes transpile:enable task as the feature no longer exists
76
+ 07/09/2013 v0.4.1 - Improved windows support when using amd
77
+ 07/09/2013 v0.4.0 - Update to v0.2.0 of es6-module-transpiler for new syntax support
78
+ 05/28/2013 v0.3.0 - Add callback for dynamically specifying AMD modulename
79
+ 05/02/2013 v0.2.0 - Fixes for globals, CoffeeScript, transpile:enable task for node scripts
80
+ 04/17/2013 v0.1.0 - Initial release, supports basic transpile task
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@risd/grunt-es6-module-transpiler",
3
+ "description": "A Grunt task for processing ES6 module import/export syntax into one of AMD, CommonJS or globals using the es6-module-transpiler",
4
+ "version": "0.7.0",
5
+ "homepage": "https://github.com/rubillionaire/grunt-es6-module-transpiler",
6
+ "author": {
7
+ "name": "Ruben Rodriguez",
8
+ "email": "mail@rubenrodriguez.me"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git://github.com/rubillionaire/grunt-es6-module-transpiler.git"
13
+ },
14
+ "licenses": [
15
+ {
16
+ "type": "MIT",
17
+ "url": "https://github.com/rubillionaire/grunt-es6-module-transpiler/blob/master/LICENSE-MIT"
18
+ }
19
+ ],
20
+ "main": "Gruntfile.js",
21
+ "engines": {
22
+ "node": ">= 0.8.0"
23
+ },
24
+ "scripts": {
25
+ "test": "grunt test"
26
+ },
27
+ "devDependencies": {
28
+ "grunt-contrib-jshint": "~0.1.1",
29
+ "grunt-contrib-clean": "~0.4.0",
30
+ "grunt-contrib-nodeunit": "~5.0.0",
31
+ "grunt": "~0.4.1",
32
+ "grunt-release": "~0.6.0"
33
+ },
34
+ "peerDependencies": {
35
+ "grunt": ">=0.4.0"
36
+ },
37
+ "keywords": [
38
+ "gruntplugin"
39
+ ],
40
+ "dependencies": {
41
+ "es6-module-transpiler": "~0.3"
42
+ }
43
+ }
@@ -0,0 +1,101 @@
1
+ /*
2
+ * grunt-es6-module-transpiler
3
+ * https://github.com/joefiorini/grunt-es6-module-transpiler
4
+ *
5
+ * Copyright (c) 2013 Joe Fiorini
6
+ * Licensed under the MIT license.
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ module.exports = function(grunt) {
12
+
13
+ var path = require('path');
14
+
15
+ function transpile(file, options) {
16
+ var src = file.src,
17
+ Compiler = require("es6-module-transpiler").Compiler,
18
+ compiler, compiled, ext, method, moduleName;
19
+
20
+ ext = path.extname(src);
21
+
22
+ if (ext.slice(1) === 'coffee') {
23
+ options = grunt.util._.extend({coffee: true}, options);
24
+ }
25
+
26
+ if (options.anonymous) {
27
+ moduleName = '';
28
+ } else if (typeof options.moduleName === 'string') {
29
+ moduleName = options.moduleName;
30
+ } else {
31
+ moduleName = path.join(path.dirname(src), path.basename(src, ext)).replace(/[\\]/g, '/');
32
+ if (file.orig.cwd) {
33
+ moduleName = moduleName.slice(file.orig.cwd.length);
34
+ }
35
+ if (options.moduleName) {
36
+ moduleName = options.moduleName(moduleName, file);
37
+ }
38
+ }
39
+
40
+ compiler = new Compiler(grunt.file.read(src), moduleName, options);
41
+
42
+ switch(options.type){
43
+ case 'cjs':
44
+ method = "toCJS";
45
+ break;
46
+ case 'amd':
47
+ method = "toAMD";
48
+ break;
49
+ case 'yui':
50
+ method = "toYUI";
51
+ break;
52
+ case 'globals':
53
+ method = "toGlobals";
54
+ break;
55
+ default:
56
+ throw new Error("unknown transpile destination type: " + options.type);
57
+ }
58
+
59
+ compiled = compiler[method].apply(compiler);
60
+
61
+ grunt.file.write(file.dest, compiled);
62
+ }
63
+
64
+ function formatTranspilerError(filename, e) {
65
+ var pos = '[' + 'L' + e.lineNumber + ':' + ('C' + e.column) + ']';
66
+ return filename + ': ' + pos + ' ' + e.description;
67
+ }
68
+
69
+ grunt.registerMultiTask("transpile", function(){
70
+
71
+ var opts = {};
72
+
73
+ opts.imports = this.data.imports;
74
+ opts.type = this.data.type;
75
+ opts.moduleName = this.data.moduleName;
76
+ opts.anonymous = this.data.anonymous;
77
+ opts.compatFix = this.data.compatFix;
78
+
79
+ this.files.forEach(function(file){
80
+ file.src.filter(function(path){
81
+ if(!grunt.file.exists(path)){
82
+ grunt.log.warn('Source file "' + path + '" not found.');
83
+ return false;
84
+ } else {
85
+ return true;
86
+ }
87
+ }).forEach(function(path){
88
+ try {
89
+ transpile({src:path, dest:file.dest, orig:file.orig}, opts);
90
+ } catch (e) {
91
+ var message = formatTranspilerError(path, e);
92
+
93
+ grunt.log.error(message);
94
+ grunt.fail.warn('Error compiling ' + path);
95
+ }
96
+ });
97
+ });
98
+
99
+ });
100
+
101
+ };
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ var grunt = require('grunt');
4
+
5
+ /*
6
+ ======== A Handy Little Nodeunit Reference ========
7
+ https://github.com/caolan/nodeunit
8
+
9
+ Test methods:
10
+ test.expect(numAssertions)
11
+ test.done()
12
+ Test assertions:
13
+ test.ok(value, [message])
14
+ test.equal(actual, expected, [message])
15
+ test.notEqual(actual, expected, [message])
16
+ test.deepEqual(actual, expected, [message])
17
+ test.notDeepEqual(actual, expected, [message])
18
+ test.strictEqual(actual, expected, [message])
19
+ test.notStrictEqual(actual, expected, [message])
20
+ test.throws(block, [error], [message])
21
+ test.doesNotThrow(block, [error], [message])
22
+ test.ifError(value)
23
+ */
24
+
25
+ function normalizedFileRead(path) {
26
+ return grunt.util.normalizelf(grunt.file.read(path));
27
+ }
28
+
29
+ exports.es6_module_transpiler = {
30
+ setUp: function(done) {
31
+ done();
32
+ },
33
+ toCJS: function(test) {
34
+ test.expect(1);
35
+
36
+ var actual = normalizedFileRead('tmp/cjs.js');
37
+ var expected = normalizedFileRead('test/expected/cjs.js');
38
+ test.equal(actual, expected, 'outputs CommonJS');
39
+
40
+ test.done();
41
+ },
42
+ toAMD: function(test) {
43
+ test.expect(1);
44
+
45
+ var actual = normalizedFileRead('tmp/amd.js');
46
+ var expected = normalizedFileRead('test/expected/amd.js');
47
+ test.equal(actual, expected, 'outputs AMD');
48
+
49
+ test.done();
50
+ },
51
+ toYUI: function(test) {
52
+ test.expect(1);
53
+
54
+ var actual = normalizedFileRead('tmp/yui.js');
55
+ var expected = normalizedFileRead('test/expected/yui.js');
56
+ test.equal(actual, expected, 'outputs YUI');
57
+
58
+ test.done();
59
+ },
60
+ toGlobals: function(test) {
61
+ test.expect(1);
62
+
63
+ var actual = normalizedFileRead('tmp/globals.js');
64
+ var expected = normalizedFileRead('test/expected/globals.js');
65
+ test.equal(actual, expected, 'outputs Globals');
66
+
67
+ test.done();
68
+ },
69
+ moduleNameOption: function(test) {
70
+ test.expect(1);
71
+
72
+ var actual = normalizedFileRead('tmp/name.js');
73
+ var expected = normalizedFileRead('test/expected/name.js');
74
+ test.equal(actual, expected, 'understands moduleName option');
75
+
76
+ test.done();
77
+ },
78
+ moduleNameCallbackOption: function(test) {
79
+ test.expect(1);
80
+
81
+ var actual = normalizedFileRead('tmp/name_callback.js');
82
+ var expected = normalizedFileRead('test/expected/name_callback.js');
83
+ test.equal(actual, expected, 'understands moduleName option with function');
84
+
85
+ test.done();
86
+ },
87
+ moduleNameCallbackOptionWithCwd: function(test) {
88
+ test.expect(1);
89
+
90
+ var actual = normalizedFileRead('tmp/name_callback_with_cwd.js');
91
+ var expected = normalizedFileRead('test/expected/name_callback_with_cwd.js');
92
+ test.equal(actual, expected, 'understands moduleName option with function with cwd');
93
+
94
+ test.done();
95
+ },
96
+ anonymousOption: function(test) {
97
+ test.expect(1);
98
+
99
+ var actual = normalizedFileRead('tmp/anonymous.js');
100
+ var expected = normalizedFileRead('test/expected/anonymous.js');
101
+ test.equal(actual, expected, 'understands anonymous option');
102
+
103
+ test.done();
104
+ },
105
+ mixedCoffeeAndJS: function(test) {
106
+ test.expect(1);
107
+
108
+ // in the config there is a .coffee file listed before this one
109
+ var actual = normalizedFileRead('tmp/anonymous.js');
110
+ var expected = normalizedFileRead('test/expected/anonymous.js');
111
+ test.equal(actual, expected, 'uses coffee option only on CoffeeScript files');
112
+
113
+ test.done();
114
+ }
115
+ };
@@ -0,0 +1,6 @@
1
+ define("test/fixtures/input",
2
+ ["bar"],
3
+ function(__dependency1__) {
4
+ "use strict";
5
+ var foo = __dependency1__.foo;
6
+ });
@@ -0,0 +1,9 @@
1
+ define(
2
+ ["exports"]
3
+ (__exports__) ->
4
+ "use strict"
5
+ foo = "bar"
6
+
7
+
8
+ __exports__.foo = foo
9
+ )
@@ -0,0 +1,8 @@
1
+ define(
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ var foo = "bar";
6
+
7
+ __exports__.foo = foo;
8
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ var foo = require("bar").foo;
@@ -0,0 +1 @@
1
+ Testing: 1 2 3 !!!
@@ -0,0 +1 @@
1
+ Testing, 1 2 3.
@@ -0,0 +1,3 @@
1
+ import foo from "./foo";
2
+
3
+ export default foo;
@@ -0,0 +1 @@
1
+ export default "bar";
@@ -0,0 +1,4 @@
1
+ (function(__dependency1__) {
2
+ "use strict";
3
+ var foo = __dependency1__.foo;
4
+ })(window.Bar);
@@ -0,0 +1,8 @@
1
+ define("namedModule",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ var foo = "bar";
6
+
7
+ __exports__.foo = foo;
8
+ });
@@ -0,0 +1,8 @@
1
+ define("my_app/name_callback",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ var foo = "bar";
6
+
7
+ __exports__.foo = foo;
8
+ });
@@ -0,0 +1,8 @@
1
+ define("my_app/name_callback_with_cwd",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ var foo = "bar";
6
+
7
+ __exports__.foo = foo;
8
+ });
@@ -0,0 +1,7 @@
1
+ YUI.add("test/fixtures/bar", function(Y, NAME, __imports__, __exports__) {
2
+ "use strict";
3
+ var foo = "bar";
4
+
5
+ __exports__.foo = foo;
6
+ return __exports__;
7
+ }, "@VERSION@", {"es":true,"requires":[]});
@@ -0,0 +1,5 @@
1
+ YUI.add("test/fixtures/input", function(Y, NAME, __imports__, __exports__) {
2
+ "use strict";
3
+ var foo = __imports__["bar"].foo;
4
+ return __exports__;
5
+ }, "@VERSION@", {"es":true,"requires":["bar"]});
@@ -0,0 +1 @@
1
+ 1 2 3
@@ -0,0 +1,3 @@
1
+ foo = "bar"
2
+
3
+ export { foo }
@@ -0,0 +1,3 @@
1
+ var foo = "bar";
2
+
3
+ export { foo };
@@ -0,0 +1,3 @@
1
+ var foo = "bar";
2
+
3
+ export { foo };
@@ -0,0 +1 @@
1
+ export doody doo;
@@ -0,0 +1 @@
1
+ import blah dee as doo;
@@ -0,0 +1 @@
1
+ import { foo } from "bar";
@@ -0,0 +1,3 @@
1
+ var foo = "bar";
2
+
3
+ export { foo };
@@ -0,0 +1,3 @@
1
+ var foo = "bar";
2
+
3
+ export { foo };
@@ -0,0 +1,3 @@
1
+ var foo = "bar";
2
+
3
+ export { foo };
@@ -0,0 +1 @@
1
+ Testing