merge-user-product.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. diff --git a/src/main.ts b/src/main.ts
  2. index c132c9b..9684685 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 { performance } from 'perf_hooks';
  9. @@ -24,2 +25,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. @@ -112,2 +114,14 @@ registerListeners();
  13. +function resolveUserProduct() {
  14. + const userProductPath = path.join(userDataPath, 'product.json');
  15. +
  16. + try {
  17. + // Assign the product configuration to the global scope
  18. + const productJson = require(userProductPath);
  19. + // @ts-expect-error
  20. + globalThis._VSCODE_USER_PRODUCT_JSON = productJson;
  21. + } catch (ex) {
  22. + }
  23. +}
  24. +
  25. /**
  26. @@ -208,2 +222,3 @@ async function startup(codeCachePath: string | undefined, nlsConfig: INLSConfigu
  27. process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
  28. + resolveUserProduct();
  29. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  30. index 1a2a619..3837df0 100644
  31. --- a/src/vs/platform/product/common/product.ts
  32. +++ b/src/vs/platform/product/common/product.ts
  33. @@ -29,2 +29,38 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  34. + const { serviceUrl, publisherUrl, itemUrl, controlUrl, extensionUrlTemplate, resourceUrlTemplate } = product.extensionsGallery || {};
  35. +
  36. + Object.assign(product, {
  37. + extensionsGallery: {
  38. + serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
  39. + publisherUrl: env['VSCODE_GALLERY_PUBLISHER_URL'] || publisherUrl,
  40. + itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
  41. + controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
  42. + extensionUrlTemplate: env['VSCODE_GALLERY_EXTENSION_URL_TEMPLATE'] || extensionUrlTemplate,
  43. + resourceUrlTemplate: env['VSCODE_GALLERY_RESOURCE_URL_TEMPLATE'] || resourceUrlTemplate,
  44. + }
  45. + });
  46. +
  47. + // Merge user-customized product.json
  48. + try {
  49. + const merge = (...objects: any[]) =>
  50. + objects.reduce((result, current) => {
  51. + Object.keys(current).forEach((key) => {
  52. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  53. + result[key] = current[key];
  54. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  55. + result[key] = merge(result[key], current[key]);
  56. + } else {
  57. + result[key] = current[key];
  58. + }
  59. + });
  60. +
  61. + return result;
  62. + }, {}) as any;
  63. +
  64. + const userProduct = (globalThis as Record<string, any>)._VSCODE_USER_PRODUCT_JSON || {};
  65. +
  66. + product = merge(product, userProduct);
  67. + } catch (ex) {
  68. + }
  69. +
  70. // Running out of sources