Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 28, 2025

What?

Adds package guidelines to packages/README.md and docs/reference-guides/packages.md, covering purpose, documentation, prerequisites, and avoiding utility/kitchen-sink packages.

Also adds links to packages/wp-build/README.md for build system details.

…o improve clarity and organization in Gutenberg development.
@ramonjd ramonjd self-assigned this Nov 28, 2025
@ramonjd ramonjd added the [Type] Developer Documentation Documentation for developers label Nov 28, 2025
@github-actions
Copy link

github-actions bot commented Nov 28, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: youknowriad <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@andrewserong
Copy link
Contributor

This is looking good to me so far! I wonder if it'd be worth having a section after ## Creating a New Package called ## Making a package private?

This is something I'm often not too sure exactly how we want to do it as I've seen a couple of different approaches across packages. Is it something like:

  • Explicitly set "wpScript": false so that it isn't included as a WordPress script.
  • Explicitly set "private": true so that the package isn't published to npm.

Anything else? (Just thought I'd double check before committing in case I got that wrong)

@ramonjd
Copy link
Member Author

ramonjd commented Nov 28, 2025

I wonder if it'd be worth having a section after ## Creating a New Package called ## Making a package private?

Agree. I'm not 100% sure what to write there either. I think we could commit away and be corrected later 😄

@andrewserong
Copy link
Contributor

Agree. I'm not 100% sure what to write there either. I think we could commit away and be corrected later 😄

Thanks, I double checked across the repo with Claude, and settled on 3da804d for describing how to make a package private. Feel free to change, anyone, if that's no good!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads well to me, and I think adds helpful clarity. LGTM!

@ramonjd
Copy link
Member Author

ramonjd commented Nov 28, 2025

Nice! Thanks for helping out 🙇🏻

@ramonjd ramonjd enabled auto-merge (squash) November 28, 2025 04:21

## Making a Package Private

If a package is only used internally within Gutenberg (or WordPress core) and should not be published to npm, mark it as private by adding the following to the package's `package.json`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid "private": true. Most packages need to be published to npm to be used by WordPress Core even if they are bundled packages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for me this documentation is a bit redundant compared to the README of @wordpress/build

"wpScript": false is also unnecessary.

Copy link
Contributor

@andrewserong andrewserong Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly added the "wpScript" bit because it wasn't clear to me from reading the README of @wordpress/build, sorry! I found those docs a bit brief in this regard. We also set "wpScript": false in the ui package, so I thought being explicit there might have been the intention 🤔

I think we should avoid "private": true.

If so, I think this would be good to explain in the docs, as there around 18 or so packages in the repo with "private" true.

I don't mean to be at all argumentative with my comment here! I mostly wanted to capture my own confusion in trying to follow the existing documentation. I feel a little embarrassed to say that the reason I'd like to document this part of things more clearly is that I spent quite a bit of time trying to wrap my head around it while preparing the media fields PR (#73071) and I'm still not quite sure I did it right 😅

So (perhaps selfishly), I was hoping we could have a clear section for "you want to add a private package for use within Gutenberg, but don't want it to be exposed anywhere, here's how to do that task".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wordpress/build

Is this a new package? Or is that wp-build?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is that wp-build?

Yep, it's wp-build in the packages directory, but @wordpress/build in the package name that gets published to npm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update these docs instead and link to them?

Sounds good 👍

Do you want it to be bundled within a WordPress Core script or not? What does "expose mean"

Great questions, I'd love it if we can tease this apart in the docs.

I'm still not 100% sure what "bundled within a WordPress Core script" means exactly, either.

To be slightly more specific about use cases, here's a couple:

  1. I want to add a media fields package, but don't (yet) want it available in npm, I simply want Gutenberg packages to be able to use it until I can stabilise the shape of the API. It also shouldn't be available from the wp global.
  2. We want to introduce an image cropper package (ie. Image Cropper: add package and basic stories #72414), and wish to use it in the block-editor package, but we don't yet want to publish it to npm. Again, until we're satisfied with the API we'd like this to be private to everything outside the Gutenberg repo. And then, once stable, switch it over to public and published to npm so that it can be used elsewhere.

For both of these cases, if we make it to a major WP release and the packages don't feel ready for npm, does bundled mean that the imported code winds up in the package that imports from it?

I'm finding the nuances surrounding this hard to wrap my head around, and I feel like I probably need to spend a little more time with the wp-build package to make sure I'm following how it's all hooked together.

Let's leave this PR open for now, and if no-one beats me to it, I'm happy to continue chipping away at this next week — it'll be a nice reminder to make sure I actually understand the package relationships properly 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ship this, I just want to correct that "private": true is potentially dangerous. Break core backports so it really shouldn't be the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to add a media fields package, but don't (yet) want it available in npm, I simply want Gutenberg packages to be able to use it until I can stabilise the shape of the API. It also shouldn't be available from the wp global.
We want to introduce an image cropper package (ie. #72414), and wish to use it in the block-editor package, but we don't yet want to publish it to npm. Again, until we're satisfied with the API we'd like this to be private to everything outside the Gutenberg repo. And then, once stable, switch it over to public and published to npm so that it can be used elsewhere.

For both of these, it should just be a regular package: no flags at all, public npm package. It's the default case basically, it's like you're building an external npm package but you still want it to be published otherwise the packages that rely on it won't be able to be added as dependencies in core. (they'll have missing dependencies in npm)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, perfect, that helps, thank you. I'll think about how to word this in the docs (and flag that packages should be public by default)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given it another pass in 3692334 with the help of Claude. I think that clarifies things a bit better, but I've quite possibly been looking at this a little too long (and there's also nuance surrounding the use of wp-build for plugins that I mightn't have considered, given that the global variable can be configured).

I'll leave it there for now — feel free to change any of this if anyone would like to! If this is still open next week I'll take a look at it with fresh eyes and when my 🧠 is a little clearer 😄

Thanks again for all the discussion here, much appreciated!

@youknowriad youknowriad disabled auto-merge November 28, 2025 04:34
@ramonjd
Copy link
Member Author

ramonjd commented Dec 2, 2025

The latest updates read well to me. Merge and iterate?

@andrewserong
Copy link
Contributor

The latest updates read well to me. Merge and iterate?

Sounds good to me!

@ramonjd ramonjd merged commit d3d43a1 into trunk Dec 2, 2025
35 checks passed
@ramonjd ramonjd deleted the update/package-docs-with-guidelines branch December 2, 2025 04:06
@github-actions github-actions bot added this to the Gutenberg 22.3 milestone Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants