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

Change version injection to be back in a package #2322

Merged
merged 19 commits into from
Mar 26, 2025

Conversation

jeremywiebe
Copy link
Collaborator

@jeremywiebe jeremywiebe commented Mar 21, 2025

Summary:

A while ago, we decided it would be useful to inject the built version of each package into the package itself. This getrs surfaced on the __perseus_debug__ object attached to the window (globalThis) object at runtime. This is handy!

Originally we implemented it in @khanacademy/perseus-core as that was a small, no-deps package. Over time, we've started moving more and more functionality into perseus-core (especially as part of server-side scoring). This ended up causing a circular dependency.

To solve this, we moved the injection code inot the /utils folder and symlinking it into each package. That worked... until we needed to enable the Typescript parser for eslint (see: typescript-eslint/typescript-eslint#2987).

So this PR changes things once more. I've re-introduced a package which we can use for small, focused utilities. I know utils can sometimes become dumping grounds, but we can also be disciplined. :)

Issue: --none--

Test plan:

Run pnpm build

Build size check is stable (in fact, the bundles shrink a bit because things aren't integrated/bundled until the consuming app bundles things now).

@jeremywiebe jeremywiebe self-assigned this Mar 21, 2025
Copy link
Contributor

github-actions bot commented Mar 21, 2025

Size Change: -4.4 kB (-0.6%)

Total Size: 732 kB

Filename Size Change
packages/kas/dist/es/index.js 39 kB -644 B (-1.62%)
packages/kmath/dist/es/index.js 10.5 kB -620 B (-5.57%)
packages/math-input/dist/es/index.js 77 kB -478 B (-0.62%)
packages/perseus-core/dist/es/index.js 31.6 kB -592 B (-1.84%)
packages/perseus-editor/dist/es/index.js 135 kB -585 B (-0.43%)
packages/perseus-linter/dist/es/index.js 22.2 kB -552 B (-2.42%)
packages/perseus/dist/es/index.js 369 kB -575 B (-0.16%)
packages/pure-markdown/dist/es/index.js 3.54 kB -604 B (-14.58%) 👏
packages/simple-markdown/dist/es/index.js 12.5 kB -558 B (-4.27%)
packages/perseus-utils/dist/es/index.js 809 B +809 B (new file) 🆕
ℹ️ 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.6 kB
packages/perseus/dist/es/strings.js 6.74 kB

compressed-size-action

@@ -29,6 +29,8 @@
},
"devDependencies": {
"@khanacademy/pure-markdown": "workspace:*",
"perseus-build-settings": "workspace:*",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was missing the build-settings dep, which it should have!

@jeremywiebe jeremywiebe requested a review from a team March 21, 2025 20:56
@jeremywiebe jeremywiebe marked this pull request as ready for review March 21, 2025 20:57
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.

Thanks for looking into this! Couple of thoughts:

  1. The bundle sizes seemed to get bigger (perseus-editor grew 3MB?) which makes me think there's a bug here
  2. I worry about the long-term maintainability of this; it feels like we're doing back flips trying to avoid copy/pasting ~50 lines of code
  3. Are people using this feature? Do people know about this feature?
  4. What if one of us just made an npm package that handled this for us; it could be an index.js file and a index.test.js file living in npm that we could depend on. Could that help us reduce the complexity in Perseus?

Open to push-back and will approve after you double-check the bundle size alerts, but I'm feeling like this feature is drifting from the KISS principle.

Copy link
Contributor

github-actions bot commented Mar 25, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2322

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

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

@jeremywiebe jeremywiebe requested review from handeyeco and a team March 25, 2025 22:23
@tatianasnook
Copy link
Contributor

How does moving this logic to a package fix the ESLint issue?

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.

I like it, thanks Jeremy!

"@khanacademy/perseus-core": "workspace:*"
"@khanacademy/perseus-core": "workspace:*",
"@khanacademy/perseus-utils": "workspace:*",
"perseus-build-settings": "workspace:*"
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that sometimes this is a dev dep and here it's a regular dep. Is one preferred over the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

purseus-build-settings should be a dev dep! I'll review and fix where it's wrong.

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 also caught one of perseus-utils in the wrong spot and fixed that too!

# @khanacademy/perseus-utils

This is a container package for utilities that are used by all, or at least
most Perseus packages.
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth mentioning that it can't depend on other Perseus packages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a note!

"directory": "packages/perseus-utils"
},
"bugs": {
"url": "https://github.com/Khan/perseus/issues"
Copy link
Contributor

Choose a reason for hiding this comment

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

Random thought: do we even have the issues tab enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do! Not sure that's good or bad. I'll leave this here for now. :)

@jeremywiebe jeremywiebe merged commit 4bd882b into main Mar 26, 2025
8 checks passed
@jeremywiebe jeremywiebe deleted the jer/version-inject-pkg branch March 26, 2025 17:20
@jeremywiebe
Copy link
Collaborator Author

How does moving this logic to a package fix the ESLint issue?

Previously, this shared logic was included in each package's source tree as a symlinked folder. (bug report)

This PR changes things so that the shared code is in a regular npm package that all of the other packages use.

ivyolamit pushed a commit that referenced this pull request Mar 26, 2025
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2328](#2328) [`5b6e9df5b`](5b6e9df) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix import of internal items to use relative paths instead of the package name


-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2296](#2296) [`7b76274f0`](7b76274) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Fix expression widget styling issues. Close button focus outline is now visible, backspace button styling is now consistent with other buttons, and adjusted the popover padding.


-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2296](#2296) [`7b76274f0`](7b76274) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Fix expression widget styling issues. Close button focus outline is now visible, backspace button styling is now consistent with other buttons, and adjusted the popover padding.


-   [#2301](#2301) [`11a3b8b24`](11a3b8b) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Fix number line input outline to meet accessible contrast standards


-   [#2328](#2328) [`5b6e9df5b`](5b6e9df) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix import of internal items to use relative paths instead of the package name


-   [#2326](#2326) [`2e26c0872`](2e26c08) Thanks [@nishasy](https://github.com/nishasy)! - [SR] Remove instructions for static graphs, mark interactive elements as disabled


-   [#2324](#2324) [`7a60db8e8`](7a60db8) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Adding roles to the Image Widget to help improve A11Y.


-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`7b76274f0`](7b76274), [`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2328](#2328) [`5b6e9df5b`](5b6e9df) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix import of internal items to use relative paths instead of the package name


-   [#2321](#2321) [`ca06cb806`](ca06cb8) Thanks [@benchristel](https://github.com/benchristel)! - Allow `itemDataVersion` to be null when parsing Perseus assessment item JSON


-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`7b76274f0`](7b76274), [`11a3b8b24`](11a3b8b), [`5b6e9df5b`](5b6e9df), [`2e26c0872`](2e26c08), [`7a60db8e8`](7a60db8), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2328](#2328) [`5b6e9df5b`](5b6e9df) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix import of internal items to use relative paths instead of the package name


-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

-   Updated dependencies \[[`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]

## [email protected]

### Patch Changes

-   [#2322](#2322) [`4bd882b43`](4bd882b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change how version injection code is shared/bundled

## @khanacademy/[email protected]

### Patch Changes

-   Updated dependencies \[[`7b76274f0`](7b76274), [`5b6e9df5b`](5b6e9df), [`ca06cb806`](ca06cb8), [`4bd882b43`](4bd882b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

Author: khan-actions-bot

Reviewers: ivyolamit

Required Reviewers:

Approved By: ivyolamit

Checks: ⏭️  1 check has been skipped, ✅ 4 checks were successful

Pull Request URL: #2330
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