Permalink
Browse files

extract ender-installer to separate package

general cleanup and remove unused cruft after extracting large chunks of
code to separate packages
  • Loading branch information...
1 parent 7761da7 commit 4a35f74d2f0ce1b9d3c8e9add3fe1675314adbd1 @rvagg rvagg committed Dec 28, 2012
View
@@ -32,21 +32,10 @@
var errno = require('errno')
, EnderError = errno.custom.createError('EnderError')
- , errorTypes = [
- 'BuildParseError'
- , 'UnknownMainError'
- , 'UnknownOptionError'
- , 'RepositorySetupError'
- , 'RepositoryCommandError'
- , 'JSONParseError'
- , 'ChildProcessError'
- , 'CompressionError'
- , 'MinifyError'
- ]
-module.exports.EnderError = EnderError
-module.exports.FilesystemError = errno.custom.FilesystemError
-
-errorTypes.forEach(function (err) {
- module.exports[err] = errno.custom.createError(err, EnderError)
-})
+module.exports.FilesystemError = errno.custom.FilesystemError
+module.exports.EnderError = EnderError
+module.exports.BuildParseError = errno.custom.createError('BuildParseError', EnderError)
+module.exports.JSONParseError = errno.custom.createError('JSONParseError', EnderError)
+module.exports.ChildProcessError = errno.custom.createError('ChildProcessError', EnderError)
+module.exports.CompressionError = errno.custom.createError('CompressionError', EnderError)
View
@@ -1,94 +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.
- */
-
-
-/******************************************************************************
- * Utilities to help the install process, particularly to help select packages
- * that require installing.
- */
-
-var path = require('path')
- , async = require('async')
- , packageUtil = require('ender-repository').util
- , util = require('./util')
-
- // scan the tree starting at the 'packages' nodes and return any dependencies that
- // are 'missing'; although if 'missing' packages exist in other parts of the complete
- // tree they are not counted
- , findMissingDependencies = function (packages, dependencyTree) {
- var unmissing = []
- , missing = []
- , localizedPackages = dependencyTree.localizePackageList(packages)
-
- // collect non-missing pkgs across the *whole* tree
- dependencyTree.forEachOrderedDependency(
- dependencyTree.allRootPackages()
- , function (pkg, parents, node) {
- if (node != 'missing') unmissing.push(pkg)
- }
- )
-
- // now look at just the part of the tree starting at the 'packages' nodes
- dependencyTree.forEachOrderedDependency(
- dependencyTree.localizePackageList(packages)
- , function (pkg, parents, node) {
- if (node == 'missing' && unmissing.indexOf(pkg) == -1) missing.push(pkg)
- }
- )
-
- // translate any packages back to their original names as passed in
- // e.g. foo@1.2.3, or /path/to/pkg
- missing = missing.map(function (p) {
- var i = localizedPackages.indexOf(p)
- return i > -1 ? packages[i] : p
- })
-
- return missing
- }
-
- , filterPackagesWithoutCwd = function (packages) {
- var cwd = path.resolve('.')
- return packages.filter(function (p) {
- return !packageUtil.isPath(p) || path.resolve(p) != cwd
- })
- }
-
- , findPathDependencies = function (packages, dependencyTree) {
- var dependencies = []
- dependencyTree.forEachUniqueOrderedDependency(
- // don't localize packages here, we want the root paths
- packageUtil.cleanName(packages)
- , function (pkg, parents, node) {
- if (packageUtil.isPath(pkg))
- dependencies.push(pkg)
- }
- )
- return dependencies
- }
-
-module.exports = {
- findMissingDependencies : findMissingDependencies
- , filterPackagesWithoutCwd : filterPackagesWithoutCwd
- , findPathDependencies : findPathDependencies
-}
View
@@ -1,145 +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.
- */
-
-
-/******************************************************************************
- * An additional abstraction of npm via repository.js. Installing packages
- * is not as simple as just asking npm to install them, there is additional
- * logic we need in order to get exactly what we want and also to control npm
- * (in particular, npm needs '.' to be installed separately).
- * Our install logic allows us to install more than just the standard
- * package.json "dependencies", we can also install "ender"->"dependencies".
- * We also get to skip installing dependencies that already exist which the npm
- * API doesn't allow us to do directly.
- * The basic flow is: (1) check dependency status in node_modules, (2) ask npm
- * to install anything missing, (3) repeat until there's not left to instal.
- * One special case is that we *always* ask npm to install packages specified
- * by a path (i.e. local).
- */
-
-var async = require('async')
- , repository = require('ender-repository')
- , packageUtil = repository.util
- , installUtil = require('./install-util')
- , DependencyGraph = require('ender-dependency-graph')
-
- , installPackages = function (options, packages, callback) {
- var filteredPackages = installUtil.filterPackagesWithoutCwd(packages)
- , installedPackages = []
- , results = []
- , dependencyTree
-
- , filterPackages = function () {
- // any packages marked 'missing' need to be installed
- filteredPackages = installUtil.findMissingDependencies(packages, dependencyTree)
- // any packages that are paths that are not already installed need to be installed
- filteredPackages = filteredPackages.concat(installUtil.findPathDependencies(packages, dependencyTree))
- // don't install '.' here, done as a special case previously in installCwd()
- filteredPackages = installUtil.filterPackagesWithoutCwd(filteredPackages)
- // don't reinstall anything that we've already installed in this loop
- filteredPackages = filteredPackages.filter(function (pkg) {
- return installedPackages.indexOf(pkg) == -1
- })
- if (filteredPackages.length)
- installedPackages = installedPackages.concat(filteredPackages)
- }
-
- // keep running this function until everything is installed
- , installRest = function (callback) {
- DependencyGraph(options, packages, function (err, _dependencyTree) {
- if (err) return callback(err) // wrapped in package-utils.js
-
- dependencyTree = _dependencyTree
- filterPackages()
-
- if (filteredPackages.length) {
- repository.install(filteredPackages, function (err, result) {
- if (err) return callback(err) // wrapped in repository.js
-
- results.push(result)
- callback()
- })
- } else {
- callback()
- }
- })
- }
-
- , completeDependenciesInstall = function () {
- // keep running installRest() until we have nothing else to install, in theory installedPackages[]
- // should stop us from going forever even if npm doesn't do the installing we want
- async.whilst(
- function () { return filteredPackages.length }
- , installRest
- , function (err) {
- repository.packup(err, function () {
- if (err) return callback(err)
-
- callback(null, results, dependencyTree)
- })
- }
- )
- }
-
- // if --force-install then explicitly install the root packages whether they exist in
- // node_modules or not, also used by 'refresh'
- , installRootPackages = function () {
- if (options['force-install'] || options['_force-install']) {
- // 'refresh' uses '_force-install' to signal that it doesn't want a trace left
- // in the 'Build:' header
- if (options['_force-install']) delete options['_force-install']
- repository.install(filteredPackages, function (err, result) {
- if (err) return callback(err) // wrapped in repository.js
- results.push(result)
-
- completeDependenciesInstall()
- })
- } else {
- completeDependenciesInstall()
- }
- }
-
- // must treat '.' as a special case, partly because of npm (see
- // https://github.com/isaacs/npm/commit/8b7bf5ab0c214b739b5fd6af07003cac9e5fc712), and
- // partly because of what we need to do with it
- , installCwd = function () {
- repository.install([ '.' ], function (err, result) {
- if (err) return callback(err) // wrapped in repository.js
- results.push(result)
- installRootPackages()
- })
- }
-
- packageUtil.preparePackagesDirectory(function (err) {
- if (err) return callback(err) // wrapped in util.js
-
- repository.setup(function (err) {
- if (err) return callback(err) // wrapped in repository.js
-
- filteredPackages.length != packages.length ? installCwd() : installRootPackages()
- })
- })
- }
-
-module.exports.installPackages = installPackages
@@ -27,10 +27,8 @@
* Simple utilities for main-build
*/
-var async = require('async')
- , path = require('path')
- , packageUtil = require('ender-repository').util
- , util = require('./util')
+var packageUtil = require('ender-repository').util
+ , DependencyGraph = require('ender-dependency-graph')
// unique packages by proper name
var uniquePackages = function (packages) {
@@ -48,15 +46,15 @@ var uniquePackages = function (packages) {
, isRootPackage = function (options, p) {
if (options.noop || options.sans) return false
- return packageUtil.cleanName(p) === util.getRootPackageName(options)
+ return packageUtil.cleanName(p) === DependencyGraph.getClientPackageName(options)
}
// given a list of packages, provide a sanitised list without duplicates and with
// the root package at the start.
, packageList = function (options) {
var packages = options.packages && options.packages.length ? options.packages : [ '.' ]
- if (!options.noop && !options.sans) packages = [ util.getRootPackageName(options) ].concat(packages)
+ if (!options.noop && !options.sans) packages = [ DependencyGraph.getClientPackageName(options) ].concat(packages)
return uniquePackages(packages)
}
View
@@ -32,9 +32,9 @@
*/
var builder = require('ender-builder')
+ , install = require('ender-installer')
, mainInfo = require('./main-info')
, buildUtil = require('./main-build-util')
- , install = require('./install')
, handle = function (options, packages, out, installedPackages, dependencyGraph, callback) {
if (out && installedPackages) out.installedFromRepository(installedPackages.length)
@@ -66,7 +66,7 @@ var builder = require('ender-builder')
// install takes care of collecting and organising dependencies for us and simply returns
// a DependencyTree object that we can use to assemble a build
- install.installPackages(options, packages, function (err, installedPackages, dependencyGraph) {
+ install(options, packages, function (err, installedPackages, dependencyGraph) {
if (err) return callback(err) // wrapped in repository.js
handle(options, packages, out, installedPackages, dependencyGraph, callback)
@@ -23,15 +23,15 @@
*/
-var extend = require('../util').extend
+var extend = require('util')._extend
, BuildOutput = require('./main-build-output')
- , AddOutput = extend(BuildOutput, { // inherit from BuildOutput
+ , AddOutput = extend({
create: function (out, debug, quiet) {
return Object.create(this).init(out, debug, quiet)
}
- })
+ }, BuildOutput) // inherit from BuildOutput
module.exports = AddOutput
@@ -23,10 +23,10 @@
*/
-var extend = require('../util').extend
+var extend = require('util')._extend
, MainInfoOutput = require('./main-info-output')
- , BuildOutput = extend(MainInfoOutput, { // inherit from MainInfoOutput
+ , BuildOutput = extend({
buildInit: function (packages) {
this.statusMsg('Installing packages: "' + packages.join(' ') + '"...')
@@ -50,6 +50,6 @@ var extend = require('../util').extend
return Object.create(this).init(out, debug, quiet)
}
- })
+ }, MainInfoOutput) // inherit from MainInfoOutput
module.exports = BuildOutput
@@ -23,11 +23,11 @@
*/
-var extend = require('../util').extend
+var extend = require('util')._extend
, toKb = require('../util').toKb
, Output = require('./output')
- , VersionOutput = extend(Output, { // inherit from Output
+ , VersionOutput = extend({
compiled: function (file, rawSize, gzipSize) {
this.log(
'Success! Your compiled source is '
@@ -46,6 +46,6 @@ var extend = require('../util').extend
return Object.create(this).init(out, debug, quiet)
}
- })
+ }, Output) // inherit from Output
module.exports = VersionOutput
Oops, something went wrong.

0 comments on commit 4a35f74

Please sign in to comment.