Skip to content

feat(npm): add publish_package_json macro for publishConfig field promotion#2891

Closed
kirkobyte wants to merge 2 commits into
aspect-build:mainfrom
kirkobyte:claude/competent-chaplygin-a3768d
Closed

feat(npm): add publish_package_json macro for publishConfig field promotion#2891
kirkobyte wants to merge 2 commits into
aspect-build:mainfrom
kirkobyte:claude/competent-chaplygin-a3768d

Conversation

@kirkobyte

@kirkobyte kirkobyte commented Jun 18, 2026

Copy link
Copy Markdown

Summary

  • Adds a new publish_package_json convenience macro that mimics pnpm publish behavior: promotes fields from publishConfig into the top-level package.json and removes publishConfig
  • Enables workspace packages to use publishConfig overrides (e.g. exports, main, types) that are applied when the package is linked as a dependency via npm_package
  • Supports optional stamp_var to combine version stamping in a single target, and publish_config_fields to customize which fields are promoted (defaults to the pnpm allowlist)

Motivation

This could fix the long-standing issue of misalignment between in-IDE type resolution and resolution within Bazel. If pkg uses a package.json processed with this rule, we can use:

Usage

load("@aspect_rules_js//npm:defs.bzl", "npm_package", "publish_package_json")

publish_package_json(
    name = "package",
    # Optional: stamp version at the same time
    # stamp_var = "STABLE_BUILD_VERSION",
)

npm_package(
    name = "pkg",
    srcs = [":lib", ":package"],
)

Test plan

  • Example test in examples/publish_package_json/ verifies jq transform output
  • E2e test in e2e/publish_package_json/ verifies a workspace consumer resolves through publishConfig.main (not source main)
  • Existing stamped_package_json tests still pass

kirkobyte and others added 2 commits June 18, 2026 13:38
…motion

Add a new `publish_package_json` convenience macro that mimics pnpm publish
behavior by promoting fields from `publishConfig` into the top-level
package.json and removing `publishConfig`. This enables workspace packages
to use `publishConfig` overrides (e.g. exports, main, types) that are
applied when the package is linked as a dependency via npm_package.

The macro supports an optional `stamp_var` to combine version stamping,
and `publish_config_fields` to customize which fields are promoted
(defaults to the pnpm allowlist).

Includes an example and an e2e test verifying that a workspace consumer
resolves through the promoted publishConfig.main path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kirkobyte kirkobyte closed this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant