Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin for moonrepo (moonrepo.dev) #579

Merged
merged 6 commits into from
Apr 6, 2024
Merged

Conversation

ethanjdiamond
Copy link
Contributor

No description provided.

Copy link
Collaborator

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first PR! Love to merge this in, but I do have a few points of feedback.

assert.deepEqual(counters, {
...baseCounters,
files: 2,
devDependencies: 4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you could add assertions about issues.devDependencies for those 4?


const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config: string[] = ['**/moon.yml', '.moon/tasks.yml', '.moon/tasks/*.yml'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever possible I try to prevent globs starting with ** (as they tend to be more "expensive"). Can we do without, or is there maybe a default location for projects so we can use that default here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know how to test this where there's various "workspaces", as I'm trying to simulate a monorepo. So the .moon/tasks.yml and .moon/tasks/*.yml are going to be against the workspace root, while moon.yml lives in the project (package) root. How would I test that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm figured it out

assert(issues.binaries['.moon/tasks/typescript.yml']['eslint']);
assert(issues.binaries['apps/a/moon.yml']['vite-node']);

assert(issues.files.has(join(cwd, 'tools/linters/lint-readme.ts')));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite-node $workspaceRoot/tools/linters/lint-readme.ts

Ideally, this file would be used, but the plugin doesn't replace $workspaceRoot (and $projectRoot. As the plugins receive the YAML contents (as a JS object) I think we can do this replacement before handing it over to getDependenciesFromScripts? However, I realize that plugins have options.config.cwd, but not the path to the "repo root" (basically process.cwd()). For now we can use process.cwd() and I can fix that up later on by adding it to those options.

Is this something you could work into this PR? Otherwise I'm happy to take a stab at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I understand what you're going for. Let me see what I can do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution looks correct, but I'm still seeing the file unused? What I usually do to debug is something like npx tsx ../../src/cli.ts --debug from inside the fixtures folder, that should show some insights into what the plugin returns (again, I'm happy to take over, but of course it's cool if you could wrap this up).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I played around with it a bunch and I'm kind of stumped. Is there something funky going on with the runtime?

When I logged the command on this line, it's correct. When I go into getDependenciesFromScripts and log npmScripts on literally the first line, it's showing an empty array.

Any idea what's going on there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The tests are "end-to-end" so the first invocation is likely from package.json.
  • I saw a few things were not in place at all, so I just went ahead and added those in this PR (and will clean up later after merging)

@ethanjdiamond
Copy link
Contributor Author

Think I addressed everything! Let me know if there's anything else.

@webpro
Copy link
Collaborator

webpro commented Apr 5, 2024

If you're OK with this, I'll merge it!

@webpro
Copy link
Collaborator

webpro commented Apr 5, 2024

Odd, those commits after rebase, no worries about that btw.

@ethanjdiamond
Copy link
Contributor Author

Yup, merge away! Thanks.

@webpro webpro merged commit 770f658 into webpro-nl:main Apr 6, 2024
8 of 11 checks passed
@webpro
Copy link
Collaborator

webpro commented Apr 7, 2024

🚀 This pull request is included in v5.9.0. See Release 5.9.0 for release notes.

Using Knip in a commercial project? Please consider sponsoring me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants