-
Notifications
You must be signed in to change notification settings - Fork 361
Stop bundling _any_ mathquill styles/fonts - let host app do that! #2385
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
Conversation
|
Size Change: +41.6 kB (+9.84%) Total Size: 465 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (60e9460) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2385If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.js -t PR2385 |
…to control bundling and font resolution
2ce7101 to
acf44e1
Compare
…ymbola hash on the SVG font
| @@ -1,2 +1,2 @@ | |||
| @import "./overrides.less"; | |||
| @import (inline) "../node_modules/mathquill/build/mathquill.css"; | |||
| @import "mathquill/build/mathquill.css"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct import syntax to resolve a CSS/Less file out of an dependant npm package.
| "@khanacademy/keypad-context": "workspace:*", | ||
| "@khanacademy/perseus-core": "workspace:*", | ||
| "@khanacademy/perseus-utils": "workspace:*", | ||
| "mathquill": "file:../../vendor/mathquill-v1.0.0.tgz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We move this to be in devDependencies because we now bundle everything from mathquill into @khanacademy/math-input. This relieves client apps from needing to depend on mathquill directly (most client apps don't use mathquill directly if they're using @khanacademy/math-input)
| } | ||
|
|
||
| @import "../../../math-input/less/main.less"; | ||
| @import (reference) "@khanacademy/math-input/styles.css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This becomes a (reference) now to avoid the situation where an app using math-input directly would "double" the math-input CSS because it's integrated into the Perseus CSS also.
This means that consuming apps will need to ensure that math-input CSS is properly imported, but that's a one-line change and allows for deduplication of math-input CSS.
vendor/mathquill-v1.0.2.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the final build yet. I'll bump this PR once more when the Mathquill PR lands and a new release is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just reference the Git tag for the release on Github.
| // note(matthewc): I changed this in a time pinch and I'm not sure | ||
| // it's right so I made a ticket to circle back to it | ||
| // https://khanacademy.atlassian.net/browse/LC-864 | ||
| devDependencies: ["**/*.stories.tsx", "**/*.test.tsx"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@handeyeco Weird. I can remove this in this PR and all linting passes. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR stops bundling Mathquill CSS and font assets with Perseus so that the consuming app manages these resources. Key changes include:
- Removing a devDependencies configuration (and its associated comments) from the ESLint configuration.
- Updating the Rollup configuration to resolve and bundle Mathquill font assets with a custom URL resolver.
- Bumping the version and updating the changeset to document the change.
Reviewed Changes
Copilot reviewed 4 out of 9 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/math-input/.eslintrc.js | Removed extraneous devDependencies configuration and associated comments. |
| config/build/rollup.config.js | Introduced a new resolve function using URL parsing to bundle Mathquill font assets. |
| .changeset/tame-grapes-ring.md | Added version bump and summary for stopping bundled Mathquill CSS/font assets. |
Files not reviewed (5)
- package.json: Language not supported
- packages/math-input/less/main.less: Language not supported
- packages/math-input/package.json: Language not supported
- packages/perseus/src/styles/perseus-renderer.less: Language not supported
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/math-input/.eslintrc.js:10
- Removing the devDependencies configuration might unintentionally affect linting of test and story files if they are not otherwise excluded. Verify that these files are still handled appropriately in the overall ESLint setup.
devDependencies: ["**/*.stories.tsx", "**/*.test.tsx"],
config/build/rollup.config.js
Outdated
| return { | ||
| from: targetFile, | ||
| source: fs.readFileSync(targetFile), |
Copilot
AI
Apr 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for fs.readFileSync to handle cases where a font file may be missing, which would otherwise cause a runtime error during the build.
| return { | |
| from: targetFile, | |
| source: fs.readFileSync(targetFile), | |
| let fileSource; | |
| try { | |
| fileSource = fs.readFileSync(targetFile); | |
| } catch (error) { | |
| console.error(`Error reading file: ${targetFile}`); | |
| console.error(error.message); | |
| throw error; | |
| } | |
| return { | |
| from: targetFile, | |
| source: fileSource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's safe to throw here as Rollup will capture the Error and fail the build with a sensible error.
config/build/rollup.config.js
Outdated
| // Some inputUrl's have a hash (eg. | ||
| // font/Symbola.svg#Symbola). We use the URL object to | ||
| // ensure we only have the file path and nothing else. | ||
| const url = new URL(inputUrl, "http://example.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the URL object here instead of string searching just to ensure we handle things correctly.
| "@storybook/react-vite": "^8.6.11", | ||
| "@swc-node/register": "^1.10.10", | ||
| "@swc/core": "1.11.13", | ||
| "@swc/helpers": "^0.5.17", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw warnings that a few files couldn't resolve this module. I'm not sure why it didn't happen earlier, but adding this to ensure our builds are correct.
jeresig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great - thank you for reworking this, these changes look good to me!
| "@khanacademy/math-input": minor | ||
| --- | ||
|
|
||
| Stop bundling mathquill CSS - enables consuming app to control bundling and font resolution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we need to let Learning Equality know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm a little confused by this changeset. Here you're saying "enables consuming app to control bundling and font resolution" but in the comment below you say "This resolve is for the fonts in Mathquill. We want to bundle them into the math-input package so that consumers of @khanacademy/math-input don't need to also depend on the mathquill package." The two comments seem at odds, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gives consumers control by bundling the Mathquill fonts into the @khanacademy/math-input package complete with correct CSS files point to the bundled font files using relative paths.
The custom resolve was for Mathquill fonts, but after you asked, I found I was able to simplify things and didn't need a custom resolver (the built-in one handles things fine). And that was exactly the motivation for updating Mathquill! Thanks.
| // note(matthewc): I changed this in a time pinch and I'm not sure | ||
| // it's right so I made a ticket to circle back to it | ||
| // https://khanacademy.atlassian.net/browse/LC-864 | ||
| devDependencies: ["**/*.stories.tsx", "**/*.test.tsx"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷
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] ### Major Changes - [#2398](#2398) [`45635f7ef`](45635f7) Thanks [@benchristel](https://github.com/benchristel)! - Remove ReadonlyArray types from `@khanacademy/perseus-core` in favor of mutable arrays. Users should define separate readonly types if desired. ## @khanacademy/[email protected] ### Minor Changes - [#2385](#2385) [`a7f293aab`](a7f293a) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Stop bundling mathquill CSS - enables consuming app to control bundling and font resolution ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#2404](#2404) [`457c9b818`](457c9b8) Thanks [@ivyolamit](https://github.com/ivyolamit)! - Add codeowners for radio widget - Updated dependencies \[[`45635f7ef`](45635f7), [`a7f293aab`](a7f293a)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7), [`457c9b818`](457c9b8), [`a7f293aab`](a7f293a)]: - @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 - Updated dependencies \[[`45635f7ef`](45635f7)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`45635f7ef`](45635f7), [`a7f293aab`](a7f293a)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] Author: khan-actions-bot Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ⏭️ 1 check has been skipped, ✅ 4 checks were successful Pull Request URL: #2405
Summary:
Fixes Perseus so that it doesn't ship Mathquill CSS with absolute font paths (ie
/fonts/Symbola.ttf). This includes a bump to a new version of Mathquill.This PR also updates the
@khanacademy/math-inputpackage to bundle all of mathquill (fonts, CSS, etc). This makes bundling things down the line much simpler. I couldn't find any apps consuming Perseus that actually used Mathquill directly, so this also aligns with that usage (consumer doesn't have to do anything special to accommodate Mathquill).Also verified Storybook loads the Symbola font properly!
Issue: LEMS-3019
Test plan:
Update webapp with a test version of Perseus from this PR.
Build webapp - OK!
Run type checking and tests - OK!
Check webapp CSS and build output to ensure the fonts are "bundled" as assets and the CSS has correct paths for font files - OK!