-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands for working with locally linked packages (#1)
- Loading branch information
Showing
16 changed files
with
354 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# CHANGELOG | ||
|
||
## 1.1.0 (May 16, 2020) | ||
|
||
Add `linked`, `linkable`, `unlink` and `unlink-all` commands for working with locally linked packages | ||
|
||
## 1.0.0 (April 4, 2020) | ||
|
||
Initial release! :tada: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "blarn", | ||
"description": "A Yarn wrapper with extra functionality", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Ian Sutherland <[email protected]>", | ||
"license": "MIT", | ||
"repository": { | ||
|
@@ -49,7 +49,8 @@ | |
] | ||
}, | ||
"dependencies": { | ||
"update-notifier": "4.1.0" | ||
"update-notifier": "4.1.0", | ||
"yarn-config-directory": "1.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/find-package-json": "1.1.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import chalk from 'chalk'; | ||
import pacote from 'pacote'; | ||
|
||
import { runYarn } from '../lib/yarn'; | ||
|
||
const add = async (packages: string[]): Promise<void> => { | ||
const typePackages = []; | ||
|
||
for (const pkg of packages) { | ||
if (!pkg.startsWith('-') && !pkg.startsWith('--') && !pkg.startsWith('@types')) { | ||
let typePackage = `@types/${pkg}`; | ||
|
||
if (pkg.startsWith('@')) { | ||
const [org, packageName] = pkg.slice(1).split('/'); | ||
|
||
typePackage = `@types/${org}__${packageName}`; | ||
} | ||
|
||
try { | ||
await pacote.manifest(typePackage); | ||
|
||
typePackages.push(typePackage); | ||
} catch (error) { | ||
if (error.code !== 'E404') { | ||
console.error(`Error finding package: ${typePackage}`); | ||
} | ||
} | ||
} | ||
|
||
if (typePackages.length > 0) { | ||
console.log(`\n${chalk.blue('info')} Installing types: ${typePackages.join(' ')}`); | ||
|
||
await runYarn('add', '--dev', ...typePackages); | ||
} | ||
} | ||
}; | ||
|
||
export { add }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import chalk from 'chalk'; | ||
import yarnConfig from 'yarn-config-directory'; | ||
|
||
import { getSymlinks } from '../lib/symlink'; | ||
|
||
const linkable = async (): Promise<void> => { | ||
const linkPath = path.join(yarnConfig(), 'link'); | ||
|
||
if (!fs.existsSync(linkPath)) { | ||
console.log('No linkable packages'); | ||
} | ||
|
||
const symlinks = getSymlinks(linkPath); | ||
const linkablePackages = symlinks.map(symlink => ({ | ||
name: symlink.name.replace(`${linkPath}/`, ''), | ||
target: symlink.target | ||
})); | ||
|
||
if (linkablePackages.length > 0) { | ||
linkablePackages.sort((a, b) => (a.name > b.name ? 1 : -1)); | ||
|
||
for (const pkg of linkablePackages) { | ||
console.log(chalk.magenta(pkg.name), '->', pkg.target); | ||
} | ||
} else { | ||
console.log('No linkable packages'); | ||
} | ||
}; | ||
|
||
export { linkable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import chalk from 'chalk'; | ||
|
||
import { getSymlinks } from '../lib/symlink'; | ||
|
||
const linked = async (): Promise<void> => { | ||
const searchPath = path.join(process.cwd(), 'node_modules'); | ||
|
||
if (!fs.existsSync(searchPath)) { | ||
console.error(`${chalk.red('error')} not a node package`); | ||
} | ||
|
||
const symlinks = getSymlinks(searchPath); | ||
const linkedPackages = symlinks | ||
.filter(symlink => !symlink.name.includes('.bin')) | ||
.map(symlink => ({ | ||
name: symlink.name.replace(`${searchPath}/`, ''), | ||
target: symlink.target | ||
})); | ||
|
||
if (linkedPackages.length > 0) { | ||
linkedPackages.sort((a, b) => (a.name > b.name ? 1 : -1)); | ||
|
||
for (const pkg of linkedPackages) { | ||
console.log(chalk.magenta(pkg.name), '->', pkg.target); | ||
} | ||
} else { | ||
console.log('No linked packages'); | ||
} | ||
}; | ||
|
||
export { linked }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PackageJson } from '../lib/package'; | ||
import { runYarn } from '../lib/yarn'; | ||
|
||
const remove = async (packageJson: PackageJson, packages: string[]): Promise<void> => { | ||
const typePackages = []; | ||
|
||
if (packageJson.devDependencies) { | ||
for (const pkg of packages) { | ||
if (!pkg.startsWith('-') && !pkg.startsWith('--') && !pkg.startsWith('@types')) { | ||
let typePackage = `@types/${pkg}`; | ||
|
||
if (pkg.startsWith('@')) { | ||
const [org, packageName] = pkg.slice(1).split('/'); | ||
|
||
typePackage = `@types/${org}__${packageName}`; | ||
} | ||
|
||
if (Object.keys(packageJson.devDependencies).includes(typePackage)) { | ||
typePackages.push(typePackage); | ||
} | ||
} | ||
} | ||
} | ||
|
||
await runYarn('remove', ...process.argv.slice(3), ...typePackages); | ||
}; | ||
|
||
export { remove }; |
Oops, something went wrong.