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

Protect Components: Use @wordpress/dataviews/wp import path #41510

Draft
wants to merge 17 commits into
base: add/protect/core
Choose a base branch
from

Conversation

nateweller
Copy link
Contributor

@nateweller nateweller commented Feb 3, 2025

See WordPress/gutenberg#66825 for more info on the @wordpress/dataviews/wp import path.

Proposed changes:

  • Changes instances of import ... from '@wordpress/dataviews' to import ... from '@wordpress/dataviews/wp'.
  • See Protect's webpack config for an example of how the components will be transpiled.

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

peb6dq-3ta-p2

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

No

Testing instructions:

  • Review automated tests, ensure all passing.
  • Manually test the ThreatsDataViews and ScanReport components.
    • Option A - Storybook: cd projects/js-packages/storybook && pnpm storybook:dev
    • Option B - Smoke test the Jetpack Protect plugin

@nateweller nateweller changed the base branch from trunk to add/protect/core February 3, 2025 16:46
Copy link
Contributor

github-actions bot commented Feb 3, 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 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 add/components/dataviews-wp-import 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 add/components/dataviews-wp-import
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/components/dataviews-wp-import
    

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 Feb 3, 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 Team 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 🤖


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!


Protect plugin:

  • Next scheduled release: none scheduled.

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 would need you to make some changes or provide some more details about your PR. Thank you! label Feb 3, 2025
Copy link
Contributor

