summaryrefslogtreecommitdiff
path: root/deno2/js/run_node.py
blob: 8f650a5348d870f5c02a9d5f520e4ac4f9398178 (plain)
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
#!/usr/bin/env python
"""
gn can only run python scripts.
"""
import subprocess
import sys
import os

def symlink(target, name, target_is_dir=False):
  if os.name == "nt":
    from ctypes import windll, WinError
    CreateSymbolicLinkW = windll.kernel32.CreateSymbolicLinkW
    flags = 0x02  # SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
    if (target_is_dir):
      flags |= 0x01  # SYMBOLIC_LINK_FLAG_DIRECTORY
    if not CreateSymbolicLinkW(name.encode('utf-16le'),
                               target.encode('utf-16le'),
                               flags):
      raise WinError()
  else:
    os.symlink(target, name)

js_path = os.path.dirname(os.path.realpath(__file__))
node_modules_path = os.path.join(js_path, "node_modules")

# root_out_dir
if not os.path.exists("node_modules"):
  symlink(node_modules_path, "node_modules", True)

args = ["node"] + sys.argv[1:]
sys.exit(subprocess.call(args))