merge-user-product.patch 2.5 KB

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