feat-user-product.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. diff --git a/src/main.ts b/src/main.ts
  2. index deba4c4..1b41bde 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 'node:os';
  7. +import { createRequire } from 'node:module';
  8. import { performance } from 'node: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 5a6c171..275cbcf 100644
  32. --- a/src/vs/platform/product/common/product.ts
  33. +++ b/src/vs/platform/product/common/product.ts
  34. @@ -31,2 +31,25 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  35. + // Merge user-customized product.json
  36. + try {
  37. + const merge = (...objects: any[]) =>
  38. + objects.reduce((result, current) => {
  39. + Object.keys(current).forEach((key) => {
  40. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  41. + result[key] = current[key];
  42. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  43. + result[key] = merge(result[key], current[key]);
  44. + } else {
  45. + result[key] = current[key];
  46. + }
  47. + });
  48. +
  49. + return result;
  50. + }, {}) as any;
  51. +
  52. + const userProduct = (globalThis as Record<string, any>)._VSCODE_USER_PRODUCT_JSON || {};
  53. +
  54. + product = merge(product, userProduct);
  55. + } catch (ex) {
  56. + }
  57. +
  58. // Running out of sources