-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Alexander Gugel <alexander.gugel@gmail.com> | ||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CURRENT_DIR = $(shell pwd) | ||
INSTALL_DIR = /usr/local/lib/node_modules | ||
BIN_DIR = /usr/local/bin | ||
BIN = mpm | ||
|
||
PHONY: install | ||
|
||
# http://blog.jgc.org/2015/04/the-one-line-you-should-add-to-every.html | ||
print-%: ; @echo $*=$($*) | ||
|
||
preinstall: | ||
mkdir -p $(INSTALL_DIR); \ | ||
mkdir -p $(BIN_DIR) | ||
|
||
link: preinstall | ||
ln -s $(CURRENT_DIR) $(INSTALL_DIR)/$(BIN); \ | ||
ln -s $(INSTALL_DIR)/mpm/cli.js $(BIN_DIR)/mpm | ||
|
||
install: preinstall | ||
cp -R $(CURRENT_DIR) $(INSTALL_DIR)/$(BIN); \ | ||
ln -s $(INSTALL_DIR)/mpm/cli.js $(BIN_DIR)/mpm | ||
|
||
uninstall: | ||
rm -rf $(INSTALL_DIR)/$(BIN); \ | ||
rm $(BIN_DIR)/$(BIN) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
mpm | ||
=== | ||
|
||
A *roughly* [**npm install**](https://www.npmjs.com/)-compatible package manager for Node.JS in **~100** lines of code. | ||
|
||
* implements `npm`'s basic [install algorithm](https://docs.npmjs.com/cli/install#algorithm) | ||
* correctly resolves (circular) dependencies | ||
* supports [semver](http://semver.org/) | ||
* correctly deals with `devDependencies` | ||
* interfaces with the [npm registry](https://www.npmjs.org/) | ||
|
||
Installation | ||
------------ | ||
|
||
``` | ||
git clone https://github.com/alexanderGugel/mpm mpm && cd $_ && make install | ||
``` | ||
|
||
Usage | ||
----- | ||
|
||
TODO | ||
|
||
Dependencies | ||
------------ | ||
|
||
The dependencies are checked into the repo. `mpm` does not rely on `npm` to install its dependencies. | ||
|
||
* [`semver`](https://www.npmjs.com/package/semver) | ||
* [`mkdirp`](https://www.npmjs.com/package/mkdirp) | ||
* [`gunzip-maybe`](https://www.npmjs.com/package/gunzip-maybe) | ||
* [`tar-fs`](https://www.npmjs.com/package/tar-fs) | ||
|
||
License | ||
------- | ||
|
||
See [LICENSE.md](LICENSE.md). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- [ ] Tests | ||
- [ ] Better error handling | ||
- [ ] `install -g` | ||
- [ ] Handle binaries | ||
- [ ] Scripts | ||
- [ ] Install from arbitrary tarball | ||
- [ ] Install from git repo | ||
- [ ] Install from BitTorrent (via DHT) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env node | ||
var path = require('path') | ||
var http = require('http') | ||
var fs = require('fs') | ||
var semver = require('semver') | ||
var gunzip = require('gunzip-maybe') | ||
var mkdirp = require('mkdirp') | ||
var tar = require('tar-fs') | ||
|
||
function resolve (dep, version, cb) { | ||
console.info('resolving', dep + '@' + version) | ||
http.get('http://registry.npmjs.org/' + dep, function (res) { | ||
var raw = '' | ||
res.on('data', function (chunk) { raw += chunk }).on('end', function () { | ||
var parsed = JSON.parse(raw) | ||
var resolved = parsed.versions[semver.maxSatisfying(Object.keys(parsed.versions), version)] | ||
cb(resolved ? null : new Error('No satisfying target found for ' + dep + '@' + version), resolved) | ||
}).on('error', cb) | ||
}).on('error', cb) | ||
} | ||
|
||
function fetch (where, what) { | ||
console.info('fetching', what.name + '@' + what.version, 'into', path.relative(__dirname, where)) | ||
http.get(what.dist.tarball, function (res) { | ||
res.pipe(gunzip()).pipe(tar.extract(where, { | ||
map: function (header) { | ||
header.name = header.name.substr('package/'.length) | ||
return header | ||
}, | ||
ignore: function (name) { | ||
return name === path.join(where, 'package.json') | ||
} | ||
})) | ||
}) | ||
} | ||
|
||
function install (where, what, family, entry) { | ||
console.info('installing', what.name + '@' + what.version, 'into', path.relative(__dirname, where)) | ||
family = family.slice() | ||
mkdirp.sync(where) | ||
var deps = [] | ||
function onResolved (err, resolved) { | ||
if (err) throw err | ||
deps.push(resolved) | ||
if (deps.length === Object.keys(what.dependencies).length) onResolvedAll() | ||
} | ||
function onResolvedAll () { | ||
deps.forEach(function (dep) { | ||
if (family.indexOf(dep.dist.shasum) > -1) return | ||
family.push(dep.dist.shasum) | ||
// `entry ? [] : family` ensures that uninstalling a single "immediate" | ||
// dependency doesn't break subsequent dependencies. | ||
process.nextTick(install.bind(null, path.join(where, 'node_modules', dep.name), dep, entry ? [] : family)) | ||
}) | ||
} | ||
for (var dep in what.dependencies) | ||
resolve(dep, what.dependencies[dep], onResolved) | ||
if (entry) { | ||
for (dep in what.devDependencies) | ||
resolve(dep, what.devDependencies[dep], onResolved) | ||
} else { | ||
fs.writeFile(path.join(where, 'package.json'), JSON.stringify(what, null, 2)) | ||
fetch(where, what) | ||
} | ||
} | ||
|
||
var target = process.argv[2] | ||
if (target) { | ||
resolve(target, target.split('@')[1] || '*', function (err, what) { | ||
if (err) throw err | ||
install(path.join(__dirname, 'node_modules', what.name), what, []) | ||
}) | ||
} else { | ||
var entry = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))) | ||
install(__dirname, entry, [], true) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.