Skip to content

Make tsserver.js a library #39291

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

Closed
wants to merge 5 commits into from
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
4 changes: 2 additions & 2 deletions .github/workflows/new-release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserver.d.ts
sed -i -e 's/const version = `${versionMajorMinor}.0-.*`/const version = `${versionMajorMinor}.0-${{ github.event.client_payload.core_tag || 'dev' }}`/g' src/compiler/corePublic.ts
npm install
gulp LKG
Expand All @@ -30,7 +30,7 @@ jobs:
git add package.json
git add src/compiler/corePublic.ts
git add tests/baselines/reference/api/typescript.d.ts
git add tests/baselines/reference/api/tsserverlibrary.d.ts
git add tests/baselines/reference/api/tsserver.d.ts
git add ./lib
git config user.email "[email protected]"
git config user.name "TypeScript Bot"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/set-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserver.d.ts
sed -i -e 's/const version = .*;/const version = "${{ github.event.client_payload.package_version }}" as string;/g' src/compiler/corePublic.ts
npm install
gulp LKG
Expand All @@ -36,7 +36,7 @@ jobs:
git add package.json
git add src/compiler/corePublic.ts
git add tests/baselines/reference/api/typescript.d.ts
git add tests/baselines/reference/api/tsserverlibrary.d.ts
git add tests/baselines/reference/api/tsserver.d.ts
git add ./lib
git config user.email "[email protected]"
git config user.name "TypeScript Bot"
Expand Down
130 changes: 51 additions & 79 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,55 @@ task("watch-services").flags = {
" --built": "Compile using the built version of the compiler."
};

