merge-user-product.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. diff --git a/src/main.js b/src/main.js
  2. index 10bd503..4048782 100644
  3. --- a/src/main.js
  4. +++ b/src/main.js
  5. @@ -132,2 +132,14 @@ registerListeners();
  6. +function resolveUserProduct() {
  7. + const userDataPath = getUserDataPath({}, product.nameShort ?? 'code-oss-dev');
  8. + const userProductPath = `file:///${userDataPath}/product.json`;
  9. +
  10. + try {
  11. + // Assign the product configuration to the global scope
  12. + const productPath = require(fileURLToPath(userProductPath));
  13. + global["_VSCODE_USER_PRODUCT_JSON"] = productPath;
  14. + } catch (ex) {
  15. + }
  16. +}
  17. +
  18. /**
  19. @@ -208,2 +220,3 @@ function startup(codeCachePath, nlsConfig) {
  20. process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
  21. + resolveUserProduct();
  22. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  23. index a98043f..204ce1b 100644
  24. --- a/src/vs/platform/product/common/product.ts
  25. +++ b/src/vs/platform/product/common/product.ts
  26. @@ -29,2 +29,36 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  27. + const { serviceUrl, searchUrl, itemUrl, controlUrl } = product.extensionsGallery || {};
  28. +
  29. + Object.assign(product, {
  30. + extensionsGallery: {
  31. + serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
  32. + searchUrl: env['VSCODE_GALLERY_SEARCH_URL'] || searchUrl,
  33. + itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
  34. + controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
  35. + }
  36. + });
  37. +
  38. + // Merge user-customized product.json
  39. + try {
  40. + const merge = (...objects: any[]) =>
  41. + objects.reduce((result, current) => {
  42. + Object.keys(current).forEach((key) => {
  43. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  44. + result[key] = current[key];
  45. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  46. + result[key] = merge(result[key], current[key]);
  47. + } else {
  48. + result[key] = current[key];
  49. + }
  50. + });
  51. +
  52. + return result;
  53. + }, {}) as any;
  54. +
  55. + const userProduct = (globalThis as Record<string, any>)._VSCODE_USER_PRODUCT_JSON || {};
  56. +
  57. + product = merge(product, userProduct);
  58. + } catch (ex) {
  59. + }
  60. +
  61. // Running out of sources