diff --git a/.dprint.jsonc b/.dprint.jsonc index f6ae7e6cc1..822ae6263e 100644 --- a/.dprint.jsonc +++ b/.dprint.jsonc @@ -53,7 +53,9 @@ "**/*_generated.go", "internal/bundled/libs/**", "internal/lsp/lsproto/_generate/*.json", - "internal/lsp/lsproto/_generate/metaModelSchema.mts" + "internal/lsp/lsproto/_generate/metaModelSchema.mts", + // Needs to be LF to have a working shebang. + "_packages/native-preview/bin/tsgo.js" ], // Note: if adding new languages, make sure settings.template.json is updated too. // Also, if updating typescript, update the one in package.json. diff --git a/.gitignore b/.gitignore index d4dfeecb24..ee0ed497bf 100644 --- a/.gitignore +++ b/.gitignore @@ -194,3 +194,5 @@ custom-gcl.hash .idea !testdata/submoduleAccepted.txt + +!NOTICE.txt diff --git a/Herebyfile.mjs b/Herebyfile.mjs index c6175571be..b70573e9e5 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -1,5 +1,6 @@ // @ts-check +import AdmZip from "adm-zip"; import chokidar from "chokidar"; import { $ as _$ } from "execa"; import { glob } from "glob"; @@ -10,6 +11,8 @@ import fs from "node:fs"; import path from "node:path"; import url from "node:url"; import { parseArgs } from "node:util"; +import os from "os"; +import pLimit from "p-limit"; import pc from "picocolors"; import which from "which"; @@ -48,7 +51,7 @@ function parseEnvBoolean(name, defaultValue = false) { throw new Error(`Invalid value for ${name}: ${value}`); } -const { values: options } = parseArgs({ +const { values: rawOptions } = parseArgs({ args: process.argv.slice(2), options: { tests: { type: "string", short: "t" }, @@ -57,6 +60,9 @@ const { values: options } = parseArgs({ insiders: { type: "boolean" }, + setPrerelease: { type: "string" }, + forRelease: { type: "boolean" }, + race: { type: "boolean", default: parseEnvBoolean("RACE") }, noembed: { type: "boolean", default: parseEnvBoolean("NOEMBED") }, concurrentTestPrograms: { type: "boolean", default: parseEnvBoolean("CONCURRENT_TEST_PROGRAMS") }, @@ -67,6 +73,16 @@ const { values: options } = parseArgs({ allowNegative: true, }); +// We can't use parseArgs' strict mode as it errors on hereby's --tasks flag. +/** + * @typedef {{ [K in keyof T as {} extends Record ? never : K]: T[K] }} RemoveIndex + * @template T + */ +/** + * @typedef {RemoveIndex} Options + */ +const options = /** @type {Options} */ (rawOptions); + const defaultGoBuildTags = [ ...(options.noembed ? ["noembed"] : []), ]; @@ -138,36 +154,46 @@ function isInstalled(tool) { return !!which.sync(tool, { nothrow: true }); } +const builtLocal = "./built/local"; + const libsDir = "./internal/bundled/libs"; const libsRegexp = /(?:^|[\\/])internal[\\/]bundled[\\/]libs[\\/]/; -async function generateLibs() { - await fs.promises.mkdir("./built/local", { recursive: true }); +/** + * @param {string} out + */ +async function generateLibs(out) { + await fs.promises.mkdir(out, { recursive: true }); const libs = await fs.promises.readdir(libsDir); await Promise.all(libs.map(async lib => { - fs.promises.copyFile(`${libsDir}/${lib}`, `./built/local/${lib}`); + fs.promises.copyFile(path.join(libsDir, lib), path.join(out, lib)); })); } export const lib = task({ name: "lib", - run: generateLibs, + run: () => generateLibs(builtLocal), }); /** - * @param {string} packagePath - * @param {AbortSignal} [abortSignal] + * @param {object} [opts] + * @param {string} [opts.out] + * @param {AbortSignal} [opts.abortSignal] + * @param {Record} [opts.env] + * @param {string[]} [opts.extraFlags] */ -function buildExecutableToBuilt(packagePath, abortSignal) { - return $({ cancelSignal: abortSignal })`go build ${goBuildFlags} ${goBuildTags("noembed")} -o ./built/local/ ${packagePath}`; +function buildTsgo(opts) { + opts ||= {}; + const out = opts.out ?? "./built/local/"; + return $({ cancelSignal: opts.abortSignal, env: opts.env })`go build ${goBuildFlags} ${opts.extraFlags ?? []} ${goBuildTags("noembed")} -o ${out} ./cmd/tsgo`; } export const tsgoBuild = task({ name: "tsgo:build", run: async () => { - await buildExecutableToBuilt("./cmd/tsgo"); + await buildTsgo(); }, }); @@ -213,12 +239,12 @@ export const buildWatch = task({ if (libsChanged) { console.log("Generating libs..."); - await generateLibs(); + await generateLibs(builtLocal); } if (goChanged) { console.log("Building tsgo..."); - await buildExecutableToBuilt("./cmd/tsgo", abortSignal); + await buildTsgo({ abortSignal }); } }, { paths: ["cmd", "internal"], @@ -230,7 +256,7 @@ export const buildWatch = task({ export const cleanBuilt = task({ name: "clean:built", hiddenFromTaskList: true, - run: () => fs.promises.rm("built", { recursive: true, force: true }), + run: () => rimraf("built"), }); export const generate = task({ @@ -350,17 +376,6 @@ export const testAll = task({ }, }); -export const installExtension = task({ - name: "install-extension", - run: async () => { - await $({ cwd: path.join(__dirname, "_extension") })`npm run package`; - await $({ cwd: path.join(__dirname, "_extension") })`${options.insiders ? "code-insiders" : "code"} --install-extension typescript-lsp.vsix`; - console.log(pc.yellowBright("\nExtension installed. ") + "Add the following to your workspace or user settings.json:\n"); - console.log(pc.whiteBright(` "typescript-go.executablePath": "${path.join(__dirname, "built", "local", process.platform === "win32" ? "tsgo.exe" : "tsgo")}"\n`)); - console.log("Select 'TypeScript: Use TypeScript Go (Experimental)' in the command palette to enable the extension and disable built-in TypeScript support.\n"); - }, -}); - const customLinterPath = "./_tools/custom-gcl"; const customLinterHashPath = customLinterPath + ".hash"; @@ -687,3 +702,532 @@ export class Debouncer { } } } + +const getVersion = memoize(() => { + const f = fs.readFileSync("./internal/core/version.go", "utf8"); + + const match = f.match(/var version\s*=\s*"(\d+\.\d+\.\d+)(-[^"]+)?"/); + if (!match) { + throw new Error("Failed to extract version from version.go"); + } + + let version = match[1]; + if (options.setPrerelease) { + version += `-${options.setPrerelease}`; + } + else if (match[2]) { + version += match[2]; + } + + return version; +}); + +const extensionDir = path.resolve("./_extension"); +const builtNpm = path.resolve("./built/npm"); +const builtVsix = path.resolve("./built/vsix"); +const builtSignTmp = path.resolve("./built/sign-tmp"); + +const getSignTempDir = memoize(async () => { + const dir = path.resolve(builtSignTmp); + await rimraf(dir); + await fs.promises.mkdir(dir, { recursive: true }); + return dir; +}); + +const cleanSignTempDirectory = task({ + name: "clean:sign-tmp", + run: () => rimraf(builtSignTmp), +}); + +let signCount = 0; + +/** + * @typedef {{ + * SignFileRecordList: { + * SignFileList: { SrcPath: string; DstPath: string | null; }[]; + * Certs: Cert; + * }[] + * }} DDSignFileList + * + * @param {DDSignFileList} filelist + */ +async function sign(filelist) { + const data = JSON.stringify(filelist, undefined, 4); + console.log("filelist:", data); + + if (!process.env.MBSIGN_APPFOLDER) { + console.log(pc.yellow("Faking signing because MBSIGN_APPFOLDER is not set.")); + + // Fake signing for testing. + + for (const record of filelist.SignFileRecordList) { + for (const file of record.SignFileList) { + const src = file.SrcPath; + const dst = file.DstPath ?? src; + + if (!fs.existsSync(src)) { + throw new Error(`Source file does not exist: ${src}`); + } + + const dstDir = path.dirname(dst); + if (!fs.existsSync(dstDir)) { + throw new Error(`Destination directory does not exist: ${dstDir}`); + } + + if (dst.endsWith(".sig")) { + console.log(`Faking signature for ${src} -> ${dst}`); + // No great way to fake a signature. + await fs.promises.writeFile(dst, "fake signature"); + } + else { + if (src === dst) { + console.log(`Faking signing ${src}`); + } + else { + console.log(`Faking signing ${src} -> ${dst}`); + } + const contents = await fs.promises.readFile(src); + await fs.promises.writeFile(dst, contents); + } + } + } + + return; + } + + const tmp = await getSignTempDir(); + const filelistPath = path.resolve(tmp, `signing-filelist-${signCount++}.json`); + await fs.promises.writeFile(filelistPath, data); + + try { + const dll = path.join(process.env.MBSIGN_APPFOLDER, "DDSignFiles.dll"); + const filelistFlag = `/filelist:${filelistPath}`; + await $`dotnet ${dll} -- ${filelistFlag}`; + } + finally { + await fs.promises.unlink(filelistPath); + } +} + +/** + * @param {string} src + * @param {string} dest + * @param {(p: string) => boolean} [filter] + */ +function cpRecursive(src, dest, filter) { + return fs.promises.cp(src, dest, { + recursive: true, + filter: filter ? src => filter(src.replace(/\\/g, "/")) : undefined, + }); +} + +/** + * @param {string} src + * @param {string} dest + */ +function cpWithoutNodeModulesOrTsconfig(src, dest) { + return cpRecursive(src, dest, p => !p.endsWith("/node_modules") && !p.endsWith("/tsconfig.json")); +} + +const mainNativePreviewPackage = { + npmPackageName: "@typescript/native-preview", + npmDir: path.join(builtNpm, "native-preview"), + npmTarball: path.join(builtNpm, "native-preview.tgz"), +}; + +/** + * @typedef {"win32" | "linux" | "darwin"} OS + * @typedef {"x64" | "arm" | "arm64"} Arch + * @typedef {"Microsoft400" | "LinuxSign" | "MacDeveloperHarden" | "8020" | "VSCodePublisher"} Cert + * @typedef {`${OS}-${Exclude | "armhf"}`} VSCodeTarget + */ +void 0; + +const nativePreviewPlatforms = memoize(() => { + /** @type {[OS, Arch, Cert][]} */ + let supportedPlatforms = [ + ["win32", "x64", "Microsoft400"], + ["win32", "arm64", "Microsoft400"], + ["linux", "x64", "LinuxSign"], + ["linux", "arm", "LinuxSign"], + ["linux", "arm64", "LinuxSign"], + ["darwin", "x64", "MacDeveloperHarden"], + ["darwin", "arm64", "MacDeveloperHarden"], + // Alpine? + // Wasm? + ]; + + if (!options.forRelease) { + supportedPlatforms = supportedPlatforms.filter(([os, arch]) => os === process.platform && arch === process.arch); + assert.equal(supportedPlatforms.length, 1, "No supported platforms found"); + } + + return supportedPlatforms.map(([os, arch, cert]) => { + const npmDirName = `native-preview-${os}-${arch}`; + const npmDir = path.join(builtNpm, npmDirName); + const npmTarball = `${npmDir}.tgz`; + const npmPackageName = `@typescript/${npmDirName}`; + /** @type {VSCodeTarget} */ + const vscodeTarget = `${os}-${arch === "arm" ? "armhf" : arch}`; + const extensionDir = path.join(builtVsix, `typescript-native-preview-${vscodeTarget}`); + const vsixPath = extensionDir + ".vsix"; + const vsixManifestPath = extensionDir + ".manifest"; + const vsixSignaturePath = extensionDir + ".signature.p7s"; + return { + nodeOs: os, + nodeArch: arch, + goos: nodeToGOOS(os), + goarch: nodeToGOARCH(arch), + npmPackageName, + npmDirName, + npmDir, + npmTarball, + vscodeTarget, + extensionDir, + vsixPath, + vsixManifestPath, + vsixSignaturePath, + cert, + }; + }); + + /** + * @param {string} os + * @returns {"darwin" | "linux" | "windows"} + */ + function nodeToGOOS(os) { + switch (os) { + case "darwin": + return "darwin"; + case "linux": + return "linux"; + case "win32": + return "windows"; + default: + throw new Error(`Unsupported OS: ${os}`); + } + } + + /** + * @param {string} arch + * @returns {"amd64" | "arm" | "arm64"} + */ + function nodeToGOARCH(arch) { + switch (arch) { + case "x64": + return "amd64"; + case "arm": + return "arm"; + case "arm64": + return "arm64"; + default: + throw new Error(`Unsupported ARCH: ${arch}`); + } + } +}); + +export const buildNativePreviewPackages = task({ + name: "native-preview:build-packages", + hiddenFromTaskList: true, + run: async () => { + await rimraf(builtNpm); + + const platforms = nativePreviewPlatforms(); + + const inputDir = "./_packages/native-preview"; + + const inputPackageJson = JSON.parse(fs.readFileSync(path.join(inputDir, "package.json"), "utf8")); + inputPackageJson.version = getVersion(); + delete inputPackageJson.private; + + const { stdout: gitHead } = await $pipe`git rev-parse HEAD`; + inputPackageJson.gitHead = gitHead; + + const mainPackage = { + ...inputPackageJson, + optionalDependencies: Object.fromEntries(platforms.map(p => [p.npmPackageName, getVersion()])), + }; + + const mainPackageDir = mainNativePreviewPackage.npmDir; + + await fs.promises.mkdir(mainPackageDir, { recursive: true }); + + await cpWithoutNodeModulesOrTsconfig(inputDir, mainPackageDir); + + await fs.promises.writeFile(path.join(mainPackageDir, "package.json"), JSON.stringify(mainPackage, undefined, 4)); + await fs.promises.copyFile("LICENSE", path.join(mainPackageDir, "LICENSE")); + // No NOTICE.txt here; does not ship the binary or libs. If this changes, we should add it. + + let ldflags = "-ldflags=-s -w"; + if (options.setPrerelease) { + ldflags += ` -X github.com/microsoft/typescript-go/internal/core.version=${getVersion()}`; + } + const extraFlags = ["-trimpath", ldflags]; + + const buildLimit = pLimit(os.availableParallelism()); + + await Promise.all(platforms.map(async ({ npmDir, npmPackageName, nodeOs, nodeArch, goos, goarch }) => { + const packageJson = { + ...inputPackageJson, + bin: undefined, + imports: undefined, + name: npmPackageName, + os: [nodeOs], + cpu: [nodeArch], + exports: { + "./package.json": "./package.json", + }, + }; + + const out = path.join(npmDir, "lib"); + await fs.promises.mkdir(out, { recursive: true }); + await fs.promises.writeFile(path.join(npmDir, "package.json"), JSON.stringify(packageJson, undefined, 4)); + await fs.promises.copyFile("LICENSE", path.join(npmDir, "LICENSE")); + await fs.promises.copyFile("NOTICE.txt", path.join(npmDir, "NOTICE.txt")); + + const readme = [ + `# \`${npmPackageName}\``, + "", + `This package provides ${nodeOs}-${nodeArch} support for [${packageJson.name}](https://www.npmjs.com/package/${packageJson.name}).`, + ]; + + fs.promises.writeFile(path.join(npmDir, "README.md"), readme.join("\n") + "\n"); + + await Promise.all([ + generateLibs(out), + buildLimit(() => + buildTsgo({ + out, + env: { GOOS: goos, GOARCH: goarch, GOARM: "6", CGO_ENABLED: "0" }, + extraFlags, + }) + ), + ]); + })); + }, +}); + +export const signNativePreviewPackages = task({ + name: "native-preview:sign-packages", + hiddenFromTaskList: true, + run: async () => { + if (!options.forRelease) { + throw new Error("This task should not be run in non-release builds."); + } + + const platforms = nativePreviewPlatforms(); + + /** @type {Map} */ + const filelistByCert = new Map(); + for (const { npmDir, nodeOs, cert, npmDirName } of platforms) { + let certFilelist = filelistByCert.get(cert); + if (!certFilelist) { + filelistByCert.set(cert, certFilelist = []); + } + certFilelist.push({ + tmpName: npmDirName, + path: path.join(npmDir, "lib", nodeOs === "win32" ? "tsgo.exe" : "tsgo"), + }); + } + + const tmp = await getSignTempDir(); + + /** @type {DDSignFileList} */ + const filelist = { + SignFileRecordList: [], + }; + + const macZips = []; + + // First, sign the files. + + for (const [cert, filelistPaths] of filelistByCert) { + switch (cert) { + case "Microsoft400": + filelist.SignFileRecordList.push({ + SignFileList: filelistPaths.map(p => ({ SrcPath: p.path, DstPath: null })), + Certs: cert, + }); + break; + case "LinuxSign": + filelist.SignFileRecordList.push({ + SignFileList: filelistPaths.map(p => ({ SrcPath: p.path, DstPath: p.path + ".sig" })), + Certs: cert, + }); + break; + case "MacDeveloperHarden": + // Mac signing requires putting files into zips and then signing those, + // along with a notarization step. + for (const p of filelistPaths) { + const unsignedZipPath = path.join(tmp, `${p.tmpName}.unsigned.zip`); + const signedZipPath = path.join(tmp, `${p.tmpName}.signed.zip`); + const notarizedZipPath = path.join(tmp, `${p.tmpName}.notarized.zip`); + + const zip = new AdmZip(); + zip.addLocalFile(p.path); + zip.writeZip(unsignedZipPath); + + macZips.push({ + path: p.path, + unsignedZipPath, + signedZipPath, + notarizedZipPath, + }); + } + filelist.SignFileRecordList.push({ + SignFileList: macZips.map(p => ({ SrcPath: p.unsignedZipPath, DstPath: p.signedZipPath })), + Certs: cert, + }); + break; + default: + throw new Error(`Unknown cert: ${cert}`); + } + } + + await sign(filelist); + + // All of the files have been signed in place / had signatures added. + + if (macZips.length) { + // Now, notarize the Mac files. + + /** @type {DDSignFileList} */ + const notarizeFilelist = { + SignFileRecordList: [ + { + SignFileList: macZips.map(p => ({ SrcPath: p.signedZipPath, DstPath: p.notarizedZipPath })), + Certs: "8020", // "MacNotarize" (friendly name not supported by the tooling) + }, + ], + }; + + await sign(notarizeFilelist); + + // Finally, unzip the notarized files and move them back to their original locations. + + for (const p of macZips) { + const zip = new AdmZip(p.notarizedZipPath); + zip.extractEntryTo(path.basename(p.path), path.dirname(p.path), false, true); + } + + // chmod +x the unsipped files. + + for (const p of macZips) { + await fs.promises.chmod(p.path, 0o755); + } + } + }, +}); + +export const packNativePreviewPackages = task({ + name: "native-preview:pack-packages", + hiddenFromTaskList: true, + dependencies: options.forRelease ? undefined : [buildNativePreviewPackages, cleanSignTempDirectory], + run: async () => { + const platforms = nativePreviewPlatforms(); + await Promise.all([mainNativePreviewPackage, ...platforms].map(async ({ npmDir, npmTarball }) => { + const { stdout } = await $pipe`npm pack --json ${npmDir}`; + const filename = JSON.parse(stdout)[0].filename.replace("@", "").replace("/", "-"); + await fs.promises.rename(filename, npmTarball); + })); + + // npm packages need to be published in reverse dep order, e.g. such that no package + // is published before its dependencies. + const publishOrder = [ + ...platforms.map(p => p.npmTarball), + mainNativePreviewPackage.npmTarball, + ].map(p => path.basename(p)); + + const publishOrderPath = path.join(builtNpm, "publish-order.txt"); + await fs.promises.writeFile(publishOrderPath, publishOrder.join("\n") + "\n"); + }, +}); + +export const packNativePreviewExtensions = task({ + name: "native-preview:pack-extensions", + hiddenFromTaskList: true, + dependencies: options.forRelease ? undefined : [buildNativePreviewPackages, cleanSignTempDirectory], + run: async () => { + await rimraf(builtVsix); + await fs.promises.mkdir(builtVsix, { recursive: true }); + + await $({ cwd: extensionDir })`npm run bundle`; + + const version = getVersion(); + const platforms = nativePreviewPlatforms(); + + await Promise.all(platforms.map(async ({ npmDir, vscodeTarget, extensionDir: thisExtensionDir, vsixPath, vsixManifestPath, vsixSignaturePath }) => { + const npmLibDir = path.join(npmDir, "lib"); + const extensionLibDir = path.join(thisExtensionDir, "lib"); + await fs.promises.mkdir(extensionLibDir, { recursive: true }); + + await cpWithoutNodeModulesOrTsconfig(extensionDir, thisExtensionDir); + await cpWithoutNodeModulesOrTsconfig(npmLibDir, extensionLibDir); + + const packageJsonPath = path.join(thisExtensionDir, "package.json"); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); + packageJson.version = version; + packageJson.main = "dist/extension.bundle.js"; + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 4)); + + await fs.promises.copyFile("NOTICE.txt", path.join(thisExtensionDir, "NOTICE.txt")); + + await $({ cwd: thisExtensionDir })`vsce package ${version} --pre-release --no-update-package-json --no-dependencies --out ${vsixPath} --target ${vscodeTarget}`; + + if (options.forRelease) { + await $({ cwd: thisExtensionDir })`vsce generate-manifest --packagePath ${vsixPath} --out ${vsixManifestPath}`; + await fs.promises.cp(vsixManifestPath, vsixSignaturePath); + } + })); + }, +}); + +export const signNativePreviewExtensions = task({ + name: "native-preview:sign-extensions", + hiddenFromTaskList: true, + run: async () => { + if (!options.forRelease) { + throw new Error("This task should not be run in non-release builds."); + } + + const platforms = nativePreviewPlatforms(); + await sign({ + SignFileRecordList: [ + { + SignFileList: platforms.map(({ vsixSignaturePath }) => ({ SrcPath: vsixSignaturePath, DstPath: null })), + Certs: "VSCodePublisher", + }, + ], + }); + }, +}); + +export const nativePreview = task({ + name: "native-preview", + dependencies: options.forRelease ? undefined : [packNativePreviewPackages, packNativePreviewExtensions], + run: options.forRelease ? async () => { + throw new Error("This task should not be run in release builds."); + } : undefined, +}); + +export const installExtension = task({ + name: "install-extension", + dependencies: options.forRelease ? undefined : [packNativePreviewExtensions], + run: async () => { + if (options.forRelease) { + throw new Error("This task should not be run in release builds."); + } + + const platforms = nativePreviewPlatforms(); + const myPlatform = platforms.find(p => p.nodeOs === process.platform && p.nodeArch === process.arch); + if (!myPlatform) { + throw new Error(`No platform found for ${process.platform}-${process.arch}`); + } + + await $`${options.insiders ? "code-insiders" : "code"} --install-extension ${myPlatform.vsixPath}`; + console.log(pc.yellowBright("\nExtension installed. ") + "To enable this extension, set:\n"); + console.log(pc.whiteBright(` "typescript.experimental.useTsgo": true\n`)); + console.log("To configure the extension to use built/local instead of its bundled tsgo, set:\n"); + console.log(pc.whiteBright(` "typescript.native-preview.tsdk": "${path.join(__dirname, "built", "local")}"\n`)); + }, +}); diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 0000000000..d04bc33fde --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,297 @@ +NOTICES AND INFORMATION +Do Not Translate or Localize + +This software incorporates material from third parties. Microsoft makes certain +open source code available at https://3rdpartysource.microsoft.com, or you may +send a check or money order for US $5.00, including the product name, the open +source component name, and version number, to: + +Source Code Compliance Team +Microsoft Corporation +One Microsoft Way +Redmond, WA 98052 +USA + +Notwithstanding any other terms, you may reverse engineer this software to the +extent required to debug changes to any libraries licensed under the GNU Lesser +General Public License. + + +------------------- DefinitelyTyped -------------------- +This file is based on or incorporates material from the projects listed below (collectively "Third Party Code"). Microsoft is not the original author of the Third Party Code. The original copyright notice and the license, under which Microsoft received such Third Party Code, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft, not the third party, licenses the Third Party Code to you under the terms set forth in the EULA for the Microsoft Product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise. +DefinitelyTyped +This project is licensed under the MIT license. Copyrights are respective of each contributor listed at the beginning of each definition file. Provided for Informational Purposes Only + +MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------------- + +------------------- Unicode -------------------- +UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE + +Unicode Data Files include all data files under the directories +http://www.unicode.org/Public/, http://www.unicode.org/reports/, +http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and +http://www.unicode.org/utility/trac/browser/. + +Unicode Data Files do not include PDF online code charts under the +directory http://www.unicode.org/Public/. + +Software includes any source code published in the Unicode Standard +or under the directories +http://www.unicode.org/Public/, http://www.unicode.org/reports/, +http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and +http://www.unicode.org/utility/trac/browser/. + +NOTICE TO USER: Carefully read the following legal agreement. +BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S +DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), +YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. +IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE +THE DATA FILES OR SOFTWARE. + +COPYRIGHT AND PERMISSION NOTICE + +Copyright (c) 1991-2017 Unicode, Inc. All rights reserved. +Distributed under the Terms of Use in http://www.unicode.org/copyright.html. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Unicode data files and any associated documentation +(the "Data Files") or Unicode software and any associated documentation +(the "Software") to deal in the Data Files or Software +without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, and/or sell copies of +the Data Files or Software, and to permit persons to whom the Data Files +or Software are furnished to do so, provided that either +(a) this copyright and permission notice appear with all copies +of the Data Files or Software, or +(b) this copyright and permission notice appear in associated +Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS +NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL +DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THE DATA FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in these Data Files or Software without prior +written authorization of the copyright holder. +------------------------------------------------------------------------------------- + +-------------------Document Object Model----------------------------- +DOM + +W3C License +This work is being provided by the copyright holders under the following license. +By obtaining and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions. +Permission to copy, modify, and distribute this work, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following +on ALL copies of the work or portions thereof, including modifications: +* The full text of this NOTICE in a location viewable to users of the redistributed or derivative work. +* Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, the W3C Software and Document Short Notice should be included. +* Notice of any changes or modifications, through a copyright statement on the new code or document such as "This software or document includes material copied from or derived +from [title and URI of the W3C document]. Copyright © [YEAR] W3C® (MIT, ERCIM, Keio, Beihang)." +Disclaimers +THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR +FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. +COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT. +The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the work without specific, written prior permission. +Title to copyright in this work will at all times remain with copyright holders. + +--------- + +DOM +Copyright © 2018 WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a Creative Commons Attribution 4.0 International License: Attribution 4.0 International +======================================================================= +Creative Commons Corporation ("Creative Commons") is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an "as-is" basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. Using Creative Commons Public Licenses Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. Considerations for licensors: Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC- licensed material, or material used under an exception or limitation to copyright. More considerations for licensors: + +wiki.creativecommons.org/Considerations_for_licensors Considerations for the public: By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor's permission is not necessary for any reason--for example, because of any applicable exception or limitation to copyright--then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. More_considerations for the public: wiki.creativecommons.org/Considerations_for_licensees ======================================================================= +Creative Commons Attribution 4.0 International Public License By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. Section 1 -- Definitions. a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. c. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. d. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. e. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. f. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. g. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. h. Licensor means the individual(s) or entity(ies) granting rights under this Public License. i. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. j. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. k. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. Section 2 -- Scope. a. License grant. 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: a. reproduce and Share the Licensed Material, in whole or in part; and b. produce, reproduce, and Share Adapted Material. 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 3. Term. The term of this Public License is specified in Section 6(a). 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a) (4) never produces Adapted Material. 5. Downstream recipients. a. Offer from the Licensor -- Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. b. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). b. Other rights. 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 2. Patent and trademark rights are not licensed under this Public License. 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. Section 3 -- License Conditions. Your exercise of the Licensed Rights is expressly made subject to the following conditions. a. Attribution. 1. If You Share the Licensed Material (including in modified form), You must: a. retain the following if it is supplied by the Licensor with the Licensed Material: i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); ii. a copyright notice; iii. a notice that refers to this Public License; iv. a notice that refers to the disclaimer of warranties; v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; b. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and c. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. Section 4 -- Sui Generis Database Rights. Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. Section 5 -- Disclaimer of Warranties and Limitation of Liability. a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. Section 6 -- Term and Termination. a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 2. upon express reinstatement by the Licensor. For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. Section 7 -- Other Terms and Conditions. a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. Section 8 -- Interpretation. a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. ======================================================================= Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the "Licensor." Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark "Creative Commons" or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. Creative Commons may be contacted at creativecommons.org. + +-------------------------------------------------------------------------------- + +----------------------Web Background Synchronization------------------------------ + +Web Background Synchronization Specification +Portions of spec © by W3C + +W3C Community Final Specification Agreement +To secure commitments from participants for the full text of a Community or Business Group Report, the group may call for voluntary commitments to the following terms; a "summary" is +available. See also the related "W3C Community Contributor License Agreement". +1. The Purpose of this Agreement. +This Agreement sets forth the terms under which I make certain copyright and patent rights available to you for your implementation of the Specification. +Any other capitalized terms not specifically defined herein have the same meaning as those terms have in the "W3C Patent Policy", and if not defined there, in the "W3C Process Document". +2. Copyrights. +2.1. Copyright Grant. I grant to you a perpetual (for the duration of the applicable copyright), worldwide, non-exclusive, no-charge, royalty-free, copyright license, without any obligation for accounting to me, to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, distribute, and implement the Specification to the full extent of my copyright interest in the Specification. +2.2. Attribution. As a condition of the copyright grant, you must include an attribution to the Specification in any derivative work you make based on the Specification. That attribution must include, at minimum, the Specification name and version number. +3. Patents. +3.1. Patent Licensing Commitment. I agree to license my Essential Claims under the W3C Community RF Licensing Requirements. This requirement includes Essential Claims that I own and any that I have the right to license without obligation of payment or other consideration to an unrelated third party. W3C Community RF Licensing Requirements obligations made concerning the Specification and described in this policy are binding on me for the life of the patents in question and encumber the patents containing Essential Claims, regardless of changes in participation status or W3C Membership. I also agree to license my Essential Claims under the W3C Community RF Licensing Requirements in derivative works of the Specification so long as all normative portions of the Specification are maintained and that this licensing commitment does not extend to any portion of the derivative work that was not included in the Specification. +3.2. Optional, Additional Patent Grant. In addition to the provisions of Section 3.1, I may also, at my option, make certain intellectual property rights infringed by implementations of the Specification, including Essential Claims, available by providing those terms via the W3C Web site. +4. No Other Rights. Except as specifically set forth in this Agreement, no other express or implied patent, trademark, copyright, or other property rights are granted under this Agreement, including by implication, waiver, or estoppel. +5. Antitrust Compliance. I acknowledge that I may compete with other participants, that I am under no obligation to implement the Specification, that each participant is free to develop competing technologies and standards, and that each party is free to license its patent rights to third parties, including for the purpose of enabling competing technologies and standards. +6. Non-Circumvention. I agree that I will not intentionally take or willfully assist any third party to take any action for the purpose of circumventing my obligations under this Agreement. +7. Transition to W3C Recommendation Track. The Specification developed by the Project may transition to the W3C Recommendation Track. The W3C Team is responsible for notifying me that a Corresponding Working Group has been chartered. I have no obligation to join the Corresponding Working Group. If the Specification developed by the Project transitions to the W3C Recommendation Track, the following terms apply: +7.1. If I join the Corresponding Working Group. If I join the Corresponding Working Group, I will be subject to all W3C rules, obligations, licensing commitments, and policies that govern that Corresponding Working Group. +7.2. If I Do Not Join the Corresponding Working Group. +7.2.1. Licensing Obligations to Resulting Specification. If I do not join the Corresponding Working Group, I agree to offer patent licenses according to the W3C Royalty-Free licensing requirements described in Section 5 of the W3C Patent Policy for the portions of the Specification included in the resulting Recommendation. This licensing commitment does not extend to any portion of an implementation of the Recommendation that was not included in the Specification. This licensing commitment may not be revoked but may be modified through the exclusion process defined in Section 4 of the W3C Patent Policy. I am not required to join the Corresponding Working Group to exclude patents from the W3C Royalty-Free licensing commitment, but must otherwise follow the normal exclusion procedures defined by the W3C Patent Policy. The W3C Team will notify me of any Call for Exclusion in the Corresponding Working Group as set forth in Section 4.5 of the W3C Patent Policy. +7.2.2. No Disclosure Obligation. If I do not join the Corresponding Working Group, I have no patent disclosure obligations outside of those set forth in Section 6 of the W3C Patent Policy. +8. Conflict of Interest. I will disclose significant relationships when those relationships might reasonably be perceived as creating a conflict of interest with my role. I will notify W3C of any change in my affiliation using W3C-provided mechanisms. +9. Representations, Warranties and Disclaimers. I represent and warrant that I am legally entitled to grant the rights and promises set forth in this Agreement. IN ALL OTHER RESPECTS THE SPECIFICATION IS PROVIDED “AS IS.” The entire risk as to implementing or otherwise using the Specification is assumed by the implementer and user. Except as stated herein, I expressly disclaim any warranties (express, implied, or otherwise), including implied warranties of merchantability, non-infringement, fitness for a particular purpose, or title, related to the Specification. IN NO EVENT WILL ANY PARTY BE LIABLE TO ANY OTHER PARTY FOR LOST PROFITS OR ANY FORM OF INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER FROM ANY CAUSES OF ACTION OF ANY KIND WITH RESPECT TO THIS AGREEMENT, WHETHER BASED ON BREACH OF CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, AND WHETHER OR NOT THE OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. All of my obligations under Section 3 regarding the transfer, successors in interest, or assignment of Granted Claims will be satisfied if I notify the transferee or assignee of any patent that I know contains Granted Claims of the obligations under Section 3. Nothing in this Agreement requires me to undertake a patent search. +10. Definitions. +10.1. Agreement. “Agreement” means this W3C Community Final Specification Agreement. +10.2. Corresponding Working Group. “Corresponding Working Group” is a W3C Working Group that is chartered to develop a Recommendation, as defined in the W3C Process Document, that takes the Specification as an input. +10.3. Essential Claims. “Essential Claims” shall mean all claims in any patent or patent application in any jurisdiction in the world that would necessarily be infringed by implementation of the Specification. A claim is necessarily infringed hereunder only when it is not possible to avoid infringing it because there is no non-infringing alternative for implementing the normative portions of the Specification. Existence of a non-infringing alternative shall be judged based on the state of the art at the time of the publication of the Specification. The following are expressly excluded from and shall not be deemed to constitute Essential Claims: +10.3.1. any claims other than as set forth above even if contained in the same patent as Essential Claims; and +10.3.2. claims which would be infringed only by: +portions of an implementation that are not specified in the normative portions of the Specification, or +enabling technologies that may be necessary to make or use any product or portion thereof that complies with the Specification and are not themselves expressly set forth in the Specification (e.g., semiconductor manufacturing technology, compiler technology, object-oriented technology, basic operating system technology, and the like); or +the implementation of technology developed elsewhere and merely incorporated by reference in the body of the Specification. +10.3.3. design patents and design registrations. +For purposes of this definition, the normative portions of the Specification shall be deemed to include only architectural and interoperability requirements. Optional features in the RFC 2119 sense are considered normative unless they are specifically identified as informative. Implementation examples or any other material that merely illustrate the requirements of the Specification are informative, rather than normative. +10.4. I, Me, or My. “I,” “me,” or “my” refers to the signatory. +10.5 Project. “Project” means the W3C Community Group or Business Group for which I executed this Agreement. +10.6. Specification. “Specification” means the Specification identified by the Project as the target of this agreement in a call for Final Specification Commitments. W3C shall provide the authoritative mechanisms for the identification of this Specification. +10.7. W3C Community RF Licensing Requirements. “W3C Community RF Licensing Requirements” license shall mean a non-assignable, non-sublicensable license to make, have made, use, sell, have sold, offer to sell, import, and distribute and dispose of implementations of the Specification that: +10.7.1. shall be available to all, worldwide, whether or not they are W3C Members; +10.7.2. shall extend to all Essential Claims owned or controlled by me; +10.7.3. may be limited to implementations of the Specification, and to what is required by the Specification; +10.7.4. may be conditioned on a grant of a reciprocal RF license (as defined in this policy) to all Essential Claims owned or controlled by the licensee. A reciprocal license may be required to be available to all, and a reciprocal license may itself be conditioned on a further reciprocal license from all. +10.7.5. may not be conditioned on payment of royalties, fees or other consideration; +10.7.6. may be suspended with respect to any licensee when licensor issued by licensee for infringement of claims essential to implement the Specification or any W3C Recommendation; +10.7.7. may not impose any further conditions or restrictions on the use of any technology, intellectual property rights, or other restrictions on behavior of the licensee, but may include reasonable, customary terms relating to operation or maintenance of the license relationship such as the following: choice of law and dispute resolution; +10.7.8. shall not be considered accepted by an implementer who manifests an intent not to accept the terms of the W3C Community RF Licensing Requirements license as offered by the licensor. +10.7.9. The RF license conforming to the requirements in this policy shall be made available by the licensor as long as the Specification is in effect. The term of such license shall be for the life of the patents in question. +I am encouraged to provide a contact from which licensing information can be obtained and other relevant licensing information. Any such information will be made publicly available. +10.8. You or Your. “You,” “you,” or “your” means any person or entity who exercises copyright or patent rights granted under this Agreement, and any person that person or entity controls. + +------------------------------------------------------------------------------------- + +------------------- WebGL ----------------------------- +Copyright (c) 2018 The Khronos Group Inc. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and/or associated documentation files (the +"Materials"), to deal in the Materials without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Materials, and to +permit persons to whom the Materials are furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Materials. + +THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +------------------------------------------------------ + + +--------------------------------------------------------- + +github.com/dlclark/regexp2 v1.11.5 - MIT +The MIT License (MIT) + +Copyright (c) Doug Clark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--------------------------------------------------------- + +--------------------------------------------------------- + +github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 - BSD-3-Clause + +Copyright (c) 2020 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--------------------------------------------------------- + +--------------------------------------------------------- + +golang.org/x/sync v0.14.0 - BSD-3-Clause + +Copyright 2009 The Go Authors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google LLC nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--------------------------------------------------------- diff --git a/README.md b/README.md index 847916b06e..ed10b42bb8 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,24 @@ [Not sure what this is? Read the announcement post!](https://devblogs.microsoft.com/typescript/typescript-native-port/) -This repo is very much under active development; as such there are no published artifacts at this time. -Interested developers can clone and run locally to try out things as they become available. +## Preview + +A preview build is available on npm as `@typescript/native-preview`. + +```sh +npm install @typescript/native-preview +npx tsgo # Use this as you would tsc. +``` + +A preview VS Code extension is [available on the VS Code marketplace](https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.native-preview). + +To use this, set this in your VS Code settings: + +```json +{ + "typescript.experimental.useTsgo": true +} +``` ## How to Build and Run @@ -44,12 +60,7 @@ After running `hereby build`, you can run `built/local/tsgo`, which behaves most ### Running LSP Prototype -* Run `hereby build` to build the LSP server -* Run `hereby install-extension` to build and install the VS Code extension. (Use `--insiders` to target `code-insiders` instead of `code`.) -* Copy the `"typescript-go.executablePath"` setting printed by `hereby install-extension` to your VS Code settings. -* Select "TypeScript: Use TypeScript Go (Experimental)" from the VS Code command palette (or set `"typescript.experimental.useTsgo"` in your VS Code settings). - -Alternatively, to debug and run the VS Code extension without installing it globally: +To debug and run the VS Code extension without installing it globally: * Run VS Code in the repo workspace (`code .`) * Copy `.vscode/launch.template.json` to `.vscode/launch.json` diff --git a/_extension/.gitignore b/_extension/.gitignore index 0e962469f0..21c68a9bf6 100644 --- a/_extension/.gitignore +++ b/_extension/.gitignore @@ -1,2 +1,3 @@ *.vsix dist/ +lib/ diff --git a/_extension/LICENSE b/_extension/LICENSE new file mode 100644 index 0000000000..8746124b27 --- /dev/null +++ b/_extension/LICENSE @@ -0,0 +1,55 @@ +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of this License; and + +You must cause any modified files to carry prominent notices stating that You changed the files; and + +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/_extension/README.md b/_extension/README.md new file mode 100644 index 0000000000..f85bce6c49 --- /dev/null +++ b/_extension/README.md @@ -0,0 +1,25 @@ +# TypeScript (Native Preview) + +This extension provides a preview of the native implementation of the TypeScript language service. It provides a nightly snapshot of features like go-to-definition, completions, errors and diagnostics, and quick info/tooltip hovers, and more. + +## Usage + +1. Install the extension from the marketplace. +2. Open a TypeScript or JavaScript file (`.ts`) in your editor. +3. Activate the extension with the command `TypeScript (Native Preview): Enable (Experimental)`, or update your settings below: + +## Configuration + +You can enable this extension by modifying the following settings: + +```jsonc +{ + // UI Setting: + // TypeScript (Native Preview) > Use Tsgo + "typescript.experimental.useTsgo": true +} +``` + +## Feedback + +If you encounter any issues or have suggestions for improvement, please open an issue on the [GitHub repository](https://github.com/microsoft/typescript-go). diff --git a/_extension/logo.png b/_extension/logo.png new file mode 100644 index 0000000000..0171eeb26e Binary files /dev/null and b/_extension/logo.png differ diff --git a/_extension/package.json b/_extension/package.json index a2f3c5d074..e5c49ac0bf 100644 --- a/_extension/package.json +++ b/_extension/package.json @@ -1,9 +1,10 @@ { - "name": "typescript-lsp", - "displayName": "TypeScript (LSP)", - "publisher": "typescript", + "name": "native-preview", + "displayName": "TypeScript (Native Preview)", + "publisher": "TypeScriptTeam", "author": "Microsoft Corp.", - "description": "Test extension for typescript-go", + "description": "Preview of the native TypeScript language server for Visual Studio Code.", + "icon": "logo.png", "private": true, "version": "0.0.0", "type": "commonjs", @@ -12,7 +13,12 @@ "url": "https://github.com/microsoft/typescript-go" }, "engines": { - "vscode": "^1.91.0" + "vscode": "^1.100.0" + }, + "capabilities": { + "untrustedWorkspaces": { + "supported": false + } }, "activationEvents": [ "onLanguage:javascript", @@ -23,9 +29,9 @@ "contributes": { "configuration": [ { - "title": "TypeScript Go", + "title": "TypeScript Native Preview", "properties": { - "typescript-go.trace.server": { + "typescript.native-preview.trace.server": { "type": "string", "enum": [ "off", @@ -33,52 +39,73 @@ "verbose" ], "default": "verbose", - "description": "Trace TypeScript Go server communication." + "description": "Trace TypeScript Go server communication.", + "tags": ["experimental"] }, - "typescript-go.pprofDir": { + "typescript.native-preview.pprofDir": { "type": "string", - "description": "Directory to write pprof profiles to." + "description": "Directory to write pprof profiles to.", + "tags": ["experimental"] }, - "typescript-go.executablePath": { + "typescript.native-preview.tsdk": { "type": "string", - "description": "Path to the tsgo binary. If not specified, the extension will look for it in the default location." + "description": "Path to the @typescript/native-preview package or tsgo binary directory. If not specified, the extension will look for it in the default location.", + "tags": ["experimental"] } } } ], "commands": [ { - "command": "typescript-go.restart", - "title": "TypeScript Go: Restart Language Server", - "enablement": "typescript-go.serverRunning" + "command": "typescript.native-preview.enable", + "title": "Enable (Experimental)", + "enablement": "!typescript.native-preview.serverRunning", + "category": "TypeScript Native Preview" + }, + { + "command": "typescript.native-preview.disable", + "title": "Disable", + "enablement": "typescript.native-preview.serverRunning", + "category": "TypeScript Native Preview" + }, + { + "command": "typescript.native-preview.restart", + "title": "Restart Language Server", + "enablement": "typescript.native-preview.serverRunning", + "category": "TypeScript Native Preview" + }, + { + "command": "typescript.native-preview.output.focus", + "title": "Show Output", + "enablement": "typescript.native-preview.serverRunning", + "category": "TypeScript Native Preview" + }, + { + "command": "typescript.native-preview.lsp-trace.focus", + "title": "Show LSP Trace", + "enablement": "typescript.native-preview.serverRunning", + "category": "TypeScript Native Preview" } - ], - "menus": { - "commandPalette": [ - { - "command": "typescript-go.restart", - "when": "typescript-go.serverRunning" - } - ] - } + ] }, "main": "./dist/extension.js", "files": [ - "dist" + "dist/extension.bundle.js", + "lib", + "LICENSE", + "NOTICE.txt", + "logo.png" ], "scripts": { "build": "tsc", "watch": "tsc --watch", - "build:prod": "esbuild src/extension.ts --bundle --external:vscode --platform=node --format=cjs --outfile=dist/extension.js --minify", - "package": "vsce package --skip-license --no-dependencies --out typescript-lsp.vsix", - "install-extension": "code --install-extension typescript-lsp.vsix", - "vscode:prepublish": "npm run build:prod" + "bundle": "esbuild src/extension.ts --bundle --external:vscode --platform=node --format=cjs --outfile=dist/extension.bundle.js --minify" }, "dependencies": { "vscode-languageclient": "^9.0.1" }, "devDependencies": { - "@types/vscode": "^1.91.0", + "@types/vscode": "^1.100.0", "@vscode/vsce": "^3.3.2", "esbuild": "^0.25.2" } diff --git a/_extension/src/client.ts b/_extension/src/client.ts new file mode 100644 index 0000000000..46fd90ebb0 --- /dev/null +++ b/_extension/src/client.ts @@ -0,0 +1,162 @@ +import * as vscode from "vscode"; +import { + LanguageClient, + LanguageClientOptions, + NotebookDocumentFilter, + ServerOptions, + TextDocumentFilter, + TransportKind, +} from "vscode-languageclient/node"; +import { + ExeInfo, + getExe, + jsTsLanguageModes, +} from "./util"; +import { getLanguageForUri } from "./util"; + +export class Client { + private outputChannel: vscode.OutputChannel; + private traceOutputChannel: vscode.OutputChannel; + private clientOptions: LanguageClientOptions; + private client?: LanguageClient; + private exe: ExeInfo | undefined; + private onStartedCallbacks: Set<() => void> = new Set(); + + constructor(outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel) { + this.outputChannel = outputChannel; + this.traceOutputChannel = traceOutputChannel; + this.clientOptions = { + documentSelector: [ + ...jsTsLanguageModes.map(language => ({ scheme: "file", language })), + ...jsTsLanguageModes.map(language => ({ scheme: "untitled", language })), + ], + outputChannel: this.outputChannel, + traceOutputChannel: this.traceOutputChannel, + diagnosticPullOptions: { + onChange: true, + onSave: true, + onTabs: true, + match(documentSelector, resource) { + // This function is called when diagnostics are requested but + // only the URI itself is known (e.g. open but not yet focused tabs), + // so will not be present in vscode.workspace.textDocuments. + // See if this file matches without consulting vscode.languages.match + // (which requires a TextDocument). + + const language = getLanguageForUri(resource); + + for (const selector of documentSelector) { + if (typeof selector === "string") { + if (selector === language) { + return true; + } + continue; + } + if (NotebookDocumentFilter.is(selector)) { + continue; + } + if (TextDocumentFilter.is(selector)) { + if (selector.language !== undefined && selector.language !== language) { + continue; + } + + if (selector.scheme !== undefined && selector.scheme !== resource.scheme) { + continue; + } + + if (selector.pattern !== undefined) { + // VS Code's glob matcher is not available via the API; + // see: https://github.com/microsoft/vscode/issues/237304 + // But, we're only called on selectors passed above, so just ignore this for now. + throw new Error("Not implemented"); + } + + return true; + } + } + + return false; + }, + }, + }; + } + + async initialize(context: vscode.ExtensionContext): Promise { + const exe = await getExe(context); + this.start(context, exe); + } + + async start(context: vscode.ExtensionContext, exe: { path: string; version: string; }): Promise { + this.exe = exe; + this.outputChannel.appendLine(`Resolved to ${this.exe.path}`); + + // Get pprofDir + const config = vscode.workspace.getConfiguration("typescript.native-preview"); + const pprofDir = config.get("pprofDir"); + const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; + + const serverOptions: ServerOptions = { + run: { + command: this.exe.path, + args: ["--lsp", ...pprofArgs], + transport: TransportKind.stdio, + }, + debug: { + command: this.exe.path, + args: ["--lsp", ...pprofArgs], + transport: TransportKind.stdio, + }, + }; + + this.client = new LanguageClient( + "typescript.native-preview", + "typescript.native-preview-lsp", + serverOptions, + this.clientOptions, + ); + + this.outputChannel.appendLine(`Starting language server...`); + await this.client.start(); + vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", true); + this.onStartedCallbacks.forEach(callback => callback()); + context.subscriptions.push( + new vscode.Disposable(() => { + if (this.client) { + this.client.stop(); + } + vscode.commands.executeCommand("setContext", "typescript.native-preview.serverRunning", false); + }), + ); + } + + getCurrentExe(): { path: string; version: string; } | undefined { + return this.exe; + } + + onStarted(callback: () => void): vscode.Disposable { + if (this.exe) { + callback(); + return new vscode.Disposable(() => {}); + } + + this.onStartedCallbacks.add(callback); + return new vscode.Disposable(() => { + this.onStartedCallbacks.delete(callback); + }); + } + + async restart(context: vscode.ExtensionContext): Promise { + if (!this.client) { + return Promise.reject(new Error("Language client is not initialized")); + } + const exe = await getExe(context); + if (exe.path !== this.exe?.path) { + this.outputChannel.appendLine(`Executable path changed from ${this.exe?.path} to ${exe.path}`); + this.outputChannel.appendLine(`Restarting language server with new executable...`); + return this.start(context, exe); + } + + this.outputChannel.appendLine(`Restarting language server...`); + return this.client.restart(); + } +} diff --git a/_extension/src/commands.ts b/_extension/src/commands.ts new file mode 100644 index 0000000000..364377a1f1 --- /dev/null +++ b/_extension/src/commands.ts @@ -0,0 +1,84 @@ +import * as vscode from "vscode"; +import { Client } from "./client"; + +export function registerCommands(context: vscode.ExtensionContext, client: Client, outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel): void { + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => { + // Fire and forget, because this will restart the extension host and cause an error if we await + updateUseTsgoSetting(true); + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.disable", () => { + // Fire and forget, because this will restart the extension host and cause an error if we await + updateUseTsgoSetting(false); + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.restart", () => { + return client.restart(context); + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.output.focus", () => { + outputChannel.show(); + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.lsp-trace.focus", () => { + traceOutputChannel.show(); + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.selectVersion", async () => { + })); + + context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.showMenu", showCommands)); +} + +/** + * Updates the TypeScript Native Preview setting and reloads extension host. + */ +async function updateUseTsgoSetting(enable: boolean): Promise { + const tsConfig = vscode.workspace.getConfiguration("typescript"); + let target: vscode.ConfigurationTarget | undefined; + const useTsgo = tsConfig.inspect("experimental.useTsgo"); + if (useTsgo) { + target = useTsgo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder : + useTsgo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace : + useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined; + } + // Update the setting and restart the extension host (needed to change the state of the built-in TS extension) + await tsConfig.update("experimental.useTsgo", enable, target); + await vscode.commands.executeCommand("workbench.action.restartExtensionHost"); +} + +/** + * Shows the quick pick menu for TypeScript Native Preview commands + */ +async function showCommands(): Promise { + const commands: readonly { label: string; description: string; command: string; }[] = [ + { + label: "$(refresh) Restart Server", + description: "Restart the TypeScript Native Preview language server", + command: "typescript.native-preview.restart", + }, + { + label: "$(output) Show TS Server Log", + description: "Show the TypeScript Native Preview server log", + command: "typescript.native-preview.output.focus", + }, + { + label: "$(debug-console) Show LSP Messages", + description: "Show the LSP communication trace", + command: "typescript.native-preview.lsp-trace.focus", + }, + { + label: "$(stop-circle) Disable TypeScript Native Preview", + description: "Switch back to the built-in TypeScript extension", + command: "typescript.native-preview.disable", + }, + ]; + + const selected = await vscode.window.showQuickPick(commands, { + placeHolder: "TypeScript Native Preview Commands", + }); + + if (selected) { + await vscode.commands.executeCommand(selected.command); + } +} diff --git a/_extension/src/extension.ts b/_extension/src/extension.ts index b90313b547..b42c356d3f 100644 --- a/_extension/src/extension.ts +++ b/_extension/src/extension.ts @@ -1,225 +1,48 @@ -import * as path from "path"; import * as vscode from "vscode"; -import { - LanguageClient, - LanguageClientOptions, - NotebookDocumentFilter, - ServerOptions, - TextDocumentFilter, - TransportKind, -} from "vscode-languageclient/node"; - -let client: LanguageClient; -let statusBarItem: vscode.StatusBarItem; - -const BUILTIN_TS_EXTENSION_ID = "vscode.typescript-language-features"; - -export function activate(context: vscode.ExtensionContext) { - const tsExtension = vscode.extensions.getExtension(BUILTIN_TS_EXTENSION_ID); - if (tsExtension?.isActive && !vscode.workspace.getConfiguration("typescript").get("experimental.useTsgo")) { - return; - } - - const output = vscode.window.createOutputChannel("typescript-go", "log"); - const traceOutput = vscode.window.createOutputChannel("typescript-go (LSP)"); - - setupStatusBar(context); - registerCommands(context, output, traceOutput); - - const config = vscode.workspace.getConfiguration("typescript-go"); - - const exe = config.get("executablePath") || context.asAbsolutePath( - path.join("../", "built", "local", `tsgo${process.platform === "win32" ? ".exe" : ""}`), - ); - - output.appendLine(`Resolved to ${exe}`); - - // Get pprofDir - const pprofDir = config.get("pprofDir"); - const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : []; - - const serverOptions: ServerOptions = { - run: { - command: exe, - args: ["--lsp", ...pprofArgs], - transport: TransportKind.stdio, - }, - debug: { - command: exe, - args: ["--lsp", ...pprofArgs], - transport: TransportKind.stdio, - }, - }; - - const clientOptions: LanguageClientOptions = { - documentSelector: [ - { scheme: "file", language: "typescript" }, - { scheme: "file", language: "typescriptreact" }, - { scheme: "file", language: "javascript" }, - { scheme: "file", language: "javascriptreact" }, - { scheme: "untitled", language: "typescript" }, - { scheme: "untitled", language: "typescriptreact" }, - { scheme: "untitled", language: "javascript" }, - { scheme: "untitled", language: "javascriptreact" }, - ], - outputChannel: output, - traceOutputChannel: traceOutput, - diagnosticPullOptions: { - onChange: true, - onSave: true, - onTabs: true, - match(documentSelector, resource) { - // This function is called when diagnostics are requested but - // only the URI itself is known (e.g. open but not yet focused tabs), - // so will not be present in vscode.workspace.textDocuments. - // See if this file matches without consulting vscode.languages.match - // (which requires a TextDocument). - - const language = getLanguageForUri(resource); - - for (const selector of documentSelector) { - if (typeof selector === "string") { - if (selector === language) { - return true; - } - continue; - } - if (NotebookDocumentFilter.is(selector)) { - continue; - } - if (TextDocumentFilter.is(selector)) { - if (selector.language !== undefined && selector.language !== language) { - continue; - } - - if (selector.scheme !== undefined && selector.scheme !== resource.scheme) { - continue; - } - - if (selector.pattern !== undefined) { - // VS Code's glob matcher is not available via the API; - // see: https://github.com/microsoft/vscode/issues/237304 - // But, we're only called on selectors passed above, so just ignore this for now. - throw new Error("Not implemented"); - } - - return true; - } +import { Client } from "./client"; +import { registerCommands } from "./commands"; +import { setupStatusBar } from "./statusBar"; +import { setupVersionStatusItem } from "./versionStatusItem"; + +export async function activate(context: vscode.ExtensionContext) { + const output = vscode.window.createOutputChannel("typescript-native-preview", "log"); + const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)"); + const client = new Client(output, traceOutput); + registerCommands(context, client, output, traceOutput); + + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => { + if (event.affectsConfiguration("typescript.experimental.useTsgo")) { + // Delay because the command to change the config setting will restart + // the extension host, so no need to show a message + setTimeout(async () => { + const selected = await vscode.window.showInformationMessage("TypeScript Native Preview setting has changed. Restart extensions to apply changes.", "Restart Extensions"); + if (selected) { + vscode.commands.executeCommand("workbench.action.restartExtensionHost"); } - - return false; - }, - }, - }; - - client = new LanguageClient( - "typescript-go", - "typescript-go-lsp", - serverOptions, - clientOptions, - ); - - output.appendLine(`Starting language server...`); - client.start(); - vscode.commands.executeCommand("setContext", "typescript-go.serverRunning", true); -} - -/** - * Sets up the status bar item for TypeScript Go - * @param context Extension context - */ -function setupStatusBar(context: vscode.ExtensionContext): void { - statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); - statusBarItem.text = "$(beaker) tsgo"; - statusBarItem.tooltip = "TypeScript Go Language Server"; - statusBarItem.command = "typescript-go.showMenu"; - statusBarItem.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground"); - statusBarItem.show(); - context.subscriptions.push(statusBarItem); -} - -/** - * Registers all commands for the extension - * @param context Extension context - */ -function registerCommands(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel): void { - context.subscriptions.push(vscode.commands.registerCommand("typescript-go.restart", async () => { - await client.restart(); - })); - - context.subscriptions.push(vscode.commands.registerCommand("typescript-go.output.focus", () => { - outputChannel.show(); - })); - - context.subscriptions.push(vscode.commands.registerCommand("typescript-go.lsp-trace.focus", () => { - traceOutputChannel.show(); + }, 100); + } })); - context.subscriptions.push(vscode.commands.registerCommand("typescript-go.showMenu", showQuickPickMenu)); -} - -/** - * Shows the quick pick menu for TypeScript Go options - */ -async function showQuickPickMenu(): Promise { - const selected = await vscode.window.showQuickPick([ - { label: "$(refresh) Restart Server", description: "Restart the TypeScript Go language server" }, - { label: "$(output) Show TS Server Log", description: "Show the TypeScript Go server log" }, - { label: "$(debug-console) Show LSP Messages", description: "Show the LSP communication trace" }, - { label: "$(stop-circle) Disable TypeScript Go", description: "Switch back to the built-in TypeScript extension" }, - ], { - placeHolder: "TypeScript Go Options", - }); - - if (selected) { - if (selected.label.includes("Restart Server")) { - await vscode.commands.executeCommand("typescript-go.restart"); + const useTsgo = vscode.workspace.getConfiguration("typescript").get("experimental.useTsgo"); + if (!useTsgo) { + if (context.extensionMode === vscode.ExtensionMode.Development) { + if (useTsgo === false) { + vscode.window.showInformationMessage( + 'TypeScript Native Preview is running in development mode. Ignoring "typescript.experimental.useTsgo": false.', + ); + } } - else if (selected.label.includes("Show TS Server Log")) { - await vscode.commands.executeCommand("typescript-go.output.focus"); + else { + output.appendLine("TypeScript Native Preview is disabled. Select 'Enable TypeScript Native Preview (Experimental)' in the command palette to enable it."); + return; } - else if (selected.label.includes("Show LSP Messages")) { - await vscode.commands.executeCommand("typescript-go.lsp-trace.focus"); - } - else if (selected.label.includes("Disable TypeScript Go")) { - // Fire and forget, because this command will restart the whole extension host - // and awaiting it shows a weird cancellation error. - vscode.commands.executeCommand("typescript.experimental.disableTsgo"); - } - } -} - -export async function deactivate(): Promise { - // Dispose of status bar item - if (statusBarItem) { - statusBarItem.dispose(); } - if (!client) { - return; - } - - await client.stop(); - return vscode.commands.executeCommand("setContext", "typescript-go.serverRunning", false); + await client.initialize(context); + setupStatusBar(context); + setupVersionStatusItem(context, client); } -function getLanguageForUri(uri: vscode.Uri): string | undefined { - const ext = path.posix.extname(uri.path); - switch (ext) { - case ".ts": - case ".mts": - case ".cts": - return "typescript"; - case ".js": - case ".mjs": - case ".cjs": - return "javascript"; - case ".tsx": - return "typescriptreact"; - case ".jsx": - return "javascriptreact"; - default: - return undefined; - } +export async function deactivate(): Promise { } diff --git a/_extension/src/statusBar.ts b/_extension/src/statusBar.ts new file mode 100644 index 0000000000..1a23782dc8 --- /dev/null +++ b/_extension/src/statusBar.ts @@ -0,0 +1,11 @@ +import * as vscode from "vscode"; + +export function setupStatusBar(context: vscode.ExtensionContext): void { + const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); + statusBarItem.text = "$(beaker) tsgo"; + statusBarItem.tooltip = "TypeScript Native Preview Language Server"; + statusBarItem.command = "typescript.native-preview.showMenu"; + statusBarItem.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground"); + statusBarItem.show(); + context.subscriptions.push(statusBarItem); +} diff --git a/_extension/src/util.ts b/_extension/src/util.ts new file mode 100644 index 0000000000..b3be8beaf6 --- /dev/null +++ b/_extension/src/util.ts @@ -0,0 +1,91 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import packageJson from "../package.json"; + +const version = packageJson.version; + +export const jsTsLanguageModes = [ + "typescript", + "typescriptreact", + "javascript", + "javascriptreact", +]; + +export const builtinTSExtensionId = "vscode.typescript-language-features"; + +export interface ExeInfo { + path: string; + version: string; +} + +export function getBuiltinExePath(context: vscode.ExtensionContext): string { + return context.asAbsolutePath(path.join("./lib", `tsgo${process.platform === "win32" ? ".exe" : ""}`)); +} + +function workspaceResolve(relativePath: string): vscode.Uri { + if (path.isAbsolute(relativePath)) { + return vscode.Uri.file(relativePath); + } + if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { + const workspaceFolder = vscode.workspace.workspaceFolders[0]; + return vscode.Uri.joinPath(workspaceFolder.uri, relativePath); + } + return vscode.Uri.file(relativePath); +} + +export async function getExe(context: vscode.ExtensionContext): Promise { + const config = vscode.workspace.getConfiguration("typescript.native-preview"); + const exeName = `tsgo${process.platform === "win32" ? ".exe" : ""}`; + + let exe = config.get("tsdk"); + if (exe) { + if (exe.endsWith("/@typescript/native-preview")) { + try { + const packagePath = workspaceResolve(exe); + const packageJsonPath = vscode.Uri.joinPath(packagePath, "package.json"); + const packageJson = JSON.parse(await vscode.workspace.fs.readFile(packageJsonPath).then(buffer => buffer.toString())); + const getExePath = (await import(vscode.Uri.joinPath(packagePath, "lib", "getExePath.js").toString())).default; + return { path: getExePath(), version: packageJson.version }; + } + catch {} + } + try { + const exePath = workspaceResolve(path.join(exe, exeName)); + await vscode.workspace.fs.stat(exePath); + return { path: exePath.fsPath, version: "(local)" }; + } + catch {} + } + + exe = context.asAbsolutePath(path.join("../", "built", "local", exeName)); + try { + await vscode.workspace.fs.stat(vscode.Uri.file(exe)); + return { path: exe, version: "(local)" }; + } + catch {} + + return { + path: getBuiltinExePath(context), + version, + }; +} + +export function getLanguageForUri(uri: vscode.Uri): string | undefined { + const ext = path.posix.extname(uri.path); + switch (ext) { + case ".ts": + case ".mts": + case ".cts": + return "typescript"; + case ".js": + case ".mjs": + case ".cjs": + return "javascript"; + case ".tsx": + return "typescriptreact"; + case ".jsx": + return "javascriptreact"; + default: + return undefined; + } +} diff --git a/_extension/src/versionStatusItem.ts b/_extension/src/versionStatusItem.ts new file mode 100644 index 0000000000..d2329cd26b --- /dev/null +++ b/_extension/src/versionStatusItem.ts @@ -0,0 +1,16 @@ +import * as vscode from "vscode"; +import { Client } from "./client"; +import { jsTsLanguageModes } from "./util"; + +export function setupVersionStatusItem( + context: vscode.ExtensionContext, + client: Client, +): void { + const statusItem = vscode.languages.createLanguageStatusItem("typescript.native-preview.version", jsTsLanguageModes); + statusItem.name = "TypeScript Native Preview version"; + statusItem.detail = "TypeScript Native Preview version"; + context.subscriptions.push(client.onStarted(() => { + statusItem.text = client.getCurrentExe()!.version; + })); + context.subscriptions.push(statusItem); +} diff --git a/_extension/tsconfig.json b/_extension/tsconfig.json index 2f6c2e9c80..6458aaa5ef 100644 --- a/_extension/tsconfig.json +++ b/_extension/tsconfig.json @@ -6,7 +6,9 @@ "outDir": "./dist", "esModuleInterop": true, "strict": true, - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true, + "sourceMap": true }, "include": ["./src/**/*"] } diff --git a/_packages/native-preview/README.md b/_packages/native-preview/README.md new file mode 100644 index 0000000000..afd47c6fd5 --- /dev/null +++ b/_packages/native-preview/README.md @@ -0,0 +1,22 @@ +# TypeScript (Native Preview) + +This package provides a preview build of [the native port of TypeScript](https://devblogs.microsoft.com/typescript/typescript-native-port/). +Not all features are implemented yet. + +This package is intended for testing and experimentation. +It will eventually be replaced by the official TypeScript package. + +## Usage + +Use the `tsgo` command just like you would use `tsc`: + +```sh +npx tsgo --help +``` + +## Issues and Feedback + +The native port of TypeScript is still in progress. +We expect many gaps, but are seeking experimentation and feedback. +If you have found differences that are not yet known, we encourage you to leave feedback on [the issue tracker](https://github.com/microsoft/typescript-go/issues). + diff --git a/_packages/native-preview/bin/tsgo.js b/_packages/native-preview/bin/tsgo.js new file mode 100755 index 0000000000..1c85849413 --- /dev/null +++ b/_packages/native-preview/bin/tsgo.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +import getExePath from "#getExePath"; +import { execFileSync } from "node:child_process"; + +const exe = getExePath(); + +try { + execFileSync(exe, process.argv.slice(2), { stdio: "inherit" }); +} +catch (e) { + if (e.status) { + process.exitCode = e.status; + } + else { + throw e; + } +} diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js new file mode 100644 index 0000000000..35faeeada3 --- /dev/null +++ b/_packages/native-preview/lib/getExePath.js @@ -0,0 +1,43 @@ +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +export default function getExePath() { + const __dirname = path.dirname(fileURLToPath(import.meta.url)); + const normalizedDirname = __dirname.replace(/\\/g, "/"); + + let exeDir; + + const expectedPackage = "native-preview-" + process.platform + "-" + process.arch; + + if (normalizedDirname.endsWith("/_packages/native-preview/lib")) { + // We're running directly from source in the repo. + exeDir = path.resolve(__dirname, "..", "..", "..", "built", "local"); + } + else if (normalizedDirname.endsWith("/built/npm/native-preview/lib")) { + // We're running from the built output. + exeDir = path.resolve(__dirname, "..", "..", expectedPackage, "lib"); + } + else { + // We're actually running from an installed package. + const platformPackageName = "@typescript/" + expectedPackage; + let packageJson; + try { + // v20.6.0, v18.19.0 + packageJson = import.meta.resolve(platformPackageName + "/package.json"); + } + catch (e) { + throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); + } + const packageJsonPath = fileURLToPath(packageJson); + exeDir = path.join(path.dirname(packageJsonPath), "lib"); + } + + const exe = path.join(exeDir, "tsgo" + (process.platform === "win32" ? ".exe" : "")); + + if (!fs.existsSync(exe)) { + throw new Error("Executable not found: " + exe); + } + + return exe; +} diff --git a/_packages/native-preview/package.json b/_packages/native-preview/package.json new file mode 100644 index 0000000000..7682cd6954 --- /dev/null +++ b/_packages/native-preview/package.json @@ -0,0 +1,38 @@ +{ + "private": true, + "name": "@typescript/native-preview", + "version": "0.0.0", + "license": "Apache-2.0", + "author": "Microsoft Corp.", + "homepage": "https://www.typescriptlang.org/", + "description": "Preview CLI of the native TypeScript compiler port", + "keywords": [ + "TypeScript", + "Microsoft", + "compiler", + "language", + "javascript", + "tsgo" + ], + "bugs": { + "url": "https://github.com/microsoft/typescript-go/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/microsoft/typescript-go.git" + }, + "type": "module", + "preferUnplugged": true, + "engines": { + "node": ">=20.6.0" + }, + "bin": { + "tsgo": "./bin/tsgo.js" + }, + "exports": { + "./package.json": "./package.json" + }, + "imports": { + "#getExePath": "./lib/getExePath.js" + } +} diff --git a/_packages/native-preview/tsconfig.json b/_packages/native-preview/tsconfig.json new file mode 100644 index 0000000000..f22195e68c --- /dev/null +++ b/_packages/native-preview/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "node16", + "strict": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "checkJs": true, + "noEmit": true, + "useUnknownInCatchVariables": false + }, + "include": ["bin"] +} diff --git a/internal/core/version.go b/internal/core/version.go index 83c28637ac..9e04cb52c4 100644 --- a/internal/core/version.go +++ b/internal/core/version.go @@ -1,6 +1,33 @@ package core -const ( - VersionMajorMinor = "7.0" - Version = "7.0.0-dev" +import ( + "strings" ) + +// This is a var so it can be overridden by ldflags. +var version = "7.0.0-dev" + +func Version() string { + return version +} + +var versionMajorMinor = func() string { + seenMajor := false + i := strings.IndexFunc(version, func(r rune) bool { + if r == '.' { + if seenMajor { + return true + } + seenMajor = true + } + return false + }) + if i == -1 { + panic("invalid version string: " + version) + } + return version[:i] +}() + +func VersionMajorMinor() string { + return versionMajorMinor +} diff --git a/internal/execute/outputs.go b/internal/execute/outputs.go index 7fcc8011d0..0515f1d55d 100644 --- a/internal/execute/outputs.go +++ b/internal/execute/outputs.go @@ -95,7 +95,7 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm } func printVersion(sys System) { - fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version)+sys.NewLine()) + fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version())+sys.NewLine()) sys.EndWrite() } @@ -158,7 +158,7 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) { output = append(output, " ", desc.Format(), sys.NewLine(), sys.NewLine()) } - msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version) + msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version()) output = append(output, getHeader(sys, msg)...) output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, sys.NewLine(), sys.NewLine()) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 2c9ff587a6..b9d9353290 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -432,7 +432,7 @@ func (s *Server) handleInitialize(req *lsproto.RequestMessage) { s.sendResult(req.ID, &lsproto.InitializeResult{ ServerInfo: &lsproto.ServerInfo{ Name: "typescript-go", - Version: ptrTo(core.Version), + Version: ptrTo(core.Version()), }, Capabilities: &lsproto.ServerCapabilities{ PositionEncoding: ptrTo(s.positionEncoding), diff --git a/internal/module/resolver.go b/internal/module/resolver.go index 741e08860b..6a23df0d8d 100644 --- a/internal/module/resolver.go +++ b/internal/module/resolver.go @@ -862,7 +862,7 @@ func (r *resolutionState) loadModuleFromSpecificNodeModulesDirectory(ext extensi versionPaths := packageInfo.Contents.GetVersionPaths(r.getTraceFunc()) if versionPaths.Exists() { if r.resolver.traceEnabled() { - r.resolver.host.Trace(diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2.Format(versionPaths.Version, core.Version, rest)) + r.resolver.host.Trace(diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2.Format(versionPaths.Version, core.Version(), rest)) } packageDirectoryExists := nodeModulesDirectoryExists && r.resolver.host.FS().DirectoryExists(packageDirectory) pathPatterns := tryParsePatterns(versionPaths.GetPaths()) @@ -1307,7 +1307,7 @@ func (r *resolutionState) loadNodeModuleFromDirectoryWorker(ext extensions, cand moduleName = tspath.GetRelativePathFromDirectory(candidate, indexPath, tspath.ComparePathsOptions{}) } if r.resolver.traceEnabled() { - r.resolver.host.Trace(diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2.Format(versionPaths.Version, core.Version, moduleName)) + r.resolver.host.Trace(diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2.Format(versionPaths.Version, core.Version(), moduleName)) } pathPatterns := tryParsePatterns(versionPaths.GetPaths()) if result := r.tryLoadModuleUsingPaths(ext, moduleName, candidate, versionPaths.GetPaths(), pathPatterns, loader, onlyRecordFailuresForPackageFile); !result.shouldContinueSearching() { diff --git a/internal/module/util.go b/internal/module/util.go index 7a5cf4b552..a583b97b6c 100644 --- a/internal/module/util.go +++ b/internal/module/util.go @@ -8,7 +8,7 @@ import ( "github.com/microsoft/typescript-go/internal/tspath" ) -var typeScriptVersion = semver.MustParse(core.Version) +var typeScriptVersion = semver.MustParse(core.Version()) const InferredTypesContainingFile = "__inferred type names__.ts" diff --git a/internal/packagejson/cache.go b/internal/packagejson/cache.go index ee0ea9271b..f38de28c45 100644 --- a/internal/packagejson/cache.go +++ b/internal/packagejson/cache.go @@ -10,7 +10,7 @@ import ( "github.com/microsoft/typescript-go/internal/tspath" ) -var typeScriptVersion = semver.MustParse(core.Version) +var typeScriptVersion = semver.MustParse(core.Version()) type PackageJson struct { Fields @@ -61,7 +61,7 @@ func (p *PackageJson) GetVersionPaths(trace func(string)) VersionPaths { } if trace != nil { - trace(diagnostics.X_package_json_does_not_have_a_typesVersions_entry_that_matches_version_0.Format(core.VersionMajorMinor)) + trace(diagnostics.X_package_json_does_not_have_a_typesVersions_entry_that_matches_version_0.Format(core.VersionMajorMinor())) } }) return p.versionPaths diff --git a/package-lock.json b/package-lock.json index 7611d80c24..24260dbb2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,31 +14,34 @@ "./_packages/*" ], "devDependencies": { + "@types/adm-zip": "^0.5.7", "@types/node": "latest", "@types/which": "^3.0.4", + "adm-zip": "^0.5.16", "chokidar": "^4.0.3", "dprint": "^0.49.1", "execa": "^9.5.2", "glob": "^10.4.5", "hereby": "^1.10.0", + "p-limit": "^6.2.0", "picocolors": "^1.1.1", "typescript": "^5.8.3", "which": "^5.0.0" } }, "_extension": { - "name": "typescript-lsp", + "name": "native-preview", "version": "0.0.0", "dependencies": { "vscode-languageclient": "^9.0.1" }, "devDependencies": { - "@types/vscode": "^1.91.0", + "@types/vscode": "^1.100.0", "@vscode/vsce": "^3.3.2", "esbuild": "^0.25.2" }, "engines": { - "vscode": "^1.91.0" + "vscode": "^1.100.0" } }, "_packages/api": { @@ -56,6 +59,17 @@ "name": "@typescript/ast", "version": "1.0.0" }, + "_packages/native-preview": { + "name": "@typescript/native-preview", + "version": "0.0.0", + "license": "Apache-2.0", + "bin": { + "tsgo": "bin/tsgo.js" + }, + "engines": { + "node": ">=20.6.0" + } + }, "node_modules/@azure/abort-controller": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz", @@ -811,6 +825,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@types/adm-zip": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.5.7.tgz", + "integrity": "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/node": { "version": "22.14.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz", @@ -821,9 +844,9 @@ } }, "node_modules/@types/vscode": { - "version": "1.99.1", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.99.1.tgz", - "integrity": "sha512-cQlqxHZ040ta6ovZXnXRxs3fJiTmlurkIWOfZVcLSZPcm9J4ikFpXuB7gihofGn5ng+kDVma5EmJIclfk0trPQ==", + "version": "1.100.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.100.0.tgz", + "integrity": "sha512-4uNyvzHoraXEeCamR3+fzcBlh7Afs4Ifjs4epINyUX/jvdk0uzLnwiDY35UKDKnkCHP5Nu3dljl2H8lR6s+rQw==", "dev": true }, "node_modules/@types/which": { @@ -840,6 +863,10 @@ "resolved": "_packages/ast", "link": true }, + "node_modules/@typescript/native-preview": { + "resolved": "_packages/native-preview", + "link": true + }, "node_modules/@vscode/vsce": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/@vscode/vsce/-/vsce-3.3.2.tgz", @@ -1134,6 +1161,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "dev": true, + "engines": { + "node": ">=12.0" + } + }, "node_modules/agent-base": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", @@ -2790,6 +2826,10 @@ "license": "MIT", "optional": true }, + "node_modules/native-preview": { + "resolved": "_extension", + "link": true + }, "node_modules/node-abi": { "version": "3.74.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.74.0.tgz", @@ -2896,6 +2936,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-limit": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.2.0.tgz", + "integrity": "sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==", + "dev": true, + "dependencies": { + "yocto-queue": "^1.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/package-json-from-dist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", @@ -3642,10 +3697,6 @@ "node": ">=14.17" } }, - "node_modules/typescript-lsp": { - "resolved": "_extension", - "link": true - }, "node_modules/typical": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", @@ -4000,6 +4051,18 @@ "buffer-crc32": "~0.2.3" } }, + "node_modules/yocto-queue": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.1.tgz", + "integrity": "sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg==", + "dev": true, + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/yoctocolors": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz", @@ -4409,6 +4472,15 @@ "integrity": "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==", "dev": true }, + "@types/adm-zip": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.5.7.tgz", + "integrity": "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "22.14.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz", @@ -4419,9 +4491,9 @@ } }, "@types/vscode": { - "version": "1.99.1", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.99.1.tgz", - "integrity": "sha512-cQlqxHZ040ta6ovZXnXRxs3fJiTmlurkIWOfZVcLSZPcm9J4ikFpXuB7gihofGn5ng+kDVma5EmJIclfk0trPQ==", + "version": "1.100.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.100.0.tgz", + "integrity": "sha512-4uNyvzHoraXEeCamR3+fzcBlh7Afs4Ifjs4epINyUX/jvdk0uzLnwiDY35UKDKnkCHP5Nu3dljl2H8lR6s+rQw==", "dev": true }, "@types/which": { @@ -4441,6 +4513,9 @@ "@typescript/ast": { "version": "file:_packages/ast" }, + "@typescript/native-preview": { + "version": "file:_packages/native-preview" + }, "@vscode/vsce": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/@vscode/vsce/-/vsce-3.3.2.tgz", @@ -4627,6 +4702,12 @@ "dev": true, "optional": true }, + "adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "dev": true + }, "agent-base": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", @@ -5758,6 +5839,15 @@ "dev": true, "optional": true }, + "native-preview": { + "version": "file:_extension", + "requires": { + "@types/vscode": "^1.100.0", + "@vscode/vsce": "^3.3.2", + "esbuild": "^0.25.2", + "vscode-languageclient": "^9.0.1" + } + }, "node-abi": { "version": "3.74.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.74.0.tgz", @@ -5830,6 +5920,15 @@ "is-wsl": "^3.1.0" } }, + "p-limit": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.2.0.tgz", + "integrity": "sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==", + "dev": true, + "requires": { + "yocto-queue": "^1.1.1" + } + }, "package-json-from-dist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", @@ -6327,15 +6426,6 @@ "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true }, - "typescript-lsp": { - "version": "file:_extension", - "requires": { - "@types/vscode": "^1.91.0", - "@vscode/vsce": "^3.3.2", - "esbuild": "^0.25.2", - "vscode-languageclient": "^9.0.1" - } - }, "typical": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", @@ -6600,6 +6690,12 @@ "buffer-crc32": "~0.2.3" } }, + "yocto-queue": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.1.tgz", + "integrity": "sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg==", + "dev": true + }, "yoctocolors": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz", diff --git a/package.json b/package.json index b798034486..ce73bc5885 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,19 @@ { + "private": true, "name": "typescript-go", - "author": "Microsoft Corp.", - "homepage": "https://www.typescriptlang.org/", "version": "0.0.0", "license": "Apache-2.0", - "description": "TypeScript is a language for application scale JavaScript development", - "keywords": [ - "TypeScript", - "Microsoft", - "compiler", - "language", - "javascript" - ], - "bugs": { - "url": "https://github.com/microsoft/typescript-go/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/microsoft/typescript-go.git" - }, "devDependencies": { + "@types/adm-zip": "^0.5.7", "@types/node": "latest", "@types/which": "^3.0.4", + "adm-zip": "^0.5.16", "chokidar": "^4.0.3", "dprint": "^0.49.1", "execa": "^9.5.2", "glob": "^10.4.5", "hereby": "^1.10.0", + "p-limit": "^6.2.0", "picocolors": "^1.1.1", "typescript": "^5.8.3", "which": "^5.0.0" @@ -37,8 +24,8 @@ "build:watch": "hereby build:watch", "test": "hereby test", "api:build": "npm run -w @typescript/api build", - "extension:build": "npm run -w typescript-lsp build", - "extension:watch": "npm run -w typescript-lsp watch", + "extension:build": "npm run -w _extension build", + "extension:watch": "npm run -w _extension watch", "node": "node --no-warnings --conditions @typescript/source" }, "workspaces": [ @@ -47,7 +34,7 @@ ], "packageManager": "npm@8.19.4", "volta": { - "node": "20.5.1", + "node": "20.19.1", "npm": "8.19.4" } }