merge-user-product.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. diff --git a/src/main.ts b/src/main.ts
  2. index 62ddd5f..90c6cfd 100644
  3. --- a/src/main.ts
  4. +++ b/src/main.ts
  5. @@ -8,2 +8,3 @@ import * as fs from 'original-fs';
  6. import * as os from 'os';
  7. +import { createRequire } from 'node:module';
  8. import { configurePortable } from './bootstrap-node.js';
  9. @@ -23,2 +24,3 @@ import { NativeParsedArgs } from './vs/platform/environment/common/argv.js';
  10. const __dirname = path.dirname(fileURLToPath(import.meta.url));
  11. +const require = createRequire(import.meta.url);
  12. @@ -103,2 +105,13 @@ registerListeners();
  13. +function resolveUserProduct() {
  14. + const userProductPath = `file:///${userDataPath}/product.json`;
  15. +
  16. + try {
  17. + // Assign the product configuration to the global scope
  18. + const productPath = require(fileURLToPath(userProductPath));
  19. + globalThis._VSCODE_PRODUCT_JSON = productPath;
  20. + } catch (ex) {
  21. + }
  22. +}
  23. +
  24. /**
  25. @@ -174,2 +188,3 @@ async function startup(codeCachePath: string | undefined, nlsConfig: INLSConfigu
  26. process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
  27. + resolveUserProduct();
  28. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  29. index 1a2a619..9bf5ac0 100644
  30. --- a/src/vs/platform/product/common/product.ts
  31. +++ b/src/vs/platform/product/common/product.ts
  32. @@ -29,2 +29,36 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  33. + const { serviceUrl, searchUrl, itemUrl, controlUrl } = product.extensionsGallery || {};
  34. +
  35. + Object.assign(product, {
  36. + extensionsGallery: {
  37. + serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
  38. + searchUrl: env['VSCODE_GALLERY_SEARCH_URL'] || searchUrl,
  39. + itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
  40. + controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
  41. + }
  42. + });
  43. +
  44. + // Merge user-customized product.json
  45. + try {
  46. + const merge = (...objects: any[]) =>
  47. + objects.reduce((result, current) => {
  48. + Object.keys(current).forEach((key) => {
  49. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  50. + result[key] = current[key];
  51. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  52. + result[key] = merge(result[key], current[key]);
  53. + } else {
  54. + result[key] = current[key];
  55. + }
  56. + });
  57. +
  58. + return result;
  59. + }, {}) as any;
  60. +
  61. + const userProduct = (globalThis as Record<string, any>)._VSCODE_USER_PRODUCT_JSON || {};
  62. +
  63. + product = merge(product, userProduct);
  64. + } catch (ex) {
  65. + }
  66. +
  67. // Running out of sources