Split the distribution of Filer into two files

The AMD-module system Filer uses can't handle require() calls that reference a node module. By creating two distributions we allow the node version to use a full implementation of RequireJS, which gracefully falls back to Node's require() when RequireJS can't find the module in its registered paths.
This commit is contained in:
Kieran Sedgwick 2014-05-21 13:06:37 -04:00
parent 9f33d8503e
commit 3ef2a4e07d
8 changed files with 8005 additions and 14 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ bower_components
.env
*~
dist/filer-test.js
/dist/filer_node-test.js

View File

@ -13,10 +13,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
(function( root, factory ) {
if ( typeof exports === "object" ) {
// Node
module.exports = factory();
} else if (typeof define === "function" && define.amd) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define( factory );
} else if( !root.Filer ) {

7
build/node_wrap.end Normal file
View File

@ -0,0 +1,7 @@
var Filer = require( "src/index" );
return Filer;
}));

16
build/node_wrap.start Normal file
View File

@ -0,0 +1,16 @@
/*
Copyright (c) 2013, Alan Kligman
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
(function( root, factory ) {
module.exports = factory();
}( this, function() {

7920
dist/filer_node.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['dist/filer-test.js'],
clean: ['dist/filer-test.js', 'dist/filer_node-test.js'],
uglify: {
options: {
@ -58,7 +58,7 @@ module.exports = function(grunt) {
},
requirejs: {
develop: {
browser_develop: {
options: {
paths: {
"src": "../src",
@ -70,8 +70,8 @@ module.exports = function(grunt) {
out: "dist/filer.js",
optimize: "none",
wrap: {
startFile: 'build/wrap.start',
endFile: 'build/wrap.end'
startFile: 'build/browser_wrap.start',
endFile: 'build/browser_wrap.end'
},
shim: {
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
@ -82,7 +82,32 @@ module.exports = function(grunt) {
}
}
},
test: {
node_develop: {
options: {
paths: {
"src": "../src",
"build": "../build"
},
baseUrl: "lib",
name: "require",
include: ["src/index"],
out: "dist/filer_node.js",
optimize: "none",
wrap: {
startFile: 'build/node_wrap.start',
endFile: 'build/node_wrap.end'
},
shim: {
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
// and we use a fake one for reduced size, since we only care about utf8.
"encoding": {
deps: ["encoding-indexes-shim"]
}
},
nodeRequire: require
}
},
browser_test: {
options: {
paths: {
"src": "../src",
@ -94,8 +119,8 @@ module.exports = function(grunt) {
out: "dist/filer-test.js",
optimize: "none",
wrap: {
startFile: 'build/wrap.start',
endFile: 'build/wrap.end'
startFile: 'build/browser_wrap.start',
endFile: 'build/browser_wrap.end'
},
shim: {
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
@ -105,6 +130,31 @@ module.exports = function(grunt) {
}
}
}
},
node_test: {
options: {
paths: {
"src": "../src",
"build": "../build"
},
baseUrl: "lib",
name: "require",
include: ["src/index"],
out: "dist/filer_node-test.js",
optimize: "none",
wrap: {
startFile: 'build/node_wrap.start',
endFile: 'build/node_wrap.end'
},
shim: {
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
// and we use a fake one for reduced size, since we only care about utf8.
"encoding": {
deps: ["encoding-indexes-shim"]
}
},
nodeRequire: require
}
}
},
@ -208,8 +258,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('develop', ['clean', 'requirejs:develop']);
grunt.registerTask('filer-test', ['clean', 'requirejs:test']);
grunt.registerTask('develop', ['clean', 'requirejs:browser_develop', 'requirejs:node_develop']);
grunt.registerTask('filer-test', ['clean', 'requirejs:node_test', 'requirejs:browser_test']);
grunt.registerTask('release', ['develop', 'uglify']);
grunt.registerTask('check', ['jshint']);

View File

@ -15,7 +15,7 @@ requirejs.config({
"bugs": "../tests/bugs",
"util": "../tests/lib/test-utils",
// see gruntfile.js for how dist/filer-test.js gets built
"Filer": "../dist/filer-test"
"Filer": "../dist/filer_node-test"
},
baseUrl: "./lib",
optimize: "none",