Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide private properties in public API baselines #58922

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions scripts/dtsBundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ assert(typeof entrypoint === "string" && entrypoint);
assert(typeof output === "string" && output);
assert(output.endsWith(dotDts));

const publicBaselineOutput = output.substring(0, output.length - dotDts.length) + ".baseline" + dotDts;
const internalOutput = output.substring(0, output.length - dotDts.length) + ".internal" + dotDts;

console.log(`Bundling ${entrypoint} to ${output} and ${internalOutput}`);
console.log(`Bundling ${entrypoint} to ${output}, ${publicBaselineOutput}, and ${internalOutput}`);

const newLineKind = ts.NewLineKind.LineFeed;
const newLine = newLineKind === ts.NewLineKind.LineFeed ? "\n" : "\r\n";
Expand Down Expand Up @@ -512,5 +513,7 @@ function dprint(contents) {
return result.replace(/\r\n/g, "\n");
}

fs.writeFileSync(output, dprint(publicContents));
const formattedPublicContents = dprint(publicContents);
fs.writeFileSync(output, formattedPublicContents);
fs.writeFileSync(publicBaselineOutput, formattedPublicContents.replace(/^\s+private .*\n/gm, ""));
fs.writeFileSync(internalOutput, dprint(internalContents));
12 changes: 6 additions & 6 deletions src/testRunner/unittests/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { libContent } from "./helpers/contents.js";
import { loadProjectFromFiles } from "./helpers/vfs.js";

describe("unittests:: Public APIs", () => {
function verifyApi(fileName: string) {
const builtFile = `built/local/${fileName}`;
const api = `api/${fileName}`;
function verifyApi(input: string, baseline: string) {
const builtFile = `built/local/${input}`;
const api = `api/${baseline}`;
let fileContent: string;
before(() => {
fileContent = Harness.IO.readFile(builtFile)!;
if (!fileContent) throw new Error(`File ${fileName} was not present in built/local`);
if (!fileContent) throw new Error(`File ${input} was not present in built/local`);
fileContent = fileContent.replace(/\r\n/g, "\n");
});

Expand All @@ -24,11 +24,11 @@ describe("unittests:: Public APIs", () => {
}

describe("for the language service and compiler", () => {
verifyApi("typescript.d.ts");
verifyApi("typescript.baseline.d.ts", "typescript.d.ts");
});

describe("for the language server", () => {
verifyApi("tsserverlibrary.d.ts");
verifyApi("tsserverlibrary.d.ts", "tsserverlibrary.d.ts");
});
});

Expand Down
Loading
Loading