From c30bffc60c616cccaa8cd2997814d169bc0c5b40 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:52:09 -0700 Subject: [PATCH] Set up vs project --- .eslintrc.json | 1 + bin/esbuild.mjs | 2 +- bin/update_vs_base.ps1 | 45 +++++++++++ package.json | 14 +--- src/browser/tsconfig.json | 6 +- src/common/tsconfig.json | 8 +- src/vs/README.md | 9 +++ src/vs/patches/nls.ts | 90 ++++++++++++++++++++++ src/vs/tsconfig.json | 71 +++++++++++++++++ src/vs/typings/base-common.d.ts | 20 +++++ src/vs/typings/require.d.ts | 42 ++++++++++ src/vs/typings/thenable.d.ts | 12 +++ src/vs/typings/vscode-globals-nls.d.ts | 36 +++++++++ src/vs/typings/vscode-globals-product.d.ts | 33 ++++++++ yarn.lock | 7 +- 15 files changed, 380 insertions(+), 16 deletions(-) create mode 100644 bin/update_vs_base.ps1 create mode 100644 src/vs/README.md create mode 100644 src/vs/patches/nls.ts create mode 100644 src/vs/tsconfig.json create mode 100644 src/vs/typings/base-common.d.ts create mode 100644 src/vs/typings/require.d.ts create mode 100644 src/vs/typings/thenable.d.ts create mode 100644 src/vs/typings/vscode-globals-nls.d.ts create mode 100644 src/vs/typings/vscode-globals-product.d.ts diff --git a/.eslintrc.json b/.eslintrc.json index 9c8493dd..345188c8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -43,6 +43,7 @@ }, "ignorePatterns": [ "addons/*/src/third-party/*.ts", + "src/vs/*", "out/*", "out-test/*", "out-esbuild/*", diff --git a/bin/esbuild.mjs b/bin/esbuild.mjs index f056e30d..3e792712 100644 --- a/bin/esbuild.mjs +++ b/bin/esbuild.mjs @@ -35,7 +35,7 @@ const devOptions = { const prodOptions = { minify: true, treeShaking: true, - logLevel: 'debug', + logLevel: 'verbose', legalComments: 'none', // TODO: Mangling private and protected properties will reduce bundle size quite a bit, we must // make sure we don't cast privates to `any` in order to prevent regressions. diff --git a/bin/update_vs_base.ps1 b/bin/update_vs_base.ps1 new file mode 100644 index 00000000..234bb92f --- /dev/null +++ b/bin/update_vs_base.ps1 @@ -0,0 +1,45 @@ +# Get latest vscode repo +if (Test-Path -Path "src/vs/temp") { + Write-Host "`e[32m> Fetching latest`e[0m" + git -C src/vs/temp checkout + git -C src/vs/temp pull +} else { + Write-Host "`e[32m> Cloning microsoft/vscode`e[0m" + $null = New-Item -ItemType Directory -Path "src/vs/temp" -Force + git clone https://github.com/microsoft/vscode src/vs/temp +} + +# Delete old base +Write-Host "`e[32m> Deleting old base`e[0m" +$null = Remove-Item -Recurse -Force "src/vs/base" + +# Copy base +Write-Host "`e[32m> Copying base`e[0m" +Copy-Item -Path "src/vs/temp/src/vs/base" -Destination "src/vs/base" -Recurse + +# Comment out any CSS imports +Write-Host "`e[32m> Commenting out CSS imports`e[0m" -NoNewline +$baseFiles = Get-ChildItem -Path "src/vs/base" -Recurse -File +$count = 0 +foreach ($file in $baseFiles) { + $content = Get-Content -Path $file.FullName + $updatedContent = $content | ForEach-Object { + if ($_ -match "^import 'vs/css!") { + Write-Host "`e[32m." -NoNewline + $count++ + "// $_" + } else { + $_ + } + } + $updatedContent | Set-Content -Path $file.FullName +} +Write-Host " $count files patched" + +# Copy typings +Write-Host "`e[32m> Copying typings`e[0m" +Copy-Item -Path "src/vs/temp/src/typings" -Destination "src/vs" -Recurse -Force + +# Deleting unwanted typings +Write-Host "`e[32m> Deleting unwanted typings`e[0m" +$null = Remove-Item -Path "src/vs/typings/vscode-globals-modules.d.ts" -Force diff --git a/package.json b/package.json index 941f78c9..e5ae2b2a 100644 --- a/package.json +++ b/package.json @@ -27,15 +27,12 @@ "setup": "npm run build", "presetup": "npm run install-addons", "install-addons": "node ./bin/install-addons.js", - "start": "node demo/start", "build-demo": "webpack --config ./demo/webpack.config.js", - "build": "npm run tsc", "watch": "npm run tsc-watch", "tsc": "tsc -b ./tsconfig.all.json", "tsc-watch": "tsc -b -w ./tsconfig.all.json --preserveWatchOutput", - "esbuild": "node bin/esbuild_all.mjs", "esbuild-watch": "node bin/esbuild_all.mjs --watch", "esbuild-package": "node bin/esbuild_all.mjs --prod", @@ -43,33 +40,26 @@ "esbuild-package-headless-only": "node bin/esbuild.mjs --prod --headless", "esbuild-demo": "node bin/esbuild.mjs --demo-client", "esbuild-demo-watch": "node bin/esbuild.mjs --demo-client --watch", - "test": "npm run test-unit", "posttest": "npm run lint", - "lint": "eslint -c .eslintrc.json --max-warnings 0 --ext .ts src/ addons/", "lint-api": "eslint --no-eslintrc -c .eslintrc.json.typings --max-warnings 0 --no-ignore --ext .d.ts typings/", - "test-unit": "node ./bin/test_unit.js", "test-unit-coverage": "node ./bin/test_unit.js --coverage", "test-unit-dev": "cross-env NODE_PATH='./out' mocha", - "test-integration": "node ./bin/test_integration.js --workers=75%", "test-integration-chromium": "node ./bin/test_integration.js --workers=75% \"--project=ChromeStable\"", "test-integration-firefox": "node ./bin/test_integration.js --workers=75% \"--project=FirefoxStable\"", "test-integration-webkit": "node ./bin/test_integration.js --workers=75% \"--project=WebKit\"", "test-integration-debug": "node ./bin/test_integration.js --workers=1 --headed --timeout=30000", - "benchmark": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json", "benchmark-baseline": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json --baseline out-tsc/test-benchmark/test/benchmark/*benchmark.js", "benchmark-eval": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json --eval out-tsc/test-benchmark/test/benchmark/*benchmark.js", - "clean": "rm -rf lib out addons/*/lib addons/*/out", "vtfeatures": "node bin/extract_vtfeatures.js src/**/*.ts src/*.ts", - "prepackage": "npm run build", "package": "webpack", - "postpackage":"npm run esbuild-package", + "postpackage": "npm run esbuild-package", "prepackage-headless": "npm run esbuild-package-headless-only", "package-headless": "webpack --config ./webpack.config.headless.js", "postpackage-headless": "node ./bin/package_headless.js", @@ -88,6 +78,7 @@ "@types/jsdom": "^16.2.13", "@types/mocha": "^9.0.0", "@types/node": "^18.16.0", + "@types/trusted-types": "^1.0.6", "@types/utf8": "^3.0.0", "@types/webpack": "^5.28.0", "@types/ws": "^8.2.0", @@ -107,6 +98,7 @@ "mustache": "^4.2.0", "node-pty": "1.1.0-beta5", "nyc": "^15.1.0", + "semver": "^7.6.2", "source-map-loader": "^3.0.0", "source-map-support": "^0.5.20", "ts-loader": "^9.3.1", diff --git a/src/browser/tsconfig.json b/src/browser/tsconfig.json index 673a55a6..d8f3a189 100644 --- a/src/browser/tsconfig.json +++ b/src/browser/tsconfig.json @@ -11,7 +11,8 @@ ], "baseUrl": "..", "paths": { - "common/*": [ "./common/*" ] + "common/*": [ "./common/*" ], + "vs/*": [ "./vs/*" ] } }, "include": [ @@ -19,6 +20,7 @@ "../../typings/xterm.d.ts" ], "references": [ - { "path": "../common" } + { "path": "../common" }, + { "path": "../vs" } ] } diff --git a/src/common/tsconfig.json b/src/common/tsconfig.json index b8baa6c0..e9b3673a 100644 --- a/src/common/tsconfig.json +++ b/src/common/tsconfig.json @@ -9,10 +9,16 @@ "types": [ "../../node_modules/@types/mocha" ], - "baseUrl": ".." + "baseUrl": "..", + "paths": { + "vs/*": [ "./vs/*" ] + } }, "include": [ "./**/*", "../../typings/xterm.d.ts" + ], + "references": [ + { "path": "../vs" } ] } diff --git a/src/vs/README.md b/src/vs/README.md new file mode 100644 index 00000000..002749b3 --- /dev/null +++ b/src/vs/README.md @@ -0,0 +1,9 @@ +This folder contains the `base/` module from the [Visual Studio Code repository](https://github.com/microsoft/vscode) which has many helpers that are useful to xterm.js. + +To update against upstream: + +``` +./bin/update_vs_base.ps1 +``` + +TODO: Mention review `src/vs/base` in xterm.js diff --git a/src/vs/patches/nls.ts b/src/vs/patches/nls.ts new file mode 100644 index 00000000..1661dfb0 --- /dev/null +++ b/src/vs/patches/nls.ts @@ -0,0 +1,90 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export interface ILocalizeInfo { + key: string; + comment: string[]; +} + +export function localize(info: ILocalizeInfo | string, message: string, ...args: (string | number | boolean | undefined | null)[]): string { + return message; +} + +export interface INLSLanguagePackConfiguration { + + /** + * The path to the translations config file that contains pointers to + * all message bundles for `main` and extensions. + */ + readonly translationsConfigFile: string; + + /** + * The path to the file containing the translations for this language + * pack as flat string array. + */ + readonly messagesFile: string; + + /** + * The path to the file that can be used to signal a corrupt language + * pack, for example when reading the `messagesFile` fails. This will + * instruct the application to re-create the cache on next startup. + */ + readonly corruptMarkerFile: string; +} + +export interface INLSConfiguration { + + /** + * Locale as defined in `argv.json` or `app.getLocale()`. + */ + readonly userLocale: string; + + /** + * Locale as defined by the OS (e.g. `app.getPreferredSystemLanguages()`). + */ + readonly osLocale: string; + + /** + * The actual language of the UI that ends up being used considering `userLocale` + * and `osLocale`. + */ + readonly resolvedLanguage: string; + + /** + * Defined if a language pack is used that is not the + * default english language pack. This requires a language + * pack to be installed as extension. + */ + readonly languagePack?: INLSLanguagePackConfiguration; + + /** + * The path to the file containing the default english messages + * as flat string array. The file is only present in built + * versions of the application. + */ + readonly defaultMessagesFile: string; + + /** + * Below properties are deprecated and only there to continue support + * for `vscode-nls` module that depends on them. + * Refs https://github.com/microsoft/vscode-nls/blob/main/src/node/main.ts#L36-L46 + */ + /** @deprecated */ + readonly locale: string; + /** @deprecated */ + readonly availableLanguages: Record; + /** @deprecated */ + readonly _languagePackSupport?: boolean; + /** @deprecated */ + readonly _languagePackId?: string; + /** @deprecated */ + readonly _translationsConfigFile?: string; + /** @deprecated */ + readonly _cacheRoot?: string; + /** @deprecated */ + readonly _resolvedLanguagePackCoreLocation?: string; + /** @deprecated */ + readonly _corruptedFile?: string; +} diff --git a/src/vs/tsconfig.json b/src/vs/tsconfig.json new file mode 100644 index 00000000..134dd908 --- /dev/null +++ b/src/vs/tsconfig.json @@ -0,0 +1,71 @@ +{ + "extends": "../tsconfig-library-base", + "compilerOptions": { + "experimentalDecorators": true, + "noImplicitReturns": true, + "noImplicitOverride": true, + "noUnusedLocals": true, + "allowUnreachableCode": false, + "strict": true, + "exactOptionalPropertyTypes": false, + "useUnknownInCatchVariables": false, + "forceConsistentCasingInFileNames": true, + "paths": { + "vs/*": [ + "./vs/*" + ], + "vs/nls": [ + "./vs/patches/nls" + ] + }, + "target": "es2022", + "useDefineForClassFields": false, + "lib": [ + "ES2022", + "DOM", + "DOM.Iterable", + "WebWorker.ImportScripts" + ], + "esModuleInterop": true, + "removeComments": false, + "preserveConstEnums": true, + "sourceMap": false, + "allowJs": true, + "resolveJsonModule": true, + "isolatedModules": true, + "types": [ + "semver", + "trusted-types", + ], + "composite": true, + "outDir": "../../out", + "baseUrl": "../", + }, + "include": [ + "./base/**/*", + "./patches/**/*", + "./typings/**/*", + ], + "exclude": [ + // Update repo folder + "temp/", + + // Unwanted layers/modules + "**/electron-main", + "**/electron-sandbox", + "**/node", + "**/test", + "**/sandbox", + "**/worker", + + // Problematic files + "base/common/amd.ts", + "base/browser/defaultWorkerFactory.ts", + "base/common/jsonc.js", + "base/common/performance.js", + "base/common/marked/marked.js", + "base/common/network.js", + + "typings/vscode-globals-modules.d.ts" + ] +} diff --git a/src/vs/typings/base-common.d.ts b/src/vs/typings/base-common.d.ts new file mode 100644 index 00000000..4fc7b598 --- /dev/null +++ b/src/vs/typings/base-common.d.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// Declare types that we probe for to implement util and/or polyfill functions + +declare global { + + interface IdleDeadline { + readonly didTimeout: boolean; + timeRemaining(): number; + } + + function requestIdleCallback(callback: (args: IdleDeadline) => void, options?: { timeout: number }): number; + function cancelIdleCallback(handle: number): void; + +} + +export { } diff --git a/src/vs/typings/require.d.ts b/src/vs/typings/require.d.ts new file mode 100644 index 00000000..79342790 --- /dev/null +++ b/src/vs/typings/require.d.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare class LoaderEvent { + readonly type: number; + readonly timestamp: number; + readonly detail: string; +} + +declare const define: { + (moduleName: string, dependencies: string[], callback: (...args: any[]) => any): any; + (moduleName: string, dependencies: string[], definition: any): any; + (moduleName: string, callback: (...args: any[]) => any): any; + (moduleName: string, definition: any): any; + (dependencies: string[], callback: (...args: any[]) => any): any; + (dependencies: string[], definition: any): any; +}; + +interface NodeRequire { + /** + * @deprecated use `FileAccess.asFileUri()` for node.js contexts or `FileAccess.asBrowserUri` for browser contexts. + */ + toUrl(path: string): string; + + /** + * @deprecated MUST not be used anymore + * + * With the move from AMD to ESM we cannot use this anymore. There will be NO MORE node require like this. + */ + __$__nodeRequire(moduleName: string): T; + + (dependencies: string[], callback: (...args: any[]) => any, errorback?: (err: any) => void): any; + config(data: any): any; + onError: Function; + getStats?(): ReadonlyArray; + hasDependencyCycle?(): boolean; + define(amdModuleId: string, dependencies: string[], callback: (...args: any[]) => any): any; +} + +declare var require: NodeRequire; diff --git a/src/vs/typings/thenable.d.ts b/src/vs/typings/thenable.d.ts new file mode 100644 index 00000000..73373ead --- /dev/null +++ b/src/vs/typings/thenable.d.ts @@ -0,0 +1,12 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +/** + * Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise, + * and others. This API makes no assumption about what promise library is being used which + * enables reusing existing code without migrating to a specific promise implementation. Still, + * we recommend the use of native promises which are available in VS Code. + */ +interface Thenable extends PromiseLike { } diff --git a/src/vs/typings/vscode-globals-nls.d.ts b/src/vs/typings/vscode-globals-nls.d.ts new file mode 100644 index 00000000..bc480767 --- /dev/null +++ b/src/vs/typings/vscode-globals-nls.d.ts @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// AMD2ESM mirgation relevant + +/** + * NLS Globals: these need to be defined in all contexts that make + * use of our `nls.localize` and `nls.localize2` functions. This includes: + * - Electron main process + * - Electron window (renderer) process + * - Utility Process + * - Node.js + * - Browser + * - Web worker + * + * That is because during build time we strip out all english strings from + * the resulting JS code and replace it with a that is then looked + * up from the `_VSCODE_NLS_MESSAGES` array. + */ +declare global { + /** + * All NLS messages produced by `localize` and `localize2` calls + * under `src/vs` translated to the language as indicated by + * `_VSCODE_NLS_LANGUAGE`. + */ + var _VSCODE_NLS_MESSAGES: string[]; + /** + * The actual language of the NLS messages (e.g. 'en', de' or 'pt-br'). + */ + var _VSCODE_NLS_LANGUAGE: string | undefined; +} + +// fake export to make global work +export { } diff --git a/src/vs/typings/vscode-globals-product.d.ts b/src/vs/typings/vscode-globals-product.d.ts new file mode 100644 index 00000000..f6aa62bf --- /dev/null +++ b/src/vs/typings/vscode-globals-product.d.ts @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// AMD2ESM mirgation relevant + +declare global { + + /** + * Holds the file root for resources. + */ + var _VSCODE_FILE_ROOT: string; + + /** + * CSS loader that's available during development time. + * DO NOT call directly, instead just import css modules, like `import 'some.css'` + */ + var _VSCODE_CSS_LOAD: (module: string) => void; + + /** + * @deprecated You MUST use `IProductService` whenever possible. + */ + var _VSCODE_PRODUCT_JSON: Record; + /** + * @deprecated You MUST use `IProductService` whenever possible. + */ + var _VSCODE_PACKAGE_JSON: Record; + +} + +// fake export to make global work +export { } diff --git a/yarn.lock b/yarn.lock index 1422c7db..e353d8ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -830,6 +830,11 @@ resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397" integrity sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw== +"@types/trusted-types@^1.0.6": + version "1.0.6" + resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-1.0.6.tgz#569b8a08121d3203398290d602d84d73c8dcf5da" + integrity sha512-230RC8sFeHoT6sSUlRO6a8cAnclO06eeiq1QDfiv2FGCLWFvvERWgwIQD4FWqD9A69BN7Lzee4OXwoMVnnsWDw== + "@types/utf8@^3.0.0": version "3.0.1" resolved "https://registry.yarnpkg.com/@types/utf8/-/utf8-3.0.1.tgz#bf081663d4fff05ee63b41f377a35f8b189f7e5b" @@ -3672,7 +3677,7 @@ semver@^7.3.4, semver@^7.5.3, semver@^7.5.4: dependencies: lru-cache "^6.0.0" -semver@^7.6.0: +semver@^7.6.0, semver@^7.6.2: version "7.6.2" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==