mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge branch 'master' into restTuples
# Conflicts: # tests/baselines/reference/APISample_Watch.errors.txt # tests/baselines/reference/APISample_WatchWithDefaults.errors.txt # tests/baselines/reference/APISample_WatchWithOwnWatchHost.errors.txt # tests/baselines/reference/APISample_compile.errors.txt # tests/baselines/reference/APISample_jsdoc.errors.txt # tests/baselines/reference/APISample_linter.errors.txt # tests/baselines/reference/APISample_parseConfig.errors.txt # tests/baselines/reference/APISample_transform.errors.txt # tests/baselines/reference/APISample_watcher.errors.txt # tests/baselines/reference/api/tsserverlibrary.d.ts # tests/baselines/reference/api/typescript.d.ts
This commit is contained in:
@@ -55,7 +55,7 @@ class DeclarationsWalker {
|
||||
if (declarations) {
|
||||
for (const decl of declarations) {
|
||||
const sourceFile = decl.getSourceFile();
|
||||
if (sourceFile === this.protocolFile || /lib\.(.*)\.d.ts/.test(path.basename(sourceFile.fileName))) {
|
||||
if (sourceFile === this.protocolFile || /lib(\..+)?\.d.ts/.test(path.basename(sourceFile.fileName))) {
|
||||
return;
|
||||
}
|
||||
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
|
||||
@@ -121,14 +121,14 @@ class DeclarationsWalker {
|
||||
}
|
||||
|
||||
function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {
|
||||
const options = { target: ts.ScriptTarget.ES5, declaration: true, noResolve: true, types: <string[]>[], stripInternal: true };
|
||||
const options = { target: ts.ScriptTarget.ES5, declaration: true, noResolve: false, types: <string[]>[], stripInternal: true };
|
||||
|
||||
/**
|
||||
* 1st pass - generate a program from protocol.ts and typescriptservices.d.ts and emit core version of protocol.d.ts with all internal members stripped
|
||||
* @return text of protocol.d.t.s
|
||||
*/
|
||||
function getInitialDtsFileForProtocol() {
|
||||
const program = ts.createProgram([protocolTs, typeScriptServicesDts], options);
|
||||
const program = ts.createProgram([protocolTs, typeScriptServicesDts, path.join(typeScriptServicesDts, "../lib.es5.d.ts")], options);
|
||||
|
||||
let protocolDts: string | undefined;
|
||||
const emitResult = program.emit(program.getSourceFile(protocolTs), (file, content) => {
|
||||
|
||||
@@ -60,7 +60,7 @@ function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
|
||||
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string, thisFilePathRel: string): string {
|
||||
let result =
|
||||
"// <auto-generated />\r\n" +
|
||||
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel + "'\r\n" +
|
||||
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel.replace(/\\/g, '/') + "'\r\n" +
|
||||
"/* @internal */\r\n" +
|
||||
"namespace ts {\r\n" +
|
||||
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}): DiagnosticMessage {\r\n" +
|
||||
@@ -119,4 +119,4 @@ function convertPropertyName(origName: string): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
100
scripts/produceLKG.ts
Normal file
100
scripts/produceLKG.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import childProcess = require('child_process');
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path');
|
||||
import removeInternal = require('remove-internal');
|
||||
import glob = require('glob');
|
||||
|
||||
const root = path.join(__dirname, "..");
|
||||
const source = path.join(root, "built/local");
|
||||
const dest = path.join(root, "lib");
|
||||
const copyright = fs.readFileSync(path.join(__dirname, "../CopyrightNotice.txt"), "utf-8");
|
||||
|
||||
async function produceLKG() {
|
||||
console.log(`Building LKG from ${source} to ${dest}`);
|
||||
await copyLibFiles();
|
||||
await copyLocalizedDiagnostics();
|
||||
await buildProtocol();
|
||||
await copyScriptOutputs();
|
||||
await buildTsc();
|
||||
await copyDeclarationOutputs();
|
||||
await writeGitAttributes();
|
||||
}
|
||||
|
||||
async function copyLibFiles() {
|
||||
await copyFilesWithGlob("lib?(.*).d.ts");
|
||||
}
|
||||
|
||||
async function copyLocalizedDiagnostics() {
|
||||
const dir = await fs.readdir(source);
|
||||
for (const d of dir) {
|
||||
const fileName = path.join(source, d);
|
||||
if (fs.statSync(fileName).isDirectory()) {
|
||||
if (d === 'tslint') continue;
|
||||
await fs.copy(fileName, path.join(dest, d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function buildProtocol() {
|
||||
const protocolScript = path.join(__dirname, "buildProtocol.js");
|
||||
if (!fs.existsSync(protocolScript)) {
|
||||
throw new Error(`Expected protocol script ${protocolScript} to exist`);
|
||||
}
|
||||
|
||||
const protocolInput = path.join(__dirname, "../src/server/protocol.ts");
|
||||
const protocolServices = path.join(source, "typescriptServices.d.ts");
|
||||
const protocolOutput = path.join(dest, "protocol.d.ts");
|
||||
|
||||
console.log(`Building ${protocolOutput}...`);
|
||||
await exec(protocolScript, [protocolInput, protocolServices, protocolOutput]);
|
||||
}
|
||||
|
||||
async function copyScriptOutputs() {
|
||||
await copyWithCopyright("tsserver.js");
|
||||
await copyWithCopyright("tsc.js");
|
||||
await copyWithCopyright("watchGuard.js");
|
||||
await copyWithCopyright("cancellationToken.js");
|
||||
await copyWithCopyright("typingsInstaller.js");
|
||||
}
|
||||
|
||||
async function buildTsc() {
|
||||
await exec(path.join(source, "tsc.js"), [`-b -f ${path.join(root, "src/tsc/tsconfig.release.json")}`]);
|
||||
}
|
||||
|
||||
async function copyDeclarationOutputs() {
|
||||
await copyWithCopyright("typescript.d.ts");
|
||||
await copyWithCopyright("typescriptServices.d.ts");
|
||||
await copyWithCopyright("tsserverlibrary.d.ts");
|
||||
}
|
||||
|
||||
async function writeGitAttributes() {
|
||||
await fs.writeFile(path.join(dest, ".gitattributes"), `* text eol=lf`, "utf-8");
|
||||
}
|
||||
|
||||
async function copyWithCopyright(fileName: string) {
|
||||
const content = await fs.readFile(path.join(source, fileName), "utf-8");
|
||||
await fs.writeFile(path.join(dest, fileName), copyright + "\r\n" + content);
|
||||
}
|
||||
|
||||
async function copyFromBuiltLocal(fileName: string) {
|
||||
await fs.copy(path.join(source, fileName), path.join(dest, fileName));
|
||||
}
|
||||
|
||||
async function copyFilesWithGlob(pattern: string) {
|
||||
const files = glob.sync(path.join(source, pattern)).map(f => path.basename(f));
|
||||
for (const f of files) {
|
||||
await copyFromBuiltLocal(f);
|
||||
}
|
||||
console.log(`Copied ${files.length} files matching pattern ${pattern}`);
|
||||
}
|
||||
|
||||
async function exec(path: string, args: string[] = []) {
|
||||
const cmdLine = ["node", path, ...args].join(" ");
|
||||
console.log(cmdLine);
|
||||
childProcess.execSync(cmdLine);
|
||||
}
|
||||
|
||||
process.on("unhandledRejection", err => { throw err; });
|
||||
produceLKG().then(() => console.log("Done"), err => { throw err; });
|
||||
20
scripts/tsconfig.json
Normal file
20
scripts/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"removeComments": false,
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"declaration": false,
|
||||
"lib": [
|
||||
"es6",
|
||||
"scripthost"
|
||||
],
|
||||
"types": ["node"]
|
||||
},
|
||||
"files": [
|
||||
"produceLKG.ts",
|
||||
"buildProtocol.ts",
|
||||
"processDiagnosticMessages.ts",
|
||||
"generateLocalizedDiagnosticMessages.ts",
|
||||
"configurePrerelease.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user