mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Compare commits
518 Commits
v1.7.9
...
fix/github
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aaf59d725 | ||
|
|
f7c5154490 | ||
|
|
cba4b2a4cd | ||
|
|
bdabf6a4e6 | ||
|
|
7896224384 | ||
|
|
3209cda975 | ||
|
|
38501a0b93 | ||
|
|
e60d236b25 | ||
|
|
044896e708 | ||
|
|
fc4c260de4 | ||
|
|
d405917b4a | ||
|
|
22bbb3fcaf | ||
|
|
8b6c8eeaa9 | ||
|
|
58ddb59104 | ||
|
|
f26fe38c30 | ||
|
|
9317bb6e33 | ||
|
|
2693bae8ed | ||
|
|
8368539a93 | ||
|
|
8947400487 | ||
|
|
44eeb60529 | ||
|
|
2309cd80c6 | ||
|
|
684ab0c0a6 | ||
|
|
1f6b32a48e | ||
|
|
e4f0295ef1 | ||
|
|
85e39cf190 | ||
|
|
16c134f0f9 | ||
|
|
bcbff32716 | ||
|
|
809117ea73 | ||
|
|
af448ba484 | ||
|
|
89069784bb | ||
|
|
57cc6f7a40 | ||
|
|
cea728c7bc | ||
|
|
f6be8e5e28 | ||
|
|
c6f7ec36de | ||
|
|
3235b3c0d3 | ||
|
|
6ca5d434a4 | ||
|
|
eb27ae8fdc | ||
|
|
353a399f75 | ||
|
|
c718541a4e | ||
|
|
1f4372299a | ||
|
|
e640d0ec5c | ||
|
|
2e5acfe076 | ||
|
|
19f3c53c70 | ||
|
|
26902aec27 | ||
|
|
08feaf2b0a | ||
|
|
db1ed1c08f | ||
|
|
3c2562ca0e | ||
|
|
b1f1b8fae3 | ||
|
|
f1c874b202 | ||
|
|
4757e7353f | ||
|
|
249ac47b9c | ||
|
|
dc59913098 | ||
|
|
343e6ac8bc | ||
|
|
e729829174 | ||
|
|
40e3ee091b | ||
|
|
8ee2d78779 | ||
|
|
7c54812ecf | ||
|
|
3251051d20 | ||
|
|
81052830f2 | ||
|
|
7b2fd5dcd1 | ||
|
|
bbc9b35cb1 | ||
|
|
3aebb34f1d | ||
|
|
8c624bbda6 | ||
|
|
7ee1686cf4 | ||
|
|
8e181c1792 | ||
|
|
4793fc0d1c | ||
|
|
4d7cdb0556 | ||
|
|
037bbff17e | ||
|
|
358a73b98e | ||
|
|
32cbb5a0e8 | ||
|
|
3853d1297e | ||
|
|
1e398f999b | ||
|
|
3a0ea968f4 | ||
|
|
5283a132bc | ||
|
|
db1453f7c0 | ||
|
|
878a228a7d | ||
|
|
b33041c3ec | ||
|
|
c8a6ff38a0 | ||
|
|
ef67955c21 | ||
|
|
36a14b9b37 | ||
|
|
c17c725057 | ||
|
|
2b31f6c07a | ||
|
|
6a18cde782 | ||
|
|
32c5538fc5 | ||
|
|
57478d86c7 | ||
|
|
42107e6fea | ||
|
|
9aae3b8d7e | ||
|
|
34ec39507c | ||
|
|
304bb36bbc | ||
|
|
376a2de600 | ||
|
|
9e58bbca31 | ||
|
|
027a0694f7 | ||
|
|
7bc97a1241 | ||
|
|
bd2c253f99 | ||
|
|
f1efce7d1f | ||
|
|
844cc5a527 | ||
|
|
0e27b6f813 | ||
|
|
9219f54718 | ||
|
|
5a2272cab1 | ||
|
|
609607b096 | ||
|
|
e9657668a9 | ||
|
|
f18b38cde5 | ||
|
|
e6f1805df0 | ||
|
|
4da1b62542 | ||
|
|
6d12ef291b | ||
|
|
c8d5199815 | ||
|
|
cd8d397e63 | ||
|
|
5a9c099188 | ||
|
|
2137089a70 | ||
|
|
fbd02852a3 | ||
|
|
f2584ade24 | ||
|
|
50bfd14968 | ||
|
|
d867095f50 | ||
|
|
e51bf20e72 | ||
|
|
15f8a30cd4 | ||
|
|
b7c19695e7 | ||
|
|
b85cf2683c | ||
|
|
8df5970300 | ||
|
|
db265d471f | ||
|
|
0441e16bdb | ||
|
|
30a489535e | ||
|
|
ac88ece259 | ||
|
|
9b45c76744 | ||
|
|
059a5f83b7 | ||
|
|
cf5cd61995 | ||
|
|
a499cc5103 | ||
|
|
bebb4fb33b | ||
|
|
2c243ea5b7 | ||
|
|
f53100d8d3 | ||
|
|
acbe60cdf1 | ||
|
|
4c7f37e0f8 | ||
|
|
3ba696937c | ||
|
|
1647994471 | ||
|
|
674e09dc56 | ||
|
|
4c129d470f | ||
|
|
c630f01baa | ||
|
|
6018fc13b2 | ||
|
|
c4fc6cd0e2 | ||
|
|
eed8735238 | ||
|
|
8c0155e8bd | ||
|
|
b2d4412e59 | ||
|
|
4e3e45a88b | ||
|
|
af9b386d8a | ||
|
|
201b8a3bc6 | ||
|
|
a23f66d889 | ||
|
|
a1596bb63c | ||
|
|
19af145166 | ||
|
|
4ed81be0c6 | ||
|
|
1c62adcdb6 | ||
|
|
95f46930a5 | ||
|
|
76dd504589 | ||
|
|
938c69c816 | ||
|
|
d5fc402a89 | ||
|
|
065a7a1f1b | ||
|
|
ccadffea73 | ||
|
|
b3390ce201 | ||
|
|
6039f6c691 | ||
|
|
c65cdc8699 | ||
|
|
7603886e04 | ||
|
|
406a96e4d1 | ||
|
|
7d74d7d8f6 | ||
|
|
e98d8139bc | ||
|
|
8a47aab01d | ||
|
|
395b208a0c | ||
|
|
f6178c2f75 | ||
|
|
f1e04e5629 | ||
|
|
cc913a728a | ||
|
|
f8c179b153 | ||
|
|
bea46fb879 | ||
|
|
379de05a61 | ||
|
|
c2f222760a | ||
|
|
9aef3b7f1d | ||
|
|
c93bbbd302 | ||
|
|
009e5ce0c8 | ||
|
|
61bb4f53c0 | ||
|
|
b6dd5e445e | ||
|
|
6f4b77a440 | ||
|
|
463584ea10 | ||
|
|
fd8d603831 | ||
|
|
a1ec83b002 | ||
|
|
041d3f2843 | ||
|
|
0b22127906 | ||
|
|
0b0b507827 | ||
|
|
16de289942 | ||
|
|
02dc97e413 | ||
|
|
703eae72eb | ||
|
|
6a629e963c | ||
|
|
f242e60c1a | ||
|
|
6d335abe21 | ||
|
|
179b8a28b4 | ||
|
|
fc13328e2a | ||
|
|
b3f28fac64 | ||
|
|
f65af7a308 | ||
|
|
559f50a3e3 | ||
|
|
18b809314c | ||
|
|
aa1f819c0d | ||
|
|
5a8cecf499 | ||
|
|
79f362abee | ||
|
|
42db74b522 | ||
|
|
3309e9f53f | ||
|
|
ae3a017143 | ||
|
|
43d7a11ba8 | ||
|
|
02e12e17d6 | ||
|
|
4f838685d6 | ||
|
|
6339ba09f0 | ||
|
|
23c2e82c97 | ||
|
|
7138d3518e | ||
|
|
f852325906 | ||
|
|
3c9082ece3 | ||
|
|
98c77ffe18 | ||
|
|
b95d5f9f23 | ||
|
|
adf59d78d7 | ||
|
|
904ae3eab7 | ||
|
|
44d2309700 | ||
|
|
5dd6a3883a | ||
|
|
5f0a3fe1c1 | ||
|
|
bc3079332c | ||
|
|
3c0395b19f | ||
|
|
9e7b591c78 | ||
|
|
b6107a1198 | ||
|
|
2d94018f12 | ||
|
|
42f0268829 | ||
|
|
4812c380c4 | ||
|
|
0e833c155a | ||
|
|
9ebb1b17d1 | ||
|
|
3397cf053c | ||
|
|
6e73b5934e | ||
|
|
a5c49d89d5 | ||
|
|
1f9a92e6ad | ||
|
|
6280611aea | ||
|
|
20c0e6e12b | ||
|
|
d3ccc73796 | ||
|
|
53d3ac570e | ||
|
|
237022baae | ||
|
|
bccfd7bbbb | ||
|
|
597853cd6c | ||
|
|
1bd6568f94 | ||
|
|
4b2235aef2 | ||
|
|
faf1c26669 | ||
|
|
c385c08e2f | ||
|
|
ab7e7ac12a | ||
|
|
3788e8d7b3 | ||
|
|
041290e1c7 | ||
|
|
1099e786df | ||
|
|
be95169c1b | ||
|
|
a899cb48b3 | ||
|
|
ed8ac01f07 | ||
|
|
12cde3ddce | ||
|
|
860d70551f | ||
|
|
6db6fcc414 | ||
|
|
25c229de73 | ||
|
|
d954a54017 | ||
|
|
78bbf1f04f | ||
|
|
52938202bd | ||
|
|
0f29818030 | ||
|
|
dd39a25dd0 | ||
|
|
6ed4be9135 | ||
|
|
02b6a21276 | ||
|
|
794ca573b8 | ||
|
|
032f771996 | ||
|
|
3dfd7a9ab1 | ||
|
|
1713e5e2eb | ||
|
|
1d7342573b | ||
|
|
64fc295ecc | ||
|
|
6b6dc8311a | ||
|
|
b1d8c3c1e3 | ||
|
|
71037cb482 | ||
|
|
1f4e5cadd2 | ||
|
|
0de9cc82f6 | ||
|
|
7dba46df9b | ||
|
|
9cb09feb65 | ||
|
|
fb084fa4cd | ||
|
|
846b8fb57e | ||
|
|
cb649830a0 | ||
|
|
89510f40d3 | ||
|
|
9f2207eb1f | ||
|
|
dfb18b305d | ||
|
|
1606395546 | ||
|
|
8dbd79d49b | ||
|
|
e2c67fa25a | ||
|
|
cf85177c7f | ||
|
|
bc4a0f448b | ||
|
|
14ef86456f | ||
|
|
12efc85baf | ||
|
|
68124dfdbe | ||
|
|
ee4158e90b | ||
|
|
0b3b7efccf | ||
|
|
6064269936 | ||
|
|
d0929896cf | ||
|
|
990e87de1f | ||
|
|
8da47dcd00 | ||
|
|
c63d88d987 | ||
|
|
c21bde192b | ||
|
|
39f1f8aff5 | ||
|
|
8b699c58ae | ||
|
|
743a97c784 | ||
|
|
ea7ae5698a | ||
|
|
3ed9b3ec39 | ||
|
|
e8f3e3b88a | ||
|
|
82d16fbfde | ||
|
|
766dcd0dd5 | ||
|
|
87302d6d86 | ||
|
|
05b94d1d15 | ||
|
|
ed0c93aec3 | ||
|
|
03b4467173 | ||
|
|
f027cc6a3e | ||
|
|
634ce6829a | ||
|
|
64b5f9af78 | ||
|
|
9269fcb8a7 | ||
|
|
f0d29cb755 | ||
|
|
897e0f1ba6 | ||
|
|
4cfa94d304 | ||
|
|
5e2abb8a33 | ||
|
|
0dc5052e36 | ||
|
|
774ad1e2ff | ||
|
|
52e91cc309 | ||
|
|
d3e6274939 | ||
|
|
ec904eb8a4 | ||
|
|
95a09c5463 | ||
|
|
125fb598d5 | ||
|
|
f8c13f939c | ||
|
|
c846b24ebb | ||
|
|
85324d9109 | ||
|
|
10b410d46f | ||
|
|
c87fe7c265 | ||
|
|
ce0984573b | ||
|
|
b38c3a5035 | ||
|
|
15dca65bd1 | ||
|
|
e1aa43147d | ||
|
|
057b18e4be | ||
|
|
d4f2ced6a3 | ||
|
|
0b6c92fcd2 | ||
|
|
4491e71ee2 | ||
|
|
d09f78801c | ||
|
|
f26ea32897 | ||
|
|
86dbea7ddb | ||
|
|
4221ddbb35 | ||
|
|
eeb0c22d90 | ||
|
|
eb801e66ae | ||
|
|
4d0d4ca6ea | ||
|
|
56cdae67c3 | ||
|
|
b50017cad4 | ||
|
|
c85c38cde3 | ||
|
|
f606eda18d | ||
|
|
08c9e2dde3 | ||
|
|
882bf7b020 | ||
|
|
da4e70bc60 | ||
|
|
f75f720c8a | ||
|
|
8d3aff5ff1 | ||
|
|
4e8c9078f7 | ||
|
|
41e4efcf1f | ||
|
|
f55e6138a5 | ||
|
|
147e24d835 | ||
|
|
4a94858ed1 | ||
|
|
12c90bae04 | ||
|
|
6f7f10b2f7 | ||
|
|
430a2ea2f6 | ||
|
|
87569617ae | ||
|
|
b17beaccf1 | ||
|
|
cddba64151 | ||
|
|
a006bfeb24 | ||
|
|
71e1a8666d | ||
|
|
16e7872a82 | ||
|
|
aa4ebb07f8 | ||
|
|
4366d6a8c7 | ||
|
|
aa76d49234 | ||
|
|
d9df06644e | ||
|
|
554ee01263 | ||
|
|
b3055067d8 | ||
|
|
7f997d4b59 | ||
|
|
d2d959f455 | ||
|
|
a9e497f878 | ||
|
|
e423e9ffba | ||
|
|
ff99fae928 | ||
|
|
3c9983ca12 | ||
|
|
d3412e7de6 | ||
|
|
2841942899 | ||
|
|
415e79b523 | ||
|
|
9a6fdaa42b | ||
|
|
0cdbe998cb | ||
|
|
35b0c49da5 | ||
|
|
d43c9f006b | ||
|
|
01a6ae61d2 | ||
|
|
4b4b233377 | ||
|
|
ccc9907034 | ||
|
|
26520abe2b | ||
|
|
1397c3248d | ||
|
|
c40dc39b88 | ||
|
|
a2753bb27d | ||
|
|
1c5529691b | ||
|
|
8e5bdc6b2b | ||
|
|
39324d6b55 | ||
|
|
b1ad187d1b | ||
|
|
606f15fec5 | ||
|
|
09a0eb26d1 | ||
|
|
bf9e8048ff | ||
|
|
21ebc226e4 | ||
|
|
8e3fef9096 | ||
|
|
829dccc1b6 | ||
|
|
a65caa62b3 | ||
|
|
ddb6f9c5b4 | ||
|
|
e152ab6cf2 | ||
|
|
4085af023a | ||
|
|
686e401368 | ||
|
|
2fdfa64b13 | ||
|
|
f406cfcebb | ||
|
|
80f35725e6 | ||
|
|
6741d99681 | ||
|
|
ad4ec14778 | ||
|
|
2bf16ad88b | ||
|
|
6c56581c15 | ||
|
|
ce89d9fbe0 | ||
|
|
e298f74310 | ||
|
|
c550c1373e | ||
|
|
6a1bb88c3b | ||
|
|
a585e96fdf | ||
|
|
e78ef493a1 | ||
|
|
c139378694 | ||
|
|
d0eb3e760f | ||
|
|
9cfa3e5002 | ||
|
|
82278037ec | ||
|
|
0b592f86d0 | ||
|
|
ee4e003c2d | ||
|
|
b2904bc6fb | ||
|
|
67b94cf52e | ||
|
|
c308d2c9dd | ||
|
|
e36370b080 | ||
|
|
d0f005a6f1 | ||
|
|
a461fa9137 | ||
|
|
22e969fb59 | ||
|
|
34527c8395 | ||
|
|
012f4d68bc | ||
|
|
724283433a | ||
|
|
aea19b93b1 | ||
|
|
73020a711d | ||
|
|
7e62e671e3 | ||
|
|
2e845ac0ab | ||
|
|
2df41e52ed | ||
|
|
bf8e93f581 | ||
|
|
f5eec3283c | ||
|
|
223161c7d6 | ||
|
|
b8ba6e4827 | ||
|
|
15c8259ac2 | ||
|
|
720492932f | ||
|
|
a08a0fb084 | ||
|
|
827fbaac1f | ||
|
|
297224bd31 | ||
|
|
9dc835c60c | ||
|
|
67a96bc2f3 | ||
|
|
ff5bf16111 | ||
|
|
8d22059462 | ||
|
|
91d144f5f7 | ||
|
|
c894b1d335 | ||
|
|
d30a7bf6a1 | ||
|
|
649d5f56c9 | ||
|
|
36b033c2f7 | ||
|
|
dc9bce915b | ||
|
|
c9a7cfafd0 | ||
|
|
9d9585ecba | ||
|
|
0ebd7e6a58 | ||
|
|
a100abc3b6 | ||
|
|
94f6945d5a | ||
|
|
442d771a7a | ||
|
|
242e11eefc | ||
|
|
7fbbae8cd4 | ||
|
|
b80d96d9c7 | ||
|
|
d8e69360b9 | ||
|
|
83ae9b66a3 | ||
|
|
4ac052c10b | ||
|
|
f1717f8319 | ||
|
|
cb000549bd | ||
|
|
2712aa2ae2 | ||
|
|
7dcefa6bee | ||
|
|
70e3528809 | ||
|
|
c7780a2708 | ||
|
|
26bab84d04 | ||
|
|
efea6136e7 | ||
|
|
c56026c18a | ||
|
|
1d9504d0f0 | ||
|
|
780b1f8acc | ||
|
|
9b6c5741de | ||
|
|
0742e18edd | ||
|
|
cb59c2489b | ||
|
|
3158b544d5 | ||
|
|
e80270d1fa | ||
|
|
99b37f24bb | ||
|
|
fdbdcc4130 | ||
|
|
08104966b2 | ||
|
|
1c99133177 | ||
|
|
28780dc67e | ||
|
|
423ce54d8a | ||
|
|
73bab73db6 | ||
|
|
3e90471fa2 | ||
|
|
7f2db8a9a7 | ||
|
|
d5fc147ffd | ||
|
|
77ffd7bbf9 | ||
|
|
42775d3477 | ||
|
|
6932b8c378 | ||
|
|
cff641ef80 | ||
|
|
373abf1b24 | ||
|
|
f668596667 | ||
|
|
93e0e815d7 | ||
|
|
05275c8938 | ||
|
|
19475db7dd | ||
|
|
aa315d7c97 | ||
|
|
080b25e30c | ||
|
|
a7c8c08183 | ||
|
|
bb98627d2b | ||
|
|
3060866586 | ||
|
|
eacf121f78 | ||
|
|
c39535fdd0 | ||
|
|
c3311df2a8 | ||
|
|
5a17314b2c | ||
|
|
07281f050c | ||
|
|
9c3757fb0c | ||
|
|
f5d5e59040 | ||
|
|
70880c066f | ||
|
|
5508c70f3a |
44
.github/ISSUE_TEMPLATE.md
vendored
Normal file
44
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<!--
|
||||
|
||||
If you are reporting a new issue, make sure that we do not have any duplicates.
|
||||
You can ensure this by searching the issue list for this repository.
|
||||
|
||||
You are welcome to open issues to discuss important general topics concerning Bower.
|
||||
However for support questions, please consider using http://stackoverflow.com or
|
||||
asking for help in our Discord channel: https://discordapp.com/invite/0fFM7QF0KpZaDeN9
|
||||
|
||||
# BUG REPORT
|
||||
|
||||
Use the commands below to provide key information to reproduce:
|
||||
You do NOT have to include this information if this is a FEATURE REQUEST OR DISCUSSION
|
||||
|
||||
For more information about reporting bugs, see:
|
||||
https://github.com/bower/bower/wiki/Report-a-Bug
|
||||
|
||||
-->
|
||||
|
||||
**Output of `bower -v && npm -v && node -v`:**
|
||||
|
||||
```
|
||||
(paste your output here)
|
||||
```
|
||||
|
||||
**Additional environment details (proxy, private registry, etc.):**
|
||||
|
||||
|
||||
|
||||
**Steps to reproduce the issue:**
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
**Describe the results you received:**
|
||||
|
||||
|
||||
|
||||
**Describe the results you expected:**
|
||||
|
||||
|
||||
|
||||
**Additional information:**
|
||||
21
.travis.yml
21
.travis.yml
@@ -1,16 +1,18 @@
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
- NODE_VERSION=0.10
|
||||
- NODE_VERSION=0.11
|
||||
- NODE_VERSION=0.12
|
||||
- NODE_VERSION=4.0
|
||||
- NODE_VERSION=5.0
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- "4.0"
|
||||
- "4.1"
|
||||
- "4.2"
|
||||
- "5"
|
||||
- "6"
|
||||
|
||||
install:
|
||||
- test $TRAVIS_OS_NAME = "osx" && brew install nvm && source $(brew --prefix nvm)/nvm.sh || test $TRAVIS_OS_NAME = "linux"
|
||||
- nvm install $NODE_VERSION
|
||||
- npm install -g npm@^2.0.0
|
||||
- node --version
|
||||
- npm --version
|
||||
- git --version
|
||||
@@ -23,6 +25,7 @@ os:
|
||||
- linux
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- os: osx
|
||||
- env: "NODE_VERSION=0.11"
|
||||
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,6 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## 1.7.8 - 2016-04-05
|
||||
## Unreleased
|
||||
|
||||
- Change default shorthand resolver for github from `git://` to `https://`
|
||||
- Allow to type the entire version when conflict occured, #2243
|
||||
- Allow `owner/reponame` shorthand for registering components, #2248
|
||||
- Allow single-char repo names and package names, #2249
|
||||
- Make `bower version` no longer honor `version` in bower.json, #2232
|
||||
- Add `postinstall` hook, #2252
|
||||
- Allow for `@` instead of `#` for `install` and `info` commands, #2322
|
||||
- Upgrade all bundled modules
|
||||
|
||||
## 1.7.9 - 2016-04-05
|
||||
|
||||
- Show warnings for invalid bower.json fields
|
||||
- Update bower-json
|
||||
@@ -83,7 +94,7 @@ https://github.com/npm/npm/issues/11227
|
||||
- Update bower config
|
||||
- Loads the .bowerrc file from the cwd specified on the command line
|
||||
- Allow the use of environment variables in .bowerrc ([#41](https://github.com/bower/config/issues/41))
|
||||
- Allow for array notation in ENV variables ([#44](https://github.com/bower/config/issues/44))
|
||||
- Allow for array notation in ENV variables ([#44](https://github.com/bower/config/issues/44))
|
||||
|
||||
## 1.6.9 - 2015-12-04
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
# Bower - A package manager for the web
|
||||
|
||||
> Bower needs resources for its maintenance. Please fill [this form](https://docs.google.com/forms/d/1i-Opb-uPdqUBBZQSbngv3Y3bfolG1gbBvtRLfxMnzRE/viewform?c=0&w=1) if you think you can help.
|
||||
> Bower needs your help. If you're willing to help, please say hello to team@bower.io or [donate](https://salt.bountysource.com/teams/bower)
|
||||
|
||||
[](https://travis-ci.org/bower/bower)
|
||||
[](https://ci.appveyor.com/project/sheerun/bower/history)
|
||||
[](https://travis-ci.org/bower/bower)
|
||||
[](https://ci.appveyor.com/project/bower/bower)
|
||||
[](https://coveralls.io/r/bower/bower?branch=master)
|
||||
[](https://discord.gg/0fFM7QF0KpZRh2cY)
|
||||
[](http://issuestats.com/github/bower/bower)
|
||||
[](http://issuestats.com/github/bower/bower)
|
||||
|
||||
<img align="right" height="300" src="http://bower.io/img/bower-logo.png">
|
||||
|
||||
|
||||
40
appveyor.yml
40
appveyor.yml
@@ -1,7 +1,8 @@
|
||||
# Thanks for Grunt for template of this file!
|
||||
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
# Set build version format here instead of in the admin panel.
|
||||
version: "{build}"
|
||||
|
||||
# Fix line endings in Windows. (runs before repo cloning)
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
@@ -11,33 +12,34 @@ environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
- nodejs_version: "4.0"
|
||||
- nodejs_version: "4.1"
|
||||
- nodejs_version: "4.2"
|
||||
- nodejs_version: "5"
|
||||
- nodejs_version: "4"
|
||||
- nodejs_version: "6"
|
||||
|
||||
# Allow failing jobs for bleeding-edge Node.js versions.
|
||||
# Finish on first failed build
|
||||
matrix:
|
||||
allow_failures:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "5"
|
||||
fast_finish: true
|
||||
|
||||
# Install scripts. (runs after repo cloning)
|
||||
# Install node, display versions, install dependencies
|
||||
install:
|
||||
# Get the latest stable version of Node 0.STABLE.latest
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
# Output useful info for debugging.
|
||||
- node --version
|
||||
- npm --version
|
||||
- git --version
|
||||
- svn --version
|
||||
# Install all dependencies
|
||||
- node --version && npm --version
|
||||
- git --version && svn --version
|
||||
- npm install
|
||||
|
||||
# Post-install test scripts.
|
||||
test_script:
|
||||
- cmd: npm run ci
|
||||
|
||||
# Don't actually build.
|
||||
build: off
|
||||
# Make clone much faster
|
||||
shallow_clone: true
|
||||
|
||||
# Set build version format here instead of in the admin panel.
|
||||
version: "{build}"
|
||||
# Disable Visual Studio build and deploy
|
||||
build: off
|
||||
deploy: off
|
||||
|
||||
# Cache node modules, and refresh if package.json changes
|
||||
cache:
|
||||
- node_modules -> package.json
|
||||
|
||||
@@ -101,7 +101,7 @@ function handleLogger(logger, renderer) {
|
||||
}
|
||||
})
|
||||
.on('error', function (err) {
|
||||
if (command !== 'help' && err.code === 'EREADOPTIONS') {
|
||||
if (command !== 'help' && (err.code === 'EREADOPTIONS' || err.code === 'EINVFORMAT')) {
|
||||
logger = bower.commands.help(command);
|
||||
renderer = cli.getRenderer('help', logger.json, bower.config);
|
||||
handleLogger(logger, renderer);
|
||||
|
||||
@@ -9,6 +9,9 @@ function info(logger, endpoint, property, config) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handle @ as version divider
|
||||
endpoint = endpoint.replace('@', '#');
|
||||
|
||||
var repository;
|
||||
var decEndpoint;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ function install(logger, endpoints, options, config) {
|
||||
// Convert endpoints to decomposed endpoints
|
||||
endpoints = endpoints || [];
|
||||
decEndpoints = endpoints.map(function (endpoint) {
|
||||
// handle @ as version divider
|
||||
endpoint = endpoint.replace('@', '#');
|
||||
return endpointParser.decompose(endpoint);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,16 +4,23 @@ var PackageRepository = require('../core/PackageRepository');
|
||||
var createError = require('../util/createError');
|
||||
var defaultConfig = require('../config');
|
||||
|
||||
function register(logger, name, url, config) {
|
||||
function register(logger, name, source, config) {
|
||||
var repository;
|
||||
var registryClient;
|
||||
var force;
|
||||
var url;
|
||||
var githubSourceRegex = /^\w[\w-]*\/\w[\w-]*$/;
|
||||
var getGithubUrl = function (source) {
|
||||
return 'git@github.com:' + source + '.git';
|
||||
};
|
||||
|
||||
config = defaultConfig(config);
|
||||
force = config.force;
|
||||
|
||||
name = (name || '').trim();
|
||||
url = (url || '').trim();
|
||||
source = (source || '').trim();
|
||||
|
||||
url = source.match(githubSourceRegex) ? getGithubUrl(source) : source;
|
||||
|
||||
// Bypass any cache
|
||||
config.offline = false;
|
||||
|
||||
@@ -4,116 +4,149 @@ var fs = require('../util/fs');
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
var execFile = require('child_process').execFile;
|
||||
var Project = require('../core/Project');
|
||||
var defaultConfig = require('../config');
|
||||
var createError = require('../util/createError');
|
||||
|
||||
function version(logger, versionArg, options, config) {
|
||||
var project;
|
||||
|
||||
options = options || {};
|
||||
|
||||
config = defaultConfig(config);
|
||||
project = new Project(config, logger);
|
||||
|
||||
return bump(project, versionArg, options.message);
|
||||
return bump(logger, config, versionArg, options.message);
|
||||
}
|
||||
|
||||
function bump(project, versionArg, message) {
|
||||
var cwd = project._config.cwd || process.cwd();
|
||||
function bump(logger, config, versionArg, message) {
|
||||
var cwd = config.cwd || process.cwd();
|
||||
var newVersion;
|
||||
var doGitCommit = false;
|
||||
|
||||
return checkGit(cwd)
|
||||
.then(function (hasGit) {
|
||||
doGitCommit = hasGit;
|
||||
})
|
||||
.then(project.getJson.bind(project))
|
||||
.then(function (json) {
|
||||
newVersion = getNewVersion(json.version, versionArg);
|
||||
json.version = newVersion;
|
||||
})
|
||||
.then(project.saveJson.bind(project))
|
||||
.then(function () {
|
||||
if (doGitCommit) {
|
||||
return gitCommitAndTag(cwd, newVersion, message);
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
console.log('v' + newVersion);
|
||||
return newVersion;
|
||||
});
|
||||
}
|
||||
|
||||
function getNewVersion(currentVersion, versionArg) {
|
||||
var newVersion = semver.valid(versionArg);
|
||||
if (!newVersion) {
|
||||
newVersion = semver.inc(currentVersion, versionArg);
|
||||
if (!versionArg) {
|
||||
throw createError('No <version> agrument provided', 'EREADOPTIONS');
|
||||
}
|
||||
if (!newVersion) {
|
||||
throw createError('Invalid version argument: `' + versionArg + '`. Usage: `bower version [<newversion> | major | minor | patch]`', 'EINVALIDVERSION');
|
||||
}
|
||||
if (currentVersion === newVersion) {
|
||||
throw createError('Version not changed', 'EVERSIONNOTCHANGED');
|
||||
}
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
function checkGit(cwd) {
|
||||
var gitDir = path.join(cwd, '.git');
|
||||
return Q.nfcall(fs.stat, gitDir)
|
||||
.then(function (stat) {
|
||||
if (stat.isDirectory()) {
|
||||
return checkGitStatus(cwd);
|
||||
return driver.check(cwd)
|
||||
.then(function () {
|
||||
return Q.all([driver.versions(cwd), driver.currentVersion(cwd)]);
|
||||
})
|
||||
.spread(function (versions, currentVersion) {
|
||||
currentVersion = currentVersion || '0.0.0';
|
||||
|
||||
if (semver.valid(versionArg)) {
|
||||
newVersion = semver.valid(versionArg);
|
||||
} else {
|
||||
newVersion = semver.inc(currentVersion, versionArg);
|
||||
|
||||
if (!newVersion) {
|
||||
throw createError('Invalid <version> argument: ' + versionArg, 'EINVALIDVERSION', { version: versionArg });
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}, function () {
|
||||
//Ignore not found .git directory
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function checkGitStatus(cwd) {
|
||||
return Q.nfcall(which, 'git')
|
||||
.fail(function (err) {
|
||||
err.code = 'ENOGIT';
|
||||
throw err;
|
||||
})
|
||||
.then(function () {
|
||||
return Q.nfcall(execFile, 'git', ['status', '--porcelain'], {env: process.env, cwd: cwd});
|
||||
})
|
||||
.then(function (value) {
|
||||
var stdout = value[0];
|
||||
var lines = filterModifiedStatusLines(stdout);
|
||||
if (lines.length) {
|
||||
throw createError('Git working directory not clean.\n' + lines.join('\n'), 'EWORKINGDIRECTORYDIRTY');
|
||||
newVersion = (currentVersion[0] === 'v') ? 'v' + newVersion : newVersion;
|
||||
|
||||
if (versions) {
|
||||
versions.forEach(function (version) {
|
||||
if (semver.eq(version, newVersion)) {
|
||||
throw createError('Version exists: ' + newVersion, 'EVERSIONEXISTS', { versions: versions, newVersion: newVersion });
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function filterModifiedStatusLines(stdout) {
|
||||
return stdout.trim().split('\n')
|
||||
.filter(function (line) {
|
||||
return line.trim() && !line.match(/^\?\? /);
|
||||
}).map(function (line) {
|
||||
return line.trim();
|
||||
});
|
||||
}
|
||||
|
||||
function gitCommitAndTag(cwd, newVersion, message) {
|
||||
var tag = 'v' + newVersion;
|
||||
message = message || tag;
|
||||
message = message.replace(/%s/g, newVersion);
|
||||
return Q.nfcall(execFile, 'git', ['add', 'bower.json'], {env: process.env, cwd: cwd})
|
||||
.then(function () {
|
||||
return Q.nfcall(execFile, 'git', ['commit', '-m', message], {env: process.env, cwd: cwd});
|
||||
return driver.bump(cwd, newVersion, message).then(function () {
|
||||
return {
|
||||
oldVersion: currentVersion,
|
||||
newVersion: newVersion
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
return Q.nfcall(execFile, 'git', ['tag', tag, '-am', message], {env: process.env, cwd: cwd});
|
||||
.then(function (result) {
|
||||
logger.info('version', 'Bumped package version from ' + result.oldVersion + ' to ' + result.newVersion, result);
|
||||
|
||||
return result.newVersion;
|
||||
});
|
||||
}
|
||||
|
||||
// -------------------
|
||||
var driver = {
|
||||
check: function (cwd) {
|
||||
function checkGit(cwd) {
|
||||
var gitDir = path.join(cwd, '.git');
|
||||
return Q.nfcall(fs.stat, gitDir)
|
||||
.then(function (stat) {
|
||||
if (stat.isDirectory()) {
|
||||
return checkGitStatus(cwd);
|
||||
}
|
||||
return false;
|
||||
}, function () {
|
||||
//Ignore not found .git directory
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function checkGitStatus(cwd) {
|
||||
return Q.nfcall(which, 'git')
|
||||
.fail(function (err) {
|
||||
err.code = 'ENOGIT';
|
||||
throw err;
|
||||
})
|
||||
.then(function () {
|
||||
return Q.nfcall(execFile, 'git', ['status', '--porcelain'], {env: process.env, cwd: cwd});
|
||||
})
|
||||
.then(function (value) {
|
||||
var stdout = value[0];
|
||||
var lines = filterModifiedStatusLines(stdout);
|
||||
if (lines.length) {
|
||||
throw createError('Version bump requires clean working directory', 'EWORKINGDIRECTORYDIRTY');
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function filterModifiedStatusLines(stdout) {
|
||||
return stdout.trim().split('\n')
|
||||
.filter(function (line) {
|
||||
return line.trim() && !line.match(/^\?\? /);
|
||||
}).map(function (line) {
|
||||
return line.trim();
|
||||
});
|
||||
}
|
||||
|
||||
return checkGit(cwd).then(function (hasGit) {
|
||||
if (!hasGit) {
|
||||
throw createError('Version bump currently supports only git repositories', 'ENOTGITREPOSITORY');
|
||||
}
|
||||
});
|
||||
},
|
||||
versions: function (cwd) {
|
||||
return Q.nfcall(execFile, 'git', ['tag'], {env: process.env, cwd: cwd})
|
||||
.then(function (res) {
|
||||
var versions = res[0]
|
||||
.split(/\r?\n/)
|
||||
.filter(semver.valid);
|
||||
|
||||
return versions;
|
||||
}, function () {
|
||||
return [];
|
||||
});
|
||||
},
|
||||
currentVersion: function (cwd) {
|
||||
return Q.nfcall(execFile, 'git', ['describe', '--abbrev=0', '--tags'], {env: process.env, cwd: cwd})
|
||||
.then(function (res) {
|
||||
var version = res[0]
|
||||
.split(/\r?\n/)
|
||||
.filter(semver.valid)[0];
|
||||
|
||||
return version;
|
||||
}, function () {
|
||||
return undefined;
|
||||
});
|
||||
},
|
||||
bump: function (cwd, tag, message) {
|
||||
message = message || tag;
|
||||
message = message.replace(/%s/g, tag);
|
||||
return Q.nfcall(execFile, 'git', ['commit', '-m', message, '--allow-empty'], {env: process.env, cwd: cwd}) .then(function () {
|
||||
return Q.nfcall(execFile, 'git', ['tag', tag, '-am', message], {env: process.env, cwd: cwd});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
version.readOptions = function (argv) {
|
||||
var cli = require('../util/cli');
|
||||
|
||||
@@ -678,6 +678,8 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
|
||||
var save;
|
||||
var choices;
|
||||
var picks = [];
|
||||
var versionRegex = /(?:[\d\w]\.){2}[\d\w](?:.)*/;
|
||||
var picksReleases;
|
||||
|
||||
// If there are both semver and non-semver, there's no way
|
||||
// to figure out the suitable one
|
||||
@@ -833,14 +835,21 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
|
||||
});
|
||||
|
||||
choices = picks.map(function (pick, index) { return index + 1; });
|
||||
picksReleases = picks.map(function (pick) { return pick.pkgMeta._release; });
|
||||
return Q.nfcall(this._logger.prompt.bind(this._logger), {
|
||||
type: 'input',
|
||||
message: 'Answer',
|
||||
validate: function (choice) {
|
||||
var invalidChoice = 'Invalid choice';
|
||||
|
||||
if (choice.match(versionRegex)) {
|
||||
return picksReleases.indexOf(choice) != -1 ? true : invalidChoice;
|
||||
}
|
||||
|
||||
choice = Number(mout.string.trim(choice.trim(), '!'));
|
||||
|
||||
if (!choice || choice < 1 || choice > picks.length) {
|
||||
return 'Invalid choice';
|
||||
return invalidChoice;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -852,8 +861,13 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
|
||||
// Sanitize choice
|
||||
choice = choice.trim();
|
||||
save = /^!/.test(choice) || /!$/.test(choice); // Save if prefixed or suffixed with !
|
||||
choice = Number(mout.string.trim(choice, '!'));
|
||||
pick = picks[choice - 1];
|
||||
|
||||
if (choice.match(versionRegex)) {
|
||||
pick = picks[picksReleases.indexOf(choice)];
|
||||
} else {
|
||||
choice = Number(mout.string.trim(choice, '!'));
|
||||
pick = picks[choice - 1];
|
||||
}
|
||||
|
||||
// Save resolution
|
||||
if (save) {
|
||||
|
||||
@@ -213,6 +213,20 @@ Project.prototype.update = function (names, options) {
|
||||
});
|
||||
};
|
||||
|
||||
function resolveUrlNames(names, flattened)
|
||||
{
|
||||
for (var i = 0; i < names.length; i++)
|
||||
if (! flattened[names[i]])
|
||||
{
|
||||
var url = names[i].trim().replace(/\/$/, '');
|
||||
var packName;
|
||||
for (packName in flattened)
|
||||
if (! ( !flattened[packName].source))
|
||||
if (url == flattened[packName].source.trim().replace(/\/$/, ''))
|
||||
names[i] = packName;
|
||||
}
|
||||
}
|
||||
|
||||
Project.prototype.uninstall = function (names, options) {
|
||||
var that = this;
|
||||
var packages = {};
|
||||
@@ -230,6 +244,7 @@ Project.prototype.uninstall = function (names, options) {
|
||||
// Fill in the packages to be uninstalled
|
||||
.spread(function (json, tree, flattened) {
|
||||
var promise = Q.resolve();
|
||||
resolveUrlNames(names, flattened);
|
||||
|
||||
names.forEach(function (name) {
|
||||
var decEndpoint = flattened[name];
|
||||
@@ -764,6 +779,9 @@ Project.prototype._removePackages = function (packages) {
|
||||
.then(function () {
|
||||
return that.saveJson();
|
||||
})
|
||||
// Run post-uninstall hook before resolving with removed packages.
|
||||
.then(scripts.postuninstall.bind(
|
||||
null, that._config, that._logger, packages, that._installed, that._json))
|
||||
// Resolve with removed packages
|
||||
.then(function () {
|
||||
return mout.object.filter(packages, function (dir) {
|
||||
|
||||
@@ -29,9 +29,6 @@ function GitHubResolver(decEndpoint, config, logger) {
|
||||
this._source += '.git';
|
||||
}
|
||||
|
||||
// Check if it's public
|
||||
this._public = mout.string.startsWith(this._source, 'git://');
|
||||
|
||||
// Use https:// rather than git:// if on a proxy
|
||||
if (this._config.proxy || this._config.httpsProxy) {
|
||||
this._source = this._source.replace('git://', 'https://');
|
||||
@@ -49,14 +46,10 @@ mout.object.mixIn(GitHubResolver, GitRemoteResolver);
|
||||
// -----------------
|
||||
|
||||
GitHubResolver.prototype._checkout = function () {
|
||||
// Only fully works with public repositories and tags
|
||||
// Could work with https/ssh protocol but not with 100% certainty
|
||||
if (!this._public || !this._resolution.tag) {
|
||||
return GitRemoteResolver.prototype._checkout.call(this);
|
||||
}
|
||||
|
||||
var msg;
|
||||
var tarballUrl = 'https://github.com/' + this._org + '/' + this._repo + '/archive/' + this._resolution.tag + '.tar.gz';
|
||||
var name = this._resolution.tag || this._resolution.branch || this._resolution.commit;
|
||||
var tarballUrl = 'https://github.com/' + this._org + '/' + this._repo + '/archive/' + name + '.tar.gz';
|
||||
|
||||
var file = path.join(this._tempDir, 'archive.tar.gz');
|
||||
var reqHeaders = {};
|
||||
var that = this;
|
||||
@@ -121,7 +114,6 @@ GitHubResolver.prototype._checkout = function () {
|
||||
|
||||
return that._cleanTempDir()
|
||||
.then(GitRemoteResolver.prototype._checkout.bind(that));
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -26,8 +26,18 @@ function GitResolver(decEndpoint, config, logger) {
|
||||
// anyway
|
||||
mkdirp.sync(config.storage.empty);
|
||||
process.env.GIT_TEMPLATE_DIR = config.storage.empty;
|
||||
process.env.GIT_SSL_NO_VERIFY = (!config.strictSsl).toString();
|
||||
process.env.GIT_TERMINAL_PROMPT = config.interactive ? '1' : '0';
|
||||
|
||||
if (!config.strictSsl) {
|
||||
process.env.GIT_SSL_NO_VERIFY = 'true';
|
||||
}
|
||||
|
||||
if (!config.interactive) {
|
||||
process.env.GIT_TERMINAL_PROMPT = '0';
|
||||
|
||||
if (!process.env.SSH_ASKPASS) {
|
||||
process.env.SSH_ASKPASS = 'echo';
|
||||
}
|
||||
}
|
||||
|
||||
Resolver.call(this, decEndpoint, config, logger);
|
||||
|
||||
@@ -206,7 +216,7 @@ GitResolver.prototype._savePkgMeta = function (meta) {
|
||||
version = semver.clean(this._resolution.tag);
|
||||
|
||||
// Warn if the package meta version is different than the resolved one
|
||||
if (typeof meta.version === 'string' && semver.neq(meta.version, version)) {
|
||||
if (typeof meta.version === 'string' && semver.valid(meta.version) && semver.neq(meta.version, version)) {
|
||||
this._logger.warn('mismatch', 'Version declared in the json (' + meta.version + ') is different than the resolved one (' + version + ')', {
|
||||
resolution: this._resolution,
|
||||
pkgMeta: meta
|
||||
|
||||
@@ -109,7 +109,7 @@ function pluginResolverFactory(resolverFactory, bower) {
|
||||
throw createError('Resolver did not provide releases of package.');
|
||||
}
|
||||
|
||||
var releases = this._releases = result;
|
||||
var releases = that._releases = result;
|
||||
|
||||
var versions = releases.filter(function (target) {
|
||||
return semver.clean(target.version);
|
||||
|
||||
@@ -89,6 +89,7 @@ var hook = function (action, ordered, config, logger, packages, installed, json)
|
||||
|
||||
module.exports = {
|
||||
preuninstall: mout.function.partial(hook, 'preuninstall', false),
|
||||
postuninstall: mout.function.partial(hook, 'postuninstall', false),
|
||||
preinstall: mout.function.partial(hook, 'preinstall', true),
|
||||
postinstall: mout.function.partial(hook, 'postinstall', true),
|
||||
//only exposed for test
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"command": "lookup",
|
||||
"description": "Looks up a package URL by name.",
|
||||
"description": "Look up a single package URL by name.",
|
||||
"usage": [
|
||||
"lookup <name> [<options>]"
|
||||
],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"command": "search",
|
||||
"description": "Finds all packages or a specific package.",
|
||||
"description": "Search for packages by name.",
|
||||
"usage": [
|
||||
"search <name> [<options>]"
|
||||
],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"command": "version",
|
||||
"description": "Run this in a package directory to bump the version and write the new data back to the bower.json file.\n\nThe newversion argument should be a valid semver string, or a valid second argument to semver.inc (one of \"build\", \"patch\", \"minor\", or \"major\"). In the second case, the existing version will be incremented\nby 1 in the specified field.\n\nIf run in a git repo, it will also create a version commit and tag, and fail if the repo is not clean.\n\nIf supplied with --message (shorthand: -m) config option, bower will use it as a commit message when creating a version commit. If the message config contains %s then that will be replaced with the resulting\nversion number. For example:\n\n bower version patch -m \"Upgrade to %s for reasons\"",
|
||||
"description": "Creates an empty version commit and tag, and fail if the repo is not clean.\n\nThe <version> argument should be a valid semver string, or one of following:\nbuild, patch, minor, major.\n\nIf supplied with --message (shorthand: -m) config option, bower will use it\nas a commit message when creating a version commit. If the message config\ncontains %s then that will be replaced with the resulting version number.\n\nFor example:\n\n bower version patch -m \"Upgrade to %s for reasons\"",
|
||||
"usage": [
|
||||
"version [<newversion> | major | minor | patch]"
|
||||
"version [<version> | major | minor | patch]"
|
||||
],
|
||||
"options": [
|
||||
{
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
"link": "Symlink a package folder",
|
||||
"list": "List local packages - and possible updates",
|
||||
"login": "Authenticate with GitHub and store credentials",
|
||||
"lookup": "Look up a package URL by name",
|
||||
"lookup": "Look up a single package URL by name",
|
||||
"prune": "Removes local extraneous packages",
|
||||
"register": "Register a package",
|
||||
"search": "Search for a package by name",
|
||||
"search": "Search for packages by name",
|
||||
"update": "Update a local package",
|
||||
"uninstall": "Remove a local package",
|
||||
"unregister": "Remove a package from the registry",
|
||||
|
||||
@@ -11,7 +11,7 @@ Commands:
|
||||
|
||||
{{#condense}}
|
||||
{{#each commands}}
|
||||
{{#rpad length="23"}}{{@key}}{{/rpad}} {{.}}
|
||||
{{#rpad minLength="23"}}{{@key}}{{/rpad}} {{.}}
|
||||
{{/each}}
|
||||
{{/condense}}
|
||||
|
||||
{{#rpad minLength="23"}}{{/rpad}}
|
||||
|
||||
@@ -19,7 +19,9 @@ function readJson(file, options) {
|
||||
|
||||
if (options.logger) {
|
||||
var issues = bowerJson.getIssues(json);
|
||||
|
||||
if (issues.warnings.length > 0){
|
||||
options.logger.warn('invalid-meta', 'for:' + jsonFile);
|
||||
}
|
||||
issues.warnings.forEach(function (warning) {
|
||||
options.logger.warn('invalid-meta', warning);
|
||||
});
|
||||
|
||||
26
package.json
26
package.json
@@ -17,7 +17,7 @@
|
||||
"dependencies": {
|
||||
"abbrev": "^1.0.5",
|
||||
"archy": "1.0.0",
|
||||
"bower-config": "^1.3.1",
|
||||
"bower-config": "^1.4.0",
|
||||
"bower-endpoint-parser": "^0.2.2",
|
||||
"bower-json": "^0.8.1",
|
||||
"bower-logger": "^0.2.2",
|
||||
@@ -67,24 +67,24 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"arr-diff": "^2.0.0",
|
||||
"chai": "^1.10.0",
|
||||
"coveralls": "^2.11.2",
|
||||
"chai": "^3.5.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"expect.js": "^0.3.1",
|
||||
"grunt": "1.0.0-rc1",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-cli": "^1.1.0",
|
||||
"grunt-contrib-watch": "^1.0.0",
|
||||
"grunt-eslint": "^18.0.0",
|
||||
"grunt-exec": "sheerun/grunt-exec",
|
||||
"grunt-eslint": "^18.1.0",
|
||||
"grunt-exec": "^0.4.7",
|
||||
"grunt-simple-mocha": "^0.4.1",
|
||||
"in-publish": "^2.0.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"load-grunt-tasks": "^2.0.0",
|
||||
"mocha": "^2.1.0",
|
||||
"istanbul": "^0.4.3",
|
||||
"load-grunt-tasks": "^3.5.0",
|
||||
"mocha": "^2.5.3",
|
||||
"multiline": "^1.0.2",
|
||||
"nock": "^3.1.0",
|
||||
"node-uuid": "^1.4.2",
|
||||
"proxyquire": "^1.3.0",
|
||||
"spawn-sync": "1.0.13",
|
||||
"nock": "^7.7.2",
|
||||
"node-uuid": "^1.4.7",
|
||||
"proxyquire": "^1.7.9",
|
||||
"spawn-sync": "1.0.15",
|
||||
"wrench": "^1.5.8"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
12
packages/bower-config/.editorconfig
Normal file
12
packages/bower-config/.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
7
packages/bower-config/.gitignore
vendored
Normal file
7
packages/bower-config/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
|
||||
test/assets/github-test-package
|
||||
test/assets/github-test-package-copy
|
||||
test/assets/temp
|
||||
test/reports
|
||||
61
packages/bower-config/.jshintrc
Normal file
61
packages/bower-config/.jshintrc
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"describe",
|
||||
"it",
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach"
|
||||
],
|
||||
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"trailing": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"es5": false,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": false,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"white": true
|
||||
}
|
||||
9
packages/bower-config/.travis.yml
Normal file
9
packages/bower-config/.travis.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- '5'
|
||||
- '4'
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
script:
|
||||
- grunt travis
|
||||
103
packages/bower-config/CHANGELOG.md
Normal file
103
packages/bower-config/CHANGELOG.md
Normal file
@@ -0,0 +1,103 @@
|
||||
# Changelog
|
||||
|
||||
## 1.4.0
|
||||
|
||||
- Change default shorthand resolver from git:// to https://
|
||||
|
||||
## 1.3.1
|
||||
|
||||
- Ignore hook scripts for environment variable expansion
|
||||
|
||||
## 1.3.0 - 2015-12-07
|
||||
|
||||
- Allow the use of environment variables in .bowerrc. Fixes [#41](https://github.com/bower/config/issues/41)
|
||||
- Loads the .bowerrc file from the cwd specified on the command line. Fixes [bower/bower#1993](https://github.com/bower/bower/issues/1993)
|
||||
- Allwow for array notation in ENV variables [#44](https://github.com/bower/config/issues/44)
|
||||
|
||||
## 1.2.3 - 2015-11-27
|
||||
|
||||
- Restores env variables if they are undefined at the beginning
|
||||
- Handles default setting for config.ca. Together with [bower/bower PR #1972](https://github.com/bower/bower/pull/1972), fixes downloading with `strict-ssl` using custom CA
|
||||
- Displays an error message if .bowerrc is a directory instead of file. Fixes [bower/bower#2022](https://github.com/bower/bower/issues/2022)
|
||||
|
||||
## 1.2.2 - 2015-10-16
|
||||
- Fixes registry configurartion expanding [bower/bower#1950](https://github.com/bower/bower/issues/1950)
|
||||
|
||||
## 1.2.1 - 2015-10-15
|
||||
- Fixes case insenstivity HTTP_PROXY setting issue on Windows
|
||||
|
||||
## 1.2.0 - 2015-09-28
|
||||
- Prevent defaulting cwd to process.cwd()
|
||||
|
||||
## 1.1.2 - 2015-09-27
|
||||
- Performs only camel case normalisation before merging
|
||||
|
||||
## 1.1.1 - 2015-09-27
|
||||
- Fix: Merge extra options after camel-case normalisation, instead of before it
|
||||
|
||||
## 1.1.0 - 2015-09-27
|
||||
- Allow for overwriting options with .load(overwrites) / .read(cwd, overwrites)
|
||||
|
||||
## 1.0.1 - 2015-09-27
|
||||
- Update dependencies and relax "mout" version range
|
||||
- Most significant changes:
|
||||
- graceful-fs updated from 2.x version to 4.x
|
||||
- osenv updated to from 0.0.x to 0.1.x, [tmp location changed](https://github.com/npm/osenv/commit/d6eddbc026538b09026b1dbd60fbc081a8c67e03)
|
||||
|
||||
## 1.0.0 - 2015-09-27
|
||||
- Support for no-proxy configuration variable
|
||||
- Overwrite HTTP_PROXY, HTTPS_PROXY, and NO_PROXY env variables in load method
|
||||
- Normalise paths to certificates with contents of them, [#28](https://github.com/bower/config/pull/28)
|
||||
|
||||
## 0.6.1 - 2015-04-1
|
||||
- Fixes merging .bowerrc files upward directory tree. [#25](https://github.com/bower/config/issues/25)
|
||||
|
||||
## 0.6.0 - 2015-03-30
|
||||
- Merge .bowerrc files upward directory tree (fixes [bower/bower#1689](https://github.com/bower/bower/issues/1689)) [#24](https://github.com/bower/config/pull/24)
|
||||
- Allow NPM config variables (resolves [bower/bower#1711](https://github.com/bower/bower/issues/1711)) [#23](https://github.com/bower/config/pull/23)
|
||||
|
||||
## 0.5.2 - 2014-06-09
|
||||
- Fixes downloading of bower modules with ignores when .bowerrc is overridden with a relative tmp path. [#17](https://github.com/bower/config/issues/17) [bower/bower#1299](https://github.com/bower/bower/issues/1299)
|
||||
|
||||
## 0.5.1 - 2014-05-21
|
||||
- [perf] Uses the same mout version as bower
|
||||
- [perf] Uses only relevant parts of mout. Related [bower/bower#1134](https://github.com/bower/bower/pull/1134)
|
||||
|
||||
## 0.5.0 - 2013-08-30
|
||||
- Adds a DEFAULT_REGISTRY key to the Config class that exposes the bower registry UR. [#6](https://github.com/bower/config/issues/6)
|
||||
|
||||
## 0.4.5 - 2013-08-28
|
||||
- Fixes crashing when home is not set
|
||||
|
||||
## 0.4.4 - 2013-08-21
|
||||
- Supports nested environment variables [#8](https://github.com/bower/config/issues/8)
|
||||
|
||||
## 0.4.3 - 2013-08-19
|
||||
- Improvement in argv.config parsing
|
||||
|
||||
## 0.4.2 - 2013-08-18
|
||||
- Sets interative to auto
|
||||
|
||||
## 0.4.1 - 2013-08-18
|
||||
- Generates a fake user instead of using 'unknown'
|
||||
|
||||
## 0.4.0 - 2013-08-16
|
||||
- Suffixes temp folder with the user and 'bower'
|
||||
|
||||
## 0.3.5 - 2013-08-14
|
||||
- Casts buffer to string
|
||||
|
||||
## 0.3.4 - 2013-08-11
|
||||
- Empty .bowerrc files no longer throw an error.
|
||||
|
||||
## 0.3.3 - 2013-08-11
|
||||
- Changes git folder to empty (was not being used anyway)
|
||||
|
||||
## 0.3.2 - 2013-08-07
|
||||
- Uses a known user agent by default when a proxy.
|
||||
|
||||
## 0.3.1 - 2013-08-06
|
||||
- Fixes Typo
|
||||
|
||||
## 0.3.0 - 2013-08-06
|
||||
- Appends the username when using the temporary folder.
|
||||
53
packages/bower-config/Gruntfile.js
Normal file
53
packages/bower-config/Gruntfile.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
module.exports = function (grunt) {
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
grunt.initConfig({
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
},
|
||||
files: [
|
||||
'Gruntfile.js',
|
||||
'bin/*',
|
||||
'lib/**/*.js',
|
||||
'test/**/*.js',
|
||||
'!test/assets/**/*',
|
||||
'!test/reports/**/*',
|
||||
'!test/tmp/**/*'
|
||||
]
|
||||
},
|
||||
simplemocha: {
|
||||
options: {
|
||||
reporter: 'spec',
|
||||
timeout: '10000'
|
||||
},
|
||||
full: {
|
||||
src: ['test/test.js']
|
||||
},
|
||||
short: {
|
||||
options: {
|
||||
reporter: 'dot'
|
||||
},
|
||||
src: ['test/test.js']
|
||||
}
|
||||
},
|
||||
exec: {
|
||||
cover: {
|
||||
command: 'STRICT_REQUIRE=1 node node_modules/istanbul/lib/cli.js cover --dir ./test/reports node_modules/mocha/bin/_mocha -- --timeout 30000 -R dot test/test.js'
|
||||
},
|
||||
coveralls: {
|
||||
command: 'node node_modules/.bin/coveralls < test/reports/lcov.info'
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
files: ['<%= jshint.files %>'],
|
||||
tasks: ['jshint', 'simplemocha:short']
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['jshint', 'simplemocha:full']);
|
||||
grunt.registerTask('cover', 'exec:cover');
|
||||
grunt.registerTask('travis', ['jshint', 'exec:cover', 'exec:coveralls']);
|
||||
grunt.registerTask('default', 'test');
|
||||
};
|
||||
19
packages/bower-config/LICENSE
Normal file
19
packages/bower-config/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
76
packages/bower-config/README.md
Normal file
76
packages/bower-config/README.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# bower-config [](http://travis-ci.org/bower/config)[](https://coveralls.io/github/bower/config?branch=master)
|
||||
|
||||
> The Bower config (`.bowerrc`) reader and writer.
|
||||
|
||||
[Bower](http://bower.io/) can be configured using JSON in a `.bowerrc` file. For example:
|
||||
|
||||
{
|
||||
"directory": "app/components/",
|
||||
"timeout": 120000,
|
||||
"registry": {
|
||||
"search": [
|
||||
"http://localhost:8000",
|
||||
"https://bower.herokuapp.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
View the complete [.bowerrc specification](http://bower.io/docs/config/#bowerrc-specification) on the website for more details. Both the `bower.json` and `.bowerrc` specifications are maintained at [github.com/bower/spec](https://github.com/bower/spec).
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save bower-config
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
#### .load(overwrites)
|
||||
|
||||
Loads the bower configuration from the configuration files.
|
||||
|
||||
Configuration is overwritten (after camelcase normalisation) with `overwrites` argument.
|
||||
|
||||
This method overwrites following environment variables:
|
||||
|
||||
- `HTTP_PROXY` with `proxy` configuration variable
|
||||
- `HTTPS_PROXY` with `https-proxy` configuration variable
|
||||
- `NO_PROXY` with `no-proxy` configuration variable
|
||||
|
||||
It also clears `http_proxy`, `https_proxy`, and `no_proxy` environment variables.
|
||||
|
||||
To restore those variables you can use `restore` method.
|
||||
|
||||
#### restore()
|
||||
|
||||
Restores environment variables overwritten by `.load` method.
|
||||
|
||||
#### .toObject()
|
||||
|
||||
Returns a deep copy of the underlying configuration object.
|
||||
The returned configuration is normalised.
|
||||
The object keys will be camelCase.
|
||||
|
||||
|
||||
#### #create(cwd)
|
||||
|
||||
Obtains a instance where `cwd` is the current working directory (defaults to `process.cwd`);
|
||||
|
||||
```js
|
||||
var config = require('bower-config').create();
|
||||
// You can also specify a working directory
|
||||
var config2 = require('bower-config').create('./some/path');
|
||||
```
|
||||
|
||||
#### #read(cwd, overrides)
|
||||
|
||||
Alias for:
|
||||
|
||||
```js
|
||||
var configObject = (new Config(cwd)).load(overrides).toJson();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
109
packages/bower-config/lib/Config.js
Normal file
109
packages/bower-config/lib/Config.js
Normal file
@@ -0,0 +1,109 @@
|
||||
var lang = require('mout/lang');
|
||||
var object = require('mout/object');
|
||||
var rc = require('./util/rc');
|
||||
var expand = require('./util/expand');
|
||||
var EnvProxy = require('./util/proxy');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
function Config(cwd) {
|
||||
this._cwd = cwd;
|
||||
this._proxy = new EnvProxy();
|
||||
this._config = {};
|
||||
}
|
||||
|
||||
Config.prototype.load = function (overwrites) {
|
||||
this._config = rc('bower', this._cwd);
|
||||
|
||||
this._config = object.merge(
|
||||
expand(this._config || {}),
|
||||
expand(overwrites || {})
|
||||
);
|
||||
|
||||
this._config = normalise(this._config);
|
||||
|
||||
this._proxy.set(this._config);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Config.prototype.restore = function () {
|
||||
this._proxy.restore();
|
||||
};
|
||||
|
||||
function readCertFile(path) {
|
||||
path = path || '';
|
||||
|
||||
var sep = '-----END CERTIFICATE-----';
|
||||
|
||||
var certificates;
|
||||
|
||||
if (path.indexOf(sep) === -1) {
|
||||
certificates = fs.readFileSync(path, { encoding: 'utf8' });
|
||||
} else {
|
||||
certificates = path;
|
||||
}
|
||||
|
||||
return certificates.
|
||||
split(sep).
|
||||
filter(function(s) { return !s.match(/^\s*$/); }).
|
||||
map(function(s) { return s + sep; });
|
||||
}
|
||||
|
||||
function loadCAs(caConfig) {
|
||||
// If a ca file path has been specified, expand that here to the file's
|
||||
// contents. As a user can specify these individually, we must load them
|
||||
// one by one.
|
||||
for (var p in caConfig) {
|
||||
if (caConfig.hasOwnProperty(p)) {
|
||||
var prop = caConfig[p];
|
||||
if (Array.isArray(prop)) {
|
||||
caConfig[p] = prop.map(function(s) {
|
||||
return readCertFile(s);
|
||||
});
|
||||
} else if (prop) {
|
||||
caConfig[p] = readCertFile(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Config.prototype.toObject = function () {
|
||||
return lang.deepClone(this._config);
|
||||
};
|
||||
|
||||
Config.create = function (cwd) {
|
||||
return new Config(cwd);
|
||||
};
|
||||
|
||||
Config.read = function (cwd, overrides) {
|
||||
var config = Config.create(cwd);
|
||||
return config.load(overrides).toObject();
|
||||
};
|
||||
|
||||
function normalise(config) {
|
||||
config = expand(config);
|
||||
|
||||
// Some backwards compatible things..
|
||||
if (config.shorthandResolver) {
|
||||
config.shorthandResolver = config.shorthandResolver
|
||||
.replace(/\{\{\{/g, '{{')
|
||||
.replace(/\}\}\}/g, '}}');
|
||||
}
|
||||
|
||||
// Ensure that every registry endpoint does not end with /
|
||||
config.registry.search = config.registry.search.map(function (url) {
|
||||
return url.replace(/\/+$/, '');
|
||||
});
|
||||
config.registry.register = config.registry.register.replace(/\/+$/, '');
|
||||
config.registry.publish = config.registry.publish.replace(/\/+$/, '');
|
||||
config.tmp = path.resolve(config.tmp);
|
||||
|
||||
loadCAs(config.ca);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
Config.DEFAULT_REGISTRY = require('./util/defaults').registry;
|
||||
|
||||
module.exports = Config;
|
||||
45
packages/bower-config/lib/util/defaults.js
Normal file
45
packages/bower-config/lib/util/defaults.js
Normal file
@@ -0,0 +1,45 @@
|
||||
var path = require('path');
|
||||
var paths = require('./paths');
|
||||
|
||||
// Guess proxy defined in the env
|
||||
var proxy = process.env.HTTP_PROXY
|
||||
|| process.env.http_proxy
|
||||
|| null;
|
||||
|
||||
var httpsProxy = process.env.HTTPS_PROXY
|
||||
|| process.env.https_proxy
|
||||
|| proxy;
|
||||
|
||||
var noProxy = process.env.NO_PROXY
|
||||
|| process.env.no_proxy;
|
||||
|
||||
// Use a well known user agent (in this case, curl) when using a proxy,
|
||||
// to avoid potential filtering on many corporate proxies with blank or unknown agents
|
||||
var userAgent = !proxy && !httpsProxy
|
||||
? 'node/' + process.version + ' ' + process.platform + ' ' + process.arch
|
||||
: 'curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5';
|
||||
|
||||
var defaults = {
|
||||
'directory': 'bower_components',
|
||||
'registry': 'https://bower.herokuapp.com',
|
||||
'shorthand-resolver': 'https://github.com/{{owner}}/{{package}}.git',
|
||||
'tmp': paths.tmp,
|
||||
'proxy': proxy,
|
||||
'https-proxy': httpsProxy,
|
||||
'no-proxy': noProxy,
|
||||
'timeout': 30000,
|
||||
'ca': { search: [] },
|
||||
'strict-ssl': true,
|
||||
'user-agent': userAgent,
|
||||
'color': true,
|
||||
'interactive': null,
|
||||
'storage': {
|
||||
packages: path.join(paths.cache, 'packages'),
|
||||
links: path.join(paths.data, 'links'),
|
||||
completion: path.join(paths.data, 'completion'),
|
||||
registry: path.join(paths.cache, 'registry'),
|
||||
empty: path.join(paths.data, 'empty') // Empty dir, used in GIT_TEMPLATE_DIR among others
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = defaults;
|
||||
126
packages/bower-config/lib/util/expand.js
Normal file
126
packages/bower-config/lib/util/expand.js
Normal file
@@ -0,0 +1,126 @@
|
||||
var object = require('mout/object');
|
||||
var lang = require('mout/lang');
|
||||
var string = require('mout/string');
|
||||
|
||||
function camelCase(config) {
|
||||
var camelCased = {};
|
||||
|
||||
// Camel case
|
||||
object.forOwn(config, function (value, key) {
|
||||
// Ignore null values
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
key = string.camelCase(key.replace(/_/g, '-'));
|
||||
camelCased[key] = lang.isPlainObject(value) ? camelCase(value) : value;
|
||||
});
|
||||
|
||||
return camelCased;
|
||||
}
|
||||
|
||||
// Function to replace ${VAR} - style variables
|
||||
// with values set in the environment
|
||||
// This function expects to be passed a string
|
||||
function doEnvReplaceStr (f) {
|
||||
|
||||
// Un-tildify
|
||||
var untildify = require('untildify');
|
||||
f = untildify(f);
|
||||
|
||||
// replace any ${ENV} values with the appropriate environ.
|
||||
var envExpr = /(\\*)\$\{([^}]+)\}/g;
|
||||
return f.replace(envExpr, function (orig, esc, name) {
|
||||
esc = esc.length && esc.length % 2;
|
||||
if (esc) return orig;
|
||||
if (undefined === process.env[name]) {
|
||||
throw new Error('Environment variable used in .bowerrc is not defined: ' + orig);
|
||||
}
|
||||
|
||||
return process.env[name];
|
||||
});
|
||||
}
|
||||
|
||||
function envReplace(config) {
|
||||
var envReplaced = {};
|
||||
|
||||
object.forOwn(config, function (value, key) {
|
||||
|
||||
// Ignore null values
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore 'scripts'
|
||||
// These hooks run within the shell
|
||||
// environment variable expansion is not required
|
||||
if ( key === 'scripts' && lang.isPlainObject(value) ){
|
||||
envReplaced[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform variable replacements based on var type
|
||||
if ( lang.isPlainObject(value) ) {
|
||||
envReplaced[key] = envReplace(value);
|
||||
}
|
||||
else if ( lang.isString(value) ) {
|
||||
envReplaced[key] = doEnvReplaceStr(value);
|
||||
}
|
||||
else {
|
||||
envReplaced[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return envReplaced;
|
||||
}
|
||||
|
||||
function expand(config) {
|
||||
config = camelCase(config);
|
||||
config = envReplace(config);
|
||||
|
||||
if (typeof config.registry === 'string') {
|
||||
config.registry = {
|
||||
default: config.registry,
|
||||
search: [config.registry],
|
||||
register: config.registry,
|
||||
publish: config.registry
|
||||
};
|
||||
} else if (typeof config.registry === 'object') {
|
||||
config.registry.default = config.registry.default || 'https://bower.herokuapp.com';
|
||||
|
||||
config.registry = {
|
||||
default: config.registry.default,
|
||||
search: config.registry.search || config.registry.default,
|
||||
register: config.registry.register || config.registry.default,
|
||||
publish: config.registry.publish || config.registry.default
|
||||
};
|
||||
|
||||
if (config.registry.search && !Array.isArray(config.registry.search)) {
|
||||
config.registry.search = [config.registry.search];
|
||||
}
|
||||
}
|
||||
|
||||
// CA
|
||||
if (typeof config.ca === 'string') {
|
||||
config.ca = {
|
||||
default: config.ca,
|
||||
search: [config.ca],
|
||||
register: config.ca,
|
||||
publish: config.ca
|
||||
};
|
||||
} else if (typeof config.ca === 'object') {
|
||||
if (config.ca.search && !Array.isArray(config.ca.search)) {
|
||||
config.ca.search = [config.ca.search];
|
||||
}
|
||||
|
||||
if (config.ca.default) {
|
||||
config.ca.search = config.ca.search || config.ca.default;
|
||||
config.ca.register = config.ca.register || config.ca.default;
|
||||
config.ca.publish = config.ca.publish || config.ca.default;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
module.exports = expand;
|
||||
44
packages/bower-config/lib/util/paths.js
Normal file
44
packages/bower-config/lib/util/paths.js
Normal file
@@ -0,0 +1,44 @@
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
var osenv = require('osenv');
|
||||
var crypto = require('crypto');
|
||||
|
||||
function generateFakeUser() {
|
||||
var uid = process.pid + '-' + Date.now() + '-' + Math.floor(Math.random() * 1000000);
|
||||
return crypto.createHash('md5').update(uid).digest('hex');
|
||||
}
|
||||
|
||||
// Assume XDG defaults
|
||||
// See: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
var paths = {
|
||||
config: process.env.XDG_CONFIG_HOME,
|
||||
data: process.env.XDG_DATA_HOME,
|
||||
cache: process.env.XDG_CACHE_HOME
|
||||
};
|
||||
|
||||
// Guess some needed properties based on the user OS
|
||||
var user = (osenv.user() || generateFakeUser()).replace(/\\/g, '-');
|
||||
var tmp = path.join(os.tmpdir ? os.tmpdir() : os.tmpDir(), user);
|
||||
var home = osenv.home();
|
||||
var base;
|
||||
|
||||
// Fallbacks for windows
|
||||
if (process.platform === 'win32') {
|
||||
base = path.resolve(process.env.LOCALAPPDATA || home || tmp);
|
||||
base = path.join(base, 'bower');
|
||||
|
||||
paths.config = paths.config || path.join(base, 'config');
|
||||
paths.data = paths.data || path.join(base, 'data');
|
||||
paths.cache = paths.cache || path.join(base, 'cache');
|
||||
// Fallbacks for other operating systems
|
||||
} else {
|
||||
base = path.resolve(home || tmp);
|
||||
|
||||
paths.config = paths.config || path.join(base, '.config/bower');
|
||||
paths.data = paths.data || path.join(base, '.local/share/bower');
|
||||
paths.cache = paths.cache || path.join(base, '.cache/bower');
|
||||
}
|
||||
|
||||
paths.tmp = path.resolve(path.join(tmp, 'bower'));
|
||||
|
||||
module.exports = paths;
|
||||
79
packages/bower-config/lib/util/proxy.js
Normal file
79
packages/bower-config/lib/util/proxy.js
Normal file
@@ -0,0 +1,79 @@
|
||||
// EnvProxy uses the proxy vaiables passed to it in set and sets the
|
||||
// process.env uppercase proxy variables to them with the ability
|
||||
// to restore the original values later
|
||||
var EnvProxy = function() {
|
||||
this.restoreFrom = {};
|
||||
};
|
||||
|
||||
EnvProxy.prototype.set = function (config) {
|
||||
this.config = config;
|
||||
|
||||
// Override environment defaults if proxy config options are set
|
||||
// This will make requests.js follow the proxies in config
|
||||
if (Object.prototype.hasOwnProperty.call(config, 'noProxy')) {
|
||||
this.restoreFrom.NO_PROXY = process.env.NO_PROXY;
|
||||
this.restoreFrom.no_proxy = process.env.no_proxy;
|
||||
delete process.env.no_proxy;
|
||||
process.env.NO_PROXY = config.noProxy;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(config, 'proxy')) {
|
||||
this.restoreFrom.HTTP_PROXY = process.env.HTTP_PROXY;
|
||||
this.restoreFrom.http_proxy = process.env.http_proxy;
|
||||
delete process.env.http_proxy;
|
||||
process.env.HTTP_PROXY = config.proxy;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(config, 'httpsProxy')) {
|
||||
this.restoreFrom.HTTPS_PROXY = process.env.HTTPS_PROXY;
|
||||
this.restoreFrom.https_proxy = process.env.https_proxy;
|
||||
delete process.env.https_proxy;
|
||||
process.env.HTTPS_PROXY = config.httpsProxy;
|
||||
}
|
||||
};
|
||||
|
||||
EnvProxy.prototype.restore = function () {
|
||||
if (Object.prototype.hasOwnProperty.call(this.config, 'noProxy')) {
|
||||
if (this.restoreFrom.NO_PROXY !== undefined) {
|
||||
process.env.NO_PROXY = this.restoreFrom.NO_PROXY;
|
||||
} else {
|
||||
delete process.env.NO_PROXY;
|
||||
}
|
||||
|
||||
if (this.restoreFrom.no_proxy !== undefined) {
|
||||
process.env.no_proxy = this.restoreFrom.no_proxy;
|
||||
} else {
|
||||
delete process.env.no_proxy;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(this.config, 'proxy')) {
|
||||
if (this.restoreFrom.HTTP_PROXY !== undefined) {
|
||||
process.env.HTTP_PROXY = this.restoreFrom.HTTP_PROXY;
|
||||
} else {
|
||||
delete process.env.HTTP_PROXY;
|
||||
}
|
||||
|
||||
if (this.restoreFrom.http_proxy !== undefined) {
|
||||
process.env.http_proxy = this.restoreFrom.http_proxy;
|
||||
} else {
|
||||
delete process.env.http_proxy;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(this.config, 'httpsProxy')) {
|
||||
if (this.restoreFrom.HTTPS_PROXY !== undefined) {
|
||||
process.env.HTTPS_PROXY = this.restoreFrom.HTTPS_PROXY;
|
||||
} else {
|
||||
delete process.env.HTTPS_PROXY;
|
||||
}
|
||||
|
||||
if (this.restoreFrom.https_proxy !== undefined) {
|
||||
process.env.https_proxy = this.restoreFrom.https_proxy;
|
||||
} else {
|
||||
delete process.env.https_proxy;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = EnvProxy;
|
||||
158
packages/bower-config/lib/util/rc.js
Normal file
158
packages/bower-config/lib/util/rc.js
Normal file
@@ -0,0 +1,158 @@
|
||||
var path = require('path');
|
||||
var fs = require('graceful-fs');
|
||||
var optimist = require('optimist');
|
||||
var osenv = require('osenv');
|
||||
var object = require('mout/object');
|
||||
var string = require('mout/string');
|
||||
var paths = require('./paths');
|
||||
var defaults = require('./defaults');
|
||||
|
||||
var win = process.platform === 'win32';
|
||||
var home = osenv.home();
|
||||
|
||||
function rc(name, cwd, argv) {
|
||||
var argvConfig;
|
||||
|
||||
argv = argv || optimist.argv;
|
||||
|
||||
// Parse --config.foo=false
|
||||
argvConfig = object.map(argv.config || {}, function (value) {
|
||||
return value === 'false' ? false : value;
|
||||
});
|
||||
|
||||
// If we have specified a cwd then use this as the base for getting config.
|
||||
cwd = argvConfig.cwd ? argvConfig.cwd : cwd;
|
||||
|
||||
if (cwd) {
|
||||
return object.deepMixIn.apply(null, [
|
||||
{},
|
||||
defaults,
|
||||
{ cwd: cwd },
|
||||
win ? {} : json(path.join('/etc', name + 'rc')),
|
||||
!home ? {} : json(path.join(home, '.' + name + 'rc')),
|
||||
json(path.join(paths.config, name + 'rc')),
|
||||
json(find('.' + name + 'rc', cwd)),
|
||||
env('npm_package_config_' + name + '_'),
|
||||
env(name + '_'),
|
||||
argvConfig
|
||||
]);
|
||||
} else {
|
||||
return object.deepMixIn.apply(null, [
|
||||
{},
|
||||
defaults,
|
||||
win ? {} : json(path.join('/etc', name + 'rc')),
|
||||
!home ? {} : json(path.join(home, '.' + name + 'rc')),
|
||||
json(path.join(paths.config, name + 'rc')),
|
||||
env('npm_package_config_' + name + '_'),
|
||||
env(name + '_'),
|
||||
argvConfig
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
function parse(content, file) {
|
||||
var error;
|
||||
|
||||
if (!content.trim().length) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(content);
|
||||
} catch (e) {
|
||||
if (file) {
|
||||
error = new Error('Unable to parse ' + file + ': ' + e.message);
|
||||
} else {
|
||||
error = new Error('Unable to parse rc config: ' + e.message);
|
||||
}
|
||||
|
||||
error.details = content;
|
||||
error.code = 'EMALFORMED';
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function json(file) {
|
||||
var content = {};
|
||||
if (!Array.isArray(file)) {
|
||||
try {
|
||||
content = fs.readFileSync(file).toString();
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parse(content, file);
|
||||
} else {
|
||||
// This is multiple json files
|
||||
file.forEach(function(filename) {
|
||||
if (fs.statSync(filename).isDirectory()) {
|
||||
var error;
|
||||
error = new Error(filename + ' should not be a directory');
|
||||
error.code = 'EFILEISDIR';
|
||||
throw error;
|
||||
}
|
||||
var json = fs.readFileSync(filename).toString();
|
||||
json = parse(json, filename);
|
||||
content = object.merge(content, json);
|
||||
});
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
function env(prefix) {
|
||||
var obj = {};
|
||||
var prefixLength = prefix.length;
|
||||
|
||||
prefix = prefix.toLowerCase();
|
||||
|
||||
object.forOwn(process.env, function (value, key) {
|
||||
key = key.toLowerCase();
|
||||
|
||||
if (string.startsWith(key, prefix)) {
|
||||
var parsedKey = key
|
||||
.substr(prefixLength)
|
||||
.replace(/__/g, '.') // __ is used for nesting
|
||||
.replace(/_/g, '-'); // _ is used as a - separator
|
||||
|
||||
//use a convention patern to accept array from process.env
|
||||
//e.g. export bower_registry__search='["http://abc.com","http://def.com"]'
|
||||
var match = /\[([^\]]*)\]/g.exec(value);
|
||||
var targetValue;
|
||||
if (!match || match.length === 0) {
|
||||
targetValue = value;
|
||||
} else {
|
||||
targetValue = match[1].split(',')
|
||||
.map(function(m) {
|
||||
return m.trim();
|
||||
});
|
||||
}
|
||||
object.set(obj, parsedKey, targetValue);
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function find(filename, dir) {
|
||||
var files = [];
|
||||
|
||||
var walk = function (filename, dir) {
|
||||
var file = path.join(dir, filename);
|
||||
var parent = path.dirname(dir);
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
files.push(file);
|
||||
}
|
||||
|
||||
if (parent !== dir) {
|
||||
walk(filename, parent);
|
||||
}
|
||||
};
|
||||
|
||||
walk(filename, dir);
|
||||
files.reverse();
|
||||
return files;
|
||||
}
|
||||
|
||||
module.exports = rc;
|
||||
45
packages/bower-config/package.json
Normal file
45
packages/bower-config/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "bower-config",
|
||||
"version": "1.4.0",
|
||||
"description": "The Bower config reader and writer.",
|
||||
"author": "Twitter",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/bower/bower/tree/master/packages/bower-config",
|
||||
"main": "lib/Config",
|
||||
"homepage": "http://bower.io",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.1.3",
|
||||
"mout": "^1.0.0",
|
||||
"optimist": "^0.6.1",
|
||||
"osenv": "^0.1.3",
|
||||
"untildify": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.4",
|
||||
"expect.js": "^0.3.1",
|
||||
"glob": "^4.5.3",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-cli": "^0.1.13",
|
||||
"grunt-contrib-jshint": "^0.10.0",
|
||||
"grunt-contrib-watch": "^0.6.1",
|
||||
"grunt-coveralls": "^1.0.0",
|
||||
"grunt-exec": "^0.4.6",
|
||||
"grunt-simple-mocha": "^0.4.0",
|
||||
"istanbul": "^0.4.1",
|
||||
"load-grunt-tasks": "^2.0.0",
|
||||
"mkdirp": "^0.5.0",
|
||||
"mocha": "~1.12.0",
|
||||
"node-uuid": "^1.4.3",
|
||||
"q": "^1.2.0",
|
||||
"rimraf": "^2.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ca": "Equifax Secure CA\n=================\n-----BEGIN CERTIFICATE-----\nMIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJVUzEQMA4GA1UE\nChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5\nMB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoT\nB0VxdWlmYXgxLTArBgNVBAsTJEVxdWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCB\nnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPR\nfM6fBeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+AcJkVV5MW\n8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kCAwEAAaOCAQkwggEFMHAG\nA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UE\nCxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoG\nA1UdEAQTMBGBDzIwMTgwODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS\nspXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB\nAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961\nzgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB\nBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95\n70+sB3c4\n-----END CERTIFICATE-----\n\nGlobalSign Root CA\n==================\n-----BEGIN CERTIFICATE-----\nMIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCQkUx\nGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jvb3QgQ0ExGzAZBgNVBAMTEkds\nb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAwMDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNV\nBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYD\nVQQDExJHbG9iYWxTaWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDa\nDuaZjc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavpxy0Sy6sc\nTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp1Wrjsok6Vjk4bwY8iGlb\nKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdGsnUOhugZitVtbNV4FpWi6cgKOOvyJBNP\nc1STE4U6G7weNLWLBYy5d4ux2x8gkasJU26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrX\ngzT/LCrBbBlDSgeF59N89iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV\nHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0BAQUF\nAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOzyj1hTdNGCbM+w6Dj\nY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE38NflNUVyRRBnMRddWQVDf9VMOyG\nj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymPAbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhH\nhm4qxFYxldBniYUr+WymXUadDKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveC\nX4XSQRjbgbMEHMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\n-----END CERTIFICATE-----"
|
||||
}
|
||||
3
packages/bower-config/test/assets/custom-ca/.bowerrc
Normal file
3
packages/bower-config/test/assets/custom-ca/.bowerrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ca": "test/assets/custom-ca/ca-bundle.crt"
|
||||
}
|
||||
40
packages/bower-config/test/assets/custom-ca/ca-bundle.crt
Normal file
40
packages/bower-config/test/assets/custom-ca/ca-bundle.crt
Normal file
@@ -0,0 +1,40 @@
|
||||
Equifax Secure CA
|
||||
=================
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJVUzEQMA4GA1UE
|
||||
ChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5
|
||||
MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoT
|
||||
B0VxdWlmYXgxLTArBgNVBAsTJEVxdWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCB
|
||||
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPR
|
||||
fM6fBeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+AcJkVV5MW
|
||||
8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kCAwEAAaOCAQkwggEFMHAG
|
||||
A1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UE
|
||||
CxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoG
|
||||
A1UdEAQTMBGBDzIwMTgwODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS
|
||||
spXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB
|
||||
Af8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961
|
||||
zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
|
||||
BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
|
||||
70+sB3c4
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
GlobalSign Root CA
|
||||
==================
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCQkUx
|
||||
GTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jvb3QgQ0ExGzAZBgNVBAMTEkds
|
||||
b2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAwMDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNV
|
||||
BAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYD
|
||||
VQQDExJHbG9iYWxTaWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDa
|
||||
DuaZjc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavpxy0Sy6sc
|
||||
THAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp1Wrjsok6Vjk4bwY8iGlb
|
||||
Kk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdGsnUOhugZitVtbNV4FpWi6cgKOOvyJBNP
|
||||
c1STE4U6G7weNLWLBYy5d4ux2x8gkasJU26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrX
|
||||
gzT/LCrBbBlDSgeF59N89iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
|
||||
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0BAQUF
|
||||
AAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOzyj1hTdNGCbM+w6Dj
|
||||
Y1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE38NflNUVyRRBnMRddWQVDf9VMOyG
|
||||
j/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymPAbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhH
|
||||
hm4qxFYxldBniYUr+WymXUadDKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveC
|
||||
X4XSQRjbgbMEHMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"scripts" : {
|
||||
"postinstall" : "${_myshellvar}"
|
||||
},
|
||||
"storage" : {
|
||||
"packages" : "${_BOWERRC_MY_PACKAGES}",
|
||||
"registry" : "~/.bower-test/registry"
|
||||
},
|
||||
"tmp" : "${_BOWERRC_MY_TMP}"
|
||||
}
|
||||
5
packages/bower-config/test/assets/env-variables/.bowerrc
Normal file
5
packages/bower-config/test/assets/env-variables/.bowerrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"proxy": "http://HTTP_PROXY",
|
||||
"https-proxy": "http://HTTPS_PROXY",
|
||||
"no-proxy": "google.com"
|
||||
}
|
||||
126
packages/bower-config/test/helpers.js
Normal file
126
packages/bower-config/test/helpers.js
Normal file
@@ -0,0 +1,126 @@
|
||||
var Q = require('q');
|
||||
var mkdirp = require('mkdirp');
|
||||
var rimraf = require('rimraf');
|
||||
var uuid = require('node-uuid');
|
||||
var object = require('mout/object');
|
||||
var fs = require('fs');
|
||||
var glob = require('glob');
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
// For better promise errors
|
||||
Q.longStackSupport = true;
|
||||
|
||||
var tmpLocation = path.join(
|
||||
os.tmpdir ? os.tmpdir() : os.tmpDir(),
|
||||
'bower-config-tests',
|
||||
uuid.v4().slice(0, 8)
|
||||
);
|
||||
|
||||
after(function () {
|
||||
rimraf.sync(tmpLocation);
|
||||
});
|
||||
|
||||
exports.TempDir = (function() {
|
||||
function TempDir (defaults) {
|
||||
this.path = path.join(tmpLocation, uuid.v4());
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
TempDir.prototype.create = function (files, defaults) {
|
||||
var that = this;
|
||||
|
||||
defaults = defaults || this.defaults || {};
|
||||
files = object.merge(files || {}, defaults);
|
||||
|
||||
this.meta = function(tag) {
|
||||
if (tag) {
|
||||
return files[tag]['bower.json'];
|
||||
} else {
|
||||
return files['bower.json'];
|
||||
}
|
||||
};
|
||||
|
||||
if (files) {
|
||||
object.forOwn(files, function (contents, filepath) {
|
||||
if (typeof contents === 'object') {
|
||||
contents = JSON.stringify(contents, null, ' ') + '\n';
|
||||
}
|
||||
|
||||
var fullPath = path.join(that.path, filepath);
|
||||
mkdirp.sync(path.dirname(fullPath));
|
||||
fs.writeFileSync(fullPath, contents);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
TempDir.prototype.prepare = function (files) {
|
||||
rimraf.sync(this.path);
|
||||
mkdirp.sync(this.path);
|
||||
this.create(files);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// TODO: Rewrite to synchronous form
|
||||
TempDir.prototype.prepareGit = function (revisions) {
|
||||
var that = this;
|
||||
|
||||
revisions = object.merge(revisions || {}, this.defaults);
|
||||
|
||||
rimraf.sync(that.path);
|
||||
|
||||
mkdirp.sync(that.path);
|
||||
|
||||
var promise = new Q();
|
||||
|
||||
object.forOwn(revisions, function (files, tag) {
|
||||
promise = promise.then(function () {
|
||||
return that.git('init');
|
||||
}).then(function () {
|
||||
that.glob('./!(.git)').map(function (removePath) {
|
||||
var fullPath = path.join(that.path, removePath);
|
||||
|
||||
rimraf.sync(fullPath);
|
||||
});
|
||||
|
||||
that.create(files, {});
|
||||
}).then(function () {
|
||||
return that.git('add', '-A');
|
||||
}).then(function () {
|
||||
return that.git('commit', '-m"commit"');
|
||||
}).then(function () {
|
||||
return that.git('tag', tag);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
TempDir.prototype.glob = function (pattern) {
|
||||
return glob.sync(pattern, {
|
||||
cwd: this.path,
|
||||
dot: true
|
||||
});
|
||||
};
|
||||
|
||||
TempDir.prototype.getPath = function (name) {
|
||||
return path.join(this.path, name);
|
||||
};
|
||||
|
||||
TempDir.prototype.read = function (name) {
|
||||
return fs.readFileSync(this.getPath(name), 'utf8');
|
||||
};
|
||||
|
||||
TempDir.prototype.readJson = function (name) {
|
||||
return JSON.parse(this.read(name));
|
||||
};
|
||||
|
||||
TempDir.prototype.exists = function (name) {
|
||||
return fs.existsSync(path.join(this.path, name));
|
||||
};
|
||||
|
||||
return TempDir;
|
||||
})();
|
||||
245
packages/bower-config/test/test.js
Normal file
245
packages/bower-config/test/test.js
Normal file
@@ -0,0 +1,245 @@
|
||||
var assert = require('assert');
|
||||
var path = require('path');
|
||||
|
||||
describe('NPM Config on package.json', function () {
|
||||
beforeEach(function () {
|
||||
delete process.env.npm_package_config_bower_directory;
|
||||
delete process.env.npm_package_config_bower_colors;
|
||||
delete process.env.npm_package_config_bower_resolvers;
|
||||
});
|
||||
|
||||
it('defaults registry entries to default registry', function () {
|
||||
var config = require('../lib/Config').read(null, {});
|
||||
|
||||
assert.deepEqual(config.registry, {
|
||||
'default': 'https://bower.herokuapp.com',
|
||||
'search': [
|
||||
'https://bower.herokuapp.com'
|
||||
],
|
||||
'register': 'https://bower.herokuapp.com',
|
||||
'publish': 'https://bower.herokuapp.com'
|
||||
});
|
||||
});
|
||||
|
||||
it('can change default registry', function () {
|
||||
var config = require('../lib/Config').read(null, { registry: 'https://foobar' });
|
||||
|
||||
assert.deepEqual(config.registry, {
|
||||
'default': 'https://foobar',
|
||||
'search': [
|
||||
'https://foobar',
|
||||
],
|
||||
'register': 'https://foobar',
|
||||
'publish': 'https://foobar'
|
||||
});
|
||||
});
|
||||
|
||||
it('can override single entries in registry configuration', function () {
|
||||
var config = require('../lib/Config').read(null, { registry: { search: 'https://foobar' } });
|
||||
|
||||
assert.deepEqual(config.registry, {
|
||||
'default': 'https://bower.herokuapp.com',
|
||||
'search': [
|
||||
'https://foobar',
|
||||
],
|
||||
'register': 'https://bower.herokuapp.com',
|
||||
'publish': 'https://bower.herokuapp.com'
|
||||
});
|
||||
});
|
||||
|
||||
it('can override single entries in registry configuration and defaults', function () {
|
||||
var config = require('../lib/Config').read(null, { registry: { default: 'https://fizfuz', search: 'https://foobar' } });
|
||||
|
||||
assert.deepEqual(config.registry, {
|
||||
'default': 'https://fizfuz',
|
||||
'search': [
|
||||
'https://foobar',
|
||||
],
|
||||
'register': 'https://fizfuz',
|
||||
'publish': 'https://fizfuz'
|
||||
});
|
||||
});
|
||||
|
||||
it('allows for not providing cwd', function () {
|
||||
var config = require('../lib/Config').read();
|
||||
|
||||
config.tmp = '/foo/bar';
|
||||
config.userAgent = 'firefox';
|
||||
delete config.storage;
|
||||
|
||||
assert.deepEqual(config, {
|
||||
'directory': 'bower_components',
|
||||
'registry': {
|
||||
'default': 'https://bower.herokuapp.com',
|
||||
'search': [
|
||||
'https://bower.herokuapp.com'
|
||||
],
|
||||
'register': 'https://bower.herokuapp.com',
|
||||
'publish': 'https://bower.herokuapp.com'
|
||||
},
|
||||
'shorthandResolver': 'https://github.com/{{owner}}/{{package}}.git',
|
||||
'tmp': '/foo/bar',
|
||||
'timeout': 30000,
|
||||
'ca': {
|
||||
'search': []
|
||||
},
|
||||
'strictSsl': true,
|
||||
'userAgent': 'firefox',
|
||||
'color': true
|
||||
});
|
||||
});
|
||||
|
||||
function assertCAContents(caData, name) {
|
||||
var r = /-----BEGIN CERTIFICATE-----[a-zA-Z0-9+\/=\n\r]+-----END CERTIFICATE-----/;
|
||||
|
||||
assert(caData, name + ' should be set');
|
||||
assert(Array.isArray(caData), name + ' should be an array');
|
||||
assert.equal(2, caData.length);
|
||||
caData.forEach(function(c, i) {
|
||||
assert(c.match(r),
|
||||
name + '[' + i + '] should contain a certificate. Given: ' + JSON.stringify(c));
|
||||
});
|
||||
}
|
||||
|
||||
describe('Setting process.env.npm_package_config', function () {
|
||||
process.env.npm_package_config_bower_directory = 'npm-path';
|
||||
process.env.npm_package_config_bower_colors = 'false';
|
||||
process.env.npm_package_config_bower_resolvers = '[foo,bar,baz]';
|
||||
|
||||
var config = require('../lib/Config').read();
|
||||
|
||||
it('should return "npm-path" for "bower_directory"', function () {
|
||||
assert.equal('npm-path', config.directory);
|
||||
});
|
||||
it('should return "false" for "bower_colors"', function () {
|
||||
assert.equal('false', config.colors);
|
||||
});
|
||||
it('should expand array "false" for "bower_resolvers"', function () {
|
||||
assert.deepEqual(['foo', 'bar', 'baz'], config.resolvers);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Specifying custom CA', function() {
|
||||
|
||||
it('should read the CA file', function() {
|
||||
var config = require('../lib/Config')
|
||||
.read(path.resolve('test/assets/custom-ca'));
|
||||
|
||||
['register', 'publish', 'default'].forEach(function (p) {
|
||||
assertCAContents(config.ca[p], 'config.ca.' + p);
|
||||
});
|
||||
|
||||
assert(Array.isArray(config.ca.search),
|
||||
'ca property search should be an array');
|
||||
|
||||
config.ca.search.forEach(function(c, i) {
|
||||
assertCAContents(c, 'config.ca.search[' + i + ']');
|
||||
});
|
||||
});
|
||||
|
||||
it('should backward-support certificate inside .bowerrc', function() {
|
||||
var config = require('../lib/Config')
|
||||
.read(path.resolve('test/assets/custom-ca-embed'));
|
||||
|
||||
['register', 'publish', 'default'].forEach(function (p) {
|
||||
assertCAContents(config.ca[p], 'config.ca.' + p);
|
||||
});
|
||||
|
||||
assert(Array.isArray(config.ca.search),
|
||||
'ca property search should be an array');
|
||||
config.ca.search.forEach(function(c, i) {
|
||||
assertCAContents(c, 'config.ca.search[' + i + ']');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('setting ENV variables', function () {
|
||||
beforeEach(function () {
|
||||
delete process.env.no_proxy;
|
||||
delete process.env.http_proxy;
|
||||
delete process.env.https_proxy;
|
||||
delete process.env.NO_PROXY;
|
||||
delete process.env.HTTP_PROXY;
|
||||
delete process.env.HTTPS_PROXY;
|
||||
});
|
||||
|
||||
it('sets env variables', function () {
|
||||
require('../lib/Config').read('test/assets/env-variables');
|
||||
|
||||
assert.equal(process.env.HTTP_PROXY, 'http://HTTP_PROXY');
|
||||
assert.equal(process.env.HTTPS_PROXY, 'http://HTTPS_PROXY');
|
||||
assert.equal(process.env.NO_PROXY, 'google.com');
|
||||
|
||||
assert.equal(process.env.http_proxy, undefined);
|
||||
assert.equal(process.env.https_proxy, undefined);
|
||||
assert.equal(process.env.no_proxy, undefined);
|
||||
});
|
||||
|
||||
it('restores env variables', function () {
|
||||
process.env.HTTP_PROXY = 'a';
|
||||
process.env.HTTPS_PROXY = 'b';
|
||||
process.env.NO_PROXY = 'c';
|
||||
process.env.http_proxy = 'd';
|
||||
process.env.https_proxy = 'e';
|
||||
process.env.no_proxy = 'f';
|
||||
|
||||
var config = require('../lib/Config').create('test/assets/env-variables').load();
|
||||
config.restore();
|
||||
|
||||
assert.equal(process.env.HTTP_PROXY, 'a');
|
||||
assert.equal(process.env.HTTPS_PROXY, 'b');
|
||||
assert.equal(process.env.NO_PROXY, 'c');
|
||||
|
||||
assert.equal(process.env.http_proxy, 'd');
|
||||
assert.equal(process.env.https_proxy, 'e');
|
||||
assert.equal(process.env.no_proxy, 'f');
|
||||
});
|
||||
|
||||
it('restores env variables if they are undefined', function () {
|
||||
var config = require('../lib/Config').create('test/assets/env-variables').load();
|
||||
config.restore();
|
||||
|
||||
assert.equal(process.env.HTTP_PROXY, undefined);
|
||||
assert.equal(process.env.HTTPS_PROXY, undefined);
|
||||
assert.equal(process.env.NO_PROXY, undefined);
|
||||
|
||||
assert.equal(process.env.http_proxy, undefined);
|
||||
assert.equal(process.env.https_proxy, undefined);
|
||||
assert.equal(process.env.no_proxy, undefined);
|
||||
});
|
||||
|
||||
it('allows for overriding options', function () {
|
||||
require('../lib/Config').read('test/assets/env-variables', {
|
||||
httpsProxy: 'http://other-proxy.local'
|
||||
});
|
||||
|
||||
assert.equal(process.env.HTTP_PROXY, 'http://HTTP_PROXY');
|
||||
assert.equal(process.env.HTTPS_PROXY, 'http://other-proxy.local');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Allow ${ENV} variables in .bowerrc', function() {
|
||||
|
||||
it('sets values from process.env', function() {
|
||||
process.env._BOWERRC_MY_PACKAGES = 'a';
|
||||
process.env._BOWERRC_MY_TMP = '/tmp/b';
|
||||
|
||||
var config = require('../lib/Config').read('test/assets/env-variables-values');
|
||||
assert.equal('a', config.storage.packages);
|
||||
assert.equal('/tmp/b', config.tmp);
|
||||
assert.equal('${_myshellvar}', config.scripts.postinstall);
|
||||
});
|
||||
});
|
||||
|
||||
describe('untildify paths in .bowerrc', function() {
|
||||
|
||||
it('resolve ~/ in .bowerrc', function() {
|
||||
var config = require('../lib/Config').read('test/assets/env-variables-values');
|
||||
var untildify = require('untildify');
|
||||
|
||||
assert.equal(untildify('~/.bower-test/registry') , config.storage.registry);
|
||||
});
|
||||
});
|
||||
|
||||
require('./util/index');
|
||||
3
packages/bower-config/test/util/index.js
Normal file
3
packages/bower-config/test/util/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
describe('util', function () {
|
||||
require('./rc');
|
||||
});
|
||||
84
packages/bower-config/test/util/rc.js
Normal file
84
packages/bower-config/test/util/rc.js
Normal file
@@ -0,0 +1,84 @@
|
||||
var expect = require('expect.js');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
describe('rc', function() {
|
||||
var tempDir = new helpers.TempDir();
|
||||
var tempDirBowerrc = new helpers.TempDir();
|
||||
|
||||
var rc = require('../../lib/util/rc');
|
||||
|
||||
tempDir.prepare({
|
||||
'.bowerrc': {
|
||||
key: 'value'
|
||||
},
|
||||
'child/.bowerrc': {
|
||||
key2: 'value2'
|
||||
},
|
||||
'child2/.bowerrc': {
|
||||
key: 'valueShouldBeOverwriteParent'
|
||||
},
|
||||
'child3/bower.json': {
|
||||
name: 'without-bowerrc'
|
||||
},
|
||||
'other_dir/.bowerrc': {
|
||||
key: 'othervalue'
|
||||
}
|
||||
});
|
||||
|
||||
tempDirBowerrc.prepare({
|
||||
'.bowerrc/foo': {
|
||||
key: 'bar'
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('correctly reads .bowerrc files', function() {
|
||||
var config = rc('bower', tempDir.path);
|
||||
|
||||
expect(config.key).to.eql('value');
|
||||
expect(config.key2).to.eql(undefined);
|
||||
});
|
||||
|
||||
it('correctly reads .bowerrc files from child', function() {
|
||||
var config = rc('bower', tempDir.path + '/child/');
|
||||
|
||||
expect(config.key).to.eql('value');
|
||||
expect(config.key2).to.eql('value2');
|
||||
});
|
||||
|
||||
it('correctly reads .bowerrc files from child2', function() {
|
||||
var config = rc('bower', tempDir.path + '/child2/');
|
||||
|
||||
expect(config.key).to.eql('valueShouldBeOverwriteParent');
|
||||
expect(config.key2).to.eql(undefined);
|
||||
});
|
||||
|
||||
it('correctly reads .bowerrc files from child3', function() {
|
||||
var config = rc('bower', tempDir.path + '/child3/');
|
||||
|
||||
expect(config.key).to.eql('value');
|
||||
expect(config.key2).to.eql(undefined);
|
||||
});
|
||||
|
||||
it('loads the .bowerrc file from the cwd specified on the command line', function(){
|
||||
var argv = {
|
||||
'config': {
|
||||
'cwd': tempDir.path + '/other_dir/'
|
||||
}
|
||||
};
|
||||
|
||||
var config = rc('bower', tempDir.path, argv);
|
||||
|
||||
expect(config.key).to.eql('othervalue');
|
||||
|
||||
});
|
||||
|
||||
it('throws an easy to understand error if .bowerrc is a dir', function() {
|
||||
// Gotta wrap this to catch the error
|
||||
var config = function () {
|
||||
rc('bower', tempDirBowerrc.path);
|
||||
};
|
||||
|
||||
expect(config).to.throwError(/should not be a directory/);
|
||||
});
|
||||
});
|
||||
12
packages/bower-endpoint-parser/.editorconfig
Normal file
12
packages/bower-endpoint-parser/.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
2
packages/bower-endpoint-parser/.gitignore
vendored
Normal file
2
packages/bower-endpoint-parser/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/npm-debug.*
|
||||
61
packages/bower-endpoint-parser/.jshintrc
Normal file
61
packages/bower-endpoint-parser/.jshintrc
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"describe",
|
||||
"it",
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach"
|
||||
],
|
||||
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"trailing": true,
|
||||
"camelcase": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": true,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"white": true
|
||||
}
|
||||
4
packages/bower-endpoint-parser/.travis.yml
Normal file
4
packages/bower-endpoint-parser/.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
19
packages/bower-endpoint-parser/LICENSE
Normal file
19
packages/bower-endpoint-parser/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
102
packages/bower-endpoint-parser/README.md
Normal file
102
packages/bower-endpoint-parser/README.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# endpoint-parser [](http://travis-ci.org/bower/endpoint-parser)
|
||||
|
||||
Little module that helps with endpoints parsing.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### .decompose(endpoint)
|
||||
|
||||
Decomposes a endpoint into `name`, `source` and `target`.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.decompose('jquery#~2.0.0');
|
||||
// { name: '', source: 'jquery', target: '~2.0.0' }
|
||||
|
||||
endpointParser.decompose('backbone=backbone-amd#~1.0.0');
|
||||
// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' }
|
||||
|
||||
endpointParser.decompose('http://twitter.github.io/bootstrap/assets/bootstrap.zip');
|
||||
// { name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
|
||||
endpointParser.decompose('bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip');
|
||||
// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
```
|
||||
|
||||
### .compose(decEndpoint)
|
||||
|
||||
Inverse of `decompose()`.
|
||||
Takes a decomposed endpoint and composes it back into a string.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.compose({ name: '', source: 'jquery', target: '~2.0.0' });
|
||||
// jquery#~2.0.0
|
||||
|
||||
endpointParser.compose({ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' });
|
||||
// backbone=backbone-amd#~1.0.0
|
||||
|
||||
endpointParser.compose({ name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// http://twitter.github.io/bootstrap/assets/bootstrap.zip
|
||||
|
||||
endpointParser.compose({ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip
|
||||
```
|
||||
|
||||
### .json2decomposed(key, value)
|
||||
|
||||
Similar to `decompose()` but specially designed to be used when parsing `bower.json` dependencies.
|
||||
For instance, in a `bower.json` like this:
|
||||
|
||||
```js
|
||||
{
|
||||
"name": "foo",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"jquery": "~1.9.1",
|
||||
"backbone": "backbone-amd#~1.0.0",
|
||||
"bootstrap": "http://twitter.github.io/bootstrap/assets/bootstrap"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You would call `json2decomposed` like so:
|
||||
|
||||
```js
|
||||
endpointParser.json2decomposed('jquery', '~1.9.1');
|
||||
// { name: 'jquery', source: 'jquery', target: '~1.9.1' }
|
||||
|
||||
endpointParser.json2decomposed('backbone', 'backbone-amd#~1.0.0');
|
||||
// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' }
|
||||
|
||||
endpointParser.json2decomposed('bootstrap', 'http://twitter.github.io/bootstrap/assets/bootstrap');
|
||||
// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
```
|
||||
|
||||
### .decomposed2json(decEndpoint)
|
||||
|
||||
Inverse of `json2decomposed()`.
|
||||
Takes a decomposed endpoint and composes it to be saved to `bower.json`.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.decomposed2json({ name: 'jquery', source: 'jquery', target: '~2.0.0' });
|
||||
// { jquery: '~2.0.0' }
|
||||
|
||||
endpointParser.decomposed2json({ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' });
|
||||
// { backbone: 'backbone-amd#~2.0.0' }
|
||||
|
||||
endpointParser.decomposed2json({ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// { bootstrap: 'http://twitter.github.io/bootstrap/assets/bootstrap' }
|
||||
```
|
||||
|
||||
This function throws an exception if the `name` from the decomposed endpoint is empty.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
128
packages/bower-endpoint-parser/index.js
Normal file
128
packages/bower-endpoint-parser/index.js
Normal file
@@ -0,0 +1,128 @@
|
||||
function decompose(endpoint) {
|
||||
// Note that we allow spaces in targets and sources but they are trimmed
|
||||
var regExp = /^(?:([\w\-]|(?:[\w\.\-]+[\w\-])?)=)?([^\|#]+)(?:#(.*))?$/;
|
||||
var matches = endpoint.match(regExp);
|
||||
var target;
|
||||
var error;
|
||||
|
||||
if (!matches) {
|
||||
error = new Error('Invalid endpoint: ' + endpoint);
|
||||
error.code = 'EINVEND';
|
||||
throw error;
|
||||
}
|
||||
|
||||
target = trim(matches[3]);
|
||||
|
||||
return {
|
||||
name: trim(matches[1]),
|
||||
source: trim(matches[2]),
|
||||
target: isWildcard(target) ? '*' : target
|
||||
};
|
||||
}
|
||||
|
||||
function compose(decEndpoint) {
|
||||
var name = trim(decEndpoint.name);
|
||||
var source = trim(decEndpoint.source);
|
||||
var target = trim(decEndpoint.target);
|
||||
var composed = '';
|
||||
|
||||
if (name) {
|
||||
composed += name + '=';
|
||||
}
|
||||
|
||||
composed += source;
|
||||
|
||||
if (!isWildcard(target)) {
|
||||
composed += '#' + target;
|
||||
}
|
||||
|
||||
return composed;
|
||||
}
|
||||
|
||||
function json2decomposed(key, value) {
|
||||
var endpoint;
|
||||
var split;
|
||||
var error;
|
||||
|
||||
key = trim(key);
|
||||
value = trim(value);
|
||||
|
||||
if (!key) {
|
||||
error = new Error('The key must be specified');
|
||||
error.code = 'EINVEND';
|
||||
throw error;
|
||||
}
|
||||
|
||||
endpoint = key + '=';
|
||||
split = value.split('#').map(trim);
|
||||
|
||||
// If # was found, the source was specified
|
||||
if (split.length > 1) {
|
||||
endpoint += (split[0] || key) + '#' + split[1];
|
||||
// Check if value looks like a source
|
||||
} else if (isSource(value)) {
|
||||
endpoint += value + '#*';
|
||||
// Otherwise use the key as the source
|
||||
} else {
|
||||
endpoint += key + '#' + split[0];
|
||||
}
|
||||
|
||||
return decompose(endpoint);
|
||||
}
|
||||
|
||||
function decomposed2json(decEndpoint) {
|
||||
var error;
|
||||
var name = trim(decEndpoint.name);
|
||||
var source = trim(decEndpoint.source);
|
||||
var target = trim(decEndpoint.target);
|
||||
var value = '';
|
||||
var ret = {};
|
||||
|
||||
if (!name) {
|
||||
error = new Error('Decomposed endpoint must have a name');
|
||||
error.code = 'EINVEND';
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Add source only if different than the name
|
||||
if (source !== name) {
|
||||
value += source;
|
||||
}
|
||||
|
||||
// If value is empty, we append the target always
|
||||
if (!value) {
|
||||
if (isWildcard(target)) {
|
||||
value += '*';
|
||||
} else {
|
||||
if (target.indexOf('/') !== -1) {
|
||||
value += '#' + target;
|
||||
} else {
|
||||
value += target;
|
||||
}
|
||||
}
|
||||
// Otherwise append only if not a wildcard or source does not look like a source
|
||||
} else if (!isWildcard(target) || !isSource(source)) {
|
||||
value += '#' + (target || '*');
|
||||
}
|
||||
|
||||
ret[name] = value;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function trim(str) {
|
||||
return str ? str.trim() : '';
|
||||
}
|
||||
|
||||
function isWildcard(target) {
|
||||
return !target || target === '*' || target === 'latest';
|
||||
}
|
||||
|
||||
function isSource(value) {
|
||||
return (/[\/\\@]/).test(value);
|
||||
}
|
||||
|
||||
module.exports.decompose = decompose;
|
||||
module.exports.compose = compose;
|
||||
module.exports.json2decomposed = json2decomposed;
|
||||
module.exports.decomposed2json = decomposed2json;
|
||||
25
packages/bower-endpoint-parser/package.json
Normal file
25
packages/bower-endpoint-parser/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "bower-endpoint-parser",
|
||||
"version": "0.2.2",
|
||||
"description": "Little module that helps with endpoints parsing.",
|
||||
"author": "Twitter",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/bower/endpoint-parser/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"repository": "https://github.com/bower/bower/tree/master/packages/bower-endpoint-parser",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.2.0",
|
||||
"mocha": "~1.12.0",
|
||||
"mout": "~0.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec"
|
||||
}
|
||||
}
|
||||
263
packages/bower-endpoint-parser/test/test.js
Normal file
263
packages/bower-endpoint-parser/test/test.js
Normal file
@@ -0,0 +1,263 @@
|
||||
var expect = require('expect.js');
|
||||
var lang = require('mout/lang');
|
||||
var object = require('mout/object');
|
||||
var endpointParser = require('../');
|
||||
|
||||
describe('endpoint-parser', function () {
|
||||
describe('.decompose', function () {
|
||||
it('should decompose endpoints correctly', function () {
|
||||
var suite = {
|
||||
'jquery#~2.0.0': { name: '', source: 'jquery', target: '~2.0.0' },
|
||||
'jquery#*': { name: '', source: 'jquery', target: '*' },
|
||||
'jquery#latest': { name: '', source: 'jquery', target: '*' },
|
||||
'jquery#3dc50c62fe2d2d01afc58e7ad42236a35acff4d8': { name: '', source: 'jquery', target: '3dc50c62fe2d2d01afc58e7ad42236a35acff4d8' },
|
||||
'jquery#master': { name: '', source: 'jquery', target: 'master' },
|
||||
'backbone=backbone-amd#~1.0.0': { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' },
|
||||
'backbone=backbone-amd#latest': { name: 'backbone', source: 'backbone-amd', target: '*' },
|
||||
'backbone=backbone-amd#*': { name: 'backbone', source: 'backbone-amd', target: '*' },
|
||||
'http://twitter.github.io/bootstrap/assets/bootstrap.zip': { name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap.zip', target: '*' },
|
||||
'bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip': { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap.zip', target: '*' },
|
||||
'bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip#latest': { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap.zip', target: '*' }
|
||||
};
|
||||
|
||||
object.forOwn(suite, function (decEndpoint, endpoint) {
|
||||
expect(endpointParser.decompose(endpoint)).to.eql(decEndpoint);
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim sources and targets', function () {
|
||||
var decEndpoint = endpointParser.decompose('foo= source # ~1.0.2 ');
|
||||
expect(decEndpoint.source).to.equal('source');
|
||||
expect(decEndpoint.target).to.equal('~1.0.2');
|
||||
|
||||
decEndpoint = endpointParser.decompose('foo= source # latest');
|
||||
expect(decEndpoint.source).to.equal('source');
|
||||
expect(decEndpoint.target).to.equal('*');
|
||||
|
||||
decEndpoint = endpointParser.decompose('foo= source # *');
|
||||
expect(decEndpoint.source).to.equal('source');
|
||||
expect(decEndpoint.target).to.equal('*');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.compose', function () {
|
||||
it('should compose endpoints correctly', function () {
|
||||
var suite = {
|
||||
'jquery#~2.0.0': { name: '', source: 'jquery', target: '~2.0.0' },
|
||||
'jquery': [{ name: '', source: 'jquery', target: '*' }, { name: '', source: 'jquery', target: 'latest' }, { name: '', source: 'jquery', target: '' }],
|
||||
'jquery#3dc50c62fe2d2d01afc58e7ad42236a35acff4d8': { name: '', source: 'jquery', target: '3dc50c62fe2d2d01afc58e7ad42236a35acff4d8' },
|
||||
'jquery#master': { name: '', source: 'jquery', target: 'master' },
|
||||
'backbone=backbone-amd#~1.0.0': { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' },
|
||||
'backbone=backbone-amd': [{ name: 'backbone', source: 'backbone-amd', target: '*' }, { name: 'backbone', source: 'backbone-amd', target: '*' }, { name: 'backbone', source: 'backbone-amd', target: '' }],
|
||||
'http://twitter.github.io/bootstrap/assets/bootstrap.zip': { name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap.zip', target: '*' },
|
||||
'bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip': { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap.zip', target: '*' }
|
||||
};
|
||||
|
||||
object.forOwn(suite, function (decEndpoints, endpoint) {
|
||||
decEndpoints = lang.toArray(decEndpoints);
|
||||
decEndpoints.forEach(function (decEndpoint) {
|
||||
expect(endpointParser.compose(decEndpoint)).to.equal(endpoint);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim values', function () {
|
||||
expect(endpointParser.compose({
|
||||
name: ' foo ',
|
||||
source: ' bar ',
|
||||
target: ' ~1.0.2 '
|
||||
})).to.equal('foo=bar#~1.0.2');
|
||||
|
||||
expect(endpointParser.compose({
|
||||
name: ' foo ',
|
||||
source: ' foo ',
|
||||
target: ' ~1.0.2 '
|
||||
})).to.equal('foo=foo#~1.0.2');
|
||||
|
||||
expect(endpointParser.compose({
|
||||
name: ' foo ',
|
||||
source: ' foo ',
|
||||
target: ' * '
|
||||
})).to.equal('foo=foo');
|
||||
|
||||
expect(endpointParser.compose({
|
||||
name: ' foo ',
|
||||
source: ' foo ',
|
||||
target: ' * '
|
||||
})).to.equal('foo=foo');
|
||||
|
||||
expect(endpointParser.compose({
|
||||
name: ' ',
|
||||
source: ' foo ',
|
||||
target: ''
|
||||
})).to.equal('foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.json2decomposed', function () {
|
||||
var expected = [
|
||||
{ name: 'jquery', source: 'jquery', target: '~1.9.1' },
|
||||
{ name: 'foo', source: 'foo', target: '*' },
|
||||
{ name: 'bar', source: 'bar', target: '*' },
|
||||
{ name: 'baz', source: 'baz', target: '~0.2.0' },
|
||||
{ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' },
|
||||
{ name: 'backbone2', source: 'backbone=backbone-amd', target: '~1.0.0' },
|
||||
{ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' },
|
||||
{ name: 'bootstrap2', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' },
|
||||
{ name: 'ssh', source: 'git@example.com', target: '*' },
|
||||
{ name: 'git', source: 'git://example.com', target: '*' },
|
||||
{ name: 'path', source: '/foo', target: '*' },
|
||||
{ name: 'winpath', source: 'c:\\foo', target: '*' }
|
||||
];
|
||||
|
||||
it('should decompose json endpoints correctly', function () {
|
||||
var dependencies = {
|
||||
jquery: '~1.9.1',
|
||||
foo: 'latest',
|
||||
bar: '*',
|
||||
baz: '#~0.2.0',
|
||||
backbone: 'backbone-amd#~1.0.0',
|
||||
backbone2: 'backbone=backbone-amd#~1.0.0',
|
||||
bootstrap: 'http://twitter.github.io/bootstrap/assets/bootstrap',
|
||||
bootstrap2: 'http://twitter.github.io/bootstrap/assets/bootstrap#*',
|
||||
ssh: 'git@example.com',
|
||||
git: 'git://example.com',
|
||||
path: '/foo',
|
||||
winpath: 'c:\\foo'
|
||||
};
|
||||
var x = 0;
|
||||
|
||||
object.forOwn(dependencies, function (value, key) {
|
||||
expect(endpointParser.json2decomposed(key, value)).to.eql(expected[x]);
|
||||
x += 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim values', function () {
|
||||
var dependencies = {
|
||||
' jquery ': ' ~1.9.1 ',
|
||||
' foo ': ' latest ',
|
||||
' bar ': ' * ',
|
||||
' baz ': '# ~0.2.0 ',
|
||||
' backbone ': ' backbone-amd#~1.0.0 ',
|
||||
' backbone2 ': ' backbone=backbone-amd # ~1.0.0 ',
|
||||
' bootstrap ': ' http://twitter.github.io/bootstrap/assets/bootstrap',
|
||||
' bootstrap2 ': ' http://twitter.github.io/bootstrap/assets/bootstrap # *',
|
||||
' ssh ': ' git@example.com ',
|
||||
' git ': ' git://example.com ',
|
||||
' path ': ' /foo ',
|
||||
' winpath ': ' c:\\foo '
|
||||
};
|
||||
var x = 0;
|
||||
|
||||
object.forOwn(dependencies, function (value, key) {
|
||||
expect(endpointParser.json2decomposed(key, value)).to.eql(expected[x]);
|
||||
x += 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('should error out if key is not specified', function () {
|
||||
try {
|
||||
endpointParser.json2decomposed(null);
|
||||
throw new Error('Should have failed');
|
||||
} catch (e) {
|
||||
expect(e.code).to.equal('EINVEND');
|
||||
expect(e.message).to.contain('key must be specified');
|
||||
}
|
||||
|
||||
try {
|
||||
endpointParser.json2decomposed('');
|
||||
throw new Error('Should have failed');
|
||||
} catch (e) {
|
||||
expect(e.code).to.equal('EINVEND');
|
||||
expect(e.message).to.contain('key must be specified');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('.decomposed2json', function () {
|
||||
var expected = [
|
||||
{ jquery: '~1.9.1' },
|
||||
{ foo: '*' },
|
||||
{ bar: '*' },
|
||||
{ baz: '*' },
|
||||
{ jqueryx: 'jquery#~1.9.1' },
|
||||
{ jqueryy: 'jquery-x#*' },
|
||||
{ jqueryy: 'jquery-x#*' },
|
||||
{ backbone: 'backbone-amd#~1.0.0' },
|
||||
{ backbone : 'backbone=backbone-amd#~1.0.0' },
|
||||
{ bootstrap: 'http://twitter.github.io/bootstrap/assets/bootstrap' },
|
||||
{ bootstrap: 'http://twitter.github.io/bootstrap/assets/bootstrap' },
|
||||
{ ssh: 'git@example.com' },
|
||||
{ git: 'git://example.com' },
|
||||
{ ckeditor: '#full/4.3.3' }
|
||||
];
|
||||
|
||||
it('should compose endpoints to json correctly', function () {
|
||||
var decEndpoints = [
|
||||
{ name: 'jquery', source: 'jquery', target: '~1.9.1' },
|
||||
{ name: 'foo', source: 'foo', target: 'latest' },
|
||||
{ name: 'bar', source: 'bar', target: '*' },
|
||||
{ name: 'baz', source: 'baz', target: '' },
|
||||
{ name: 'jqueryx', source: 'jquery', target: '~1.9.1' },
|
||||
{ name: 'jqueryy', source: 'jquery-x', target: '' },
|
||||
{ name: 'jqueryy', source: 'jquery-x', target: '*' },
|
||||
{ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' },
|
||||
{ name: 'backbone', source: 'backbone=backbone-amd', target: '~1.0.0' },
|
||||
{ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '' },
|
||||
{ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' },
|
||||
{ name: 'ssh', source: 'git@example.com', target: '*' },
|
||||
{ name: 'git', source: 'git://example.com', target: '*' },
|
||||
{ name: 'ckeditor', source: 'ckeditor', target: 'full/4.3.3' }
|
||||
];
|
||||
var x = 0;
|
||||
|
||||
decEndpoints.forEach(function (decEndpoint) {
|
||||
expect(endpointParser.decomposed2json(decEndpoint)).to.eql(expected[x]);
|
||||
x += 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim values', function () {
|
||||
var decEndpoints = [
|
||||
{ name: ' jquery ', source: ' jquery ', target: ' ~1.9.1 ' },
|
||||
{ name: 'foo', source: ' foo', target: ' latest ' },
|
||||
{ name: 'bar', source: 'bar ', target: ' * ' },
|
||||
{ name: 'baz ', source: 'baz', target: ' ' },
|
||||
{ name: ' jqueryx ', source: ' jquery ', target: ' ~1.9.1 ' },
|
||||
{ name: ' jqueryy ', source: ' jquery-x ', target: ' ' },
|
||||
{ name: ' jqueryy ', source: ' jquery-x ', target: ' * ' },
|
||||
{ name: ' backbone ', source: ' backbone-amd ', target: ' ~1.0.0 ' },
|
||||
{ name: ' backbone ', source: ' backbone=backbone-amd ', target: ' ~1.0.0 ' },
|
||||
{ name: ' bootstrap ', source: ' http://twitter.github.io/bootstrap/assets/bootstrap ', target: ' ' },
|
||||
{ name: ' bootstrap ', source: ' http://twitter.github.io/bootstrap/assets/bootstrap ', target: ' * ' },
|
||||
{ name: ' ssh ', source: ' git@example.com ', target: ' * ' },
|
||||
{ name: ' git ', source: ' git://example.com ', target: ' * ' }
|
||||
];
|
||||
var x = 0;
|
||||
|
||||
decEndpoints.forEach(function (decEndpoint) {
|
||||
expect(endpointParser.decomposed2json(decEndpoint)).to.eql(expected[x]);
|
||||
x += 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if name is empty', function () {
|
||||
try {
|
||||
endpointParser.decomposed2json({ name: '', source: 'jquery', target: '*' });
|
||||
throw new Error('Should have failed');
|
||||
} catch (e) {
|
||||
expect(e.code).to.equal('EINVEND');
|
||||
expect(e.message).to.contain('must have a name');
|
||||
}
|
||||
|
||||
try {
|
||||
endpointParser.decomposed2json({ name: ' ', source: 'jquery', target: '*' });
|
||||
throw new Error('Should have failed');
|
||||
} catch (e) {
|
||||
expect(e.code).to.equal('EINVEND');
|
||||
expect(e.message).to.contain('must have a name');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
12
packages/bower-json/.editorconfig
Normal file
12
packages/bower-json/.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
4
packages/bower-json/.gitignore
vendored
Normal file
4
packages/bower-json/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/npm-debug.*
|
||||
|
||||
/test/reports
|
||||
48
packages/bower-json/.jshintrc
Normal file
48
packages/bower-json/.jshintrc
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
"mocha": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"camelcase": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"es5": false,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": false,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false
|
||||
}
|
||||
10
packages/bower-json/.travis.yml
Normal file
10
packages/bower-json/.travis.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- '5'
|
||||
- '4'
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
|
||||
script:
|
||||
- grunt travis
|
||||
17
packages/bower-json/CHANGELOG.md
Normal file
17
packages/bower-json/CHANGELOG.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# 0.8.1
|
||||
|
||||
- Revert strict name validations and allow @, spaces and slashes
|
||||
|
||||
# 0.8.0
|
||||
|
||||
- Update graceful-fs to 4.x
|
||||
- Add name validations that reflect what's happening in registry
|
||||
|
||||
# 0.7.1
|
||||
|
||||
- Unpublished
|
||||
|
||||
# 0.7.0
|
||||
|
||||
- Add getIssues function to retrieve all errors and warnings
|
||||
- Add readSync and findSync functions for synchronous read
|
||||
60
packages/bower-json/Gruntfile.js
Normal file
60
packages/bower-json/Gruntfile.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (grunt) {
|
||||
require('load-grunt-tasks')(grunt);
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
|
||||
jshint: {
|
||||
files: [
|
||||
'Gruntfile.js',
|
||||
'lib/**/*.js',
|
||||
'test/**/*.js',
|
||||
'!test/reports/**/*'
|
||||
],
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
}
|
||||
},
|
||||
|
||||
simplemocha: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
full: { src: ['test/test.js'] },
|
||||
short: {
|
||||
options: {
|
||||
reporter: 'dot'
|
||||
},
|
||||
src: ['test/test.js']
|
||||
},
|
||||
build: {
|
||||
options: {
|
||||
reporter: 'tap'
|
||||
},
|
||||
src: ['test/test.js']
|
||||
}
|
||||
},
|
||||
|
||||
exec: {
|
||||
cover: {
|
||||
command: 'STRICT_REQUIRE=1 node node_modules/istanbul/lib/cli.js cover --dir ./test/reports node_modules/mocha/bin/_mocha -- --timeout 30000 -R dot test/test.js'
|
||||
},
|
||||
coveralls: {
|
||||
command: 'node node_modules/.bin/coveralls < test/reports/lcov.info'
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
watch: {
|
||||
files: ['<%= jshint.files %>'],
|
||||
tasks: ['jshint', 'simplemocha:short']
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Default task.
|
||||
grunt.registerTask('test', ['simplemocha:full']);
|
||||
grunt.registerTask('default', ['jshint', 'test']);
|
||||
grunt.registerTask('travis', ['jshint', 'exec:cover', 'exec:coveralls']);
|
||||
};
|
||||
19
packages/bower-json/LICENSE
Normal file
19
packages/bower-json/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2016 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
159
packages/bower-json/README.md
Normal file
159
packages/bower-json/README.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# bower-json [](http://travis-ci.org/bower/json) [](https://coveralls.io/github/bower/json?branch=master)
|
||||
|
||||
Read `bower.json` files with semantics, normalisation, defaults and validation.
|
||||
|
||||
Install via [npm](https://www.npmjs.org/package/bower-json): `npm install --save bower-json`
|
||||
|
||||
## Usage
|
||||
|
||||
#### .read(file, options, callback)
|
||||
#### .readSync(file, options)
|
||||
|
||||
Reads `file` and applies normalisation, defaults and validation according to the `bower.json` spec.
|
||||
If the passed `file` does not exist, the callback is called with `error.code` equal to `ENOENT`.
|
||||
If the passed `file` contents are not valid JSON, the callback is called with `error.code` equal to `EMALFORMED`.
|
||||
If the `json` does not comply with the `bower.json` spec, the callback is called with `error.code` equal to `EINVALID`.
|
||||
|
||||
If `file` is a directory, `find()` will be used to search for the json file.
|
||||
The `options` argument is optional and can be omitted. These options will be passed to `parse` method.
|
||||
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
// Can also be used by simply calling bowerJson()
|
||||
bowerJson.read('/path/to/bower.json', function (err, json) {
|
||||
if (err) {
|
||||
console.error('There was an error reading the file');
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('JSON: ', json);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
#### .parse(json, options)
|
||||
|
||||
Parses an object. Useful when you want to apply normalisation and validation directly to an object.
|
||||
If the `json` does not comply with the `bower.json` spec, an error is thrown with `error.code` equal to `EINVALID`.
|
||||
|
||||
The `options` arguments is optional and can be omitted. Available options:
|
||||
|
||||
- validate: Apply validation, defaults to `true`
|
||||
- normalize: Apply normalisation, defaults to `false`
|
||||
- clone: clone, use and return the passed in `json` object instead of using it directly, defaults to `false`
|
||||
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
var json = {
|
||||
name: 'my-package',
|
||||
version: '0.0.1'
|
||||
};
|
||||
|
||||
try {
|
||||
bowerJson.parse(json);
|
||||
} catch (err) {
|
||||
console.error('There was an error parsing the object');
|
||||
console.error(err.message);
|
||||
}
|
||||
```
|
||||
|
||||
#### .getIssues(json) - DEPRECATED
|
||||
|
||||
Validates the passed `json` object.
|
||||
|
||||
Returns an object with errors and warnings of this bower.json contents.
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
var json = {
|
||||
name: 'myPackage',
|
||||
version: '0.0.1',
|
||||
main: {}
|
||||
};
|
||||
|
||||
var issues = bowerJson.getIssues(json);
|
||||
|
||||
expect(issues).toEqual({
|
||||
errors: ['The "main" field has to be either an Array or a String'],
|
||||
warnings: ['The "name" must be lowercase']
|
||||
});
|
||||
|
||||
#### .validate(json)
|
||||
|
||||
Validates the passed `json` object.
|
||||
|
||||
Throws an error with `error.code` equal to `EINVALID` if it does not comply with the spec.
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
var json = {
|
||||
name: 'myPackage',
|
||||
version: '0.0.1'
|
||||
};
|
||||
|
||||
try {
|
||||
bowerJson.validate(json);
|
||||
} catch (err) {
|
||||
console.error('There was an error validating the object');
|
||||
console.error(err.message);
|
||||
}
|
||||
```
|
||||
|
||||
#### .normalize(json)
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
var json = {
|
||||
name: 'my-package',
|
||||
version: '0.0.1',
|
||||
main: 'foo.js,bar.js'
|
||||
};
|
||||
|
||||
bowerJson.normalize(json);
|
||||
json.main // ['foo.js', 'bar.js']
|
||||
```
|
||||
|
||||
|
||||
#### .find(folder, callback)
|
||||
#### .findSync(folder)
|
||||
|
||||
Finds the `json` filename inside a folder.
|
||||
Checks if a `bower.json` exists, falling back to `component.json` (deprecated) and `.bower.json`.
|
||||
If no file was found, the callback is called with a `error.code` of `ENOENT`.
|
||||
|
||||
```js
|
||||
var bowerJson = require('bower-json');
|
||||
|
||||
bowerJson.find('/path/to/folder', function (err, filename) {
|
||||
if (err) {
|
||||
console.error('There is no json file in the folder');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Filename: ', filename);
|
||||
|
||||
// Now that we got the filename, we can read its contents
|
||||
bowerJson.read(filename, function (err, json) {
|
||||
if (err) {
|
||||
console.error('There was an error reading the file');
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('JSON: ', json);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
297
packages/bower-json/lib/json.js
Normal file
297
packages/bower-json/lib/json.js
Normal file
@@ -0,0 +1,297 @@
|
||||
var fs = require('graceful-fs');
|
||||
var path = require('path');
|
||||
var deepExtend = require('deep-extend');
|
||||
var isAsset = require('./util/isAsset');
|
||||
var isComponent = require('./util/isComponent');
|
||||
var createError = require('./util/createError');
|
||||
|
||||
var possibleJsons = ['bower.json', 'component.json', '.bower.json'];
|
||||
|
||||
function read(file, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Check if file is a directory
|
||||
fs.stat(file, function (err, stat) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// It's a directory, so we find the json inside it
|
||||
if (stat.isDirectory()) {
|
||||
return find(file, function (err, file) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
read(file, options, callback);
|
||||
});
|
||||
}
|
||||
|
||||
// Otherwise read it
|
||||
fs.readFile(file, function (err, contents) {
|
||||
var json;
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
try {
|
||||
json = JSON.parse(contents.toString());
|
||||
} catch (err) {
|
||||
err.file = path.resolve(file);
|
||||
err.code = 'EMALFORMED';
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Parse it
|
||||
try {
|
||||
json = parse(json, options);
|
||||
} catch (err) {
|
||||
err.file = path.resolve(file);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, json, file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function readSync(file, options) {
|
||||
var stat;
|
||||
var filename;
|
||||
var contents;
|
||||
var json;
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
try {
|
||||
stat = fs.statSync(file);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
if (stat.isDirectory()) {
|
||||
filename = findSync(file);
|
||||
return readSync(filename);
|
||||
}
|
||||
|
||||
contents = fs.readFileSync(file);
|
||||
|
||||
try {
|
||||
json = JSON.parse(contents.toString());
|
||||
} catch (err) {
|
||||
err.file = path.resolve(file);
|
||||
err.code = 'EMALFORMED';
|
||||
return err;
|
||||
}
|
||||
|
||||
try {
|
||||
json = parse(json, options);
|
||||
} catch (err) {
|
||||
err.file = path.resolve(file);
|
||||
return err;
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
function parse(json, options) {
|
||||
options = deepExtend({
|
||||
normalize: false,
|
||||
validate: true,
|
||||
clone: false
|
||||
}, options || {});
|
||||
|
||||
// Clone
|
||||
if (options.clone) {
|
||||
json = deepExtend({}, json);
|
||||
}
|
||||
|
||||
// Validate
|
||||
if (options.validate) {
|
||||
validate(json);
|
||||
}
|
||||
|
||||
// Normalize
|
||||
if (options.normalize) {
|
||||
normalize(json);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
// This function implements:
|
||||
//
|
||||
// https://github.com/bower/bower.json-spec
|
||||
function getIssues(json) {
|
||||
// For things that shouldn't happen
|
||||
var errors = [];
|
||||
|
||||
// For things that happen but they shoudn't
|
||||
var warnings = [];
|
||||
|
||||
if (!json.name) {
|
||||
errors.push('No "name" property set');
|
||||
} else {
|
||||
if (!/^[a-zA-Z0-9_@][a-zA-Z0-9_@\.\- \/]*$/.test(json.name)) {
|
||||
errors.push('Name must be lowercase, can contain digits, dots, dashes, "@" or spaces');
|
||||
}
|
||||
|
||||
if (json.name.length > 50) {
|
||||
warnings.push('The "name" is too long, the limit is 50 characters');
|
||||
}
|
||||
|
||||
if (!/^[a-z0-9_][a-z0-9_\.\-]*$/.test(json.name)) {
|
||||
warnings.push('The "name" is recommended to be lowercase, can contain digits, dots, dashes');
|
||||
}
|
||||
|
||||
if (/^[\.-]/.test(json.name)) {
|
||||
warnings.push('The "name" cannot start with dot or dash');
|
||||
}
|
||||
|
||||
if (/[\.-]$/.test(json.name)) {
|
||||
warnings.push('The "name" cannot end with dot or dash');
|
||||
}
|
||||
}
|
||||
|
||||
if (json.description && json.description.length > 140) {
|
||||
warnings.push('The "description" is too long, the limit is 140 characters');
|
||||
}
|
||||
|
||||
if (json.main !== undefined) {
|
||||
var main = json.main;
|
||||
if (typeof main === 'string') {
|
||||
main = [main];
|
||||
}
|
||||
if (!(main instanceof Array)) {
|
||||
errors.push('The "main" field has to be either an Array or a String');
|
||||
} else {
|
||||
var ext2files = {};
|
||||
main.forEach(function (filename) {
|
||||
if (typeof filename !== 'string') {
|
||||
errors.push('The "main" Array has to contain only Strings');
|
||||
}
|
||||
if (/[*]/.test(filename)) {
|
||||
warnings.push('The "main" field cannot contain globs (example: "*.js")');
|
||||
}
|
||||
if (/[.]min[.][^/]+$/.test(filename)) {
|
||||
warnings.push('The "main" field cannot contain minified files');
|
||||
}
|
||||
if (isAsset(filename)) {
|
||||
warnings.push('The "main" field cannot contain font, image, audio, or video files');
|
||||
}
|
||||
var ext = path.extname(filename);
|
||||
if (ext.length >= 2) {
|
||||
var files = ext2files[ext];
|
||||
if (!files) {
|
||||
files = ext2files[ext] = [];
|
||||
}
|
||||
files.push(filename);
|
||||
}
|
||||
});
|
||||
Object.keys(ext2files).forEach(function (ext) {
|
||||
var files = ext2files[ext];
|
||||
if (files.length > 1) {
|
||||
warnings.push('The "main" field has to contain only 1 file per filetype; found multiple ' + ext + ' files: ' + JSON.stringify(files));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
errors: errors,
|
||||
warnings: warnings
|
||||
};
|
||||
}
|
||||
|
||||
// For backward compatibility, it throws first error
|
||||
function validate(json) {
|
||||
var issues = getIssues(json);
|
||||
|
||||
if (issues.errors && issues.errors.length > 0) {
|
||||
throw createError(issues.errors[0], 'EINVALID');
|
||||
}
|
||||
}
|
||||
|
||||
function normalize(json) {
|
||||
if (typeof json.main === 'string') {
|
||||
json.main = [json.main];
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
function find(folder, files, callback) {
|
||||
var err;
|
||||
var file;
|
||||
|
||||
if (typeof files === 'function') {
|
||||
callback = files;
|
||||
files = possibleJsons;
|
||||
}
|
||||
|
||||
if (!files.length) {
|
||||
err = createError('None of ' + possibleJsons.join(', ') + ' were found in ' + folder, 'ENOENT');
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
file = path.resolve(path.join(folder, files[0]));
|
||||
fs.exists(file, function (exists) {
|
||||
if (!exists) {
|
||||
return find(folder, files.slice(1), callback);
|
||||
}
|
||||
|
||||
if (files[0] !== 'component.json') {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
// If the file is component.json, check it it's a component(1) file
|
||||
// If it is, we ignore it and keep searching
|
||||
isComponent(file, function (is) {
|
||||
if (is) {
|
||||
return find(folder, files.slice(1), callback);
|
||||
}
|
||||
|
||||
callback(null, file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function findSync(folder, files) {
|
||||
var file;
|
||||
var exists;
|
||||
|
||||
if (files === undefined) {
|
||||
files = possibleJsons;
|
||||
}
|
||||
|
||||
if (!files.length) {
|
||||
return createError('None of ' + possibleJsons.join(', ') + ' were found in ' + folder, 'ENOENT');
|
||||
}
|
||||
|
||||
file = path.resolve(path.join(folder, files[0]));
|
||||
try{
|
||||
exists = fs.statSync(file);
|
||||
}
|
||||
catch (err) {
|
||||
exists = false;
|
||||
}
|
||||
if (exists && exists.isFile()) {
|
||||
return file;
|
||||
} else {
|
||||
return findSync(folder, files.slice(1));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = read;
|
||||
module.exports.read = read;
|
||||
module.exports.readSync = readSync;
|
||||
module.exports.parse = parse;
|
||||
module.exports.getIssues = getIssues;
|
||||
module.exports.validate = validate;
|
||||
module.exports.normalize = normalize;
|
||||
module.exports.find = find;
|
||||
module.exports.findSync = findSync;
|
||||
8
packages/bower-json/lib/util/createError.js
Normal file
8
packages/bower-json/lib/util/createError.js
Normal file
@@ -0,0 +1,8 @@
|
||||
function createError(msg, code) {
|
||||
var err = new Error(msg);
|
||||
err.code = code;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
module.exports = createError;
|
||||
12
packages/bower-json/lib/util/isAsset.js
Normal file
12
packages/bower-json/lib/util/isAsset.js
Normal file
@@ -0,0 +1,12 @@
|
||||
var extName = require('ext-name');
|
||||
|
||||
function isAsset(filename) {
|
||||
var info = extName(filename);
|
||||
|
||||
return info && info.mime && (
|
||||
/^((image)|(audio)|(video)|(font))\//.test(info.mime) ||
|
||||
/application\/((x[-]font[-])|(font[-]woff(\d?))|(vnd[.]ms[-]fontobject))/.test(info.mime)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = isAsset;
|
||||
41
packages/bower-json/lib/util/isComponent.js
Normal file
41
packages/bower-json/lib/util/isComponent.js
Normal file
@@ -0,0 +1,41 @@
|
||||
var fs = require('graceful-fs');
|
||||
var intersect = require('intersect');
|
||||
|
||||
// Function to check if a file is a component(1) file
|
||||
function isComponent(file, callback) {
|
||||
fs.readFile(file, function (err, contents) {
|
||||
var json;
|
||||
var keys;
|
||||
var common;
|
||||
|
||||
// If an error occurs while reading the file, we ignore it
|
||||
if (err) {
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
try {
|
||||
json = JSON.parse(contents.toString());
|
||||
} catch (err) {
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
// Attempt to find specific things from the component(1) spec
|
||||
// Note that we don't parse the dependencies property because at any point
|
||||
// we can allow / to specify directories
|
||||
// Bellow only some clearly not ambiguous properties are checked
|
||||
keys = Object.keys(json);
|
||||
common = intersect(keys, [
|
||||
'repo',
|
||||
'development',
|
||||
'local',
|
||||
'remotes',
|
||||
'paths',
|
||||
'demo'
|
||||
]);
|
||||
|
||||
// If none were found, than it's a valid component.json bower file
|
||||
callback(common.length ? true : false);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = isComponent;
|
||||
40
packages/bower-json/package.json
Normal file
40
packages/bower-json/package.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "bower-json",
|
||||
"version": "0.8.1",
|
||||
"description": "Read bower.json files with semantics, normalisation, defaults and validation",
|
||||
"author": "Twitter",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/bower/bower/tree/master/packages/bower-json",
|
||||
"main": "lib/json",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"deep-extend": "^0.4.0",
|
||||
"ext-name": "^3.0.0",
|
||||
"graceful-fs": "^4.1.3",
|
||||
"intersect": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.2",
|
||||
"expect.js": "^0.3.1",
|
||||
"grunt": "^0.4.4",
|
||||
"grunt-cli": "^0.1.13",
|
||||
"grunt-contrib-jshint": "^0.11.2",
|
||||
"grunt-contrib-watch": "^0.6.1",
|
||||
"grunt-coveralls": "^1.0.0",
|
||||
"grunt-exec": "^0.4.6",
|
||||
"grunt-simple-mocha": "^0.4.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"load-grunt-tasks": "^3.3.0",
|
||||
"mocha": "*",
|
||||
"request": "^2.64.0",
|
||||
"underscore.string": "^3.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1 @@
|
||||
{
|
||||
5
packages/bower-json/test/pkg-bower-json/bower.json
Normal file
5
packages/bower-json/test/pkg-bower-json/bower.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "some-pkg",
|
||||
"version": "0.0.0",
|
||||
"main": "foo.js"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "route",
|
||||
"repo": "apily/route",
|
||||
"version": "0.0.1",
|
||||
"description": "Route component",
|
||||
"keywords": ["router", "route"],
|
||||
"scripts": ["index.js"],
|
||||
"dependencies": {},
|
||||
"development": {
|
||||
"component/assert": "*",
|
||||
"visionmedia/mocha": "*"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "some-pkg",
|
||||
"version": "0.0.0"
|
||||
}
|
||||
5
packages/bower-json/test/pkg-dot-bower-json/.bower.json
Normal file
5
packages/bower-json/test/pkg-dot-bower-json/.bower.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "some-installed-pkg",
|
||||
"version": "0.0.1",
|
||||
"main": "bar.js"
|
||||
}
|
||||
497
packages/bower-json/test/test.js
Normal file
497
packages/bower-json/test/test.js
Normal file
@@ -0,0 +1,497 @@
|
||||
var path = require('path');
|
||||
var expect = require('expect.js');
|
||||
var _s = require('underscore.string');
|
||||
var bowerJson = require('../lib/json');
|
||||
var request = require('request');
|
||||
|
||||
describe('.find', function () {
|
||||
it('should find the bower.json file', function (done) {
|
||||
bowerJson.find(__dirname + '/pkg-bower-json', function (err, file) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-bower-json/bower.json'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fallback to the component.json file', function (done) {
|
||||
bowerJson.find(__dirname + '/pkg-component-json', function (err, file) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-component-json/component.json'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fallback to the component.json file if it\'s a component(1) file', function (done) {
|
||||
bowerJson.find(__dirname + '/pkg-component(1)-json', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
expect(err.message).to.equal('None of bower.json, component.json, .bower.json were found in ' + __dirname + '/pkg-component(1)-json');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fallback to the .bower.json file', function (done) {
|
||||
bowerJson.find(__dirname + '/pkg-dot-bower-json', function (err, file) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-dot-bower-json/.bower.json'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if no component.json / bower.json / .bower.json is found', function (done) {
|
||||
bowerJson.find(__dirname, function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
expect(err.message).to.equal('None of bower.json, component.json, .bower.json were found in ' + __dirname);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.findSync', function () {
|
||||
|
||||
it('should find the bower.json file', function (done) {
|
||||
var file = bowerJson.findSync(__dirname + '/pkg-bower-json');
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-bower-json/bower.json'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should fallback to the component.json file', function (done) {
|
||||
var file = bowerJson.findSync(__dirname + '/pkg-component-json');
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-component-json/component.json'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should fallback to the .bower.json file', function (done) {
|
||||
var file = bowerJson.findSync(__dirname + '/pkg-dot-bower-json');
|
||||
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-dot-bower-json/.bower.json'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should error if no component.json / bower.json / .bower.json is found', function (done) {
|
||||
var err = bowerJson.findSync(__dirname);
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
expect(err.message).to.equal('None of bower.json, component.json, .bower.json were found in ' + __dirname);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('.read', function () {
|
||||
it('should give error if file does not exists', function (done) {
|
||||
bowerJson.read(__dirname + '/willneverexist', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should give error if when reading an invalid json', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-bower-json-malformed/bower.json', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('EMALFORMED');
|
||||
expect(err.file).to.equal(path.resolve(__dirname + '/pkg-bower-json-malformed/bower.json'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should read the file and give an object', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-bower-json/bower.json', function (err, json) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(json).to.be.an('object');
|
||||
expect(json.name).to.equal('some-pkg');
|
||||
expect(json.version).to.equal('0.0.0');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should give the json file that was read', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-bower-json', function (err, json, file) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
|
||||
expect(file).to.equal(__dirname + '/pkg-bower-json/bower.json');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should find for a json file if a directory is given', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-component-json', function (err, json, file) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(json).to.be.an('object');
|
||||
expect(json.name).to.equal('some-pkg');
|
||||
expect(json.version).to.equal('0.0.0');
|
||||
expect(file).to.equal(path.resolve(__dirname + '/pkg-component-json/component.json'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should validate the returned object unless validate is false', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-bower-json-invalid/bower.json', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.message).to.contain('name');
|
||||
expect(err.file).to.equal(path.resolve(__dirname + '/pkg-bower-json-invalid/bower.json'));
|
||||
|
||||
bowerJson.read(__dirname + '/pkg-bower-json-invalid/bower.json', { validate: false }, function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should normalize the returned object if normalize is true', function (done) {
|
||||
bowerJson.read(__dirname + '/pkg-bower-json/bower.json', function (err, json) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(json.main).to.equal('foo.js');
|
||||
|
||||
bowerJson.read(__dirname + '/pkg-bower-json/bower.json', { normalize: true }, function (err, json) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(json.main).to.eql(['foo.js']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readSync', function () {
|
||||
it('should give error if file does not exists', function (done) {
|
||||
var err = bowerJson.readSync(__dirname + '/willneverexist');
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should give error if when reading an invalid json', function (done) {
|
||||
var err = bowerJson.readSync(__dirname + '/pkg-bower-json-malformed/bower.json');
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.equal('EMALFORMED');
|
||||
expect(err.file).to.equal(path.resolve(__dirname + '/pkg-bower-json-malformed/bower.json'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should read the file and give an object', function (done) {
|
||||
var json = bowerJson.readSync(__dirname + '/pkg-bower-json/bower.json');
|
||||
|
||||
expect(json).to.be.an('object');
|
||||
expect(json.name).to.equal('some-pkg');
|
||||
expect(json.version).to.equal('0.0.0');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should find for a json file if a directory is given', function (done) {
|
||||
var json = bowerJson.readSync(__dirname + '/pkg-component-json');
|
||||
|
||||
expect(json).to.be.an('object');
|
||||
expect(json.name).to.equal('some-pkg');
|
||||
expect(json.version).to.equal('0.0.0');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should validate the returned object unless validate is false', function (done) {
|
||||
var err = bowerJson.readSync(__dirname + '/pkg-bower-json-invalid/bower.json');
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.message).to.contain('name');
|
||||
expect(err.file).to.equal(path.resolve(__dirname + '/pkg-bower-json-invalid/bower.json'));
|
||||
|
||||
err = bowerJson.readSync(__dirname + '/pkg-bower-json-invalid/bower.json', { validate: false });
|
||||
expect(err).to.not.be.an(Error);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should normalize the returned object if normalize is true', function (done) {
|
||||
var json = bowerJson.readSync(__dirname + '/pkg-bower-json/bower.json');
|
||||
expect(json.main).to.equal('foo.js');
|
||||
|
||||
json = bowerJson.readSync(__dirname + '/pkg-bower-json/bower.json', { normalize: true });
|
||||
|
||||
expect(json.main).to.eql(['foo.js']);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('.parse', function () {
|
||||
it('should return the same object, unless clone is true', function () {
|
||||
var json = { name: 'foo' };
|
||||
|
||||
expect(bowerJson.parse(json)).to.equal(json);
|
||||
expect(bowerJson.parse(json, { clone: true })).to.not.equal(json);
|
||||
expect(bowerJson.parse(json, { clone: true })).to.eql(json);
|
||||
});
|
||||
|
||||
it('should validate the passed object, unless validate is false', function () {
|
||||
expect(function () {
|
||||
bowerJson.parse({});
|
||||
}).to.throwException(/name/);
|
||||
|
||||
expect(function () {
|
||||
bowerJson.parse({}, { validate: false });
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not normalize the passed object unless normalize is true', function () {
|
||||
var json = { name: 'foo', main: 'foo.js' };
|
||||
|
||||
bowerJson.parse(json);
|
||||
expect(json.main).to.eql('foo.js');
|
||||
|
||||
bowerJson.parse(json, { normalize: true });
|
||||
expect(json.main).to.eql(['foo.js']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getIssues', function () {
|
||||
it('should print no errors even for weird package names', function () {
|
||||
var json = { name: '@gruNt/my dependency' };
|
||||
|
||||
expect(bowerJson.getIssues(json).errors).to.be.empty();
|
||||
});
|
||||
|
||||
it('should validate the name length', function () {
|
||||
var json = { name: 'a_123456789_123456789_123456789_123456789_123456789_z' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" is too long, the limit is 50 characters'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name is lowercase', function () {
|
||||
var json = { name: 'gruNt' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" is recommended to be lowercase, can contain digits, dots, dashes'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name starts with lowercase', function () {
|
||||
var json = { name: '-runt' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" cannot start with dot or dash'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name starts with lowercase', function () {
|
||||
var json = { name: '.grunt' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" cannot start with dot or dash'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name ends with lowercase', function () {
|
||||
var json = { name: 'grun-' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" cannot end with dot or dash'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name ends with lowercase', function () {
|
||||
var json = { name: 'grun.' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "name" cannot end with dot or dash'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the name is valid', function () {
|
||||
var json = { name: 'gru.n-t' };
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.eql([]);
|
||||
});
|
||||
|
||||
it('should validate the description length', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
description: _s.repeat('æ', 141)
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "description" is too long, the limit is 140 characters'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate the description is valid', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
description: _s.repeat('æ', 140)
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.eql([]);
|
||||
});
|
||||
|
||||
it('should validate that main does not contain globs', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: ['js/*.js']
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "main" field cannot contain globs (example: "*.js")'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate that main does not contain minified files', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: ['foo.min.css']
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "main" field cannot contain minified files'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate that main does not contain fonts', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: ['foo.woff']
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "main" field cannot contain font, image, audio, or video files'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate that main does not contain images', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: ['foo.png']
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "main" field cannot contain font, image, audio, or video files'
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate that main does not contain multiple files of the same filetype', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: ['foo.js', 'bar.js']
|
||||
};
|
||||
|
||||
expect(bowerJson.getIssues(json).warnings).to.contain(
|
||||
'The "main" field has to contain only 1 file per filetype; found multiple .js files: ["foo.js","bar.js"]'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.validate', function () {
|
||||
it('should validate the name property', function () {
|
||||
expect(function () {
|
||||
bowerJson.validate({});
|
||||
}).to.throwException(/name/);
|
||||
});
|
||||
|
||||
it('should validate the type of main', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: {}
|
||||
};
|
||||
expect(function () {
|
||||
bowerJson.validate(json);
|
||||
}).to.throwException();
|
||||
});
|
||||
it('should validate the type of items of an Array main', function () {
|
||||
var json = {
|
||||
name: 'foo',
|
||||
main: [{}]
|
||||
};
|
||||
expect(function () {
|
||||
bowerJson.validate(json);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.normalize', function () {
|
||||
it('should normalize the main property', function () {
|
||||
var json = { name: 'foo', main: 'foo.js' };
|
||||
|
||||
bowerJson.normalize(json);
|
||||
expect(json.main).to.eql(['foo.js']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('packages from bower registry', function () {
|
||||
|
||||
var packageList,
|
||||
packageListUrl = 'http://bower.herokuapp.com/packages';
|
||||
|
||||
this.timeout(60000);
|
||||
|
||||
it('can be downloaded from online source ' + packageListUrl, function(done) {
|
||||
request({
|
||||
url: packageListUrl,
|
||||
json: true
|
||||
}, function(error, response, body) {
|
||||
|
||||
if(error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
expect(body).to.be.an('array');
|
||||
expect(body).to.not.be.empty();
|
||||
packageList = body;
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should validate each listed package', function (done) {
|
||||
|
||||
expect(packageList).to.be.an('array');
|
||||
|
||||
var invalidPackageCount = 0;
|
||||
|
||||
packageList.forEach(function(package) {
|
||||
try {
|
||||
bowerJson.validate(package);
|
||||
} catch(e) {
|
||||
invalidPackageCount++;
|
||||
console.error('validation of "' + package.name + '" failed: ' + e.message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if(invalidPackageCount) {
|
||||
throw new Error(invalidPackageCount + '/' + packageList.length + ' package names do not validate');
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
12
packages/bower-logger/.editorconfig
Normal file
12
packages/bower-logger/.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
2
packages/bower-logger/.gitignore
vendored
Normal file
2
packages/bower-logger/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/npm-debug.*
|
||||
62
packages/bower-logger/.jshintrc
Normal file
62
packages/bower-logger/.jshintrc
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"describe",
|
||||
"it",
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach"
|
||||
],
|
||||
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"trailing": true,
|
||||
"camelcase": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"es5": false,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": false,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"white": true
|
||||
}
|
||||
6
packages/bower-logger/.travis.yml
Normal file
6
packages/bower-logger/.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- 'iojs'
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
19
packages/bower-logger/LICENSE
Normal file
19
packages/bower-logger/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
126
packages/bower-logger/README.md
Normal file
126
packages/bower-logger/README.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# bower-logger [](http://travis-ci.org/bower/logger)
|
||||
|
||||
The logger used in the various architecture components of Bower.
|
||||
|
||||
Install
|
||||
|
||||
```sh
|
||||
npm install --save bower-logger
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### .error(id, message, data)
|
||||
|
||||
Alias to `.log('error', id, message, data)`
|
||||
|
||||
|
||||
### .conflict(id, message, data)
|
||||
|
||||
Alias to `.log('conflict', id, message, data)`
|
||||
|
||||
|
||||
### .warn(id, message, data)
|
||||
|
||||
Alias to `.log('warn', id, message, data)`
|
||||
|
||||
|
||||
### .action(id, message, data)
|
||||
|
||||
Alias to `.log('action', id, message, data)`
|
||||
|
||||
|
||||
### .info(id, message, data)
|
||||
|
||||
Alias to `.log('info', id, message, data)`
|
||||
|
||||
|
||||
### .debug(id, message, data)
|
||||
|
||||
Alias to `.log('debug', id, message, data)`
|
||||
|
||||
|
||||
### .log(level, id, message, data)
|
||||
|
||||
Emits a `log` event, with an object like so:
|
||||
|
||||
```js
|
||||
logger.log('warn', 'foo', 'bar', { dog: 'loves cat' })
|
||||
{
|
||||
level: 'warn',
|
||||
id: 'foo',
|
||||
message: 'bar',
|
||||
data: {
|
||||
dog: 'loves cat'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### .prompt(prompts, callback)
|
||||
|
||||
Emits a `prompt` event with an array of `prompts` with a `callback`.
|
||||
`prompts` can be an object or an array of objects. The `callback` will be called with an
|
||||
the answer or an object of answers (if prompts was only one or an array respectively).
|
||||
The `callback` is guaranteed to run only once.
|
||||
|
||||
```js
|
||||
logger.on('prompt', function (prompts, callback) {
|
||||
// "prompts" is always an array of prompts
|
||||
// Call "callback" with an object of answers when done
|
||||
|
||||
// In this example, we will use the inquirer module to do the
|
||||
// prompting for us
|
||||
inquirer(prompts, callback);
|
||||
})
|
||||
|
||||
logger.prompt({
|
||||
type: 'input' // Can be 'input', 'confirm' or 'password'
|
||||
message: 'Type something',
|
||||
validate: function (value) {
|
||||
if (value !== 'I am awesome') {
|
||||
return 'You must type "I am awesome"'
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, function (err, answer) {
|
||||
// Error will only happen on unsupported 'type'
|
||||
if (err) {
|
||||
return console.error(err.message);
|
||||
}
|
||||
|
||||
console.log(answer);
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
### .pipe(logger)
|
||||
|
||||
Pipes all logger events to another logger.
|
||||
Basically all events emitted with `.emit()` will get piped.
|
||||
|
||||
|
||||
### .geminate()
|
||||
|
||||
Creates a new logger that pipes events to the parent logger.
|
||||
Alias for `(new Logger()).pipe(logger)`.
|
||||
|
||||
|
||||
### .intercept(fn)
|
||||
|
||||
Intercepts `log` events, calling `fn` before listeners of the instance.
|
||||
|
||||
|
||||
### #LEVELS
|
||||
|
||||
A static property that contains an object where keys are the recognized log levels and values their importance.
|
||||
The higher the importance, the more important the level is.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
150
packages/bower-logger/lib/Logger.js
Normal file
150
packages/bower-logger/lib/Logger.js
Normal file
@@ -0,0 +1,150 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
function Logger() {
|
||||
this._interceptors = [];
|
||||
this._piped = [];
|
||||
}
|
||||
|
||||
util.inherits(Logger, EventEmitter);
|
||||
|
||||
Logger.prototype.intercept = function (fn) {
|
||||
this._interceptors.push(fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
Logger.prototype.emit = function () {
|
||||
var ret;
|
||||
var args = slice.call(arguments);
|
||||
|
||||
// Run interceptors before
|
||||
if (args[0] === 'log') {
|
||||
this._interceptors.forEach(function (interceptor) {
|
||||
interceptor.apply(this, args.slice(1));
|
||||
});
|
||||
}
|
||||
|
||||
ret = EventEmitter.prototype.emit.apply(this, args);
|
||||
|
||||
// Pipe
|
||||
this._piped.forEach(function (emitter) {
|
||||
emitter.emit.apply(emitter, args);
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
Logger.prototype.pipe = function (emitter) {
|
||||
this._piped.push(emitter);
|
||||
|
||||
return emitter;
|
||||
};
|
||||
|
||||
Logger.prototype.geminate = function () {
|
||||
var logger = new Logger();
|
||||
|
||||
logger.pipe(this);
|
||||
return logger;
|
||||
};
|
||||
|
||||
Logger.prototype.log = function (level, id, message, data) {
|
||||
var log = {
|
||||
level: level,
|
||||
id: id,
|
||||
message: message,
|
||||
data: data || {}
|
||||
};
|
||||
|
||||
// Emit log
|
||||
this.emit('log', log);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Logger.prototype.prompt = function (prompts, callback) {
|
||||
var fn;
|
||||
var one;
|
||||
var invalid;
|
||||
var runned;
|
||||
var error;
|
||||
var validPrompts = Logger._validPrompts;
|
||||
|
||||
if (!Array.isArray(prompts)) {
|
||||
prompts.name = 'prompt';
|
||||
prompts = [prompts];
|
||||
one = true;
|
||||
}
|
||||
|
||||
// Validate prompt types
|
||||
invalid = prompts.some(function (prompt) {
|
||||
return validPrompts.indexOf(prompt.type) === -1;
|
||||
});
|
||||
|
||||
if (invalid) {
|
||||
error = new Error('Unknown prompt type');
|
||||
error.code = 'ENOTSUP';
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
fn = function (answers) {
|
||||
// Run callback only once
|
||||
if (runned) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trim answers automatically
|
||||
Object.keys(answers).forEach(function (key) {
|
||||
var value = answers[key];
|
||||
|
||||
if (typeof value === 'string') {
|
||||
answers[key] = value.trim();
|
||||
} else if (Array.isArray(value)) {
|
||||
answers[key] = value.map(function (item) {
|
||||
if (typeof item === 'string') {
|
||||
return item.trim();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
runned = true;
|
||||
|
||||
// If only one prompt was requested, resolve with its answer
|
||||
if (one) {
|
||||
answers = answers.prompt;
|
||||
}
|
||||
|
||||
callback(null, answers);
|
||||
};
|
||||
|
||||
this.emit('prompt', prompts, fn);
|
||||
};
|
||||
|
||||
// ------------------
|
||||
|
||||
Logger._validPrompts = [
|
||||
'input',
|
||||
'confirm',
|
||||
'password',
|
||||
'checkbox'
|
||||
];
|
||||
|
||||
Logger.LEVELS = {
|
||||
'error': 5,
|
||||
'conflict': 4,
|
||||
'warn': 3,
|
||||
'action': 2,
|
||||
'info': 1,
|
||||
'debug': 0
|
||||
};
|
||||
|
||||
// Add helpful log methods
|
||||
Object.keys(Logger.LEVELS).forEach(function (level) {
|
||||
Logger.prototype[level] = function (id, message, data) {
|
||||
this.log(level, id, message, data);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = Logger;
|
||||
27
packages/bower-logger/package.json
Normal file
27
packages/bower-logger/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "bower-logger",
|
||||
"version": "0.2.1",
|
||||
"description": "The logger used in the various architecture components of Bower.",
|
||||
"author": "Bower",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/bower/logger/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"repository": "https://github.com/bower/bower/tree/master/packages/bower-logger",
|
||||
"main": "lib/Logger",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.2.0",
|
||||
"mocha": "~1.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
389
packages/bower-logger/test/test.js
Normal file
389
packages/bower-logger/test/test.js
Normal file
@@ -0,0 +1,389 @@
|
||||
var expect = require('expect.js');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Logger = require('../');
|
||||
|
||||
describe('Logger', function () {
|
||||
var logger;
|
||||
|
||||
beforeEach(function () {
|
||||
logger = new Logger();
|
||||
});
|
||||
|
||||
describe('.constructor', function () {
|
||||
it('should provide an instance of Logger', function () {
|
||||
expect(logger instanceof Logger).to.be(true);
|
||||
});
|
||||
|
||||
it('should provide an instance of EventEmitter', function () {
|
||||
expect(logger instanceof EventEmitter).to.be(true);
|
||||
});
|
||||
|
||||
it('should have prototype methods', function () {
|
||||
var methods = [
|
||||
'intercept', 'pipe', 'geminate', 'log'
|
||||
];
|
||||
|
||||
methods.forEach(function (method) {
|
||||
expect(logger).to.have.property(method);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('events', function () {
|
||||
var logData = {
|
||||
foo: 'bar',
|
||||
baz: 'string'
|
||||
};
|
||||
|
||||
it('should pass through {}', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.info();
|
||||
});
|
||||
|
||||
it('should pass through logData', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.data).to.eql(logData);
|
||||
next();
|
||||
});
|
||||
logger.info('foo', 'message', logData);
|
||||
});
|
||||
|
||||
it('should emit error event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('error');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('error message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.error('foo', 'error message');
|
||||
});
|
||||
|
||||
it('should emit conflict event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('conflict');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('conflict message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.conflict('foo', 'conflict message');
|
||||
});
|
||||
|
||||
it('should emit warn event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('warn');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('warn message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.warn('foo', 'warn message');
|
||||
});
|
||||
|
||||
it('should emit action event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('action');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('action message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.action('foo', 'action message');
|
||||
});
|
||||
|
||||
it('should emit info event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('info');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('info message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.info('foo', 'info message');
|
||||
});
|
||||
|
||||
it('should emit debug event', function (next) {
|
||||
logger.on('log', function (log) {
|
||||
expect(log.level).to.eql('debug');
|
||||
expect(log.id).to.eql('foo');
|
||||
expect(log.message).to.eql('debug message');
|
||||
expect(log.data).to.eql({});
|
||||
next();
|
||||
});
|
||||
logger.debug('foo', 'debug message');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.intercept', function () {
|
||||
it('should add the function and call it when a log occurs', function (next) {
|
||||
var called;
|
||||
var data = {
|
||||
'some': 'thing'
|
||||
};
|
||||
|
||||
logger.intercept(function (log) {
|
||||
called = true;
|
||||
|
||||
expect(log).to.eql({
|
||||
level: 'warn',
|
||||
id: 'foo',
|
||||
message: 'bar',
|
||||
data: data
|
||||
});
|
||||
expect(log.data).to.equal(data);
|
||||
});
|
||||
|
||||
logger.log('warn', 'foo', 'bar', data);
|
||||
|
||||
expect(called).to.be(true);
|
||||
next();
|
||||
});
|
||||
|
||||
it('should call the interceptors by order before emitting the event', function (next) {
|
||||
var called = [];
|
||||
|
||||
logger.intercept(function () {
|
||||
called.push(1);
|
||||
});
|
||||
logger.intercept(function () {
|
||||
called.push(2);
|
||||
});
|
||||
|
||||
logger.log('warn', 'foo', 'bar');
|
||||
|
||||
expect(called).to.eql([1, 2]);
|
||||
next();
|
||||
});
|
||||
|
||||
it('should call the interceptors along the chain', function (next) {
|
||||
var called = [];
|
||||
var childLogger = logger.geminate();
|
||||
|
||||
childLogger.intercept(function () {
|
||||
called.push(1);
|
||||
});
|
||||
logger.intercept(function () {
|
||||
called.push(3);
|
||||
});
|
||||
|
||||
childLogger.on('log', function () {
|
||||
called.push(2);
|
||||
});
|
||||
logger.on('log', function () {
|
||||
called.push(4);
|
||||
});
|
||||
|
||||
childLogger.log('warn', 'foo', 'bar');
|
||||
|
||||
expect(called).to.eql([1, 2, 3, 4]);
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.pipe', function () {
|
||||
it('should return the passed emitter', function () {
|
||||
var otherEmitter = new EventEmitter();
|
||||
expect(logger.pipe(otherEmitter)).to.equal(otherEmitter);
|
||||
});
|
||||
|
||||
it('should pipe log events to another emitter', function (next) {
|
||||
var otherEmitter = new EventEmitter();
|
||||
var data = {
|
||||
'some': 'thing'
|
||||
};
|
||||
var piped;
|
||||
|
||||
logger.pipe(otherEmitter);
|
||||
|
||||
otherEmitter.on('log', function (log) {
|
||||
piped = true;
|
||||
expect(log).to.eql({
|
||||
level: 'warn',
|
||||
id: 'foo',
|
||||
message: 'bar',
|
||||
data: data
|
||||
});
|
||||
});
|
||||
|
||||
logger.log('warn', 'foo', 'bar', data);
|
||||
|
||||
expect(piped).to.be(true);
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.geminate', function () {
|
||||
it('should return a new logger instance', function () {
|
||||
var newLogger = logger.geminate();
|
||||
|
||||
expect(newLogger).to.be.an(Logger);
|
||||
expect(newLogger).to.be.an(EventEmitter);
|
||||
expect(newLogger).to.not.be.equal(logger);
|
||||
});
|
||||
|
||||
it('should pipe the new logger events to the original logger', function (next) {
|
||||
var piped = [];
|
||||
var childLogger = logger.geminate();
|
||||
var data = {
|
||||
'some': 'thing'
|
||||
};
|
||||
|
||||
childLogger.on('log', function (log) {
|
||||
piped.push(1);
|
||||
expect(log).to.eql({
|
||||
level: 'warn',
|
||||
id: 'foo',
|
||||
message: 'bar',
|
||||
data: data
|
||||
});
|
||||
expect(log.data).to.equal(data);
|
||||
});
|
||||
|
||||
logger.on('log', function (log) {
|
||||
piped.push(2);
|
||||
expect(log).to.eql({
|
||||
level: 'warn',
|
||||
id: 'foo',
|
||||
message: 'bar',
|
||||
data: data
|
||||
});
|
||||
expect(log.data).to.equal(data);
|
||||
});
|
||||
|
||||
childLogger.log('warn', 'foo', 'bar', data);
|
||||
expect(piped).to.eql([1, 2]);
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prompt', function () {
|
||||
it('should only allow calling the callback once', function () {
|
||||
var calls = 0;
|
||||
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({ prompt: 'bar' });
|
||||
callback({ prompt: 'foo' });
|
||||
})
|
||||
.prompt({
|
||||
type: 'input',
|
||||
message: 'foo'
|
||||
}, function () {
|
||||
calls += 1;
|
||||
});
|
||||
|
||||
expect(calls).to.equal(1);
|
||||
});
|
||||
|
||||
it('should accept a prompt', function (next) {
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({
|
||||
prompt: 'bar'
|
||||
});
|
||||
})
|
||||
.prompt({
|
||||
type: 'input',
|
||||
message: 'foo'
|
||||
}, function (err, answer) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(answer).to.equal('bar');
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
it('should accept several prompts', function (next) {
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({
|
||||
foo: 'bar',
|
||||
foz: 'baz'
|
||||
});
|
||||
})
|
||||
.prompt([
|
||||
{
|
||||
name: 'foo',
|
||||
type: 'input',
|
||||
message: 'foo'
|
||||
},
|
||||
{
|
||||
name: 'foz',
|
||||
type: 'confirm',
|
||||
message: 'foz'
|
||||
}
|
||||
], function (err, answer) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(answer.foo).to.equal('bar');
|
||||
expect(answer.foz).to.equal('baz');
|
||||
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({
|
||||
foo: 'bar'
|
||||
});
|
||||
})
|
||||
.prompt([
|
||||
{
|
||||
name: 'foo',
|
||||
type: 'input',
|
||||
message: 'foo'
|
||||
}
|
||||
], function (err, answer) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(answer.foo).to.equal('bar');
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should error on invalid prompt type', function (next) {
|
||||
logger.prompt({
|
||||
type: 'xxx',
|
||||
message: 'foo'
|
||||
}, function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.be('ENOTSUP');
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim the answers', function (next) {
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({
|
||||
prompt: ' bar '
|
||||
});
|
||||
})
|
||||
.prompt({
|
||||
type: 'input',
|
||||
message: 'foo'
|
||||
}, function (err, answer) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(answer).to.equal('bar');
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
it('should trim multiple response answers', function (next) {
|
||||
logger
|
||||
.once('prompt', function (prompts, callback) {
|
||||
callback({
|
||||
prompt: [' bar ', ' foo', 'baz ']
|
||||
});
|
||||
})
|
||||
.prompt({
|
||||
type: 'checkbox',
|
||||
message: 'foo'
|
||||
}, function (err, answer) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(answer).to.eql(['bar', 'foo', 'baz']);
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
12
packages/bower-registry-client/.editorconfig
Normal file
12
packages/bower-registry-client/.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
2
packages/bower-registry-client/.gitignore
vendored
Normal file
2
packages/bower-registry-client/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/npm-debug.*
|
||||
61
packages/bower-registry-client/.jshintrc
Normal file
61
packages/bower-registry-client/.jshintrc
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"describe",
|
||||
"it",
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach"
|
||||
],
|
||||
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": "vars",
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"trailing": true,
|
||||
"camelcase": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": true,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"white": true
|
||||
}
|
||||
6
packages/bower-registry-client/.travis.yml
Normal file
6
packages/bower-registry-client/.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- 'iojs'
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
70
packages/bower-registry-client/Client.js
Normal file
70
packages/bower-registry-client/Client.js
Normal file
@@ -0,0 +1,70 @@
|
||||
var async = require('async');
|
||||
var methods = require('./lib');
|
||||
var Cache = require('./lib/util/Cache');
|
||||
|
||||
function RegistryClient(config, logger) {
|
||||
this._logger = logger;
|
||||
this._config = config;
|
||||
|
||||
if (!this._config.registry) {
|
||||
throw new Error("You need to pass config as read by bower-config module. Registry field is missing.");
|
||||
}
|
||||
|
||||
// Cache defaults to storage registry
|
||||
if (!Object.prototype.hasOwnProperty.call(this._config, 'cache')) {
|
||||
this._config.cache = this._config.storage ? this._config.storage.registry : null;
|
||||
}
|
||||
|
||||
// Init the cache
|
||||
this._initCache();
|
||||
}
|
||||
|
||||
// Add every method to the prototype
|
||||
RegistryClient.prototype.lookup = methods.lookup;
|
||||
RegistryClient.prototype.search = methods.search;
|
||||
RegistryClient.prototype.list = methods.list;
|
||||
RegistryClient.prototype.register = methods.register;
|
||||
RegistryClient.prototype.unregister = methods.unregister;
|
||||
|
||||
RegistryClient.prototype.clearCache = function (name, callback) {
|
||||
if (typeof name === 'function') {
|
||||
callback = name;
|
||||
name = null;
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
this.lookup.clearCache.bind(this, name),
|
||||
this.search.clearCache.bind(this, name),
|
||||
this.list.clearCache.bind(this)
|
||||
], callback);
|
||||
};
|
||||
|
||||
RegistryClient.prototype.resetCache = function (name) {
|
||||
this.lookup.resetCache.call(this, name);
|
||||
this.search.resetCache.call(this, name);
|
||||
this.list.resetCache.call(this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
RegistryClient.clearRuntimeCache = function () {
|
||||
Cache.clearRuntimeCache();
|
||||
};
|
||||
|
||||
// -----------------------------
|
||||
|
||||
RegistryClient.prototype._initCache = function () {
|
||||
var cache;
|
||||
var dir = this._config.cache;
|
||||
|
||||
// Cache is stored/retrieved statically to ensure singularity
|
||||
// among instances
|
||||
cache = this.constructor._cache = this.constructor._cache || {};
|
||||
this._cache = cache[dir] = cache[dir] || {};
|
||||
|
||||
this.lookup.initCache.call(this);
|
||||
this.search.initCache.call(this);
|
||||
this.list.initCache.call(this);
|
||||
};
|
||||
|
||||
module.exports = RegistryClient;
|
||||
47
packages/bower-registry-client/Gruntfile.js
Normal file
47
packages/bower-registry-client/Gruntfile.js
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
module.exports = function (grunt) {
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-simple-mocha');
|
||||
|
||||
grunt.initConfig({
|
||||
jshint: {
|
||||
files: [
|
||||
'Gruntfile.js',
|
||||
'lib/**/*.js',
|
||||
'test/**/*.js'
|
||||
],
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
}
|
||||
},
|
||||
simplemocha: {
|
||||
options: {
|
||||
reporter: 'spec',
|
||||
timeout: 20000
|
||||
},
|
||||
full: {
|
||||
src: ['test/runner.js']
|
||||
},
|
||||
short: {
|
||||
options: {
|
||||
reporter: 'dot'
|
||||
},
|
||||
src: ['test/runner.js']
|
||||
},
|
||||
build: {
|
||||
options: {
|
||||
reporter: 'tap'
|
||||
},
|
||||
src: ['test/runner.js']
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
files: ['<%= jshint.files %>'],
|
||||
tasks: ['jshint', 'simplemocha:short']
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['simplemocha:full']);
|
||||
grunt.registerTask('default', ['jshint', 'test']);
|
||||
};
|
||||
19
packages/bower-registry-client/LICENSE
Normal file
19
packages/bower-registry-client/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
155
packages/bower-registry-client/README.md
Normal file
155
packages/bower-registry-client/README.md
Normal file
@@ -0,0 +1,155 @@
|
||||
# bower-registry-client [](https://travis-ci.org/bower/registry-client)
|
||||
|
||||
> Provides easy interaction with the Bower registry
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save bower-registry-client
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var RegistryClient = require('bower-registry-client');
|
||||
var Config = require('bower-config');
|
||||
var config = Config.read(process.cwd(), options);
|
||||
var registry = new RegistryClient(config, logger);
|
||||
```
|
||||
|
||||
The `logger` is optional and is expected to be an instance of the bower [logger](https://github.com/bower/logger).
|
||||
Available constructor options:
|
||||
|
||||
- `cache`: the cache folder to use for some operations; using null will disable persistent cache (defaults to bower registry cache folder)
|
||||
- `registry.search`: an array of registry search endpoints (defaults to the Bower server)
|
||||
- `registry.register`: the endpoint to use when registering packages (defaults to the Bower server)
|
||||
- `registry.publish`: the endpoint to use when publishing packages (defaults to the Bower server)
|
||||
- `ca.search`: an array of CA certificates for each registry.search (defaults to null).
|
||||
- `ca.register`: the CA certificate for registry.register
|
||||
- `ca.publish`: the CA certificate for registry.publish
|
||||
- `proxy`: the proxy to use for http requests (defaults to null)
|
||||
- `httpsProxy`: the proxy to use for https requests (defaults to null)
|
||||
- `strictSsl`: whether or not to do SSL key validation when making requests via https (defaults to true).
|
||||
- `userAgent`: the user agent to use for the requests (defaults to null)
|
||||
- `timeout`: the timeout for the requests to finish (defaults to 60000)
|
||||
- `force`: If set to true, cache will be bypassed and remotes will always be hit (defaults to false).
|
||||
- `offline`: If set to true, only the cache will be used (defaults to false).
|
||||
|
||||
|
||||
Note that `force` and `offline` are mutually exclusive.
|
||||
The cache will speedup operations such as `list`, `lookup` and `search`.
|
||||
Different operations may have different cache expiration times.
|
||||
|
||||
|
||||
#### .lookup(name, callback)
|
||||
|
||||
Looks the registry for the package `name`,
|
||||
|
||||
```js
|
||||
registry.lookup('jquery', function (err, entry) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// For now resp.type is always 'alias'
|
||||
console.log('type', entry.type);
|
||||
console.log('url', entry.url);
|
||||
});
|
||||
```
|
||||
|
||||
#### .register(name, url, callback)
|
||||
|
||||
Registers a package in the registry.
|
||||
|
||||
```js
|
||||
registry.register('my-package', 'git://github.com/my-org/my-package.git', function (err, pkg) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('name', pkg.name);
|
||||
console.log('url: ', pkg.url);
|
||||
});
|
||||
```
|
||||
|
||||
#### .search(str, callback)
|
||||
|
||||
Searches the registry.
|
||||
|
||||
```js
|
||||
registry.search('jquery', function (err, results) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
results.forEach(function (pkg) {
|
||||
console.log('name', pkg.name);
|
||||
console.log('url', pkg.url);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### .clearCache(name, callback)
|
||||
|
||||
Clears the persistent and runtime cache associated with the `name` package.
|
||||
If `name` is null, clears the cache for every package.
|
||||
|
||||
Note that in most cases, you don't need to clear the cache since it has
|
||||
self expiration times.
|
||||
|
||||
```js
|
||||
// Clear jquery cache
|
||||
registry.clearCache('jquery', function (err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Done');
|
||||
});
|
||||
|
||||
// Clear all cache
|
||||
registry.clearCache(function (err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Done');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
#### .resetCache()
|
||||
|
||||
Clears the in-memory cache used to speed up the instance.
|
||||
|
||||
Note that in most cases, you don't need to clear the runtime cache since it has
|
||||
self expiration times.
|
||||
Might be useful if you use this module in long-living programs.
|
||||
|
||||
```js
|
||||
registry.resetCache();
|
||||
```
|
||||
|
||||
#### #clearRuntimeCache()
|
||||
|
||||
Clears the in-memory cache used to speed up the whole module.
|
||||
This clears the static in-memory cache as well as in-memory cache used by instances.
|
||||
|
||||
Note that in edge cases, some instance's in-memory cache might be skipped.
|
||||
If that's a problem, you should create fresh instances instead.
|
||||
|
||||
```js
|
||||
RegistryClient.clearRuntimeCache();
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
7
packages/bower-registry-client/lib/index.js
Normal file
7
packages/bower-registry-client/lib/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
lookup: require('./lookup'),
|
||||
list: require('./list'),
|
||||
register: require('./register'),
|
||||
search: require('./search'),
|
||||
unregister: require('./unregister')
|
||||
};
|
||||
184
packages/bower-registry-client/lib/list.js
Normal file
184
packages/bower-registry-client/lib/list.js
Normal file
@@ -0,0 +1,184 @@
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
var async = require('async');
|
||||
var request = require('request');
|
||||
var replay = require('request-replay');
|
||||
var Cache = require('./util/Cache');
|
||||
var createError = require('./util/createError');
|
||||
|
||||
function list(callback) {
|
||||
var data = [];
|
||||
var that = this;
|
||||
var registry = this._config.registry.search;
|
||||
var total = registry.length;
|
||||
var index = 0;
|
||||
|
||||
// If no registry entries were passed, simply
|
||||
// error with package not found
|
||||
if (!total) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
// List packages in series in each registry
|
||||
async.doUntil(function (next) {
|
||||
var remote = url.parse(registry[index]);
|
||||
var listCache = that._listCache[remote.host];
|
||||
|
||||
// If offline flag is passed, only query the cache
|
||||
if (that._config.offline) {
|
||||
return listCache.get('list', function (err, results) {
|
||||
if (err || !results) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Add each result
|
||||
results.forEach(function (result) {
|
||||
addResult.call(that, data, result);
|
||||
});
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
// Otherwise make a request to always obtain fresh data
|
||||
doRequest.call(that, index, function (err, results) {
|
||||
if (err || !results) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Add each result
|
||||
results.forEach(function (result) {
|
||||
addResult(data, result);
|
||||
});
|
||||
|
||||
// Store in cache for future offline usage
|
||||
listCache.set('list', results, getMaxAge(), next);
|
||||
});
|
||||
}, function () {
|
||||
// Until there's still registries to test
|
||||
return ++index === total;
|
||||
}, function (err) {
|
||||
// Clear runtime cache, keeping the persistent data
|
||||
// in files for future offline usage
|
||||
resetCache();
|
||||
|
||||
// If some of the registry entries failed, error out
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
function addResult(accumulated, result) {
|
||||
var exists = accumulated.some(function (current) {
|
||||
return current.name === result.name;
|
||||
});
|
||||
|
||||
if (!exists) {
|
||||
accumulated.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
function doRequest(index, callback) {
|
||||
var req;
|
||||
var msg;
|
||||
var requestUrl = this._config.registry.search[index] + '/packages';
|
||||
var remote = url.parse(requestUrl);
|
||||
var headers = {};
|
||||
var that = this;
|
||||
|
||||
if (this._config.userAgent) {
|
||||
headers['User-Agent'] = this._config.userAgent;
|
||||
}
|
||||
|
||||
req = replay(request.get(requestUrl, {
|
||||
ca: this._config.ca.search[index],
|
||||
headers: headers,
|
||||
strictSSL: this._config.strictSsl,
|
||||
timeout: this._config.timeout,
|
||||
json: true
|
||||
}, function (err, response, body) {
|
||||
// If there was an internal error (e.g. timeout)
|
||||
if (err) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed: ' + err.message, err.code));
|
||||
}
|
||||
|
||||
// Abort if there was an error (range different than 2xx)
|
||||
if (response.statusCode < 200 || response.statusCode > 299) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed with ' + response.statusCode, 'EINVRES'));
|
||||
}
|
||||
|
||||
// Validate response body, since we are expecting a JSON object
|
||||
// If the server returns an invalid JSON, it's still a string
|
||||
if (typeof body !== 'object') {
|
||||
return callback(createError('Response of request to ' + requestUrl + ' is not a valid json', 'EINVRES'));
|
||||
}
|
||||
|
||||
callback(null, body);
|
||||
}));
|
||||
|
||||
if (this._logger) {
|
||||
req.on('replay', function (replay) {
|
||||
msg = 'Request to ' + requestUrl + ' failed with ' + replay.error.code + ', ';
|
||||
msg += 'retrying in ' + (replay.delay / 1000).toFixed(1) + 's';
|
||||
that._logger.warn('retry', msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getMaxAge() {
|
||||
// Make it 5 minutes
|
||||
return 5 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
function initCache() {
|
||||
this._listCache = this._cache.list || {};
|
||||
|
||||
// Generate a cache instance for each registry endpoint
|
||||
this._config.registry.search.forEach(function (registry) {
|
||||
var cacheDir;
|
||||
var host = url.parse(registry).host;
|
||||
|
||||
// Skip if there's a cache for the same host
|
||||
if (this._listCache[host]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._config.cache) {
|
||||
cacheDir = path.join(this._config.cache, encodeURIComponent(host), 'list');
|
||||
}
|
||||
|
||||
this._listCache[host] = new Cache(cacheDir, {
|
||||
max: 250,
|
||||
// If offline flag is passed, we use stale entries from the cache
|
||||
useStale: this._config.offline
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
function clearCache(callback) {
|
||||
var listCache = this._listCache;
|
||||
var remotes = Object.keys(listCache);
|
||||
|
||||
// There's only one key, which is 'list'..
|
||||
// But we clear everything anyway
|
||||
async.forEach(remotes, function (remote, next) {
|
||||
listCache[remote].clear(next);
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function resetCache() {
|
||||
var remote;
|
||||
|
||||
for (remote in this._listCache) {
|
||||
this._listCache[remote].reset();
|
||||
}
|
||||
}
|
||||
|
||||
list.initCache = initCache;
|
||||
list.clearCache = clearCache;
|
||||
list.resetCache = resetCache;
|
||||
|
||||
module.exports = list;
|
||||
202
packages/bower-registry-client/lib/lookup.js
Normal file
202
packages/bower-registry-client/lib/lookup.js
Normal file
@@ -0,0 +1,202 @@
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
var async = require('async');
|
||||
var request = require('request');
|
||||
var replay = require('request-replay');
|
||||
var createError = require('./util/createError');
|
||||
var Cache = require('./util/Cache');
|
||||
|
||||
function lookup(name, callback) {
|
||||
var data;
|
||||
var that = this;
|
||||
var registry = this._config.registry.search;
|
||||
var total = registry.length;
|
||||
var index = 0;
|
||||
|
||||
// If no registry entries were passed..
|
||||
if (!total) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Lookup package in series in each registry
|
||||
// endpoint until we got the data
|
||||
async.doUntil(function (next) {
|
||||
var remote = url.parse(registry[index]);
|
||||
var lookupCache = that._lookupCache[remote.host];
|
||||
|
||||
// If force flag is disabled we check the cache
|
||||
if (!that._config.force) {
|
||||
lookupCache.get(name, function (err, value) {
|
||||
data = value;
|
||||
|
||||
// Don't proceed with making a request if we got an error,
|
||||
// a value from the cache or if the offline flag is enabled
|
||||
if (err || data || that._config.offline) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
doRequest.call(that, name, index, function (err, entry) {
|
||||
if (err || !entry) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
data = entry;
|
||||
|
||||
// Store in cache
|
||||
lookupCache.set(name, entry, getMaxAge(entry), next);
|
||||
});
|
||||
});
|
||||
// Otherwise, we totally bypass the cache and
|
||||
// make only the request
|
||||
} else {
|
||||
doRequest.call(that, name, index, function (err, entry) {
|
||||
if (err || !entry) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
data = entry;
|
||||
|
||||
// Store in cache
|
||||
lookupCache.set(name, entry, getMaxAge(entry), next);
|
||||
});
|
||||
}
|
||||
}, function () {
|
||||
// Until the data is unknown or there's still registries to test
|
||||
return !!data || ++index === total;
|
||||
}, function (err) {
|
||||
// If some of the registry entries failed, error out
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
function doRequest(name, index, callback) {
|
||||
var req;
|
||||
var msg;
|
||||
var requestUrl = this._config.registry.search[index] + '/packages/' + encodeURIComponent(name);
|
||||
var remote = url.parse(requestUrl);
|
||||
var headers = {};
|
||||
var that = this;
|
||||
|
||||
if (this._config.userAgent) {
|
||||
headers['User-Agent'] = this._config.userAgent;
|
||||
}
|
||||
|
||||
req = replay(request.get(requestUrl, {
|
||||
headers: headers,
|
||||
ca: this._config.ca.search[index],
|
||||
strictSSL: this._config.strictSsl,
|
||||
timeout: this._config.timeout,
|
||||
json: true
|
||||
}, function (err, response, body) {
|
||||
// If there was an internal error (e.g. timeout)
|
||||
if (err) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed: ' + err.message, err.code));
|
||||
}
|
||||
|
||||
// If not found, try next
|
||||
if (response.statusCode === 404) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Abort if there was an error (range different than 2xx)
|
||||
if (response.statusCode < 200 || response.statusCode > 299) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed with ' + response.statusCode, 'EINVRES'));
|
||||
}
|
||||
|
||||
// Validate response body, since we are expecting a JSON object
|
||||
// If the server returns an invalid JSON, it's still a string
|
||||
if (typeof body !== 'object') {
|
||||
return callback(createError('Response of request to ' + requestUrl + ' is not a valid json', 'EINVRES'));
|
||||
}
|
||||
|
||||
var data;
|
||||
if (body.url) {
|
||||
data = {
|
||||
type: 'alias',
|
||||
url: body.url
|
||||
};
|
||||
}
|
||||
callback(null, data);
|
||||
}));
|
||||
|
||||
if (this._logger) {
|
||||
req.on('replay', function (replay) {
|
||||
msg = 'Request to ' + requestUrl + ' failed with ' + replay.error.code + ', ';
|
||||
msg += 'retrying in ' + (replay.delay / 1000).toFixed(1) + 's';
|
||||
that._logger.warn('retry', msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getMaxAge(entry) {
|
||||
// If type is alias, make it 5 days
|
||||
if (entry.type === 'alias') {
|
||||
return 5 * 24 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
// Otherwise make it 5 minutes
|
||||
return 5 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
function initCache() {
|
||||
this._lookupCache = this._cache.lookup || {};
|
||||
|
||||
// Generate a cache instance for each registry endpoint
|
||||
this._config.registry.search.forEach(function (registry) {
|
||||
var cacheDir;
|
||||
var host = url.parse(registry).host;
|
||||
|
||||
// Skip if there's a cache for the same host
|
||||
if (this._lookupCache[host]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._config.cache) {
|
||||
cacheDir = path.join(this._config.cache, encodeURIComponent(host), 'lookup');
|
||||
}
|
||||
|
||||
this._lookupCache[host] = new Cache(cacheDir, {
|
||||
max: 250,
|
||||
// If offline flag is passed, we use stale entries from the cache
|
||||
useStale: this._config.offline
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
function clearCache(name, callback) {
|
||||
var lookupCache = this._lookupCache;
|
||||
var remotes = Object.keys(lookupCache);
|
||||
|
||||
if (typeof name === 'function') {
|
||||
callback = name;
|
||||
name = null;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
async.forEach(remotes, function (remote, next) {
|
||||
lookupCache[remote].del(name, next);
|
||||
}, callback);
|
||||
} else {
|
||||
async.forEach(remotes, function (remote, next) {
|
||||
lookupCache[remote].clear(next);
|
||||
}, callback);
|
||||
}
|
||||
}
|
||||
|
||||
function resetCache() {
|
||||
var remote;
|
||||
|
||||
for (remote in this._lookupCache) {
|
||||
this._lookupCache[remote].reset();
|
||||
}
|
||||
}
|
||||
|
||||
lookup.initCache = initCache;
|
||||
lookup.clearCache = clearCache;
|
||||
lookup.resetCache = resetCache;
|
||||
|
||||
module.exports = lookup;
|
||||
58
packages/bower-registry-client/lib/register.js
Normal file
58
packages/bower-registry-client/lib/register.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var parseUrl = require('url').parse;
|
||||
var request = require('request');
|
||||
var createError = require('./util/createError');
|
||||
|
||||
function register(name, url, callback) {
|
||||
var config = this._config;
|
||||
var requestUrl = config.registry.register + '/packages';
|
||||
var remote = parseUrl(requestUrl);
|
||||
var headers = {};
|
||||
|
||||
if (config.userAgent) {
|
||||
headers['User-Agent'] = config.userAgent;
|
||||
}
|
||||
|
||||
if (config.accessToken) {
|
||||
requestUrl += '?access_token=' + config.accessToken;
|
||||
}
|
||||
|
||||
request.post({
|
||||
url: requestUrl,
|
||||
headers: headers,
|
||||
ca: config.ca.register,
|
||||
strictSSL: config.strictSsl,
|
||||
timeout: config.timeout,
|
||||
json: true,
|
||||
form: {
|
||||
name: name,
|
||||
url: url
|
||||
}
|
||||
}, function (err, response) {
|
||||
// If there was an internal error (e.g. timeout)
|
||||
if (err) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed: ' + err.message, err.code));
|
||||
}
|
||||
|
||||
// Duplicate
|
||||
if (response.statusCode === 403) {
|
||||
return callback(createError('Duplicate package', 'EDUPLICATE'));
|
||||
}
|
||||
|
||||
// Invalid format
|
||||
if (response.statusCode === 400) {
|
||||
return callback(createError('Invalid URL format', 'EINVFORMAT'));
|
||||
}
|
||||
|
||||
// Everything other than 201 is unknown
|
||||
if (response.statusCode !== 201) {
|
||||
return callback(createError('Unknown error: ' + response.statusCode + ' - ' + response.body, 'EUNKNOWN'));
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
name: name,
|
||||
url: url
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = register;
|
||||
200
packages/bower-registry-client/lib/search.js
Normal file
200
packages/bower-registry-client/lib/search.js
Normal file
@@ -0,0 +1,200 @@
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
var async = require('async');
|
||||
var request = require('request');
|
||||
var replay = require('request-replay');
|
||||
var Cache = require('./util/Cache');
|
||||
var createError = require('./util/createError');
|
||||
|
||||
// TODO:
|
||||
// The search cache simply stores a specific search result
|
||||
// into a file. This is a very rudimentary algorithm but
|
||||
// works to support elementary offline support
|
||||
// Once the registry server is rewritten, a better strategy
|
||||
// can be implemented (with diffs and local search), similar to npm.
|
||||
|
||||
function search(name, callback) {
|
||||
var data = [];
|
||||
var that = this;
|
||||
var registry = this._config.registry.search;
|
||||
var total = registry.length;
|
||||
var index = 0;
|
||||
|
||||
// If no registry entries were passed, simply
|
||||
// error with package not found
|
||||
if (!total) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
// Search package in series in each registry,
|
||||
// merging results together
|
||||
async.doUntil(function (next) {
|
||||
var remote = url.parse(registry[index]);
|
||||
var searchCache = that._searchCache[remote.host];
|
||||
|
||||
// If offline flag is passed, only query the cache
|
||||
if (that._config.offline) {
|
||||
return searchCache.get(name, function (err, results) {
|
||||
if (err || !results || !results.length) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Add each result
|
||||
results.forEach(function (result) {
|
||||
addResult.call(that, data, result);
|
||||
});
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
// Otherwise make a request to always obtain fresh data
|
||||
doRequest.call(that, name, index, function (err, results) {
|
||||
if (err || !results || !results.length) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Add each result
|
||||
results.forEach(function (result) {
|
||||
addResult.call(that, data, result);
|
||||
});
|
||||
|
||||
// Store in cache for future offline usage
|
||||
searchCache.set(name, results, getMaxAge(), next);
|
||||
});
|
||||
}, function () {
|
||||
// Until the data is unknown or there's still registries to test
|
||||
return ++index === total;
|
||||
}, function (err) {
|
||||
// Clear runtime cache, keeping the persistent data
|
||||
// in files for future offline usage
|
||||
resetCache();
|
||||
|
||||
// If some of the registry entries failed, error out
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
function addResult(accumulated, result) {
|
||||
var exists = accumulated.some(function (current) {
|
||||
return current.name === result.name;
|
||||
});
|
||||
|
||||
if (!exists) {
|
||||
accumulated.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
function doRequest(name, index, callback) {
|
||||
var req;
|
||||
var msg;
|
||||
var requestUrl = this._config.registry.search[index] + '/packages/search/' + encodeURIComponent(name);
|
||||
var remote = url.parse(requestUrl);
|
||||
var headers = {};
|
||||
var that = this;
|
||||
|
||||
if (this._config.userAgent) {
|
||||
headers['User-Agent'] = this._config.userAgent;
|
||||
}
|
||||
|
||||
req = replay(request.get(requestUrl, {
|
||||
headers: headers,
|
||||
ca: this._config.ca.search[index],
|
||||
strictSSL: this._config.strictSsl,
|
||||
timeout: this._config.timeout,
|
||||
json: true
|
||||
}, function (err, response, body) {
|
||||
// If there was an internal error (e.g. timeout)
|
||||
if (err) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed: ' + err.message, err.code));
|
||||
}
|
||||
|
||||
// Abort if there was an error (range different than 2xx)
|
||||
if (response.statusCode < 200 || response.statusCode > 299) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed with ' + response.statusCode, 'EINVRES'));
|
||||
}
|
||||
|
||||
// Validate response body, since we are expecting a JSON object
|
||||
// If the server returns an invalid JSON, it's still a string
|
||||
if (typeof body !== 'object') {
|
||||
return callback(createError('Response of request to ' + requestUrl + ' is not a valid json', 'EINVRES'));
|
||||
}
|
||||
|
||||
callback(null, body);
|
||||
}));
|
||||
|
||||
if (this._logger) {
|
||||
req.on('replay', function (replay) {
|
||||
msg = 'Request to ' + requestUrl + ' failed with ' + replay.error.code + ', ';
|
||||
msg += 'retrying in ' + (replay.delay / 1000).toFixed(1) + 's';
|
||||
that._logger.warn('retry', msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getMaxAge() {
|
||||
// Make it 5 minutes
|
||||
return 5 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
function initCache() {
|
||||
this._searchCache = this._cache.search || {};
|
||||
|
||||
// Generate a cache instance for each registry endpoint
|
||||
this._config.registry.search.forEach(function (registry) {
|
||||
var cacheDir;
|
||||
var host = url.parse(registry).host;
|
||||
|
||||
// Skip if there's a cache for the same host
|
||||
if (this._searchCache[host]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._config.cache) {
|
||||
cacheDir = path.join(this._config.cache, encodeURIComponent(host), 'search');
|
||||
}
|
||||
|
||||
this._searchCache[host] = new Cache(cacheDir, {
|
||||
max: 250,
|
||||
// If offline flag is passed, we use stale entries from the cache
|
||||
useStale: this._config.offline
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
function clearCache(name, callback) {
|
||||
var searchCache = this._searchCache;
|
||||
var remotes = Object.keys(searchCache);
|
||||
|
||||
if (typeof name === 'function') {
|
||||
callback = name;
|
||||
name = null;
|
||||
}
|
||||
|
||||
// Simply erase everything since other searches could
|
||||
// contain the "name" package
|
||||
// One possible solution would be to read every entry from the cache and
|
||||
// delete if the package is contained in the search results
|
||||
// But this is too expensive
|
||||
async.forEach(remotes, function (remote, next) {
|
||||
searchCache[remote].clear(next);
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function resetCache() {
|
||||
var remote;
|
||||
|
||||
for (remote in this._searchCache) {
|
||||
this._searchCache[remote].reset();
|
||||
}
|
||||
}
|
||||
|
||||
search.initCache = initCache;
|
||||
search.clearCache = clearCache;
|
||||
search.resetCache = resetCache;
|
||||
|
||||
module.exports = search;
|
||||
47
packages/bower-registry-client/lib/unregister.js
Normal file
47
packages/bower-registry-client/lib/unregister.js
Normal file
@@ -0,0 +1,47 @@
|
||||
var parseUrl = require('url').parse;
|
||||
var request = require('request');
|
||||
var createError = require('./util/createError');
|
||||
|
||||
function unregister(name, callback) {
|
||||
var config = this._config;
|
||||
var requestUrl = config.registry.register + '/packages/' + name;
|
||||
var remote = parseUrl(requestUrl);
|
||||
var headers = {};
|
||||
|
||||
if (config.userAgent) {
|
||||
headers['User-Agent'] = config.userAgent;
|
||||
}
|
||||
|
||||
if (config.accessToken) {
|
||||
requestUrl += '?access_token=' + config.accessToken;
|
||||
}
|
||||
|
||||
request.del({
|
||||
url: requestUrl,
|
||||
headers: headers,
|
||||
ca: config.ca.register,
|
||||
strictSSL: config.strictSsl,
|
||||
timeout: config.timeout
|
||||
}, function (err, response) {
|
||||
// If there was an internal error (e.g. timeout)
|
||||
if (err) {
|
||||
return callback(createError('Request to ' + requestUrl + ' failed: ' + err.message, err.code));
|
||||
}
|
||||
|
||||
// Forbidden
|
||||
if (response.statusCode === 403) {
|
||||
return callback(createError(response.body, 'EFORBIDDEN'));
|
||||
}
|
||||
|
||||
// Everything other than 204 is unknown
|
||||
if (response.statusCode !== 204) {
|
||||
return callback(createError(response.body, 'EUNKNOWN'));
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
name: name
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = unregister;
|
||||
195
packages/bower-registry-client/lib/util/Cache.js
Normal file
195
packages/bower-registry-client/lib/util/Cache.js
Normal file
@@ -0,0 +1,195 @@
|
||||
var fs = require('graceful-fs');
|
||||
var path = require('path');
|
||||
var async = require('async');
|
||||
var mkdirp = require('mkdirp');
|
||||
var LRU = require('lru-cache');
|
||||
var md5 = require('./md5');
|
||||
|
||||
function Cache(dir, options) {
|
||||
options = options || {};
|
||||
|
||||
this._dir = dir;
|
||||
this._options = options;
|
||||
this._cache = this.constructor._cache.get(this._dir);
|
||||
|
||||
if (!this._cache) {
|
||||
this._cache = new LRU(options);
|
||||
this.constructor._cache.set(this._dir, this._cache);
|
||||
}
|
||||
|
||||
if (dir) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
}
|
||||
|
||||
Cache.prototype.get = function (key, callback) {
|
||||
var file;
|
||||
var json = this._cache.get(key);
|
||||
|
||||
// Check in memory
|
||||
if (json) {
|
||||
if (this._hasExpired(json)) {
|
||||
this.del(key, callback);
|
||||
} else {
|
||||
callback(null, json.value);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check in disk
|
||||
if (!this._dir) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
file = this._getFile(key);
|
||||
fs.readFile(file, function (err, contents) {
|
||||
var json;
|
||||
|
||||
// Check if there was an error reading
|
||||
// Note that if the file does not exist then
|
||||
// we don't have its value
|
||||
if (err) {
|
||||
return callback(err.code === 'ENOENT' ? null : err);
|
||||
}
|
||||
|
||||
// If there was an error reading the file as json
|
||||
// simply assume it doesn't exist
|
||||
try {
|
||||
json = JSON.parse(contents.toString());
|
||||
} catch (e) {
|
||||
return this.del(key, callback); // If so, delete it
|
||||
}
|
||||
|
||||
// Check if it has expired
|
||||
if (this._hasExpired(json)) {
|
||||
return this.del(key, callback);
|
||||
}
|
||||
|
||||
this._cache.set(key, json);
|
||||
callback(null, json.value);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Cache.prototype.set = function (key, value, maxAge, callback) {
|
||||
var file;
|
||||
var entry;
|
||||
var str;
|
||||
|
||||
maxAge = maxAge != null ? maxAge : this._options.maxAge;
|
||||
entry = {
|
||||
expires: maxAge ? Date.now() + maxAge : null,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Store in memory
|
||||
this._cache.set(key, entry);
|
||||
|
||||
// Store in disk
|
||||
if (!this._dir) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
// If there was an error generating the json
|
||||
// then there's some cyclic reference or some other issue
|
||||
try {
|
||||
str = JSON.stringify(entry);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
file = this._getFile(key);
|
||||
fs.writeFile(file, str, callback);
|
||||
};
|
||||
|
||||
Cache.prototype.del = function (key, callback) {
|
||||
// Delete from memory
|
||||
this._cache.del(key);
|
||||
|
||||
// Delete from disk
|
||||
if (!this._dir) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
fs.unlink(this._getFile(key), function (err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
Cache.prototype.clear = function (callback) {
|
||||
var dir = this._dir;
|
||||
|
||||
// Clear in memory cache
|
||||
this._cache.reset();
|
||||
|
||||
// Clear everything from the disk
|
||||
if (!dir) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
fs.readdir(dir, function (err, files) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Delete every file in parallel
|
||||
async.forEach(files, function (file, next) {
|
||||
fs.unlink(path.join(dir, file), function (err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Cache.prototype.reset = function () {
|
||||
this._cache.reset();
|
||||
};
|
||||
|
||||
Cache.clearRuntimeCache = function () {
|
||||
// Note that _cache refers to the static _cache variable
|
||||
// that holds other caches per dir!
|
||||
// Do not confuse it with the instance cache
|
||||
|
||||
// Clear cache of each directory
|
||||
this._cache.forEach(function (cache) {
|
||||
cache.reset();
|
||||
});
|
||||
|
||||
// Clear root cache
|
||||
this._cache.reset();
|
||||
};
|
||||
|
||||
//-------------------------------
|
||||
|
||||
Cache.prototype._hasExpired = function (json) {
|
||||
var expires = json.expires;
|
||||
|
||||
if (!expires || this._options.useStale) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the key has expired
|
||||
return Date.now() > expires;
|
||||
};
|
||||
|
||||
Cache.prototype._getFile = function (key) {
|
||||
// Append a truncated md5 to the end of the file to solve case issues
|
||||
// on case insensitive file systems
|
||||
// See: https://github.com/bower/bower/issues/859
|
||||
return path.join(this._dir, encodeURIComponent(key) + '_' + md5(key).substr(0, 5));
|
||||
};
|
||||
|
||||
Cache._cache = new LRU({
|
||||
max: 5,
|
||||
maxAge: 60 * 30 * 1000 // 30 minutes
|
||||
});
|
||||
|
||||
module.exports = Cache;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user