Skip to content

feat: use dev/prod conditions instead of webpack in exports#5858

Merged
acywatson merged 5 commits intofacebook:mainfrom
etrepum:forkless-exports
Apr 14, 2024
Merged

feat: use dev/prod conditions instead of webpack in exports#5858
acywatson merged 5 commits intofacebook:mainfrom
etrepum:forkless-exports

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Apr 9, 2024

Replace the "webpack" condition in package.json exports with "development" and "production" to make it easier to skip consideration of the fork module. Before this change, there was no metadata that pointed directly to the dev or prod artifacts.

See also: https://webpack.js.org/guides/package-exports/#optimizations

Not quite sure if rollup, vite, etc. support this condition without configuration but they have been demonstrated to work with the fork module as-is.

I was also thinking that this would be useful for CDN usage (as one would want with #5840) since esm.sh supports conditions (Development Mode)

I also noticed the size-limit action was failing so I added some custom configuration that I think should be easier to maintain. I also changed it to run build-prod instead of build so we are measuring the artifact that matters.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 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 Apr 10, 2024 9:48pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2024 9:48pm

@etrepum
Copy link
Copy Markdown
Collaborator Author

etrepum commented Apr 9, 2024

As far as I can tell the failure is a flaky collab test. It didn't repro locally on my mac

const path = require('node:path');
const fs = require('fs-extra');

const alias = Object.fromEntries(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pls add comment that explains purpose of this file.
Also can you pls elaborate on why we replace simple config from package.json with this fairly complex file?

Copy link
Copy Markdown
Collaborator Author

@etrepum etrepum Apr 10, 2024

Choose a reason for hiding this comment

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

It never really worked correctly, outside of the main lexical package anyway, so that's one reason! :)

When checking the size of @lexical/rich-text or @lexical/plain-text it would have to pull in whatever lexical package was in node_modules (plus their other monorepo dependencies like @lexical/clipboard), which would be some previously published version.

The other reason is that it simply didn't work with the simpler configuration. I don't know why or when it stopped working, but that was the primary motivation. I only discovered it was often wrong even in the best of times when I investigated further.

};
}

module.exports = ['lexical', '@lexical/rich-text', '@lexical/plain-text'].map(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why only these 3 packages? Can we discover them based on the config property in their dirs/package.json? We already do glob here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think that would be an @fantactuka question (size-limit was introduced in #3600), these were the only modules measured in the previous configuration. Now that we do have more infrastructure to support this size-limit tool we have more options but the measurements are only useful if people care about them and I don't know what the team cares about especially because there is no configured limits such that the build would fail.

"postversion": "git checkout -b ${npm_package_version}__release && npm install && npm run update-version && npm run update-changelog && git add -A && git commit -m v${npm_package_version} && git tag -a v${npm_package_version} -m v${npm_package_version}",
"release": "npm run prepare-release && node ./scripts/npm/release.js",
"size": "npm run build && size-limit"
"size": "npm run build-prod && size-limit"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Previously, the size measurements were done using the dev build! If we wanted to measure both dev and prod we would change this to build-release. If we use build-release here as-is it would take slightly longer and still use the prod build (through the fork module) so there's no reason to do that now unless we want to start measuring both.

Copy link
Copy Markdown
Contributor

@StyleT StyleT left a comment

Choose a reason for hiding this comment

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

LGTM! I will give others opportunity to review and merge

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