Skip to content

Commit

Permalink
Removed support for 'parent' links in packages and for executable dir…
Browse files Browse the repository at this point in the history
…ectories.
  • Loading branch information
kriskowal committed Oct 3, 2009
1 parent 46eb379 commit 1d06e45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
50 changes: 23 additions & 27 deletions docs/packages-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,27 @@ A package consists of a directory of modules conforming to the ServerJS [Securab

A package directory might have the following files and directories:

* "package.json" for package metadata like dependencies and overrides for the conventional directory names.
* "local.json" for overrides on "package.json" provided by the user.
* "bin" for executables.
* "lib" for all object code, including JavaScript modules, and C extensions.
* "src" for all buildable source code, including C and Java source code.
* "jars" for Java class trees and archives.
* "packages/{name}" for installed sub-packages.
* "engines/{engine}" for engine-specific packages.
* "parent" for an inherited package tree, like the "narwhal" package installed by the system administrator or OS package management system.

"package.json" and "local.json" may contain the following attributes:

* "name" - the name of the package. The package system will only load one package with a given name. The name defaults to the name of the parent directory.
* "author" - the original author of the package. The author may be a String including an optional `(` URL in parentheses `)` and optional `<` email address in angle brackets `>`. Alternately, it may be an Object with any of `name`, `email`, and `url` attributes. The package reader normalizes authors to the latter Object form.
* "maintainer" - the package maintainer for the project as a String or Object just as the author attribute.
* "contributors" - may be an Array of additional author Strings.
* "url" - the URL of the project website.
* "license" - the name of the license as a String, with an optional URL in parentheses, or an Object with "name" and "url" attributes.
* "description" - a String describing the package. Most package descriptions end with a period/full stop.
* "keywords" - an Array of String keywords to assist users searching for the package with "tusk search" or "tusk apropos".
* "lib" - a path or array of paths to top-level module directories provided in this package. Defaults to ["lib"].
* "jars" - for Rhino engines, a path or array of paths to directories to add to the Java CLASSPATH (uses a Java URLClassLoader, so accepts ".jar" paths and directory paths ending with "/").
* "packages" - a path or array of paths to directories containing additional packages, defaults to ["packages"].
* "engines" - a path or array of paths to directories containing engine-specific packages, defaults to ["engines"]. These engine packages will be loaded if and in the prioritized order they appear in the "system.engines" array, and with higher priority that those in this package's generic "js" path so that they can override engine-specific modules.
* "main" - a path to a main program if the package is run with "bin/narwhal" and its directory instead of a specific script.
* "parent" - a path to a package tree to inherit, like the "narwhal" package installed by the system administorator. Defaults to "parent" if a symlink exists by that name.

* `package.json` for package metadata like dependencies and overrides for the conventional directory names.
* `local.json` for overrides on `package.json` provided by the user.
* `bin` for executables.
* `lib` for all object code, including JavaScript modules, and C extensions.
* `src` for all buildable source code, including C and Java source code.
* `jars` for Java class trees and archives.
* `packages/{name}` for installed sub-packages.
* `engines/{engine}` for engine-specific packages.

`package.json` and `local.json` may contain the following attributes:

* `name` - the name of the package. The package system will only load one package with a given name. The name defaults to the name of the parent directory.
* `author` - the original author of the package. The author may be a String including an optional `(` URL in parentheses `)` and optional `<` email address in angle brackets `>`. Alternately, it may be an Object with any of `name`, `email`, and `url` attributes. The package reader normalizes authors to the latter Object form.
* `maintainer` - the package maintainer for the project as a String or Object just as the author attribute.
* `contributors` - may be an Array of additional author Strings.
* `url` - the URL of the project website.
* `license` - the name of the license as a String, with an optional URL in parentheses, or an Object with `name` and `url` attributes.
* `description` - a String describing the package. Most package descriptions end with a period/full stop.
* `keywords` - an Array of String keywords to assist users searching for the package with `tusk search` or `tusk apropos`.
* `lib` - a path or array of paths to top-level module directories provided in this package. Defaults to `["lib"]`.
* `jars` - for Rhino engines, a path or array of paths to directories to add to the Java CLASSPATH (uses a Java URLClassLoader, so accepts `.jar` paths and directory paths ending with `/`).
* `packages` - a path or array of paths to directories containing additional packages, defaults to `["packages"]`.
* `engines` - a path or array of paths to directories containing engine-specific packages, defaults to `["engines"]`. These engine packages will be loaded if and in the prioritized order they appear in the `system.engines` array, and with higher priority that those in this package's generic `js` path so that they can override engine-specific modules.

21 changes: 2 additions & 19 deletions lib/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ exports.load = function (prefixes) {

/*** read
recursively loads all package data from package.json files
and packages/ directories, starting with the given directory,
usually the system.packagePrefix.
and packages/ directories.
*/
exports.read = function read(prefixes, catalog) {
// construct an object graph from package json files
Expand All @@ -97,8 +96,7 @@ exports.read = function read(prefixes, catalog) {
prefixes = [prefixes];

// queue-based breadth-first-search of the package
// tree starting with the "root", usually
// system.packagePrefix
// tree starting with the "root"
while (prefixes.length) {
var queue = [fs.path(prefixes.shift())];
while (queue.length) {
Expand Down Expand Up @@ -168,21 +166,6 @@ exports.read = function read(prefixes, catalog) {
}
});

// enqueue parent package root
var parents = packageDatum.parent;
if (parents !== null) {
if (typeof parents == "string")
parents = [parents];
if (parents === undefined)
parents = ["parent"];
parents.forEach(function (parent) {
parent = packageDirectory.join('').resolve(parent);
if (parent.isDirectory()) {
prefixes.push(parent);
}
});
}

// the first package we encounter gets
// top-billing, the root package
if (!root)
Expand Down
29 changes: 12 additions & 17 deletions narwhal.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ for (var i = 0; i < prefixes.length; i++) {
var prefix = prefixes[i];
for (var j = 0; j < system.engines.length; j++) {
var engine = system.engines[j];
paths.push(prefixes[i] + '/engines/' + engine + '/lib');
paths.push(prefixes[i] + "/engines/" + engine + "/lib");
}
paths.push(prefixes[i] + '/lib');
paths.push(prefixes[i] + "/lib");
}

// create the primary Loader and Sandbox:
Expand Down Expand Up @@ -99,9 +99,9 @@ global.require.force("system");
// augment the path search array with those provided in
// environment variables
paths.push([
system.env.JS_PATH || '',
system.env.NARWHAL_PATH || ''
].join(':').split(':').filter(function (path) {
system.env.JS_PATH || "",
system.env.NARWHAL_PATH || ""
].join(":").split(":").filter(function (path) {
return !!path;
}));

Expand All @@ -122,7 +122,7 @@ global.require.debug = options.verbose;
// already loaded
if (!wasVerbose && system.verbose) {
Object.keys(modules).forEach(function (name) {
print('| ' + name);
print("| " + name);
});
}

Expand All @@ -137,16 +137,11 @@ if (system.args.length && !options.interactive && !options.main) {
var parts = system.fs.split(program);
for (var i = 0; i < parts.length; i++) {
var path = system.fs.join.apply(null, parts.slice(0, i));
var packageJson = system.fs.join(path, 'package.json');
var packageJson = system.fs.join(path, "package.json");
if (system.fs.isFile(packageJson))
system.prefixes.unshift(path);
}

if (program.isDirectory()) {
if (!program.join('package.json').isFile())
throw new Error("Program directory does not contain a package.json");
system.prefixes.unshift(program);
}
}

// user package prefix
Expand Down Expand Up @@ -183,7 +178,7 @@ options.todo.forEach(function (item) {
system.evalGlobal(value);
} else if (action == "path") {
var paths = packages.order.map(function (pkg) {
return pkg.directory.join('bin');
return pkg.directory.join("bin");
}).filter(function (path) {
return path.isDirectory();
});
Expand All @@ -199,20 +194,20 @@ options.todo.forEach(function (item) {

// load the program module
if (options.interactive) {
require('narwhal/repl').repl();
require("narwhal/repl").repl();
} else if (options.main) {
require.main(options.main);
} else if (program) {
if (program.isDirectory()) {
require.main(packages.root.directory.resolve(packages.root.main || 'main').toString());
require.main(packages.root.directory.resolve(packages.root.main || "main").toString());
} else {
require.main(program.toString());
}
}

// send an unload event if that module has been required
if (require.loader.isLoaded('unload')) {
require('unload').send();
if (require.loader.isLoaded("unload")) {
require("unload").send();
}

})

0 comments on commit 1d06e45

Please sign in to comment.