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
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/pwa-buildpack/lib/WebpackTools/ModuleTransformConfig.js
@@ -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 context = path.resolve(__dirname, '../../../../../');
0m3r marked this conversation as resolved.
Show resolved Hide resolved
const configPath = path.resolve(context, 'package.json');
if (!fs.existsSync(configPath)) {
return [];
}
const config = require(configPath)['pwa-studio'];
return config && config['trusted_vendors']
0m3r marked this conversation as resolved.
Show resolved Hide resolved
? config['trusted_vendors']
: [];
}
_traceableError(msg) {
const capturedError = new Error(`ModuleTransformConfig: ${msg}`);
Error.captureStackTrace(capturedError, ModuleTransformConfig);
Expand Down