Skip to content

Commit

Permalink
Added possibility to allow trusted vendors to change code outside the…
Browse files Browse the repository at this point in the history
…ir namespace (#3156) (#3266)

* Added possibility to allow trusted vendors to change code outside their namespace (#3156)
* Read trusted vendors from root project package.json
* Checking if package.json exists (Wrong context in some tests)
* Rename trusted_vendors to trusted-vendors
* use process.cwd instead of hard context
* Run prettier

Co-authored-by: Lars Roettig <l.roettig@techdivision.com>
Co-authored-by: Tommy Wiebell <twiebell@adobe.com>
  • Loading branch information
3 people authored Sep 1, 2021
1 parent 3399d31 commit a972fe5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/pwa-buildpack/lib/WebpackTools/ModuleTransformConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path');
const fs = require('fs');
const buildpackName = require('../../package.json').name;

/**
Expand Down Expand Up @@ -154,6 +155,7 @@ class ModuleTransformConfig {
if (
!this._isLocal(requestor) && // Local project can modify anything
!this._isBuiltin(requestor) && // Buildpack itself can modify anything
!this._isTrustedExtensionVendor(requestor) && // Trusted extension vendors can modify anything
!fileToTransform.startsWith(requestor)
) {
throw this._traceableError(
Expand All @@ -167,6 +169,22 @@ class ModuleTransformConfig {
_isLocal(requestor) {
return requestor === this._localProjectName;
}
_isTrustedExtensionVendor(requestor) {
const vendors = this._getTrustedExtensionVendors();
const requestorVendor = requestor.split('/')[0];
return requestorVendor.length > 0 && vendors.includes(requestorVendor);
}
_getTrustedExtensionVendors() {
const configPath = path.resolve(process.cwd(), 'package.json');
if (!fs.existsSync(configPath)) {
return [];
}
const config = require(configPath)['pwa-studio'];
const configSectionName = 'trusted-vendors';
return config && config[configSectionName]
? config[configSectionName]
: [];
}
_traceableError(msg) {
const capturedError = new Error(`ModuleTransformConfig: ${msg}`);
Error.captureStackTrace(capturedError, ModuleTransformConfig);
Expand Down

0 comments on commit a972fe5

Please sign in to comment.