@openedx/frontend-base 1.0.0-alpha.0 → 1.0.0-alpha.2

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 (164) hide show
  1. package/config/types.js +0 -2
  2. package/config/webpack/plugins/html-webpack-new-relic-plugin/test/HtmlWebpackNewRelicPlugin.test.js +66 -0
  3. package/package.json +8 -1
  4. package/runtime/__mocks__/file.js +1 -0
  5. package/runtime/__mocks__/svg.js +1 -0
  6. package/runtime/__mocks__/universal-cookie.js +6 -0
  7. package/runtime/analytics/interface.test.js +242 -0
  8. package/runtime/auth/AxiosJwtAuthService.test.jsx +1076 -0
  9. package/runtime/auth/interceptors/createRetryInterceptor.test.js +23 -0
  10. package/runtime/config/getExternalLinkUrl.test.js +76 -0
  11. package/runtime/i18n/lib.test.js +230 -0
  12. package/runtime/initialize.async.function.config.test.js +43 -0
  13. package/runtime/initialize.const.config.test.js +41 -0
  14. package/runtime/initialize.function.config.test.js +41 -0
  15. package/runtime/initialize.test.js +356 -0
  16. package/runtime/logging/NewRelicLoggingService.test.js +214 -0
  17. package/runtime/react/AuthenticatedPageRoute.test.jsx +135 -0
  18. package/runtime/react/ErrorBoundary.test.jsx +83 -0
  19. package/runtime/react/SiteProvider.test.jsx +66 -0
  20. package/runtime/react/hooks.test.jsx +104 -0
  21. package/runtime/routing/utils.test.ts +7 -0
  22. package/runtime/scripts/GoogleAnalyticsLoader.test.ts +77 -0
  23. package/runtime/site.config.test.tsx +33 -0
  24. package/runtime/slots/Slot.test.tsx +40 -0
  25. package/runtime/slots/layout/DefaultSlotLayout.test.tsx +31 -0
  26. package/runtime/slots/layout/hooks.test.tsx +178 -0
  27. package/runtime/slots/layout/utils.test.ts +67 -0
  28. package/runtime/slots/types.ts +1 -0
  29. package/runtime/slots/utils.test.ts +64 -0
  30. package/runtime/slots/utils.ts +28 -9
  31. package/runtime/testing/initializeMockApp.test.ts +66 -0
  32. package/runtime/utils.test.js +116 -0
  33. package/shell/Logo.test.tsx +32 -0
  34. package/shell/__mocks__/file.js +1 -0
  35. package/shell/__mocks__/svg.js +1 -0
  36. package/shell/__mocks__/universal-cookie.js +6 -0
  37. package/shell/app.ts +14 -0
  38. package/shell/dev/devHome/app.ts +2 -2
  39. package/shell/dev/slotShowcase/app.tsx +9 -9
  40. package/shell/header/app.tsx +3 -3
  41. package/shell/router/createRouter.test.tsx +50 -0
  42. package/shell/router/getAppRoutes.test.tsx +59 -0
  43. package/shell/site.config.dev.tsx +3 -3
  44. package/shell/site.config.test.tsx +16 -0
  45. package/tools/dist/cli/intl-imports.test.js +146 -0
  46. package/tools/dist/cli/openedx.js +1 -15
  47. package/tools/dist/cli/utils/printUsage.js +0 -9
  48. package/tools/dist/types.js +0 -2
  49. package/tools/dist/webpack/plugins/html-webpack-new-relic-plugin/test/HtmlWebpackNewRelicPlugin.test.js +66 -0
  50. package/types.ts +1 -1
  51. package/eslint.config.js +0 -18
  52. package/frontend-base.d.ts +0 -8
  53. package/jest.config.js +0 -7
  54. package/openedx-frontend-base.tgz +0 -0
  55. package/test-site/app.d.ts +0 -15
  56. package/test-site/dist/176.436443549ebb858db483.js +0 -2
  57. package/test-site/dist/176.436443549ebb858db483.js.map +0 -1
  58. package/test-site/dist/362.536eff787d2380fe246c.js +0 -2
  59. package/test-site/dist/362.536eff787d2380fe246c.js.map +0 -1
  60. package/test-site/dist/653.486966b108d224551296.js +0 -2
  61. package/test-site/dist/653.486966b108d224551296.js.map +0 -1
  62. package/test-site/dist/74e025d3fe9a7b7f8503054e2563b353.jpg +0 -0
  63. package/test-site/dist/806.323cf6496ad0a7fe73a7.js +0 -3
  64. package/test-site/dist/806.323cf6496ad0a7fe73a7.js.LICENSE.txt +0 -106
  65. package/test-site/dist/806.323cf6496ad0a7fe73a7.js.map +0 -1
  66. package/test-site/dist/95ec738c0b7faac5b5c9126794446bbd.svg +0 -4
  67. package/test-site/dist/app.612058b36c74787759ac.css +0 -61
  68. package/test-site/dist/app.612058b36c74787759ac.css.map +0 -1
  69. package/test-site/dist/app.612058b36c74787759ac.js +0 -2
  70. package/test-site/dist/app.612058b36c74787759ac.js.map +0 -1
  71. package/test-site/dist/cb28cdb1468c915e27e5cec9af64f22f.svg +0 -1
  72. package/test-site/dist/index.html +0 -1
  73. package/test-site/dist/report.html +0 -39
  74. package/test-site/dist/runtime.c7aeaf7b967496cb076f.js +0 -2
  75. package/test-site/dist/runtime.c7aeaf7b967496cb076f.js.map +0 -1
  76. package/test-site/eslint.config.js +0 -12
  77. package/test-site/package-lock.json +0 -19226
  78. package/test-site/package.json +0 -29
  79. package/test-site/public/index.html +0 -10
  80. package/test-site/site.config.build.tsx +0 -27
  81. package/test-site/site.config.dev.tsx +0 -27
  82. package/test-site/src/authenticated-page/AuthenticatedPage.tsx +0 -18
  83. package/test-site/src/authenticated-page/i18n/index.ts +0 -27
  84. package/test-site/src/authenticated-page/index.tsx +0 -28
  85. package/test-site/src/example-page/ExamplePage.tsx +0 -79
  86. package/test-site/src/example-page/Image.tsx +0 -11
  87. package/test-site/src/example-page/ParagonPreview.jsx +0 -66
  88. package/test-site/src/example-page/apple.jpg +0 -0
  89. package/test-site/src/example-page/apple.svg +0 -1
  90. package/test-site/src/example-page/index.ts +0 -16
  91. package/test-site/src/i18n/README.md +0 -3
  92. package/test-site/src/i18n/messages/frontend-app-sample/ar.json +0 -4
  93. package/test-site/src/i18n/messages/frontend-app-sample/eo.json +0 -1
  94. package/test-site/src/i18n/messages/frontend-app-sample/es_419.json +0 -4
  95. package/test-site/src/i18n/messages/frontend-component-emptylangs/ar.json +0 -1
  96. package/test-site/src/i18n/messages/frontend-component-singlelang/ar.json +0 -3
  97. package/test-site/src/iframe-widget/IframeWidget.tsx +0 -14
  98. package/test-site/src/iframe-widget/index.ts +0 -16
  99. package/test-site/src/index.tsx +0 -3
  100. package/test-site/src/messages.js +0 -11
  101. package/test-site/src/site.scss +0 -11
  102. package/test-site/tsconfig.json +0 -14
  103. package/tools/babel/babel.config.js +0 -27
  104. package/tools/babel.config.js +0 -3
  105. package/tools/cli/README.md +0 -29
  106. package/tools/cli/commands/pack.ts +0 -9
  107. package/tools/cli/commands/release.ts +0 -27
  108. package/tools/cli/commands/serve.ts +0 -43
  109. package/tools/cli/intl-imports.ts +0 -274
  110. package/tools/cli/openedx.ts +0 -101
  111. package/tools/cli/transifex-utils.ts +0 -75
  112. package/tools/cli/utils/ensureConfigFilenameOption.ts +0 -40
  113. package/tools/cli/utils/formatter.ts +0 -10
  114. package/tools/cli/utils/getResolvedConfigPath.ts +0 -23
  115. package/tools/cli/utils/prettyPrintTitle.ts +0 -15
  116. package/tools/cli/utils/printUsage.ts +0 -53
  117. package/tools/config-helpers/createConfig.ts +0 -8
  118. package/tools/config-helpers/createLintConfig.ts +0 -14
  119. package/tools/config-helpers/getBaseConfig.ts +0 -11
  120. package/tools/defaultConfigPaths.ts +0 -30
  121. package/tools/dist/cli/commands/pack.js +0 -14
  122. package/tools/dist/cli/commands/release.js +0 -28
  123. package/tools/eslint/base.eslint.config.js +0 -124
  124. package/tools/eslint/modules.d.ts +0 -5
  125. package/tools/eslint.config.js +0 -15
  126. package/tools/index.ts +0 -3
  127. package/tools/jest/jest.config.js +0 -30
  128. package/tools/jest.config.js +0 -19
  129. package/tools/tsconfig.json +0 -24
  130. package/tools/types.ts +0 -21
  131. package/tools/typescript/tsconfig.json +0 -32
  132. package/tools/webpack/common-config/README.md +0 -15
  133. package/tools/webpack/common-config/all/getCodeRules.ts +0 -51
  134. package/tools/webpack/common-config/all/getFileLoaderRules.ts +0 -23
  135. package/tools/webpack/common-config/all/getIgnoreWarnings.ts +0 -13
  136. package/tools/webpack/common-config/all/getImageMinimizer.ts +0 -26
  137. package/tools/webpack/common-config/all/getStylesheetRule.ts +0 -111
  138. package/tools/webpack/common-config/dev/getDevServer.ts +0 -35
  139. package/tools/webpack/common-config/index.ts +0 -6
  140. package/tools/webpack/common-config/site/getHtmlWebpackPlugin.ts +0 -11
  141. package/tools/webpack/modules.d.ts +0 -6
  142. package/tools/webpack/plugins/html-webpack-new-relic-plugin/HtmlWebpackNewRelicPlugin.ts +0 -102
  143. package/tools/webpack/plugins/html-webpack-new-relic-plugin/LICENSE +0 -21
  144. package/tools/webpack/plugins/html-webpack-new-relic-plugin/README.md +0 -7
  145. package/tools/webpack/plugins/html-webpack-new-relic-plugin/index.js +0 -3
  146. package/tools/webpack/plugins/html-webpack-new-relic-plugin/test/fixtures/entry.js +0 -1
  147. package/tools/webpack/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.ts +0 -134
  148. package/tools/webpack/plugins/paragon-webpack-plugin/index.ts +0 -3
  149. package/tools/webpack/plugins/paragon-webpack-plugin/utils/assetUtils.ts +0 -71
  150. package/tools/webpack/plugins/paragon-webpack-plugin/utils/htmlUtils.ts +0 -72
  151. package/tools/webpack/plugins/paragon-webpack-plugin/utils/index.ts +0 -6
  152. package/tools/webpack/plugins/paragon-webpack-plugin/utils/paragonStylesheetUtils.ts +0 -131
  153. package/tools/webpack/plugins/paragon-webpack-plugin/utils/scriptUtils.ts +0 -144
  154. package/tools/webpack/plugins/paragon-webpack-plugin/utils/stylesheetUtils.ts +0 -106
  155. package/tools/webpack/plugins/paragon-webpack-plugin/utils/tagUtils.ts +0 -54
  156. package/tools/webpack/types.ts +0 -69
  157. package/tools/webpack/utils/getLocalAliases.ts +0 -65
  158. package/tools/webpack/utils/getPublicPath.ts +0 -3
  159. package/tools/webpack/utils/getResolvedSiteConfigPath.ts +0 -28
  160. package/tools/webpack/utils/paragonUtils.ts +0 -152
  161. package/tools/webpack/webpack.config.build.ts +0 -93
  162. package/tools/webpack/webpack.config.dev.shell.ts +0 -122
  163. package/tools/webpack/webpack.config.dev.ts +0 -90
  164. package/tsconfig.json +0 -23
