Skip to content

Commit 3c6c557

Browse files
authored
Move tsserverlibrary.js to typescript.js, make tsserverlibrary.js a shim (#55273)
1 parent fd390e7 commit 3c6c557

File tree

12 files changed

+4105
-11401
lines changed

12 files changed

+4105
-11401
lines changed

Herebyfile.mjs

+37-14
Original file line numberDiff line numberDiff line change
@@ -404,27 +404,50 @@ export const watchMin = task({
404404

405405

406406

407-
const { main: lssl, build: buildLssl, watch: watchLssl } = entrypointBuildTask({
407+
// This is technically not enough to make tsserverlibrary loadable in the
408+
// browser, but it's unlikely that anyone has actually been doing that.
409+
const lsslJs = `
410+
if (typeof module !== "undefined" && module.exports) {
411+
module.exports = require("./typescript.js");
412+
}
413+
else {
414+
throw new Error("tsserverlibrary requires CommonJS; use typescript.js instead");
415+
}
416+
`;
417+
418+
const lsslDts = `
419+
import ts = require("./typescript.js");
420+
export = ts;
421+
`;
422+
423+
const lsslDtsInternal = `
424+
import ts = require("./typescript.internal.js");
425+
export = ts;
426+
`;
427+
428+
/**
429+
* @param {string} contents
430+
*/
431+
async function fileContentsWithCopyright(contents) {
432+
return await copyright() + contents.trim().replace(/\r\n/g, "\n") + "\n";
433+
}
434+
435+
const lssl = task({
408436
name: "lssl",
409437
description: "Builds language service server library",
410-
buildDeps: [generateDiagnostics],
411-
project: "src/tsserverlibrary",
412-
srcEntrypoint: "./src/tsserverlibrary/tsserverlibrary.ts",
413-
builtEntrypoint: "./built/local/tsserverlibrary/tsserverlibrary.js",
414-
output: "./built/local/tsserverlibrary.js",
415-
mainDeps: [generateLibs],
416-
bundlerOptions: { exportIsTsObject: true },
438+
dependencies: [services],
439+
run: async () => {
440+
await fs.promises.writeFile("./built/local/tsserverlibrary.js", await fileContentsWithCopyright(lsslJs));
441+
}
417442
});
418-
export { lssl, watchLssl };
419443

420444
export const dtsLssl = task({
421445
name: "dts-lssl",
422446
description: "Bundles tsserverlibrary.d.ts",
423-
dependencies: [buildLssl],
447+
dependencies: [dtsServices],
424448
run: async () => {
425-
if (needsUpdate("./built/local/tsserverlibrary/tsconfig.tsbuildinfo", ["./built/local/tsserverlibrary.d.ts", "./built/local/tsserverlibrary.internal.d.ts"])) {
426-
await runDtsBundler("./built/local/tsserverlibrary/tsserverlibrary.d.ts", "./built/local/tsserverlibrary.d.ts");
427-
}
449+
await fs.promises.writeFile("./built/local/tsserverlibrary.d.ts", await fileContentsWithCopyright(lsslDts));
450+
await fs.promises.writeFile("./built/local/tsserverlibrary.internal.d.ts", await fileContentsWithCopyright(lsslDtsInternal));
428451
}
429452
});
430453

@@ -563,7 +586,7 @@ export const watchLocal = task({
563586
name: "watch-local",
564587
description: "Watches the full compiler and services",
565588
hiddenFromTaskList: true,
566-
dependencies: [localize, watchTsc, watchTsserver, watchServices, watchLssl, watchOtherOutputs, dts, watchSrc],
589+
dependencies: [localize, watchTsc, watchTsserver, watchServices, lssl, watchOtherOutputs, dts, watchSrc],
567590
});
568591

569592
const runtestsDeps = [tests, generateLibs].concat(cmdLineOptions.typecheck ? [dts] : []);

src/testRunner/unittests/publicApi.ts

-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as compiler from "../_namespaces/compiler";
21
import * as documents from "../_namespaces/documents";
32
import * as fakes from "../_namespaces/fakes";
43
import * as Harness from "../_namespaces/Harness";
@@ -19,21 +18,6 @@ describe("unittests:: Public APIs", () => {
1918
it("should be acknowledged when they change", () => {
2019
Harness.Baseline.runBaseline(api, fileContent, { PrintDiff: true });
2120
});
22-
23-
it("should compile", () => {
24-
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
25-
fs.linkSync(`${vfs.builtFolder}/${fileName}`, `${vfs.srcFolder}/${fileName}`);
26-
const sys = new fakes.System(fs);
27-
const options: ts.CompilerOptions = {
28-
...ts.getDefaultCompilerOptions(),
29-
strict: true,
30-
exactOptionalPropertyTypes: true,
31-
lib: ["lib.es2018.d.ts"],
32-
};
33-
const host = new fakes.CompilerHost(sys, options);
34-
const result = compiler.compileFiles(host, [`${vfs.srcFolder}/${fileName}`], options);
35-
assert(!result.diagnostics || !result.diagnostics.length, Harness.Compiler.minimalDiagnosticsToString(result.diagnostics, /*pretty*/ true));
36-
});
3721
}
3822

3923
describe("for the language service and compiler", () => {

src/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
{ "path": "./testRunner" },
1414
{ "path": "./tsc" },
1515
{ "path": "./tsserver" },
16-
{ "path": "./tsserverlibrary" },
1716
{ "path": "./typescript" },
1817
{ "path": "./typingsInstaller" },
1918
{ "path": "./typingsInstallerCore" },

src/tsserverlibrary/_namespaces/ts.ts

-8
This file was deleted.

src/tsserverlibrary/tsconfig.json

-12
This file was deleted.

src/tsserverlibrary/tsserverlibrary.ts

-3
This file was deleted.

src/typescript/_namespaces/ts.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
export * from "../../compiler/_namespaces/ts";
44
export * from "../../jsTyping/_namespaces/ts";
55
export * from "../../services/_namespaces/ts";
6-
export * from "../../deprecatedCompat/_namespaces/ts";
6+
export * from "../../server/_namespaces/ts";
7+
import * as server from "./ts.server";
8+
export { server };

src/typescript/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{ "path": "../compiler" },
77
{ "path": "../jsTyping" },
88
{ "path": "../services" },
9-
{ "path": "../deprecatedCompat" }
9+
{ "path": "../server" }
1010
],
1111
"include": ["**/*"]
1212
}

tests/baselines/reference/APILibCheck.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import tsInternal = require("typescript-internal");
88
>tsInternal : typeof tsInternal
99

1010
import tsserverlibrary = require("tsserverlibrary");
11-
>tsserverlibrary : typeof tsserverlibrary
11+
>tsserverlibrary : typeof ts
1212

1313
import tsserverlibraryInternal = require("tsserverlibrary-internal");
14-
>tsserverlibraryInternal : typeof tsserverlibraryInternal
14+
>tsserverlibraryInternal : typeof tsInternal
1515

0 commit comments

Comments
 (0)