Fix babel-preset-es2015

This commit is contained in:
Rico Sta. Cruz
2016-01-28 14:30:45 +08:00
parent 7c22efbf84
commit cd2d6c0174
3 changed files with 41 additions and 8 deletions

View File

@@ -55,6 +55,7 @@ module.exports = function install (ctx, pkg, modules, options) {
.then(_ => mkdirp(join(ctx.root, 'node_modules', '.store')))
.then(_ => fetchIf(ctx.tmp, target, dist.tarball, dist.shasum))
.then(_ => recurseDependencies())
.then(_ => symlinkSelf())
.then(_ => unlock(target))
})
.then(_ => mkdirp(modules))
@@ -77,6 +78,19 @@ module.exports = function install (ctx, pkg, modules, options) {
}
}
// symlink itself to itself. this way, babel-runtime@5 can
// require('babel-runtime') within itself.
function symlinkSelf () {
if (depth === 0) {
return Promise.resolve()
} else {
return mkdirp(join(target, 'node_modules'))
.then(_ => symlink(
join('..', '..', fullname),
join(target, 'node_modules', name)))
}
}
function lock (path) {
if (!ctx.lock) ctx.lock = {}
ctx.lock[path] = true

View File

@@ -2,6 +2,7 @@ todo:
- [x] put in proper node_modules
- [ ] npm install "rimraf@>2 <3"
- [ ] symlink .bin
- [ ] scoped modules
how it should look like:

View File

@@ -1,14 +1,13 @@
var test = require('tape')
var join = require('path').join
var prepare = require('./support/prepare')
var install = require('../bin/unpm-install')
require('./support/sepia')
test('small with dependencies (rimraf)', function (t) {
prepare()
require('../bin/unpm-install')({
input: ['rimraf@2.5.1']
})
.then(function (res) {
install({ input: ['rimraf@2.5.1'] })
.then(function () {
var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf'))
t.ok(typeof rimraf === 'function', 'rimraf is available')
t.end()
@@ -17,13 +16,32 @@ test('small with dependencies (rimraf)', function (t) {
test('no dependencies (lodash)', function (t) {
prepare()
require('../bin/unpm-install')({
input: ['lodash@4.0.0']
})
.then(function (res) {
install({ input: ['lodash@4.0.0'] })
.then(function () {
var _ = require(join(process.cwd(), 'node_modules', 'lodash'))
t.ok(typeof _ === 'function', '_ is available')
t.ok(typeof _.clone === 'function', '_.clone is available')
t.end()
}, t.end)
})
test('idempotency (rimraf)', function (t) {
prepare()
install({ input: ['rimraf@2.5.1'] })
.then(function () { return install({ input: [ 'rimraf@2.5.1' ] }) })
.then(function () {
var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf'))
t.ok(typeof rimraf === 'function', 'rimraf is available')
t.end()
}, t.end)
})
test('big with dependencies (babel-preset-2015)', function (t) {
prepare()
install({ input: ['babel-preset-es2015@6.3.13'] })
.then(function () {
var b = require(join(process.cwd(), 'node_modules', 'babel-preset-es2015'))
t.ok(typeof b === 'object', 'babel-preset-es2015 is available')
t.end()
}, t.end)
})