Remove `react-packager` indirection.

Summary:
This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense.

Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change?

Reviewed By: jeanlauliac

Differential Revision: D4487867

fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb
This commit is contained in:
Christoph Pojer 2017-02-02 05:30:03 -08:00 committed by Facebook Github Bot
parent 0ecc4047af
commit a2c84d14ce
156 changed files with 121 additions and 81 deletions

View File

@ -12,7 +12,7 @@
'use strict';
// This is a stub for flow to make it understand require('./icon.png')
// See packager/react-packager/src/Bundler/index.js
// See packager/src/Bundler/index.js
var AssetRegistry = require('AssetRegistry');

View File

@ -15,7 +15,7 @@ const path = require('path');
const nodeFiles = RegExp([
'/local-cli/',
'/packager/(?!react-packager/src/Resolver/polyfills/)',
'/packager/(?!src/Resolver/polyfills/)',
].join('|'));
const nodeOptions = babelRegisterOnly.config([nodeFiles]);

View File

@ -10,9 +10,9 @@
const mockComponent = require.requireActual('./mockComponent');
require.requireActual('../packager/react-packager/src/Resolver/polyfills/babelHelpers.js');
require.requireActual('../packager/react-packager/src/Resolver/polyfills/Object.es7.js');
require.requireActual('../packager/react-packager/src/Resolver/polyfills/error-guard');
require.requireActual('../packager/src/Resolver/polyfills/babelHelpers.js');
require.requireActual('../packager/src/Resolver/polyfills/Object.es7.js');
require.requireActual('../packager/src/Resolver/polyfills/error-guard');
global.__DEV__ = true;

View File

@ -12,8 +12,8 @@
'use strict';
const log = require('../util/log').out('bundle');
const Server = require('../../packager/react-packager/src/Server');
const TerminalReporter = require('../../packager/react-packager/src/lib/TerminalReporter');
const Server = require('../../packager/src/Server');
const TerminalReporter = require('../../packager/src/lib/TerminalReporter');
const outputBundle = require('./output/bundle');
const path = require('path');

View File

