Skip to content

Commit 4594f94

Browse files
committed
add installations clean/show
1 parent 3b66f3c commit 4594f94

17 files changed

+191
-43
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
tsconfig.json
44
/test
55
*.lock
6-
.*
6+
.*
7+
*.yml

.vscode/settings.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
"search.exclude": {},
44
"files.exclude": {
55
"**/*.js": {
6-
"when": "$(basename).ts"
7-
},
8-
"**/*.js.map": {
9-
"when": "$(basename).ts"
10-
},
11-
"**/*.d.ts": {
12-
"when": "$(basename).ts"
13-
}
6+
"when": "$(basename).ts"
7+
},
8+
"**/*.js.map": true,
9+
"**/*.d.ts": {
10+
"when": "$(basename).ts"
11+
}
1412
},
15-
"prettier.tslintIntegration": true,
13+
"prettier.tslintIntegration": false,
1614
// "tslint.run": "onSave",
1715
// "tslint.autoFixOnSave": true,
1816
//"editor.formatOnType": true,
1917
"editor.tabSize": 2,
20-
"editor.insertSpaces": true
21-
}
18+
"editor.insertSpaces": true
19+
}

.yalcignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Yalc changelog
22

3+
## 1.0.0.pre.24
4+
- postupdate script on update (and push)
5+
- new file inclusion algorithm with `npm-packlist`
6+
- .yalcignore added
7+
- installations show/clean commmand
8+
39
## 1.0.0.pre.16 (2018-01-02)
410
- fix package deps
511
- fix `--link` removal

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ yarn global add yalc
3535

