threedayAAAAA / vite-plugin-circular-dependency

Detect circular dependencies
MIT License
34 stars 2 forks source link

The error is not thrown if there are cyclic dependencies #6

Closed rushelex closed 8 months ago

rushelex commented 8 months ago

In the plugin parameters there is an option circleImportThrowErr. It does not work. Circular dependencies are simply shown in the console, but the build continues and completes successfully.

I think this is happening because the argument data is an object and does not have a length property. I think the problem can be solved quite simply – you need to check the length of the object keys:

function validateCircleData(ctx: Context, data: CircleData){
    if(ctx.circleImportThrowErr && Object.keys(data).length){
        throw new Error('has circular dependencies in this project')
    }
}
threedayAAAAA commented 8 months ago

Thank you very much for reporting this issue, it was my mistake. I have solved this problem in this commit. https://github.com/threedayAAAAA/vite-plugin-circular-dependency/commit/faa301dc7c45470faf75335ab2c3f556b613179a I will release a new version later and you can try to update to the latest version. Thanks again sincerely for pointing out this problem for me.