Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 085d512

Browse filesBrowse files
committed
pin ranged dependencies to an installed version
0 parents  commit 085d512
Copy full SHA for 085d512

File tree

Expand file treeCollapse file tree

9 files changed

+327
-0
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+327
-0
lines changed

‎.gitignore

Copy file name to clipboard
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sql
27+
*.sqlite
28+
29+
# OS generated files #
30+
######################
31+
.DS_Store*
32+
ehthumbs.db
33+
Icon?
34+
Thumbs.db
35+
36+
# Node.js #
37+
###########
38+
lib-cov
39+
*.seed
40+
*.log
41+
*.csv
42+
*.dat
43+
*.out
44+
*.pid
45+
*.gz
46+
47+
pids
48+
logs
49+
results
50+
51+
node_modules
52+
npm-debug.log
53+
54+
# Git #
55+
#######
56+
*.orig
57+
*.BASE.*
58+
*.BACKUP.*
59+
*.LOCAL.*
60+
*.REMOTE.*
61+
62+
# Components #
63+
##############
64+
65+
/build
66+
/components
67+
component.json

‎.npmignore

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

‎.travis.yml

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
- "0.11"

‎Makefile

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
BIN = ./node_modules/.bin/
2+
NODE ?= node
3+
SRC = $(shell find lib -name "*.js")
4+
BUILD = $(subst lib,build,$(SRC))
5+
6+
build: $(BUILD)
7+
8+
build/%.js: lib/%.js
9+
@mkdir -p build
10+
@$(BIN)regenerator --include-runtime $< > $@
11+
12+
clean:
13+
@rm -rf build
14+
15+
test:
16+
@$(NODE) $(BIN)mocha \
17+
--harmony-generators \
18+
--require should \
19+
--reporter spec \
20+
--timeout 30s \
21+
--bail
22+
23+
.PHONY: test clean

‎README.md

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Component Pin
2+
3+
Pin your ranged dependencies to the latest installed version.
4+
5+
## API
6+
7+
### pin(tree, options, callback)
8+
9+
Note: you need to wrap `pin` with `co`.
10+
11+
```js
12+
var co = require('co');
13+
var pin = co(require('component-pin'));
14+
var resolve = require('component-resolve');
15+
16+
resolve(process.cwd(), function (err, tree) {
17+
pin(tree, function (err) {
18+
// everything is pinned!
19+
})
20+
})
21+
```
22+
23+
## License
24+
25+
(The MIT License)
26+
27+
Copyright (c) 2014 segmentio &lt;team@segment.io&gt;
28+
29+
Permission is hereby granted, free of charge, to any person obtaining
30+
a copy of this software and associated documentation files (the
31+
'Software'), to deal in the Software without restriction, including
32+
without limitation the rights to use, copy, modify, merge, publish,
33+
distribute, sublicense, and/or sell copies of the Software, and to
34+
permit persons to whom the Software is furnished to do so, subject to
35+
the following conditions:
36+
37+
The above copyright notice and this permission notice shall be
38+
included in all copies or substantial portions of the Software.
39+
40+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
41+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
44+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
45+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎index.js

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = require('generator-supported')
2+
? require('./lib')
3+
: require('./build');

‎lib/index.js