@@ -1,28 +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.default = release;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const child_process_1 = require("child_process");
9
- const fs_1 = require("fs");
10
- const path_1 = __importDefault(require("path"));
11
- function release() {
12
- const tsconfigPath = path_1.default.resolve(process.cwd(), './tsconfig.build.json');
13
- if (!(0, fs_1.existsSync)(tsconfigPath)) {
14
- console.error(chalk_1.default.red('openedx release: the library must include a tsconfig.build.json. Aborting.'));
15
- process.exit(1);
16
- }
17
- // Clean up our dist folder.
18
- (0, fs_1.rmSync)(path_1.default.resolve(process.cwd(), 'dist'), { recursive: true, force: true });
19
- (0, child_process_1.execSync)(`tsc --project ${path_1.default.resolve(process.cwd(), './tsconfig.build.json')}`, { stdio: 'inherit' });
20
- // Copy all non JS/TS files from src into dist. This is so imports of our assets still work.
21
- (0, child_process_1.execSync)(`rsync -aR src/**/* --exclude='*.tsx' --exclude='*.ts' --exclude='*.js' --exclude='*.jsx' dist/`);
22
- // The above rsync command will put the files in dist/src - move them up a folder into dist,
23
- // merging them into the compiled code there, and then delete dist/src.
24
- if ((0, fs_1.existsSync)(path_1.default.resolve(process.cwd(), 'dist/src'))) {
25
- (0, child_process_1.execSync)('cp -R dist/src/* dist');
26
- (0, child_process_1.execSync)('rm -rf dist/src');
27
- }
28
- }
@@ -1,124 +0,0 @@
1
- // @ts-check
2
-
3
- const { fixupPluginRules } = require('@eslint/compat');
4
- const eslint = require('@eslint/js');
5
- const formatjs = require('eslint-plugin-formatjs');
6
- const jest = require('eslint-plugin-jest');
7
- const jsxA11y = require('eslint-plugin-jsx-a11y');
8
- const react = require('eslint-plugin-react');
9
- const reactHooks = require('eslint-plugin-react-hooks');
10
- const globals = require('globals');
11
- const tseslint = require('typescript-eslint');
12
- const stylistic = require('@stylistic/eslint-plugin');
13
-
14
- module.exports = tseslint.config(
15
- eslint.configs.recommended,
16
- ...tseslint.configs.stylisticTypeChecked,
17
- ...tseslint.configs.recommended,
18
- stylistic.configs['recommended-flat'],
19
- {
20
- ignores: [
21
- 'coverage/*',
22
- 'dist/*',
23
- 'node_modules/*',
24
- '**/__mocks__/*',
25
- '**/__snapshots__/*',
26
- ],
27
- },
28
- {
29
- languageOptions: {
30
- parserOptions: {
31
- projectService: true,
32
- }
33
- }
34
- },
35
- {
36
- languageOptions: {
37
- ...(react.configs.flat !== undefined ? react.configs.flat.recommended.languageOptions : {}),
38
- globals: {
39
- ...globals.browser,
40
- ...globals.node,
41
- ...globals.jest,
42
- PARAGON_THEME: 'readonly',
43
- newrelic: 'readonly',
44
- },
45
- },
46
- plugins: {
47
- jest,
48
- // Type assertion is workaround for incorrect TypeScript
49
- // types in eslint-plugin-react
50
- //
51
- // TODO: Remove when types are fixed in eslint-plugin-react
52
- // - https://github.com/jsx-eslint/eslint-plugin-react/issues/3838
53
- react: /** @type {import('eslint').ESLint.Plugin} */ (react),
54
- 'react-hooks': fixupPluginRules(reactHooks),
55
- formatjs,
56
- 'jsx-a11y': jsxA11y,
57
- },
58
- settings: {
59
- react: {
60
- version: 'detect',
61
- }
62
- }
63
- },
64
- {
65
- rules: {
66
- // For some reasons the 'flat' key in react.configs is optional, so Typescript complains if
67
- // we don't guard using it. But... it exists in the export, so something's odd with their types.
68
- ...(react.configs.flat !== undefined ? react.configs.flat.recommended.rules : {}),
69
- ...(react.configs.flat !== undefined ? react.configs.flat['jsx-runtime'].rules : {}),
70
- ...reactHooks.configs.recommended.rules,
71
- '@typescript-eslint/no-explicit-any': 'off',
72
- '@typescript-eslint/non-nullable-type-assertion-style': 'off',
73
- 'react/no-array-index-key': 'error',
74
- 'formatjs/enforce-description': ['error', 'literal'],
75
- 'jsx-a11y/label-has-associated-control': ['error', {
76
- labelComponents: [],
77
- labelAttributes: [],
78
- controlComponents: [],
79
- assert: 'htmlFor',
80
- depth: 25,
81
- }],
82
- // https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/340#issuecomment-338424908
83
- 'jsx-a11y/anchor-is-valid': ['error', {
84
- components: ['Link'],
85
- specialLink: ['to'],
86
- }],
87
- '@typescript-eslint/no-unused-vars': ['error', {
88
- caughtErrors: 'none',
89
- }],
90
- '@typescript-eslint/no-empty-function': 'off',
91
- '@stylistic/semi': ['error', 'always', { omitLastInOneLineBlock: true, omitLastInOneLineClassBody: true }],
92
- '@stylistic/quotes': ['error', 'single', {
93
- avoidEscape: true,
94
- allowTemplateLiterals: true,
95
- }],
96
- '@stylistic/comma-dangle': 'off',
97
- '@stylistic/quote-props': ['error', 'as-needed'],
98
- '@stylistic/arrow-parens': 'off',
99
- '@stylistic/jsx-one-expression-per-line': 'off',
100
- '@stylistic/multiline-ternary': 'off',
101
- '@stylistic/brace-style': ['error', '1tbs'],
102
- '@stylistic/member-delimiter-style': ['error', {
103
- multiline: {
104
- delimiter: 'comma',
105
- requireLast: true,
106
- },
107
- singleline: {
108
- delimiter: 'comma',
109
- requireLast: false,
110
- }
111
- }],
112
- },
113
- },
114
- {
115
- files: [
116
- 'babel.config.js',
117
- 'jest.config.js',
118
- 'eslint.config.js'
119
- ],
120
- rules: {
121
- '@typescript-eslint/no-require-imports': 'off'
122
- }
123
- }
124
- );
@@ -1,5 +0,0 @@
1
- // This file needs to exist to declare modules for dependencies that don't publish their types.
2
-
3
- declare module 'eslint-plugin-jest';
4
- declare module 'eslint-plugin-jsx-a11y';
5
- declare module 'eslint-plugin-react-hooks';
@@ -1,15 +0,0 @@
1
- // @ts-check
2
-
3
- const tseslint = require('typescript-eslint');
4
- const eslintConfig = require('./eslint/base.eslint.config.js');
5
-
6
- module.exports = tseslint.config(
7
- {
8
- extends: eslintConfig,
9
- },
10
- {
11
- rules: {
12
- '@typescript-eslint/no-require-imports': 'off'
13
- }
14
- },
15
- );
package/tools/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as createConfig } from './config-helpers/createConfig';
2
- export { default as createLintConfig } from './config-helpers/createLintConfig';
3
- export { default as getBaseConfig } from './config-helpers/getBaseConfig';
@@ -1,30 +0,0 @@
1
- const path = require('path');
2
-
3
- module.exports = {
4
- testEnvironment: 'jsdom',
5
- testEnvironmentOptions: {
6
- url: 'http://localhost/',
7
- },
8
- rootDir: process.cwd(),
9
- moduleNameMapper: {
10
- '\\.(css|scss)$': require.resolve('identity-obj-proxy'),
11
- 'site.config': path.resolve(process.cwd(), './site.config.test.tsx'),
12
- },
13
- collectCoverageFrom: [
14
- 'src/**/*.{js,jsx,ts,tsx}',
15
- ],
16
- coveragePathIgnorePatterns: [
17
- '/node_modules/',
18
- ],
19
- transformIgnorePatterns: [
20
- '/node_modules/(?!(@openedx|@edx)/)',
21
- ],
22
- modulePathIgnorePatterns: [
23
- '/dist/',
24
- ],
25
- testPathIgnorePatterns: [
26
- '/site.config.test.tsx',
27
- '/node_modules/',
28
- '/dist/',
29
- ],
30
- };
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- testEnvironment: 'node',
3
- testEnvironmentOptions: {
4
- url: 'http://localhost/',
5
- },
6
- collectCoverageFrom: [
7
- 'cli/**/*.{js,jsx,ts,tsx}',
8
- ],
9
- transformIgnorePatterns: [
10
- '/node_modules/(?!(@openedx|@edx)/)',
11
- ],
12
- modulePathIgnorePatterns: [
13
- '/dist/',
14
- ],
15
- testPathIgnorePatterns: [
16
- '/node_modules/',
17
- '/dist/',
18
- ],
19
- };
@@ -1,24 +0,0 @@
1
- {
2
- "extends": "@tsconfig/node20/tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- "outDir": "dist",
6
- "noEmit": false,
7
- "allowJs": true,
8
- "resolveJsonModule": true,
9
- },
10
- "include": [
11
- "babel/**/*",
12
- "cli/**/*",
13
- "config-helpers/**/*",
14
- "jest/jest.config.js",
15
- "typescript/tsconfig.json",
16
- "webpack/**/*",
17
- "types.ts",
18
- "index.ts",
19
- "defaultConfigPaths.ts",
20
- "eslint/**/*",
21
- "eslint.config.js",
22
- "jest.config.js",
23
- ],
24
- }
package/tools/types.ts DELETED
@@ -1,21 +0,0 @@
1
- export enum ConfigTypes {
2
- BABEL = 'babel',
3
- WEBPACK_BUILD = 'webpack-build',
4
- WEBPACK_DEV = 'webpack-dev',
5
- WEBPACK_DEV_SHELL = 'webpack-dev-shell',
6
- LINT = 'lint',
7
- TEST = 'test',
8
- }
9
-
10
- export enum CommandTypes {
11
- RELEASE = 'release',
12
- PACK = 'pack',
13
- LINT = 'lint',
14
- TEST = 'test',
15
- BUILD = 'build',
16
- DEV_SHELL = 'dev:shell',
17
- DEV = 'dev',
18
- FORMAT_JS = 'formatjs',
19
- SERVE = 'serve',
20
- HELP = 'help',
21
- }
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "allowSyntheticDefaultImports": true,
5
- "declaration": true,
6
- "esModuleInterop": true,
7
- "forceConsistentCasingInFileNames": true,
8
- "jsx": "react-jsx",
9
- "lib": [
10
- "DOM",
11
- "DOM.Iterable",
12
- "ESNext",
13
- "esnext.intl",
14
- "es2017.intl",
15
- "es2018.intl"
16
- ],
17
- "isolatedModules": true,
18
- "module": "ESNext",
19
- "moduleResolution": "node",
20
- "noEmit": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "noImplicitAny": false,
23
- "noImplicitThis": true,
24
- "noUnusedParameters": true,
25
- "resolveJsonModule": true,
26
- "skipLibCheck": true,
27
- "sourceMap": true,
28
- "strict": true,
29
- "strictFunctionTypes": false,
30
- "target": "ES6"
31
- }
32
- }
@@ -1,15 +0,0 @@
1
- # Using this 'common-config' folder
2
-
3
- **Don't try too hard to re-use code.**
4
-
5
- If extracting webpack config to this folder makes the config harder to reason, then it's not worth it.
6
-
7
- The things that have been extracted so far are either:
8
-
9
- 1) So similar (or exactly the same) across configs that they're easy to understand. `getHtmlWebpackPlugin`, `getImageMinimizer`, `ignoreWarnings`, and `getFileLoaderRules` fit in this category.
10
- 2) Need to be kept in sync and tended to drift, despite being a bit different. The `getStylesheetRule` and `getCodeRules` functions fit in this category. They are arguably easier to reason all in one place so we can understand the differences between
11
- them.
12
-
13
- What they all share in common is that they're fairly long and make the configs harder to read. Extracting them has made the configs about a page of text and all the important high-level stuff that makes them different is still present.
14
-
15
- More or less. Use your judgment.
@@ -1,51 +0,0 @@
1
- import { transform } from '@formatjs/ts-transformer';
2
- import ReactRefreshTypeScript from 'react-refresh-typescript';
3
-
4
- import { RuleSetRule } from 'webpack';
5
-
6
- export default function getCodeRules(mode: 'dev' | 'production', resolvedSiteConfigPath: string) {
7
- const rules: RuleSetRule[] = [
8
- {
9
- test: /\.(js|jsx|ts|tsx)$/,
10
- include: [
11
- /src/,
12
- /node_modules\/@openedx\/frontend-base/,
13
- resolvedSiteConfigPath,
14
- ],
15
- use: {
16
- loader: require.resolve('ts-loader'),
17
- options: {
18
- transpileOnly: true,
19
- compilerOptions: {
20
- noEmit: false,
21
- },
22
- getCustomTransformers() {
23
- const before = [
24
- transform({
25
- overrideIdFn: '[sha512:contenthash:base64:6]',
26
- }),
27
- ];
28
- if (mode === 'dev') {
29
- before.push(ReactRefreshTypeScript());
30
- }
31
- return {
32
- before,
33
- };
34
- },
35
- },
36
- },
37
- },
38
- ];
39
-
40
- if (mode === 'production') {
41
- rules.push({
42
- test: /\.(js|jsx|ts|tsx)$/,
43
- use: [
44
- require.resolve('source-map-loader'),
45
- ],
46
- enforce: 'pre',
47
- });
48
- }
49
-
50
- return rules;
51
- }
@@ -1,23 +0,0 @@
1
- export default function getFileLoaderRules() {
2
- return [
3
- // Webpack, by default, uses the url-loader for images and fonts that are required/included by
4
- // files it processes, which just base64 encodes them and inlines them in the javascript
5
- // bundles. This makes the javascript bundles ginormous and defeats caching so we will use the
6
- // file-loader instead to copy the files directly to the output directory.
7
- {
8
- test: /\.(woff2?|ttf|svg|eot)(\?v=\d+\.\d+\.\d+)?$/,
9
- loader: require.resolve('file-loader'),
10
- },
11
- {
12
- test: /favicon.ico$/,
13
- loader: require.resolve('file-loader'),
14
- options: {
15
- name: '[name].[ext]', // <-- retain original file name
16
- },
17
- },
18
- {
19
- test: /\.(jpe?g|png|gif)(\?v=\d+\.\d+\.\d+)?$/,
20
- loader: require.resolve('file-loader'),
21
- },
22
- ];
23
- }
@@ -1,13 +0,0 @@
1
- import { WebpackError } from 'webpack';
2
-
3
- export default function getIgnoreWarnings() {
4
- return [
5
- // Ignore warnings raised by source-map-loader.
6
- // some third party packages may ship miss-configured sourcemaps, that interrupts the build
7
- // See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169
8
- (warning: WebpackError) => !!(
9
- // @ts-expect-error 'resource' is something TypeScript can't find for whatever reason.
10
- warning.module?.resource.includes('node_modules')
11
- && warning.details?.includes('source-map-loader')),
12
- ];
13
- }
@@ -1,26 +0,0 @@
1
- import ImageMinimizerPlugin, { Compiler } from 'image-minimizer-webpack-plugin';
2
- import { WebpackPluginInstance } from 'webpack';
3
-
4
- // This is pulled from the definition of optimization.minimizer in the webpack Configuration type.
5
- type ImageMinimizerReturnType = (false | '' | 0 | '...' | ((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance | null | undefined)[] | undefined;
6
-
7
- export default function getImageMinimizer(): ImageMinimizerReturnType {
8
- return [
9
- '...',
10
- new ImageMinimizerPlugin({
11
- minimizer: {
12
- implementation: ImageMinimizerPlugin.sharpMinify,
13
- options: {
14
- encodeOptions: {
15
- ...['png', 'jpeg', 'jpg'].reduce((accumulator, value) => (
16
- { ...accumulator, [value]: { progressive: true, quality: 65 } }
17
- ), {}),
18
- gif: {
19
- effort: 5,
20
- },
21
- },
22
- },
23
- },
24
- }),
25
- ];
26
- }
@@ -1,111 +0,0 @@
1
- import PostCssAutoprefixerPlugin from 'autoprefixer';
2
- import CssNano from 'cssnano';
3
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
4
- import path from 'path';
5
- import PostCssCustomMediaCSS from 'postcss-custom-media';
6
- import PostCssRTLCSS from 'postcss-rtlcss';
7
- import { RuleSetRule } from 'webpack';
8
-
9
- /**
10
- * There are a few things we need to do here.
11
- *
12
- * - We only want to use MiniCssExtractPlugin on dependencies in dev, but not on our source code.
13
- * - We only want CssNano in production.
14
- */
15
- export default function getStylesheetRule(mode: 'dev' | 'production'): RuleSetRule {
16
- if (mode === 'production') {
17
- // In the production case, all files should go through MiniCssExtractPlugin.
18
- return {
19
- test: /(.scss|.css)$/,
20
- use: [
21
- MiniCssExtractPlugin.loader,
22
- ...getStyleUseConfig(mode),
23
- ],
24
- };
25
- } else {
26
- // In the dev case, only our @openedx dependencies go through MiniCssExtractPlugin.
27
- // We are not extracting CSS from the javascript bundles in development because extracting
28
- // prevents hot-reloading from working, it increases build time, and we don't care about
29
- // flash-of-unstyled-content issues in development.
30
- return {
31
- test: /(.scss|.css)$/,
32
- oneOf: [
33
- {
34
- resource: /(@openedx\/paragon|@(open)?edx\/brand)/,
35
- use: [
36
- MiniCssExtractPlugin.loader,
37
- ...getStyleUseConfig(mode),
38
- ],
39
- },
40
- {
41
- use: [
42
- require.resolve('style-loader'), // creates style nodes from JS strings
43
- ...getStyleUseConfig(mode),
44
- ],
45
- },
46
- ]
47
- };
48
- }
49
- }
50
-
51
- function getStyleUseConfig(mode: 'dev' | 'production') {
52
- return [
53
- {
54
- loader: require.resolve('css-loader'), // translates CSS into CommonJS
55
- options: {
56
- sourceMap: true,
57
- modules: {
58
- // namedExport defaults to true in css-loader v7, but we rely on the old behavior.
59
- // Details here:
60
- // https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#700-2024-04-04
61
- namedExport: false,
62
- mode: 'icss',
63
- },
64
- },
65
- },
66
- {
67
- loader: require.resolve('postcss-loader'),
68
- options: {
69
- postcssOptions: {
70
- plugins: getPostCssLoaderPlugins(mode), // Different behavior for dev and production.
71
- },
72
- },
73
- },
74
- require.resolve('resolve-url-loader'),
75
- {
76
- loader: require.resolve('sass-loader'), // compiles Sass to CSS
77
- options: {
78
- sourceMap: true,
79
- sassOptions: {
80
- includePaths: [
81
- path.join(process.cwd(), 'node_modules'),
82
- path.join(process.cwd(), 'src'),
83
- ],
84
- // Silences compiler deprecation warnings. They mostly come from bootstrap and/or paragon.
85
- quietDeps: true,
86
- silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin', 'legacy-js-api'],
87
- },
88
- },
89
- },
90
- ];
91
- }
92
-
93
- /**
94
- * This exists just to conditionally include CssNano in production.
95
- */
96
- function getPostCssLoaderPlugins(mode: 'dev' | 'production') {
97
- const plugins: any[] = [
98
- PostCssAutoprefixerPlugin({
99
- remove: false, // Prevents removing vendor prefixes
100
- }),
101
- PostCssRTLCSS(),
102
- ];
103
-
104
- // We want CSSNano third, and only in production.
105
- if (mode === 'production') {
106
- plugins.push(CssNano());
107
- }
108
-
109
- plugins.push(PostCssCustomMediaCSS());
110
- return plugins;
111
- }
@@ -1,35 +0,0 @@
1
- import path from 'path';
2
- import { Configuration } from 'webpack-dev-server';
3
-
4
- import getPublicPath from '../../utils/getPublicPath';
5
-
6
- export default function getDevServer(): Configuration {
7
- return {
8
- allowedHosts: 'all',
9
- headers: {
10
- 'Access-Control-Allow-Origin': '*',
11
- },
12
- // For obvious reasons, 'auto' won't work for publicPath here, so we
13
- // force '/' unless PUBLIC_PATH is set.
14
- historyApiFallback: {
15
- index: path.join(getPublicPath('/'), 'index.html'),
16
- disableDotRule: true,
17
- },
18
- host: 'apps.local.openedx.io',
19
- hot: true,
20
- port: process.env.PORT ?? 8080,
21
- proxy: [
22
- {
23
- context: ['/api/mfe_config/v1'],
24
- target: 'http://local.openedx.io:8000',
25
- changeOrigin: true,
26
- }
27
- ],
28
- // Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
29
- // for the WebpackDevServer client so it can learn when the files were
30
- // updated. The WebpackDevServer client is included as an entry point
31
- // in the webpack development configuration. Note that only changes
32
- // to CSS are currently hot reloaded. JS changes will refresh the browser.
33
- webSocketServer: 'ws',
34
- };
35
- }
@@ -1,6 +0,0 @@
1
- export { default as getCodeRules } from './all/getCodeRules';
2
- export { default as getFileLoaderRules } from './all/getFileLoaderRules';
3
- export { default as getImageMinimizer } from './all/getImageMinimizer';
4
- export { default as getStylesheetRule } from './all/getStylesheetRule';
5
- export { default as getDevServer } from './dev/getDevServer';
6
- export { default as getHtmlWebpackPlugin } from './site/getHtmlWebpackPlugin';
@@ -1,11 +0,0 @@
1
- import HtmlWebpackPlugin from 'html-webpack-plugin';
2
- import path from 'path';
3
-
4
- // Generates an HTML file in the output directory.
5
- export default function getHtmlWebpackPlugin() {
6
- return new HtmlWebpackPlugin({
7
- inject: true, // Appends script tags linking to the webpack bundles at the end of the body
8
- template: path.resolve(process.cwd(), 'public/index.html'),
9
- chunks: ['app'],
10
- });
11
- }
@@ -1,6 +0,0 @@
1
- // This file needs to exist to declare modules for dependencies that don't publish their types.
2
-
3
- declare module 'postcss-custom-media';
4
- declare module '@edx/new-relic-source-map-webpack-plugin';
5
- declare module 'mini-css-extract-plugin';
6
- declare module 'webpack-bundle-analyzer';