@ -11,11 +11,11 @@
'use strict';
const meta = require('./meta');
const relativizeSourceMap = require('../../../packager/react-packager/src/lib/relativizeSourceMap');
const relativizeSourceMap = require('../../../packager/src//lib/relativizeSourceMap');
const writeFile = require('./writeFile');
import type Bundle from '../../../packager/react-packager/src/Bundler/Bundle';
import type Server from '../../../packager/react-packager/src/Server';
import type Bundle from '../../../packager/src//Bundler/Bundle';
import type Server from '../../../packager/src//Server';
import type {OutputOptions, RequestOptions} from '../types.flow';
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {

View File

@ -15,13 +15,13 @@ const MAGIC_UNBUNDLE_NUMBER = require('./magic-number');
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
const mkdirp = require('mkdirp');
const path = require('path');
const relativizeSourceMap = require('../../../../packager/react-packager/src/lib/relativizeSourceMap');
const relativizeSourceMap = require('../../../../packager/src//lib/relativizeSourceMap');
const writeFile = require('../writeFile');
const writeSourceMap = require('./write-sourcemap');
const {joinModules} = require('./util');
import type Bundle from '../../../../packager/react-packager/src/Bundler/Bundle';
import type Bundle from '../../../../packager/src//Bundler/Bundle';
import type {OutputOptions} from '../../types.flow';
// must not start with a dot, as that won't go into the apk

View File

@ -14,12 +14,12 @@ const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
const buildSourceMapWithMetaData = require('./build-unbundle-sourcemap-with-metadata');
const fs = require('fs');
const relativizeSourceMap = require('../../../../packager/react-packager/src/lib/relativizeSourceMap');
const relativizeSourceMap = require('../../../../packager/src//lib/relativizeSourceMap');
const writeSourceMap = require('./write-sourcemap');
const {joinModules} = require('./util');
import type ModuleTransport from '../../../../packager/react-packager/src/lib/ModuleTransport';
import type ModuleTransport from '../../../../packager/src//lib/ModuleTransport';
import type {Bundle, ModuleGroups, OutputOptions} from '../../types.flow';
const SIZEOF_UINT32 = 4;

View File

@ -13,8 +13,8 @@
const asAssets = require('./as-assets');
const asIndexedFile = require('./as-indexed-file');
import type Bundle from '../../../../packager/react-packager/src/Bundler/Bundle';
import type Server from '../../../../packager/react-packager/src/Server';
import type Bundle from '../../../../packager/src//Bundler/Bundle';
import type Server from '../../../../packager/src//Server';
import type {OutputOptions, RequestOptions} from '../../types.flow';
function buildBundle(packagerClient: Server, requestOptions: RequestOptions) {

View File

@ -10,10 +10,10 @@
*/
'use strict';
import type Bundle from '../../packager/react-packager/src/Bundler/Bundle';
import type {Unbundle} from '../../packager/react-packager/src/Bundler/Bundle';
import type ModuleTransport from '../../packager/react-packager/src/lib/ModuleTransport';
import type {MixedSourceMap} from '../../packager/react-packager/src/lib/SourceMap';
import type Bundle from '../../packager/src/Bundler/Bundle';
import type {Unbundle} from '../../packager/src/Bundler/Bundle';
import type ModuleTransport from '../../packager/src/lib/ModuleTransport';
import type {MixedSourceMap} from '../../packager/src/lib/SourceMap';
export type {Bundle, ModuleTransport, MixedSourceMap as SourceMap, Unbundle};

View File

@ -15,7 +15,7 @@ const Config = require('../util/Config');
const defaultConfig = require('./default.config');
const minimist = require('minimist');
import type {GetTransformOptions} from '../../packager/react-packager/src/Bundler';
import type {GetTransformOptions} from '../../packager/src/Bundler';
import type {CommandT} from '../commands';
/**

View File

@ -10,7 +10,7 @@
const InspectorProxy = require('./util/inspectorProxy.js');
const ReactPackager = require('../../packager/react-packager');
const TerminalReporter = require('../../packager/react-packager/src/lib/TerminalReporter');
const TerminalReporter = require('../../packager/src/lib/TerminalReporter');
const attachHMRServer = require('./util/attachHMRServer');
const connect = require('connect');

View File

@ -11,7 +11,7 @@
const querystring = require('querystring');
const url = require('url');
const {getInverseDependencies} = require('../../../packager/react-packager/src/node-haste');
const {getInverseDependencies} = require('../../../packager/src//node-haste');
const blacklist = [
'Libraries/Utilities/HMRClient.js',

View File

@ -17,20 +17,20 @@ exports.assetExts = [
'html', 'pdf', // Document formats
];
exports.moduleSystem = require.resolve('./react-packager/src/Resolver/polyfills/require.js');
exports.moduleSystem = require.resolve('./src/Resolver/polyfills/require.js');
exports.platforms = ['ios', 'android', 'windows', 'web'];
exports.polyfills = [
require.resolve('./react-packager/src/Resolver/polyfills/polyfills.js'),
require.resolve('./react-packager/src/Resolver/polyfills/console.js'),
require.resolve('./react-packager/src/Resolver/polyfills/error-guard.js'),
require.resolve('./react-packager/src/Resolver/polyfills/Number.es6.js'),
require.resolve('./react-packager/src/Resolver/polyfills/String.prototype.es6.js'),
require.resolve('./react-packager/src/Resolver/polyfills/Array.prototype.es6.js'),
require.resolve('./react-packager/src/Resolver/polyfills/Array.es6.js'),
require.resolve('./react-packager/src/Resolver/polyfills/Object.es7.js'),
require.resolve('./react-packager/src/Resolver/polyfills/babelHelpers.js'),
require.resolve('./src/Resolver/polyfills/polyfills.js'),
require.resolve('./src/Resolver/polyfills/console.js'),
require.resolve('./src/Resolver/polyfills/error-guard.js'),
require.resolve('./src/Resolver/polyfills/Number.es6.js'),
require.resolve('./src/Resolver/polyfills/String.prototype.es6.js'),
require.resolve('./src/Resolver/polyfills/Array.prototype.es6.js'),
require.resolve('./src/Resolver/polyfills/Array.es6.js'),
require.resolve('./src/Resolver/polyfills/Object.es7.js'),
require.resolve('./src/Resolver/polyfills/babelHelpers.js'),
];
exports.providesModuleNodeModules = [

View File

@ -11,5 +11,5 @@
'use strict';
require('../../setupBabel')();
require('../setupBabel')();
module.exports = require('./react-packager');

View File

@ -1,8 +0,0 @@
*~
*.swm
*.swn
*.swp
*.DS_STORE
npm-debug.log
.cache
node_modules

View File

@ -28,7 +28,7 @@ jest
var Bundler = require('../');
var Resolver = require('../../Resolver');
var defaults = require('../../../../defaults');
var defaults = require('../../../defaults');
var sizeOf = require('image-size');
var fs = require('fs');

View File

@ -143,8 +143,9 @@ class Bundler {
cacheKey: transformCacheKey,
});
/* $FlowFixMe: in practice it's always here. */
this._transformer = new Transformer(opts.transformModulePath);
this._transformer = new Transformer({
transformModulePath: opts.transformModulePath,
});
this._resolver = new Resolver({
assetExts: opts.assetExts,

View File

@ -25,7 +25,7 @@ var Transformer = require('../');
const {any} = jasmine;
describe('Transformer', function() {
let workers, Cache;
let options, workers, Cache;
const fileName = '/an/arbitrary/file.js';
const transformModulePath = __filename;
@ -34,6 +34,7 @@ describe('Transformer', function() {
Cache.prototype.get = jest.fn((a, b, c) => c());
fs.writeFileSync.mockClear();
options = {transformModulePath};
workerFarm.mockClear();
workerFarm.mockImplementation((opts, path, methods) => {
const api = workers = {};
@ -42,11 +43,11 @@ describe('Transformer', function() {
});
});
it('passes transform module path, file path, source code' +
' to the worker farm when transforming', () => {
it('passes transform module path, file path, source code,' +
' and options to the worker farm when transforming', () => {
const transformOptions = {arbitrary: 'options'};
const code = 'arbitrary(code)';
new Transformer(transformModulePath).transformFile(fileName, code, transformOptions);
new Transformer(options).transformFile(fileName, code, transformOptions);
expect(workers.transformAndExtractDependencies).toBeCalledWith(
transformModulePath,
fileName,
@ -57,7 +58,7 @@ describe('Transformer', function() {
});
it('should add file info to parse errors', function() {
const transformer = new Transformer(transformModulePath);
const transformer = new Transformer(options);
var message = 'message';
var snippet = 'snippet';

View File

@ -13,13 +13,12 @@
const Logger = require('../Logger');
const debug = require('debug')('RNP:JStransformer');
const declareOpts = require('../lib/declareOpts');
const denodeify = require('denodeify');
const invariant = require('fbjs/lib/invariant');
const os = require('os');
const path = require('path');
const util = require('util');
const workerFarm = require('worker-farm');
const debug = require('debug')('RNP:JStransformer');
import type {Data as TransformData, Options as TransformOptions} from './worker/worker';
import type {SourceMap} from '../lib/SourceMap';
@ -30,11 +29,36 @@ import type {SourceMap} from '../lib/SourceMap';
const MAX_CALLS_PER_WORKER = 600;
// Worker will timeout if one of the callers timeout.
const TRANSFORM_TIMEOUT_INTERVAL = 301000;
const DEFAULT_MAX_CALL_TIME = 301000;
// How may times can we tolerate failures from the worker.
const MAX_RETRIES = 2;
const validateOpts = declareOpts({
transformModulePath: {
type:'string',
required: false,
},
transformTimeoutInterval: {
type: 'number',
default: DEFAULT_MAX_CALL_TIME,
},
worker: {
type: 'string',
},
methods: {
type: 'array',
default: [],
},
});
type Options = {
transformModulePath?: ?string,
transformTimeoutInterval?: ?number,
worker?: ?string,
methods?: ?Array<string>,
};
const maxConcurrentWorkers = ((cores, override) => {
if (override) {
return Math.min(cores, override);
@ -69,8 +93,14 @@ function makeFarm(worker, methods, timeout) {
class Transformer {
_opts: {
transformModulePath?: ?string,
transformTimeoutInterval: number,
worker: ?string,
methods: Array<string>,
};
_workers: {[name: string]: mixed};
_transformModulePath: string;
_transformModulePath: ?string;
_transform: (
transform: string,
filename: string,
@ -83,18 +113,32 @@ class Transformer {
sourceMap: SourceMap,
) => Promise<{code: string, map: SourceMap}>;
constructor(transformModulePath: string) {
invariant(path.isAbsolute(transformModulePath), 'transform module path should be absolute');
this._transformModulePath = transformModulePath;
constructor(options: Options) {
const opts = this._opts = validateOpts(options);
const {transformModulePath} = opts;
if (opts.worker) {
this._workers =
makeFarm(opts.worker, opts.methods, opts.transformTimeoutInterval);
opts.methods.forEach(name => {
/* $FlowFixMe: assigning the class object fields directly is
* questionable, because it's prone to conflicts. */
this[name] = this._workers[name];
});
}
else if (transformModulePath) {
this._transformModulePath = require.resolve(transformModulePath);
this._workers = makeFarm(
require.resolve('./worker'),
['minify', 'transformAndExtractDependencies'],
TRANSFORM_TIMEOUT_INTERVAL,
opts.transformTimeoutInterval,
);
this._transform = denodeify(this._workers.transformAndExtractDependencies);
this.minify = denodeify(this._workers.minify);
}
}
kill() {
this._workers && workerFarm.end(this._workers);
@ -106,6 +150,7 @@ class Transformer {
}
debug('transforming file', fileName);
return this
/* $FlowFixMe: _transformModulePath may be empty, see constructor */
._transform(this._transformModulePath, fileName, code, options)
.then(data => {
Logger.log(data.transformFileStartLogEntry);
@ -117,7 +162,7 @@ class Transformer {
if (error.type === 'TimeoutError') {
const timeoutErr = new Error(
`TimeoutError: transforming ${fileName} took longer than ` +
`${TRANSFORM_TIMEOUT_INTERVAL / 1000} seconds.\n` +
`${this._opts.transformTimeoutInterval / 1000} seconds.\n` +
'You can adjust timeout via the \'transformTimeoutInterval\' option'
);
/* $FlowFixMe: monkey-patch Error */
@ -126,7 +171,8 @@ class Transformer {
} else if (error.type === 'ProcessTerminatedError') {
const uncaughtError = new Error(
'Uncaught error in the transformer worker: ' +
this._transformModulePath
/* $FlowFixMe: _transformModulePath may be empty, see constructor */
this._opts.transformModulePath
);
/* $FlowFixMe: monkey-patch Error */
uncaughtError.type = 'ProcessTerminatedError';

View File

@ -9,5 +9,5 @@
'use strict';
require('../../../../../setupBabel')();
require('../../../../setupBabel')();
module.exports = require('./worker');

View File

@ -10,7 +10,7 @@
*/
'use strict';
const defaults = require('../../../defaults');
const defaults = require('../../defaults');
const nullthrows = require('fbjs/lib/nullthrows');
const parallel = require('async/parallel');
const seq = require('async/seq');

View File

@ -11,7 +11,7 @@
jest.disableAutomock();
const ModuleGraph = require('../ModuleGraph');
const defaults = require('../../../../defaults');
const defaults = require('../../../defaults');
const FILE_TYPE = 'module';

View File

@ -28,7 +28,7 @@ const Module = require('./Module');
const ModuleCache = require('./ModuleCache');
const ResolutionRequest = require('../../node-haste/DependencyGraph/ResolutionRequest');
const defaults = require('../../../../defaults');
const defaults = require('../../../defaults');
type ResolveOptions = {|
assetExts: Extensions,

View File

@ -12,7 +12,7 @@ jest.disableAutomock();
const optimizeModule = require('../optimize-module');
const transformModule = require('../transform-module');
const transform = require('../../../../../transformer.js');
const transform = require('../../../../transformer.js');
const {SourceMapConsumer} = require('source-map');
const {objectContaining} = jasmine;

View File

@ -9,7 +9,7 @@
'use strict';
jest.unmock('../');
jest.unmock('../../../../defaults');
jest.unmock('../../../defaults');
jest.mock('path');
const {join: pathJoin} = require.requireActual('path');

View File

@ -13,7 +13,7 @@
const DependencyGraph = require('../node-haste');
const defaults = require('../../../defaults');
const defaults = require('../../defaults');
const pathJoin = require('path').join;
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';

View File

@ -166,8 +166,8 @@ function loadModuleImplementation(moduleId, module) {
}
// keep args in sync with with defineModuleCode in
// packager/react-packager/src/Resolver/index.js
// and packager/react-packager/src/ModuleGraph/worker.js
// packager/src//Resolver/index.js
// and packager/src//ModuleGraph/worker.js
factory(global, require, moduleObject, exports, dependencyMap);
// avoid removing factory in DEV mode as it breaks HMR

Some files were not shown because too many files have changed in this diff Show More