-
Notifications
You must be signed in to change notification settings - Fork 364
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
Changes from 10 commits
dd46e1e
041cf94
244028f
58b47fc
acf44e1
65203fc
357c027
0c069ea
74b367e
6db55ec
9facb1a
9300471
3888003
3d17c26
e3d7f06
0ed73a4
60e9460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@khanacademy/math-input": minor | ||
| --- | ||
|
|
||
| Stop bundling mathquill CSS - enables consuming app to control bundling and font resolution | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||
| /* eslint-disable import/no-commonjs */ | ||||||||||||||||||||||||||||||
| import fs from "fs"; | ||||||||||||||||||||||||||||||
| import {URL} from "node:url"; | ||||||||||||||||||||||||||||||
| import path from "path"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import alias from "@rollup/plugin-alias"; | ||||||||||||||||||||||||||||||
|
|
@@ -149,12 +150,26 @@ const createConfig = ( | |||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||
| styles({ | ||||||||||||||||||||||||||||||
| mode: "extract", | ||||||||||||||||||||||||||||||
| // We don't want to try to resolve the url() occurrences in our | ||||||||||||||||||||||||||||||
| // stylesheets. We'll leave that for consumers of the library | ||||||||||||||||||||||||||||||
| // to deal with. Otherwise we end up packaging upstream assets | ||||||||||||||||||||||||||||||
| // into our libraries when our consumers should be the ones | ||||||||||||||||||||||||||||||
| // handling asset bundling. | ||||||||||||||||||||||||||||||
| url: false, | ||||||||||||||||||||||||||||||
| minimize: true, | ||||||||||||||||||||||||||||||
| url: { | ||||||||||||||||||||||||||||||
| publicPath: "./assets", | ||||||||||||||||||||||||||||||
| // 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. | ||||||||||||||||||||||||||||||
| resolve(inputUrl, baseDir) { | ||||||||||||||||||||||||||||||
| // 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"); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| const targetFile = path.join(baseDir, url.pathname); | ||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||
| from: targetFile, | ||||||||||||||||||||||||||||||
| source: fs.readFileSync(targetFile), | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| 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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| "@storybook/react-vite": "^8.6.11", | ||
| "@swc-node/register": "^1.10.10", | ||
| "@swc/core": "1.11.13", | ||
| "@swc/helpers": "^0.5.17", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| "@swc/jest": "^0.2.37", | ||
| "@testing-library/dom": "^10.3.1", | ||
| "@testing-library/jest-dom": "^6.4.6", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| @import "./overrides.less"; | ||
| @import (inline) "../node_modules/mathquill/build/mathquill.css"; | ||
| @import "mathquill/build/mathquill.css"; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,7 @@ | |
| "dependencies": { | ||
| "@khanacademy/keypad-context": "workspace:*", | ||
| "@khanacademy/perseus-core": "workspace:*", | ||
| "@khanacademy/perseus-utils": "workspace:*", | ||
| "mathquill": "file:../../vendor/mathquill-v1.0.0.tgz" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We move this to be in |
||
| "@khanacademy/perseus-utils": "workspace:*" | ||
| }, | ||
| "devDependencies": { | ||
| "@khanacademy/mathjax-renderer": "catalog:", | ||
|
|
@@ -57,6 +56,7 @@ | |
| "aphrodite": "catalog:", | ||
| "jquery": "catalog:", | ||
| "katex": "0.11.1", | ||
| "mathquill": "file:../../vendor/mathquill-v1.0.2.tgz", | ||
| "perseus-build-settings": "workspace:*", | ||
| "prop-types": "catalog:", | ||
| "react": "catalog:", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -714,4 +714,4 @@ div.graphie { | |
| padding-top: 0; | ||
| } | ||
|
|
||
| @import "../../../math-input/less/main.less"; | ||
| @import (reference) "@khanacademy/math-input/styles.css"; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This becomes a 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. |
||
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-inputpackage 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.