Updates from Wed Feb 25

- [react-packager] Fix lint errors | Amjad Masad
- [react-packager] fix a typo s/pacakge/package | Chengyin Liu
- [react-packager] Fix jest tests | Amjad Masad
- [Image] Really improve the quality of mis-sized images w/trilinear filtering | James Ide
This commit is contained in:
Christopher Chedeau
2015-03-02 10:42:31 -08:00
parent c892d2c8d1
commit 9bebc7e519
40 changed files with 227 additions and 276 deletions

View File

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

View File

@@ -9,8 +9,6 @@ jest
.dontMock('../docblock')
.setMock('../../../ModuleDescriptor', function(data) {return data;});
var q = require('q');
describe('DependencyGraph', function() {
var DependencyGraph;
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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/somedir/somefile.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.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() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@@ -386,7 +414,6 @@ describe('DependencyGraph', function() {
});
describe('file watch updating', function() {
var fileWatcher;
var triggerFileChange;
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() {
filesystem.root['index.js'] =
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() {
filesystem.root['index.js'] =
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() {
delete filesystem.root.foo;
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() {
filesystem.root['bar.js'] = [
'/**',
@@ -679,7 +718,7 @@ describe('DependencyGraph', function() {
pit('should ignore directory updates', function() {
var root = '/root';
var filesystem = fs.__setMockFilesystem({
fs.__setMockFilesystem({
'root': {
'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() {
triggerFileChange('change', 'aPackage', '/root', {
isDirectory: function(){ return true; }

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
'use strict';
var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
@@ -35,7 +36,8 @@ var commentStartRe = /^\/\*\*?/;
var commentEndRe = /\*\/$/;
var wsRe = /[\t ]+/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;
/**
@@ -51,15 +53,15 @@ function parse(docblock) {
// Normalize multi-line directives
var prev = '';
while (prev != docblock) {
while (prev !== docblock) {
prev = docblock;
docblock = docblock.replace(multilineRe, "\n$1 $2\n");
docblock = docblock.replace(multilineRe, '\n$1 $2\n');
}
docblock = docblock.trim();
var result = [];
var match;
while (match = propertyRe.exec(docblock)) {
while ((match = propertyRe.exec(docblock))) {
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,
fromModule.id
);
return;
return null;
}
var main = packageJson.main || 'index';
@@ -147,7 +147,7 @@ DependecyGraph.prototype.resolveDependency = function(
dep = this._graph[modulePath];
if (dep == null) {
throw new Error(
'Cannot find package main file for pacakge: ' + packageJson._root
'Cannot find package main file for package: ' + packageJson._root
);
}
return dep;
@@ -223,7 +223,7 @@ DependecyGraph.prototype._search = function() {
.then(function(filePaths) {
filePaths = filePaths.filter(function(filePath) {
if (filePath == null) {
return false
return false;
}
return !self._ignoreFilePath(filePath);
@@ -454,7 +454,8 @@ DependecyGraph.prototype._getAbsolutePath = function(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);
if (this._graph[absPath]) {
return absPath;

View File

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

View File

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

View File

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

View File

@@ -39,7 +39,7 @@
return ErrorUtils._inGuard;
},
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);
return null;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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