This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typecheck-sources.js
61 lines (54 loc) · 2 KB
/
typecheck-sources.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @fileoverview Typecheck sample's sources w/ TypeScript & Closure compilers.
* @module tasks/typecheck-sources
* @author Derek Lewis
*/
'use strict';
module.exports = (() => {
const { basename, join, resolve } = require('path');
const { cp } = require('shelljs');
const { jsSampleSrcs } = require('../repomap.json');
const { spawn } = require('cross-spawn');
const projectRootDir = resolve('.');
const tmpSrcDir = require('tempy').directory();
const compilerOpts = {
clFlags: [ // Closure compiler CLI args.
'--compilation_level=ADVANCED_OPTIMIZATIONS',
'--warning_level=VERBOSE',
'--checks_only',
'--jscomp_error=strictCheckTypes', // Our main concern.
'--jscomp_off=moduleLoad', // Closure won't resolve the builtins.
'--jscomp_off=undefinedVars', // ESLint performs this check anyways.
'--externs=externs/node.extern.js', // Annotated symbols w/o implemention.
'--language_out=ECMASCRIPT_NEXT', // No emissions, yet required.
'--module_resolution=node',
'--process_common_js_modules',
],
tsFlags: [ // TypeScript compiler CLI args.
'--allowJs',
'--checkJs',
'--noEmit',
'--strict',
'--module', 'esnext',
'--moduleResolution', 'node',
'--allowSyntheticDefaultImports',
],
clSrcPathArgs: jsSampleSrcs.map((path) => {
return '--js=' + path;
}),
tsSrcPathArgs: jsSampleSrcs.map((srcPath) => {
let srcBaseName = basename(srcPath);
if (/\.mjs$/.test(srcBaseName))
srcBaseName = srcBaseName.replace('.mjs', '.js');
const tmpSrcPath = resolve(tmpSrcDir, srcBaseName);
cp(join(projectRootDir, srcPath), tmpSrcPath);
return tmpSrcPath;
}),
};
spawn('npx', ['tsc',
...compilerOpts.tsFlags, ...compilerOpts.tsSrcPathArgs],
{ stdio: 'inherit' });
spawn('npx', ['google-closure-compiler',
...compilerOpts.clFlags, ...compilerOpts.clSrcPathArgs],
{ stdio: 'inherit' });
})();