mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
0ecc4047af
commit
a2c84d14ce
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (c) 2016-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import type {IdForPathFn, Module} from '../types.flow';
|
||||
|
||||
// Transformed modules have the form
|
||||
// __d(function(require, module, global, exports, dependencyMap) {
|
||||
// /* code */
|
||||
// });
|
||||
//
|
||||
// This function adds the numeric module ID, and an array with dependencies of
|
||||
// the dependencies of the module before the closing parenthesis.
|
||||
exports.addModuleIdsToModuleWrapper = (
|
||||
module: Module,
|
||||
idForPath: {path: string} => number,
|
||||
): string => {
|
||||
const {dependencies, file} = module;
|
||||
const {code} = file;
|
||||
const index = code.lastIndexOf(')');
|
||||
|
||||
// calling `idForPath` on the module itself first gives us a lower module id
|
||||
// for the file itself than for its dependencies. That reflects their order
|
||||
// in the bundle.
|
||||
const fileId = idForPath(file);
|
||||
|
||||
// This code runs for both development and production builds, after
|
||||
// minification. That's why we leave out all spaces.
|
||||
const depencyIds =
|
||||
dependencies.length ? `,[${dependencies.map(idForPath).join(',')}]` : '';
|
||||
return (
|
||||
code.slice(0, index) +
|
||||
`,${fileId}` +
|
||||
depencyIds +
|
||||
code.slice(index)
|
||||
);
|
||||
};
|
||||
|
||||
// Creates an idempotent function that returns numeric IDs for objects based
|
||||
// on their `path` property.
|
||||
exports.createIdForPathFn = (): ({path: string} => number) => {
|
||||
const seen = new Map();
|
||||
let next = 0;
|
||||
return ({path}) => {
|
||||
let id = seen.get(path);
|
||||
if (id == null) {
|
||||
id = next++;
|
||||
seen.set(path, id);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
};
|
||||
|
||||
// creates a series of virtual modules with require calls to the passed-in
|
||||
// modules.
|
||||
exports.requireCallsTo = function* (
|
||||
modules: Iterable<Module>,
|
||||
idForPath: IdForPathFn,
|
||||
): Iterable<Module> {
|
||||
for (const module of modules) {
|
||||
yield virtualModule(`require(${idForPath(module.file)});`);
|
||||
}
|
||||
};
|
||||
|
||||
// creates a virtual module (i.e. not corresponding to a file on disk)
|
||||
// with the given source code.
|
||||
exports.virtualModule = virtualModule;
|
||||
function virtualModule(code: string) {
|
||||
return {
|
||||
dependencies: [],
|
||||
file: {
|
||||
code,
|
||||
path: '',
|
||||
type: 'script',
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user