diff --git a/src/cli.ts b/src/cli.ts index b643e34..2f228ef 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -5,2 +5,4 @@ +import * as path from 'node:path'; +import { createRequire } from 'node:module'; import './bootstrap-cli.js'; // this MUST come before other imports as it changes global state @@ -10,3 +12,5 @@ import { resolveNLSConfiguration } from './vs/base/node/nls.js'; import { product } from './bootstrap-meta.js'; +import { getUserDataPath } from './vs/platform/environment/node/userDataPath.js'; +const require = createRequire(import.meta.url); // NLS @@ -21,2 +25,4 @@ process.env['VSCODE_CLI'] = '1'; +resolveUserProduct(); + // Bootstrap ESM @@ -26 +32,14 @@ await bootstrapESM(); await import('./vs/code/node/cli.js'); + +function resolveUserProduct() { + const userDataPath = getUserDataPath({_:[]}, product.nameShort ?? 'code-oss-dev'); + const userProductPath = path.join(userDataPath, 'product.json'); + + try { + // Assign the product configuration to the global scope + const productJson = require(userProductPath); + + globalThis._VSCODE_USER_PRODUCT_JSON = productJson; + } catch (ex) { + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 7b7e1da..f07b015 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,2 +8,3 @@ import * as fs from 'original-fs'; import * as os from 'node:os'; +import { createRequire } from 'node:module'; import { performance } from 'node:perf_hooks'; @@ -22,2 +23,4 @@ import { NativeParsedArgs } from './vs/platform/environment/common/argv.js'; +const require = createRequire(import.meta.url); + perf.mark('code/didStartMain'); @@ -109,2 +112,14 @@ registerListeners(); +function resolveUserProduct() { + const userProductPath = path.join(userDataPath, 'product.json'); + + try { + // Assign the product configuration to the global scope + const productJson = require(userProductPath); + + globalThis._VSCODE_USER_PRODUCT_JSON = productJson; + } catch (ex) { + } +} + /** @@ -205,2 +220,3 @@ async function startup(codeCachePath: string | undefined, nlsConfig: INLSConfigu process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || ''; + resolveUserProduct(); diff --git a/src/typings/vscode-globals-product.d.ts b/src/typings/vscode-globals-product.d.ts index 2cd632e..dbb25e3 100644 --- a/src/typings/vscode-globals-product.d.ts +++ b/src/typings/vscode-globals-product.d.ts @@ -29,2 +29,4 @@ declare global { + var _VSCODE_USER_PRODUCT_JSON: Record; + } diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts index 6f093e9..b63af55 100644 --- a/src/vs/platform/product/common/product.ts +++ b/src/vs/platform/product/common/product.ts @@ -31,2 +31,25 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) { + // Merge user-customized product.json + try { + const merge = (...objects: any[]) => + objects.reduce((result, current) => { + Object.keys(current).forEach((key) => { + if (Array.isArray(result[key]) && Array.isArray(current[key])) { + result[key] = current[key]; + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') { + result[key] = merge(result[key], current[key]); + } else { + result[key] = current[key]; + } + }); + + return result; + }, {}) as any; + + const userProduct = globalThis._VSCODE_USER_PRODUCT_JSON || {}; + + product = merge(product, userProduct); + } catch (ex) { + } + // Running out of sources