knip icon indicating copy to clipboard operation
knip copied to clipboard

Support command arrays in moonrepo plugin

Open SlexAxton opened this issue 1 year ago • 5 comments

I required this change in order for knip to work with my moonrepo monorepo on the latest version. I believe it's some combination of how you structure your moon.yml file and the version of moon that you use. This should support both old/new.

Before this change I'd get the following error:

❯ pnpm run knip

> monorepo@ knip /Users/slexaxton/monorepo
> knip

Analyzing workspace ....
file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/plugins/moonrepo/index.js:12
        .map(command => command.replace('$workspaceRoot', options.rootCwd))
                                ^

TypeError: command.replace is not a function
    at file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/plugins/moonrepo/index.js:12:33
    at Array.map (<anonymous>)
    at Object.resolveConfig (file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/plugins/moonrepo/index.js:12:10)
    at runPlugin (file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/WorkspaceWorker.js:253:77)
    at async WorkspaceWorker.findDependenciesByPlugins (file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/WorkspaceWorker.js:282:13)
    at async main (file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/index.js:119:41)
    at async run (file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/cli.js:26:83)
    at async file:///Users/slexaxton/monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/knip/dist/cli.js:104:1

Node.js v22.14.0
 ELIFECYCLE  Command failed with exit code 1.

SlexAxton avatar Feb 12 '25 10:02 SlexAxton

Thanks Alex, any chance you could update the MoonConfiguration type? Then we also don't require the extra comment(s).

webpro avatar Feb 12 '25 10:02 webpro

Not totally familiar with the way all the things in the repo work, but i think i did the thing you were asking.

SlexAxton avatar Feb 12 '25 11:02 SlexAxton

Open in Stackblitz

npm i https://pkg.pr.new/knip@943

commit: 024b9c9

pkg-pr-new[bot] avatar Feb 12 '25 11:02 pkg-pr-new[bot]

Thanks! That was it indeed. Please run bun format.

webpro avatar Feb 12 '25 11:02 webpro

Currently, CI indicates code formatting issues. Any chance you could format the code using bun format? Happy to merge and include the changes in the next release then.

webpro avatar Mar 08 '25 07:03 webpro

Closing this due to inactivity. Feel free to reopen or discuss as you see fit.

webpro avatar Mar 31 '25 05:03 webpro