Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan Package: Fix Build #40299

Merged
merged 4 commits into from
Nov 26, 2024
Merged

Scan Package: Fix Build #40299

merged 4 commits into from
Nov 26, 2024

Conversation

nateweller
Copy link
Contributor

@nateweller nateweller commented Nov 21, 2024

Following up on #40262, this PR ensures the js-packages/scan project actually builds the build folder using tsc.

Proposed changes:

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

#40262

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

No

Testing instructions:

  • Run jetpack build js-packages/scan and validate the build directory is generated.

@nateweller nateweller self-assigned this Nov 21, 2024
@nateweller nateweller requested review from anomiex and a team November 21, 2024 22:54
@nateweller nateweller added the [Type] Bug When a feature is broken and / or not performing as intended label Nov 21, 2024
Copy link
Contributor

github-actions bot commented Nov 21, 2024

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 WordPress.com Simple 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, and enable the fix/scan/build branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack fix/scan/build
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/scan/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

Copy link
Contributor

github-actions bot commented Nov 21, 2024

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 Team Review, ...).
  • ✅ 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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@nateweller nateweller force-pushed the fix/scan/build branch 3 times, most recently from f45ec68 to aa72eaf Compare November 22, 2024 00:02
@nateweller nateweller mentioned this pull request Nov 22, 2024
3 tasks
@nateweller nateweller force-pushed the fix/scan/build branch 4 times, most recently from 428ed09 to ff114a3 Compare November 22, 2024 01:13
@nateweller
Copy link
Contributor Author

nateweller commented Nov 22, 2024

@anomiex What do you think about this alternate to #40262?

I had to extend tsconfig.base.json instead of tsconfig.tsc.json to get tests passing. Is that change appropriate for the use case of this package?

My ultimate hope and dream for the scan package is to have a reusable TS lib that exports types, functions, and translatable strings related to Jetpack Scan features. Initially for use across Jetpack and Jetpack Protect plugins, and then potentially sharing code with Calypso if/as possible and useful.

I know the inclusion of @wordpress/i18n complicates things. I appreciate any notes! Thanks 😄

Edit: Could we use the declaration-only base to export types, and then have consumers (Jetpack, Jetpack Protect) be responsible for compiling the TS?

@anomiex
Copy link
Contributor

anomiex commented Nov 22, 2024

I had to extend tsconfig.base.json instead of tsconfig.tsc.json to get tests passing. Is that change appropriate for the use case of this package?

No, if you're using tsc to build then you should be using tsconfig.tsc.json. The tests will have to be fixed to work with that.

The reason for that is that tsconfig.base.json uses "moduleResolution": "bundler", which is infectious: if a library package uses that, then anything using the library also needs to use that or else tsc blows up. tsconfig.tsc.json uses "moduleResolution": "nodenext", which is what https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution-for-libraries recommends for interoperability.

If you can't figure the tests out on your own, feel free to push what you have and ask for help. 🙂

Edit: Could we use the declaration-only base to export types, and then have consumers (Jetpack, Jetpack Protect) be responsible for compiling the TS?

You could, but there's not much point IMO. The intent of the declaration-only base is for when you want to use webpack instead of tsc to compile the TS to JS but also want to produce .d.ts files (using tsc or fork-ts-checker-webpack-plugin). If the consumers have to compile the TS themselves, they don't need exported types because they get the types directly from the TS sources.

The consumers having to compile the TS themselves is effectively the case now, and if it's the way you want to go with this package then #40262 should be done to clean up. The down side is that it'll be harder to use in external consumers such as Calypso, because they would also have to be configured to compile the TS from this package themselves.

@nateweller nateweller mentioned this pull request Nov 22, 2024
3 tasks
@nateweller
Copy link
Contributor Author

Thanks again @anomiex, your expertise here is super valuable. I would vote we continue not shipping JS, and have re-opened a PR for that here: #40318

My thought is, we need the consumers/plugins to compile the translations. Otherwise, we could just build and ship JS right from the plugin if it was just types and utils.

P2'd this as well: peb6dq-3as-p2

@nateweller nateweller marked this pull request as ready for review November 23, 2024 01:21
@nateweller nateweller added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review DO NOT MERGE don't merge it! and removed [Status] In Progress [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Nov 23, 2024
@nateweller nateweller marked this pull request as draft November 23, 2024 01:24
@nateweller nateweller removed the DO NOT MERGE don't merge it! label Nov 23, 2024
@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Nov 23, 2024
@anomiex
Copy link
Contributor

anomiex commented Nov 25, 2024

Translations are a whole other issue! 😀

For modern-ish plugins on dotorg, translation generally happens via translate.wordpress.org based on what JS is in the actual bundles. Whether that was compiled directly from TS into the bundle or was compiled to JS and then the JS was bundled doesn't make a difference.

For other stuff it all depends on their toolchain for doing translations. Which as far as I know there isn't much of a standard around, but I'd be surprised if compiling directly from a TS-package versus using already-compiled JS from a JS-package made much difference.

@nateweller nateweller removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] In Progress labels Nov 25, 2024
@nateweller nateweller marked this pull request as ready for review November 25, 2024 23:21
@nateweller
Copy link
Contributor Author

@anomiex Thanks again for the guidance! I've updated this PR. Here's the outline:

  • Use tsc to build the scan package, extending jetpack-js-tools/tsconfig.tsc.json.
  • Add ts-jest-resolver to enable the JS Tests checks to follow the .js imports inside the scan package's .ts files.
  • Remove babel deps.

This will allow us to write TS, export JS, and maintain compatibility with monorepo tooling. I've been using the ai-client package as a reference, aside from the related updated to the JS Tests/Jest resolver. I've tested stacking this PR on top of this setup, and the package integrates smoothly with the Jetpack Protect plugin 👍

@nateweller nateweller added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Nov 26, 2024
Copy link
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 to me, and I see CI is happy.

@nateweller nateweller merged commit 70a19bc into trunk Nov 26, 2024
76 checks passed
@nateweller nateweller deleted the fix/scan/build branch November 26, 2024 17:19
@github-actions github-actions bot removed [Status] Needs Team Review [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Nov 26, 2024
@anomiex anomiex mentioned this pull request Dec 4, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Scan RNA [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants