[react-packager] Fix lint errors

This commit is contained in:
Amjad Masad 2015-02-25 20:29:14 -08:00
parent 3d65001426
commit d740d17d42
32 changed files with 198 additions and 254 deletions

View File

@ -1,86 +0,0 @@
{
"-W093": true,
"asi": false,
"bitwise": true,
"boss": false,
"browser": false,
"camelcase": true,
"couch": false,
"curly": true,
"debug": false,
"devel": true,
"dojo": false,
"eqeqeq": true,
"eqnull": true,
"esnext": true,
"evil": false,
"expr": true,
"forin": false,
"freeze": true,
"funcscope": true,
"gcl": false,
"globals": {
"Promise": true,
"React": true,
"XMLHttpRequest": true,
"document": true,
"location": true,
"window": true
},
"globalstrict": true,
"immed": false,
"indent": 2,
"iterator": false,
"jquery": false,
"lastsemic": false,
"latedef": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"maxcomplexity": false,
"maxdepth": false,
"maxerr": 50,
"maxlen": 80,
"maxparams": false,
"maxstatements": false,
"mootools": false,
"moz": false,
"multistr": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": false,
"nonbsp": true,
"nonew": true,
"nonstandard": false,
"notypeof": false,
"noyield": false,
"phantom": false,
"plusplus": false,
"predef": [
"afterEach",
"beforeEach",
"describe",
"expect",
"it",
"jest",
"pit"
],
"proto": false,
"prototypejs": false,
"quotmark": true,
"rhino": false,
"scripturl": false,
"shadow": false,
"smarttabs": false,
"strict": false,
"sub": false,
"supernew": false,
"trailing": true,
"undef": true,
"unused": true,
"validthis": false,
"worker": false,
"wsh": false,
"yui": false
}

View File

