├── .flowconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── cli.js ├── example ├── external-project │ ├── package.json │ └── packages │ │ ├── jquery │ │ └── package.json │ │ ├── react │ │ └── package.json │ │ └── test.js └── simple-project │ └── packages │ ├── package-a │ └── package.json │ └── package-b │ └── package.json ├── fixtures ├── bolt-repo │ ├── package.json │ └── packages │ │ ├── elem │ │ └── package.json │ │ ├── react │ │ └── package.json │ │ └── util │ │ └── package.json ├── generic-repo │ ├── package.json │ └── packages │ │ ├── elem │ │ └── package.json │ │ ├── react │ │ └── package.json │ │ └── util │ │ └── package.json └── lerna-repo │ ├── lerna.json │ ├── package.json │ └── packages │ ├── elem │ └── package.json │ ├── react │ └── package.json │ └── util │ └── package.json ├── github └── preview.png ├── index.js ├── lib ├── commands │ ├── global.js │ └── internal.js └── utils │ ├── cli.js │ ├── dir.js │ └── getInternalDependency.js ├── package.json ├── readme.md ├── test ├── commands │ ├── global.test.js │ └── internal.test.js └── utils │ ├── cli.test.js │ ├── dir.test.js │ └── getInternalDependency.test.js └── yarn.lock /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [lints] 8 | 9 | [options] 10 | 11 | [strict] 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependency cache 2 | node_modules 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | cache: yarn 5 | script: yarn test && yarn typecheck 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-present Ajay Narain Mathur 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // @flow 3 | "use strict"; 4 | const meow = require("meow"); 5 | const chalk = require("chalk"); 6 | const {internal, global} = require('./'); 7 | 8 | /*:: 9 | type FlagsType = { 10 | cwd?: string 11 | } 12 | */ 13 | /*:: 14 | type CliType = { 15 | input: Array, 16 | flags: FlagsType, 17 | showHelp: Function, 18 | } 19 | */ 20 | 21 | async function cli(argv /*: Array*/) { 22 | const cli /*: CliType*/ = meow({ 23 | argv, 24 | help: ` 25 | popular package helps identify the popular package within a mono repo 26 | 27 | Usage 28 | 29 | $ popular-package [options] 30 | 31 | Commands 32 | 33 | internal Get the internal (within monorepo) popularity of the packages 34 | global Get the popularity of packages by number of downloads on npm 35 | 36 | Examples 37 | 38 | View internal popularity of a package in bolt or lerna repo: 39 | 40 | $ popular-package internal 41 | 42 | 43 | View popularity of packages on npm for a bolt or lerna repo: 44 | 45 | $ popular-package global 46 | ` 47 | }); 48 | 49 | if (cli.input.length < 1) { 50 | cli.showHelp(); 51 | } 52 | 53 | const command = cli.input[0]; 54 | const cwd = cli.flags.cwd || process.cwd(); 55 | 56 | if (command === 'internal') { 57 | await internal({ 58 | cwd, 59 | }); 60 | } else if (command === 'global') { 61 | await global({ 62 | cwd, 63 | }); 64 | } else { 65 | throw new Error(chalk`Unknown command {red "${command}"}. Supported commands are {green "internal"} and {green "global"}`); 66 | } 67 | } 68 | 69 | cli(process.argv.slice(2)).catch(err => { 70 | console.error(err); 71 | process.exit(1); 72 | }); 73 | -------------------------------------------------------------------------------- /example/external-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "external-project", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT" 6 | } 7 | -------------------------------------------------------------------------------- /example/external-project/packages/jquery/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT" 6 | } 7 | -------------------------------------------------------------------------------- /example/external-project/packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT" 6 | } 7 | -------------------------------------------------------------------------------- /example/external-project/packages/test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaymathur/popular-package/0c9d14b8de9273f71fb3119f18d27433a5b3993f/example/external-project/packages/test.js -------------------------------------------------------------------------------- /example/simple-project/packages/package-a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "package-a", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "package-b": "^1.0.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/simple-project/packages/package-b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "package-b", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "package-a": "^1.0.0", 8 | "package-b": "^1.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /fixtures/bolt-repo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bolt-repo", 3 | "version": "0.0.1", 4 | "bolt": { 5 | "workspaces": [ 6 | "packages/*" 7 | ] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/bolt-repo/packages/elem/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elem", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/bolt-repo/packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "research", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/bolt-repo/packages/util/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "util", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/generic-repo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generic-repo", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/generic-repo/packages/elem/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elem", 3 | "version": "0.0.0", 4 | "dependencies": { 5 | "react": "^18.2.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/generic-repo/packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react", 3 | "version": "18.2.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/generic-repo/packages/util/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "util", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/lerna-repo/lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.3", 3 | "packages": ["packages/*"] 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/lerna-repo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lerna-repo", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/lerna-repo/packages/elem/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elem", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/lerna-repo/packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "research", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/lerna-repo/packages/util/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "util", 3 | "version": "0.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /github/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaymathur/popular-package/0c9d14b8de9273f71fb3119f18d27433a5b3993f/github/preview.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | exports.internal = require('./lib/commands/internal'); 4 | exports.global = require('./lib/commands/global'); 5 | -------------------------------------------------------------------------------- /lib/commands/global.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | const got = require('got'); 4 | const ora = require('ora'); 5 | const chalk = require('chalk'); 6 | const { table } = require('../utils/cli'); 7 | const { getAllPackages } = require('../utils/dir'); 8 | const { getAllPackagesName } = require('../utils/getInternalDependency'); 9 | 10 | /*:: 11 | type SpinnerType = { 12 | text: string, 13 | start: Function, 14 | succeed: Function, 15 | fail: Function, 16 | } 17 | */ 18 | 19 | async function getNpmStats(pkg, spinner) { 20 | try { 21 | const res = await got( 22 | `https://api.npmjs.org/downloads/point/last-day/${pkg}` 23 | ); 24 | spinner.succeed(chalk`Download complete for {green ${pkg}}`); 25 | return JSON.parse(res.body); 26 | } catch(error) { 27 | spinner.fail(chalk`Download failed for {red ${pkg}} with {red ${error}}`); 28 | return {downloads: 0}; 29 | } 30 | } 31 | 32 | async function global({ cwd } /*: {cwd: string}*/) { 33 | const spinner /*: SpinnerType*/ = ora({ 34 | text: chalk`Getting packages to download stats for` 35 | }).start(); 36 | const packages = await getAllPackages(cwd); 37 | const pkgNames = await getAllPackagesName(cwd, packages); 38 | let pkgsStat/*: { [key: string]: { downloads: number } }*/ = { }; 39 | 40 | spinner.succeed(chalk`Found {green ${pkgNames.size}} packages`); 41 | 42 | for (const pkg of pkgNames) { 43 | spinner.start(chalk`Downloading npm data for {yellow ${pkg}}`); 44 | const pkgStats /* {downloads: number} */ = await getNpmStats(pkg, spinner); 45 | pkgsStat[pkg] = pkgStats; 46 | } 47 | 48 | let sortedKeys = Object.keys(pkgsStat).sort( 49 | (maybeSmall, maybeBig) => 50 | pkgsStat[maybeBig].downloads - pkgsStat[maybeSmall].downloads 51 | ); 52 | 53 | console.log( 54 | table({ 55 | columns: ['', chalk`{yellow Package Name}`, chalk`{yellow Download}`], 56 | rows: sortedKeys.map((key, index) => [index+1, key, pkgsStat[key].downloads]) 57 | }) 58 | ); 59 | } 60 | 61 | module.exports = global; 62 | -------------------------------------------------------------------------------- /lib/commands/internal.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | const ora = require('ora'); 4 | const chalk = require('chalk'); 5 | const { table } = require('../utils/cli'); 6 | const { getInternalDependency } = require('../utils/getInternalDependency'); 7 | const { getAllPackages } = require('../utils/dir'); 8 | 9 | async function internal({ cwd } /*: {cwd: string}*/) { 10 | const spinner = new ora({ 11 | text: 'Calculating internal dependency Data' 12 | }).start(); 13 | const packages = await getAllPackages(cwd); 14 | const dependencyTree = await getInternalDependency(cwd, packages); 15 | 16 | let sortedKeys = Object.keys(dependencyTree).sort( 17 | (maybeSmall, maybeBig) => 18 | dependencyTree[maybeBig].length - dependencyTree[maybeSmall].length 19 | ); 20 | 21 | spinner.succeed('Completed with calculation for internal dependency') 22 | 23 | console.log( 24 | table({ 25 | columns: ['', chalk`{yellow Package Name}`, chalk`{yellow Dependent Packages Count}`, chalk`{yellow Dependent Packages}`], 26 | rows: sortedKeys.map((key, index) => { 27 | const extraPackages = Math.max(dependencyTree[key].length - 3, 0); 28 | const dependentPackagesExtraMessage = `and ${extraPackages} more.` 29 | return [ 30 | index+1, 31 | key, 32 | dependencyTree[key].length, 33 | chalk`${dependencyTree[key].slice(0, 3)} {green ${extraPackages > 0 ? dependentPackagesExtraMessage: ''}}`, 34 | ] 35 | }) 36 | }) 37 | ); 38 | } 39 | 40 | module.exports = internal; 41 | -------------------------------------------------------------------------------- /lib/utils/cli.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | const Table = require('cli-table'); 4 | 5 | function table({ columns, rows } /*: {columns: Array, rows: Array} */) /*: string */ { 6 | let table = new Table({ head: columns }); 7 | table.push(...rows); 8 | return table.toString(); 9 | } 10 | 11 | module.exports = { 12 | table 13 | } 14 | -------------------------------------------------------------------------------- /lib/utils/dir.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const readPkg = require('read-pkg'); 6 | const globby = require('globby'); 7 | const {promisify} = require('util'); 8 | 9 | const readFile = promisify(fs.readFile); 10 | const stat = promisify(fs.stat); 11 | 12 | /*:: 13 | type LernaConfigType = { 14 | packages: Array, 15 | [Key: string]: mixed, 16 | } 17 | */ 18 | 19 | /*:: 20 | type PackageJsonType = { 21 | name: string, 22 | dependencies: { [key: string]: string }, 23 | [key: string]: string | { [key: string]: string }, 24 | } 25 | */ 26 | 27 | async function exists(filePath /*: string*/) { 28 | try { 29 | await stat(filePath); 30 | return true; 31 | } catch (err) { 32 | if (err.code !== 'ENOENT') { 33 | throw err; 34 | } 35 | } 36 | return false; 37 | } 38 | 39 | async function getAllPackages(cwd /*: string */) { 40 | const isLernaProject /*: boolean */ = await exists(path.join(cwd, 'lerna.json')); 41 | let defaultPkgsDirPattern /*: Array*/ = ['packages/*']; 42 | let projectDirsPattern = defaultPkgsDirPattern; 43 | 44 | if (isLernaProject) { 45 | const lernaConfig = await readFile(path.join(cwd, 'lerna.json')); 46 | const lernaJson /*: LernaConfigType */ = JSON.parse(lernaConfig); 47 | projectDirsPattern = lernaJson.packages || defaultPkgsDirPattern; 48 | } else { 49 | const pkgJSON /*: PackageJsonType*/ = await readPkg(path.join(cwd, 'package.json')); 50 | projectDirsPattern = (pkgJSON.bolt && pkgJSON.bolt.workspaces) || defaultPkgsDirPattern; 51 | } 52 | 53 | const projectPkgs/*: Array */ = await globby(projectDirsPattern, { cwd, nodir: false, gitignore: true }); 54 | 55 | return projectPkgs; 56 | } 57 | 58 | module.exports = { 59 | getAllPackages, 60 | } 61 | -------------------------------------------------------------------------------- /lib/utils/getInternalDependency.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 'use strict'; 3 | const path = require('path'); 4 | const readPkg = require('read-pkg'); 5 | const fileExists = require('file-exists'); 6 | const pathExists = require('path-exists'); 7 | 8 | /*:: 9 | type PackageJsonType = { 10 | name: string, 11 | dependencies: { [key: string]: string }, 12 | [key: string]: string | { [key: string]: string }, 13 | } 14 | */ 15 | 16 | async function getAllPackagesName(cwd /*: string */, pkgPath /*: Array */) { 17 | const packages = new Set(); 18 | for (const pkg of pkgPath) { 19 | const doesPathExit /*: boolean */ = await pathExists(path.join(cwd, pkg, 'package.json')); 20 | if (doesPathExit) { 21 | const pkgJson /*: PackageJsonType */ = await readPkg(path.join(cwd, pkg)); 22 | if (!pkgJson.private) { 23 | packages.add(pkgJson.name); 24 | } 25 | } 26 | } 27 | return packages; 28 | } 29 | 30 | async function getInternalDependency(cwd /*: string */, packages /*: Array */) { 31 | let dependentGraph /*: { [key: string]: Array }*/= {}; 32 | const allPackages = await getAllPackagesName(cwd, packages); 33 | 34 | for (const pkg of packages) { 35 | const pathExit /*: boolean*/ = await pathExists(path.join(cwd, pkg, 'package.json')); 36 | 37 | if (pathExit) { 38 | const pkgJson /*: PackageJsonType */ = await readPkg(path.join(cwd, pkg)); 39 | 40 | if (pkgJson.dependencies) { 41 | Object.keys(pkgJson.dependencies).map(dependency => { 42 | if (allPackages.has(dependency)) { 43 | dependentGraph[dependency] 44 | ? dependentGraph[dependency].push(pkgJson.name) 45 | : (dependentGraph[dependency] = [pkgJson.name]); 46 | } 47 | }); 48 | } 49 | } 50 | } 51 | 52 | return dependentGraph; 53 | } 54 | 55 | module.exports = { 56 | getAllPackagesName, 57 | getInternalDependency, 58 | }; 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "popular-package", 3 | "version": "1.0.1", 4 | "author": { 5 | "name": "Ajay Narain Mathur", 6 | "email": "ajaynarainmathur@gmail.com" 7 | }, 8 | "main": "index.js", 9 | "bin": "cli.js", 10 | "repository": "git@github.com:ajaymathur/popular-package.git", 11 | "license": "MIT", 12 | "scripts": { 13 | "test": "ava", 14 | "typecheck": "glow" 15 | }, 16 | "dependencies": { 17 | "chalk": "^2.3.0", 18 | "cli-table": "^0.3.1", 19 | "file-exists": "^5.0.1", 20 | "globby": "^7.1.1", 21 | "got": "^8.0.3", 22 | "meow": "^4.0.0", 23 | "ora": "^1.4.0", 24 | "path-exists": "^3.0.0", 25 | "read-pkg": "^3.0.0" 26 | }, 27 | "engines": { 28 | "node": ">=8.5.0" 29 | }, 30 | "files": [ 31 | "cli.js", 32 | "index.js", 33 | "lib" 34 | ], 35 | "keywords": [ 36 | "downloads", 37 | "popular", 38 | "package", 39 | "mono-repo", 40 | "mono", 41 | "popularity", 42 | "npm" 43 | ], 44 | "devDependencies": { 45 | "ava": "^0.25.0", 46 | "fixturez": "^1.1.0", 47 | "flow-bin": "^0.65.0", 48 | "glow": "^1.2.2" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # popular-package 2 | 3 | > Get the popularity stats of packages in a mono repository either internally or on npm for [bolt](https://github.com/boltpkg/bolt) or [lerna](https://github.com/lerna/lerna). 4 | 5 | ![preview](https://raw.githubusercontent.com/ajaymathur/popular-package/master/github/preview.png) 6 | 7 | ## Install 8 | 9 | ```sh 10 | $ yarn global add popular-package 11 | ``` 12 | 13 | ## Examples 14 | 15 | View internal popularity of a package in bolt or lerna repository: 16 | 17 | ```sh 18 | $ popular-package internal 19 | ``` 20 | 21 | View popularity of packages on npm for a bolt or lerna repository: 22 | 23 | ```sh 24 | $ popular-package global 25 | ``` 26 | 27 | ## Usage 28 | 29 | ```sh 30 | $ popular-package 31 | ``` 32 | 33 | - `command` - (`internal | global`) Wheather to show stats for popularity in repository or globally on npm 34 | 35 | ### Commands 36 | 37 | #### `internal` 38 | 39 | Get the stats of a package with dependency in other packages within repository. 40 | 41 | #### `global` 42 | 43 | Get the stats of a package by the number of downloads in last day on npm. 44 | 45 | ### Packages Pattern 46 | 47 | #### `Bolt` 48 | 49 | It will read pattern of workspaces from bolt config in package json of the repository. 50 | 51 | #### `Lerna` 52 | 53 | It will read pattern of packages from lerna.json in repository. 54 | 55 | --- 56 | 57 | ***If neither lerna.json or bolt config in packages json is found packages pattern will default to → `[packages/*]`*** 58 | -------------------------------------------------------------------------------- /test/commands/global.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | 4 | test('global', async (t) => { 5 | t.is(4, 4); 6 | }); 7 | -------------------------------------------------------------------------------- /test/commands/internal.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | 4 | test('internal', async (t) => { 5 | t.is(4, 4); 6 | }); 7 | -------------------------------------------------------------------------------- /test/utils/cli.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | 4 | test.todo('cli()'); 5 | -------------------------------------------------------------------------------- /test/utils/dir.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | const fixtures = require('fixturez'); 4 | const {getAllPackages} = require('../../lib/utils/dir'); 5 | const f = fixtures(__dirname); 6 | 7 | test('to get packages in bolt repo', async t => { 8 | let cwd = f.copy('bolt-repo'); 9 | let h = await getAllPackages(cwd); 10 | t.regex(h.toString(), /elem/); 11 | t.regex(h.toString(), /react/); 12 | t.regex(h.toString(), /util/); 13 | }); 14 | 15 | test('to get packages in lerna repo', async t => { 16 | let cwd = f.copy('lerna-repo'); 17 | let h = await getAllPackages(cwd); 18 | t.regex(h.toString(), /elem/); 19 | t.regex(h.toString(), /react/); 20 | t.regex(h.toString(), /util/); 21 | }); 22 | 23 | test('to get packages in generic repo', async t => { 24 | let cwd = f.copy('generic-repo'); 25 | let h = await getAllPackages(cwd); 26 | t.regex(h.toString(), /elem/); 27 | t.regex(h.toString(), /react/); 28 | t.regex(h.toString(), /util/); 29 | }); 30 | -------------------------------------------------------------------------------- /test/utils/getInternalDependency.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | const fixtures = require('fixturez'); 4 | const {getAllPackagesName, getInternalDependency} = require('../../lib/utils/getInternalDependency'); 5 | const f = fixtures(__dirname); 6 | 7 | test('getAllPackagesName()', async t => { 8 | let cwd = f.copy('generic-repo'); 9 | const allPackagesName = await getAllPackagesName(cwd, ['/packages/elem', '/packages/react', '/packages/util']); 10 | t.is(allPackagesName.size, 3); 11 | t.truthy(allPackagesName.has('elem')); 12 | t.truthy(allPackagesName.has('react')); 13 | t.truthy(allPackagesName.has('util')); 14 | }); 15 | 16 | test('getInternalDependency()', async t => { 17 | let cwd = f.copy('generic-repo'); 18 | const dependencyGraph = await getInternalDependency(cwd, ['/packages/elem', '/packages/react', '/packages/util']); 19 | t.deepEqual(dependencyGraph, { react: [ 'elem' ] }) 20 | }); 21 | --------------------------------------------------------------------------------