Skip to content

Commit

Permalink
Move version-embed fn and embed in each package (#2259)
Browse files Browse the repository at this point in the history
## 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).

Author: jeremywiebe

Reviewers: Myranae, handeyeco, jeremywiebe, benchristel

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x)

Pull Request URL: #2259
  • Loading branch information
jeremywiebe authored Feb 21, 2025
1 parent 08409c6 commit a90cf79
Show file tree
Hide file tree
Showing 32 changed files with 107 additions and 32 deletions.
14 changes: 14 additions & 0 deletions .changeset/famous-badgers-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@khanacademy/kas": patch
"@khanacademy/kmath": patch
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
"@khanacademy/perseus-core": patch
"@khanacademy/perseus-editor": patch
"@khanacademy/perseus-linter": patch
"@khanacademy/perseus-score": patch
"@khanacademy/pure-markdown": patch
"@khanacademy/simple-markdown": patch
---

Minor change to how each package embeds it's package version in itself (slightly larger bundle size)
4 changes: 1 addition & 3 deletions packages/kas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
"gen:parsers": "node src/parser-generator.ts"
},
"dependencies": {
"@khanacademy/perseus-core": "workspace:*"
},
"dependencies": {},
"devDependencies": {
"jison": "0.4.15",
"perseus-build-settings": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/kas/src/shared-utils
9 changes: 8 additions & 1 deletion packages/kas/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/kas";
export const libVersion = "__lib_version__";
Expand Down
1 change: 0 additions & 1 deletion packages/kas/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"rootDir": "src"
},
"references": [
{"path": "../perseus-core/tsconfig-build.json"}
]
}
1 change: 1 addition & 0 deletions packages/keypad-context/src/shared-utils
1 change: 1 addition & 0 deletions packages/kmath/src/shared-utils
9 changes: 8 additions & 1 deletion packages/kmath/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/kmath";
export const libVersion = "__lib_version__";
Expand Down
1 change: 1 addition & 0 deletions packages/math-input/src/shared-utils
9 changes: 8 additions & 1 deletion packages/math-input/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/math-input";
export const libVersion = "__lib_version__";
Expand Down
2 changes: 0 additions & 2 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type {ErrorKind} from "./error/errors";
export type {FunctionTypeMappingKeys} from "./utils/grapher-util";
export type {Coords} from "./utils/grapher-types";

// Careful, `version.ts` uses this function so it _must_ be imported above it
export {addLibraryVersionToPerseusDebug} from "./utils/add-library-version-to-perseus-debug";
export {default as getMatrixSize} from "./utils/get-matrix-size";
export {default as getDecimalSeparator} from "./utils/get-decimal-separator";
export {approximateEqual, approximateDeepEqual} from "./utils/equality";
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-core/src/shared-utils
9 changes: 8 additions & 1 deletion packages/perseus-core/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "./utils/add-library-version-to-perseus-debug";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/perseus-core";
export const libVersion = "__lib_version__";
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-editor/src/shared-utils
9 changes: 8 additions & 1 deletion packages/perseus-editor/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/perseus-editor";
export const libVersion = "__lib_version__";
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-linter/src/shared-utils
9 changes: 8 additions & 1 deletion packages/perseus-linter/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/perseus-linter";
export const libVersion = "__lib_version__";
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-score/src/shared-utils
9 changes: 8 additions & 1 deletion packages/perseus-score/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/perseus-score";
export const libVersion = "__lib_version__";
Expand Down
1 change: 1 addition & 0 deletions packages/perseus/src/shared-utils
9 changes: 8 additions & 1 deletion packages/perseus/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/perseus";
export const libVersion = "__lib_version__";
Expand Down
1 change: 0 additions & 1 deletion packages/pure-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
},
"dependencies": {
"@khanacademy/perseus-core": "workspace:*",
"@khanacademy/simple-markdown": "workspace:*"
},
"devDependencies": {},
Expand Down
1 change: 1 addition & 0 deletions packages/pure-markdown/src/shared-utils
9 changes: 8 additions & 1 deletion packages/pure-markdown/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/pure-markdown";
export const libVersion = "__lib_version__";
Expand Down
1 change: 0 additions & 1 deletion packages/pure-markdown/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"rootDir": "src",
},
"references": [
{"path": "../perseus-core/tsconfig-build.json"},
{"path": "../simple-markdown/tsconfig-build.json"},
]
}
4 changes: 1 addition & 3 deletions packages/simple-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"scripts": {
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
},
"dependencies": {
"@khanacademy/perseus-core": "workspace:*"
},
"dependencies": {},
"devDependencies": {
"perseus-build-settings": "workspace:*"
},
Expand Down
1 change: 1 addition & 0 deletions packages/simple-markdown/src/shared-utils
9 changes: 8 additions & 1 deletion packages/simple-markdown/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// version number during the release build.
// In dev, you'll never see the version number.

import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-core";
// We use a shared, symlinked directory to bring in this function so that we
// don't need to have cross-package dependencies just for a few hundred bytes
// of shared code.
// 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
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";

const libName = "@khanacademy/simple-markdown";
export const libVersion = "__lib_version__";
Expand Down
1 change: 0 additions & 1 deletion packages/simple-markdown/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"rootDir": "src",
},
"references": [
{"path": "../perseus-core/tsconfig-build.json"},
]
}
10 changes: 0 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a90cf79

Please sign in to comment.