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

Added possibility to allow trusted vendors to change code outside their namespace (#3156) #3266

Merged
merged 18 commits into from Sep 1, 2021

Conversation

0m3r
Copy link
Contributor

@0m3r 0m3r commented Jul 13, 2021

Gives the possibility to add trusted vendors in package.json

"pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    },
   "trusted-vendors":  [
      "@vendor"
   ]

and add custom checking into the file: packages/pwa-buildpack/lib/WebpackTools/ModuleTransformConfig.js _assertAllowedToTransform

Description

Added possibility to allow trusted vendors to change code outside their namespace

Related Issue

Closes #3156.

Acceptance

@sirugh
@zetlen

Verification Stakeholders

@jerschipper
@Jordaneisenburger

Verification Steps

in your project root package.json

"pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    },
   "trusted-vendors":  [
      "@vendor"
   ]

in your extension intercept.js ('@vendor/extension/lib/intercept.js')

const { Targetables } = require('@magento/pwa-buildpack');
module.exports = targets => {
   const targetables = Targetables.using(targets);

   const HeaderComponent = targetables.reactComponent(
        '@magento/venia-ui/lib/components/Header/header.js'
    );
    
    HeaderComponent.insertAfterJSX(    
        '<SearchBar isOpen={isSearchOpen} ref={searchRef} />',
        `<span>INSERTED</span>`
    );
}

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jul 13, 2021

Messages
📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

Generated by 🚫 dangerJS against 1543a9c

@fooman
Copy link
Contributor

fooman commented Jul 13, 2021

@0m3r I like the direction where this is going. I am a little bit afraid that having this part of the .env makes a bit harder than necessary to administer though. Ideally the decision to add a vendor as trusted is done on a per project basis rather than on a per environment basis. It could lead to hard to track down issues once you end up with a list longer than a few vendors.

Ideally this configuration could live in a file that is part of the checked in code for the project. packages.json might a good fit as part of this:

  "pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    }

to

  "pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    },
   "trusted_vendors":  [
      "@vendor"
   ]

@larsroettig
Copy link
Member

@0m3r I like the direction where this is going. I am a little bit afraid that having this part of the .env makes a bit harder than necessary to administer though. Ideally the decision to add a vendor as trusted is done on a per project basis rather than on a per environment basis. It could lead to hard to track down issues once you end up with a list longer than a few vendors.

Ideally this configuration could live in a file that is part of the checked in code for the project. packages.json might a good fit as part of this:

  "pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    }

to

  "pwa-studio": {
    "targets": {
      "intercept": "./local-intercept.js"
    },
   "trusted_vendors":  [
      "@vendor"
   ]

Hi @0m3r. I totally agree with @fooman from my point of view this would be very nice if we can do this via package.json.
Currently, I will ask the core team about their opinion.

kind regards,

Lars

@0m3r
Copy link
Contributor Author

0m3r commented Jul 29, 2021

Currently, I will ask the core team about their opinion.

what about core team opinion?

@larsroettig
Copy link
Member

@supernova-at agreed with me on this yesterday would be cool if you can do it

@0m3r
Copy link
Contributor Author

0m3r commented Jul 29, 2021

@larsroettig, @supernova-at review this commit e29c51e, please

@larsroettig larsroettig self-requested a review July 30, 2021 09:39
Copy link
Member

@larsroettig larsroettig left a comment

Choose a reason for hiding this comment

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

Hi @0m3r,
The code looks good pls. Add test coverage, fix the two failing test cases and run yarn run prettier.

packages/peregrine/lib/targets/__tests__/peregrine-targets.spec.js
packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js

Thank you in advance. Also, I recommend joining as Slack then we answer questions mutch faster

https://devdocs.magento.com/community/resources.html

@0m3r
Copy link
Contributor Author

0m3r commented Jul 30, 2021

Can I fix test fails in "my" code?

something like below

        const fs = require('fs');
...
        const context = path.resolve(__dirname, '../../../../../');
        const configPath = path.resolve(context, 'package.json');
        try {
            if (fs.existsSync(configPath)) {
                const config = require(configPath)['pwa-studio'];
                return config && config['trusted_vendors'] ? config['trusted_vendors'] : [];
                //file exists
            }
        } catch(err) {
          // console.error(err)
        }
        return [];

@larsroettig larsroettig requested a review from jimbo July 31, 2021 18:02
@larsroettig
Copy link
Member

Hi @jimbo.
what do think about this PR like the idea and is very helpful for partners.

kind regards.,

Lars

@0m3r 0m3r requested a review from larsroettig August 2, 2021 08:30
@larsroettig
Copy link
Member

larsroettig commented Aug 3, 2021

One think about Extension package.json if some extension it allows itself via

trusted_vendors":  [
      "@vendor"
   ]

Should be prevented in every case a yarn install should be not enough to get access to this low level to react extension point for security reasons.

Verification Steps

  • Checks for trusted_vendors will only be parsed from the root project package.json

@jimbo if we accept this from the core team we should ask also for adding test case to https://github.com/larsroettig/pwa-studio/blob/e5d4c42855627c4365fb3313f52837945a30aeb4/packages/pwa-buildpack/lib/WebpackTools/__tests__/MagentoResolver.spec.js

@jimbo
Copy link
Contributor

jimbo commented Aug 16, 2021

Hi @jimbo.
what do think about this PR like the idea and is very helpful for partners.

I think it's great. We can certainly do more to expose components + API, as we do for talons, but this is a great way to relieve people's pain while we figure out those details.

@tjwiebell tjwiebell added the version: Minor This changeset includes functionality added in a backwards compatible manner. label Aug 26, 2021
Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

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

@0m3r Add support for monorepo and I think @larsroettig was also requesting test coverage if possible. Otherwise this looks perfect, nice work 👍

@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in Pull Request Progress Aug 27, 2021
@0m3r
Copy link
Contributor Author

0m3r commented Aug 30, 2021

@0m3r Add support for monorepo and I think @larsroettig was also requesting test coverage if possible. Otherwise this looks perfect, nice work

about tests

I did not find ModuleTransformConfig.spec.js
Unfortunately, I don't have enough experience to write this from scratch.

@tjwiebell
Copy link
Contributor

@0m3r Existing code appears to be tested by integration tests in other packages, there is no unit test. Instead of building all that out in this scope, I've created a manual test that we'll run during regression and aim to automate if it becomes a priority. Thank you for the contribution.

✅ QA Passed

@m2-community-project m2-community-project bot moved this from Review in Progress to Reviewer Approved in Pull Request Progress Sep 1, 2021
@tjwiebell tjwiebell dismissed larsroettig’s stale review September 1, 2021 20:27

Added manual test for now

@tjwiebell tjwiebell merged commit a972fe5 into magento:develop Sep 1, 2021
@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:pwa-buildpack Progress: done version: Minor This changeset includes functionality added in a backwards compatible manner.
Development

Successfully merging this pull request may close these issues.

[feature]: Add the possibility to allow certain packages to change code outside their namespace
6 participants