const buildServer = () => buildProject("src/tsserver", cmdLineOptions);
const buildServer = (() => {
// build tsserver.out.js
const buildServerOut = () => buildProject("src/tsserver/tsconfig.json", cmdLineOptions);

// create tsserver.js
const createServerJs = () => src("built/local/tsserver.out.js")
.pipe(newer("built/local/tsserver.js"))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(prependFile(copyright))
.pipe(rename("tsserver.js"))
.pipe(sourcemaps.write(".", { includeContent: false, destPath: "built/local" }))
.pipe(dest("built/local"));

// create tsserver.d.ts
const createServerDts = () => src("built/local/tsserver.out.d.ts")
.pipe(newer("built/local/tsserver.d.ts"))
.pipe(prependFile(copyright))
.pipe(transform(content => content.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4")))
.pipe(append("\nexport = ts;\nexport as namespace ts;"))
.pipe(rename("tsserver.d.ts"))
.pipe(dest("built/local"));

return series(
buildServerOut,
createServerJs,
createServerDts,
);
})();
task("tsserver", series(preBuild, buildServer));
task("tsserver").description = "Builds the language server";
task("tsserver").flags = {
" --built": "Compile using the built version of the compiler."
};

const cleanServer = () => cleanProject("src/tsserver");
const cleanServer = async () => {
await cleanProject("src/tsserver");
if (fs.existsSync("built/local/tsserver.tsconfig.json")) {
await cleanProject("built/local/tsserver.tsconfig.json");
}
await del([
"built/local/tsserver.out.js",
"built/local/tsserver.out.js.map",
"built/local/tsserver.out.d.ts",
"built/local/tsserver.out.tsbuildinfo",
"built/local/tsserver.js",
"built/local/tsserver.js.map",
"built/local/tsserver.d.ts",
]);
};
cleanTasks.push(cleanServer);
task("clean-tsserver", cleanServer);
task("clean-tsserver").description = "Cleans outputs for the language server";
Expand All @@ -249,76 +290,8 @@ task("watch-min").flags = {
" --built": "Compile using the built version of the compiler."
};

const buildLssl = (() => {
// build tsserverlibrary.out.js
const buildServerLibraryOut = () => buildProject("src/tsserverlibrary/tsconfig.json", cmdLineOptions);

// create tsserverlibrary.js
const createServerLibraryJs = () => src("built/local/tsserverlibrary.out.js")
.pipe(newer("built/local/tsserverlibrary.js"))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(prependFile(copyright))
.pipe(rename("tsserverlibrary.js"))
.pipe(sourcemaps.write(".", { includeContent: false, destPath: "built/local" }))
.pipe(dest("built/local"));

// create tsserverlibrary.d.ts
const createServerLibraryDts = () => src("built/local/tsserverlibrary.out.d.ts")
.pipe(newer("built/local/tsserverlibrary.d.ts"))
.pipe(prependFile(copyright))
.pipe(transform(content => content.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4")))
.pipe(append("\nexport = ts;\nexport as namespace ts;"))
.pipe(rename("tsserverlibrary.d.ts"))
.pipe(dest("built/local"));

return series(
buildServerLibraryOut,
createServerLibraryJs,
createServerLibraryDts,
);
})();
task("lssl", series(preBuild, buildLssl));
task("lssl").description = "Builds language service server library";
task("lssl").flags = {
" --built": "Compile using the built version of the compiler."
};

const cleanLssl = async () => {
if (fs.existsSync("built/local/tsserverlibrary.tsconfig.json")) {
await cleanProject("built/local/tsserverlibrary.tsconfig.json");
}
await del([
"built/local/tsserverlibrary.out.js",
"built/local/tsserverlibrary.out.d.ts",
"built/local/tsserverlibrary.out.tsbuildinfo",
"built/local/tsserverlibrary.js",
"built/local/tsserverlibrary.d.ts",
]);
};
cleanTasks.push(cleanLssl);
task("clean-lssl", cleanLssl);
task("clean-lssl").description = "Clean outputs for the language service server library";

const watchLssl = () => watch([
"src/compiler/tsconfig.json",
"src/compiler/**/*.ts",
"src/jsTyping/tsconfig.json",
"src/jsTyping/**/*.ts",
"src/services/tsconfig.json",
"src/services/**/*.ts",
"src/server/tsconfig.json",
"src/server/**/*.ts",
"src/tsserver/tsconfig.json",
"src/tsserver/**/*.ts",
], buildLssl);
task("watch-lssl", series(preBuild, parallel(watchLib, watchDiagnostics, watchLssl)));
task("watch-lssl").description = "Watch for changes and rebuild tsserverlibrary only";
task("watch-lssl").flags = {
" --built": "Compile using the built version of the compiler."
};

const buildTests = () => buildProject("src/testRunner");
task("tests", series(preBuild, parallel(buildLssl, buildTests)));
task("tests", series(preBuild, parallel(buildServer, buildTests)));
task("tests").description = "Builds the test infrastructure";
task("tests").flags = {
" --built": "Compile using the built version of the compiler."
Expand Down Expand Up @@ -428,13 +401,13 @@ task("other-outputs").description = "Builds miscelaneous scripts and documents d

const buildFoldStart = async () => { if (fold.isTravis()) console.log(fold.start("build")); };
const buildFoldEnd = async () => { if (fold.isTravis()) console.log(fold.end("build")); };
task("local", series(buildFoldStart, preBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs), buildFoldEnd));
task("local", series(buildFoldStart, preBuild, parallel(localize, buildTsc, buildServer, buildServices, buildOtherOutputs), buildFoldEnd));
task("local").description = "Builds the full compiler and services";
task("local").flags = {
" --built": "Compile using the built version of the compiler."
};

task("watch-local", series(preBuild, parallel(watchLib, watchDiagnostics, watchTsc, watchServices, watchServer, watchLssl)));
task("watch-local", series(preBuild, parallel(watchLib, watchDiagnostics, watchTsc, watchServices, watchServer)));
task("watch-local").description = "Watches for changes to projects in src/ (but does not execute tests).";
task("watch-local").flags = {
" --built": "Compile using the built version of the compiler."
Expand All @@ -444,7 +417,7 @@ const generateCodeCoverage = () => exec("istanbul", ["cover", "node_modules/moch
task("generate-code-coverage", series(preBuild, buildTests, generateCodeCoverage));
task("generate-code-coverage").description = "Generates code coverage data via istanbul";

const preTest = parallel(buildTsc, buildTests, buildServices, buildLssl);
const preTest = parallel(buildTsc, buildTests, buildServices, buildServer);
preTest.displayName = "preTest";

const postTest = (done) => cmdLineOptions.lint ? lint(done) : done();
Expand Down Expand Up @@ -529,7 +502,7 @@ const cleanInstrumenter = () => cleanProject("src/instrumenter");
cleanTasks.push(cleanInstrumenter);

const tscInstrumented = () => exec(process.execPath, ["built/local/instrumenter.js", "record", cmdLineOptions.tests || "iocapture", "built/local"]);
task("tsc-instrumented", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildLoggedIO, buildInstrumenter), tscInstrumented));
task("tsc-instrumented", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLoggedIO, buildInstrumenter), tscInstrumented));
task("tsc-instrumented").description = "Builds an instrumented tsc.js";
task("tsc-instrumented").flags = {
"-t --tests=<testname>": "The test to run."
Expand Down Expand Up @@ -563,10 +536,9 @@ const produceLKG = async () => {
"built/local/typescriptServices.js",
"built/local/typescriptServices.d.ts",
"built/local/tsserver.js",
"built/local/tsserver.d.ts",
"built/local/typescript.js",
"built/local/typescript.d.ts",
"built/local/tsserverlibrary.js",
"built/local/tsserverlibrary.d.ts",
"built/local/typingsInstaller.js",
"built/local/cancellationToken.js"
].concat(libs.map(lib => lib.target));
Expand All @@ -584,7 +556,7 @@ const produceLKG = async () => {
}
};

task("LKG", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs, buildReleaseTsc), produceLKG));
task("LKG", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildOtherOutputs, buildReleaseTsc), produceLKG));
task("LKG").description = "Makes a new LKG out of the built js files";
task("LKG").flags = {
" --built": "Compile using the built version of the compiler.",
Expand Down Expand Up @@ -630,7 +602,7 @@ const watchRuntests = () => watch(["built/local/*.js", "tests/cases/**/*.ts", "t
await runConsoleTests("built/local/run.js", "min", /*runInParallel*/ true, /*watchMode*/ true);
}
});
task("watch", series(preBuild, preTest, parallel(watchLib, watchDiagnostics, watchServices, watchLssl, watchTests, watchRuntests)));
task("watch", series(preBuild, preTest, parallel(watchLib, watchDiagnostics, watchServices, watchServer, watchTests, watchRuntests)));
task("watch").description = "Watches for changes and rebuilds and runs tests in parallel.";
task("watch").flags = {
"-t --tests=<regex>": "Pattern for tests to run. Forces tests to be run in a single worker.",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
// finally, do a sanity check and build the compiler with the built version of itself
log.info("Starting sanity check build...");
// Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"], { cancelToken });
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-tests"], { cancelToken });
const { exitCode } = await exec("gulp", ["local", "--lkg=false"], { cancelToken });
if (exitCode !== 0) {
errorStatus = exitCode;
Expand Down
3 changes: 1 addition & 2 deletions scripts/configureLanguageServiceBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ function main(): void {
const toRemove = [
// JS Files
"tsserver.js",
"tsserverlibrary.js",
"typescriptServices.js",
"typingsInstaller.js",
"tsc.js",
// DTS files
"typescriptServices.d.ts",
"tsserverlibrary.d.ts"
"tsserver.d.ts"
];

// Get a link to the main dependency JS file
Expand Down
5 changes: 2 additions & 3 deletions scripts/produceLKG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ async function buildProtocol() {
async function copyScriptOutputs() {
await copyWithCopyright("cancellationToken.js");
await copyWithCopyright("tsc.release.js", "tsc.js");
await copyWithCopyright("tsserver.js");
await copyFromBuiltLocal("tsserverlibrary.js"); // copyright added by build
await copyFromBuiltLocal("tsserver.js"); // copyright added by build
await copyFromBuiltLocal("typescript.js"); // copyright added by build
await copyFromBuiltLocal("typescriptServices.js"); // copyright added by build
await copyWithCopyright("typingsInstaller.js");
await copyWithCopyright("watchGuard.js");
}

async function copyDeclarationOutputs() {
await copyFromBuiltLocal("tsserverlibrary.d.ts"); // copyright added by build
await copyFromBuiltLocal("tsserver.d.ts"); // copyright added by build
await copyFromBuiltLocal("typescript.d.ts"); // copyright added by build
await copyFromBuiltLocal("typescriptServices.d.ts"); // copyright added by build
}
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("unittests:: Public APIs", () => {
});

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

Expand Down
Loading