github-actions bot commented Feb 3, 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 self-assigned this Feb 3, 2025
@nateweller nateweller force-pushed the add/components/dataviews-wp-import branch from 8cc7233 to 65b7cd0 Compare February 3, 2025 21:31
@github-actions github-actions bot added the [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. label Feb 3, 2025
@nateweller
Copy link
Contributor Author

nateweller commented Feb 3, 2025

Build currently fails with the following:

In GitHub build (logs):

[plugins/jetpack 2:09.374] [build-production-extensions] ERROR in ../../../node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/build-wp/index.js 8555:0-65
[plugins/jetpack 2:09.374] [build-production-extensions] Module not found: Error: Can't resolve '@wordpress/date' in '/home/runner/work/jetpack/jetpack/node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/build-wp'
[plugins/jetpack 2:09.374] [build-production-extensions] resolve '@wordpress/date' in '/home/runner/work/jetpack/jetpack/node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/build-wp'
[plugins/jetpack 2:09.374] [build-production-extensions]   Parsed request is a module
[plugins/jetpack 2:09.374] [build-production-extensions]   using description file: /home/runner/work/jetpack/jetpack/node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/package.json (relative path: ./build-wp)
[plugins/jetpack 2:09.374] [build-production-extensions]     Field 'browser' doesn't contain a valid alias configuration
[plugins/jetpack 2:09.374] [build-production-extensions]     resolve as module
[plugins/jetpack 2:09.374] [build-production-extensions]       /home/runner/work/jetpack/jetpack/node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/build-wp/node_modules doesn't exist or is not a directory

When running locally (jetpack build plugins/protect --production -v I get something different:

ERROR in index.js:60:6036: domain argument (index 2) is missing: (0,s.__)("Select item")

@nateweller nateweller force-pushed the add/components/dataviews-wp-import branch from 33306a4 to dd2f628 Compare February 4, 2025 20:30
@nateweller nateweller force-pushed the add/components/dataviews-wp-import branch from 65e404a to 907c3b8 Compare February 4, 2025 21:11
pnpm-lock.yaml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

You've got a lot of accidental downgrades going on here. You should probably do something like git fetch && git checkout $( git merge-base HEAD origin/add/protect/core ) pnpm-lock.yaml && pnpm dedupe to regnerate this file.

.pnpmfile.cjs Outdated Show resolved Hide resolved
@nateweller nateweller force-pushed the add/components/dataviews-wp-import branch 2 times, most recently from dbeb4ff to 672faeb Compare February 6, 2025 01:34
@nateweller
Copy link
Contributor Author

nateweller commented Feb 7, 2025

This PR has been updated. Summary of changes:

  1. Adds missing deps to .pnpmfile.cjs.
  2. Updates Protect's build config:
  • Targets the specific @wordpress/dataviews/build-wp path for the replace textdomain rule.
  • Adds custom functions map to the replace textdomain config.

Rebased and rebuilt pnpm to address unintentional downgrades.

Currently looking into why the JS Tests are failing:

[plugins/jetpack] [test-extensions] FAIL extensions/blocks/goodreads/test/validate.js
[plugins/jetpack] [test-extensions]   ● Test suite failed to run
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     Jest encountered an unexpected token
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     By default "node_modules" folder is ignored by transformers.
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     Here's what you can do:
[plugins/jetpack] [test-extensions]      • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
[plugins/jetpack] [test-extensions]      • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
[plugins/jetpack] [test-extensions]      • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
[plugins/jetpack] [test-extensions]      • If you need a custom transformation specify a "transform" option in your config.
[plugins/jetpack] [test-extensions]      • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     You'll find more details and examples of these config options in the docs:
[plugins/jetpack] [test-extensions]     https://jestjs.io/docs/configuration
[plugins/jetpack] [test-extensions]     For information about custom transformations, see:
[plugins/jetpack] [test-extensions]     https://jestjs.io/docs/code-transformation
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     Details:
[plugins/jetpack] [test-extensions] 
[plugins/jetpack]     /home/runner/work/jetpack/jetpack/node_modules/.pnpm/@[email protected]_patch_hash=uzs6glhpt3sq2uqjvqzk6vk2ze_@[email protected][email protected]/node_modules/@wordpress/dataviews/build-wp/index.js:8
[plugins/jetpack] [test-extensions]     import clsx from "clsx";
[plugins/jetpack] [test-extensions]     ^^^^^^
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]     SyntaxError: Cannot use import statement outside a module
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]        6 | 	type Threat,
[plugins/jetpack] [test-extensions]        7 | } from '@automattic/jetpack-scan';
[plugins/jetpack] [test-extensions]     >  8 | import {
[plugins/jetpack] [test-extensions]          | ^
[plugins/jetpack] [test-extensions]        9 | 	type Field,
[plugins/jetpack] [test-extensions]       10 | 	type FieldType,
[plugins/jetpack] [test-extensions]       11 | 	type Filter,
[plugins/jetpack] [test-extensions] 
[plugins/jetpack] [test-extensions]       at Runtime.createScriptFromCode (../../../node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1505:14)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/components/components/threats-data-views/index.tsx:8:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/components/index.ts:49:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/connection/components/connect-screen/basic/visual.tsx:1:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/connection/components/connect-screen/basic/index.tsx:4:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/connection/index.jsx:20:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/shared-extension-utils/src/hooks/use-analytics.js:2:1)
[plugins/jetpack] [test-extensions]       at Object.require (../../js-packages/shared-extension-utils/index.js:18:1)
[plugins/jetpack] [test-extensions]       at Object.require (extensions/blocks/goodreads/edit.js:1:1)
[plugins/jetpack] [test-extensions]       at Object.require (extensions/blocks/goodreads/test/validate.js:3:1)

The above error is introduced when switching between importing from @wordpress/dataviews to @wordpress/dataviews/wp. This might be resolved when we migrate the threats components into their own package, where there could be a different Jest config.

@nateweller nateweller force-pushed the add/components/dataviews-wp-import branch from d9c496f to c97a1b2 Compare February 9, 2025 21:56
@anomiex
Copy link
Contributor

anomiex commented Feb 10, 2025

The test failure looks like the same thing as described in the "ESM" section of WordPress/gutenberg#67897. TL;DR: The way @wordpress/dataviews is set up, the file is supposed to contain CommonJS, but it actually contains ESM. We currently have a hack around it for the normal import, but we can't do the same for the /wp entry point because there's no CommonJS build of that to point at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Components [Package] Protect Status [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. RNA [Status] In Progress [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants