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

Build: Migrate create-plugin to ESM #658

Merged
merged 16 commits into from
Jan 12, 2024
Merged

Build: Migrate create-plugin to ESM #658

merged 16 commits into from
Jan 12, 2024

Conversation

jackw
Copy link
Collaborator

@jackw jackw commented Jan 11, 2024

What this PR does / why we need it:
This PR updates the create-plugin package to build only as an es module. The following changes have been made with reasoning on approaches:

  • Updates Typescript config to output ESM. These changes are in line with tsconfig/bases/node20 suggested config. Having found these configs I'm wondering if we should update the entire repo to use them over writing our own.
  • Updates all import paths inline with Typescripts requirements by adding .js extension to imports. Note that auto barrel file resolution (from './commands/' resolved to from './commands/index.js') no longer work with ESM. You have to reference a file. VsCode autocompletion seems to work out the box. I attempted to use a bundler ESbuild to prevent the need to change all these imports but hit a wall.
  • Update all imports to use import over require. I'm not sure why utils.console.ts used require but changing them led to complications with TS types and needing to patch the marked-terminal package and set overrides for marked nested dependency.
  • Replaces Jest with Vitest. Turns out Jest support for ESM is quite poor. Mocking in particular is complicated due to esm static import analysis and needing to use unstable_mockModule which I didn't particularly like the sound of. Vitest migration was quite painless, only the mocks needed some attention.
  • Updates some dependencies to their ESM compatible versions. Other dependency updates will be done in future PRs.

Which issue(s) this PR fixes:

Related #654

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @grafana/create-plugin@3.0.0-canary.658.52bb056.0
# or 
yarn add @grafana/create-plugin@3.0.0-canary.658.52bb056.0

@jackw jackw added major Increment the major version when merged release Create a release when this pr is merged chore Other changes that don't modify src or test files labels Jan 11, 2024
@jackw jackw self-assigned this Jan 11, 2024
@jackw jackw requested a review from a team as a code owner January 11, 2024 10:00
@jackw jackw requested review from academo and removed request for a team January 11, 2024 10:00
@jackw jackw requested a review from mckn January 11, 2024 10:02
Copy link

github-actions bot commented Jan 11, 2024

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new major release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@jackw jackw mentioned this pull request Jan 11, 2024
5 tasks
@jackw jackw added minor Increment the minor version when merged and removed major Increment the major version when merged labels Jan 11, 2024
Copy link
Collaborator

@mckn mckn left a comment

Choose a reason for hiding this comment

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

LGTM! Interesting since I tried to do the same thing with Levitate and manage to get everything working except the jest tests. But then the solution might be to migrate over to vitest.

@jackw
Copy link
Collaborator Author

jackw commented Jan 12, 2024

But then the solution might be to migrate over to vitest.

Probably will make life much easier. Admittedly this is a small project but the Vitest migration was surprisingly straightforward. It was only mocks that needed any attention. Jest and ESM just don't very work well together. 😞

@jackw jackw added major Increment the major version when merged and removed minor Increment the minor version when merged labels Jan 12, 2024
@jackw jackw merged commit eee309a into main Jan 12, 2024
13 checks passed
@jackw jackw deleted the jackw/create-plugin-esm branch January 12, 2024 16:02
@grafana-plugins-platform-bot
Copy link

🚀 PR was released in @grafana/create-plugin@3.0.0 🚀

@grafana-plugins-platform-bot grafana-plugins-platform-bot bot added the released This issue/pull request has been released. label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Other changes that don't modify src or test files major Increment the major version when merged release Create a release when this pr is merged released This issue/pull request has been released.
Projects
Development

Successfully merging this pull request may close these issues.

2 participants