Split up the two web content patchers

pull/142116/head
Alex Dima 2022-02-03 15:02:33 +01:00
parent 70512df882
commit 9fb5c8e094
No known key found for this signature in database
GPG Key ID: 39563C1504FDD0C9
1 changed files with 42 additions and 4 deletions

View File

@ -77,10 +77,7 @@ exports.vscodeWebEntryPoints = vscodeWebEntryPoints;
const buildDate = new Date().toISOString();
/**
* @param extensionsRoot {string} The location where extension will be read from
*/
const createVSCodeWebFileContentMapper = (extensionsRoot) => {
const createVSCodeWebProductConfigurationPatcher = () => {
/**
* @param content {string} The contens of the file
* @param path {string} The absolute file path, always using `/`, even on Windows
@ -98,6 +95,20 @@ const createVSCodeWebFileContentMapper = (extensionsRoot) => {
return content.replace('/*BUILD->INSERT_PRODUCT_CONFIGURATION*/', productConfiguration.substr(1, productConfiguration.length - 2) /* without { and }*/);
}
return content;
};
return result;
};
/**
* @param extensionsRoot {string} The location where extension will be read from
*/
const createVSCodeWebBuiltinExtensionsPatcher = (extensionsRoot) => {
/**
* @param content {string} The contens of the file
* @param path {string} The absolute file path, always using `/`, even on Windows
*/
const result = (content, path) => {
// (2) Patch builtin extensions
if (path.endsWith('vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.js')) {
const builtinExtensions = JSON.stringify(extensions.scanBuiltinExtensions(extensionsRoot));
@ -108,6 +119,33 @@ const createVSCodeWebFileContentMapper = (extensionsRoot) => {
};
return result;
};
/**
* @param patchers {((content:string, path: string)=>string)[]}
*/
const combineContentPatchers = (...patchers) => {
/**
* @param content {string} The contens of the file
* @param path {string} The absolute file path, always using `/`, even on Windows
*/
const result = (content, path) => {
for (const patcher of patchers) {
content = patcher(content, path);
}
return content;
};
return result;
};
/**
* @param extensionsRoot {string} The location where extension will be read from
*/
const createVSCodeWebFileContentMapper = (extensionsRoot) => {
return combineContentPatchers(
createVSCodeWebProductConfigurationPatcher(),
createVSCodeWebBuiltinExtensionsPatcher(extensionsRoot)
);
};
exports.createVSCodeWebFileContentMapper = createVSCodeWebFileContentMapper;
const optimizeVSCodeWebTask = task.define('optimize-vscode-web', task.series(