Skip to content

Commit 1951c4b

Browse files
authored
Merge pull request #618 from CodinGame/fix-product-config
[FIX] Properly inject product configuration
2 parents 05b2386 + 558e728 commit 1951c4b

7 files changed

Lines changed: 47 additions & 30 deletions

File tree

rollup/rollup.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default (args: Record<string, string>): rollup.RollupOptions => {
125125
external,
126126
transformers: [typeDedupReplaceTransformer]
127127
}),
128-
resolveVscodePlugin(),
128+
resolveVscodePlugin(vscodeVersion, vscodeCommit),
129129
vscodeLocalizationPlugin(),
130130
typescript({
131131
noEmitOnError: true,
@@ -148,9 +148,6 @@ export default (args: Record<string, string>): rollup.RollupOptions => {
148148
}
149149
}),
150150
replace({
151-
VSCODE_VERSION: JSON.stringify(vscodeVersion),
152-
VSCODE_REF: JSON.stringify(vscodeRef),
153-
VSCODE_COMMIT: JSON.stringify(vscodeCommit),
154151
BUILD_ID: JSON.stringify(`${vscodeRef}-${crypto.randomUUID()}`),
155152
'globalThis.require': 'undefined',
156153
preventAssignment: true

rollup/tools/vscode.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
VSCODE_DIR,
1515
VSCODE_SRC_DIR
1616
} from './config.js'
17+
import { dataToEsm } from '@rollup/pluginutils'
18+
19+
const product = JSON.parse(
20+
fs.readFileSync(new URL('../../vscode/product.json', import.meta.url).pathname).toString()
21+
)
1722

1823
const { firstBy } = thenby
1924

@@ -112,7 +117,12 @@ function getMemberExpressionPath(
112117
return null
113118
}
114119

115-
export function transformVSCodeCode(id: string, code: string): string {
120+
export function transformVSCodeCode(
121+
id: string,
122+
code: string,
123+
vscodeVersion?: string,
124+
vscodeCommit?: string
125+
): string {
116126
// HACK: assign typescript decorator result to a decorated class field so rollup doesn't remove them
117127
// before:
118128
// __decorate([
@@ -129,6 +139,26 @@ export function transformVSCodeCode(id: string, code: string): string {
129139
'$2.__decorator = $1'
130140
)
131141

142+
/**
143+
* Replace default product file by product.json file content
144+
*/
145+
if (id.endsWith('vs/platform/product/common/product.js')) {
146+
patchedCode = dataToEsm(
147+
{
148+
...product,
149+
quality: 'stable',
150+
version: vscodeVersion,
151+
commit: vscodeCommit,
152+
date: new Date().toISOString()
153+
},
154+
{
155+
compact: false,
156+
namedExports: false,
157+
preferConst: false
158+
}
159+
)
160+
}
161+
132162
let cssImportCounter = 0
133163
const ast = recast.parse(patchedCode, {
134164
parser: babylonParser
@@ -321,7 +351,7 @@ function resolveVscode(importee: string, importer?: string) {
321351
return undefined
322352
}
323353

324-
export function resolveVscodePlugin(): rollup.Plugin {
354+
export function resolveVscodePlugin(vscodeVersion?: string, vscodeCommit?: string): rollup.Plugin {
325355
return {
326356
name: 'resolve-vscode',
327357
resolveId: (importeeUrl, importer) => {
@@ -345,7 +375,7 @@ export function resolveVscodePlugin(): rollup.Plugin {
345375
}
346376

347377
const content = (await fs.promises.readFile(id)).toString('utf-8')
348-
return transformVSCodeCode(id, content)
378+
return transformVSCodeCode(id, content, vscodeVersion, vscodeCommit)
349379
}
350380
}
351381
}

scripts/install-vscode

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ NODE_OPTIONS=--max-old-space-size=8192 npx tsc --declaration --importHelpers --o
8181
find ./ \( -name '*.js' -o -name '*.d.ts' -o -name '*.ttf' -o -name '*.css' -o -name '*.mp3' -o -name '*.scm' -o -name '*.svg' -o -name '*.png' -o -name '*.html' -o -name '*.sh' -o -name '*.zsh' -o -name '*.ps1' \) -exec rsync -R \{\} "$output_directory/src" \;
8282

8383
cd ..
84-
cp package.json $output_directory
84+
cp package.json product.json $output_directory
8585
# Copy editor types
8686
cp out-monaco-editor-core/esm/vs/editor/editor.api.d.ts $output_directory/src/vs/editor/editor.api.d.ts
8787

src/extension.api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions'
2323
import * as uri from 'vs/base/common/uri'
2424
import * as telemetry from 'vs/platform/telemetry/common/telemetryUtils'
2525
import { defaultApi } from './localExtensionHost.js'
26+
import deprecatedProduct from 'vs/platform/product/common/product'
2627

2728
function createProxy<T extends keyof typeof vscode>(key: T): (typeof vscode)[T] {
2829
return new Proxy(
@@ -42,7 +43,7 @@ function createProxy<T extends keyof typeof vscode>(key: T): (typeof vscode)[T]
4243
}
4344

4445
const api: typeof vscode = {
45-
version: VSCODE_VERSION,
46+
version: deprecatedProduct.version,
4647
tasks: createProxy('tasks'),
4748
notebooks: createProxy('notebooks'),
4849
scm: createProxy('scm'),

src/missing-services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,8 @@ registerSingleton(IPathService, PathService, InstantiationType.Delayed)
13421342
class ProductService implements IProductService {
13431343
readonly _serviceBrand = undefined
13441344

1345-
version = VSCODE_VERSION
1346-
commit = VSCODE_COMMIT
1345+
version = 'unknown'
1346+
commit = 'unknown'
13471347
quality = 'oss'
13481348
nameShort = 'Code - OSS Dev'
13491349
nameLong = 'Code - OSS Dev'

src/services.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type {
2121
IWorkbenchConstructionOptions,
2222
IWorkspaceProvider
2323
} from 'vs/workbench/browser/web.api'
24-
import type { IProductConfiguration } from 'vs/base/common/product'
2524
import {
2625
type ILazyWorkbenchContributionInstantiation,
2726
type IOnEditorWorkbenchContributionInstantiation,
@@ -50,6 +49,8 @@ import getLayoutServiceOverride from './service-override/layout'
5049
import getHostServiceOverride from './service-override/host'
5150
import getBaseServiceOverride from './service-override/base'
5251
import { injectCss } from './css'
52+
import deprecatedProduct from 'vs/platform/product/common/product'
53+
import { mixin } from 'vs/base/common/objects'
5354

5455
declare global {
5556
interface Window {
@@ -76,22 +77,13 @@ export async function initialize(
7677
injectCss(container)
7778
initializeWorkbench(container, configuration, env)
7879

80+
const productService: IProductService = mixin(
81+
{ _serviceBrand: undefined, ...deprecatedProduct },
82+
configuration.productConfiguration
83+
)
84+
7985
const instantiationService = StandaloneServices.initialize({
80-
[IProductService.toString()]: <Partial<IProductConfiguration>>{
81-
version: VSCODE_VERSION,
82-
quality: 'stable',
83-
commit: VSCODE_COMMIT,
84-
nameShort: 'Code - OSS',
85-
nameLong: 'Code - OSS',
86-
applicationName: 'code-oss',
87-
dataFolderName: '.vscode-oss',
88-
urlProtocol: 'code-oss',
89-
reportIssueUrl: 'https://github.com/microsoft/vscode/issues/new',
90-
licenseName: 'MIT',
91-
licenseUrl: 'https://github.com/microsoft/vscode/blob/main/LICENSE.txt',
92-
serverApplicationName: 'code-server-oss',
93-
...(configuration.productConfiguration ?? {})
94-
},
86+
[IProductService.toString()]: productService,
9587
...getLayoutServiceOverride(), // Always override layout service to break cyclic dependency with ICodeEditorService
9688
...getEnvironmentServiceOverride(),
9789
...getExtensionsServiceOverride(),

src/types.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare const VSCODE_VERSION: string
2-
declare const VSCODE_REF: string
3-
declare const VSCODE_COMMIT: string
41
declare const BUILD_ID: string
52

63
declare module 'vs/platform/accessibilitySignal/browser/media/*.mp3' {

0 commit comments

Comments
 (0)