Skip to content

chore: add no-imports-from-self eslint rule to monorepo - #7272

Merged
zurfyx merged 18 commits into
meta:mainfrom
AlessioGr:chore/eslint-no-imports-from-self
Mar 3, 2025
Merged

zurfyx merged 18 commits into
meta:mainfrom
AlessioGr:chore/eslint-no-imports-from-self

Conversation

@AlessioGr

@AlessioGr AlessioGr commented Mar 2, 2025 •

Copy link
Copy Markdown
Contributor

This adds a new no-imports-from-self eslint rule to this monorepo, which will prevent regression of #7271 - cc @etrepum

CleanShot 2025-03-01 at 23 17 16@2x

The rule is taken from here. We cannot install @payloadcms/eslint-plugin directly, as that's an esm-only package which would require us to move to the flat eslint config.

@vercel

vercel Bot commented Mar 2, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 3, 2025 2:56pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 3, 2025 2:56pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 2, 2025

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this needs to be modified a bit to work for this repo.

Tests and private packages (shared, lexical-devtools, lexical-playground) should be excluded from this rule, they aren't a build artifact and shouldn't be subject to these rules.

Type-only imports (import type) shouldn't matter as they are erased and the .d.ts files that are produced are ignored by the runtime (and typescript doesn't have this class of issue).

Comment thread scripts/eslint/no-imports-from-self.js Outdated
@@ -0,0 +1,92 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that this can be accepted without relicensing to carry the meta header

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could you confirm that this can't be accepted if we include both the Payload MIT and Meta MIT license headers? I updated it to mention Payload under Portions Copyright, which I believe should satisfy the MIT requirements given that we share the same license.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don’t work at Meta, am not a lawyer, and haven’t read the CLA recently so I can’t answer that. The PR will probably sit on hold for a while until someone at Meta can figure out whether it’s acceptable or not if it doesn’t follow the standard license header template (even if compliant with MIT). Basically if payload can assign copyright to Meta for this file it will look like everything else and can be approved more quickly.

Comment thread .eslintrc.js Resolved
@etrepum

etrepum commented Mar 2, 2025

Copy link
Copy Markdown
Collaborator

lexical-react is also correct in importing '@lexical/react/X' from '@lexical/react/Y', if these were relative imports then code will be duplicated across the multiple module entrypoints which is not really desirable. The rule should probably be about modules and not packages (although this is currently the only package that has multiple entrypoints so it could be special cased in a fairly straightforward way).

@AlessioGr

AlessioGr commented Mar 2, 2025 •

Copy link
Copy Markdown
Contributor Author

lexical-react is also correct in importing '@lexical/react/X' from '@lexical/react/Y', if these were relative imports then code will be duplicated across the multiple module entrypoints which is not really desirable

Yep, you're right. I tested it, and node seems to handle the @lexical/react/X and @lexical/react/Y self-imports just fine. It appears the problematic self-import in the previous issue might have only caused problems because it was a recursive reference, which isn’t the case for @lexical/react/X, since those bundles are separate.

Interestingly, the same issue occurs with @lexical/code. A few weeks back, I commented about @lexical/markdown breaking if it imports @lexical/code, and I initially thought it was due to Prism. But it turns out it was another self-reference within @lexical/code. This brings a lot of clarity! What a nightmare to debug if it's unclear that the issue stems from self-imports hah

I’m going to open a separate PR to remove the remaining invalid self-imports first, so we can hopefully include those fixes in next week’s release.

@AlessioGr

Copy link
Copy Markdown
Contributor Author

Nevermind that, just saw that the @lexical/code self-import is type-only. The @lexical/code issue occurs because it is importing from lexical, which had that self-import issue. Must have been something unrelated then (although the error message, "Warning: Detected unsettled top-level await at", was the same)

AlessioGr added a commit to payloadcms/payload that referenced this pull request Mar 2, 2025
…s used (#11483)

Our `no-imports-from-self` eslint rule was supposed to cache the package.json name to ensure it doesn't try to find and read the package.json for every single import statement.

Turns out that cache was never used. Credits to @etrepum for [finding this issue](meta/lexical#7272 (comment))
etrepum
etrepum previously approved these changes Mar 3, 2025

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code looks good, waiting for clarification from Meta on the copyright comments

Comment on lines +9 to +14
/**
* From: https://github.com/payloadcms/payload/blob/main/packages/eslint-plugin/customRules/no-imports-from-self.js
* Copyright (c) Payload CMS, Inc. <info@payloadcms.com>
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

@zurfyx zurfyx Mar 3, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's keep it to a liner as we've previously done with other references in this repo that add historical value. I like the fact that we're easily able to trace back to the source (which may be updated over time), given that using the package directly is not viable. Thank you!

Suggested change
/**
* From: https://github.com/payloadcms/payload/blob/main/packages/eslint-plugin/customRules/no-imports-from-self.js
* Copyright (c) Payload CMS, Inc. <info@payloadcms.com>
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// From: https://github.com/payloadcms/payload/blob/main/packages/eslint-plugin/customRules/no-imports-from-self.js

@AlessioGr

AlessioGr commented Mar 3, 2025 •

Copy link
Copy Markdown
Contributor Author

@zurfyx @etrepum

This PR is now updated to only link to the original monorepo + the Payload license header is removed.

Regarding

Since you are representing that you have the copyright to the code you are contributing and are granting that copyright to Meta through the CLA, the license it has elsewhere is not relevant.

I don't have the copyright of the original code, which is why I added the license header - @denolfe is the author and copyright holder of the original eslint rule. He just re-committed that file to this PR and signed to CLA, so as co-author, I believe this should be fine now

@zurfyx

zurfyx commented Mar 3, 2025

Copy link
Copy Markdown
Member

LGTM, thank you Alessio!

@zurfyx
zurfyx enabled auto-merge March 3, 2025 15:49
@zurfyx
zurfyx added this pull request to the merge queue Mar 3, 2025
Merged via the queue into meta:main with commit 6d7b670 Mar 3, 2025
@etrepum etrepum mentioned this pull request Mar 3, 2025

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — d2d39c15 Deployed Mar 3, 2025 by vercel[bot]
Preview – lexical — d2d39c15 Deployed Mar 3, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants