@openedx/frontend-build 15.0.0-alpha.2 → 15.0.0-alpha.20

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 (220) hide show
  1. package/README.md +1 -1
  2. package/config/.eslintrc.js +1 -0
  3. package/config/data/paragonUtils.js +171 -0
  4. package/config/jest/setupTest.js +35 -0
  5. package/config/jest.config.js +4 -1
  6. package/config/webpack.common.config.js +44 -0
  7. package/config/webpack.dev-stage.config.js +1 -0
  8. package/config/webpack.dev.config.js +57 -35
  9. package/config/webpack.prod.config.js +2 -1
  10. package/lib/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.js +126 -0
  11. package/lib/plugins/paragon-webpack-plugin/index.js +3 -0
  12. package/lib/plugins/paragon-webpack-plugin/utils/assetUtils.js +75 -0
  13. package/lib/plugins/paragon-webpack-plugin/utils/htmlUtils.js +69 -0
  14. package/lib/plugins/paragon-webpack-plugin/utils/index.js +9 -0
  15. package/lib/plugins/paragon-webpack-plugin/utils/paragonStylesheetUtils.js +120 -0
  16. package/lib/plugins/paragon-webpack-plugin/utils/scriptUtils.js +144 -0
  17. package/lib/plugins/paragon-webpack-plugin/utils/stylesheetUtils.js +107 -0
  18. package/lib/plugins/paragon-webpack-plugin/utils/tagUtils.js +58 -0
  19. package/package.json +22 -14
  20. package/.eslintignore +0 -5
  21. package/.eslintrc.js +0 -10
  22. package/.github/workflows/add-depr-ticket-to-depr-board.yml +0 -19
  23. package/.github/workflows/add-remove-label-on-comment.yml +0 -20
  24. package/.github/workflows/ci.yml +0 -30
  25. package/.github/workflows/commitlint.yml +0 -17
  26. package/.github/workflows/lockfileversion-check.yml +0 -13
  27. package/.github/workflows/release.yml +0 -34
  28. package/.github/workflows/self-assign-issue.yml +0 -12
  29. package/.github/workflows/sync-master-alpha.yml +0 -35
  30. package/.nvmrc +0 -1
  31. package/coverage/clover.xml +0 -6
  32. package/coverage/coverage-final.json +0 -1
  33. package/coverage/lcov-report/base.css +0 -224
  34. package/coverage/lcov-report/block-navigation.js +0 -87
  35. package/coverage/lcov-report/favicon.png +0 -0
  36. package/coverage/lcov-report/index.html +0 -101
  37. package/coverage/lcov-report/prettify.css +0 -1
  38. package/coverage/lcov-report/prettify.js +0 -2
  39. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  40. package/coverage/lcov-report/sorter.js +0 -196
  41. package/coverage/lcov.info +0 -0
  42. package/docs/0001-non-usage-of-gatsby.rst +0 -37
  43. package/docs/0002-js-environment-config.md +0 -47
  44. package/docs/0003-fedx-scripts-serve.md +0 -37
  45. package/example/.env +0 -0
  46. package/example/.env.development +0 -3
  47. package/example/.env.test +0 -2
  48. package/example/.eslintignore +0 -5
  49. package/example/.eslintrc.js +0 -3
  50. package/example/dist/1382e1cbf8d733d7301cdd212192bfea.jpg +0 -0
  51. package/example/dist/652.70be34739115e11aaeb3.js +0 -3
  52. package/example/dist/652.70be34739115e11aaeb3.js.LICENSE.txt +0 -41
  53. package/example/dist/652.70be34739115e11aaeb3.js.map +0 -1
  54. package/example/dist/app.9b26aa9c728d62e6064d.css +0 -3
  55. package/example/dist/app.9b26aa9c728d62e6064d.css.map +0 -1
  56. package/example/dist/app.9b26aa9c728d62e6064d.js +0 -2
  57. package/example/dist/app.9b26aa9c728d62e6064d.js.map +0 -1
  58. package/example/dist/babel/App.js +0 -94
  59. package/example/dist/babel/App.js.map +0 -1
  60. package/example/dist/babel/App.test.jsx +0 -11
  61. package/example/dist/babel/Image.tsx +0 -16
  62. package/example/dist/babel/__snapshots__/App.test.jsx.snap +0 -120
  63. package/example/dist/babel/apple.jpg +0 -0
  64. package/example/dist/babel/apple.svg +0 -1
  65. package/example/dist/babel/index.js +0 -13
  66. package/example/dist/babel/index.js.map +0 -1
  67. package/example/dist/babel/style.scss +0 -9
  68. package/example/dist/cb28cdb1468c915e27e5cec9af64f22f.svg +0 -1
  69. package/example/dist/index.html +0 -4
  70. package/example/dist/report.html +0 -39
  71. package/example/dist/runtime.40856db71d718a3e9d37.js +0 -2
  72. package/example/dist/runtime.40856db71d718a3e9d37.js.map +0 -1
  73. package/example/env.config.js +0 -6
  74. package/example/node_modules/.package-lock.json +0 -98
  75. package/example/node_modules/js-tokens/CHANGELOG.md +0 -151
  76. package/example/node_modules/js-tokens/LICENSE +0 -21
  77. package/example/node_modules/js-tokens/README.md +0 -240
  78. package/example/node_modules/js-tokens/index.js +0 -23
  79. package/example/node_modules/js-tokens/package.json +0 -30
  80. package/example/node_modules/loose-envify/LICENSE +0 -21
  81. package/example/node_modules/loose-envify/README.md +0 -45
  82. package/example/node_modules/loose-envify/cli.js +0 -16
  83. package/example/node_modules/loose-envify/custom.js +0 -4
  84. package/example/node_modules/loose-envify/index.js +0 -3
  85. package/example/node_modules/loose-envify/loose-envify.js +0 -36
  86. package/example/node_modules/loose-envify/package.json +0 -36
  87. package/example/node_modules/loose-envify/replace.js +0 -65
  88. package/example/node_modules/object-assign/index.js +0 -90
  89. package/example/node_modules/object-assign/license +0 -21
  90. package/example/node_modules/object-assign/package.json +0 -42
  91. package/example/node_modules/object-assign/readme.md +0 -61
  92. package/example/node_modules/prop-types/LICENSE +0 -21
  93. package/example/node_modules/prop-types/README.md +0 -302
  94. package/example/node_modules/prop-types/checkPropTypes.js +0 -103
  95. package/example/node_modules/prop-types/factory.js +0 -19
  96. package/example/node_modules/prop-types/factoryWithThrowingShims.js +0 -65
  97. package/example/node_modules/prop-types/factoryWithTypeCheckers.js +0 -610
  98. package/example/node_modules/prop-types/index.js +0 -19
  99. package/example/node_modules/prop-types/lib/ReactPropTypesSecret.js +0 -12
  100. package/example/node_modules/prop-types/lib/has.js +0 -1
  101. package/example/node_modules/prop-types/package.json +0 -60
  102. package/example/node_modules/prop-types/prop-types.js +0 -1315
  103. package/example/node_modules/prop-types/prop-types.min.js +0 -1
  104. package/example/node_modules/react/LICENSE +0 -21
  105. package/example/node_modules/react/README.md +0 -13
  106. package/example/node_modules/react/build-info.json +0 -8
  107. package/example/node_modules/react/cjs/react-jsx-dev-runtime.development.js +0 -889
  108. package/example/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +0 -9
  109. package/example/node_modules/react/cjs/react-jsx-runtime.development.js +0 -911
  110. package/example/node_modules/react/cjs/react-jsx-runtime.production.min.js +0 -10
  111. package/example/node_modules/react/cjs/react.development.js +0 -1912
  112. package/example/node_modules/react/cjs/react.production.min.js +0 -25
  113. package/example/node_modules/react/index.js +0 -7
  114. package/example/node_modules/react/jsx-dev-runtime.js +0 -7
  115. package/example/node_modules/react/jsx-runtime.js +0 -7
  116. package/example/node_modules/react/package.json +0 -44
  117. package/example/node_modules/react/umd/react.development.js +0 -3318
  118. package/example/node_modules/react/umd/react.production.min.js +0 -32
  119. package/example/node_modules/react/umd/react.profiling.min.js +0 -39
  120. package/example/node_modules/react-dom/LICENSE +0 -21
  121. package/example/node_modules/react-dom/README.md +0 -54
  122. package/example/node_modules/react-dom/build-info.json +0 -8
  123. package/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js +0 -4043
  124. package/example/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js +0 -54
  125. package/example/node_modules/react-dom/cjs/react-dom-server.node.development.js +0 -4085
  126. package/example/node_modules/react-dom/cjs/react-dom-server.node.production.min.js +0 -55
  127. package/example/node_modules/react-dom/cjs/react-dom-test-utils.development.js +0 -1480
  128. package/example/node_modules/react-dom/cjs/react-dom-test-utils.production.min.js +0 -35
  129. package/example/node_modules/react-dom/cjs/react-dom-unstable-fizz.browser.development.js +0 -141
  130. package/example/node_modules/react-dom/cjs/react-dom-unstable-fizz.browser.production.min.js +0 -11
  131. package/example/node_modules/react-dom/cjs/react-dom-unstable-fizz.node.development.js +0 -162
  132. package/example/node_modules/react-dom/cjs/react-dom-unstable-fizz.node.production.min.js +0 -12
  133. package/example/node_modules/react-dom/cjs/react-dom-unstable-native-dependencies.development.js +0 -1629
  134. package/example/node_modules/react-dom/cjs/react-dom-unstable-native-dependencies.production.min.js +0 -31
  135. package/example/node_modules/react-dom/cjs/react-dom.development.js +0 -25012
  136. package/example/node_modules/react-dom/cjs/react-dom.production.min.js +0 -292
  137. package/example/node_modules/react-dom/cjs/react-dom.profiling.min.js +0 -299
  138. package/example/node_modules/react-dom/index.js +0 -38
  139. package/example/node_modules/react-dom/package.json +0 -60
  140. package/example/node_modules/react-dom/profiling.js +0 -38
  141. package/example/node_modules/react-dom/server.browser.js +0 -7
  142. package/example/node_modules/react-dom/server.js +0 -3
  143. package/example/node_modules/react-dom/server.node.js +0 -7
  144. package/example/node_modules/react-dom/test-utils.js +0 -7
  145. package/example/node_modules/react-dom/umd/react-dom-server.browser.development.js +0 -4147
  146. package/example/node_modules/react-dom/umd/react-dom-server.browser.production.min.js +0 -45
  147. package/example/node_modules/react-dom/umd/react-dom-test-utils.development.js +0 -1499
  148. package/example/node_modules/react-dom/umd/react-dom-test-utils.production.min.js +0 -30
  149. package/example/node_modules/react-dom/umd/react-dom-unstable-fizz.browser.development.js +0 -141
  150. package/example/node_modules/react-dom/umd/react-dom-unstable-fizz.browser.production.min.js +0 -10
  151. package/example/node_modules/react-dom/umd/react-dom-unstable-native-dependencies.development.js +0 -1628
  152. package/example/node_modules/react-dom/umd/react-dom-unstable-native-dependencies.production.min.js +0 -28
  153. package/example/node_modules/react-dom/umd/react-dom.development.js +0 -25147
  154. package/example/node_modules/react-dom/umd/react-dom.production.min.js +0 -239
  155. package/example/node_modules/react-dom/umd/react-dom.profiling.min.js +0 -247
  156. package/example/node_modules/react-dom/unstable-fizz.browser.js +0 -7
  157. package/example/node_modules/react-dom/unstable-fizz.js +0 -3
  158. package/example/node_modules/react-dom/unstable-fizz.node.js +0 -7
  159. package/example/node_modules/react-dom/unstable-native-dependencies.js +0 -7
  160. package/example/node_modules/react-is/LICENSE +0 -21
  161. package/example/node_modules/react-is/README.md +0 -104
  162. package/example/node_modules/react-is/build-info.json +0 -8
  163. package/example/node_modules/react-is/cjs/react-is.development.js +0 -181
  164. package/example/node_modules/react-is/cjs/react-is.production.min.js +0 -15
  165. package/example/node_modules/react-is/index.js +0 -7
  166. package/example/node_modules/react-is/package.json +0 -27
  167. package/example/node_modules/react-is/umd/react-is.development.js +0 -181
  168. package/example/node_modules/react-is/umd/react-is.production.min.js +0 -13
  169. package/example/node_modules/react-test-renderer/LICENSE +0 -21
  170. package/example/node_modules/react-test-renderer/README.md +0 -26
  171. package/example/node_modules/react-test-renderer/build-info.json +0 -8
  172. package/example/node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js +0 -1019
  173. package/example/node_modules/react-test-renderer/cjs/react-test-renderer-shallow.production.min.js +0 -35
  174. package/example/node_modules/react-test-renderer/cjs/react-test-renderer.development.js +0 -15596
  175. package/example/node_modules/react-test-renderer/cjs/react-test-renderer.production.min.js +0 -181
  176. package/example/node_modules/react-test-renderer/index.js +0 -7
  177. package/example/node_modules/react-test-renderer/package.json +0 -41
  178. package/example/node_modules/react-test-renderer/shallow.js +0 -7
  179. package/example/node_modules/react-test-renderer/umd/react-test-renderer-shallow.development.js +0 -1176
  180. package/example/node_modules/react-test-renderer/umd/react-test-renderer-shallow.production.min.js +0 -31
  181. package/example/node_modules/react-test-renderer/umd/react-test-renderer.development.js +0 -15709
  182. package/example/node_modules/react-test-renderer/umd/react-test-renderer.production.min.js +0 -151
  183. package/example/node_modules/scheduler/LICENSE +0 -21
  184. package/example/node_modules/scheduler/README.md +0 -9
  185. package/example/node_modules/scheduler/build-info.json +0 -8
  186. package/example/node_modules/scheduler/cjs/scheduler-tracing.development.js +0 -349
  187. package/example/node_modules/scheduler/cjs/scheduler-tracing.production.min.js +0 -10
  188. package/example/node_modules/scheduler/cjs/scheduler-tracing.profiling.min.js +0 -17
  189. package/example/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +0 -857
  190. package/example/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +0 -20
  191. package/example/node_modules/scheduler/cjs/scheduler.development.js +0 -858
  192. package/example/node_modules/scheduler/cjs/scheduler.production.min.js +0 -21
  193. package/example/node_modules/scheduler/index.js +0 -7
  194. package/example/node_modules/scheduler/package.json +0 -39
  195. package/example/node_modules/scheduler/tracing-profiling.js +0 -7
  196. package/example/node_modules/scheduler/tracing.js +0 -7
  197. package/example/node_modules/scheduler/umd/scheduler-tracing.development.js +0 -80
  198. package/example/node_modules/scheduler/umd/scheduler-tracing.production.min.js +0 -80
  199. package/example/node_modules/scheduler/umd/scheduler-tracing.profiling.min.js +0 -80
  200. package/example/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +0 -857
  201. package/example/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +0 -17
  202. package/example/node_modules/scheduler/umd/scheduler.development.js +0 -152
  203. package/example/node_modules/scheduler/umd/scheduler.production.min.js +0 -146
  204. package/example/node_modules/scheduler/umd/scheduler.profiling.min.js +0 -146
  205. package/example/node_modules/scheduler/unstable_mock.js +0 -7
  206. package/example/package-lock.json +0 -110
  207. package/example/package.json +0 -24
  208. package/example/public/index.html +0 -13
  209. package/example/src/App.jsx +0 -43
  210. package/example/src/App.test.jsx +0 -11
  211. package/example/src/Image.tsx +0 -16
  212. package/example/src/__snapshots__/App.test.jsx.snap +0 -120
  213. package/example/src/apple.jpg +0 -0
  214. package/example/src/apple.svg +0 -1
  215. package/example/src/index.jsx +0 -13
  216. package/example/src/style.scss +0 -9
  217. package/example/tsconfig.json +0 -16
  218. package/openedx.yaml +0 -10
  219. package/renovate.json +0 -22
  220. package/smoke-test.sh +0 -11
package/README.md CHANGED
@@ -155,7 +155,7 @@ frontend-platform:
155
155
  dist: The sub-directory of the source code where it puts its build artifact. Often "dist".
156
156
  */
157
157
  localModules: [
158
- { moduleName: '@openedx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout
158
+ { moduleName: '@edx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout
159
159
  { moduleName: '@openedx/paragon/scss/core', dir: '../src/paragon', dist: 'scss/core' },
160
160
  { moduleName: '@openedx/paragon/icons', dir: '../src/paragon', dist: 'icons' },
161
161
  { moduleName: '@openedx/paragon', dir: '../src/paragon', dist: 'dist' },
@@ -39,6 +39,7 @@ module.exports = {
39
39
  },
40
40
  globals: {
41
41
  newrelic: false,
42
+ PARAGON_THEME: false,
42
43
  },
43
44
  ignorePatterns: [
44
45
  'module.config.js',
@@ -0,0 +1,171 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ /**
5
+ * Retrieves the name of the brand package from the given directory.
6
+ *
7
+ * @param {string} dir - The directory path containing the package.json file.
8
+ * @return {string} The name of the brand package, or an empty string if not found.
9
+ */
10
+ function getBrandPackageName(dir) {
11
+ const appDependencies = JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json'), 'utf-8')).dependencies;
12
+ return Object.keys(appDependencies).find((key) => key.match(/@(open)?edx\/brand/)) || '';
13
+ }
14
+
15
+ /**
16
+ * Attempts to extract the Paragon version from the `node_modules` of
17
+ * the consuming application.
18
+ *
19
+ * @param {string} dir Path to directory containing `node_modules`.
20
+ * @returns {string} Paragon dependency version of the consuming application
21
+ */
22
+ function getParagonVersion(dir, { isBrandOverride = false } = {}) {
23
+ const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
24
+ const pathToPackageJson = `${dir}/node_modules/${npmPackageName}/package.json`;
25
+ if (!fs.existsSync(pathToPackageJson)) {
26
+ return undefined;
27
+ }
28
+ return JSON.parse(fs.readFileSync(pathToPackageJson, 'utf-8')).version;
29
+ }
30
+
31
+ /**
32
+ * @typedef {Object} ParagonThemeCssAsset
33
+ * @property {string} filePath
34
+ * @property {string} entryName
35
+ * @property {string} outputChunkName
36
+ */
37
+
38
+ /**
39
+ * @typedef {Object} ParagonThemeVariantCssAsset
40
+ * @property {string} filePath
41
+ * @property {string} entryName
42
+ * @property {string} outputChunkName
43
+ */
44
+
45
+ /**
46
+ * @typedef {Object} ParagonThemeCss
47
+ * @property {ParagonThemeCssAsset} core The metadata about the core Paragon theme CSS
48
+ * @property {Object.<string, ParagonThemeVariantCssAsset>} variants A collection of theme variants.
49
+ */
50
+
51
+ /**
52
+ * Attempts to extract the Paragon theme CSS from the locally installed `@openedx/paragon` package.
53
+ * @param {string} dir Path to directory containing `node_modules`.
54
+ * @param {boolean} isBrandOverride
55
+ * @returns {ParagonThemeCss}
56
+ */
57
+ function getParagonThemeCss(dir, { isBrandOverride = false } = {}) {
58
+ const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
59
+ const pathToParagonThemeOutput = path.resolve(dir, 'node_modules', npmPackageName, 'dist', 'theme-urls.json');
60
+
61
+ if (!fs.existsSync(pathToParagonThemeOutput)) {
62
+ return undefined;
63
+ }
64
+ const paragonConfig = JSON.parse(fs.readFileSync(pathToParagonThemeOutput, 'utf-8'));
65
+ const {
66
+ core: themeCore,
67
+ variants: themeVariants,
68
+ defaults,
69
+ } = paragonConfig?.themeUrls || {};
70
+
71
+ const pathToCoreCss = path.resolve(dir, 'node_modules', npmPackageName, 'dist', themeCore.paths.minified);
72
+ const coreCssExists = fs.existsSync(pathToCoreCss);
73
+
74
+ const themeVariantResults = Object.entries(themeVariants || {}).reduce((themeVariantAcc, [themeVariant, value]) => {
75
+ const themeVariantCssDefault = path.resolve(dir, 'node_modules', npmPackageName, 'dist', value.paths.default);
76
+ const themeVariantCssMinified = path.resolve(dir, 'node_modules', npmPackageName, 'dist', value.paths.minified);
77
+
78
+ if (!fs.existsSync(themeVariantCssDefault) && !fs.existsSync(themeVariantCssMinified)) {
79
+ return themeVariantAcc;
80
+ }
81
+
82
+ return ({
83
+ ...themeVariantAcc,
84
+ [themeVariant]: {
85
+ filePath: themeVariantCssMinified,
86
+ entryName: isBrandOverride ? `brand.theme.variants.${themeVariant}` : `paragon.theme.variants.${themeVariant}`,
87
+ outputChunkName: isBrandOverride ? `brand-theme-variants-${themeVariant}` : `paragon-theme-variants-${themeVariant}`,
88
+ },
89
+ });
90
+ }, {});
91
+
92
+ if (!coreCssExists || themeVariantResults.length === 0) {
93
+ return undefined;
94
+ }
95
+
96
+ const coreResult = {
97
+ filePath: path.resolve(dir, pathToCoreCss),
98
+ entryName: isBrandOverride ? 'brand.theme.core' : 'paragon.theme.core',
99
+ outputChunkName: isBrandOverride ? 'brand-theme-core' : 'paragon-theme-core',
100
+ };
101
+
102
+ return {
103
+ core: fs.existsSync(pathToCoreCss) ? coreResult : undefined,
104
+ variants: themeVariantResults,
105
+ defaults,
106
+ };
107
+ }
108
+
109
+ /**
110
+ * @typedef CacheGroup
111
+ * @property {string} type The type of cache group.
112
+ * @property {string|function} name The name of the cache group.
113
+ * @property {function} chunks A function that returns true if the chunk should be included in the cache group.
114
+ * @property {boolean} enforce If true, this cache group will be created even if it conflicts with default cache groups.
115
+ */
116
+
117
+ /**
118
+ * @param {ParagonThemeCss} paragonThemeCss The Paragon theme CSS metadata.
119
+ * @returns {Object.<string, CacheGroup>} The cache groups for the Paragon theme CSS.
120
+ */
121
+ function getParagonCacheGroups(paragonThemeCss) {
122
+ if (!paragonThemeCss) {
123
+ return {};
124
+ }
125
+ const cacheGroups = {
126
+ [paragonThemeCss.core.outputChunkName]: {
127
+ type: 'css/mini-extract',
128
+ name: paragonThemeCss.core.outputChunkName,
129
+ chunks: chunk => chunk.name === paragonThemeCss.core.entryName,
130
+ enforce: true,
131
+ },
132
+ };
133
+
134
+ Object.values(paragonThemeCss.variants).forEach(({ entryName, outputChunkName }) => {
135
+ cacheGroups[outputChunkName] = {
136
+ type: 'css/mini-extract',
137
+ name: outputChunkName,
138
+ chunks: chunk => chunk.name === entryName,
139
+ enforce: true,
140
+ };
141
+ });
142
+ return cacheGroups;
143
+ }
144
+
145
+ /**
146
+ * @param {ParagonThemeCss} paragonThemeCss The Paragon theme CSS metadata.
147
+ * @returns {Object.<string, string>} The entry points for the Paragon theme CSS. Example: ```
148
+ * {
149
+ * "paragon.theme.core": "/path/to/node_modules/@openedx/paragon/dist/core.min.css",
150
+ * "paragon.theme.variants.light": "/path/to/node_modules/@openedx/paragon/dist/light.min.css"
151
+ * }
152
+ * ```
153
+ */
154
+ function getParagonEntryPoints(paragonThemeCss) {
155
+ if (!paragonThemeCss) {
156
+ return {};
157
+ }
158
+
159
+ const entryPoints = { [paragonThemeCss.core.entryName]: path.resolve(process.cwd(), paragonThemeCss.core.filePath) };
160
+ Object.values(paragonThemeCss.variants).forEach(({ filePath, entryName }) => {
161
+ entryPoints[entryName] = path.resolve(process.cwd(), filePath);
162
+ });
163
+ return entryPoints;
164
+ }
165
+
166
+ module.exports = {
167
+ getParagonVersion,
168
+ getParagonThemeCss,
169
+ getParagonCacheGroups,
170
+ getParagonEntryPoints,
171
+ };
@@ -8,3 +8,38 @@ const testEnvFile = path.resolve(process.cwd(), '.env.test');
8
8
  if (fs.existsSync(testEnvFile)) {
9
9
  dotenv.config({ path: testEnvFile });
10
10
  }
11
+
12
+ global.PARAGON_THEME = {
13
+ paragon: {
14
+ version: '1.0.0',
15
+ themeUrls: {
16
+ core: {
17
+ fileName: 'core.min.css',
18
+ },
19
+ defaults: {
20
+ light: 'light',
21
+ },
22
+ variants: {
23
+ light: {
24
+ fileName: 'light.min.css',
25
+ },
26
+ },
27
+ },
28
+ },
29
+ brand: {
30
+ version: '1.0.0',
31
+ themeUrls: {
32
+ core: {
33
+ fileName: 'core.min.css',
34
+ },
35
+ defaults: {
36
+ light: 'light',
37
+ },
38
+ variants: {
39
+ light: {
40
+ fileName: 'light.min.css',
41
+ },
42
+ },
43
+ },
44
+ },
45
+ };
@@ -27,7 +27,7 @@ module.exports = {
27
27
  'env.config': envConfigPath,
28
28
  },
29
29
  collectCoverageFrom: [
30
- 'src/**/*.{js,jsx}',
30
+ 'src/**/*.{js,jsx,ts,tsx}',
31
31
  ],
32
32
  coveragePathIgnorePatterns: [
33
33
  '/node_modules/',
@@ -45,4 +45,7 @@ module.exports = {
45
45
  ],
46
46
  ...tsjPreset.transform,
47
47
  },
48
+ watchPathIgnorePatterns: [
49
+ '/node_modules/',
50
+ ],
48
51
  };
@@ -1,8 +1,35 @@
1
1
  const path = require('path');
2
+ const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
3
+
4
+ const ParagonWebpackPlugin = require('../lib/plugins/paragon-webpack-plugin/ParagonWebpackPlugin');
5
+ const {
6
+ getParagonThemeCss,
7
+ getParagonCacheGroups,
8
+ getParagonEntryPoints,
9
+ } = require('./data/paragonUtils');
10
+
11
+ const paragonThemeCss = getParagonThemeCss(process.cwd());
12
+ const brandThemeCss = getParagonThemeCss(process.cwd(), { isBrandOverride: true });
2
13
 
3
14
  module.exports = {
4
15
  entry: {
5
16
  app: path.resolve(process.cwd(), './src/index'),
17
+ /**
18
+ * The entry points for the Paragon theme CSS. Example: ```
19
+ * {
20
+ * "paragon.theme.core": "/path/to/node_modules/@openedx/paragon/dist/core.min.css",
21
+ * "paragon.theme.variants.light": "/path/to/node_modules/@openedx/paragon/dist/light.min.css"
22
+ * }
23
+ */
24
+ ...getParagonEntryPoints(paragonThemeCss),
25
+ /**
26
+ * The entry points for the brand theme CSS. Example: ```
27
+ * {
28
+ * "paragon.theme.core": "/path/to/node_modules/@(open)edx/brand/dist/core.min.css",
29
+ * "paragon.theme.variants.light": "/path/to/node_modules/@(open)edx/brand/dist/light.min.css"
30
+ * }
31
+ */
32
+ ...getParagonEntryPoints(brandThemeCss),
6
33
  },
7
34
  output: {
8
35
  path: path.resolve(process.cwd(), './dist'),
@@ -19,6 +46,23 @@ module.exports = {
19
46
  },
20
47
  extensions: ['.js', '.jsx', '.ts', '.tsx'],
21
48
  },
49
+ optimization: {
50
+ splitChunks: {
51
+ chunks: 'all',
52
+ cacheGroups: {
53
+ ...getParagonCacheGroups(paragonThemeCss),
54
+ ...getParagonCacheGroups(brandThemeCss),
55
+ },
56
+ },
57
+ },
58
+ plugins: [
59
+ // RemoveEmptyScriptsPlugin get rid of empty scripts generated by webpack when using mini-css-extract-plugin
60
+ // This helps to clean up the final bundle application
61
+ // See: https://www.npmjs.com/package/webpack-remove-empty-scripts#usage-with-mini-css-extract-plugin
62
+
63
+ new RemoveEmptyScriptsPlugin(),
64
+ new ParagonWebpackPlugin(),
65
+ ],
22
66
  ignoreWarnings: [
23
67
  // Ignore warnings raised by source-map-loader.
24
68
  // some third party packages may ship miss-configured sourcemaps, that interrupts the build
@@ -157,6 +157,7 @@ module.exports = merge(commonConfig, {
157
157
  new HtmlWebpackPlugin({
158
158
  inject: true, // Appends script tags linking to the webpack bundles at the end of the body
159
159
  template: path.resolve(process.cwd(), 'public/index.html'),
160
+ chunks: ['app'],
160
161
  FAVICON_URL: process.env.FAVICON_URL || null,
161
162
  OPTIMIZELY_PROJECT_ID: process.env.OPTIMIZELY_PROJECT_ID || null,
162
163
  NODE_ENV: process.env.NODE_ENV || null,
@@ -1,7 +1,7 @@
1
1
  // This is the dev Webpack config. All settings here should prefer a fast build
2
2
  // time at the expense of creating larger, unoptimized bundles.
3
3
  const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
4
-
4
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5
5
  const { merge } = require('webpack-merge');
6
6
  const Dotenv = require('dotenv-webpack');
7
7
  const dotenv = require('dotenv');
@@ -31,6 +31,47 @@ resolvePrivateEnvConfig('.env.private');
31
31
  const aliases = getLocalAliases();
32
32
  const PUBLIC_PATH = process.env.PUBLIC_PATH || '/';
33
33
 
34
+ function getStyleUseConfig() {
35
+ return [
36
+ {
37
+ loader: 'css-loader', // translates CSS into CommonJS
38
+ options: {
39
+ sourceMap: true,
40
+ modules: {
41
+ compileType: 'icss',
42
+ },
43
+ },
44
+ },
45
+ {
46
+ loader: 'postcss-loader',
47
+ options: {
48
+ postcssOptions: {
49
+ plugins: [
50
+ PostCssAutoprefixerPlugin(),
51
+ PostCssRTLCSS(),
52
+ PostCssCustomMediaCSS(),
53
+ ],
54
+ },
55
+ },
56
+ },
57
+ 'resolve-url-loader',
58
+ {
59
+ loader: 'sass-loader', // compiles Sass to CSS
60
+ options: {
61
+ sourceMap: true,
62
+ sassOptions: {
63
+ includePaths: [
64
+ path.join(process.cwd(), 'node_modules'),
65
+ path.join(process.cwd(), 'src'),
66
+ ],
67
+ // silences compiler warnings regarding deprecation warnings
68
+ quietDeps: true,
69
+ },
70
+ },
71
+ },
72
+ ];
73
+ }
74
+
34
75
  module.exports = merge(commonConfig, {
35
76
  mode: 'development',
36
77
  devtool: 'eval-source-map',
@@ -68,43 +109,19 @@ module.exports = merge(commonConfig, {
68
109
  // flash-of-unstyled-content issues in development.
69
110
  {
70
111
  test: /(.scss|.css)$/,
71
- use: [
72
- 'style-loader', // creates style nodes from JS strings
112
+ oneOf: [
73
113
  {
74
- loader: 'css-loader', // translates CSS into CommonJS
75
- options: {
76
- sourceMap: true,
77
- modules: {
78
- compileType: 'icss',
79
- },
80
- },
81
- },
82
- {
83
- loader: 'postcss-loader',
84
- options: {
85
- postcssOptions: {
86
- plugins: [
87
- PostCssAutoprefixerPlugin(),
88
- PostCssRTLCSS(),
89
- PostCssCustomMediaCSS(),
90
- ],
91
- },
92
- },
114
+ resource: /(@openedx\/paragon|@(open)?edx\/brand)/,
115
+ use: [
116
+ MiniCssExtractPlugin.loader,
117
+ ...getStyleUseConfig(),
118
+ ],
93
119
  },
94
- 'resolve-url-loader',
95
120
  {
96
- loader: 'sass-loader', // compiles Sass to CSS
97
- options: {
98
- sourceMap: true,
99
- sassOptions: {
100
- includePaths: [
101
- path.join(process.cwd(), 'node_modules'),
102
- path.join(process.cwd(), 'src'),
103
- ],
104
- // silences compiler warnings regarding deprecation warnings
105
- quietDeps: true,
106
- },
107
- },
121
+ use: [
122
+ 'style-loader', // creates style nodes from JS strings
123
+ ...getStyleUseConfig(),
124
+ ],
108
125
  },
109
126
  ],
110
127
  },
@@ -156,10 +173,15 @@ module.exports = merge(commonConfig, {
156
173
  },
157
174
  // Specify additional processing or side-effects done on the Webpack output bundles as a whole.
158
175
  plugins: [
176
+ // Writes the extracted CSS from each entry to a file in the output directory.
177
+ new MiniCssExtractPlugin({
178
+ filename: '[name].css',
179
+ }),
159
180
  // Generates an HTML file in the output directory.
160
181
  new HtmlWebpackPlugin({
161
182
  inject: true, // Appends script tags linking to the webpack bundles at the end of the body
162
183
  template: path.resolve(process.cwd(), 'public/index.html'),
184
+ chunks: ['app'],
163
185
  FAVICON_URL: process.env.FAVICON_URL || null,
164
186
  OPTIMIZELY_PROJECT_ID: process.env.OPTIMIZELY_PROJECT_ID || null,
165
187
  NODE_ENV: process.env.NODE_ENV || null,
@@ -114,8 +114,8 @@ module.exports = merge(commonConfig, {
114
114
  plugins: [
115
115
  PostCssAutoprefixerPlugin(),
116
116
  PostCssRTLCSS(),
117
- CssNano(),
118
117
  PostCssCustomMediaCSS(),
118
+ CssNano(),
119
119
  ...extraPostCssPlugins,
120
120
  ],
121
121
  },
@@ -202,6 +202,7 @@ module.exports = merge(commonConfig, {
202
202
  new HtmlWebpackPlugin({
203
203
  inject: true, // Appends script tags linking to the webpack bundles at the end of the body
204
204
  template: path.resolve(process.cwd(), 'public/index.html'),
205
+ chunks: ['app'],
205
206
  FAVICON_URL: process.env.FAVICON_URL || null,
206
207
  OPTIMIZELY_PROJECT_ID: process.env.OPTIMIZELY_PROJECT_ID || null,
207
208
  NODE_ENV: process.env.NODE_ENV || null,
@@ -0,0 +1,126 @@
1
+ const { Compilation, sources } = require('webpack');
2
+ const {
3
+ getParagonVersion,
4
+ getParagonThemeCss,
5
+ } = require('../../../config/data/paragonUtils');
6
+ const {
7
+ injectMetadataIntoDocument,
8
+ getParagonStylesheetUrls,
9
+ injectParagonCoreStylesheets,
10
+ injectParagonThemeVariantStylesheets,
11
+ } = require('./utils');
12
+
13
+ // Get Paragon and brand versions / CSS files from disk.
14
+ const paragonVersion = getParagonVersion(process.cwd());
15
+ const paragonThemeCss = getParagonThemeCss(process.cwd());
16
+ const brandVersion = getParagonVersion(process.cwd(), { isBrandOverride: true });
17
+ const brandThemeCss = getParagonThemeCss(process.cwd(), { isBrandOverride: true });
18
+
19
+ /**
20
+ * 1. Injects `PARAGON_THEME` global variable into the HTML document during the Webpack compilation process.
21
+ * 2. Injects `<link rel="preload" as="style">` element(s) for the Paragon and brand CSS into the HTML document.
22
+ */
23
+ class ParagonWebpackPlugin {
24
+ constructor({ processAssetsHandlers = [] } = {}) {
25
+ this.pluginName = 'ParagonWebpackPlugin';
26
+ this.paragonThemeUrlsConfig = {};
27
+ this.paragonMetadata = {};
28
+
29
+ // List of handlers to be executed after processing assets during the Webpack compilation.
30
+ this.processAssetsHandlers = [
31
+ this.resolveParagonThemeUrlsFromConfig,
32
+ this.injectParagonMetadataIntoDocument,
33
+ this.injectParagonStylesheetsIntoDocument,
34
+ ...processAssetsHandlers,
35
+ ].map(handler => handler.bind(this));
36
+ }
37
+
38
+ /**
39
+ * Resolves the MFE configuration from ``PARAGON_THEME_URLS`` in the environment variables. `
40
+ *
41
+ * @returns {Object} Metadata about the Paragon and brand theme URLs from configuration.
42
+ */
43
+ async resolveParagonThemeUrlsFromConfig() {
44
+ try {
45
+ this.paragonThemeUrlsConfig = JSON.parse(process.env.PARAGON_THEME_URLS);
46
+ } catch (error) {
47
+ console.info('Paragon Plugin cannot load PARAGON_THEME_URLS env variable, skipping.');
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Generates `PARAGON_THEME` global variable in HTML document.
53
+ * @param {Object} compilation Webpack compilation object.
54
+ */
55
+ injectParagonMetadataIntoDocument(compilation) {
56
+ const paragonMetadata = injectMetadataIntoDocument(compilation, {
57
+ paragonThemeCss,
58
+ paragonVersion,
59
+ brandThemeCss,
60
+ brandVersion,
61
+ });
62
+ if (paragonMetadata) {
63
+ this.paragonMetadata = paragonMetadata;
64
+ }
65
+ }
66
+
67
+ injectParagonStylesheetsIntoDocument(compilation) {
68
+ const file = compilation.getAsset('index.html');
69
+
70
+ // If the `index.html` hasn't loaded yet, or there are no Paragon theme URLs, then there is nothing to do yet.
71
+ if (!file || Object.keys(this.paragonThemeUrlsConfig || {}).length === 0) {
72
+ return;
73
+ }
74
+
75
+ // Generates `<link rel="preload" as="style">` element(s) for the Paragon and brand CSS files.
76
+ const paragonStylesheetUrls = getParagonStylesheetUrls({
77
+ paragonThemeUrls: this.paragonThemeUrlsConfig,
78
+ paragonVersion,
79
+ brandVersion,
80
+ });
81
+ const {
82
+ core: paragonCoreCss,
83
+ variants: paragonThemeVariantCss,
84
+ } = paragonStylesheetUrls;
85
+
86
+ const originalSource = file.source.source();
87
+
88
+ // Inject core CSS
89
+ let newSource = injectParagonCoreStylesheets({
90
+ source: originalSource,
91
+ paragonCoreCss,
92
+ paragonThemeCss,
93
+ brandThemeCss,
94
+ });
95
+
96
+ // Inject theme variant CSS
97
+ newSource = injectParagonThemeVariantStylesheets({
98
+ source: newSource.source(),
99
+ paragonThemeVariantCss,
100
+ paragonThemeCss,
101
+ brandThemeCss,
102
+ });
103
+
104
+ compilation.updateAsset('index.html', new sources.RawSource(newSource.source()));
105
+ }
106
+
107
+ apply(compiler) {
108
+ compiler.hooks.thisCompilation.tap(this.pluginName, (compilation) => {
109
+ compilation.hooks.processAssets.tap(
110
+ {
111
+ name: this.pluginName,
112
+ stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
113
+ additionalAssets: true,
114
+ },
115
+ () => {
116
+ // Iterate through each configured handler, passing the compilation to each.
117
+ this.processAssetsHandlers.forEach(async (handler) => {
118
+ await handler(compilation);
119
+ });
120
+ },
121
+ );
122
+ });
123
+ }
124
+ }
125
+
126
+ module.exports = ParagonWebpackPlugin;
@@ -0,0 +1,3 @@
1
+ const ParagonWebpackPlugin = require('./ParagonWebpackPlugin');
2
+
3
+ module.exports = ParagonWebpackPlugin;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Finds the core CSS asset from the given array of Paragon assets.
3
+ *
4
+ * @param {Array} paragonAssets - An array of Paragon assets.
5
+ * @return {Object|undefined} The core CSS asset, or undefined if not found.
6
+ */
7
+ function findCoreCssAsset(paragonAssets) {
8
+ return paragonAssets?.find((asset) => asset.name.includes('core') && asset.name.endsWith('.css'));
9
+ }
10
+
11
+ /**
12
+ * Finds the theme variant CSS assets from the given Paragon assets based on the provided options.
13
+ *
14
+ * @param {Array} paragonAssets - An array of Paragon assets.
15
+ * @param {Object} options - The options for finding the theme variant CSS assets.
16
+ * @param {boolean} [options.isBrandOverride=false] - Indicates if the theme variant is a brand override.
17
+ * @param {Object} [options.brandThemeCss] - The brand theme CSS object.
18
+ * @param {Object} [options.paragonThemeCss] - The Paragon theme CSS object.
19
+ * @return {Object} - The theme variant CSS assets.
20
+ */
21
+ function findThemeVariantCssAssets(paragonAssets, {
22
+ isBrandOverride = false,
23
+ brandThemeCss,
24
+ paragonThemeCss,
25
+ }) {
26
+ const themeVariantsSource = isBrandOverride ? brandThemeCss?.variants : paragonThemeCss?.variants;
27
+ const themeVariantCssAssets = {};
28
+ Object.entries(themeVariantsSource || {}).forEach(([themeVariant, value]) => {
29
+ const foundThemeVariantAsset = paragonAssets.find((asset) => asset.name.includes(value.outputChunkName));
30
+ if (!foundThemeVariantAsset) {
31
+ return;
32
+ }
33
+ themeVariantCssAssets[themeVariant] = {
34
+ fileName: foundThemeVariantAsset.name,
35
+ };
36
+ });
37
+ return themeVariantCssAssets;
38
+ }
39
+
40
+ /**
41
+ * Retrieves the CSS assets from the compilation based on the provided options.
42
+ *
43
+ * @param {Object} compilation - The compilation object.
44
+ * @param {Object} options - The options for retrieving the CSS assets.
45
+ * @param {boolean} [options.isBrandOverride=false] - Indicates if the assets are for a brand override.
46
+ * @param {Object} [options.brandThemeCss] - The brand theme CSS object.
47
+ * @param {Object} [options.paragonThemeCss] - The Paragon theme CSS object.
48
+ * @return {Object} - The CSS assets, including the core CSS asset and theme variant CSS assets.
49
+ */
50
+ function getCssAssetsFromCompilation(compilation, {
51
+ isBrandOverride = false,
52
+ brandThemeCss,
53
+ paragonThemeCss,
54
+ }) {
55
+ const assetSubstring = isBrandOverride ? 'brand' : 'paragon';
56
+ const paragonAssets = compilation.getAssets().filter(asset => asset.name.includes(assetSubstring) && asset.name.endsWith('.css'));
57
+ const coreCssAsset = findCoreCssAsset(paragonAssets);
58
+ const themeVariantCssAssets = findThemeVariantCssAssets(paragonAssets, {
59
+ isBrandOverride,
60
+ paragonThemeCss,
61
+ brandThemeCss,
62
+ });
63
+ return {
64
+ coreCssAsset: {
65
+ fileName: coreCssAsset?.name,
66
+ },
67
+ themeVariantCssAssets,
68
+ };
69
+ }
70
+
71
+ module.exports = {
72
+ findCoreCssAsset,
73
+ findThemeVariantCssAssets,
74
+ getCssAssetsFromCompilation,
75
+ };