package.json format with full npm compatibility, plus additional fields for security and configuration.
Basic Structure
Required Fields
name
Package name. For scoped packages, use@scope/package-name.
- Must be lowercase
- No spaces or special characters except
-and_ - Max 214 characters
- Cannot start with
.or_
version
Package version following semantic versioning.MAJOR.MINOR.PATCH
- MAJOR: Breaking changes
- MINOR: New features (backwards compatible)
- PATCH: Bug fixes
Module System
type
Specify module system:"module" (ESM) or "commonjs" (CJS).
"module": Use ESM (import/export),.jsfiles treated as ESM"commonjs"(default): Use CommonJS (require/module.exports)
main
Entry point for the package.imports or requires your package.
exports
Define package entry points and subpath exports.Dependencies
dependencies
Production dependencies required to run the package.| Specifier | Meaning | Example |
|---|---|---|
1.2.3 | Exact version | "lodash": "4.17.21" |
^1.2.3 | Compatible (minor/patch) | "express": "^4.18.0" |
~1.2.3 | Patch updates only | "react": "~18.2.0" |
>=1.2.3 | Greater than or equal | "node": ">=18.0.0" |
<2.0.0 | Less than | "lodash": "<5.0.0" |
1.2.x | Wildcard | "express": "4.x" |
* | Any version | "util": "*" |
latest | Latest version | "typescript": "latest" |
devDependencies
Development-only dependencies (testing, building, linting).- Not installed in production environments
- Installed with
ant install - Added with
ant add -D <package>
peerDependencies
Dependencies that your package expects the consumer to provide.- Plugin systems
- React/Vue component libraries
- Build tool plugins
optionalDependencies
Optional dependencies that may fail to install without breaking the build.dependencies and optionalDependencies, the optional one takes precedence.
Scripts
Define runnable commands withant run <script>.
Lifecycle Scripts
Special scripts that run automatically during package operations:Pre/Post Scripts
Any script can havepre and post variants:
ant run build executes:
prebuildbuildpostbuild
Trusted Dependencies
trustedDependencies
Ant-specific field: List of packages allowed to run lifecycle scripts.postinstall, etc.) can execute arbitrary code during installation. This is a security risk:
- Malicious packages can run harmful code
- Compromised packages can be used for supply chain attacks
- Scripts may have unintended side effects
-
Install package:
-
Ant detects lifecycle scripts and prompts:
-
Explicitly trust the package:
-
Ant adds to
trustedDependenciesand runs scripts:
puppeteer- Downloads Chromiumesbuild- Downloads native binariessharp- Downloads native binaries@swc/core- Downloads native binariescanvas- Builds native modulessqlite3- Builds native modules
Binary Executables
bin
Define executable commands provided by the package.node_modules/.bin/my-cli.
Usage:
- Have shebang line (
#!/usr/bin/env node) - Be executable (
chmod +x cli.js)
Metadata Fields
description
Short package description.keywords
Array of keywords for discoverability.author
Package author.license
SPDX license identifier.repository
Source code repository.homepage
Project homepage URL.bugs
Bug tracker URL.Files and Publishing
files
Files to include when publishing to npm.package.jsonREADME/README.*LICENSE/LICENCE- Main entry point
.gitnode_modules.envfiles