Skip to content

Commit 4bd882b

Browse files
authored
Change version injection to be back in a package (#2322)
## 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). Author: jeremywiebe Reviewers: jeremywiebe, handeyeco Required Reviewers: Approved By: handeyeco Checks: ✅ 8 checks were successful Pull Request URL: #2322
1 parent 0174965 commit 4bd882b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+366
-203
lines changed

.changeset/violet-items-study.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"perseus-build-settings": patch
3+
"@khanacademy/kas": patch
4+
"@khanacademy/keypad-context": patch
5+
"@khanacademy/kmath": patch
6+
"@khanacademy/math-input": patch
7+
"@khanacademy/perseus": patch
8+
"@khanacademy/perseus-core": patch
9+
"@khanacademy/perseus-editor": patch
10+
"@khanacademy/perseus-linter": patch
11+
"@khanacademy/perseus-score": patch
12+
"@khanacademy/perseus-utils": patch
13+
"@khanacademy/pure-markdown": patch
14+
"@khanacademy/simple-markdown": patch
15+
---
16+
17+
Change how version injection code is shared/bundled

config/build/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const createConfig = (
137137
alias({
138138
// We don't use pnpm's workspace:* feature for these because
139139
// then they are marked as external and not bundled (by the
140-
// autoExternals() plugin). For now, this works!
140+
// autoExternal() plugin). For now, this works!
141141
entries: {
142142
hubble: path.join(rootDir, "vendor", "hubble"),
143143
jsdiff: path.join(rootDir, "vendor", "jsdiff"),

packages/kas/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"prepublishOnly": "../../utils/package-pre-publish-check.sh",
2626
"gen:parsers": "node src/parser-generator.ts"
2727
},
28-
"dependencies": {},
28+
"dependencies": {
29+
"@khanacademy/perseus-utils": "workspace:*"
30+
},
2931
"devDependencies": {
3032
"jison": "0.4.15",
3133
"perseus-build-settings": "workspace:*",

packages/kas/src/shared-utils

-1
This file was deleted.

packages/kas/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/kas";
158
export const libVersion = "__lib_version__";

packages/kas/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"rootDir": "src"
66
},
77
"references": [
8+
{"path": "../perseus-utils/tsconfig-build.json"}
89
]
910
}

packages/keypad-context/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
2626
},
2727
"dependencies": {
28-
"@khanacademy/perseus-core": "workspace:*"
28+
"@khanacademy/perseus-core": "workspace:*",
29+
"@khanacademy/perseus-utils": "workspace:*"
2930
},
3031
"devDependencies": {
32+
"perseus-build-settings": "workspace:*",
3133
"react": "catalog:"
3234
},
3335
"peerDependencies": {

packages/keypad-context/src/shared-utils

-1
This file was deleted.

packages/keypad-context/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"rootDir": "src",
66
},
77
"references": [
8-
{"path": "../perseus-core/tsconfig-build.json"}
8+
{"path": "../perseus-core/tsconfig-build.json"},
9+
{"path": "../perseus-utils/tsconfig-build.json"}
910
]
1011
}

packages/kmath/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
2626
},
2727
"dependencies": {
28-
"@khanacademy/perseus-core": "workspace:*"
28+
"@khanacademy/perseus-core": "workspace:*",
29+
"@khanacademy/perseus-utils": "workspace:*"
2930
},
3031
"devDependencies": {
31-
"perseus-build-settings": "workspace:*",
3232
"jquery": "catalog:",
33+
"perseus-build-settings": "workspace:*",
3334
"underscore": "catalog:"
3435
},
3536
"peerDependencies": {

packages/kmath/src/shared-utils

-1
This file was deleted.

packages/kmath/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/kmath";
158
export const libVersion = "__lib_version__";

packages/kmath/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"rootDir": "src",
66
},
77
"references": [
8-
{"path": "../perseus-core/tsconfig-build.json"}
8+
{"path": "../perseus-core/tsconfig-build.json"},
9+
{"path": "../perseus-utils/tsconfig-build.json"}
910
]
1011
}

packages/math-input/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"dependencies": {
4343
"@khanacademy/keypad-context": "workspace:*",
4444
"@khanacademy/perseus-core": "workspace:*",
45+
"@khanacademy/perseus-utils": "workspace:*",
4546
"mathquill": "https://github.com/Khan/mathquill/releases/download/v1.0.0/mathquill-v1.0.0.tgz"
4647
},
4748
"devDependencies": {

packages/math-input/src/shared-utils

-1
This file was deleted.

packages/math-input/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/math-input";
158
export const libVersion = "__lib_version__";

packages/math-input/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"rootDir": "src",
66
},
77
"references": [
8-
{"path": "../perseus-core/tsconfig-build.json"},
98
{"path": "../keypad-context/tsconfig-build.json"},
9+
{"path": "../perseus-core/tsconfig-build.json"},
10+
{"path": "../perseus-utils/tsconfig-build.json"}
1011
]
1112
}

packages/perseus-core/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
2626
},
2727
"dependencies": {
28-
"@khanacademy/kas": "workspace:*"
28+
"@khanacademy/kas": "workspace:*",
29+
"@khanacademy/perseus-utils": "workspace:*"
2930
},
3031
"devDependencies": {
3132
"@khanacademy/wonder-stuff-core": "catalog:",
33+
"perseus-build-settings": "workspace:*",
3234
"underscore": "catalog:"
3335
},
3436
"peerDependencies": {

packages/perseus-core/src/shared-utils

-1
This file was deleted.

packages/perseus-core/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/perseus-core";
158
export const libVersion = "__lib_version__";

packages/perseus-core/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/* Add in-repo pacakge references here, like this:
1616
{"path": "../path/to/package/tsconfig-build.json"}
1717
*/
18-
{"path": "../kas/tsconfig-build.json"}
18+
{"path": "../kas/tsconfig-build.json"},
19+
{"path": "../perseus-utils/tsconfig-build.json"}
1920
]
2021
}

packages/perseus-editor/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@khanacademy/perseus": "workspace:*",
4343
"@khanacademy/perseus-core": "workspace:*",
4444
"@khanacademy/perseus-score": "workspace:*",
45+
"@khanacademy/perseus-utils": "workspace:*",
4546
"@khanacademy/pure-markdown": "workspace:*",
4647
"katex": "0.11.1",
4748
"mafs": "^0.19.0"

packages/perseus-editor/src/shared-utils

-1
This file was deleted.

packages/perseus-editor/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/perseus-editor";
158
export const libVersion = "__lib_version__";

packages/perseus-editor/tsconfig-build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"references": [
1717
{"path": "../kas/tsconfig-build.json"},
1818
{"path": "../kmath/tsconfig-build.json"},
19-
{"path": "../perseus/tsconfig-build.json"},
2019
{"path": "../perseus-core/tsconfig-build.json"},
20+
{"path": "../perseus-utils/tsconfig-build.json"},
21+
{"path": "../perseus/tsconfig-build.json"},
2122
]
2223
}

packages/perseus-linter/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
2626
},
2727
"dependencies": {
28-
"@khanacademy/perseus-core": "workspace:*"
28+
"@khanacademy/perseus-core": "workspace:*",
29+
"@khanacademy/perseus-utils": "workspace:*"
2930
},
3031
"devDependencies": {
3132
"@khanacademy/pure-markdown": "workspace:*",
33+
"perseus-build-settings": "workspace:*",
3234
"prop-types": "catalog:"
3335
},
3436
"peerDependencies": {

packages/perseus-linter/src/shared-utils

-1
This file was deleted.

packages/perseus-linter/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/perseus-linter";
158
export const libVersion = "__lib_version__";

packages/perseus-linter/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"references": [
88
{"path": "../perseus-core/tsconfig-build.json"},
9+
{"path": "../perseus-utils/tsconfig-build.json"},
910
{"path": "../pure-markdown/tsconfig-build.json"},
1011
]
1112
}

packages/perseus-score/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
"dependencies": {
2828
"@khanacademy/kas": "workspace:*",
2929
"@khanacademy/kmath": "workspace:*",
30-
"@khanacademy/perseus-core": "workspace:*"
30+
"@khanacademy/perseus-core": "workspace:*",
31+
"@khanacademy/perseus-utils": "workspace:*"
3132
},
3233
"devDependencies": {
34+
"perseus-build-settings": "workspace:*",
3335
"underscore": "catalog:"
3436
},
3537
"peerDependencies": {

packages/perseus-score/src/shared-utils

-1
This file was deleted.

packages/perseus-score/src/version.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
// version number during the release build.
33
// In dev, you'll never see the version number.
44

5-
// We use a shared, symlinked directory to bring in this function so that we
6-
// don't need to have cross-package dependencies just for a few hundred bytes
7-
// of shared code.
8-
// ESLint's import/no-relative-packages doesn't understand symlinks! If this
9-
// lint suppression is removed, it autofixes the import path to an invalid
10-
// package+path entry.
11-
// eslint-disable-next-line import/no-relative-packages
12-
import {addLibraryVersionToPerseusDebug} from "./shared-utils/add-library-version-to-perseus-debug";
5+
import {addLibraryVersionToPerseusDebug} from "@khanacademy/perseus-utils";
136

147
const libName = "@khanacademy/perseus-score";
158
export const libVersion = "__lib_version__";

packages/perseus-score/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
{"path": "../kas/tsconfig-build.json"},
1616
{"path": "../kmath/tsconfig-build.json"},
1717
{"path": "../perseus-core/tsconfig-build.json"},
18+
{"path": "../perseus-utils/tsconfig-build.json"},
1819
]
1920
}

packages/perseus-utils/.eslintrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/* eslint-disable import/no-commonjs */
3+
const path = require("path");
4+
5+
module.exports = {
6+
rules: {
7+
"import/no-extraneous-dependencies": [
8+
"error",
9+
{
10+
packageDir: [__dirname, path.join(__dirname, "../../")],
11+
includeTypes: true,
12+
},
13+
],
14+
},
15+
};

packages/perseus-utils/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @khanacademy/shared-inline

packages/perseus-utils/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @khanacademy/perseus-utils
2+
3+
This is a container package for utilities that are used by all, or at least
4+
most Perseus packages.
5+
6+
**NOTE**: This package should not depend on any Perseus packages.

packages/perseus-utils/package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@khanacademy/perseus-utils",
3+
"description": "Miscellaneous utilities used by the Khan Academy Perseus ecosystem",
4+
"author": "Khan Academy",
5+
"license": "MIT",
6+
"version": "0.0.1",
7+
"publishConfig": {
8+
"access": "public"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/Khan/perseus.git",
13+
"directory": "packages/perseus-utils"
14+
},
15+
"bugs": {
16+
"url": "https://github.com/Khan/perseus/issues"
17+
},
18+
"module": "dist/es/index.js",
19+
"main": "dist/index.js",
20+
"source": "src/index.ts",
21+
"types": "dist/index.d.ts",
22+
"files": [
23+
"dist"
24+
],
25+
"scripts": {
26+
"prepublishOnly": "../../utils/package-pre-publish-check.sh"
27+
},
28+
"dependencies": {
29+
},
30+
"devDependencies": {
31+
"perseus-build-settings": "workspace:*"
32+
}
33+
}

packages/perseus-utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {addLibraryVersionToPerseusDebug} from "./add-library-version-to-perseus-debug";

0 commit comments

Comments
 (0)