mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
This adds a "small" d.ts bundler script. This script is very basic, using Node printing to produce its output. Generally speaking, this is inadvisable as it completely disregards name shadowing, globals, etc. However, in our case, we don't care about the globals, and we can opt to restructure our codebase in order to avoid conflict, which we largely had to do anyway when we were namespaces and everything was in scope.
87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
import fs from "fs-extra";
|
|
import path from "path";
|
|
import glob from "glob";
|
|
import url from "url";
|
|
import del from "del";
|
|
import { localizationDirectories } from "./build/localization.mjs";
|
|
|
|
const __filename = url.fileURLToPath(new URL(import.meta.url));
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const root = path.join(__dirname, "..");
|
|
const source = path.join(root, "built/local");
|
|
const dest = path.join(root, "lib");
|
|
|
|
async function produceLKG() {
|
|
console.log(`Building LKG from ${source} to ${dest}`);
|
|
await del(`${dest.replace(/\\/g, "/")}/**`, { ignore: ["**/README.md"] });
|
|
await fs.mkdirp(dest);
|
|
await copyLibFiles();
|
|
await copyLocalizedDiagnostics();
|
|
await copyTypesMap();
|
|
await copyScriptOutputs();
|
|
await copyDeclarationOutputs();
|
|
await writeGitAttributes();
|
|
}
|
|
|
|
async function copyLibFiles() {
|
|
await copyFilesWithGlob("lib?(.*).d.ts");
|
|
}
|
|
|
|
async function copyLocalizedDiagnostics() {
|
|
for (const d of localizationDirectories) {
|
|
const fileName = path.join(source, d);
|
|
if (fs.statSync(fileName).isDirectory()) {
|
|
await fs.copy(fileName, path.join(dest, d));
|
|
}
|
|
}
|
|
}
|
|
|
|
async function copyTypesMap() {
|
|
await copyFromBuiltLocal("typesMap.json"); // Cannot accommodate copyright header
|
|
}
|
|
|
|
async function copyScriptOutputs() {
|
|
await copyFromBuiltLocal("cancellationToken.js");
|
|
await copyFromBuiltLocal("tsc.js");
|
|
await copyFromBuiltLocal("tsserver.js");
|
|
await copyFromBuiltLocal("tsserverlibrary.js");
|
|
await copyFromBuiltLocal("typescript.js");
|
|
await copyFromBuiltLocal("typingsInstaller.js");
|
|
await copyFromBuiltLocal("watchGuard.js");
|
|
}
|
|
|
|
async function copyDeclarationOutputs() {
|
|
await copyFromBuiltLocal("tsserverlibrary.d.ts");
|
|
await copyFromBuiltLocal("typescript.d.ts");
|
|
}
|
|
|
|
async function writeGitAttributes() {
|
|
await fs.writeFile(path.join(dest, ".gitattributes"), `* text eol=lf`, "utf-8");
|
|
}
|
|
|
|
/**
|
|
* @param {string} fileName
|
|
*/
|
|
async function copyFromBuiltLocal(fileName) {
|
|
await fs.copy(path.join(source, fileName), path.join(dest, fileName));
|
|
}
|
|
|
|
/**
|
|
* @param {string} pattern
|
|
*/
|
|
async function copyFilesWithGlob(pattern) {
|
|
const files = glob.sync(pattern, { cwd: source }).map(f => path.basename(f));
|
|
for (const f of files) {
|
|
await copyFromBuiltLocal(f);
|
|
}
|
|
console.log(`Copied ${files.length} files matching pattern ${pattern}`);
|
|
}
|
|
|
|
process.on("unhandledRejection", err => {
|
|
throw err;
|
|
});
|
|
produceLKG().then(() => console.log("Done"), err => {
|
|
throw err;
|
|
});
|