Skip to content

Components: Add Build#41536

Merged
nateweller merged 11 commits intotrunkfrom
add/components/build
Mar 17, 2025
Merged

Components: Add Build#41536
nateweller merged 11 commits intotrunkfrom
add/components/build

Conversation

@nateweller
Copy link
Copy Markdown
Contributor

@nateweller nateweller commented Feb 4, 2025

Proposed changes:

  • Adds build to the components package.
    • Use tsconfig.tsc.json base with custom compilerOptions.
    • Update Storybook files for tsconfig compatibility.
    • Adds typecasting to unblock build for UplotReact and ReactSlider.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

p1738271950791069-slack-CDLH4C1UZ

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Validate that both jetpack build js-packages/components -v and jetpack build js-packages/components --production -v run successfully.
  • Validate that both jetpack build plugins/jetpack -v and jetpack build plugins/jetpack --production -v run successfully.
  • Validate that no extraneous files are generated by the build (empty git status).
  • Review the generated build directory contents.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/components/build branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/components/build
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/components/build

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: April 1, 2025
    • Code freeze: March 30, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Starter Plugin plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Classic Theme helper plugin plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Feb 4, 2025
@nateweller nateweller force-pushed the add/components/build branch from b5f288c to fd3a6ac Compare February 4, 2025 06:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2025

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

@nateweller nateweller force-pushed the add/components/build branch from 486cf38 to e93e444 Compare February 4, 2025 20:37
@nateweller nateweller force-pushed the add/components/js-imports branch 3 times, most recently from 643217f to 93a48e4 Compare February 10, 2025 00:08
@nateweller nateweller self-assigned this Feb 10, 2025
@nateweller nateweller requested a review from a team February 10, 2025 00:57
Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Looks reasonable so far.

I wonder if @manzoorwanijk has any better ideas about the inline comments, he knows TypeScript stuff a lot better than I do.


return (
<div ref={ uplotContainer } className="boost-uplot-container">
{ /* @ts-expect-error JSX element type 'UplotReact' does not have any construct or call signatures.ts(2604) */ }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, there's either some sort of weirdness when a package's default export is a function that gets TypeScript confused, or there's some sort of confusing mismatch between what the .js actually has and what the .d.ts says when the package's default export is a function. I haven't been able to find a really clear explanation.

Either way, this seems like a reasonable workaround to me. 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ended up with an interesting conflict where jetpack build plugins/jetpack would fail due to no TS error being thrown, but required for jetpack build plugins/jetpack --production when the TS errors are thrown.

I resorted to typecasting with as unknown as ... to manually specify the component types for UplotReact and ReactSlider.


return (
<div className={ componentClassName } data-testid="number-slider">
{ /* @ts-expect-error JSX element type 'ReactSlider' does not have any construct or call signatures.ts(2604) */ }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same.

@manzoorwanijk
Copy link
Copy Markdown
Member

Using this tsconfig should fix those errors

{
	"extends": "jetpack-js-tools/tsconfig.tsc.json",
	"include": [ "./index.ts", "./components", "./lib", "./tools" ],
	"compilerOptions": {
		"module": "esnext",
		"moduleResolution": "bundler",
		// ... Rest of the config
	}
}

@manzoorwanijk
Copy link
Copy Markdown
Member

As rightly pointed out by @anomiex, if you wish to include test files in tsconfig, then you will need to have a separate tsconfig for build.

@nateweller nateweller force-pushed the add/components/js-imports branch from 878df52 to 60f0892 Compare February 12, 2025 18:18
@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Feb 13, 2025

Using this tsconfig should fix those errors

{
	"extends": "jetpack-js-tools/tsconfig.tsc.json",
	"include": [ "./index.ts", "./components", "./lib", "./tools" ],
	"compilerOptions": {
		"module": "esnext",
		"moduleResolution": "bundler",
		// ... Rest of the config
	}
}

Using that tsconfig will fail the test we have that complains about trying to set "module" or "moduleResolution". 😀

After getting complaints about how "bundler" is infectious and seeing that TypeScript says libraries should use "nodenext" for best compatibility, we set up the current structure with three base tsconfig files and tests that reject use of "module", "moduleResolution", or "noEmit" elsewhere.

  • jetpack-js-tools/tsconfig.base.json is a base for setting noEmit true and using "bundler" (i.e. what you'll want for a plugin where tsc is only being used to check).
  • jetpack-js-tools/tsconfig.tsc.json is a base for setting noEmit false and using "nodenext", for when you want tsc to build the JS and emit .d.ts files (i.e. what you'll want for most libraries).
  • jetpack-js-tools/tsconfig.tsc-declaration-only.json is a base for setting noEmit false, emitDeclarationOnly true, and using "nodenext", for when you want to generate .d.ts files without using tsc for building the JS (for libs that want to use webpack to bundle the js but still want to generate .d.ts too).

@manzoorwanijk
Copy link
Copy Markdown
Member

Instead of having the bundling in that components package, should we instead bundle it via a PHP package like assets and have it loaded externally?

That way, we won't need to change anything with the components package as it's used in many different ways that may break.

For example, the weird imports like these can be tedious and can result in duplicated code in bundles

import { STORE_ID as CONNECTION_STORE_ID } from '../../../../js-packages/connection/state/store';

@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Feb 14, 2025

Instead of having the bundling in that components package, should we instead bundle it via a PHP package like assets and have it loaded externally?

The package still needs to be usable to build against. And not every reuser would want to (or be able to) externalize the dependency and use a PHP package.

For example, the weird imports like these can be tedious and can result in duplicated code in bundles

import { STORE_ID as CONNECTION_STORE_ID } from '../../../../js-packages/connection/state/store';

That's definitely something that needs to be fixed before this PR can work. See some prior discussion at #41524 (comment) for a few more details.

Base automatically changed from add/components/js-imports to trunk February 15, 2025 21:31
@nateweller nateweller marked this pull request as ready for review March 11, 2025 22:10
anomiex
anomiex previously approved these changes Mar 12, 2025
Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Looks good to me from a Garage perspective, assuming we're ok with losing TypeScript type checking of the various test files. The right files are being produced in the build artifact, no unexpected changes.

Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Now that I think of it, we should probably update
https://github.com/Automattic/jetpack/blob/1571c9f4d847cbe757727d73b2b6f747ecedd345/projects/js-packages/components/package.json#L87-L88
to be something like

		"build": "pnpm run clean && pnpm run compile-ts",
		"clean": "rm -rf build/",
		"compile-ts": "tsc --pretty",

@anomiex anomiex dismissed their stale review March 12, 2025 21:26

Thought of stuff to improve

@nateweller nateweller force-pushed the add/components/build branch from 510a836 to 9d02ba5 Compare March 16, 2025 20:58
@nateweller
Copy link
Copy Markdown
Contributor Author

@anomiex Applied all of your suggestions, builds and tests continue to pass, and TS hints/lints appear to work nicely for package consumers 👍

@nateweller nateweller added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Mar 16, 2025
@nateweller nateweller requested a review from a team March 16, 2025 21:47
Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

LGTM

@nateweller nateweller merged commit 8c7cd54 into trunk Mar 17, 2025
86 checks passed
@nateweller nateweller deleted the add/components/build branch March 17, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants