summaryrefslogtreecommitdiff
path: root/deno2/js/run_node.py
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-06-13 15:01:21 +0200
committerRyan Dahl <ry@tinyclouds.org>2018-06-13 15:01:21 +0200
commit5c7ba22f2242930ad09f011eaea12a59153e294f (patch)
tree6edb4e52147fe81b76e340028fa9cc67e4f058e7 /deno2/js/run_node.py
parent69868c2b0e4372e6d7e49821caca41d372686eea (diff)
parentbb6222c91872695cbe98aa2a75166265f52cec2e (diff)
Merge branch 'deno2'
Diffstat (limited to 'deno2/js/run_node.py')
-rwxr-xr-xdeno2/js/run_node.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/deno2/js/run_node.py b/deno2/js/run_node.py
new file mode 100755
index 000000000..1a69dc502
--- /dev/null
+++ b/deno2/js/run_node.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+"""
+gn can only run python scripts. This launches a subprocess Node process.
+The working dir of this program is out/Debug/ (AKA root_build_dir)
+Before running node, we symlink js/node_modules to out/Debug/node_modules.
+"""
+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")
+
+if not os.path.exists("node_modules"):
+ symlink(node_modules_path, "node_modules", True)
+
+args = ["node"] + sys.argv[1:]
+sys.exit(subprocess.call(args))