@ -1,3 +1,5 @@
'use strict';
jest.autoMockOff(); jest.autoMockOff();
describe('Activity', function() { describe('Activity', function() {

View File

@ -1,3 +1,5 @@
'use strict';
var COLLECTION_PERIOD = 1000; var COLLECTION_PERIOD = 1000;
var _endedEvents = Object.create(null); var _endedEvents = Object.create(null);

View File

@ -1,3 +1,5 @@
'use strict';
function ModuleDescriptor(fields) { function ModuleDescriptor(fields) {
if (!fields.id) { if (!fields.id) {
throw new Error('Missing required fields id'); throw new Error('Missing required fields id');
@ -28,7 +30,7 @@ ModuleDescriptor.prototype.toJSON = function() {
id: this.id, id: this.id,
path: this.path, path: this.path,
dependencies: this.dependencies dependencies: this.dependencies
} };
}; };
module.exports = ModuleDescriptor; module.exports = ModuleDescriptor;

View File

@ -9,8 +9,6 @@ jest
.dontMock('../docblock') .dontMock('../docblock')
.setMock('../../../ModuleDescriptor', function(data) {return data;}); .setMock('../../../ModuleDescriptor', function(data) {return data;});
var q = require('q');
describe('DependencyGraph', function() { describe('DependencyGraph', function() {
var DependencyGraph; var DependencyGraph;
var fileWatcher; var fileWatcher;
@ -46,7 +44,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -75,7 +76,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -105,7 +109,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -135,7 +142,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -175,7 +185,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/somedir/somefile.js')) expect(dgraph.getOrderedDependencies('/root/somedir/somefile.js'))
.toEqual([ .toEqual([
@ -216,7 +229,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -245,7 +261,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -280,7 +299,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -320,7 +342,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -360,7 +385,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js')) expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([ .toEqual([
@ -386,7 +414,6 @@ describe('DependencyGraph', function() {
}); });
describe('file watch updating', function() { describe('file watch updating', function() {
var fileWatcher;
var triggerFileChange; var triggerFileChange;
beforeEach(function() { beforeEach(function() {
@ -428,7 +455,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
filesystem.root['index.js'] = filesystem.root['index.js'] =
filesystem.root['index.js'].replace('require("foo")', ''); filesystem.root['index.js'].replace('require("foo")', '');
@ -476,7 +506,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
filesystem.root['index.js'] = filesystem.root['index.js'] =
filesystem.root['index.js'].replace('require("foo")', ''); filesystem.root['index.js'].replace('require("foo")', '');
@ -524,7 +557,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
delete filesystem.root.foo; delete filesystem.root.foo;
triggerFileChange('delete', 'foo.js', root); triggerFileChange('delete', 'foo.js', root);
@ -571,7 +607,10 @@ describe('DependencyGraph', function() {
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
filesystem.root['bar.js'] = [ filesystem.root['bar.js'] = [
'/**', '/**',
@ -679,7 +718,7 @@ describe('DependencyGraph', function() {
pit('should ignore directory updates', function() { pit('should ignore directory updates', function() {
var root = '/root'; var root = '/root';
var filesystem = fs.__setMockFilesystem({ fs.__setMockFilesystem({
'root': { 'root': {
'index.js': [ 'index.js': [
'/**', '/**',
@ -703,7 +742,10 @@ describe('DependencyGraph', function() {
} }
} }
}); });
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher}); var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() { return dgraph.load().then(function() {
triggerFileChange('change', 'aPackage', '/root', { triggerFileChange('change', 'aPackage', '/root', {
isDirectory: function(){ return true; } isDirectory: function(){ return true; }

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
'use strict';
var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/; var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
@ -35,7 +36,8 @@ var commentStartRe = /^\/\*\*?/;
var commentEndRe = /\*\/$/; var commentEndRe = /\*\/$/;
var wsRe = /[\t ]+/g; var wsRe = /[\t ]+/g;
var stringStartRe = /(\r?\n|^) *\*/g; var stringStartRe = /(\r?\n|^) *\*/g;
var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g; var multilineRe =
/(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g; var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
/** /**
@ -51,15 +53,15 @@ function parse(docblock) {
// Normalize multi-line directives // Normalize multi-line directives
var prev = ''; var prev = '';
while (prev != docblock) { while (prev !== docblock) {
prev = docblock; prev = docblock;
docblock = docblock.replace(multilineRe, "\n$1 $2\n"); docblock = docblock.replace(multilineRe, '\n$1 $2\n');
} }
docblock = docblock.trim(); docblock = docblock.trim();
var result = []; var result = [];
var match; var match;
while (match = propertyRe.exec(docblock)) { while ((match = propertyRe.exec(docblock))) {
result.push([match[1], match[2]]); result.push([match[1], match[2]]);
} }

View File

@ -1,25 +0,0 @@
var path = require('path');
var DependecyGraph = require('./');
var example_project = path.resolve(__dirname, '../../../../example_project');
var watcher = new (require('../../../FileWatcher'))({projectRoot: example_project});
var graph = new DependecyGraph({
fileWatcher: watcher,
root: example_project
});
graph.load().then(function() {
var index = path.join(example_project, 'index.js');
console.log(graph.getOrderedDependencies(index));
}).done();
watcher.getWatcher().then(function(watcher) {
watcher.on('all', function() {
setImmediate(function() {
graph.load().then(function() {
var index = path.join(example_project, 'index.js');
console.log(graph.getOrderedDependencies(index));
});
})
});
});

View File

@ -139,7 +139,7 @@ DependecyGraph.prototype.resolveDependency = function(
depModuleId, depModuleId,
fromModule.id fromModule.id
); );
return; return null;
} }
var main = packageJson.main || 'index'; var main = packageJson.main || 'index';
@ -223,7 +223,7 @@ DependecyGraph.prototype._search = function() {
.then(function(filePaths) { .then(function(filePaths) {
filePaths = filePaths.filter(function(filePath) { filePaths = filePaths.filter(function(filePath) {
if (filePath == null) { if (filePath == null) {
return false return false;
} }
return !self._ignoreFilePath(filePath); return !self._ignoreFilePath(filePath);
@ -454,7 +454,8 @@ DependecyGraph.prototype._getAbsolutePath = function(filePath) {
return filePath; return filePath;
} }
for (var i = 0, root; root = this._roots[i]; i++) { for (var i = 0; i < this._roots.length; i++) {
var root = this._roots[i];
var absPath = path.join(root, filePath); var absPath = path.join(root, filePath);
if (this._graph[absPath]) { if (this._graph[absPath]) {
return absPath; return absPath;

View File

@ -1,3 +1,4 @@
'use strict';
jest.dontMock('../') jest.dontMock('../')
.dontMock('q') .dontMock('q')
@ -7,7 +8,6 @@ var q = require('q');
describe('HasteDependencyResolver', function() { describe('HasteDependencyResolver', function() {
var HasteDependencyResolver; var HasteDependencyResolver;
var DependencyGraph;
beforeEach(function() { beforeEach(function() {
// For the polyfillDeps // For the polyfillDeps
@ -15,7 +15,6 @@ describe('HasteDependencyResolver', function() {
return b; return b;
}); });
HasteDependencyResolver = require('../'); HasteDependencyResolver = require('../');
DependencyGraph = require('../DependencyGraph');
}); });
describe('getDependencies', function() { describe('getDependencies', function() {
@ -223,7 +222,7 @@ describe('HasteDependencyResolver', function() {
}); });
var depGraph = depResolver._depGraph; var depGraph = depResolver._depGraph;
var dependencies = ['x', 'y', 'z'] var dependencies = ['x', 'y', 'z'];
var code = [ var code = [
'require("x")', 'require("x")',
'require("y")', 'require("y")',
@ -248,10 +247,10 @@ describe('HasteDependencyResolver', function() {
}, code); }, code);
expect(processedCode).toEqual([ expect(processedCode).toEqual([
"__d('test module',[\"changed\",\"y\"],function(global," + '__d(\'test module\',["changed","y"],function(global,' +
" require, requireDynamic, requireLazy, module, exports) {" + ' require, requireDynamic, requireLazy, module, exports) {' +
" require('changed')", ' require(\'changed\')',
"require('y')", 'require(\'y\')',
'require("z")});', 'require("z")});',
].join('\n')); ].join('\n'));
}); });

View File

@ -6,14 +6,15 @@ var DependencyGraph = require('./DependencyGraph');
var ModuleDescriptor = require('../ModuleDescriptor'); var ModuleDescriptor = require('../ModuleDescriptor');
var declareOpts = require('../../lib/declareOpts'); var declareOpts = require('../../lib/declareOpts');
var DEFINE_MODULE_CODE = var DEFINE_MODULE_CODE = [
'__d(' + '__d(',
'\'_moduleName_\',' + '\'_moduleName_\',',
'_deps_,' + '_deps_,',
'function(global, require, requireDynamic, requireLazy, module, exports) {'+ 'function(global, require, requireDynamic, requireLazy, module, exports) {',
' _code_' + ' _code_',
'}' + '}',
');'; ');',
].join('');
var DEFINE_MODULE_REPLACE_RE = /_moduleName_|_code_|_deps_/g; var DEFINE_MODULE_REPLACE_RE = /_moduleName_|_code_|_deps_/g;
@ -116,7 +117,6 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
return code; return code;
} }
var depGraph = this._depGraph;
var resolvedDeps = Object.create(null); var resolvedDeps = Object.create(null);
var resolvedDepsArr = []; var resolvedDepsArr = [];
@ -131,9 +131,9 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
var relativizedCode = var relativizedCode =
code.replace(REL_REQUIRE_STMT, function(codeMatch, depName) { code.replace(REL_REQUIRE_STMT, function(codeMatch, depName) {
var dep = resolvedDeps[depName]; var depId = resolvedDeps[depName];
if (dep != null) { if (depId != null) {
return 'require(\'' + dep + '\')'; return 'require(\'' + depId + '\')';
} else { } else {
return codeMatch; return codeMatch;
} }

View File

@ -20,7 +20,9 @@
* @polyfill * @polyfill
*/ */
/*eslint global-strict:0*/
(function(global) { (function(global) {
'use strict';
var OBJECT_COLUMN_NAME = '(index)'; var OBJECT_COLUMN_NAME = '(index)';
@ -45,7 +47,7 @@
if (typeof arg.toString === 'function') { if (typeof arg.toString === 'function') {
try { try {
return arg.toString(); return arg.toString();
} catch (e) { } catch (E) {
return 'unknown'; return 'unknown';
} }
} }
@ -53,7 +55,7 @@
} }
}).join(', '); }).join(', ');
global.nativeLoggingHook(str); global.nativeLoggingHook(str);
}; }
var repeat = function(element, n) { var repeat = function(element, n) {
return Array.apply(null, Array(n)).map(function() { return element; }); return Array.apply(null, Array(n)).map(function() { return element; });
@ -120,7 +122,7 @@
// logged string, which would shift the header and screw up // logged string, which would shift the header and screw up
// the table // the table
global.nativeLoggingHook('\n' + table.join('\n')); global.nativeLoggingHook('\n' + table.join('\n'));
}; }
global.console = { global.console = {
error: doNativeLog, error: doNativeLog,
@ -130,7 +132,7 @@
table: consoleTablePolyfill table: consoleTablePolyfill
}; };
}; }
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
module.exports = setupConsole; module.exports = setupConsole;

View File

@ -39,7 +39,7 @@
return ErrorUtils._inGuard; return ErrorUtils._inGuard;
}, },
guard: function(fun, name, context) { guard: function(fun, name, context) {
if (typeof fun !== "function") { if (typeof fun !== 'function') {
console.warn('A function must be passed to ErrorUtils.guard, got ', fun); console.warn('A function must be passed to ErrorUtils.guard, got ', fun);
return null; return null;
} }

View File

@ -22,7 +22,7 @@
// WARNING: This is an optimized version that fails on hasOwnProperty checks // WARNING: This is an optimized version that fails on hasOwnProperty checks
// and non objects. It's not spec-compliant. It's a perf optimization. // and non objects. It's not spec-compliant. It's a perf optimization.
/* eslint global-strict:0 */
Object.assign = function(target, sources) { Object.assign = function(target, sources) {
if (__DEV__) { if (__DEV__) {
if (target == null) { if (target == null) {

View File

@ -1 +1,2 @@
/* eslint global-strict:0 */
__DEV__ = false; __DEV__ = false;

View File

@ -1 +1,2 @@
/* eslint global-strict:0 */
__DEV__ = true; __DEV__ = true;

View File

@ -1,3 +1,4 @@
/* eslint global-strict:0,eqeqeq:0,no-bitwise:0,no-undef:0 */
(function(global) { (function(global) {
// avoid redefining require() // avoid redefining require()

View File

@ -1,3 +1,5 @@
'use strict';
var HasteDependencyResolver = require('./haste'); var HasteDependencyResolver = require('./haste');
var NodeDependencyResolver = require('./node'); var NodeDependencyResolver = require('./node');

View File

@ -1,17 +1,12 @@
'use strict';
var Promise = require('q').Promise; var Promise = require('q').Promise;
var ModuleDescriptor = require('../ModuleDescriptor'); var ModuleDescriptor = require('../ModuleDescriptor');
var mdeps = require('module-deps'); var mdeps = require('module-deps');
var path = require('path'); var path = require('path');
var fs = require('fs');
// var REQUIRE_RUNTIME = fs.readFileSync( exports.getRuntimeCode = function() {};
// path.join(__dirname, 'require.js')
// ).toString();
exports.getRuntimeCode = function() {
return REQUIRE_RUNTIME;
};
exports.wrapModule = function(id, source) { exports.wrapModule = function(id, source) {
return Promise.resolve( return Promise.resolve(
@ -21,7 +16,7 @@ exports.wrapModule = function(id, source) {
}; };
exports.getDependencies = function(root, fileEntryPath) { exports.getDependencies = function(root, fileEntryPath) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve) {
fileEntryPath = path.join(process.cwd(), root, fileEntryPath); fileEntryPath = path.join(process.cwd(), root, fileEntryPath);
var md = mdeps(); var md = mdeps();

View File

@ -1,8 +1,12 @@
'use strict'; 'use strict';
jest.dontMock('../') jest
.dontMock('q') .dontMock('../')
.setMock('child_process', { exec: function(cmd, cb) { cb(null, '/usr/bin/watchman') } }); .dontMock('q')
.setMock(
'child_process',
{ exec: function(cmd, cb) { cb(null, '/usr/bin/watchman'); } }
);
describe('FileWatcher', function() { describe('FileWatcher', function() {
var FileWatcher; var FileWatcher;

View File

@ -3,7 +3,7 @@
var path = require('path'); var path = require('path');
var version = require('../../../../package.json').version; var version = require('../../../../package.json').version;
var tmpdir = require('os').tmpDir(); var tmpdir = require('os').tmpDir();
var pathUtils = require('../fb-path-utils'); var isAbsolutePath = require('absolute-path');
var declareOpts = require('../lib/declareOpts'); var declareOpts = require('../lib/declareOpts');
var fs = require('fs'); var fs = require('fs');
var _ = require('underscore'); var _ = require('underscore');
@ -48,7 +48,7 @@ function Cache(options) {
} }
Cache.prototype.get = function(filepath, loaderCb) { Cache.prototype.get = function(filepath, loaderCb) {
if (!pathUtils.isAbsolutePath(filepath)) { if (!isAbsolutePath(filepath)) {
throw new Error('Use absolute paths'); throw new Error('Use absolute paths');
} }
@ -62,7 +62,7 @@ Cache.prototype.get = function(filepath, loaderCb) {
}; };
Cache.prototype._set = function(filepath, loaderPromise) { Cache.prototype._set = function(filepath, loaderPromise) {
return this._data[filepath] = loaderPromise.then(function(data) { this._data[filepath] = loaderPromise.then(function(data) {
return [ return [
data, data,
q.nfbind(fs.stat)(filepath) q.nfbind(fs.stat)(filepath)
@ -74,10 +74,12 @@ Cache.prototype._set = function(filepath, loaderPromise) {
mtime: stat.mtime.getTime(), mtime: stat.mtime.getTime(),
}; };
}.bind(this)); }.bind(this));
return this._data[filepath];
}; };
Cache.prototype.invalidate = function(filepath){ Cache.prototype.invalidate = function(filepath){
if(this._has(filepath)) { if (this._has(filepath)) {
delete this._data[filepath]; delete this._data[filepath];
} }
}; };
@ -94,7 +96,7 @@ Cache.prototype._persistCache = function() {
var data = this._data; var data = this._data;
var cacheFilepath = this._cacheFilePath; var cacheFilepath = this._cacheFilePath;
return this._persisting = q.all(_.values(data)) this._persisting = q.all(_.values(data))
.then(function(values) { .then(function(values) {
var json = Object.create(null); var json = Object.create(null);
Object.keys(data).forEach(function(key, i) { Object.keys(data).forEach(function(key, i) {
@ -106,6 +108,8 @@ Cache.prototype._persistCache = function() {
this._persisting = null; this._persisting = null;
return true; return true;
}.bind(this)); }.bind(this));
return this._persisting;
}; };
function loadCacheSync(cacheFilepath) { function loadCacheSync(cacheFilepath) {

View File

@ -5,7 +5,6 @@ jest
.dontMock('path') .dontMock('path')
.dontMock('q') .dontMock('q')
.dontMock('absolute-path') .dontMock('absolute-path')
.dontMock('../../fb-path-utils')
.dontMock('../Cache'); .dontMock('../Cache');
var q = require('q'); var q = require('q');

View File

@ -7,6 +7,7 @@ var Cache = require('./Cache');
var _ = require('underscore'); var _ = require('underscore');
var workerFarm = require('worker-farm'); var workerFarm = require('worker-farm');
var declareOpts = require('../lib/declareOpts'); var declareOpts = require('../lib/declareOpts');
var util = require('util');
var readFile = q.nfbind(fs.readFile); var readFile = q.nfbind(fs.readFile);
@ -75,9 +76,7 @@ Transformer.prototype.kill = function() {
Transformer.prototype.invalidateFile = function(filePath) { Transformer.prototype.invalidateFile = function(filePath) {
this._cache.invalidate(filePath); this._cache.invalidate(filePath);
//TODO: We can read the file and put it into the cache right here };
// This would simplify some caching logic as we can be sure that the cache is up to date
}
Transformer.prototype.loadFileAndTransform = function( Transformer.prototype.loadFileAndTransform = function(
transformSets, transformSets,
@ -116,7 +115,7 @@ Transformer.prototype.loadFileAndTransform = function(
}; };
function TransformError() {} function TransformError() {}
TransformError.__proto__ = SyntaxError.prototype; util.inherits(TransformError, SyntaxError);
function formatEsprimaError(err, filename, source) { function formatEsprimaError(err, filename, source) {
if (!(err.lineNumber && err.column)) { if (!(err.lineNumber && err.column)) {

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var _ = require('underscore'); var _ = require('underscore');
var SourceMapGenerator = require('source-map').SourceMapGenerator;
var base64VLQ = require('./base64-vlq'); var base64VLQ = require('./base64-vlq');
module.exports = Package; module.exports = Package;
@ -102,7 +101,7 @@ Package.prototype._getMappings = function() {
mappings += ';'; mappings += ';';
} }
} }
if (i != modules.length - 1) { if (i !== modules.length - 1) {
mappings += ';'; mappings += ';';
} }
} }

View File

@ -1,5 +0,0 @@
var SourceMapGenerator = jest.genMockFn();
SourceMapGenerator.prototype.addMapping = jest.genMockFn();
SourceMapGenerator.prototype.setSourceContent = jest.genMockFn();
SourceMapGenerator.prototype.toJSON = jest.genMockFn();
exports.SourceMapGenerator = SourceMapGenerator;

View File

@ -50,13 +50,13 @@ describe('Package', function() {
describe('sourcemap package', function() { describe('sourcemap package', function() {
it('should create sourcemap', function() { it('should create sourcemap', function() {
var ppackage = new Package('test_url'); var p = new Package('test_url');
ppackage.addModule('transformed foo;\n', 'source foo', 'foo path'); p.addModule('transformed foo;\n', 'source foo', 'foo path');
ppackage.addModule('transformed bar;\n', 'source bar', 'bar path'); p.addModule('transformed bar;\n', 'source bar', 'bar path');
ppackage.setMainModuleId('foo'); p.setMainModuleId('foo');
ppackage.finalize({runMainModule: true}); p.finalize({runMainModule: true});
var s = ppackage.getSourceMap(); var s = p.getSourceMap();
expect(s).toEqual(genSourceMap(ppackage._modules)); expect(s).toEqual(genSourceMap(p._modules));
}); });
}); });
}); });
@ -92,4 +92,4 @@ describe('Package', function() {
); );
} }
return sourceMapGen.toJSON(); return sourceMapGen.toJSON();
}; }

View File

@ -35,9 +35,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*eslint no-bitwise:0,quotes:0,global-strict:0*/
var charToIntMap = {}; var charToIntMap = {};
var intToCharMap = {}; var intToCharMap = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
.split('') .split('')
.forEach(function (ch, index) { .forEach(function (ch, index) {
@ -55,7 +57,7 @@ base64.encode = function base64_encode(aNumber) {
} }
throw new TypeError("Must be between 0 and 63: " + aNumber); throw new TypeError("Must be between 0 and 63: " + aNumber);
}; };
/** /**
* Decode a single base 64 digit to an integer. * Decode a single base 64 digit to an integer.
*/ */
@ -65,7 +67,7 @@ base64.decode = function base64_decode(aChar) {
} }
throw new TypeError("Not a valid base 64 digit: " + aChar); throw new TypeError("Not a valid base 64 digit: " + aChar);
}; };
// A single base 64 digit can contain 6 bits of data. For the base 64 variable // A single base 64 digit can contain 6 bits of data. For the base 64 variable
@ -165,4 +167,3 @@ exports.decode = function base64VLQ_decode(aStr, aOutParam) {
aOutParam.value = fromVLQSigned(result); aOutParam.value = fromVLQSigned(result);
aOutParam.rest = aStr.slice(i); aOutParam.rest = aStr.slice(i);
}; };

View File

@ -1,4 +1,6 @@
jest.setMock('worker-farm', function(){ return function(){}; }) 'use strict';
jest.setMock('worker-farm', function() { return function() {}; })
.dontMock('q') .dontMock('q')
.dontMock('os') .dontMock('os')
.dontMock('errno/custom') .dontMock('errno/custom')
@ -8,9 +10,8 @@ jest.setMock('worker-farm', function(){ return function(){}; })
var q = require('q'); var q = require('q');
describe('processRequest', function(){ describe('processRequest', function() {
var server; var server;
var Activity;
var Packager; var Packager;
var FileWatcher; var FileWatcher;
@ -21,16 +22,16 @@ describe('processRequest', function(){
polyfillModuleNames: null polyfillModuleNames: null
}; };
var makeRequest = function(requestHandler, requrl){ var makeRequest = function(requestHandler, requrl) {
var deferred = q.defer(); var deferred = q.defer();
requestHandler({ requestHandler({
url: requrl url: requrl
},{ },{
end: function(res){ end: function(res) {
deferred.resolve(res); deferred.resolve(res);
} }
},{ },{
next: function(){} next: function() {}
} }
); );
return deferred.promise; return deferred.promise;
@ -40,8 +41,7 @@ describe('processRequest', function(){
var watcherFunc = jest.genMockFunction(); var watcherFunc = jest.genMockFunction();
var requestHandler; var requestHandler;
beforeEach(function(){ beforeEach(function() {
Activity = require('../../Activity');
Packager = require('../../Packager'); Packager = require('../../Packager');
FileWatcher = require('../../FileWatcher'); FileWatcher = require('../../FileWatcher');
@ -50,7 +50,7 @@ describe('processRequest', function(){
getSource: function() { getSource: function() {
return 'this is the source'; return 'this is the source';
}, },
getSourceMap: function(){ getSourceMap: function() {
return 'this is the source map'; return 'this is the source map';
}, },
}); });
@ -65,26 +65,32 @@ describe('processRequest', function(){
requestHandler = server.processRequest.bind(server); requestHandler = server.processRequest.bind(server);
}); });
pit('returns JS bundle source on request of *.bundle',function(){ pit('returns JS bundle source on request of *.bundle',function() {
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle'); return makeRequest(
return result.then(function(response){ requestHandler,
expect(response).toEqual("this is the source"); 'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
expect(response).toEqual('this is the source');
}); });
}); });
pit('returns sourcemap on request of *.map', function(){ pit('returns sourcemap on request of *.map', function() {
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle.map'); makeRequest(
return result.then(function(response){ requestHandler,
expect(response).toEqual('"this is the source map"'); 'mybundle.includeRequire.runModule.bundle.map'
).then(function(response) {
expect(response).toEqual('this is the source map');
}); });
}); });
pit('watches all files in projectRoot', function(){ pit('watches all files in projectRoot', function() {
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle'); makeRequest(
return result.then(function(response){ requestHandler,
'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
expect(watcherFunc.mock.calls[0][0]).toEqual('all'); expect(watcherFunc.mock.calls[0][0]).toEqual('all');
expect(watcherFunc.mock.calls[0][1]).not.toBe(null); expect(watcherFunc.mock.calls[0][1]).not.toBe(null);
}) });
}); });
@ -101,8 +107,10 @@ describe('processRequest', function(){
}); });
pit('invalides files in package when file is updated', function() { pit('invalides files in package when file is updated', function() {
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle'); makeRequest(
return result.then(function(response){ requestHandler,
'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
var onFileChange = watcherFunc.mock.calls[0][1]; var onFileChange = watcherFunc.mock.calls[0][1];
onFileChange('all','path/file.js', options.projectRoots[0]); onFileChange('all','path/file.js', options.projectRoots[0]);
expect(invalidatorFunc.mock.calls[0][0]).toEqual('root/path/file.js'); expect(invalidatorFunc.mock.calls[0][0]).toEqual('root/path/file.js');
@ -114,41 +122,41 @@ describe('processRequest', function(){
packageFunc packageFunc
.mockReturnValueOnce( .mockReturnValueOnce(
q({ q({
getSource: function(){ getSource: function() {
return "this is the first source" return 'this is the first source';
}, },
getSourceMap: function(){}, getSourceMap: function() {},
}) })
) )
.mockReturnValue( .mockReturnValue(
q({ q({
getSource: function(){ getSource: function() {
return "this is the rebuilt source" return 'this is the rebuilt source';
}, },
getSourceMap: function(){}, getSourceMap: function() {},
}) })
); );
Packager.prototype.package = packageFunc; Packager.prototype.package = packageFunc;
var Server = require('../../Server'); var Server = require('../../Server');
var server = new Server(options); server = new Server(options);
requestHandler = server.processRequest.bind(server); requestHandler = server.processRequest.bind(server);
return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle') return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle')
.then(function(response){ .then(function(response) {
expect(response).toEqual("this is the first source"); expect(response).toEqual('this is the first source');
expect(packageFunc.mock.calls.length).toBe(1); expect(packageFunc.mock.calls.length).toBe(1);
triggerFileChange('all','path/file.js', options.projectRoots[0]); triggerFileChange('all','path/file.js', options.projectRoots[0]);
jest.runAllTimers(); jest.runAllTimers();
}) })
.then(function(){ .then(function() {
expect(packageFunc.mock.calls.length).toBe(2); expect(packageFunc.mock.calls.length).toBe(2);
return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle') return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle')
.then(function(response){ .then(function(response) {
expect(response).toEqual("this is the rebuilt source"); expect(response).toEqual('this is the rebuilt source');
}); });
}); });
}); });

View File

@ -1,3 +1,5 @@
'use strict';
var url = require('url'); var url = require('url');
var path = require('path'); var path = require('path');
var declareOpts = require('../lib/declareOpts'); var declareOpts = require('../lib/declareOpts');
@ -154,7 +156,7 @@ Server.prototype.processRequest = function(req, res, next) {
var startReqEventId = Activity.startEvent('request:' + req.url); var startReqEventId = Activity.startEvent('request:' + req.url);
var options = getOptionsFromPath(url.parse(req.url).pathname); var options = getOptionsFromPath(url.parse(req.url).pathname);
var building = this._packages[req.url] || this._buildPackage(options) var building = this._packages[req.url] || this._buildPackage(options);
this._packages[req.url] = building; this._packages[req.url] = building;
building.then( building.then(
function(p) { function(p) {

View File

@ -1,14 +0,0 @@
var absolutePath = require('absolute-path');
var path = require('path');
var pathIsInside = require('path-is-inside');
function isAbsolutePath(pathStr) {
return absolutePath(pathStr);
}
function isChildPath(parentPath, childPath) {
return pathIsInside(parentPath, childPath);
}
exports.isAbsolutePath = isAbsolutePath;
exports.isChildPath = isChildPath;

View File

@ -1,3 +1,5 @@
'use strict';
module.exports = function(declared) { module.exports = function(declared) {
return function(opts) { return function(opts) {
for (var p in declared) { for (var p in declared) {

View File

@ -1,3 +1,5 @@
'use strict';
jest.autoMockOff(); jest.autoMockOff();
var declareOpts = require('../declareOpts'); var declareOpts = require('../declareOpts');

View File

@ -10,6 +10,8 @@
* var myOptions = validate(someOptions); * var myOptions = validate(someOptions);
*/ */
'use strict';
var Joi = require('joi'); var Joi = require('joi');
module.exports = function(descriptor) { module.exports = function(descriptor) {