Skip to content

Commit 8d99bcb

Browse files
committed
Solve minor bug in node port which did not allow paths like './asd.py'.
1 parent e20b30e commit 8d99bcb

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def sum(a, b):
3131

3232
`main.js`
3333
``` javascript
34-
const { sum } = require('sum.py');
34+
const { sum } = require('./sum.py');
3535

3636
sum(3, 4); // 7
3737
```

source/ports/node_port/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ const metacall_require = (tag, name) => {
101101
// TODO: Inspect only the handle instead of the whole metacall namespace
102102
/* return */ addon.metacall_load_from_file(tag, [ name ]);
103103

104-
105104
const inspect = metacall_inspect();
106-
const script = inspect[tag].find(s => s.name === name);
105+
const script = inspect[tag].find(s => s.name === path.basename(name));
106+
107107
const obj = {};
108108

109109
for (const func of script.scope.funcs) {

source/ports/node_port/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/ports/node_port/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metacall",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "Call Python, C#, Ruby... functions from NodeJS (a NodeJS Port for MetaCall)",
55
"repository": "github:metacall/core",
66
"bugs": "https://github.com/metacall/core/issues",

source/ports/node_port/test/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ describe('metacall', () => {
7474
});
7575
}
7676
it('require (mock)', () => {
77-
const asd = require('asd.mock');
77+
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?
78+
// const asd = require('asd.mock');
79+
const asd = require('./asd.mock');
7880
assert.notStrictEqual(asd, undefined);
7981
assert.strictEqual(asd.my_empty_func(), 1234);
8082
assert.strictEqual(asd.my_empty_func_str(), 'Hello World');
@@ -86,7 +88,9 @@ describe('metacall', () => {
8688
assert.strictEqual(asd.mixed_args('a', 3, 4, 3.4, 'NOT IMPLEMENTED'), 65);
8789
});
8890
it('require (py)', () => {
89-
const example = require('example.py');
91+
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?
92+
// const example = require('example.py');
93+
const example = require('./example.py');
9094
assert.notStrictEqual(example, undefined);
9195
assert.strictEqual(example.multiply(2, 2), 4);
9296
assert.strictEqual(example.divide(4.0, 2.0), 2.0);
@@ -108,7 +112,9 @@ describe('metacall', () => {
108112
assert.strictEqual(py_encode_basestring_ascii('asd'), '"asd"');
109113
});
110114
it('require (rb)', () => {
111-
const cache = require('cache.rb');
115+
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?
116+
// const cache = require('cache.rb');
117+
const cache = require('./cache.rb');
112118
assert.notStrictEqual(cache, undefined);
113119
assert.strictEqual(cache.cache_set('asd', 'efg'), undefined);
114120
assert.strictEqual(cache.cache_get('asd'), 'efg');

0 commit comments

Comments
 (0)