|
4 | 4 |
|
5 | 5 | const path = require('path');
|
6 | 6 | const childProcess = require('child_process');
|
7 |
| -const assert = require('assert'); |
8 |
| -const fs = require('fs'); |
9 |
| - |
10 |
| -const glob = require('glob'); |
11 |
| -const semver = require('semver'); |
12 | 7 |
|
13 | 8 | const { dependencies } = require('./package.json');
|
14 | 9 |
|
15 | 10 | const tsVersions = Object.keys(dependencies)
|
16 | 11 | .filter((pkg) => pkg.startsWith('typescript-'))
|
17 | 12 | .sort((a, b) => b.localeCompare(a));
|
18 | 13 |
|
19 |
| -// To allow omitting certain code from older versions of TypeScript, we have a |
20 |
| -// "magic" comment syntax. We precede a block of code with: |
21 |
| -// |
22 |
| -// /*! SEMVER_RANGE !*/ |
23 |
| -// |
24 |
| -// replacing SEMVER_RANGE with a semver range spec, such as '>=3.2'; we |
25 |
| -// terminate the block of code with: |
26 |
| -// |
27 |
| -// /*!!*/ |
28 |
| -// |
29 |
| -// We will only include the code between these comments if the TypeScript |
30 |
| -// version being tested satisfies the semver range that was specified. NOTE: We |
31 |
| -// currently do not allow nesting of these blocks. |
32 |
| -const templates = glob.sync('./*.ts.template').map((filename) => { |
33 |
| - const content = fs.readFileSync(filename, 'utf8'); |
34 |
| - const targetFilename = filename.replace(/\.template$/, ''); |
35 |
| - assert.notEqual(filename, targetFilename); |
36 |
| - const writeFileSync = (version) => { |
37 |
| - // Captures our magic comment syntax: `/*!(CAPTURE1)!*/(CAPTURE 2)/*!!*/` |
38 |
| - const regex = /\/\*!([^!]+)!\*\/([\s\S]*?)\/\*!!\*\//g; |
39 |
| - const finalContent = content.replace(regex, (_, versionRange, payload) => { |
40 |
| - if (semver.satisfies(version, versionRange)) { |
41 |
| - return payload; |
42 |
| - } |
43 |
| - return ''; |
44 |
| - }); |
45 |
| - fs.writeFileSync(targetFilename, finalContent); |
46 |
| - }; |
47 |
| - return { writeFileSync }; |
48 |
| -}); |
49 |
| - |
50 | 14 | for (const version of tsVersions) {
|
51 | 15 | console.log(`Testing on ${version} ...`);
|
52 | 16 |
|
53 |
| - for (const template of templates) { |
54 |
| - template.writeFileSync(version); |
55 |
| - } |
56 |
| - |
57 | 17 | const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc');
|
58 | 18 | childProcess.execSync(tscPath, { stdio: 'inherit' });
|
59 | 19 | }
|
0 commit comments