Skip to content

Commit 378dfa7

Browse files
committed
Tracked endless loop loading and refactored ts loader files and examples, solved properly, it was in the monkey patch of node loader when guessing the modules.
1 parent da241bf commit 378dfa7

File tree

18 files changed

+289
-3
lines changed

18 files changed

+289
-3
lines changed

source/cli/metacallcli/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,18 @@ endif()
333333
if(OPTION_BUILD_LOADERS AND OPTION_BUILD_LOADERS_TS AND OPTION_BUILD_SCRIPTS AND OPTION_BUILD_SCRIPTS_TS)
334334
add_test(NAME ${target}-ts
335335
COMMAND ${TEST_COMMAND} "echo 'load ts typedfunc.ts\ninspect\ncall typed_sum(4, 5)\nexit' | $<TARGET_FILE:${target}> | ${GREP_COMMAND} \"9.0\""
336-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
336+
WORKING_DIRECTORY ${LOADER_SCRIPT_PATH}/typedfunc
337337
)
338338
test_environment_variables(${target}-ts
339339
""
340340
${TESTS_ENVIRONMENT_VARIABLES}
341341
)
342+
add_test(NAME ${target}-tsx-loop-fail
343+
COMMAND ${TEST_COMMAND} "$<TARGET_FILE:${target}> loopfail.tsx | ${GREP_COMMAND} \"Error: Cannot find module 'yeet-oof/whatever'\""
344+
WORKING_DIRECTORY ${LOADER_SCRIPT_PATH}/loopfail
345+
)
346+
test_environment_variables(${target}-tsx-loop-fail
347+
""
348+
${TESTS_ENVIRONMENT_VARIABLES}
349+
)
342350
endif()

source/ports/node_port/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,13 @@ mod.prototype.require = function (name) {
261261
/* If it is not a NodeJS module, try to guess the runtime */
262262
const loaders = new Set(Object.values(tags));
263263

264-
/* Mock and node loaders are not included */
264+
/* Mock, node and ts loaders are not included, Mock will always load
265+
* so it's not an option, Node and TypeScript will enter in a endless loop
266+
* in some cases, because it will hit the monkey patched require again
267+
* and also you usually do not publish ts packages without the js into npm */
265268
loaders.delete('mock');
266269
loaders.delete('node');
270+
loaders.delete('ts');
267271

268272
for (let it = loaders.values(), tag = null; tag = it.next().value; ) {
269273
try {

source/scripts/typescript/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ include(TypeScriptProject)
1515

1616
add_subdirectory(typedfunc)
1717
add_subdirectory(templating)
18+
add_subdirectory(loopfail)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Configure typescript project
3+
#
4+
5+
ts_project(loopfail 0.1.0)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { renderToString } = require('yeet-oof/whatever');
2+
3+
console.log(renderToString);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"include": [
3+
"loopfail.tsx"
4+
],
5+
"compilerOptions": {
6+
"target": "es5",
7+
"jsx": "react",
8+
"lib": ["es2015", "dom"]
9+
}
10+
}

source/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ add_subdirectory(metacall_typescript_test)
186186
add_subdirectory(metacall_typescript_node_test)
187187
add_subdirectory(metacall_typescript_call_map_test)
188188
#add_subdirectory(metacall_typescript_tsx_test) # TODO: Download react dependencies locally instead of globally
189+
add_subdirectory(metacall_typescript_tsx_loop_fail_test)
189190
add_subdirectory(metacall_lua_test)
190191
add_subdirectory(metacall_rpc_test)
191192
# add_subdirectory(metacall_csharp_function_test) # TODO: C# 9.0 seems not to work so top level expressions do not work

0 commit comments

Comments
 (0)