Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
call-a3 committed Dec 8, 2014
2 parents 107bf2e + 68a9528 commit 73ee040
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Module.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ class Module extends BuiltinModule
self = @
content = content.replace /^\#\!.*/, ''

require = (path) ->
self.require path

require.resolve = (request) ->
BuiltinModule._resolveFilename self, request
require.main = process.mainModule
require.extensions = BuiltinModule._extensions
require.cache = BuiltinModule._cache

sandbox = new Sandbox({
filename
module: self
require
imports: {gulp: wrapper}
})

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
gulp-loader
===========

[![Build Status](https://travis-ci.org/call-a3/gulp-loader.svg?tag=1.1.0)](https://travis-ci.org/call-a3/gulp-loader)
[![Build Status](https://travis-ci.org/call-a3/gulp-loader.svg?tag=1.1.1)](https://travis-ci.org/call-a3/gulp-loader)
[![Dependency Status](https://david-dm.org/call-a3/gulp-loader.svg)](https://david-dm.org/call-a3/gulp-loader) [![devDependency Status](https://david-dm.org/call-a3/gulp-loader/dev-status.svg)](https://david-dm.org/call-a3/gulp-loader#info=devDependencies)

Gulp plugin that wraps gulp and loads tasks from a specified folder. Task definitions are compatible with [gulp-task-loader](https://www.npmjs.org/package/gulp-task-loader).
Expand Down
7 changes: 4 additions & 3 deletions Sandbox.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
path = require 'path'

module.exports = class Sandbox
constructor: ({filename, module, imports}) ->
constructor: ({filename, module, require, imports}) ->
self = @

# Include global as reference to self
Expand All @@ -23,9 +23,10 @@ module.exports = class Sandbox
get: () -> exports
set: (value) ->
exports = value

# Set require
Object.defineProperty @, 'require',
value: (id) ->
module.require.call module, id
value: require

# Add imported globals if they don't override fixed globals
for name, prop of imports
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-loader",
"version": "1.1.0",
"version": "1.1.1",
"description": "Gulp plugin that wraps gulp and loads tasks as seperate files from a gulp folder",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions test/gulp/check-module-shim.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
check = (bool, message) ->
if bool
gulp.util.log 'yes ' + message
else
gulp.util.log 'no ' + message

module.exports = (done) ->
check (typeof require is 'function'),
'require should be a function'
check (typeof require.resolve is 'function'),
'require.resolve should be a function'
check (require.main == process.mainModule),
'main should be a process.mainModule'
check (typeof require.extensions is 'object'),
'module.extensions should be an object map'
check (typeof require.cache is 'object'),
'module.cache should be an object map'
done()
24 changes: 24 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,28 @@ test('configurability test', function(t) {
t.equal(dump.dirs.test, 'debug', 'gulp.dirs.test should match the setting in package.json');
t.equal(dump.dirs.dist, 'production', 'gulp.dirs.dist should match the setting in package.json');
});
});

test('module shim test', function (t) {
t.plan(6);

exec('gulp check-module-shim', function (error, stdout, stderr) {
t.error(error, 'gulp command should execute without errors');
var actualOutput = false;
stdout.split('\n').forEach(function(line) {
if (line.match(/\[(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]\] Starting 'check-module-shim'.../)) {
actualOutput = true;
} else if (actualOutput) {
if (line.match(/\[(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]\] Finished 'check-module-shim' after [^\n]*/)) {
actualOutput = false;
} else {
var m = line.match(/\[(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]\] ((yes)|(no)) ([^\n]*)/);
if (m) {
t.equal(m[4], 'yes', m[7]);
}
}
}
});
});

});

0 comments on commit 73ee040

Please sign in to comment.