Skip to content

Commit 93228cf

Browse files
committed
Rename the smaller build to '@typescript/language-services' and have a separate build step for creating and publishing vs configuring the build
1 parent 31c08b6 commit 93228cf

6 files changed

+158
-111
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ scripts/buildProtocol.js
4545
scripts/ior.js
4646
scripts/authors.js
4747
scripts/configurePrerelease.js
48-
scripts/configureTSCBuild.js
48+
scripts/configureLanguageServiceBuild.js
49+
scripts/createLanguageServiceBuild.js
4950
scripts/open-user-pr.js
5051
scripts/open-cherry-pick-pr.js
5152
scripts/processDiagnosticMessages.d.ts

Gulpfile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ const configureExperimental = () => exec(process.execPath, ["scripts/configurePr
588588
task("configure-experimental", series(buildScripts, configureExperimental));
589589
task("configure-experimental").description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing";
590590

591-
const configureTSCOnly = () => exec(process.execPath, ["scripts/configureTSCBuild.js", "package.json", "src/compiler/core.ts"]);
592-
task("configure-tsc-only", series(buildScripts, configureNightly));
593-
task("configure-tsc-only").description = "Runs scripts/configureTSCOnly.ts to prepare a build for build which only has tsc ";
591+
const createLanguageServicesBuild = () => exec(process.execPath, ["scripts/createLanguageServicesBuild.js"]);
592+
task("create-language-services-build", series(buildScripts, createLanguageServicesBuild));
593+
task("create-language-services-build").description = "Runs scripts/createLanguageServicesBuild.ts to prepare a build which only has the require('typescript') JS.";
594594

595595
const publishNightly = () => exec("npm", ["publish", "--tag", "next"]);
596596
task("publish-nightly", series(task("clean"), task("LKG"), task("clean"), task("runtests-parallel"), publishNightly));

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"scripts": {
105105
"prepare": "gulp build-eslint-rules",
106106
"pretest": "gulp tests",
107-
"postpublish": "gulp configure-tsc-only",
107+
"postpublish": "gulp create-language-services-build",
108108
"test": "gulp runtests-parallel --light=false",
109109
"test:eslint-rules": "gulp run-eslint-rules-tests",
110110
"build": "npm run build:compiler && npm run build:tests",

scripts/configureTSCBuild.ts scripts/configureLanguageServiceBuild.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function main(): void {
3737
delete packageJsonValue.scripts.postpublish;
3838

3939
// Set the new name
40-
packageJsonValue.name = "@orta/language-services";
40+
packageJsonValue.name = "@typescript/language-services";
4141

4242
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4));
4343

@@ -74,10 +74,10 @@ function main(): void {
7474

7575
// This section verifies that the build of TypeScript compiles and emits
7676

77-
const ts = require("../" + lib);
77+
const ts = require(lib);
7878
const source = "let x: string = 'string'";
7979

80-
const results =ts.transpileModule(source, {
80+
const results = ts.transpileModule(source, {
8181
compilerOptions: { module: ts.ModuleKind.CommonJS }
8282
});
8383

scripts/costly-tests.js

+103-103
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
// @ts-check
2-
const fs = require("fs");
3-
const git = require('simple-git/promise')('.')
4-
const readline = require('readline')
5-
6-
/** @typedef {{ [s: string]: number}} Histogram */
7-
8-
async function main() {
9-
/** @type {Histogram} */
10-
const edits = Object.create(null)
11-
/** @type {Histogram} */
12-
const perf = JSON.parse(fs.readFileSync('.parallelperf.json', 'utf8'))
13-
14-
await collectCommits(git, "release-2.3", "master", /*author*/ undefined, files => fillMap(files, edits))
15-
16-
const totalTime = Object.values(perf).reduce((n,m) => n + m, 0)
17-
const untouched = Object.values(perf).length - Object.values(edits).length
18-
const totalEdits = Object.values(edits).reduce((n,m) => n + m, 0) + untouched + Object.values(edits).length
19-
20-
let i = 0
21-
/** @type {{ name: string, time: number, edits: number, cost: number }[]} */
22-
let data = []
23-
for (const k in perf) {
24-
const otherk = k.replace(/tsrunner-[a-z-]+?:\/\//, '')
25-
const percentTime = perf[k] / totalTime
26-
const percentHits = (1 + (edits[otherk] || 0)) / totalEdits
27-
const cost = 5 + Math.log(percentTime / percentHits)
28-
data.push({ name: otherk, time: perf[k], edits: 1 + (edits[otherk] || 0), cost})
29-
if (edits[otherk])
30-
i++
31-
}
32-
const output = {
33-
totalTime,
34-
totalEdits,
35-
data: data.sort((x,y) => y.cost - x.cost).map(x => ({ ...x, cost: x.cost.toFixed(2) }))
36-
}
37-
38-
fs.writeFileSync('tests/.test-cost.json', JSON.stringify(output), 'utf8')
39-
}
40-
41-
main().catch(e => {
42-
console.log(e);
43-
process.exit(1);
44-
})
45-
46-
/**
47-
* @param {string[]} files
48-
* @param {Histogram} histogram
49-
*/
50-
function fillMap(files, histogram) {
51-
// keep edits to test cases (but not /users), and not file moves
52-
const tests = files.filter(f => f.startsWith('tests/cases/') && !f.startsWith('tests/cases/user') && !/=>/.test(f))
53-
for (const test of tests) {
54-
histogram[test] = (histogram[test] || 0) + 1
55-
}
56-
}
57-
58-
/**
59-
* @param {string} s
60-
*/
61-
function isSquashMergeMessage(s) {
62-
return /\(#[0-9]+\)$/.test(s)
63-
}
64-
65-
/**
66-
* @param {string} s
67-
*/
68-
function isMergeCommit(s) {
69-
return /Merge pull request #[0-9]+/.test(s)
70-
}
71-
72-
/**
73-
* @param {string} s
74-
*/
75-
function parseFiles(s) {
76-
const lines = s.split('\n')
77-
// Note that slice(2) only works for merge commits, which have an empty newline after the title
78-
return lines.slice(2, lines.length - 2).map(line => line.split("|")[0].trim())
79-
}
80-
81-
/**
82-
* @param {import('simple-git/promise').SimpleGit} git
83-
* @param {string} from
84-
* @param {string} to
85-
* @param {string | undefined} author - only include commits from this author
86-
* @param {(files: string[]) => void} update
87-
*/
88-
async function collectCommits(git, from, to, author, update) {
89-
let i = 0
90-
for (const commit of (await git.log({ from, to })).all) {
91-
i++
92-
if ((!author || commit.author_name === author) && isMergeCommit(commit.message) || isSquashMergeMessage(commit.message)) {
93-
readline.clearLine(process.stdout, /*left*/ -1)
94-
readline.cursorTo(process.stdout, 0)
95-
process.stdout.write(i + ": " + commit.date)
96-
const files = parseFiles(await git.show([commit.hash, "--stat=1000,960,40", "--pretty=oneline"]))
97-
update(files)
98-
}
99-
}
100-
}
101-
102-
103-
1+
// @ts-check
2+
const fs = require("fs");
3+
const git = require('simple-git/promise')('.')
4+
const readline = require('readline')
5+
6+
/** @typedef {{ [s: string]: number}} Histogram */
7+
8+
async function main() {
9+
/** @type {Histogram} */
10+
const edits = Object.create(null)
11+
/** @type {Histogram} */
12+
const perf = JSON.parse(fs.readFileSync('.parallelperf.json', 'utf8'))
13+
14+
await collectCommits(git, "release-2.3", "master", /*author*/ undefined, files => fillMap(files, edits))
15+
16+
const totalTime = Object.values(perf).reduce((n,m) => n + m, 0)
17+
const untouched = Object.values(perf).length - Object.values(edits).length
18+
const totalEdits = Object.values(edits).reduce((n,m) => n + m, 0) + untouched + Object.values(edits).length
19+
20+
let i = 0
21+
/** @type {{ name: string, time: number, edits: number, cost: number }[]} */
22+
let data = []
23+
for (const k in perf) {
24+
const otherk = k.replace(/tsrunner-[a-z-]+?:\/\//, '')
25+
const percentTime = perf[k] / totalTime
26+
const percentHits = (1 + (edits[otherk] || 0)) / totalEdits
27+
const cost = 5 + Math.log(percentTime / percentHits)
28+
data.push({ name: otherk, time: perf[k], edits: 1 + (edits[otherk] || 0), cost})
29+
if (edits[otherk])
30+
i++
31+
}
32+
const output = {
33+
totalTime,
34+
totalEdits,
35+
data: data.sort((x,y) => y.cost - x.cost).map(x => ({ ...x, cost: x.cost.toFixed(2) }))
36+
}
37+
38+
fs.writeFileSync('tests/.test-cost.json', JSON.stringify(output), 'utf8')
39+
}
40+
41+
main().catch(e => {
42+
console.log(e);
43+
process.exit(1);
44+
})
45+
46+
/**
47+
* @param {string[]} files
48+
* @param {Histogram} histogram
49+
*/
50+
function fillMap(files, histogram) {
51+
// keep edits to test cases (but not /users), and not file moves
52+
const tests = files.filter(f => f.startsWith('tests/cases/') && !f.startsWith('tests/cases/user') && !/=>/.test(f))
53+
for (const test of tests) {
54+
histogram[test] = (histogram[test] || 0) + 1
55+
}
56+
}
57+
58+
/**
59+
* @param {string} s
60+
*/
61+
function isSquashMergeMessage(s) {
62+
return /\(#[0-9]+\)$/.test(s)
63+
}
64+
65+
/**
66+
* @param {string} s
67+
*/
68+
function isMergeCommit(s) {
69+
return /Merge pull request #[0-9]+/.test(s)
70+
}
71+
72+
/**
73+
* @param {string} s
74+
*/
75+
function parseFiles(s) {
76+
const lines = s.split('\n')
77+
// Note that slice(2) only works for merge commits, which have an empty newline after the title
78+
return lines.slice(2, lines.length - 2).map(line => line.split("|")[0].trim())
79+
}
80+
81+
/**
82+
* @param {import('simple-git/promise').SimpleGit} git
83+
* @param {string} from
84+
* @param {string} to
85+
* @param {string | undefined} author - only include commits from this author
86+
* @param {(files: string[]) => void} update
87+
*/
88+
async function collectCommits(git, from, to, author, update) {
89+
let i = 0
90+
for (const commit of (await git.log({ from, to })).all) {
91+
i++
92+
if ((!author || commit.author_name === author) && isMergeCommit(commit.message) || isSquashMergeMessage(commit.message)) {
93+
readline.clearLine(process.stdout, /*left*/ -1)
94+
readline.cursorTo(process.stdout, 0)
95+
process.stdout.write(i + ": " + commit.date)
96+
const files = parseFiles(await git.show([commit.hash, "--stat=1000,960,40", "--pretty=oneline"]))
97+
update(files)
98+
}
99+
}
100+
}
101+
102+
103+

scripts/createLanguageServiceBuild.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// <reference types="node"/>
2+
import { join } from "path";
3+
import { readFileSync, unlinkSync } from "fs";
4+
import { tmpdir } from "os";
5+
import { execSync, ExecSyncOptions } from "child_process";
6+
import chalk from "chalk";
7+
8+
interface PackageJson {
9+
name: string;
10+
version: string
11+
}
12+
13+
const exec = (cmd: string, opts?: ExecSyncOptions) => {
14+
console.log(chalk.gray(`> ${cmd} ${opts ? JSON.stringify(opts) : ""}`));
15+
execSync(cmd, opts);
16+
};
17+
18+
const step = (msg: string) => {
19+
console.log("\n\n" + chalk.bold("- ") + msg);
20+
};
21+
22+
function main(): void {
23+
console.log(chalk.bold("## Creating the language services build of TypeScript"));
24+
process.stdout.write(chalk.grey("> node /scripts/createLanguageServiceBuild.ts"));
25+
26+
// Create a tarball of the current version
27+
step("Packing the current TypeScript via npm.");
28+
exec("npm pack");
29+
30+
const packageJsonValue: PackageJson = JSON.parse(readFileSync("package.json", "utf8"));
31+
const tarballFileName = `${packageJsonValue.name}-${packageJsonValue.version}.tgz`;
32+
33+
const unzipDir = tmpdir();
34+
step(`Extracting the built version into a temporary folder. ${unzipDir}/package`);
35+
exec(`tar -xvzf ${tarballFileName} -C ${unzipDir}`);
36+
unlinkSync(tarballFileName);
37+
38+
step(`Updating the build metadata`);
39+
const packagePath = join(unzipDir, "package");
40+
exec(`node scripts/configureLanguageServiceBuild.js ${join(packagePath, "package.json")}`);
41+
42+
step(`Deploying the language service`);
43+
exec("npm publish --access public", { cwd: packagePath });
44+
}
45+
46+
main();

0 commit comments

Comments
 (0)