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

Move version-embed fn and embed in each package #2259

Merged
merged 5 commits into from
Feb 21, 2025
Merged

Conversation

jeremywiebe
Copy link
Collaborator

Summary:

As we are working on Server-Side Scoring, the fact that the addLibraryVersionToPerseusDebug function lived in @khanacdemy/perseus-core was becoming problematic. All packages need to depend on perseus-core because they all need to use this function.

This PR moves the function out to a top-level directory and then each package simply imports it using a relative-path import. This violates our lint rules so we suppress it and because we do this, each package will be a few hundred bytes larger. But it completely eliminates the need for cross-package dependencies just for this one function.

Issue: LEMS-2881

Test plan:

I ran yarn build and inspected the files in each package's dist/ folder. They had the built version number properly embedded in their output. They also had the addLibraryVersionToPerseusDebug function in them (the fn was copied into the bundle successfully).

@jeremywiebe jeremywiebe self-assigned this Feb 20, 2025
Copy link
Contributor

github-actions bot commented Feb 20, 2025

Size Change: +4.58 kB (+0.53%)

Total Size: 871 kB

Filename Size Change
packages/kas/dist/es/index.js 39.5 kB +647 B (+1.66%)
packages/kmath/dist/es/index.js 11.1 kB +624 B (+5.98%) 🔍
packages/math-input/dist/es/index.js 78 kB +442 B (+0.57%)
packages/perseus-core/dist/es/index.js 29.6 kB -17 B (-0.06%)
packages/perseus-editor/dist/es/index.js 276 kB +581 B (+0.21%)
packages/perseus-linter/dist/es/index.js 22.5 kB +561 B (+2.55%)
packages/perseus/dist/es/index.js 368 kB +583 B (+0.16%)
packages/pure-markdown/dist/es/index.js 4.14 kB +605 B (+17.09%) ⚠️
packages/simple-markdown/dist/es/index.js 13.1 kB +559 B (+4.47%)
ℹ️ View Unchanged
Filename Size
packages/keypad-context/dist/es/index.js 760 B
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-score/dist/es/index.js 20.3 kB
packages/perseus/dist/es/strings.js 6.57 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Feb 21, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (29a8812) and published it to npm. You
can install it using the tag PR2259.

Example:

pnpm add @khanacademy/perseus@PR2259

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR2259

@jeremywiebe jeremywiebe marked this pull request as ready for review February 21, 2025 01:04
@jeremywiebe jeremywiebe requested review from benchristel, handeyeco, Myranae and a team February 21, 2025 01:04
@@ -0,0 +1 @@
../../../utils/shared
Copy link
Contributor

@Myranae Myranae Feb 21, 2025

Choose a reason for hiding this comment

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

What do all these files and lines do?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they're symlinks to the utils/shared directory.

My understanding is that he wants to share the logic across packages, but doesn't want the logic to be in a package (to avoid circular dependencies). So each package has a "directory" with the logic, but really the directory is just pointing to a different place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly that. That's how git represents symlinks. By using a directory that's symlinked in... we can share the code, but it's just copied into each bundle instead of being referenced as a package dependency.

Comment on lines +5 to +8
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
// lint suppression is removed, it autofixes the import path to an invalid
// package+path entry.
// eslint-disable-next-line import/no-relative-packages
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if maybe these comments should explain why this is being done since I can imagine something maybe trying to fix this down the road and moving it back to perseus-core. Maybe this PR is enough to prevent that though XD

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I edited these comments to hopefully be clearer. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Looks great :D

Copy link
Contributor

@handeyeco handeyeco left a comment

Choose a reason for hiding this comment

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

Makes sense 🤞

@@ -5,7 +5,6 @@
"rootDir": "src",
},
"references": [
{"path": "../perseus-core/tsconfig-build.json"},
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't need to do this for the other packages that no longer depend on perseus-core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed this for every Package where we no longer depend on @khanacademy/perseus-core (so each package.json has a matched tsconfig-build.json change. :)

@@ -0,0 +1 @@
../../../utils/shared
Copy link
Contributor

Choose a reason for hiding this comment

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

I think they're symlinks to the utils/shared directory.

My understanding is that he wants to share the logic across packages, but doesn't want the logic to be in a package (to avoid circular dependencies). So each package has a "directory" with the logic, but really the directory is just pointing to a different place.

@jeremywiebe jeremywiebe merged commit a90cf79 into main Feb 21, 2025
8 checks passed
@jeremywiebe jeremywiebe deleted the jer/version-embed branch February 21, 2025 18:25
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.

3 participants