Copy file name to clipboard
+88Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
var flatten = require('component-flatten');
3+
var utils = require('component-consoler');
4+
var remotes = require('remotes');
5+
var write = require('fs').writeFile;
6+
var semver = require('semver');
7+
var fs = require('fs');
8+
9+
var log = utils.log;
10+
11+
module.exports = function* (tree, options) {
12+
options = options || {};
13+
var verbose = options.verbose;
14+
15+
var fns = [];
16+
var start = Date.now();
17+
if (verbose) log('pin', 'pinning ' + tree.name + '\'s ranged dependencies');
18+
19+
var remote = remotes.local(options);
20+
21+
flatten(tree)
22+
.filter(isLocal)
23+
.forEach(function (node) { fns.push(function* () {
24+
var component;
25+
var json = node.node;
26+
var fns = [];
27+
var updates = [];
28+
29+
push(json.dependencies || {}, false);
30+
push((json.development || {}).dependencies || {}, true);
31+
32+
yield fns;
33+
34+
if (!updates.length) return;
35+
36+
component = yield* read(node.filename);
37+
updates.forEach(call);
38+
39+
yield write.bind(null, node.filename, JSON.stringify(component, null, 2));
40+
41+
function push(deps, dev) {
42+
Object.keys(deps).forEach(function (name) {
43+
var version = deps[name];
44+
if (!isRange(version)) return;
45+
46+
fns.push(function* () {
47+
var versions = yield* remote.versions(name);
48+
// no version to pin, ex. uses a branch
49+
if (!versions || !versions.length) return;
50+
51+
var latest = semver.maxSatisfying(versions, version);
52+
53+
updates.push(function () {
54+
// to do: backwards compatibility
55+
var dep = dev
56+
? component.development.dependencies
57+
: component.dependencies;
58+
dep[name] = latest;
59+
60+
if (verbose) log('pin', node.name + '\'s dependency "' + name + '" from "' + version + '" to "' + latest + '".');
61+
});
62+
});
63+
});
64+
}
65+
})})
66+
67+
yield fns;
68+
69+
if (verbose) log('pin', 'pinned ' + tree.name + '\'s ranged dependencies in ' + (Date.now() - start) + 'ms');
70+
}
71+
72+
function isLocal(node) {
73+
return node.type === 'local';
74+
}
75+
76+
function isRange(x) {
77+
return semver.validRange(x)
78+
&& !semver.valid(x);
79+
}
80+
81+
function call(fn) {
82+
fn();
83+
}
84+
85+
function* read(filename) {
86+
var string = yield fs.readFile.bind(null, filename, 'utf8');
87+
return JSON.parse(string);
88+
}

‎package.json

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "component-pin",
3+
"description": "pin ranged dependencies to an installed version",
4+
"version": "1.0.0",
5+
"author": {
6+
"name": "Jonathan Ong",
7+
"email": "me@jongleberry.com",
8+
"url": "http://jongleberry.com",
9+
"twitter": "https://twitter.com/jongleberry"
10+
},
11+
"license": "MIT",
12+
"repository": "component/pin.js",
13+
"dependencies": {
14+
"generator-supported": "~0.0.1",
15+
"component-consoler": "^1.0.0",
16+
"component-flatten": "^1.0.0",
17+
"remotes": "^1.0.0",
18+
"semver": "^2.2.1",
19+
"co": "^3"
20+
},
21+
"devDependencies": {
22+
"rimraf": "^2.2.5",
23+
"mocha": "^1.17.0",
24+
"should": "^3.0.0",
25+
"gnode": "0",
26+
"regenerator": "0"
27+
},
28+
"scripts": {
29+
"test": "NODE=gnode make test",
30+
"prepublish": "make clean build"
31+
}
32+
}

‎test/index.js

Copy file name to clipboard
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
var resolve = require('component-resolver');
3+
var assert = require('assert');
4+
var path = require('path');
5+
var co = require('co');
6+
var fs = require('fs');
7+
8+
var pin = require('..');
9+
10+
var filename = path.resolve('component.json');
11+
12+
describe('pin', function () {
13+
beforeEach(function (done) {
14+
fs.unlink(filename, done);
15+
})
16+
17+
it('should pin dependencies', co(function* () {
18+
yield* write({
19+
name: 'test',
20+
dependencies: {
21+
"component/emitter": "~1.0.1"
22+
}
23+
});
24+
25+
var tree = yield* resolve(process.cwd(), {
26+
install: true,
27+
});
28+
29+
yield* pin(tree);
30+
31+
var json = yield* read();
32+
assert.equal(json.dependencies['component/emitter'], '1.0.1');
33+
}))
34+
35+
it('should pin development dependencies', co(function* () {
36+
yield* write({
37+
name: 'test',
38+
development: {
39+
dependencies: {
40+
"component/emitter": "~1.0.1"
41+
}
42+
}
43+
});
44+
45+
var tree = yield* resolve(process.cwd(), {
46+
install: true,
47+
});
48+
49+
yield* pin(tree);
50+
51+
var json = yield* read();
52+
assert.equal(json.development.dependencies['component/emitter'], '1.0.1');
53+
}))
54+
})
55+
56+
function* write(json) {
57+
yield fs.writeFile.bind(null, filename, JSON.stringify(json, null, 2));
58+
}
59+
60+
function* read() {
61+
var string = yield fs.readFile.bind(null, filename, 'utf8');
62+
return JSON.parse(string);
63+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.