Skip to content

Commit

Permalink
Replace projectRoots with projectRoot + watchRoots
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Alexey Kureev authored and facebook-github-bot committed Jun 19, 2018
1 parent d7e0fe2 commit c5ce762
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions local-cli/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -96,14 +95,15 @@ 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,
resolveRequest: config.resolveRequest,
sourceExts: sourceExts.concat(defaultSourceExts),
transformModulePath: transformModulePath,
watch: false,
watchFolders: config.getWatchFolders(),
workerPath: config.getWorkerPath && config.getWorkerPath(),
});

Expand Down
12 changes: 7 additions & 5 deletions local-cli/dependencies/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions local-cli/server/middleware/getDevToolsMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type Args = {|
+resetCache: boolean,
+sourceExts: $ReadOnlyArray<string>,
+verbose: boolean,
+watchFolders: $ReadOnlyArray<string>,
|};

function runServer(
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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,
Expand All @@ -205,6 +206,7 @@ function getPackagerServer(args, config, reporter) {
transformModulePath: transformModulePath,
verbose: args.verbose,
watch: !args.nonPersistent,
watchFolders: config.getWatchFolders(),
workerPath: config.getWorkerPath(),
});
}
Expand Down
9 changes: 6 additions & 3 deletions local-cli/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
Expand Down

0 comments on commit c5ce762

Please sign in to comment.