File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed
Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -299,7 +299,13 @@ def _createRequireInner(*args):
299299 module.paths.push(path + '/node_modules');
300300 module.require.path.push(python.pythonMonkey.dir + '/builtin_modules');
301301 module.require.path.push(python.pythonMonkey.nodeModules);
302+
303+ /* Add a .py loader, making it the first extension to be enumerated so py modules take precedence */
304+ const extCopy = Object.assign({}, module.require.extensions);
305+ for (let ext in module.require.extensions)
306+ delete module.require.extensions[ext];
302307 module.require.extensions['.py'] = loadPythonModule;
308+ Object.assign(module.require.extensions, extCopy);
303309
304310 if (isMain)
305311 {
Original file line number Diff line number Diff line change 1+ /**
2+ * @file collide.simple
3+ * Test to ensure require module identitifier collision that resolves both py and js
4+ * modules correctly prefers py modules.
5+ * @author Wes Garland <
[email protected] >
6+ * @date Mar 2024
7+ */
8+
9+ const { which } = require('./modules/collide')
10+ const whichjs = require('./modules/collide.js').which;
11+ const whichpy = require('./modules/collide.py').which;
12+
13+ if (which !== 'python')
14+ throw new Error(`python module was not preferred, got ${which} instead`)
15+
16+ if (whichpy !== 'python')
17+ throw new Error(`python module was not explicitly loaded, got ${whichpy} instead`)
18+
19+ if (whichjs !== 'javascript')
20+ throw new Error(`javascript module was not explicitly loaded, got ${whichjs} instead`)
Original file line number Diff line number Diff line change 1+ exports . which = "javascript"
Original file line number Diff line number Diff line change 1+ exports ['which' ]= "python"
You can’t perform that action at this time.
0 commit comments