Permalink
Browse files

extracted package-utils and package-descriptor

to new ender-package-utils lib
  • Loading branch information...
1 parent 8657ed9 commit 1bebb20709dda4652adb897ce8f69d443d2d892a @rvagg rvagg committed Dec 25, 2012
View
39 LICENSE
@@ -0,0 +1,39 @@
+Copyright 2012, Rod Vagg, Dustin Diaz, Jacob Thornton and other contributors. (the "Original Author")
+All rights reserved.
+
+MIT +no-false-attribs License
+
+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.
+
+Distributions of all or part of the Software intended to be used
+by the recipients as they would use the unmodified Software,
+containing modifications that substantially alter, remove, or
+disable functionality of the Software, outside of the documented
+configuration mechanisms provided by the Software, shall be
+modified such that the Original Author's bug reporting email
+addresses and urls are either replaced with the contact information
+of the parties responsible for the changes, or removed entirely.
+
+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.
+
+
+Except where noted, this license applies to any and all software
+programs and associated documentation files created by the
+Original Author, when distributed with the Software.
View
@@ -32,7 +32,7 @@
var path = require('path')
, async = require('async')
- , packageUtil = require('./package-util')
+ , packageUtil = require('ender-repository').util
, util = require('./util')
, DependencyTree = {
View
@@ -30,7 +30,7 @@
var path = require('path')
, async = require('async')
- , packageUtil = require('./package-util')
+ , packageUtil = require('ender-repository').util
, util = require('./util')
// scan the tree starting at the 'packages' nodes and return any dependencies that
View
@@ -40,7 +40,7 @@
var async = require('async')
, repository = require('ender-repository')
- , packageUtil = require('./package-util')
+ , packageUtil = repository.util
, installUtil = require('./install-util')
, DependencyTree = require('./dependency-tree')
View
@@ -29,7 +29,7 @@
var async = require('async')
, path = require('path')
- , packageUtil = require('./package-util')
+ , packageUtil = require('ender-repository').util
, util = require('./util')
// unique packages by proper name
View
@@ -32,11 +32,11 @@
*/
var path = require('path')
+ , packageUtil = require('ender-repository').util
, util = require('./util')
, write = require('./write')
, mainInfo = require('./main-info')
, buildUtil = require('./main-build-util')
- , packageUtil = require('./package-util')
, install = require('./install')
, SourceBuild = require('./source-build')
, SourcePackage = require('./source-package')
View
@@ -1,70 +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.
- */
-
-
-/******************************************************************************
- * Wrapper for parsed package.json data. Makes a copy of package.json but will
- * replace root properties where they are duplicated in an "ender" sub-object
- * or an "overlay->ender" sub-object (as per Packages/1.1)
- */
-
-var overrides = {
- 'name' : 'name',
- 'main' : 'main',
- 'bridge' : 'ender',
- 'dependencies' : 'dependencies',
- 'devDependencies' : 'devDependencies'
- }
-
- , create = function (json) {
- var newJson = Object.create(json) // original is available via Object.getPrototypeOf
- , key
-
- if (typeof json.overlay == 'object'
- && typeof json.overlay.ender == 'object') {
- for (key in overrides) {
- if (key in json.overlay.ender) {
- newJson[overrides[key]] = json.overlay.ender[key]
- }
- }
- }
-
- if (typeof json.ender == 'object') {
- for (key in overrides) {
- if (key in json.ender) {
- newJson[overrides[key]] = json.ender[key]
- }
- }
- }
-
- for (key in json) {
- if (!newJson.hasOwnProperty(key)) {
- newJson[key] = json[key]
- }
- }
-
- return newJson
- }
-
-module.exports.create = create
View
@@ -1,146 +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.
- */
-
-
-/******************************************************************************
- * Collection of utility functions that deal with npm packages on the
- * filesystem. Anything to do with node_modules, package.json, etc. should be
- * done here, the rest of the app shouldn't have to know about any of this
- * detail.
- */
-
-var fs = require('fs')
- , path = require('path')
- , util = require('./util')
- , PackageDescriptor = require('./package-descriptor')
- , JSONParseError = require('./errors').JSONParseError
- , FilesystemError = require('./errors').FilesystemError
-
- , stripVersionRegex = /@.*$/
-
- // strip out the version if it exists, bean@0.4.5 -> bean
- , cleanName = function (name) {
- if (Array.isArray(name)) {
- return name.map(function (n) {
- return cleanName(n)
- })
- } else {
- return name.replace(stripVersionRegex, '')
- }
- }
-
- , isCWD = function (pkg) {
- return path.resolve(pkg) == path.resolve('.')
- }
-
- , isPath = function (pkg) {
- return (pkg = cleanName(pkg)) === '.' || /[\/\\]/.test(pkg)
- }
-
- // given an array of parent packages and a package name, give us a path to the
- // package inside the CWD node_modules directory
- , getPackageRoot = function (parents, pkg) {
- var dirs = [ 'node_modules' ]
-
- pkg = cleanName(pkg)
-
- if (!isPath(pkg)) { // not a directory reference of some kind
- parents.forEach(function (p) {
- dirs.push(p)
- dirs.push(dirs[0])
- })
- return path.resolve(path.join.apply(null, dirs), pkg)
- }
-
- return path.resolve(pkg)
- }
-
- // perhaps this could be done with `require()` since it can now read package.json?
- , readPackageJSON = function (parents, pkg, callback) {
- var root = getPackageRoot(parents, pkg)
- , file = path.resolve(root, 'package.json')
-
- fs.readFile(file, 'utf-8', function (err, data) {
- if (err) return callback(new FilesystemError(err))
- try {
- data = JSON.parse(data)
- } catch (err) {
- return callback(new JSONParseError(err.message + ' [' + file + ']', err))
- }
- callback(null, PackageDescriptor.create(data))
- })
- }
-
- // if one of the packages is a path that points to the CWD then get the
- // name of it
- , findRootPackageName = function (packages, callback) {
- var found = function (err, data) {
- if (err) return callback(err) // wrapped by readPackageJSON
- callback(null, data.name)
- }
-
- for (var i = 0; i < packages.length; i++) {
- if (isCWD(packages[i])) return readPackageJSON([], packages[i], found)
- }
-
- callback()
- }
-
- , getDependenciesFromJSON = function (packageJSON) {
- var dep = packageJSON.dependencies
- if (dep && !Array.isArray(dep)) dep = Object.keys(dep)
- return dep && dep.length ? dep : []
- }
-
- , getDependenciesFromDirectory = function (parents, pkg, callback) {
- var root = getPackageRoot(parents, pkg)
- , dir = path.resolve(path.join(root, 'node_modules'))
-
- fs.exists(dir, function (exists) {
- if (!exists) return callback(null, [])
- fs.readdir(dir, function (err, files) {
- if (err) return callback(new FilesystemError(err))
- files = files.filter(function(file) {
- return file !== '.bin'
- });
- callback.call(null, err, files)
- })
- })
- }
-
- , preparePackagesDirectory = function (callback) {
- util.mkdir('node_modules', callback)
- }
-
-module.exports = {
- cleanName : cleanName
- , isCWD : isCWD
- , isPath : isPath
- , getPackageRoot : getPackageRoot
- , readPackageJSON : readPackageJSON
- , findRootPackageName : findRootPackageName
- , getDependenciesFromJSON : getDependenciesFromJSON
- , preparePackagesDirectory : preparePackagesDirectory
- , getDependenciesFromDirectory : getDependenciesFromDirectory
-}
View
@@ -33,8 +33,8 @@
var path = require('path')
, async = require('async')
+ , packageUtil = require('ender-repository').util
, template = require('./template')
- , packageUtil = require('./package-util')
, sourcePackageUtil = require('./source-package-util')
, templateFiles = {
View
@@ -9,9 +9,9 @@
]
, "keywords": [ "ender", "modules", "builder", "framework", "packager" ]
, "main": "./lib/main.js"
- , "homepage": "https://ender.no.de"
+ , "homepage": "https://ender.jit.su"
, "dependencies": {
- "ender-repository" : "~0.0.1"
+ "ender-repository" : "~0.0.2"
, "ender-minify" : "~0.0.4"
, "colors" : "~0.6.0"
, "async" : "~0.1.22"
@@ -26,8 +26,9 @@
var buster = require('buster')
, path = require('path')
, assert = buster.assert
+ , packageUtil = require('ender-repository').util
, DependencyTree = require('../../lib/dependency-tree')
- , packageUtil = require('../../lib/package-util')
+
buster.testCase('Dependency tree', {
'constructDependencyTree': {
@@ -40,7 +40,8 @@ testCase('Install', {
this.optionsArg = { options: 1 }
this.packagesArg = [ 'yee', 'haw' ] // length 2
- this.mockUtil.expects('mkdir').once().withArgs('node_modules').callsArg(1)
+ //this.mockUtil.expects('mkdir').once().withArgs('node_modules').callsArg(1)
+ // done by mkdirp now, probably should be mocked out...
this.mockRepository.expects('setup').once().callsArg(0)
this.mockRepository.expects('packup').once().callsArg(1)
@@ -26,9 +26,9 @@
var buster = require('buster')
, path = require('path')
, assert = buster.assert
+ , packageUtil = require('ender-repository').util
, DependencyTree = require('../../lib/dependency-tree.js')
, installUtil = require('../../lib/install-util')
- , packageUtil = require('../../lib/package-util')
buster.testCase('Install util', {
'findMissingDependencies': {
@@ -26,8 +26,8 @@
var buster = require('buster')
, path = require('path')
, assert = buster.assert
+ , packageUtil = require('ender-repository').util
, buildUtil = require('../../lib/main-build-util')
- , packageUtil = require('../../lib/package-util')
buster.testCase('Build util', {
'packageList': {
Oops, something went wrong.

0 comments on commit 1bebb20

Please sign in to comment.