Skip to content

Switch to ESM#366

Merged
vladislavarsenev merged 12 commits into
trivago:v6from
RobbieTheWagner:esm
Jul 9, 2025
Merged

Switch to ESM#366
vladislavarsenev merged 12 commits into
trivago:v6from
RobbieTheWagner:esm

Conversation

@RobbieTheWagner
Copy link
Copy Markdown
Contributor

CJS has some issues, so this attempts to convert everything to be ESM compatible.

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

@byara @ayusharma what do you think about these changes? There are several pieces needed for this plugin to be able to consume an ESM only prettier plugin, so I am trying to break all the pieces into their own PRs for easier review.

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

Now that I am looking at this, it seems a lot of the snapshots changed, so I suppose sorting might not be working anymore 🤔

@byara byara requested a review from vladislavarsenev June 30, 2025 12:53
@byara
Copy link
Copy Markdown
Collaborator

byara commented Jun 30, 2025

Hey @vladislavarsenev could you please take a look here?

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

@vladislavarsenev I seem to have done something wrong here, as all the snapshots seem to have updated and the imports are no longer sorted. Please let me know if you have ideas to get things working again.

@vladislavarsenev
Copy link
Copy Markdown
Collaborator

@vladislavarsenev I seem to have done something wrong here, as all the snapshots seem to have updated and the imports are no longer sorted. Please let me know if you have ideas to get things working again.

Hi @RobbieTheWagner. Thank you for your effort! It seems, prettier failed in resolving plugin properly. It sees module, but cannot access default export.

inside test-setup/run_spec.cjs try to resolve plugin for prettier.

const plugin = require('../src');

function run_spec(dirname, parsers, options) {
    options = Object.assign(
        {
            plugins: [plugin.default],
            tabWidth: 4,
        },
        options,
    );

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

@vladislavarsenev ah, that worked, thank you! It looks like all the snapshots now correctly show being renamed, but no other changes. Would you mind giving this a review? Happy to make any tweaks required to get this in.

Comment thread tsconfig.json Outdated
Comment thread src/preprocessors/svelte-preprocessor.ts
Comment thread src/preprocessors/svelte-preprocessor.ts Outdated
@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

@vladislavarsenev I reverted that file, but it still seems to not be sorting for svelte. Not sure why. Any ideas?

@vladislavarsenev
Copy link
Copy Markdown
Collaborator

@vladislavarsenev I reverted that file, but it still seems to not be sorting for svelte. Not sure why. Any ideas?

Sorry for long delay in answer. The issue was the same as previously.

in tests/Svelte/ppsi.spec.cjs you need to fix path to plugin. It was needed due to the specific order that is needed specifically for Svelte.

const plugin = require('../../src');

run_spec(__dirname, ["svelte"], {
    importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '^[./]'],
    importOrderSeparation: true,
    plugins: ['prettier-plugin-svelte', plugin.default],
    overrides: [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
});

That should work.

Jest doesn't handle ESM well, I'd rather switch to Vite someday, as it is faster and supports ESM out of the box.

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

Ah thank you @vladislavarsenev! Svelte files seem to sort correctly now! Is there anything else we need to get this in?

@vladislavarsenev
Copy link
Copy Markdown
Collaborator

@RobbieTheWagner Looks good to me! Thank you

@vladislavarsenev vladislavarsenev changed the base branch from main to v6 July 4, 2025 07:52
@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

Awesome, thanks for your help @vladislavarsenev! Please feel free to merge whenever you can and I can rebase my other PRs.

@RobbieTheWagner
Copy link
Copy Markdown
Contributor Author

@vladislavarsenev @byara any chance we could get this merged? It would be ideal to have it in and be able to rebase my other PRs before continuing on them.

@byara
Copy link
Copy Markdown
Collaborator

byara commented Jul 9, 2025

@vladislavarsenev @byara any chance we could get this merged? It would be ideal to have it in and be able to rebase my other PRs before continuing on them.

We will try to merge and release this soon 👍

@vladislavarsenev vladislavarsenev merged commit 5aa0a76 into trivago:v6 Jul 9, 2025
3 checks passed
@RobbieTheWagner RobbieTheWagner deleted the esm branch July 9, 2025 11:45
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.

4 participants