Skip to content

Commit c2ff52c

Browse files
committed
fix: node_modules lookup path
1 parent 14dd94c commit c2ff52c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

python/pythonmonkey/require.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@
2626
import sys, os
2727
from typing import Union, Dict
2828
import importlib
29+
import importlib.util
2930
from importlib import machinery
3031
import inspect
3132
import functools
3233

3334
from . import pythonmonkey as pm
35+
node_modules = os.path.abspath(
36+
os.path.join(
37+
importlib.util.find_spec("pminit").submodule_search_locations[0],
38+
"..",
39+
"pythonmonkey",
40+
"node_modules"
41+
)
42+
)
3443

3544
# Add some python functions to the global python object for code in this file to use.
3645
globalThis = pm.eval("globalThis;");
@@ -183,7 +192,7 @@ def existsSync(filename: str) -> bool:
183192
# require and exports symbols injected from the bootstrap object above. Current PythonMonkey bugs
184193
# prevent us from injecting names properly so they are stolen from trail left behind in the global
185194
# scope until that can be fixed.
186-
with open(os.path.dirname(__file__) + "/node_modules/ctx-module/ctx-module.js", "r") as ctxModuleSource:
195+
with open(node_modules + "/ctx-module/ctx-module.js", "r") as ctxModuleSource:
187196
initCtxModule = pm.eval("""'use strict';
188197
(function moduleWrapper_forCtxModule(broken_require, broken_exports)
189198
{

0 commit comments

Comments
 (0)