From abe8d13c9c52ba66efe8b8e2d58ab9d8279a5b13 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Sun, 19 May 2019 23:33:41 +0500 Subject: [PATCH 1/4] Check for package.json --- src/Project.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Project.js b/src/Project.js index 48a6e6e3..8e0fb6a3 100644 --- a/src/Project.js +++ b/src/Project.js @@ -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); + } } From a11719483c43cc1d5987cd1d77598253e7c596d9 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Mon, 20 May 2019 00:14:16 +0500 Subject: [PATCH 2/4] Don't read packages on each iteration --- src/commands/install.js | 3 ++- src/utils/symlinkPackageDependencies.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/install.js b/src/commands/install.js index 619e7316..f6d4ddcd 100644 --- a/src/commands/install.js +++ b/src/commands/install.js @@ -55,7 +55,8 @@ export async function install(opts: InstallOptions) { 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); } logger.info(messages.linkingWorkspaceBinaries(), { diff --git a/src/utils/symlinkPackageDependencies.js b/src/utils/symlinkPackageDependencies.js index 5dcfa4e3..8a3ff6fa 100644 --- a/src/utils/symlinkPackageDependencies.js +++ b/src/utils/symlinkPackageDependencies.js @@ -14,11 +14,11 @@ import * as yarn from './yarn'; export default async function symlinkPackageDependencies( project: Project, pkg: Package, - dependencies: Array + dependencies: Array, + packages: Array ) { let projectDeps = project.pkg.getAllDependencies(); let pkgDependencies = project.pkg.getAllDependencies(); - let packages = await project.getPackages(); let { graph: dependencyGraph, valid: dependencyGraphValid From b5d33eec29a1c962b91672c4d199af9fab234704 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Mon, 20 May 2019 00:23:31 +0500 Subject: [PATCH 3/4] Add prepare lifecycle --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c942d439..3e230ec1 100644 --- a/package.json +++ b/package.json @@ -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": { From efe4d7716c7c8c2e55cf614927d8a2ff74c7d6a1 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Wed, 22 May 2019 05:12:02 +0500 Subject: [PATCH 4/4] Move graph calculation out of loop --- src/commands/install.js | 9 ++++++++- src/utils/symlinkPackageDependencies.js | 23 +++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/commands/install.js b/src/commands/install.js index f6d4ddcd..ea631a4d 100644 --- a/src/commands/install.js +++ b/src/commands/install.js @@ -53,10 +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()); logger.info(`Linking ${pkg.config.json.name}`, {}); - await symlinkPackageDependencies(project, pkg, dependencies, packages); + await symlinkPackageDependencies( + project, + pkg, + dependencies, + packages, + packagesGraph + ); } logger.info(messages.linkingWorkspaceBinaries(), { diff --git a/src/utils/symlinkPackageDependencies.js b/src/utils/symlinkPackageDependencies.js index 8a3ff6fa..db6a7914 100644 --- a/src/utils/symlinkPackageDependencies.js +++ b/src/utils/symlinkPackageDependencies.js @@ -15,14 +15,17 @@ export default async function symlinkPackageDependencies( project: Project, pkg: Package, dependencies: Array, - packages: Array + packages: Array, + { + graph: dependencyGraph, + valid: dependencyGraphValid + }: { + graph: Map }>, + valid: boolean + } ) { let projectDeps = project.pkg.getAllDependencies(); let pkgDependencies = project.pkg.getAllDependencies(); - 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 || []; @@ -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); @@ -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) || {}; @@ -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 @@ -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 @@ -194,7 +197,7 @@ export default async function symlinkPackageDependencies( /********************************** * Create directories and symlinks * - ***********************************/ + ***********************************/ await yarn.runIfExists(pkg, 'preinstall');