Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extracted repository to new ender-repository lib

  • Loading branch information...
commit 8657ed9f5060c6add57d8e1d181ae3381eb8bac2 1 parent d0229c9
@rvagg rvagg authored
View
2  lib/install.js
@@ -39,8 +39,8 @@
*/
var async = require('async')
+ , repository = require('ender-repository')
, packageUtil = require('./package-util')
- , repository = require('./repository')
, installUtil = require('./install-util')
, DependencyTree = require('./dependency-tree')
View
2  lib/main-remove.js
@@ -34,10 +34,10 @@
*/
var async = require('async')
+ , repository = require('ender-repository')
, util = require('./util')
, mainBuild = require('./main-build')
, argsParse = require('./args-parse')
- , repository = require('./repository')
, mainInfoUtil = require('./main-info-util')
, mainBuildUtil = require('./main-build-util')
View
2  lib/main-search.js
@@ -30,7 +30,7 @@
* first and also only show 'max' results.
*/
-var repository = require('./repository')
+var repository = require('ender-repository')
, xregexp = require('xregexp')
, searchUtil = require('./main-search-util')
, defaultMax = 8
View
147 lib/repository.js
@@ -1,147 +0,0 @@
-/*!
- * ENDER - The open module JavaScript framework
- *
- * Copyright (c) 2011-2012 @ded, @fat, @rvagg 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.
- */
-
-
-/******************************************************************************
- * Our only interface with `npm`, all npm interaction must go through here so
- * it's safely abstracted away from the rest of the code. The important parts
- * are the `setup()` and `packup()` methods which must wrap around any call to
- * an npm command. If you don't do a `setup()` then you'll get an error, if
- * you don't do a `packup()` then you'll likely have a hanging-process.
- * These two methods manage npm initialisation and also manage an npm logfile
- * that goes into /tmp/ender_npm_... If `packup()` is called with a falsy
- * first arg then the log file is deleted, otherwise it is left alone for
- * debugging.
- * Note that multiple npm commands can be run between `setup()` and `packup()`,
- * they only need to be done once per app execute.
- */
-
-var npm = require('npm')
- , fs = require('fs')
- , path = require('path')
- , net = require('net')
- , util = require('./util')
- , colors = require('colors')
- , packageUtil = require('./package-util')
- , FilesystemError = require('./errors').FilesystemError
- , RepositorySetupError = require('./errors').RepositorySetupError
- , RepositoryCommandError = require('./errors').RepositoryCommandError
-
- , isSetup
- , sessionFile
- , sessionStream
-
- // This is no longer an async function due to the way that createWriteStream works
- , generateTempFile = function () {
- sessionFile = path.join(util.tmpDir, 'ender_npm_' + process.pid + '.' + (+new Date()))
- return fs.createWriteStream(sessionFile, {flags: 'w', mode: '0644'})
- }
-
- // must be called at the start of an npm session
- , setup = function (callback) {
- if (isSetup) return callback()
-
- try {
- sessionStream = generateTempFile()
- } catch (err) {
- return callback(new FilesystemError(err))
- }
-
- sessionStream.on('error', function(err) {
- callback(new FilesystemError(err))
- })
-
- // streams are the safest way to deal with npm, actual fds are now unreliable
- // and since we have no real way to tell when npm is finished (the callbacks
- // are triggered before it does its own cleanup) the best we can do is a
- // destroySoon() on our stream.
- var config = {
- logstream : sessionStream
- , outfd : sessionStream
- }
-
- npm.load(config, function (err) {
- if (!err) isSetup = true
- callback.apply(null, arguments)
- })
- }
-
- // must be called at the end of an npm session
- , packup = function (wasError, callback) { // callback is optional here, usually not required
- if (!isSetup) return callback && callback()
-
- isSetup = false
-
- // gently close so we don't upset npm
- sessionStream.on('close', function () {
- if (!wasError) return fs.unlink(sessionFile, callback)
- callback && callback()
- sessionStream = null
- })
-
- sessionStream.destroySoon()
- }
-
- // wrap around npm.commands.search()
- , search = function (keywords, callback) {
- if (!isSetup) throw new RepositorySetupError('repository.setup() has not been called')
-
- npm.commands.search(keywords, function (err) {
- if (err) return callback(new RepositoryCommandError(err))
- callback.apply(null, arguments)
- })
- }
-
- // wrap around npm.commands.uninstall()
- , uninstall = function (packages, callback) {
- if (!isSetup) throw new RepositorySetupError('repository.setup() has not been called')
-
- npm.commands.uninstall(packages, function (err) {
- if (err) return callback(new RepositoryCommandError(err))
- callback.apply(null, arguments)
- })
- }
-
- // simple wraper around npm.commands.install()
- , install = function (packages, callback) {
- if (!isSetup) throw new RepositorySetupError('repository.setup() has not been called')
-
- npm.commands.install(packages, function (err, installed, tree, pretty) {
- if (err) return callback(new RepositoryCommandError(err))
-
- callback(null, {
- tree : tree
- , pretty : pretty
- , installed : installed
- })
- })
- }
-
-module.exports = {
- setup : setup
- , packup : packup
- , search : search
- , install : install
- , uninstall : uninstall
-}
View
34 package.json
@@ -1,7 +1,7 @@
{
"name": "ender"
, "description": "Open Module JavaScript Framework"
- , "version": "0.9.6-dev"
+ , "version": "0.9.7-dev"
, "authors": [
"Jacob Thornton @fat <jacob@twitter.com> (https://github.com/fat)"
, "Dustin Diaz @ded <dustin@obvious.com> (https://github.com/ded)"
@@ -10,31 +10,27 @@
, "keywords": [ "ender", "modules", "builder", "framework", "packager" ]
, "main": "./lib/main.js"
, "homepage": "https://ender.no.de"
- , "engines": {
- "node" : ">= 0.7.12"
- }
, "dependencies": {
- "npm" : ">= 1.1.30"
- , "colors" : ">= 0.6.0"
- , "uglify-js" : ">= 1.3.0"
- , "async" : ">= 0.1.22"
- , "hogan.js" : ">= 2.0.0"
- , "archy" : ">= 0.0.2"
- , "colors-tmpl" : ">= 0.0.3"
- , "xregexp" : ">= 2.0.0"
- , "errno" : ">= 0.0.1"
- , "glob" : ">= 3.1.10"
- , "ender-minify" : ">= 0.0.3"
+ "ender-repository" : "~0.0.1"
+ , "ender-minify" : "~0.0.4"
+ , "colors" : "~0.6.0"
+ , "async" : "~0.1.22"
+ , "hogan.js" : "~2.0.0"
+ , "archy" : "~0.0.2"
+ , "colors-tmpl" : "~0.1.0"
+ , "xregexp" : "~2.0.0"
+ , "errno" : "~0.0.3"
+ , "glob" : "~3.1.14"
}
, "directories": {
"lib" : "./lib"
, "bin" : "./bin"
}
, "devDependencies": {
- "buster" : ">= 0.5.4"
- , "rimraf" : ">= 2.0.2"
- , "jshint" : ">= 0.7.1"
- , "mkfiletree" : ">= 0.0.0"
+ "buster" : "~0.6.12"
+ , "rimraf" : "~2.1.1"
+ , "jshint" : "~0.9.1"
+ , "mkfiletree" : "~0.0.0"
}
, "bin": {
"ender" : "./bin/ender"
View
2  test/unit/install-test.js
@@ -24,8 +24,8 @@
var testCase = require('buster').testCase
+ , repository = require('ender-repository')
, install = require('../../lib/install')
- , repository = require('../../lib/repository')
, util = require('../../lib/util')
, installUtil = require('../../lib/install-util')
, DependencyTree = require('../../lib/dependency-tree')
View
2  test/unit/main-remove-test.js
@@ -24,11 +24,11 @@
var testCase = require('buster').testCase
+ , repository = require('ender-repository')
, util = require('../../lib/util')
, mainBuild = require('../../lib/main-build')
, mainInfoUtil = require('../../lib/main-info-util')
, mainRemove = require('../../lib/main-remove')
- , repository = require('../../lib/repository')
testCase('Remove', {
'test basic remove': function (done) {
View
2  test/unit/main-search-test.js
@@ -24,8 +24,8 @@
var testCase = require('buster').testCase
+ , repository = require('ender-repository')
, searchUtil = require('../../lib/main-search-util')
- , repository = require('../../lib/repository')
, search = require('../../lib/main-search')
, searchOutput = require('../../lib/output/main-search-output').create()
View
360 test/unit/repository-test.js
@@ -1,360 +0,0 @@
-/*!
- * ENDER - The open module JavaScript framework
- *
- * Copyright (c) 2011-2012 @ded, @fat, @rvagg 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.
- */
-
-
-var buster = require('buster')
- , assert = buster.assert
- , fs = require('fs')
- , repository = require('../../lib/repository')
- , util = require('../../lib/util')
- , FilesystemError = require('../../lib/errors').FilesystemError
- , RepositoryCommandError = require('../../lib/errors').RepositoryCommandError
-
- , executeSetupPackupTempDirTest = function (execute, verify, done) {
- fs.readdir(util.tmpDir, function (err, files) {
- if (err) {
- assert.fail('couldn\'t list files in temp dir: ' + util.tmpDir)
- done()
- } else {
- execute(function () {
- fs.readdir(util.tmpDir, function (err, files2) {
- if (err) {
- assert.fail('couldn\'t list files in temp dir: ' + util.tmpDir)
- done()
- } else {
- verify(files, files2)
- done()
- }
- })
- })
- }
- })
- }
- , verifySameFiles = function (files, files2) {
- assert.equals(files2, files)
- }
-
-buster.testCase('Repository (npm interface)', {
- 'setup() and packup()': {
- 'test setup() and packup() exist': function () {
- assert.isFunction(repository.setup)
- assert.isFunction(repository.packup)
- assert.equals(1, repository.setup.length)
- assert.equals(2, repository.packup.length)
- }
-
- , 'test setup() and packup() leave no temporary files': function (done) {
- executeSetupPackupTempDirTest(
- function (callback) {
- repository.setup(function () {
- repository.packup(null, callback)
- })
- }
- , verifySameFiles
- , done
- )
- }
-
- , 'test multiple sequential setup()/packup() leave no temporary files': function (done) {
- executeSetupPackupTempDirTest(
- function (callback) {
- repository.setup(function () {
- repository.packup(null, function () {
- repository.setup(function () {
- repository.packup(null, callback)
- })
- })
- })
- }
- , verifySameFiles
- , done
- )
- }
-
- , 'test multiple stacked setup() and packup() leave no temporary files and throw no errors': function (done) {
- executeSetupPackupTempDirTest(
- function (callback) {
- repository.setup(function () {
- repository.setup(function () {
- repository.packup(null, function () {
- repository.packup(null, callback)
- })
- })
- })
- }
- , verifySameFiles
- , done
- )
- }
-
- , 'test setup creates output file given by packup(false)': function (done) {
- executeSetupPackupTempDirTest(
- function (callback) {
- callback()
- }
- , function () {
- assert(true)
- }
- , done
- )
- }
- }
-
- , 'setup()': {
- 'test setup() calls npm.load()': function (done) {
- var npm = require('npm')
- , npmMock = this.mock(npm)
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- repository.setup(finish)
- assert(true) // required, buster issue #62
- }
-
- , 'test setup() calls npm.load() only once regardless of how many times setup() is called': function (done) {
- var npm = require('npm')
- , npmMock = this.mock(npm)
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- repository.setup(function () { // mock calls this one
- repository.setup(function () { // isSetup shortcut calls this one
- repository.setup(finish) // isSetup shortcut calls this too
- })
- })
- assert(true) // required, buster issue #62
- }
-
- , 'test open temp file error': function (done) {
- var fsMock = this.mock(fs)
- , errThrown = new Error('this is an error')
-
- fsMock.expects('createWriteStream').throws(errThrown)
-
- repository.setup(function (err) {
- assert(err)
- assert(err instanceof FilesystemError)
- assert.same(err.cause, errThrown)
- assert.same(err.message, errThrown.message)
- done()
- })
- }
- }
-
- , 'search()': {
- setUp: function () {
- // we have to replace npm.commands because all properties on the original object
- // are defined with only getters (via defineProperty) so can't be mocked as they are
- this.npm = require('npm')
- this.npmCommandsOriginal = this.npm.commands
- this.npm.commands = this.npmCommands = {
- search: function () {}
- }
- }
- , tearDown: function () {
- this.npm.commands = this.npmCommandsOriginal
- }
-
- , 'test search() throws RepositorySetupError if setup() has not been called': function () {
- assert.exception(repository.search, 'RepositorySetupError')
- }
-
- , 'test search() calls npm.commands.search()': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , keywords = 'keywords argument'
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('search').once().withArgs(keywords).callsArg(1)
-
- repository.setup(function () {
- repository.search(keywords, finish)
- })
-
- assert(true) // required, buster issue #62
- }
-
- , 'test npm.commands.search error': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , keywords = 'keywords argument'
- , errArg = new Error('this is an error')
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('search').once().withArgs(keywords).callsArgWith(1, errArg)
-
- repository.setup(function () {
- repository.search(keywords, function (err) {
- assert(err)
- assert(err instanceof RepositoryCommandError)
- assert.same(err.cause, errArg)
- assert.same(err.message, errArg.message)
- repository.packup(false, done)
- })
- })
- }
- }
-
- , 'uninstall()': {
- setUp: function () {
- // we have to replace npm.commands because all properties on the original object
- // are defined with only getters (via defineProperty) so can't be mocked as they are
- this.npm = require('npm')
- this.npmCommandsOriginal = this.npm.commands
- this.npm.commands = this.npmCommands = {
- uninstall: function () {}
- }
- }
- , tearDown: function () {
- this.npm.commands = this.npmCommandsOriginal
- }
-
- , 'test uninstall() throws RepositorySetupError if setup() has not been called': function () {
- assert.exception(repository.uninstall, 'RepositorySetupError')
- }
-
- , 'test uninstall() calls npm.commands.uninstall()': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , packages = [ 'packages', 'argument' ]
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('uninstall').once().withArgs(packages).callsArg(1)
-
- repository.setup(function () {
- repository.uninstall(packages, finish)
- })
-
- assert(true) // required, buster issue #62
- }
-
- , 'test npm.commands.uninstall error': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , packages = [ 'packages', 'argument' ]
- , errArg = new Error('this is an error')
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('uninstall').once().withArgs(packages).callsArgWith(1, errArg)
-
- repository.setup(function () {
- repository.uninstall(packages, function (err) {
- assert(err)
- assert(err instanceof RepositoryCommandError)
- assert.same(err.cause, errArg)
- assert.same(err.message, errArg.message)
- repository.packup(false, done)
- })
- })
- }
- }
-
- , 'install()': {
- setUp: function () {
- // see note for search() setUp
- this.npm = require('npm')
- this.npmCommandsOriginal = this.npm.commands
- this.npm.commands = this.npmCommands = {
- install: function () {}
- }
- }
- , tearDown: function () {
- this.npm.commands = this.npmCommandsOriginal
- }
-
- , 'test install() throws RepositorySetupError if setup() has not been called': function () {
- assert.exception(repository.install, 'RepositorySetupError')
- }
-
- , 'test install() calls npm.commands.install()': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , packages = [ 'packages', 'argument' ]
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('install').once().withArgs(packages).callsArg(1)
-
- repository.setup(function () {
- repository.install(packages, finish)
- })
-
- assert(true) // required, buster issue #62
- }
-
- // disabled as the '.' special case has been moved into the main-build logic instead
- /*
- , 'test install() calls npm.commands.install() twice if "." package is specified': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , packages = [ 'packages', 'argument', 'foo/..' ]
- , finish = function () {
- repository.packup(false, done)
- }
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('install').once().withArgs(packages.slice(0, 2)).callsArg(1)
- npmCommandsMock.expects('install').once().withArgs([ '.' ]).callsArg(1)
-
- repository.setup(function () {
- repository.install(packages, finish)
- })
-
- assert(true) // required, buster issue #62
- }
- */
-
- , 'test npm.commands.install error': function (done) {
- var npmMock = this.mock(this.npm)
- , npmCommandsMock = this.mock(this.npmCommands)
- , packages = [ 'packages', 'argument' ]
- , errArg = new Error('this is an error')
-
- npmMock.expects('load').once().callsArg(1)
- npmCommandsMock.expects('install').once().withArgs(packages).callsArgWith(1, errArg)
-
- repository.setup(function () {
- repository.install(packages, function (err) {
- assert(err)
- assert(err instanceof RepositoryCommandError)
- assert.same(err.cause, errArg)
- assert.same(err.message, errArg.message)
- repository.packup(false, done)
- })
- })
- }
- }
-})
Please sign in to comment.
Something went wrong with that request. Please try again.