code-complexity
code-complexity copied to clipboard
pass filename to transfromSync
I didn't see any contributor documentation but wanted to open this PR in case it helps anyone else.
Thanks for creating this tool its exactly what I was looking for!
When I attempted to use it I was getting the following error.
ConfigError: [BABEL] unknown file: Preset /* your preset */ requires a filename to be set when babel is called directly,
babel.transformSync(code, { filename: 'file.ts', presets: [/* your preset */] });
See https://babeljs.io/docs/en/options#filename for more information.
at transformSync (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/node_modules/@babel/core/lib/transform.js:42:76)
at fromJavaScript (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/strategies/cyclomatic.js:26:50)
at calculate (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/strategies/cyclomatic.js:17:20)
at Complexity.computeComplexity (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/complexity.js:28:59)
at Complexity.compute (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/complexity.js:13:45)
at /Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/complexities.js:10:98
at Array.map (<anonymous>)
at Complexities.computeFor (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/complexity/complexities.js:10:54)
at Statistics.compute (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/lib/statistics/statistics.js:16:59)
at main (/Users/dan/.nvm/versions/node/v18.19.0/lib/node_modules/code-complexity/dist/src/io/index.js:13:44)
I didn't see any other bug reports so perhaps this is a misconfiguration within my project. Let me know if that might be the case
Version info from my project
Node: v18.19.0
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"typescript": "^4.7.4",
It should no longer be needed with v5, could you tell me if it solves your issue?
You can grab it like this: npx code-complexity@alpha <path> [options]