JavaScript/TypeScript Ecosystem
Relevant source files
The following files were used as context for generating this wiki page:
The JavaScript/TypeScript Ecosystem within pubm provides the core logic for detecting, managing, and publishing Node.js and Deno-based projects. It abstracts the complexities of different manifest formats (such as package.json and jsr.json) and package managers (npm, yarn, pnpm, bun) to provide a unified interface for versioning and distribution.
This ecosystem handles critical tasks such as manifest discovery, lockfile synchronization, and dependency resolution specifically for the JS/TS landscape. It supports a variety of project structures, ranging from single-package repositories to complex monorepos using workspace protocols.
Architecture and Detection
The JsEcosystem class serves as the primary controller for JS/TS projects. Detection is triggered by the presence of specific manifest files.
Detection Logic
A project is identified as part of the JavaScript ecosystem if it contains a package.json, deno.json, or deno.jsonc file at the specified package path.
Registry Integration
The JS ecosystem primarily supports two registry types:
- npm: The default for projects with a
package.json. - jsr: Supported for Deno-native projects or hybrid projects containing
jsr.json,deno.json, ordeno.jsonc.
Sources: packages/core/src/ecosystem/js.ts:39-45, packages/core/src/ecosystem/js.ts:74-76
Manifest Management
The system utilizes a ManifestReader and specific schemas to extract metadata from JS/TS projects. This allows pubm to handle variations in field names and data structures across different manifest types.
Manifest Priority
When reading project information (like name and version), the ecosystem follows a priority order if multiple files are present:
package.jsonjsr.jsondeno.jsondeno.jsonc
Sources: packages/core/tests/unit/ecosystem/manifest-delegation.test.ts:44-55, packages/core/src/ecosystem/js.ts:48-62
Version Updates
The ecosystem performs regex-based updates to version strings within manifests to ensure consistency across multiple files during a release.
| Manifest File | Search Pattern | Target Field |
|---|---|---|
package.json | JSON key-value | version |
jsr.json | JSON key-value | version |
deno.json | ("version"\s*:\s*")[^"]*(") | version |
deno.jsonc | ("version"\s*:\s*")[^"]*(") | version |
Sources: packages/core/src/ecosystem/js.ts:20-22, packages/core/src/ecosystem/js.ts:48-62
Package Manager Support
The system automatically detects the preferred package manager by scanning for lockfiles. This detection informs the commands used for installation, testing, and building.
Package Manager Detection Priority
The detection logic traverses upward from the package directory to find the nearest lockfile:
- Bun:
bun.lockorbun.lockb - pnpm:
pnpm-lock.yaml - Yarn:
yarn.lock - npm:
package-lock.json(fallback)
Sources: packages/pubm/src/commands/init-workflows.ts:51-62, packages/core/src/ecosystem/js.ts:114-138
Default Commands
The ecosystem provides default CLI commands based on the detected package manager:
Workspace and Dependency Resolution
For monorepos, the ecosystem handles the workspace: protocol. Before publishing, it resolves internal dependencies to their actual versions to ensure valid package installation for consumers.
Resolution Logic
- Reads
package.jsondependencies. - Identifies versions prefixed with
workspace:. - Replaces prefixes (
*,^,~) with the actual version currently being released for the sibling package. - Backs up the original
package.jsonto allow for rollback or restoration after the publish phase.
Sources: packages/core/src/ecosystem/js.ts:140-192
CI/CD Workflow Generation
The JS ecosystem includes utilities to generate GitHub Actions workflows tailored to the detected package manager.
| Manager | Setup Action | Install Command | Publish Wrapper |
|---|---|---|---|
| Bun | oven-sh/setup-bun@v2 | bun install --frozen-lockfile | bunx pubm |
| pnpm | pnpm/action-setup@v4 | pnpm install --frozen-lockfile | pnpm exec pubm |
| Yarn | actions/setup-node@v4 | yarn install --immutable | yarn pubm |
| npm | actions/setup-node@v4 | npm ci | npx pubm |
Sources: packages/pubm/src/commands/init-workflows.ts:65-117, packages/pubm/src/commands/init-workflows.ts:120-131
Workflow Sequence
Summary
The JavaScript/TypeScript Ecosystem module is a robust abstraction layer that enables pubm to work seamlessly across diverse Node.js and Deno environments. By handling manifest synchronization, package manager detection, and workspace protocol resolution, it ensures that JS/TS projects can be published reliably to multiple registries with minimal manual configuration.