Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't read packages on each iteration #232

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build:legacy": "cross-env BABEL_ENV=legacy babel src -d dist/legacy",
"build:modern": "cross-env BABEL_ENV=modern babel src -d dist/modern",
"build": "yarn run clean && yarn build:legacy && yarn build:modern",
"prepublish": "yarn build",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"precommit": "lint-staged"
},
"devDependencies": {
Expand Down
12 changes: 7 additions & 5 deletions src/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ export default class Project {
let matchedPaths = await globs.findWorkspaces(cwd, patterns);

for (let matchedPath of matchedPaths) {
let dir = path.join(cwd, matchedPath);
let stats = await fs.stat(dir);
if (!stats.isDirectory()) continue;
let file = path.join(cwd, matchedPath);
let stats = await fs.stat(file);
if (!stats.isFile()) continue;

let filePath = path.join(dir, 'package.json');
let pkg = await Package.init(filePath);
let isPackage = path.basename(file) === 'package.json';
if (!isPackage) continue;
let pkg = await Package.init(file);

queue.push(pkg);
packages.push(pkg);

}
}

Expand Down
10 changes: 9 additions & 1 deletion src/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ export async function install(opts: InstallOptions) {
prefix: false
});

let packagesGraph = await project.getDependencyGraph(packages);
for (let pkg of packages) {
let dependencies = Array.from(pkg.getAllDependencies().keys());
await symlinkPackageDependencies(project, pkg, dependencies);
logger.info(`Linking ${pkg.config.json.name}`, {});
await symlinkPackageDependencies(
project,
pkg,
dependencies,
packages,
packagesGraph
);
}

logger.info(messages.linkingWorkspaceBinaries(), {
Expand Down
25 changes: 14 additions & 11 deletions src/utils/symlinkPackageDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import * as yarn from './yarn';
export default async function symlinkPackageDependencies(
project: Project,
pkg: Package,
dependencies: Array<string>
dependencies: Array<string>,
packages: Array<Package>,
{
graph: dependencyGraph,
valid: dependencyGraphValid
}: {
graph: Map<string, { pkg: Package, dependencies: Array<string> }>,
valid: boolean
}
) {
let projectDeps = project.pkg.getAllDependencies();
let pkgDependencies = project.pkg.getAllDependencies();
let packages = await project.getPackages();
let {
graph: dependencyGraph,
valid: dependencyGraphValid
} = await project.getDependencyGraph(packages);
let pkgName = pkg.config.getName();
// get all the dependencies that are internal workspaces in this project
let internalDeps = (dependencyGraph.get(pkgName) || {}).dependencies || [];
Expand All @@ -34,7 +37,7 @@ export default async function symlinkPackageDependencies(

/*********************************************************************
* Calculate all the external dependencies that need to be symlinked *
**********************************************************************/
**********************************************************************/

directoriesToCreate.push(pkg.nodeModules, pkg.nodeModulesBin);

Expand Down Expand Up @@ -87,7 +90,7 @@ export default async function symlinkPackageDependencies(

/*********************************************************************
* Calculate all the internal dependencies that need to be symlinked *
**********************************************************************/
**********************************************************************/

for (let dependency of internalDeps) {
let depWorkspace = dependencyGraph.get(dependency) || {};
Expand All @@ -103,7 +106,7 @@ export default async function symlinkPackageDependencies(

/********************************************************
* Calculate all the bin files that need to be symlinked *
*********************************************************/
*********************************************************/
let projectBinFiles = await fs.readdirSafe(project.pkg.nodeModulesBin);

// TODO: For now, we'll search through each of the bin files in the Project and find which ones are
Expand Down Expand Up @@ -151,7 +154,7 @@ export default async function symlinkPackageDependencies(

/*****************************************************************
* Calculate all the internal bin files that need to be symlinked *
******************************************************************/
******************************************************************/

// TODO: Same as above, we should really be making sure we get all the transitive bins as well

Expand Down Expand Up @@ -194,7 +197,7 @@ export default async function symlinkPackageDependencies(

/**********************************
* Create directories and symlinks *
***********************************/
***********************************/

await yarn.runIfExists(pkg, 'preinstall');

Expand Down