Packages/1.1

From CommonJS Spec Wiki
Jump to: navigation, search

STATUS: DRAFT

Implementations
PINF JS Loader

Contents

Packages

This specification describes the CommonJS package format for distributing CommonJS programs and libraries. A CommonJS package is a cohesive wrapping of a collection of modules, code and other assets into a single form. It provides the basis for convenient delivery, installation and management of CommonJS components.

This specifies the CommonJS package descriptor file and package file format. It does not specify a package catalogue file or format; this is an exercise for future specifications. The package descriptor file is a statement of known fact at the time the package is published and may not be modified without publishing a new release.

Package Descriptor File

Each package must provide a top-level package descriptor file called "package.json". This file is a JSON format file. Each package must provide all the following fields in its package descriptor file.

One of the following must also be in the package description file in order for it to be valid.

Optional Keywords

"maintainers":[ {
   "name": "Bill Bloggs",
   "email": "billblogs@bblogmedia.com",
  " web": "http://www.bblogmedia.com",
}]
"licenses": [
   {
       "type": "GPLv2",
       "url": "http://www.example.com/licenses/gpl.html",
   }
]
"repositories": [
       {
            "type": "git", 
            "url": "http://github.com/example.git",
            "path": "packages/mypackage"
       }
]
"dependencies": {
       "webkit": "1.2",
       "ssl": {
           "gnutls": ["1.0", "2.0"],
           "openssl": "0.9.8",
       },
}
  "implements": [ "CommonJS/Modules/1.0", "CommonJS/JSGI/1.0"]
   "scripts": {
       "install": "install.js",
       "uninstall": "uninstall.js",
       "build": "build.js",
       "doc": "make-doc.js",
       "test": "test.js",
   }
   "overlay": {
       "node" : {"dependencies":[...]},
       "npm"  : {"scripts":{"install":"./npm-install.sh"}
     }

Package managers and loaders should ignore unknown fields in the package descriptor file.

Reserved Properties

The following fields are reserved for future expansion: build, default, email, external, files, imports, maintainer, paths, platform, require, summary, test, using, downloads, uid. Extensions to the package descriptor specification should strive to avoid collisions for future standard names by name spacing their properties with innocuous names that do not have meanings relevant to general package management.

The following fields are reserved for package registries to use at their discretion: id, type.

All properties beginning with _ or $ are also reserved for package registries to use that their discretion.

Catalog Properties

When a package.json is included in a catalog of packages, the following fields should be present for each package.

   checksums: {"md5": "841959b03e98c92d938cdeade9e0784d"}

Package File Format

The package files shall be a simple archive of the package directory including the package.json file in a relative, ZIP archive format (Though this format may change in future revisions of this specification). The archive must have a single top level directory.

Package Directory Layout

A CommonJS package will observe the following:

Package Files

To install and uninstall a CommonJS package some local installation steps may be required. A package may specify various scripts to run via the "scripts" package.json field.

Other Requirements

Minimal Example Package Descriptor File

{
   "name" : "mypackage",
   "version" : "0.7.0",
   "main" : "./lib/main",
}


Large Example Package Descriptor File

{
   "name": "mypackage",
   "version": "0.7.0",
   "description": "Sample package for CommonJS. This package demonstrates the required elements of a CommonJS package.",
   "keywords": [
       "package",
       "example" 
   ],
   "maintainers": [
       {
           "name": "Bill Smith",
           "email": "bills@example.com",
           "web": "http://www.example.com" 
       } 
   ],
   "contributors": [
       {
           "name": "Mary Brown",
           "email": "maryb@embedthis.com",
           "web": "http://www.embedthis.com" 
       } 
   ],
   "bugs": {
       "mail": "dev@example.com",
       "web": "http://www.example.com/bugs" 
   },
   "licenses": [
       {
           "type": "GPLv2",
           "url": "http://www.example.org/licenses/gpl.html" 
       } 
   ],
   "repositories": [
       {
           "type": "git",
           "url": "http://hg.example.com/mypackage.git" 
       } 
   ],
   "dependencies": {
       "webkit": "1.2",
       "ssl": {
           "gnutls": ["1.0", "2.0"],
           "openssl": "0.9.8" 
       } 
   },
   "implements": ["cjs-module-0.3", "cjs-jsgi-0.1"],
   "os": ["linux", "macos", "win"],
   "cpu": ["x86", "ppc", "x86_64"],
   "engines": ["v8", "ejs", "node", "rhino"],
   "scripts": {
       "install": "install.js",
       "uninstall": "uninstall.js",
       "build": "build.js",
       "test": "test.js" 
   },
   "directories": {
       "lib": "src/lib",
       "bin": "local/binaries",
       "jars": "java" 
   } 
}

Editor Macros/Scripts

Remembering the format and typing the common bits can be boring. So listed below are know editor scripts to make this easier:

Background

Related Discussions

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox