@openedx/frontend-base 1.0.0-alpha.5 → 1.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/config/eslint/base.eslint.config.js +0 -1
  2. package/config/webpack/common-config/all/getStylesheetRule.js +1 -1
  3. package/config/webpack/webpack.config.build.js +0 -11
  4. package/config/webpack/webpack.config.dev.js +0 -11
  5. package/config/webpack/webpack.config.dev.shell.js +0 -11
  6. package/package.json +4 -3
  7. package/runtime/config/index.ts +2 -3
  8. package/runtime/react/SiteProvider.tsx +26 -3
  9. package/runtime/react/constants.ts +3 -0
  10. package/runtime/react/hooks/index.ts +8 -0
  11. package/runtime/react/hooks/theme/index.ts +2 -0
  12. package/runtime/react/hooks/theme/useTheme.test.ts +221 -0
  13. package/runtime/react/hooks/theme/useTheme.ts +179 -0
  14. package/runtime/react/hooks/theme/useThemeConfig.test.ts +107 -0
  15. package/runtime/react/hooks/theme/useThemeConfig.ts +34 -0
  16. package/runtime/react/hooks/theme/useThemeCore.test.ts +65 -0
  17. package/runtime/react/hooks/theme/useThemeCore.ts +52 -0
  18. package/runtime/react/hooks/theme/useThemeVariants.test.ts +97 -0
  19. package/runtime/react/hooks/theme/useThemeVariants.ts +116 -0
  20. package/runtime/react/hooks/theme/useTrackColorSchemeChoice.test.ts +54 -0
  21. package/runtime/react/hooks/theme/useTrackColorSchemeChoice.ts +30 -0
  22. package/runtime/react/hooks/theme/utils.ts +11 -0
  23. package/runtime/react/hooks/useActiveRoles.ts +15 -0
  24. package/runtime/react/hooks/useActiveRouteRoleWatcher.ts +31 -0
  25. package/runtime/react/hooks/useAppConfig.ts +9 -0
  26. package/runtime/react/hooks/useAuthenticatedUser.test.tsx +41 -0
  27. package/runtime/react/hooks/useAuthenticatedUser.ts +9 -0
  28. package/runtime/react/hooks/useSiteConfig.test.tsx +13 -0
  29. package/runtime/react/hooks/useSiteConfig.ts +9 -0
  30. package/runtime/react/hooks/useSiteEvent.ts +24 -0
  31. package/runtime/react/reducers.ts +40 -0
  32. package/runtime/setupTest.js +0 -35
  33. package/runtime/slots/widget/iframe/hooks.ts +1 -1
  34. package/runtime/testing/initializeMockApp.ts +5 -0
  35. package/shell/app.scss +2 -1
  36. package/shell/setupTest.js +0 -35
  37. package/tools/dist/eslint/base.eslint.config.js +0 -1
  38. package/tools/dist/webpack/common-config/all/getStylesheetRule.js +1 -1
  39. package/tools/dist/webpack/webpack.config.build.js +0 -11
  40. package/tools/dist/webpack/webpack.config.dev.js +0 -11
  41. package/tools/dist/webpack/webpack.config.dev.shell.js +0 -11
  42. package/types.ts +20 -0
  43. package/config/webpack/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.js +0 -108
  44. package/config/webpack/plugins/paragon-webpack-plugin/index.js +0 -7
  45. package/config/webpack/plugins/paragon-webpack-plugin/utils/assetUtils.js +0 -64
  46. package/config/webpack/plugins/paragon-webpack-plugin/utils/htmlUtils.js +0 -53
  47. package/config/webpack/plugins/paragon-webpack-plugin/utils/index.js +0 -9
  48. package/config/webpack/plugins/paragon-webpack-plugin/utils/paragonStylesheetUtils.js +0 -114
  49. package/config/webpack/plugins/paragon-webpack-plugin/utils/scriptUtils.js +0 -146
  50. package/config/webpack/plugins/paragon-webpack-plugin/utils/stylesheetUtils.js +0 -126
  51. package/config/webpack/plugins/paragon-webpack-plugin/utils/tagUtils.js +0 -57
  52. package/config/webpack/types.js +0 -2
  53. package/config/webpack/utils/paragonUtils.js +0 -138
  54. package/runtime/react/hooks.test.jsx +0 -104
  55. package/runtime/react/hooks.ts +0 -106
  56. package/tools/dist/webpack/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.js +0 -108
  57. package/tools/dist/webpack/plugins/paragon-webpack-plugin/index.js +0 -7
  58. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/assetUtils.js +0 -64
  59. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/htmlUtils.js +0 -53
  60. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/index.js +0 -9
  61. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/paragonStylesheetUtils.js +0 -114
  62. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/scriptUtils.js +0 -146
  63. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/stylesheetUtils.js +0 -126
  64. package/tools/dist/webpack/plugins/paragon-webpack-plugin/utils/tagUtils.js +0 -57
  65. package/tools/dist/webpack/types.js +0 -2
  66. package/tools/dist/webpack/utils/paragonUtils.js +0 -138
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.insertScriptContentsIntoDocument = insertScriptContentsIntoDocument;
37
- exports.addToScriptContents = addToScriptContents;
38
- exports.generateScriptContents = generateScriptContents;
39
- const parse5 = __importStar(require("parse5"));
40
- const webpack_1 = require("webpack");
41
- const tagUtils_1 = require("./tagUtils");
42
- /**
43
- * Finds the insertion point for a script in an HTML document.
44
- *
45
- * @param {Object} options - The options object.
46
- * @param {Object} options.document - The parsed HTML document.
47
- * @param {string} options.originalSource - The original source code of the HTML document.
48
- * @throws {Error} If the body element is missing in the HTML document.
49
- * @return {number} The insertion point for the script in the HTML document.
50
- */
51
- function findScriptInsertionPoint({ document, originalSource }) {
52
- const bodyElement = (0, tagUtils_1.getDescendantByTag)(document, 'body');
53
- if (!bodyElement) {
54
- throw new Error('Missing body element in index.html.');
55
- }
56
- // determine script insertion point
57
- if (bodyElement.sourceCodeLocation?.endTag) {
58
- return bodyElement.sourceCodeLocation.endTag.startOffset;
59
- }
60
- // less accurate fallback
61
- return originalSource.indexOf('</body>');
62
- }
63
- /**
64
- * Inserts the given script contents into the HTML document and returns a new source with the modified content.
65
- *
66
- * @param {Object} options - The options object.
67
- * @param {string} options.originalSource - The original HTML source.
68
- * @param {Object} options.scriptContents - The contents of the script to be inserted.
69
- * @return {sources.ReplaceSource} The new source with the modified HTML content.
70
- */
71
- function insertScriptContentsIntoDocument({ originalSource, scriptContents, }) {
72
- // parse file as html document
73
- const document = parse5.parse(originalSource, {
74
- sourceCodeLocationInfo: true,
75
- });
76
- // find the body element
77
- const scriptInsertionPoint = findScriptInsertionPoint({
78
- document,
79
- originalSource,
80
- });
81
- // create Paragon script to inject into the HTML document
82
- const paragonScript = `<script type="text/javascript">var PARAGON_THEME = ${JSON.stringify(scriptContents, null, 2)};</script>`;
83
- // insert the Paragon script into the HTML document
84
- const newSource = new webpack_1.sources.ReplaceSource(new webpack_1.sources.RawSource(originalSource), 'index.html');
85
- newSource.insert(scriptInsertionPoint, (0, tagUtils_1.minifyScript)(paragonScript));
86
- return newSource;
87
- }
88
- /**
89
- * Creates an object with the provided version, defaults, coreCssAsset, and themeVariantCssAssets
90
- * and returns it. The returned object has the following structure:
91
- * {
92
- * version: The provided version,
93
- * themeUrls: {
94
- * core: The provided coreCssAsset,
95
- * variants: The provided themeVariantCssAssets,
96
- * defaults: The provided defaults
97
- * }
98
- * }
99
- *
100
- * @param {Object} options - The options object.
101
- * @param {string} options.version - The version to be added to the returned object.
102
- * @param {Object} options.defaults - The defaults to be added to the returned object.
103
- * @param {Object} options.coreCssAsset - The coreCssAsset to be added to the returned object.
104
- * @param {Object} options.themeVariantCssAssets - The themeVariantCssAssets to be added to the returned object.
105
- * @return {Object} The object with the provided version, defaults, coreCssAsset, and themeVariantCssAssets.
106
- */
107
- function addToScriptContents({ version, defaults, coreCssAsset, themeVariantCssAssets, }) {
108
- return {
109
- version,
110
- themeUrls: {
111
- core: coreCssAsset,
112
- variants: themeVariantCssAssets,
113
- defaults,
114
- },
115
- };
116
- }
117
- /**
118
- * Generates the script contents object based on the provided assets and versions.
119
- *
120
- * @param {Object} options - The options object.
121
- * @param {Object} options.paragonCoreCssAsset - The asset for the Paragon core CSS.
122
- * @param {Object} options.paragonThemeVariantCssAssets - The assets for the Paragon theme variants.
123
- * @param {Object} options.brandCoreCssAsset - The asset for the brand core CSS.
124
- * @param {Object} options.brandThemeVariantCssAssets - The assets for the brand theme variants.
125
- * @param {Object} options.paragonThemeCss - The Paragon theme CSS.
126
- * @param {string} options.paragonVersion - The version of the Paragon theme.
127
- * @param {Object} options.brandThemeCss - The brand theme CSS.
128
- * @param {string} options.brandVersion - The version of the brand theme.
129
- * @return {Object} The script contents object.
130
- */
131
- function generateScriptContents({ paragonCoreCssAsset, paragonThemeVariantCssAssets, brandCoreCssAsset, brandThemeVariantCssAssets, paragonThemeCss, paragonVersion, brandThemeCss, brandVersion, }) {
132
- const scriptContents = {};
133
- scriptContents.paragon = addToScriptContents({
134
- version: paragonVersion,
135
- coreCssAsset: paragonCoreCssAsset,
136
- themeVariantCssAssets: paragonThemeVariantCssAssets,
137
- defaults: paragonThemeCss?.defaults,
138
- });
139
- scriptContents.brand = addToScriptContents({
140
- version: brandVersion,
141
- coreCssAsset: brandCoreCssAsset,
142
- themeVariantCssAssets: brandThemeVariantCssAssets,
143
- defaults: brandThemeCss?.defaults,
144
- });
145
- return scriptContents;
146
- }
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.findStylesheetInsertionPoint = findStylesheetInsertionPoint;
37
- exports.insertStylesheetsIntoDocument = insertStylesheetsIntoDocument;
38
- const parse5 = __importStar(require("parse5"));
39
- const webpack_1 = require("webpack");
40
- const tagUtils_1 = require("./tagUtils");
41
- /**
42
- * Finds the insertion point for a stylesheet in an HTML document.
43
- *
44
- * @param {Object} options - The options object.
45
- * @param {Object} options.document - The parsed HTML document.
46
- * @param {string} options.source - The original source code of the HTML document.
47
- * @throws {Error} If the head element is missing in the HTML document.
48
- * @return {number} The insertion point for the stylesheet in the HTML document.
49
- */
50
- function findStylesheetInsertionPoint({ document, source }) {
51
- const headElement = (0, tagUtils_1.getDescendantByTag)(document, 'head');
52
- if (!headElement) {
53
- throw new Error('Missing head element in index.html.');
54
- }
55
- // determine script insertion point
56
- if (headElement.sourceCodeLocation?.startTag) {
57
- return headElement.sourceCodeLocation.startTag.endOffset;
58
- }
59
- // less accurate fallback
60
- const headTagString = '<head>';
61
- const headTagIndex = source.indexOf(headTagString);
62
- return headTagIndex + headTagString.length;
63
- }
64
- /**
65
- * Inserts stylesheets into an HTML document.
66
- *
67
- * @param {object} options - The options for inserting stylesheets.
68
- * @param {string} options.source - The HTML source code.
69
- * @param {object} options.urls - The URLs of the stylesheets to be inserted.
70
- * @param {string} options.urls.default - The URL of the default stylesheet.
71
- * @param {string} options.urls.brandOverride - The URL of the brand override stylesheet.
72
- * @return {object|undefined} The new source code with the stylesheets inserted.
73
- */
74
- function insertStylesheetsIntoDocument({ source, urls, }) {
75
- // parse file as html document
76
- const document = parse5.parse(source, {
77
- sourceCodeLocationInfo: true,
78
- });
79
- if (!(0, tagUtils_1.getDescendantByTag)(document, 'head')) {
80
- return undefined;
81
- }
82
- const newSource = new webpack_1.sources.ReplaceSource(new webpack_1.sources.RawSource(source), 'index.html');
83
- // insert the brand overrides styles into the HTML document
84
- const stylesheetInsertionPoint = findStylesheetInsertionPoint({
85
- // @ts-expect-error Typescript complains this document instance is missing properties. Is parse5.parse not returning a valid Document instance?
86
- document,
87
- // @ts-expect-error We're passing a ReplaceSource here, when we expect a string in the function.
88
- source: newSource,
89
- });
90
- /**
91
- * Creates a new stylesheet link element.
92
- *
93
- * @param {string} url - The URL of the stylesheet.
94
- * @return {string} The HTML code for the stylesheet link element.
95
- */
96
- function createNewStylesheet(url) {
97
- const baseLink = `<link
98
- type="text/css"
99
- rel="preload"
100
- as="style"
101
- href="${url}"
102
- onload="this.rel='stylesheet';"
103
- onerror="this.remove();"
104
- />`;
105
- return baseLink;
106
- }
107
- if (urls.default) {
108
- // @ts-expect-error getDescendantByTag requires two parameters.
109
- const existingDefaultLink = (0, tagUtils_1.getDescendantByTag)(`link[href='${urls.default}']`);
110
- if (!existingDefaultLink) {
111
- // create link to inject into the HTML document
112
- const stylesheetLink = createNewStylesheet(urls.default);
113
- newSource.insert(stylesheetInsertionPoint, stylesheetLink);
114
- }
115
- }
116
- if (urls.brandOverride) {
117
- // @ts-expect-error getDescendantByTag requires two parameters.
118
- const existingBrandLink = (0, tagUtils_1.getDescendantByTag)(`link[href='${urls.brandOverride}']`);
119
- if (!existingBrandLink) {
120
- // create link to inject into the HTML document
121
- const stylesheetLink = createNewStylesheet(urls.brandOverride);
122
- newSource.insert(stylesheetInsertionPoint, stylesheetLink);
123
- }
124
- }
125
- return newSource;
126
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDescendantByTag = getDescendantByTag;
4
- exports.handleVersionSubstitution = handleVersionSubstitution;
5
- exports.minifyScript = minifyScript;
6
- /**
7
- * Recursively searches for a descendant node with the specified tag name.
8
- *
9
- * @param {Object} node - The root node to start the search from.
10
- * @param {string} tag - The tag name to search for.
11
- * @return {Object|null} The first descendant node with the specified tag name, or null if not found.
12
- */
13
- function getDescendantByTag(node, tag) {
14
- for (let i = 0; i < node.childNodes?.length; i++) {
15
- if (node.childNodes[i].tagName === tag) {
16
- return node.childNodes[i];
17
- }
18
- const result = getDescendantByTag(node.childNodes[i], tag);
19
- if (result) {
20
- return result;
21
- }
22
- }
23
- return null;
24
- }
25
- /**
26
- * Replaces a wildcard keyword in a URL with a local version.
27
- *
28
- * @param {Object} options - The options object.
29
- * @param {string} options.url - The URL to substitute the keyword in.
30
- * @param {string} options.wildcardKeyword - The wildcard keyword to replace.
31
- * @param {string} options.localVersion - The local version to substitute the keyword with.
32
- * @return {string} The URL with the wildcard keyword substituted with the local version,
33
- * or the original URL if no substitution is needed.
34
- */
35
- function handleVersionSubstitution({ url, wildcardKeyword, localVersion }) {
36
- if (!url || !url.includes(wildcardKeyword) || !localVersion) {
37
- return url;
38
- }
39
- return url.replaceAll(wildcardKeyword, localVersion);
40
- }
41
- /**
42
- * Minifies a script by removing unnecessary whitespace and line breaks.
43
- *
44
- * @param {string} script - The script to be minified.
45
- * @return {string} The minified script.
46
- */
47
- function minifyScript(script) {
48
- return script
49
- .replace(/>[\r\n ]+</g, '><')
50
- .replace(/(<.*?>)|\s+/g, (m, $1) => {
51
- if ($1) {
52
- return $1;
53
- }
54
- return ' ';
55
- })
56
- .trim();
57
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getParagonVersion = getParagonVersion;
7
- exports.getParagonThemeCss = getParagonThemeCss;
8
- exports.getParagonCacheGroups = getParagonCacheGroups;
9
- exports.getParagonEntryPoints = getParagonEntryPoints;
10
- const fs_1 = __importDefault(require("fs"));
11
- const path_1 = __importDefault(require("path"));
12
- /**
13
- * Retrieves the name of the brand package from the given directory.
14
- *
15
- * @param {string} dir - The directory path containing the package.json file.
16
- * @return {string} The name of the brand package, or an empty string if not found.
17
- */
18
- function getBrandPackageName(dir) {
19
- const appDependencies = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(dir, 'package.json'), 'utf-8')).dependencies;
20
- return Object.keys(appDependencies).find((key) => /@(open)?edx\/brand/.exec(key)) ?? '';
21
- }
22
- /**
23
- * Attempts to extract the Paragon version from the `node_modules` of
24
- * the consuming application.
25
- *
26
- * @param {string} dir Path to directory containing `node_modules`.
27
- * @returns {string} Paragon dependency version of the consuming application
28
- */
29
- function getParagonVersion(dir, { isBrandOverride = false } = {}) {
30
- const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
31
- const pathToPackageJson = `${dir}/node_modules/${npmPackageName}/package.json`;
32
- if (!fs_1.default.existsSync(pathToPackageJson)) {
33
- return undefined;
34
- }
35
- return JSON.parse(fs_1.default.readFileSync(pathToPackageJson, 'utf-8')).version;
36
- }
37
- /**
38
- * Attempts to extract the Paragon theme CSS from the locally installed `@openedx/paragon` package.
39
- * @param {string} dir Path to directory containing `node_modules`.
40
- * @param {boolean} isBrandOverride
41
- * @returns {ParagonThemeCss}
42
- */
43
- function getParagonThemeCss(dir, { isBrandOverride = false } = {}) {
44
- const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
45
- const pathToParagonThemeOutput = path_1.default.resolve(dir, 'node_modules', npmPackageName, 'dist', 'theme-urls.json');
46
- if (!fs_1.default.existsSync(pathToParagonThemeOutput)) {
47
- return undefined;
48
- }
49
- const paragonConfig = JSON.parse(fs_1.default.readFileSync(pathToParagonThemeOutput, 'utf-8'));
50
- const { core: themeCore, variants: themeVariants, defaults, } = paragonConfig?.themeUrls || {};
51
- const pathToCoreCss = path_1.default.resolve(dir, 'node_modules', npmPackageName, 'dist', themeCore.paths.minified);
52
- const coreCssExists = fs_1.default.existsSync(pathToCoreCss);
53
- const themeVariantResults = Object.entries(themeVariants || {}).reduce((themeVariantAcc, [themeVariant, value]) => {
54
- const themeVariantCssDefault = path_1.default.resolve(dir, 'node_modules', npmPackageName, 'dist', value.paths.default);
55
- const themeVariantCssMinified = path_1.default.resolve(dir, 'node_modules', npmPackageName, 'dist', value.paths.minified);
56
- if (!fs_1.default.existsSync(themeVariantCssDefault) && !fs_1.default.existsSync(themeVariantCssMinified)) {
57
- return themeVariantAcc;
58
- }
59
- return ({
60
- ...themeVariantAcc,
61
- [themeVariant]: {
62
- filePath: themeVariantCssMinified,
63
- entryName: isBrandOverride ? `brand.theme.variants.${themeVariant}` : `paragon.theme.variants.${themeVariant}`,
64
- outputChunkName: isBrandOverride ? `brand-theme-variants-${themeVariant}` : `paragon-theme-variants-${themeVariant}`,
65
- },
66
- });
67
- }, {});
68
- if (!coreCssExists || Object.keys(themeVariantResults).length === 0) {
69
- return undefined;
70
- }
71
- const coreResult = {
72
- filePath: path_1.default.resolve(dir, pathToCoreCss),
73
- entryName: isBrandOverride ? 'brand.theme.core' : 'paragon.theme.core',
74
- outputChunkName: isBrandOverride ? 'brand-theme-core' : 'paragon-theme-core',
75
- };
76
- return {
77
- core: fs_1.default.existsSync(pathToCoreCss) ? coreResult : undefined,
78
- variants: themeVariantResults,
79
- defaults,
80
- };
81
- }
82
- /**
83
- * @typedef CacheGroup
84
- * @property {string} type The type of cache group.
85
- * @property {string|function} name The name of the cache group.
86
- * @property {function} chunks A function that returns true if the chunk should be included in the cache group.
87
- * @property {boolean} enforce If true, this cache group will be created even if it conflicts with default cache groups.
88
- */
89
- /**
90
- * @param {ParagonThemeCss} paragonThemeCss The Paragon theme CSS metadata.
91
- * @returns {Object.<string, CacheGroup>} The cache groups for the Paragon theme CSS.
92
- */
93
- function getParagonCacheGroups(paragonThemeCss) {
94
- if (!paragonThemeCss) {
95
- return {};
96
- }
97
- const cacheGroups = {};
98
- if (paragonThemeCss.core !== undefined) {
99
- const { core } = paragonThemeCss;
100
- cacheGroups[paragonThemeCss.core.outputChunkName] = {
101
- type: 'css/mini-extract',
102
- name: paragonThemeCss.core.outputChunkName,
103
- chunks: (chunk) => chunk.name === core.entryName,
104
- enforce: true,
105
- };
106
- }
107
- Object.values(paragonThemeCss.variants).forEach(({ entryName, outputChunkName }) => {
108
- cacheGroups[outputChunkName] = {
109
- type: 'css/mini-extract',
110
- name: outputChunkName,
111
- chunks: (chunk) => chunk.name === entryName,
112
- enforce: true,
113
- };
114
- });
115
- return cacheGroups;
116
- }
117
- /**
118
- * @param {ParagonThemeCss} paragonThemeCss The Paragon theme CSS metadata.
119
- * @returns {Object.<string, string>} The entry points for the Paragon theme CSS. Example: ```
120
- * {
121
- * "paragon.theme.core": "/path/to/node_modules/@openedx/paragon/dist/core.min.css",
122
- * "paragon.theme.variants.light": "/path/to/node_modules/@openedx/paragon/dist/light.min.css"
123
- * }
124
- * ```
125
- */
126
- function getParagonEntryPoints(paragonThemeCss) {
127
- if (!paragonThemeCss) {
128
- return {};
129
- }
130
- const entryPoints = {};
131
- if (paragonThemeCss.core !== undefined) {
132
- entryPoints[paragonThemeCss.core.entryName] = path_1.default.resolve(process.cwd(), paragonThemeCss.core.filePath);
133
- }
134
- Object.values(paragonThemeCss.variants).forEach(({ filePath, entryName }) => {
135
- entryPoints[entryName] = path_1.default.resolve(process.cwd(), filePath);
136
- });
137
- return entryPoints;
138
- }