feat(npm): add publish_package_json macro for publishConfig field promotion#2891
Closed
kirkobyte wants to merge 2 commits into
Closed
feat(npm): add publish_package_json macro for publishConfig field promotion#2891kirkobyte wants to merge 2 commits into
kirkobyte wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
publish_package_jsonconvenience macro that mimicspnpm publishbehavior: promotes fields frompublishConfiginto the top-levelpackage.jsonand removespublishConfigpublishConfigoverrides (e.g.exports,main,types) that are applied when the package is linked as a dependency vianpm_packagestamp_varto combine version stamping in a single target, andpublish_config_fieldsto 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
pkguses a package.json processed with this rule, we can use:src/index.ts)publishConfigafter feat(npm): use pnpm publish for npm_package #2868)dist/index.js)Usage
Test plan
examples/publish_package_json/verifies jq transform outpute2e/publish_package_json/verifies a workspace consumer resolves throughpublishConfig.main(not sourcemain)stamped_package_jsontests still pass