plugin-tools icon indicating copy to clipboard operation
plugin-tools copied to clipboard

Bug: create plugin "update" script modifies (prettyfies) all files in plugin's directory

Open cletter7 opened this issue 1 year ago • 5 comments

Which package(s) does this bug affect?

  • [x] Create Plugin
  • [ ] Sign Plugin
  • [ ] Plugin E2E
  • [ ] Plugin Meta Extractor

Package versions

5.3.10

What happened?

When running npx @grafana/create-plugin@latest update command it seems it prettifies all files in the plugin directory. This creates a lot of changes which complicates the review.

What you expected to happen

Only files inside .config directory should be prettified.

How to reproduce it (as minimally and precisely as possible)

  1. Pick any plugin that doesn't have the latest config.
  2. Plugin should have some files that are not prettified (e.g. test *.jsonc files, *.md etc.).
  3. Run npx @grafana/create-plugin@latest update
  4. Observe how files outside .config folder got modified (prettified).

Environment

System: OS: macOS 15.0 CPU: (10) arm64 Apple M1 Pro Memory: 863.66 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm Watchman: 2024.09.09.00 - /opt/homebrew/bin/watchman Browsers: Brave Browser: 128.1.69.168 Chrome: 129.0.6668.59 Safari: 18.0

Additional context

No response

cletter7 avatar Sep 24 '24 09:09 cletter7

Thanks for writing this up @cletter7 however I'm struggling to reproduce it in my plugin. I created a markdown file in the root of the plugin directory that prettier will act on. I ran npx -y @grafana/create-plugin@latest update from the root. It didn't run prettier over the md file. I then run npx prettier --write *.md and it formats it.

Image

Do you have a reproduction case I can take a look at?

jackw avatar Sep 26 '24 14:09 jackw

@jackw this happens to me all the time in our plugin monorepos. Haven't actually tried this in single repo plugins. Could you try in monorepo?

cletter7 avatar Oct 04 '24 15:10 cletter7

@jackw this happens to me all the time in our plugin monorepos. Haven't actually tried this in single repo plugins. Could you try in monorepo?

Is that this repo?

jackw avatar Oct 05 '24 17:10 jackw

@jackw yes.

cletter7 avatar Oct 05 '24 17:10 cletter7

Ok, I think I've narrowed it down to how create plugin sets the cwd then executes prettier however prettier doesn't resolve the . correctly and I think it's somehow resolving the workspace root (maybe by finding the first package.json) then running against the entire project.

~/dev/grafana/plugins-private/plugins/grafana-dynatrace-datasource/.config $ yarn prettier . --list-different
yarn run v1.22.22
$ /Users/jackwestbrook/dev/grafana/plugins-private/node_modules/.bin/prettier . --list-different
cypress/e2e/grafana-dynatrace-datasource.cy.ts
src/dashboards/overview.json
src/datasource.test.ts
error Command failed with exit code 1.

If I give it a specific directory from the workspace I believe it works as intended.

~/dev/grafana/plugins-private/plugins/grafana-dynatrace-datasource $ yarn prettier "./.config" --list-different
yarn run v1.22.22
$ /Users/jackwestbrook/dev/grafana/plugins-private/node_modules/.bin/prettier ./.config --list-different
✨  Done in 0.52s.

I'll get a fix in place shortly once I've done a bit more testing. 👍

jackw avatar Oct 07 '24 07:10 jackw

:rocket: Issue was released in @grafana/[email protected] :rocket: