Updates from Wed 1 Jul

This commit is contained in:
Alexsander Akers 2015-07-01 19:10:35 +01:00
commit d8fc316032
10 changed files with 40 additions and 27 deletions

View File

@ -8,6 +8,8 @@
*/ */
'use strict'; 'use strict';
var path = require('path');
// Don't forget to everything listed here to `testConfig.json` // Don't forget to everything listed here to `testConfig.json`
// modulePathIgnorePatterns. // modulePathIgnorePatterns.
var sharedBlacklist = [ var sharedBlacklist = [
@ -24,7 +26,7 @@ var platformBlacklists = {
ios: [ ios: [
'node_modules/react-tools/src/browser/ui/React.js', 'node_modules/react-tools/src/browser/ui/React.js',
'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js', 'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js',
// 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js', 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js',
'.web.js', '.web.js',
'.android.js', '.android.js',
], ],
@ -32,14 +34,16 @@ var platformBlacklists = {
'node_modules/react-tools/src/browser/ui/React.js', 'node_modules/react-tools/src/browser/ui/React.js',
'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js', 'node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js',
'node_modules/react-tools/src/browser/ReactTextComponent.js', 'node_modules/react-tools/src/browser/ReactTextComponent.js',
// 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js', 'node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js',
'.web.js', '.web.js',
'.ios.js', '.ios.js',
], ],
}; };
function escapeRegExp(str) { function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); var escaped = str.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
// convert the '/' into an escaped local file separator
return escaped.replace(/\//g,'\\' + path.sep);
} }
function blacklist(platform, additionalBlacklist) { function blacklist(platform, additionalBlacklist) {

View File

@ -25,7 +25,7 @@
}, },
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"jest-cli": "0.4.5", "jest-cli": "git://github.com/facebook/jest#0.5.x",
"eslint": "0.9.2" "eslint": "0.9.2"
} }
} }

View File

@ -12,6 +12,7 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
var execFile = require('child_process').execFile; var execFile = require('child_process').execFile;
var http = require('http'); var http = require('http');
var isAbsolutePath = require('absolute-path');
var getFlowTypeCheckMiddleware = require('./getFlowTypeCheckMiddleware'); var getFlowTypeCheckMiddleware = require('./getFlowTypeCheckMiddleware');
@ -56,6 +57,11 @@ var options = parseCommandLine([{
}, { }, {
command: 'nonPersistent', command: 'nonPersistent',
description: 'Disable file watcher' description: 'Disable file watcher'
}, {
command: 'transformer',
type: 'string',
default: require.resolve('./transformer.js'),
description: 'Specify a custom transformer to be used (absolute path)'
}]); }]);
if (options.projectRoots) { if (options.projectRoots) {
@ -63,7 +69,8 @@ if (options.projectRoots) {
options.projectRoots = options.projectRoots.split(','); options.projectRoots = options.projectRoots.split(',');
} }
} else { } else {
if (__dirname.match(/node_modules\/react-native\/packager$/)) { // match on either path separator
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]packager$/)) {
// packager is running from node_modules of another project // packager is running from node_modules of another project
options.projectRoots = [path.resolve(__dirname, '../../..')]; options.projectRoots = [path.resolve(__dirname, '../../..')];
} else if (__dirname.match(/Pods\/React\/packager$/)) { } else if (__dirname.match(/Pods\/React\/packager$/)) {
@ -91,7 +98,8 @@ if (options.assetRoots) {
}); });
} }
} else { } else {
if (__dirname.match(/node_modules\/react-native\/packager$/)) { // match on either path separator
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]packager$/)) {
options.assetRoots = [path.resolve(__dirname, '../../..')]; options.assetRoots = [path.resolve(__dirname, '../../..')];
} else if (__dirname.match(/Pods\/React\/packager$/)) { } else if (__dirname.match(/Pods\/React\/packager$/)) {
options.assetRoots = [path.resolve(__dirname, '../../..')]; options.assetRoots = [path.resolve(__dirname, '../../..')];
@ -208,12 +216,17 @@ function statusPageMiddleware(req, res, next) {
} }
function getAppMiddleware(options) { function getAppMiddleware(options) {
var transformerPath = options.transformer;
if (!isAbsolutePath(transformerPath)) {
transformerPath = path.resolve(process.cwd(), transformerPath);
}
return ReactPackager.middleware({ return ReactPackager.middleware({
nonPersistent: options.nonPersistent, nonPersistent: options.nonPersistent,
projectRoots: options.projectRoots, projectRoots: options.projectRoots,
blacklistRE: blacklist(options.platform), blacklistRE: blacklist(options.platform),
cacheVersion: '2', cacheVersion: '2',
transformModulePath: require.resolve('./transformer.js'), transformModulePath: transformerPath,
assetRoots: options.assetRoots, assetRoots: options.assetRoots,
assetExts: ['png', 'jpeg', 'jpg'], assetExts: ['png', 'jpeg', 'jpg'],
polyfillModuleNames: [ polyfillModuleNames: [

View File

@ -8,7 +8,7 @@
*/ */
'use strict'; 'use strict';
require('babel/register')({ require('babel-core/register')({
only: /react-packager\/src/ only: /react-packager\/src/
}); });

View File

@ -2353,7 +2353,8 @@ describe('DependencyGraph', function() {
} }
callbacks.push(callback); callbacks.push(callback);
return this; return this;
} },
isWatchman: () => Promise.resolve(false),
}; };
}); });

View File

@ -29,6 +29,7 @@ const validateOpts = declareOpts({
}, },
ignoreFilePath: { ignoreFilePath: {
type: 'function', type: 'function',
default: function(){} default: function(){}
}, },
fileWatcher: { fileWatcher: {

View File

@ -1,21 +1,11 @@
'use strict'; 'use strict';
const nodeCrawl = require('./node'); const nodeCrawl = require('./node');
//const watchmanCrawl = require('./watchman'); const watchmanCrawl = require('./watchman');
function crawl(roots, options) { function crawl(roots, options) {
return nodeCrawl(roots, options);
// Although, in theory, watchman should be much faster;
// there is currently a bottleneck somewhere in the
// encoding/decoding that is causing it to be slower
// than node crawling. However, this should be fixed soon.
// https://github.com/facebook/watchman/issues/113
/*
const {fileWatcher} = options; const {fileWatcher} = options;
return fileWatcher.isWatchman().then(isWatchman => { return fileWatcher.isWatchman().then(isWatchman => {
console.log(isWatchman);
if (!isWatchman) { if (!isWatchman) {
return false; return false;
} }
@ -30,7 +20,7 @@ function crawl(roots, options) {
} }
return nodeCrawl(roots, options); return nodeCrawl(roots, options);
});*/ });
} }
module.exports = crawl; module.exports = crawl;

View File

@ -36,7 +36,7 @@ function watchmanRecReadDir(roots, {ignore, fileWatcher, exts}) {
} }
} }
const cmd = Promise.promisify(watcher.client.command.bind(watcher.client)); const cmd = Promise.denodeify(watcher.client.command.bind(watcher.client));
return cmd(['query', watchedRoot, { return cmd(['query', watchedRoot, {
'suffix': exts, 'suffix': exts,
'expression': ['allof', ['type', 'f'], 'exists', dirExpr], 'expression': ['allof', ['type', 'f'], 'exists', dirExpr],

View File

@ -12,9 +12,11 @@ const EventEmitter = require('events').EventEmitter;
const sane = require('sane'); const sane = require('sane');
const Promise = require('promise'); const Promise = require('promise');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const _ = require('underscore');
const MAX_WAIT_TIME = 25000; const MAX_WAIT_TIME = 25000;
// TODO(amasad): can we use watchman version command instead?r
const detectingWatcherClass = new Promise(function(resolve) { const detectingWatcherClass = new Promise(function(resolve) {
exec('which watchman', function(err, out) { exec('which watchman', function(err, out) {
if (err || out.length === 0) { if (err || out.length === 0) {
@ -79,9 +81,11 @@ class FileWatcher extends EventEmitter {
static createDummyWatcher() { static createDummyWatcher() {
const ev = new EventEmitter(); const ev = new EventEmitter();
ev.end = function() { _.extend(ev, {
return Promise.resolve(); isWatchman: () => Promise.resolve(false),
}; end: () => Promise.resolve(),
});
return ev; return ev;
} }
} }

View File

@ -10,7 +10,7 @@
*/ */
'use strict'; 'use strict';
var babel = require('babel'); var babel = require('babel-core');
function transform(srcTxt, filename, options) { function transform(srcTxt, filename, options) {
var result = babel.transform(srcTxt, { var result = babel.transform(srcTxt, {