Skip to content

Commit 7f7d0c6

Browse files
authored
Baseline public API (microsoft#18897)
* Add unit test which tracks public API changes * Accept strict function types updates * 100% Linefeeds, no carriage returns * How were these missing? * That would be why they were there * Extract and comment * Accept comment changes
1 parent a8b7f7d commit 7f7d0c6

File tree

8 files changed

+12222
-28
lines changed

8 files changed

+12222
-28
lines changed

CopyrightNotice.txt

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/*! *****************************************************************************
2-
Copyright (c) Microsoft Corporation. All rights reserved.
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4-
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
7-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
12-
See the Apache Version 2.0 License for specific language governing permissions
13-
and limitations under the License.
14-
***************************************************************************** */
15-
1+
/*! *****************************************************************************
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the
5+
License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10+
MERCHANTABLITY OR NON-INFRINGEMENT.
11+
12+
See the Apache Version 2.0 License for specific language governing permissions
13+
and limitations under the License.
14+
***************************************************************************** */
15+

Gulpfile.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ const gulp = helpMaker(originalGulp);
3434

3535
Error.stackTraceLimit = 1000;
3636

37+
/**
38+
* This regexp exists to capture our const enums and replace them with normal enums in our public API
39+
* - this is fine since we compile with preserveConstEnums, and ensures our consumers are not locked
40+
* to the TS version they compile with.
41+
*/
42+
const constEnumCaptureRegexp = /^(\s*)(export )?const enum (\S+) {(\s*)$/gm;
43+
const constEnumReplacement = "$1$2enum $3 {$4";
44+
3745
const cmdLineOptions = minimist(process.argv.slice(2), {
3846
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
3947
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
@@ -261,8 +269,8 @@ function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): ts
261269
}
262270
if (!useDebugMode) {
263271
if (copy.removeComments === undefined) copy.removeComments = true;
264-
copy.newLine = "lf";
265272
}
273+
copy.newLine = "lf";
266274
if (useBuiltCompiler === true) {
267275
copy.typescript = require("./built/local/typescript.js");
268276
}
@@ -432,7 +440,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
432440
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/ true))
433441
.pipe(insert.transform((contents, file) => {
434442
file.path = standaloneDefinitionsFile;
435-
return contents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4");
443+
return contents.replace(constEnumCaptureRegexp, constEnumReplacement);
436444
}));
437445
return merge2([
438446
completedJs,
@@ -442,7 +450,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
442450
completedDts.pipe(clone())
443451
.pipe(insert.transform((content, file) => {
444452
file.path = nodeDefinitionsFile;
445-
return content + "\r\nexport = ts;";
453+
return content + "\nexport = ts;";
446454
}))
447455
.pipe(gulp.dest("src/services")),
448456
completedDts.pipe(clone())
@@ -509,7 +517,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile, typesMapJson], (do
509517
.pipe(gulp.dest("src/server")),
510518
dts.pipe(prependCopyright(/*outputCopyright*/ true))
511519
.pipe(insert.transform((content) => {
512-
return content + "\r\nexport = ts;\r\nexport as namespace ts;";
520+
return content.replace(constEnumCaptureRegexp, constEnumReplacement) + "\nexport = ts;\nexport as namespace ts;";
513521
}))
514522
.pipe(gulp.dest("src/server"))
515523
]);
@@ -588,7 +596,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
588596

589597
// Task to build the tests infrastructure using the built compiler
590598
const run = path.join(builtLocalDirectory, "run.js");
591-
gulp.task(run, /*help*/ false, [servicesFile], () => {
599+
gulp.task(run, /*help*/ false, [servicesFile, tsserverLibraryFile], () => {
592600
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
593601
return testProject.src()
594602
.pipe(newer(run))

Jakefile.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ var harnessSources = harnessCoreSources.concat([
151151
"programMissingFiles.ts",
152152
"symbolWalker.ts",
153153
"languageService.ts",
154+
"publicApi.ts",
154155
].map(function (f) {
155156
return path.join(unittestsDirectory, f);
156157
})).concat([
@@ -341,9 +342,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
341342
options += " -sourcemap";
342343
}
343344
}
344-
else {
345-
options += " --newLine LF";
346-
}
345+
options += " --newLine LF";
347346

348347
if (opts.stripInternal) {
349348
options += " --stripInternal";
@@ -608,7 +607,7 @@ compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].conc
608607

609608
// Official node package definition file, pointed to by 'typings' in package.json
610609
// Created by appending 'export = ts;' at the end of the standalone file to turn it into an external module
611-
var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;";
610+
var nodeDefinitionsFileContents = definitionFileContents + "\nexport = ts;";
612611
fs.writeFileSync(nodeDefinitionsFile, nodeDefinitionsFileContents);
613612

614613
// Node package definition file to be distributed without the package. Created by replacing
@@ -655,8 +654,8 @@ compileFile(
655654
// Appending exports at the end of the server library
656655
var tsserverLibraryDefinitionFileContents =
657656
fs.readFileSync(tsserverLibraryDefinitionFile).toString() +
658-
"\r\nexport = ts;" +
659-
"\r\nexport as namespace ts;";
657+
"\nexport = ts;" +
658+
"\nexport as namespace ts;";
660659
tsserverLibraryDefinitionFileContents = removeConstModifierFromEnumDeclarations(tsserverLibraryDefinitionFileContents);
661660

662661
fs.writeFileSync(tsserverLibraryDefinitionFile, tsserverLibraryDefinitionFileContents);
@@ -763,7 +762,7 @@ var run = path.join(builtLocalDirectory, "run.js");
763762
compileFile(
764763
/*outFile*/ run,
765764
/*source*/ harnessSources,
766-
/*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
765+
/*prereqs*/[builtLocalDirectory, tscFile, tsserverLibraryFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
767766
/*prefixes*/[],
768767
/*useBuiltCompiler:*/ true,
769768
/*opts*/ { types: ["node", "mocha", "chai"], lib: "es6" });

src/harness/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"./unittests/textChanges.ts",
136136
"./unittests/telemetry.ts",
137137
"./unittests/languageService.ts",
138-
"./unittests/programMissingFiles.ts"
138+
"./unittests/programMissingFiles.ts",
139+
"./unittests/publicApi.ts"
139140
]
140141
}

src/harness/unittests/publicApi.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="../harness.ts" />
2+
3+
describe("Public APIs", () => {
4+
it("for the language service and compiler should be acknowledged when they change", () => {
5+
Harness.Baseline.runBaseline("api/typescript.d.ts", () => Harness.IO.readFile("built/local/typescript.d.ts"));
6+
});
7+
it("for the language server should be acknowledged when they change", () => {
8+
Harness.Baseline.runBaseline("api/tsserverlibrary.d.ts", () => Harness.IO.readFile("built/local/tsserverlibrary.d.ts"));
9+
});
10+
});

src/tsconfig-base.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"stripInternal": true,
1313
"sourceMap": true,
1414
"target": "es5",
15+
"newLine": "lf",
1516
"types": []
1617
}
1718
}

0 commit comments

Comments
 (0)