custom-gallery.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. diff --git a/src/vs/base/common/product.ts b/src/vs/base/common/product.ts
  2. index 657b9c9..9b9b12e 100644
  3. --- a/src/vs/base/common/product.ts
  4. +++ b/src/vs/base/common/product.ts
  5. @@ -70,6 +70,7 @@ export interface IProductConfiguration {
  6. readonly extensionsGallery?: {
  7. readonly serviceUrl: string;
  8. + readonly cacheUrl?: string;
  9. readonly itemUrl: string;
  10. readonly resourceUrlTemplate: string;
  11. readonly controlUrl: string;
  12. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  13. index 5e38d35..12bb161 100644
  14. --- a/src/vs/platform/product/common/product.ts
  15. +++ b/src/vs/platform/product/common/product.ts
  16. @@ -4,11 +4,12 @@
  17. *--------------------------------------------------------------------------------------------*/
  18. import { FileAccess } from 'vs/base/common/network';
  19. -import { globals } from 'vs/base/common/platform';
  20. +import { globals, isWindows } from 'vs/base/common/platform';
  21. import { env } from 'vs/base/common/process';
  22. import { IProductConfiguration } from 'vs/base/common/product';
  23. import { dirname, joinPath } from 'vs/base/common/resources';
  24. import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
  25. +import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
  26. /**
  27. * @deprecated You MUST use `IProductService` if possible.
  28. @@ -34,6 +35,32 @@ else if (typeof require?.__$__nodeRequire === 'function') {
  29. product = require.__$__nodeRequire(joinPath(rootPath, 'product.json').fsPath);
  30. const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string; };
  31. + // Merge user-customized product.json
  32. + try {
  33. + const merge = (...objects: any[]) =>
  34. + objects.reduce((result, current) => {
  35. + Object.keys(current).forEach((key) => {
  36. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  37. + result[key] = current[key];
  38. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  39. + result[key] = merge(result[key], current[key]);
  40. + } else {
  41. + result[key] = current[key];
  42. + }
  43. + });
  44. +
  45. + return result;
  46. + }, {}) as any;
  47. +
  48. + const userDataPath = getUserDataPath({} as any);
  49. + const userProductPath = isWindows ? `file:///${userDataPath}/product.json` : `file://${userDataPath}/product.json`;
  50. +
  51. + const userProduct = require.__$__nodeRequire(FileAccess.asFileUri(userProductPath, require).fsPath);
  52. +
  53. + product = merge(product, userProduct);
  54. + } catch (ex) {
  55. + }
  56. +
  57. // Running out of sources
  58. if (env['VSCODE_DEV']) {
  59. Object.assign(product, {
  60. @@ -43,6 +70,19 @@ else if (typeof require?.__$__nodeRequire === 'function') {
  61. });
  62. }
  63. + // Set user-defined extension gallery
  64. + const { serviceUrl, cacheUrl, itemUrl, controlUrl, recommendationsUrl } = product.extensionsGallery || {}
  65. +
  66. + Object.assign(product, {
  67. + extensionsGallery: {
  68. + serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
  69. + cacheUrl: env['VSCODE_GALLERY_CACHE_URL'] || cacheUrl,
  70. + itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
  71. + controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
  72. + recommendationsUrl: env['VSCODE_GALLERY_RECOMMENDATIONS_URL'] || recommendationsUrl
  73. + }
  74. + })
  75. +
  76. Object.assign(product, {
  77. version: pkg.version
  78. });