blob: be7feb5083c183e7620647ceda991d74a11a80bc [file] [log] [blame]
Corentin Wallez76b49d52022-04-12 16:10:41 +00001#!/usr/bin/env python3
Austin Eng1cdea902022-03-24 00:21:55 +00002#
3# Copyright 2022 The Dawn Authors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Kai Ninomiya5c780d72022-03-17 21:43:17 +000016
17import subprocess
18import sys
19import os
20
21from dir_paths import node_dir
22
23try:
24 old_sys_path = sys.path
25 sys.path = [node_dir] + sys.path
26
27 from node import GetBinaryPath as get_node_binary_path
28finally:
29 sys.path = old_sys_path
30
31tsc = os.path.join(node_dir, 'node_modules', 'typescript', 'lib', 'tsc.js')
32
33
34def run_tsc_ignore_errors(args):
35 cmd = [get_node_binary_path(), tsc] + args
36 process = subprocess.Popen(cmd,
37 cwd=os.getcwd(),
38 stdout=subprocess.PIPE,
39 stderr=subprocess.PIPE)
40
41 stdout, stderr = process.communicate()
42
43 # Typecheck errors go in stdout, not stderr. If we see something in stderr, raise an error.
44 if len(stderr):
45 raise RuntimeError('tsc \'%s\' failed\n%s' % (' '.join(cmd), stderr))
46
47 return stdout
48
49
50if __name__ == '__main__':
51 run_tsc_ignore_errors(sys.argv[1:])