3636
### Publish
3737
- Run `yalc publish` in your dependency package `my-package`.
38-
- It will copy [all the files that should be published in remote NPM registry](https://docs.npmjs.com/files/package.json#files), but will not include standard non-code files like `README`, `LICENCE` etc. (If you need them included, add `!LICENCE` to `.npmignore`).
38+
- It will copy [all the files that should be published in remote NPM registry](https://docs.npmjs.com/files/package.json#files).
39+
3940
- It will run `preyalc` or `prepublish` scripts before, and `postyalc` or `postpublish` after. Use `--force` to publish without running scripts.
4041

42+
- While copying package content, `yalc` calculates the hash signature of all files and, by default, adds this signature to the package manifest `version`. You can disable this by using the `--no-sig` option.
43+
44+
- You may also use `.yalcignore` to exclude files from publishing to yalc repo, for example files like README.md, etc.
45+
4146
- **NB!** Windows users should make sure the `LF` new line symbol is used in published sources; it may be needed for some packages to work correctly (for example, `bin` scripts). `yalc` won't convert line endings for you (because `npm` and `yarn` won't either).
4247

43-
- While copying package content, `yalc` calculates the hash signature of all files and, by default, adds this signature to the package manifest `version`. You can disable this by using the `--no-sig` option.
48+
- **NB!** Note that, if you want to include `.yalc` folder in published package content, you should add `!.yalc` line to `.npmignore`.
4449

4550
- [Easily propagate package updates everywhere.](#pushing-updates-automatically-to-all-installations)
4651

@@ -87,11 +92,17 @@ will copy the current version from the store to your project's `.yalc` folder an
8792
### Keep it in git
8893
- You may want to keep shared `yalc'ed` stuff within the projects you are working on and treat it as a part of the project's codebase. This may really simplify management and usage of shared *work in progress* packages within your projects and help to make things consistent. So, then just do it, keep `.yalc` folder and `yalc.lock` in git.
8994
- Replace it with published versions from remote repository when ready.
95+
- **NB!** - standard non-code files like `README`, `LICENCE` etc. will be included also, so you may want to excluded them in `.gitignore` with a line like `**/.yalc/**/*.md` or you may use `.yalcignore` not to include those files in package content.
96+
9097

9198
### Publish/push sub-projects
9299

93100
- Useful for monorepos (projects with multiple sub-projects/packages): `yalc publish package-dir will perform publish operation in nested `package` folder of current working dir.
94101

102+
### Clean up installations file
103+
104+
- While working with yalc for some time on the dev machine you may face the situation when you have locations where you added yalc'ed packages being removed from file system, and this will cause some warning messages when yalc will try to push package to removed location. To get rid of such messages there in an explicit command for this `yalc installations clean [package]`.
105+
95106

96107
## Related links
97108

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
{
22
"name": "yalc",
3-
"version": "1.0.0-pre.23",
3+
"version": "1.0.0-pre.24",
44
"description": "Work yarn packages locally like a boss.",
55
"homepage": "https://github.com/whitecolor/yalc",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/whitecolor/yalc.git"
99
},
10+
"prettier": {
11+
"semi": false,
12+
"singleQuote": true
13+
},
1014
"bin": {
1115
"yalc": "src/yalc.js"
1216
},
1317
"main": "src/index.js",
1418
"scripts": {
1519
"build": "tsc",
20+
"clean": "trash **/*.js **/*.js.map **/*.d.ts **/*.log !**/node_modules/**",
1621
"precommit": "yalc check",
17-
"prepublishOnly": "tsc && yarn test",
22+
"prepublishOnly": "yarn clean && tsc && yarn test",
1823
"test": "tsc && mocha test && yarn lint",
1924
"watch": "mocha test --watch",
2025
"ci": "tsc && yarn test",
2126
"lint": "tslint -p ."
2227
},
23-
"license": "MIT",
2428
"dependencies": {
2529
"del": "^2.2.2",
2630
"fs-extra": "^4.0.2",
31+
"ignore": "^5.0.4",
2732
"npm-packlist": "^1.1.12",
2833
"user-home": "^2.0.0",
2934
"yargs": "^7.1.0"
@@ -45,6 +50,7 @@
4550
"tslint": "^5.11.0",
4651
"tslint-config-prettier": "^1.15.0",
4752
"tslint-plugin-prettier": "^1.3.0",
48-
"typescript": "2.6.1-insiders.20171016"
49-
}
53+
"typescript": "^3.2.0-rc"
54+
},
55+
"license": "MIT"
5056
}

src/add.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface AddPackagesOptions {
2323
linkDep?: boolean
2424
yarn?: boolean
2525
safe?: boolean
26+
to?: string
27+
from?: string
2628
workingDir: string
2729
}
2830

src/copy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as fs from 'fs-extra'
22
import * as crypto from 'crypto'
33
import * as npmPacklist from 'npm-packlist'
4+
import ignore from 'ignore'
45

56
import { join, dirname } from 'path'
7+
import { readIgnoreFile } from '.'
68
import {
79
PackageManifest,
810
getStorePackagesDir,
@@ -47,9 +49,14 @@ export const copyPackageToStore = async (
4749
const copyFromDir = options.workingDir
4850
const locPackageStoreDir = join(getStorePackagesDir(), pkg.name, pkg.version)
4951

50-
fs.removeSync(locPackageStoreDir)
52+
await fs.remove(locPackageStoreDir)
53+
54+
const ignoreFileContent = readIgnoreFile(workingDir)
55+
56+
const ignoreRule = ignore().add(ignoreFileContent)
57+
const filesToCopy = (await npmPacklist({ path: workingDir }))
58+
.filter(f => !ignoreRule.ignores(f))
5159

52-
const filesToCopy = await npmPacklist({ path: workingDir })
5360
const hashes = await Promise.all(
5461
filesToCopy
5562
.sort()

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { join } = path
88

99
export const values = {
1010
myNameIs: 'yalc',
11+
ignoreFileName: '.yalcignore',
1112
myNameIsCapitalized: 'Yalc',
1213
lockfileName: 'yalc.lock',
1314
yalcPackagesFolder: '.yalc',
@@ -65,6 +66,8 @@ export interface PackageManifest {
6566
devDependencies?: { [name: string]: string }
6667
scripts?: {
6768
preinstall?: string
69+
postupdate: string
70+
postpush: string
6871
install?: string
6972
prepublish?: string
7073
prepublishOnly?: string
@@ -134,6 +137,16 @@ export function readSignatureFile(workingDir: string) {
134137
}
135138
}
136139

140+
export function readIgnoreFile(workingDir: string) {
141+
const flePath = join(workingDir, values.ignoreFileName)
142+
try {
143+
const fileData = fs.readFileSync(flePath, 'utf-8')
144+
return fileData
145+
} catch (e) {
146+
return ''
147+
}
148+
}
149+
137150
export function writeSignatureFile(workingDir: string, signature: string) {
138151
const signatureFilePath = join(workingDir, signatureFileName)
139152
try {

src/installations.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs-extra'
22
import * as path from 'path'
3-
import { getStoreMainDir, values } from '.'
3+
import { getStoreMainDir, values, readPackageManifest } from '.'
4+
import { readLockfile } from './lockfile'
45

56
export type PackageName = string & { __packageName: true }
67

@@ -34,6 +35,68 @@ export const readInstallationsFile = (): InstallationsFile => {
3435
return installationsConfig
3536
}
3637

38+
export const showInstallations = ({ packages }: { packages: string[] }) => {
39+
const config = readInstallationsFile()
40+
Object.keys(config)
41+
.filter(
42+
packageName =>
43+
packages.length ? packages.indexOf(packageName) >= 0 : true
44+
)
45+
.map((name: PackageName) => ({ name, locations: config[name] }))
46+
.forEach(({ name, locations }) => {
47+
console.log(`Installations of package ${name}:`)
48+
locations.forEach(loc => {
49+
console.log(` ${loc}`)
50+
})
51+
})
52+
}
53+
54+
export const cleanInstallations = async ({
55+
packages,
56+
dry
57+
}: {
58+
packages: string[],
59+
dry: boolean
60+
}) => {
61+
const config = readInstallationsFile()
62+
const installsToRemove = Object.keys(config)
63+
.filter(
64+
packageName =>
65+
packages.length ? packages.indexOf(packageName) >= 0 : true
66+
)
67+
.map((name: PackageName) => ({ name, locations: config[name] }))
68+
.reduce(
69+
(list, { name, locations }) => {
70+
return locations.reduce((list, loc) => {
71+
const lockfile = readLockfile({ workingDir: loc })
72+
const lockPackages = Object.keys(lockfile.packages)
73+
if (lockPackages.indexOf(name) < 0) {
74+
return list.concat([
75+
{
76+
name,
77+
version: '',
78+
path: loc
79+
}
80+
])
81+
}
82+
return list
83+
}, list)
84+
},
85+
[] as PackageInstallation[]
86+
)
87+
if (installsToRemove.length) {
88+
console.log(`Installations clean up:`)
89+
installsToRemove.forEach(inst => {
90+
console.log(`Package ${inst.name}: ${inst.path}`)
91+
})
92+
if (!dry) {
93+
await removeInstallations(installsToRemove)
94+
} else {
95+
console.log(`Dry run.`)
96+
}
97+
}
98+
}
99+
37100
export const saveInstallationsFile = async (
38101
installationsConfig: InstallationsFile
39102
) => {
@@ -66,7 +129,7 @@ export const addInstallations = async (
66129
}
67130

68131
export const removeInstallations = async (
69-
installations: (PackageInstallation)[]
132+
installations: PackageInstallation[]
70133
) => {
71134
const installationsConfig = readInstallationsFile()
72135
let updated = false

0 commit comments

Comments
 (0)