feat-user-product.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. diff --git a/src/cli.ts b/src/cli.ts
  2. index b643e34..2f228ef 100644
  3. --- a/src/cli.ts
  4. +++ b/src/cli.ts
  5. @@ -5,2 +5,4 @@
  6. +import * as path from 'node:path';
  7. +import { createRequire } from 'node:module';
  8. import './bootstrap-cli.js'; // this MUST come before other imports as it changes global state
  9. @@ -10,3 +12,5 @@ import { resolveNLSConfiguration } from './vs/base/node/nls.js';
  10. import { product } from './bootstrap-meta.js';
  11. +import { getUserDataPath } from './vs/platform/environment/node/userDataPath.js';
  12. +const require = createRequire(import.meta.url);
  13. // NLS
  14. @@ -21,2 +25,4 @@ process.env['VSCODE_CLI'] = '1';
  15. +resolveUserProduct();
  16. +
  17. // Bootstrap ESM
  18. @@ -26 +32,14 @@ await bootstrapESM();
  19. await import('./vs/code/node/cli.js');
  20. +
  21. +function resolveUserProduct() {
  22. + const userDataPath = getUserDataPath({_:[]}, product.nameShort ?? 'code-oss-dev');
  23. + const userProductPath = path.join(userDataPath, 'product.json');
  24. +
  25. + try {
  26. + // Assign the product configuration to the global scope
  27. + const productJson = require(userProductPath);
  28. +
  29. + globalThis._VSCODE_USER_PRODUCT_JSON = productJson;
  30. + } catch (ex) {
  31. + }
  32. +}
  33. \ No newline at end of file
  34. diff --git a/src/main.ts b/src/main.ts
  35. index 7b7e1da..f07b015 100644
  36. --- a/src/main.ts
  37. +++ b/src/main.ts
  38. @@ -8,2 +8,3 @@ import * as fs from 'original-fs';
  39. import * as os from 'node:os';
  40. +import { createRequire } from 'node:module';
  41. import { performance } from 'node:perf_hooks';
  42. @@ -22,2 +23,4 @@ import { NativeParsedArgs } from './vs/platform/environment/common/argv.js';
  43. +const require = createRequire(import.meta.url);
  44. +
  45. perf.mark('code/didStartMain');
  46. @@ -109,2 +112,14 @@ registerListeners();
  47. +function resolveUserProduct() {
  48. + const userProductPath = path.join(userDataPath, 'product.json');
  49. +
  50. + try {
  51. + // Assign the product configuration to the global scope
  52. + const productJson = require(userProductPath);
  53. +
  54. + globalThis._VSCODE_USER_PRODUCT_JSON = productJson;
  55. + } catch (ex) {
  56. + }
  57. +}
  58. +
  59. /**
  60. @@ -205,2 +220,3 @@ async function startup(codeCachePath: string | undefined, nlsConfig: INLSConfigu
  61. process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
  62. + resolveUserProduct();
  63. diff --git a/src/typings/vscode-globals-product.d.ts b/src/typings/vscode-globals-product.d.ts
  64. index 2cd632e..dbb25e3 100644
  65. --- a/src/typings/vscode-globals-product.d.ts
  66. +++ b/src/typings/vscode-globals-product.d.ts
  67. @@ -29,2 +29,4 @@ declare global {
  68. + var _VSCODE_USER_PRODUCT_JSON: Record<string, any>;
  69. +
  70. }
  71. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  72. index 6f093e9..b63af55 100644
  73. --- a/src/vs/platform/product/common/product.ts
  74. +++ b/src/vs/platform/product/common/product.ts
  75. @@ -31,2 +31,25 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  76. + // Merge user-customized product.json
  77. + try {
  78. + const merge = (...objects: any[]) =>
  79. + objects.reduce((result, current) => {
  80. + Object.keys(current).forEach((key) => {
  81. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  82. + result[key] = current[key];
  83. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  84. + result[key] = merge(result[key], current[key]);
  85. + } else {
  86. + result[key] = current[key];
  87. + }
  88. + });
  89. +
  90. + return result;
  91. + }, {}) as any;
  92. +
  93. + const userProduct = globalThis._VSCODE_USER_PRODUCT_JSON || {};
  94. +
  95. + product = merge(product, userProduct);
  96. + } catch (ex) {
  97. + }
  98. +
  99. // Running out of sources