From 2dfa2970e7c2ae02f597f8e313414a00f945d3cc Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 8 Jun 2020 14:43:25 -0400 Subject: [PATCH 01/10] Adds testing the TypeScript repo against PR changes --- .github/workflows/test_typescript.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/test_typescript.yml diff --git a/.github/workflows/test_typescript.yml b/.github/workflows/test_typescript.yml new file mode 100644 index 000000000..ea786c7f0 --- /dev/null +++ b/.github/workflows/test_typescript.yml @@ -0,0 +1,27 @@ +name: Runs with TypeScript Tests +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + + - run:| + # Get local dependencies + npm install + # Make our new dom APIs + npm build + + # Clone TypeScript, set it up + git clone https://github.com/microsoft/TypeScript -–depth 1 + cd TypeScript + npm i + + # Move in the generated dom APIs into a new version of TSC + cp -rf ../generated/* src/lib + + # Run TypeScript's tests with the new DOM libs + npm test From 04df3f0630b75e9c7355711f3c5e73da51cc86ce Mon Sep 17 00:00:00 2001 From: Orta Date: Sat, 12 Dec 2020 10:09:15 +0000 Subject: [PATCH 02/10] Gets TypeScript cloned properly --- .github/workflows/test_typescript.yml | 28 +++++++++++++-------------- .gitignore | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test_typescript.yml b/.github/workflows/test_typescript.yml index ea786c7f0..2a9bb69fe 100644 --- a/.github/workflows/test_typescript.yml +++ b/.github/workflows/test_typescript.yml @@ -9,19 +9,19 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - - run:| - # Get local dependencies - npm install - # Make our new dom APIs - npm build + - run: | + # Get local dependencies + npm install + # Make our new dom APIs + npm run build - # Clone TypeScript, set it up - git clone https://github.com/microsoft/TypeScript -–depth 1 - cd TypeScript - npm i - - # Move in the generated dom APIs into a new version of TSC - cp -rf ../generated/* src/lib + # Clone TypeScript, set it up + git clone https://github.com/microsoft/TypeScript --depth 1 + cd TypeScript + npm i + + # Move in the generated dom APIs into a new version of TSC + cp -rf ../generated/* src/lib - # Run TypeScript's tests with the new DOM libs - npm test + # Run TypeScript's tests with the new DOM libs + npm test diff --git a/.gitignore b/.gitignore index 9b2dda73d..72bc839d1 100644 --- a/.gitignore +++ b/.gitignore @@ -285,3 +285,4 @@ inputfiles/browser.webidl.json !.vscode/launch.template.json package-lock.json yarn.lock +TypeScript From b15105ec263369c68698c150122c6fd4d636d989 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 15:31:29 +0000 Subject: [PATCH 03/10] Try show the baseline diff in the github PR --- .github/workflows/test_typescript.yml | 14 ++++++++++++-- dangerfile.js | 8 ++++++++ package.json | 4 +++- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 dangerfile.js diff --git a/.github/workflows/test_typescript.yml b/.github/workflows/test_typescript.yml index 2a9bb69fe..121bbb31c 100644 --- a/.github/workflows/test_typescript.yml +++ b/.github/workflows/test_typescript.yml @@ -23,5 +23,15 @@ jobs: # Move in the generated dom APIs into a new version of TSC cp -rf ../generated/* src/lib - # Run TypeScript's tests with the new DOM libs - npm test + # Run TypeScript's tests with the new DOM libs, but don't fail + npm test || true + gulp baseline-accept + + # The git diff now is the difference between tests + git diff > baseline-changes.diff + + - name: Danger + run: npm run danger -- ci + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/dangerfile.js b/dangerfile.js new file mode 100644 index 000000000..c5bfc1071 --- /dev/null +++ b/dangerfile.js @@ -0,0 +1,8 @@ +const {message} = require("danger") +const {readFileSync, existsSync} = require("fs") + +const diffPath = "baseline-changes.diff" +if (existsSync(diffPath)) { + const diffContents = readFileSync(diffPath, "utf8") + message(diffContents) +} diff --git a/package.json b/package.json index e23118bd8..75a6912bd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "fetch-mdn": "npm run build && node ./lib/mdnfetcher.js", "fetch": "echo This could take a few minutes... && npm run fetch-idl && npm run fetch-mdn", "baseline-accept": "cpx \"generated\\*\" baselines\\", - "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js" + "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js", + "danger": "danger" }, "dependencies": { "@types/jsdom": "^16.2.4", @@ -15,6 +16,7 @@ "@types/node-fetch": "^2.5.7", "@types/webidl2": "^23.13.2", "cpx2": "^2.0.0", + "danger": "^10.5.4", "jsdom": "^16.4.0", "node-fetch": "^2.6.1", "print-diff": "^1.0.0", From e78d6213936c0dad92caf73eef277041b155e616 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 15:47:38 +0000 Subject: [PATCH 04/10] Get the diff from the subfolder --- dangerfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dangerfile.js b/dangerfile.js index c5bfc1071..cfb4e9871 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,7 +1,7 @@ const {message} = require("danger") const {readFileSync, existsSync} = require("fs") -const diffPath = "baseline-changes.diff" +const diffPath = "./TypeScript/baseline-changes.diff" if (existsSync(diffPath)) { const diffContents = readFileSync(diffPath, "utf8") message(diffContents) From 84791e331298e650b009d8037ce934d65dc3614d Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 16:14:46 +0000 Subject: [PATCH 05/10] Read the diff and only print the interesting stuff --- dangerfile.js | 23 ++++++++++++++++++++++- package.json | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dangerfile.js b/dangerfile.js index cfb4e9871..0a0cfb461 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,8 +1,29 @@ const {message} = require("danger") const {readFileSync, existsSync} = require("fs") +const parseDiff = require("parse-diff") const diffPath = "./TypeScript/baseline-changes.diff" if (existsSync(diffPath)) { const diffContents = readFileSync(diffPath, "utf8") - message(diffContents) + const diffedFiles = parseDiff(diffContents) + + const uninterestingFiles = [".generated.d.ts", "globalThisBlockscopedProperties.types", "mappedTypeRecursiveInference.types"] + const withoutKnownNormalFails = diffedFiles.filter(diff => { + return uninterestingFiles.filter(suffix => diff.to?.endsWith(suffix)).length > 0 + }) + + const md = ["## Changed baselines from the TypeScript test suite"] + + withoutKnownNormalFails.forEach(diff => { + md.push(`#### ${diff.to || diff.from}}`) + + md.push("```diff") + diff.chunks.forEach(chunk => { + md.push(chunk.content) + }) + md.push("```") + }) + + + message(md.join("\n")) } diff --git a/package.json b/package.json index 75a6912bd..540b5575f 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "danger": "^10.5.4", "jsdom": "^16.4.0", "node-fetch": "^2.6.1", + "parse-diff": "^0.7.0", "print-diff": "^1.0.0", "styleless-innertext": "^1.1.2", "typescript": "4.1.0-dev.20200908", From 127edeb34595d1e9da05495e417418418dace3f0 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 16:32:36 +0000 Subject: [PATCH 06/10] Don't use fancy syntax --- dangerfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dangerfile.js b/dangerfile.js index 0a0cfb461..965c0f939 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -9,7 +9,7 @@ if (existsSync(diffPath)) { const uninterestingFiles = [".generated.d.ts", "globalThisBlockscopedProperties.types", "mappedTypeRecursiveInference.types"] const withoutKnownNormalFails = diffedFiles.filter(diff => { - return uninterestingFiles.filter(suffix => diff.to?.endsWith(suffix)).length > 0 + return uninterestingFiles.filter(suffix => diff.to && diff.to.endsWith(suffix)).length > 0 }) const md = ["## Changed baselines from the TypeScript test suite"] From 02df9f5622751cec2d3b4c08f94a13907f4b6475 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 16:51:12 +0000 Subject: [PATCH 07/10] Revert file lookup, and push chunk changes into markdown --- dangerfile.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dangerfile.js b/dangerfile.js index 965c0f939..beefd240d 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -9,17 +9,21 @@ if (existsSync(diffPath)) { const uninterestingFiles = [".generated.d.ts", "globalThisBlockscopedProperties.types", "mappedTypeRecursiveInference.types"] const withoutKnownNormalFails = diffedFiles.filter(diff => { - return uninterestingFiles.filter(suffix => diff.to && diff.to.endsWith(suffix)).length > 0 + return !uninterestingFiles.filter(suffix => diff.to && diff.to.endsWith(suffix)).length > 0 }) const md = ["## Changed baselines from the TypeScript test suite"] withoutKnownNormalFails.forEach(diff => { md.push(`#### ${diff.to || diff.from}}`) - + md.push("```diff") diff.chunks.forEach(chunk => { md.push(chunk.content) + + chunk.changes.forEach(change => { + md.push(change.content) + }) }) md.push("```") }) From 2398dac3dd06d8f4972dff2f532464dace988c44 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 16 Dec 2020 17:26:08 +0000 Subject: [PATCH 08/10] Include some more info on what is going on --- dangerfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dangerfile.js b/dangerfile.js index beefd240d..b7cc51f93 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -12,10 +12,10 @@ if (existsSync(diffPath)) { return !uninterestingFiles.filter(suffix => diff.to && diff.to.endsWith(suffix)).length > 0 }) - const md = ["## Changed baselines from the TypeScript test suite"] + const md = ["## Changed baselines from the TypeScript test suite", "\nThese are the test changes in the TypeScript codebase which showed a difference (excluding a few which will always change), it should give a small sense of what to expect on the TypeScript side if this PR is merged."] withoutKnownNormalFails.forEach(diff => { - md.push(`#### ${diff.to || diff.from}}`) + md.push(`#### [${diff.to || diff.from}](https://github.com/microsoft/TypeScript/blob/master/${diff.to || diff.from})`) md.push("```diff") diff.chunks.forEach(chunk => { From 575087a699159c6ebe250eb48ad1f1eadea89f8b Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 21 Dec 2020 18:18:02 +0000 Subject: [PATCH 09/10] Adds a quick migration script --- README.md | 8 ++++++++ package.json | 3 ++- src/migrate-to-tsc.ts | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/migrate-to-tsc.ts diff --git a/README.md b/README.md index 7777562e5..22b71aaf7 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ To test: npm run test ``` +To deploy: + +```sh +npm run migrate +``` + +The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in. + ## Contribution Guidelines The `dom.generated.d.ts`, `webworker.generated.d.ts` and `dom.iterable.generated.d.ts` files from the TypeScript repo are used as baselines. diff --git a/package.json b/package.json index e23118bd8..1a309116d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "fetch-mdn": "npm run build && node ./lib/mdnfetcher.js", "fetch": "echo This could take a few minutes... && npm run fetch-idl && npm run fetch-mdn", "baseline-accept": "cpx \"generated\\*\" baselines\\", - "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js" + "test": "tsc -p ./tsconfig.json && node ./lib/index.js && node ./lib/test.js", + "migrate": "node ./lib/migrate-to-tsc.js" }, "dependencies": { "@types/jsdom": "^16.2.4", diff --git a/src/migrate-to-tsc.ts b/src/migrate-to-tsc.ts new file mode 100644 index 000000000..90ec52edf --- /dev/null +++ b/src/migrate-to-tsc.ts @@ -0,0 +1,21 @@ +// Mainly a quick script to migrate the generated files into the +// lib folder of a TypeScript clone. +// +// node ./lib/migrate-to-tsc.js [optional/file/path/to/tsc] + +import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs" +import { join } from "path" + +const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"] +const tscWD = maybeTSWorkingDir.find(wd => existsSync(wd)) + +if (!tscWD) throw new Error("Could not find a TypeScript clone to put the generated files in.") + +const generatedFiles = readdirSync("generated") +generatedFiles.forEach(file => { + const contents = readFileSync(join("generated", file) , "utf8") + const newFilePath = join(tscWD, "src", "lib", file) + writeFileSync(newFilePath, contents) +}) + +console.log(`Moved ${generatedFiles.map(f => f.replace(".generated", "")).join(", ")} to '${tscWD}'.`) From 2f44fbb4a9ef88a70bd9f9ef2599160533fd9e03 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 13 Jan 2021 11:58:20 +0000 Subject: [PATCH 10/10] Omit the message when there's no changes --- .github/workflows/test_typescript.yml | 3 ++- dangerfile.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_typescript.yml b/.github/workflows/test_typescript.yml index ac7f8aa2d..bd4dac5c6 100644 --- a/.github/workflows/test_typescript.yml +++ b/.github/workflows/test_typescript.yml @@ -9,7 +9,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - - run: | + - name: Run TypeScript Compiler Tests with new dom.d.ts + run: | # Get local dependencies npm install # Make our new dom APIs diff --git a/dangerfile.js b/dangerfile.js index b7cc51f93..59101410f 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,4 +1,4 @@ -const {message} = require("danger") +const {markdown} = require("danger") const {readFileSync, existsSync} = require("fs") const parseDiff = require("parse-diff") @@ -28,6 +28,7 @@ if (existsSync(diffPath)) { md.push("```") }) - - message(md.join("\n")) + if (md.length > 2) { + markdown(md.join("\n")) + } }