Replace projectRoots with projectRoot + watchRoots

Summary:
We use projectRoots to limit crawling of jest-haste-map in large codebases. Since this implies multiple projects roots, it makes it very hard (or impossible) to reliably cache dependency resolutions.

If we can replace this with a single project root and a set of watch roots, we can have relative path resolutions for all dependencies which van be cached.

Reviewed By: rafeca

Differential Revision: D8450498

fbshipit-source-id: 830c21e847c3236e42d5414a8587508cb73864bd
This commit is contained in:
Alexey Kureev
2018-06-19 13:45:17 -07:00
committed by Facebook Github Bot
parent d7e0fe2c2c
commit c5ce762697
6 changed files with 23 additions and 16 deletions

View File

@@ -75,7 +75,6 @@ async function buildBundle(
: defaultProvidesModuleNodeModules;
const terminal = new Terminal(process.stdout);
const server = new Server({
asyncRequireModulePath: config.getAsyncRequireModulePath(),
assetExts: defaultAssetExts.concat(assetExts),
@@ -96,7 +95,7 @@ async function buildBundle(
platforms: defaultPlatforms.concat(platforms),
postMinifyProcess: config.postMinifyProcess,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
projectRoots: config.getProjectRoots(),
projectRoot: config.getProjectRoot(),
providesModuleNodeModules: providesModuleNodeModules,
reporter: new TerminalReporter(terminal),
resetCache: args.resetCache,
@@ -104,6 +103,7 @@ async function buildBundle(
sourceExts: sourceExts.concat(defaultSourceExts),
transformModulePath: transformModulePath,
watch: false,
watchFolders: config.getWatchFolders(),
workerPath: config.getWorkerPath && config.getWorkerPath(),
});

View File

@@ -34,7 +34,7 @@ function dependencies(argv, config, args, packagerInstance) {
const packageOpts = {
assetRegistryPath: ASSET_REGISTRY_PATH,
cacheStores: [],
projectRoots: config.getProjectRoots(),
projectRoot: config.getProjectRoot(),
blacklistRE: config.getBlacklistRE(),
dynamicDepsInPackages: config.dynamicDepsInPackages,
getPolyfills: config.getPolyfills,
@@ -44,12 +44,14 @@ function dependencies(argv, config, args, packagerInstance) {
transformModulePath: transformModulePath,
extraNodeModules: config.extraNodeModules,
verbose: config.verbose,
watchFolders: config.getWatchFolders(),
workerPath: config.getWorkerPath(),
};
const relativePath = packageOpts.projectRoots.map(root =>
path.relative(root, rootModuleAbsolutePath),
)[0];
const relativePath = path.relative(
packageOpts.projectRoot,
rootModuleAbsolutePath,
);
const options = {
platform: args.platform,
@@ -75,7 +77,7 @@ function dependencies(argv, config, args, packagerInstance) {
// (a) JS code to not depend on anything outside this directory, or
// (b) Come up with a way to declare this dependency in Buck.
const isInsideProjectRoots =
packageOpts.projectRoots.filter(root => modulePath.startsWith(root))
packageOpts.watchFolders.filter(root => modulePath.startsWith(root))
.length > 0;
if (isInsideProjectRoots) {

View File

@@ -23,11 +23,11 @@ function escapePath(pathname) {
return '"' + pathname + '"';
}
function launchDevTools({host, projectRoots}, isChromeConnected) {
function launchDevTools({host, watchFolders}, isChromeConnected) {
// Explicit config always wins
var customDebugger = process.env.REACT_DEBUGGER;
if (customDebugger) {
var projects = projectRoots.map(escapePath).join(' ');
var projects = watchFolders.map(escapePath).join(' ');
var command = customDebugger + ' ' + projects;
console.log('Starting custom debugger by executing: ' + command);
exec(command, function(error, stdout, stderr) {

View File

@@ -11,11 +11,11 @@
const launchEditor = require('../util/launchEditor');
module.exports = function({projectRoots}) {
module.exports = function({watchFolders}) {
return function(req, res, next) {
if (req.url === '/open-stack-frame') {
const frame = JSON.parse(req.rawBody);
launchEditor(frame.file, frame.lineNumber, projectRoots);
launchEditor(frame.file, frame.lineNumber, watchFolders);
res.end('OK');
} else {
next();

View File

@@ -60,6 +60,7 @@ export type Args = {|
+resetCache: boolean,
+sourceExts: $ReadOnlyArray<string>,
+verbose: boolean,
+watchFolders: $ReadOnlyArray<string>,
|};
function runServer(
@@ -100,7 +101,7 @@ function runServer(
.use(indexPageMiddleware)
.use(packagerServer.processRequest.bind(packagerServer));
args.projectRoots.forEach(root => app.use(serveStatic(root)));
args.watchFolders.forEach(root => app.use(serveStatic(root)));
app.use(morgan('combined')).use(errorhandler());
@@ -196,7 +197,7 @@ function getPackagerServer(args, config, reporter) {
polyfillModuleNames: config.getPolyfillModuleNames(),
postMinifyProcess: config.postMinifyProcess,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
projectRoots: args.projectRoots,
projectRoot: config.getProjectRoot(),
providesModuleNodeModules: providesModuleNodeModules,
reporter,
resetCache: args.resetCache,
@@ -205,6 +206,7 @@ function getPackagerServer(args, config, reporter) {
transformModulePath: transformModulePath,
verbose: args.verbose,
watch: !args.nonPersistent,
watchFolders: config.getWatchFolders(),
workerPath: config.getWorkerPath(),
});
}

View File

@@ -75,10 +75,13 @@ module.exports = {
default: [],
},
{
command: '--projectRoots [list]',
description: 'override the root(s) to be used by the packager',
command: '--watchFolders [list]',
description:
'Sepcify any additional folders to be added to the watch list',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getProjectRoots(),
default: (config: ConfigT) => {
return config.getProjectRoots ? config.getProjectRoots() : undefined;
},
},
{
command: '--assetExts [list]',