Skip to content

Commit bf2e9fa

Browse files
committed
Replace Smash with ES6 modules
This is a pretty huge diff, and deserves some explanation. * Replaces the smash-specific "import" declarations and the jslint @Globals and @exports docblocks with ES6-module-style "import" and "export" declarations. * Excludes `smash` from the dev dependencies, includes `esperanto` - a bundler similar to `smash` but which operates on ES6-modules. * Broke the implicit circular dependencies by moving most of Iterable's implementation to IterableImpl.js, responsible for building the prototype of Iterable. * There were a few other implicit circular dependencies solved by moving shared utility functions into their own modules. This is also the first step in this direction. While the bundle builds and all tests pass, this has introduced awkwardness and a few (negligable) additional bytes to the bundle. There is also ample opportunity for further refactoring of the larger modules to better organize and make circular dependencies more clear. Closes immutable-js#273
1 parent cc70bcb commit bf2e9fa

32 files changed

+4676
-4619
lines changed

Gruntfile.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function(grunt) {
3434
clean: {
3535
build: ['dist/*']
3636
},
37-
smash: {
37+
bundle: {
3838
build: {
3939
files: [{
4040
src: 'src/Immutable.js',
@@ -59,26 +59,31 @@ module.exports = function(grunt) {
5959

6060

6161
var fs = require('fs');
62-
var smash = require('smash');
62+
var esperanto = require('esperanto');
6363
var traceur = require('traceur');
6464
var uglify = require('uglify-js');
6565

66-
grunt.registerMultiTask('smash', function () {
66+
grunt.registerMultiTask('bundle', function () {
6767
var done = this.async();
68+
6869
this.files.map(function (file) {
69-
var unTransformed = '';
70-
smash(file.src).on('data', function (data) {
71-
unTransformed += data;
72-
}).on('end', function () {
73-
var transformed = traceur.compile(unTransformed, {
70+
esperanto.bundle({ entry: file.src[0] }).then(function (bundle) {
71+
var unTransformed = bundle.toCjs({ name: 'Immutable' }).code;
72+
73+
var transformResult = traceur.compile(unTransformed, {
7474
filename: file.src[0]
7575
});
76-
if (transformed.error) {
77-
throw transformed.error;
76+
if (transformResult.error) {
77+
throw transformResult.error;
7878
}
79-
var transformed = fs.readFileSync('resources/traceur-runtime.js', {encoding: 'utf8'}) + transformed.js;
79+
if (transformResult.errors && transformResult.errors.length > 0) {
80+
throw transformResult.errors;
81+
}
82+
83+
var transformed = transformResult.js;
84+
var runnable = fs.readFileSync('resources/traceur-runtime.js', {encoding: 'utf8'}) + transformed;
8085
var wrapped = fs.readFileSync('resources/universal-module.js', {encoding: 'utf8'})
81-
.replace('%MODULE%', transformed);
86+
.replace('%MODULE%', runnable);
8287

8388
var copyright = fs.readFileSync('resources/COPYRIGHT');
8489

@@ -101,7 +106,9 @@ module.exports = function(grunt) {
101106
});
102107

103108
fs.writeFileSync(file.dest + '.min.js', copyright + result.code);
104-
done();
109+
}).then(function(){ done(); }, function(error) {
110+
grunt.log.error(error);
111+
done(false);
105112
});
106113
});
107114
});
@@ -162,7 +169,7 @@ module.exports = function(grunt) {
162169
grunt.loadNpmTasks('grunt-release');
163170

164171
grunt.registerTask('lint', 'Lint all source javascript', ['jshint']);
165-
grunt.registerTask('build', 'Build distributed javascript', ['clean', 'smash', 'copy']);
172+
grunt.registerTask('build', 'Build distributed javascript', ['clean', 'bundle', 'copy']);
166173
grunt.registerTask('test', 'Test built javascript', ['init_ts_compiler', 'jest']);
167174
grunt.registerTask('default', 'Lint, build and test.', ['lint', 'build', 'stats', 'test']);
168175
}

0 commit comments

Comments
 (0)