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(build): clean up of build-www rewriteImports (follow-up to #5995) #5999

Merged
merged 3 commits into from
May 2, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented May 1, 2024

Description

Follow-up to #5995, while this fix worked it was not as clean as it should be and probably shouldn't pass flow type checks if it was analyzed. I did a little more digging and I found a more correct incantation, but it could probably still use some improvement if there is a hermes-transform expert around.

Test plan

Before

node ./scripts/www/rewriteImports.js rewrites flow files correctly (using sketchy code)

After

node ./scripts/www/rewriteImports.js rewrites flow files correctly (using slightly better code)

Copy link

vercel bot commented May 1, 2024

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 May 1, 2024 11:15pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 11:15pm

@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 May 1, 2024
Comment on lines 54 to 63
// This is mutated in-place because I couldn't find a mutation that
// did not fail for replacing the Program node.
node.docblock.comment.value = node.docblock.comment.value.replace(
/ \* @flow strict/g,
' * @flow strict\n * @generated\n * @oncall lexical_web_text_editor',
);
// Let the transform know we actually did something.
// Could not figure out the right way to update the
// docblock without an in-place update
context.addLeadingComments(node, '');
// We need the mutations array to be non-empty, so remove something
// that is not there. The AST traversals use object identity in a
// Set so we don't have to worry about some other line changing.
context.removeComments(t.LineComment({value: ''}));
Copy link
Member

Choose a reason for hiding this comment

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

Yeah sorry mutating the program node is not really supported atm, i have a task to fix it. Your solution looks roughly reasonable. The other maybe more correct (but still not ideal) solution is to find the doc block comment within the program. It will be attached to the first statement of the program, then you can use the standard comment remove and add API's.

acywatson
acywatson previously approved these changes May 1, 2024
@etrepum
Copy link
Collaborator Author

etrepum commented May 1, 2024

I'll take a look at that approach and write some unit tests

@acywatson acywatson merged commit 6bb75a4 into facebook:main May 2, 2024
45 of 46 checks passed
@etrepum etrepum deleted the rewriteImports-cleaner-fix branch May 2, 2024 00:09
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.

4 participants