karakum-team / karakum

Converter of TypeScript declaration files to Kotlin declarations
Apache License 2.0
42 stars 2 forks source link

Maximum call stack size exceeded when trying to convert `pixi.js` v8. #11

Closed Ayfri closed 1 month ago

Ayfri commented 1 year ago

Hello, I'm trying to convert PIXI.js v8 with the following configuration :

{
    "input": "node_modules/pixi.js/lib/**/*.d.ts",
    "output": "dist",
    "libraryName": "pixi.js"
}

But I'm getting the following error :

file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17
    return commonPrefix(common, ...rest);
           ^

RangeError: Maximum call stack size exceeded
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)
    at commonPrefix (file:///C:/Users/MyUser/IdeaProjects/random/karakum-test/node_modules/karakum/build/utils/fileName.js:17:12)

Here is my package.json :

{
    "name": "karakum-test",
    "version": "1.0.0",
    "scripts": {
        "start": "karakum --config karakum.config.json"
    },
    "dependencies": {
        "pixi.js": "^8.0.0-beta.6"
    },
    "devDependencies": {
        "karakum": "^1.0.0-alpha.25",
        "typescript": "^5.2.2"
    }
}
sgrishchenko commented 1 year ago

Thank you for the report. I will check what is wrong with this commonPrefix helper.

sgrishchenko commented 1 year ago

@Ayfri I removed recursion in the commonPrefix helper. It is used only for detection of common file root that can be set up manually using inputRoots config option, so also now I compute common root lazily only if inputRoots is not specified. All changes are published, so you can check them.

But to be honest, I didn't reproduce your problem. After running of Karakum for your setup, I received only two files

/dist/filters.kt
/dist/index.kt

I noticed that index.kt re-exports a lot of stuff, so maybe the number of reexported files causes the issue with recursion? It would be great if you provide more details about your conversion. Maybe I will even add you configs as an example in Karakum repository.

sgrishchenko commented 1 year ago

Sorry, I used v7 of PIXI.js, that is why the number of files was so small. I tested it with v8 and now I see, the number of files is really big. I still didn't reproduce it on Linux (I don't know why), but I will try to do it on Windows later.

Ayfri commented 11 months ago

@sgrishchenko Have you had time to test ?

sgrishchenko commented 11 months ago

No, I didn't yet, but I already published a fix, that should solve this issue. You can try a new Karakum version.