merge-user-product.patch 2.3 KB

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