Skip to content

Commit 5c070ad

Browse files
committed
Update the CI
1 parent 89ff34f commit 5c070ad

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

Diff for: .github/workflows/sync.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
GITHUB_TOKEN: ${{ secrets.TS_BOT_TOKEN }}
2121

2222
# Update search links from the origin repo before pushing to the upstream
23-
- run: git clone --depth 1 https://github.com/microsoft/TypeScript.git
23+
- run: git clone --depth 1 https://github.com/microsoft/TypeScript.git TypeScript
2424
- run: npm i
2525
- run: node scripts/convertRelativeLinksToHardcoded.js "**/*.md" --write
2626
- run: rm -rf TypeScript

Diff for: learn/systems/systems-fourslash.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Fourslash automatically generates mocha tests based on files you put inside [`/t
1515
for this lives in [`/src/testRunner/fourslashRunner.ts`][1]. This class is instantiated in
1616
[`/src/testRunner/runner.ts`][2].
1717

18-
Fom here the main work all lives in [`/src/harness/foudslash.ts`][3] where we'll be spending the rest of this
18+
Fom here the main work all lives in [`/src/harness/fourslash.ts`][3] where we'll be spending the rest of this
1919
section. The initial entry point is [`runFourSlashTest`][4] but the work is in [`runFourSlashTestContent`][5].
2020

2121
This function first creates a virtual fs, uses [`parseTestData`][6] to fill up the virtual fs. `parseTestData`:
@@ -56,8 +56,8 @@ moment;`
5656
[0]: https://github.com/microsoft/TypeScript/blob/master/src/testRunner/fourslashRunner.ts
5757
[1]: https://github.com/microsoft/TypeScript/blob/master/tests/cases/fourslash
5858
[2]: https://github.com/microsoft/TypeScript/blob/master/src/testRunner/runner.ts
59-
[3]: https://github.com/microsoft/TypeScript/blob/master/src/harness/fourslash.ts
60-
[4]: <src/harness/fourslash.ts - function runFourSlashTest(>
61-
[5]: <src/harness/fourslash.ts - function runFourSlashTestContent(>
62-
[5]: <src/harness/fourslash.ts - function parseTestData(>
59+
[3]: https://github.com/microsoft/TypeScript/blob/master/src/harness/fourslashImpl.ts
60+
[4]: <src/harness/fourslashImpl.ts - function runFourSlashTest(>
61+
[5]: <src/harness/fourslashImpl.ts - function runFourSlashTestContent(>
62+
[5]: <src/harness/fourslashImpl.ts - function parseTestData(>
6363
<!-- prettier-ignore-end -->

Diff for: scripts/convertRelativeLinksToHardcoded.js

+50-36
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,64 @@
1212
// Write:
1313
// node scripts/convertRelativeLinksToHardcoded.js scripts/fixtures/input.md --write
1414

15-
const glob = require("glob")
16-
const {readFileSync, writeFileSync, existsSync} = require("fs")
17-
const {join} = require("path")
15+
const glob = require("glob");
16+
const { readFileSync, writeFileSync, existsSync } = require("fs");
17+
const { join } = require("path");
1818
const { execSync } = require("child_process");
1919
const escapeRegex = require("escape-regex-string");
2020

21-
if (!process.argv[2]) throw new Error("Did not include a glob for markdown files to change")
21+
if (!process.argv[2]) throw new Error("Did not include a glob for markdown files to change");
2222

2323
// This can be anything
24-
const write = process.argv[3] !== undefined
24+
const write = process.argv[3] !== undefined;
2525

26-
const possibleTSRepo = ["../typescript-compiler", "../TypeScript", "TypeScript"]
27-
let repoPath = possibleTSRepo.find(existsSync)
26+
const possibleTSRepo = ["../typescript-compiler", "../TypeScript", "TypeScript"];
27+
let repoPath = possibleTSRepo.find(f => existsSync(join(f, "package.json")));
2828
if (!repoPath) throw new Error("Could not find a TypeScript repo");
2929

3030
const repoHead = execSync(`git rev-parse HEAD | cut -c 1-8`, { cwd: repoPath, encoding: "utf8" });
31-
if (!repoHead) throw new Error("Could not get the git info from the sibling TypeScript repo")
31+
if (!repoHead) throw new Error("Could not get the git info from the sibling TypeScript repo");
3232

33-
const files = glob.sync(process.argv[2])
34-
if (!files.length) throw new Error("Did not get any files with that glob")
33+
const files = glob.sync(process.argv[2]);
34+
if (!files.length) throw new Error("Did not get any files with that glob");
35+
36+
let failed = [];
3537

3638
files.forEach(file => {
37-
let content = readFileSync(file, "utf8")
39+
if (file === "README.md") return;
40+
41+
let content = readFileSync(file, "utf8");
3842
// https://regex101.com/r/w1dEG1/1
39-
const regex = new RegExp(/\[.*]: <(.*) - (.*)>/g)
40-
41-
let result
42-
while (result = regex.exec(content)) {
43-
const file = result[1];
43+
const regex = new RegExp(/\[.*]: <(.*) - (.*)>/g);
44+
45+
let result;
46+
while ((result = regex.exec(content))) {
47+
const fileRef = result[1];
4448
const searchTerm = result[2];
45-
const original = `: <${file} - ${searchTerm}>`
46-
const originalFile = readFileSync(join(repoPath, file), "utf8")
47-
if (!originalFile) throw new Error(`Could not find a file at '${join(repoPath, file)}'`)
48-
49-
const line = getLineNo(originalFile, new RegExp(escapeRegex(searchTerm)))
50-
const lineRef = line && line[0] && line[0].number ? `#L${line[0].number}`: ""
51-
const replacement = `: https://github.com/microsoft/TypeScript/blob/${repoHead.trim()}/${file}${lineRef}`
52-
content = content.replace(original, replacement)
49+
const original = `: <${fileRef} - ${searchTerm}>`;
50+
try {
51+
const originalFile = readFileSync(join(repoPath, fileRef), "utf8");
52+
const line = getLineNo(originalFile, new RegExp(escapeRegex(searchTerm)));
53+
const lineRef = line && line[0] && line[0].number ? `#L${line[0].number}` : "";
54+
const replacement = `: https://github.com/microsoft/TypeScript/blob/${repoHead.trim()}/${fileRef}${lineRef}`;
55+
content = content.replace(original, replacement);
56+
} catch (e) {
57+
failed.push([file, fileRef]);
58+
}
5359
}
5460

5561
if (write) {
56-
writeFileSync(file, content)
62+
writeFileSync(file, content);
5763
} else {
58-
console.log(content)
64+
console.log(content);
5965
}
6066
});
6167

68+
if (failed.length) {
69+
console.error("Could not find:");
70+
console.error(failed);
71+
process.exit(1);
72+
}
6273

6374
/*!
6475
* line-number <https://github.com/jonschlinkert/line-number>
@@ -67,13 +78,16 @@ files.forEach(file => {
6778
* Licensed under the MIT License
6879
*/
6980
function getLineNo(str, re) {
70-
return str.split(/\r?\n/).map(function (line, i) {
71-
if (re.test(line)) {
72-
return {
73-
line: line,
74-
number: i + 1,
75-
match: line.match(re)[0]
76-
};
77-
}
78-
}).filter(Boolean);
79-
};
81+
return str
82+
.split(/\r?\n/)
83+
.map(function(line, i) {
84+
if (re.test(line)) {
85+
return {
86+
line: line,
87+
number: i + 1,
88+
match: line.match(re)[0]
89+
};
90+
}
91+
})
92+
.filter(Boolean);
93+
}

0 commit comments

Comments
 (0)