Skip to content

Commit

Permalink
Solve bugs from node port.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Feb 12, 2021
1 parent ecf2c4a commit 101289c
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions source/ports/node_port/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,34 +214,25 @@ mod.prototype.require = function (name) {
// /* Continue loading */
// }

/* Try to load it with NodeJS first */
try {
return node_require.apply(this, [ name ]);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

try {
return node_require.apply(this, [ require.resolve(name) ]);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

const index = name.lastIndexOf('.');

if (index !== -1) {
/* If there is extension, load the module depending on the tag */
const extension = name.substr(index + 1);
const tag = tags[extension];
/* If there is extension, load the module depending on the tag */
const extension = name.substr(index + 1);
const tag = tags[extension];

if (tag && tag !== 'node') {
/* Load with MetaCall if we found a tag and it is not NodeJS */
return metacall_require(tag, name);
}
if (tag && tag !== 'node') {
/* Load with MetaCall if we found a tag and it is not NodeJS */
return metacall_require(tag, name);
}
}

try {
return node_require.apply(this, [ name ]);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

/* If there is no extension or the extension is not supported or it is 'node', load it with NodeJS require */
Expand Down

0 comments on commit 101289c

Please sign in to comment.