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

fix: 🐛 correctly export meta for ESM types #374

Conversation

jimmy-guzman
Copy link
Contributor

Not entirely sure why this is happening, but when we have:

import * as meta from "./meta"

It leads to:

declare const meta: typeof __metadeclare const rules: {
    [key: string]: eslint.Rule.RuleModule;
};

Which leads to a TypeScript error: ',' expected.ts(1005).

Changing it to:

import { name, version } from "./meta"

export const plugin = {
  meta: { name, version },
  environments,
  rules,
  processors,
}

Leads to:

declare const meta: {
    name: string;
    version: string;
};
declare const rules: {
    [key: string]: eslint.Rule.RuleModule;
};

Which should be the correct output.

Copy link

changeset-bot bot commented Apr 30, 2024

🦋 Changeset detected

Latest commit: a9a5bfb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

That's a very interesting bug. It's probably a bug in the bundler, but I agree that we need a workaround.

Could you please add test cases to tests/integration where we can confirm that the correction was made?

@jimmy-guzman
Copy link
Contributor Author

That's a very interesting bug. It's probably a bug in the bundler, but I agree that we need a workaround.

Could you please add test cases to tests/integration where we can confirm that the correction was made?

Yeah I'll look into adding a test. I'll also look into reporting this in tsup or what's powering --dts.

@ota-meshi ota-meshi linked an issue Apr 30, 2024 that may be closed by this pull request
2 tasks
@ota-meshi ota-meshi mentioned this pull request Apr 30, 2024
2 tasks
try {
cp.execSync(`npx tsc`, { cwd: TEST_CWD })

assert.fail("Expect error")
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm. I thought the command should succeed. Was it wrong?

Copy link
Contributor Author

@jimmy-guzman jimmy-guzman Apr 30, 2024

Choose a reason for hiding this comment

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

It is passing but for some reason it's landing on the catch block. I'll take another look.

I know what's happening, i'll update.

Copy link
Owner

@ota-meshi ota-meshi Apr 30, 2024

Choose a reason for hiding this comment

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

Oh, I get it! I was writing the test case incorrectly.
My previously written test case should have been:

      try {
        // ...
        fs.writeFileSync(actualFile, `no error:${res}`)
-        assert.fail("Expect error")
      } catch (e: any) {
        // ...
+        return
      }
+      assert.fail("Expect error")

The only test case we'll probably add is:

    it("should NOT fail when running tsc", () => {
      cp.execSync(`npx tsc`, { cwd: TEST_CWD })
    })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah just realize that as well, pushed a changed.

Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you so much!

@ota-meshi ota-meshi merged commit 1de0fed into ota-meshi:main Apr 30, 2024
8 checks passed
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.

1.1.0 breaks tsc with error TS1005
2 participants