@elliemae/pui-cli 6.0.0-beta.8 → 6.0.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 (50) hide show
  1. package/README.md +8 -0
  2. package/lib/cli-commands/build.js +11 -5
  3. package/lib/cli-commands/pack.js +18 -78
  4. package/lib/cli-commands/test.js +1 -12
  5. package/lib/cli-commands/tsc.js +103 -0
  6. package/lib/cli-commands/utils.js +9 -4
  7. package/lib/cli-commands/vitest.js +66 -0
  8. package/lib/cli.js +2 -0
  9. package/lib/index.js +3 -1
  10. package/lib/lint/eslint/common.js +16 -8
  11. package/lib/lint/eslint/typescript/common.js +6 -1
  12. package/lib/lint/eslint/typescript/non-react.js +1 -1
  13. package/lib/lint/eslint/typescript/react.js +6 -1
  14. package/lib/lint/lint-staged.config.js +8 -1
  15. package/lib/lint/stylelint.config.js +0 -1
  16. package/lib/pui-config/index.js +18 -0
  17. package/lib/server/index.js +0 -7
  18. package/lib/server/middlewares/addDevMiddlewares.js +2 -2
  19. package/lib/server/middlewares/addProdMiddlewares.js +10 -3
  20. package/lib/testing/jest.config.js +18 -8
  21. package/lib/testing/jest.node.config.js +8 -0
  22. package/lib/testing/mocks/matchMedia.js +12 -6
  23. package/lib/testing/mocks/pui-app-loader.js +1 -3
  24. package/lib/testing/mocks/pui-diagnostics.js +27 -35
  25. package/lib/testing/mocks/pui-user-monitoring.js +3 -5
  26. package/lib/testing/mocks/retry-axios.js +3 -5
  27. package/lib/testing/mocks/svg.js +5 -3
  28. package/lib/testing/mocks/webpack-hmr.js +1 -0
  29. package/lib/testing/resolver.js +47 -0
  30. package/lib/testing/setup-react-env.js +3 -0
  31. package/lib/testing/setup-tests.js +28 -4
  32. package/lib/testing/vitest.config.ts +16 -0
  33. package/lib/testing/vitest.setup.ts +0 -0
  34. package/lib/transpile/.swcrc +11 -0
  35. package/lib/transpile/esbuild.js +116 -0
  36. package/lib/transpile/react-shim.js +2 -0
  37. package/lib/transpile/swcrc.config.js +13 -0
  38. package/lib/typescript/tsc-files/index.js +66 -0
  39. package/lib/typescript/tsc-files/utils.js +16 -0
  40. package/lib/webpack/helpers.js +44 -3
  41. package/lib/webpack/webpack.base.babel.js +47 -81
  42. package/lib/webpack/webpack.dev.babel.js +16 -10
  43. package/lib/webpack/webpack.lib.base.babel.js +33 -55
  44. package/lib/webpack/webpack.lib.dev.babel.js +2 -3
  45. package/lib/webpack/webpack.lib.prod.babel.js +5 -11
  46. package/lib/webpack/webpack.prod.babel.js +29 -24
  47. package/lib/webpack/webpack.storybook.js +19 -98
  48. package/package.json +116 -124
  49. package/lib/esbuild.js +0 -44
  50. package/lib/testing/setup-styled-components-tests.js +0 -1
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
2
  const { getAppConfig, getAssetPath } = require('../webpack/helpers');
3
+ const swcrcConfig = require('../transpile/swcrc.config.js');
3
4
 
4
5
  const name = '@elliemae/pui-cli';
5
6
  const rootDir = path.join('<rootDir>', 'node_modules', name);
@@ -42,8 +43,8 @@ const jestConfig = {
42
43
  '!app/*/RbGenerated*/*.{js, ts, jsx, tsx}',
43
44
  '!app/index.{js, ts, jsx, tsx}',
44
45
  '!app/global-styles.{js, ts, jsx, tsx}',
45
- '!app/*/*/loadable.{js, ts, jsx, tsx}',
46
- '!lib/*/*/loadable.{js, ts, jsx, tsx}',
46
+ '!app/**/loadable.{js, ts, jsx, tsx}',
47
+ '!lib/**/loadable.{js, ts, jsx, tsx}',
47
48
  ],
48
49
  coverageThreshold: {
49
50
  // Todo: enable the coverage threshold later
@@ -58,6 +59,7 @@ const jestConfig = {
58
59
  coverageReporters: ['lcov', 'html', 'text-summary'],
59
60
  moduleDirectories: ['node_modules', 'app', 'lib'],
60
61
  moduleNameMapper: {
62
+ '.*\\webpack-hmr(.[t|j]s)?$': `${getRootDir()}/lib/testing/mocks/webpack-hmr.js`,
61
63
  '.*\\.(css|scss)$': `${getRootDir()}/lib/testing/mocks/cssModule.js`,
62
64
  '.*\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ico)$': `${getRootDir()}/lib/testing/mocks/image.js`,
63
65
  '.*\\.svg$': `${getRootDir()}/lib/testing/mocks/svg.js`,
@@ -66,17 +68,24 @@ const jestConfig = {
66
68
  '@elliemae/pui-user-monitoring': `${getRootDir()}/lib/testing/mocks/pui-user-monitoring.js`,
67
69
  '@elliemae/pui-app-loader': `${getRootDir()}/lib/testing/mocks/pui-app-loader.js`,
68
70
  '@elliemae/pui-diagnostics': `${getRootDir()}/lib/testing/mocks/pui-diagnostics.js`,
71
+ 'react-spring/web': '<rootDir>/node_modules/react-spring/web.cjs.js',
72
+ 'react-spring/renderprops':
73
+ '<rootDir>/node_modules/react-spring/renderprops.cjs.js',
69
74
  'styled-components':
70
75
  '<rootDir>/node_modules/styled-components/dist/styled-components.cjs.js',
71
76
  },
77
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
72
78
  setupFilesAfterEnv: [`${getRootDir()}/lib/testing/setup-tests.js`],
73
79
  setupFiles: ['raf/polyfill', 'whatwg-fetch'],
74
- testRegex: '(app|lib).*/tests/.*\\.test\\.(js|ts)$',
80
+ testRegex: '(app|lib).*/tests/.*\\.test\\.[jt]sx?$',
75
81
  snapshotSerializers: [],
76
82
  testResultsProcessor: 'jest-sonar-reporter',
83
+ resolver: path.resolve(__dirname, './resolver.js'),
84
+ transform: {
85
+ '^.+\\.[jt]sx?$': ['@swc/jest', swcrcConfig],
86
+ },
77
87
  transformIgnorePatterns: [
78
- 'node_modules/(?!(@elliemae/*|lodash-es/*)/)',
79
- 'node_modules/@elliemae/em-platform-document-viewer',
88
+ 'node_modules/(?!(.*@elliemae/pui-cli|lodash-es|react-select|react-dates)/)',
80
89
  ],
81
90
  globals: {
82
91
  APP_CONFIG: getAppConfig(),
@@ -86,8 +95,9 @@ const jestConfig = {
86
95
  testEnvironment: 'jsdom',
87
96
  };
88
97
 
89
- if (isReactModule)
98
+ if (isReactModule && jestConfig.setupFilesAfterEnv)
90
99
  jestConfig.setupFilesAfterEnv.push(
91
- `${getRootDir()}/lib/testing/setup-styled-components-tests.js`,
100
+ `${getRootDir()}/lib/testing/setup-react-env.js`,
92
101
  );
93
- module.exports = jestConfig;
102
+
103
+ exports.jestConfig = jestConfig;
@@ -0,0 +1,8 @@
1
+ const { jestConfig } = require('./jest.config');
2
+ exports.jestNodeConfig = {
3
+ ...jestConfig,
4
+ testEnvironment: 'node',
5
+ transformIgnorePatterns: [],
6
+ setupFiles: [],
7
+ setupFilesAfterEnv: [],
8
+ };
@@ -1,13 +1,19 @@
1
1
  /**
2
2
  *
3
3
  */
4
- export default function () {
4
+ export default () => {
5
5
  Object.defineProperty(window, 'matchMedia', {
6
- value: () => ({
6
+ writable: true,
7
+ value: jest.fn().mockImplementation((query) => ({
7
8
  matches: false,
8
- addListener: () => {},
9
- removeListener: () => {},
10
- }),
9
+ media: query,
10
+ onchange: null,
11
+ addListener: jest.fn(), // Deprecated
12
+ removeListener: jest.fn(), // Deprecated
13
+ addEventListener: jest.fn(),
14
+ removeEventListener: jest.fn(),
15
+ dispatchEvent: jest.fn(),
16
+ })),
11
17
  });
12
18
 
13
19
  Object.defineProperty(window, 'getComputedStyle', {
@@ -15,4 +21,4 @@ export default function () {
15
21
  getPropertyValue: () => {},
16
22
  }),
17
23
  });
18
- }
24
+ };
@@ -1,3 +1 @@
1
- module.exports = {
2
- load: () => {},
3
- };
1
+ export const load = () => {};
@@ -1,36 +1,28 @@
1
- module.exports = {
2
- logger() {
3
- return {
4
- setLogLevel() {},
5
- setOptions() {},
6
- info() {},
7
- warn() {},
8
- error() {},
9
- trace() {},
10
- debug() {},
11
- audit() {},
12
- fatal() {},
13
- };
14
- },
15
- LogLevel: {
16
- info: 'info',
17
- debug: 'debug',
18
- trace: 'trace',
19
- warn: 'warn',
20
- error: 'error',
21
- audit: 'audit',
22
- fatal: 'fatal',
23
- },
24
- Console() {
25
- return {
26
- log() {},
27
- };
28
- },
29
- http() {
30
- return {
31
- log() {},
32
- };
33
- },
34
- webvitals() {},
35
- logUnhandledErrors() {},
1
+ export const logger = () => ({
2
+ setLogLevel() {},
3
+ setOptions() {},
4
+ info() {},
5
+ warn() {},
6
+ error() {},
7
+ trace() {},
8
+ debug() {},
9
+ audit() {},
10
+ fatal() {},
11
+ });
12
+ export const LogLevel = {
13
+ info: 'info',
14
+ debug: 'debug',
15
+ trace: 'trace',
16
+ warn: 'warn',
17
+ error: 'error',
18
+ audit: 'audit',
19
+ fatal: 'fatal',
36
20
  };
21
+ export const Console = () => ({
22
+ log: () => {},
23
+ });
24
+ export const http = () => ({
25
+ log() {},
26
+ });
27
+ export const webvitals = () => {};
28
+ export const logUnhandledErrors = () => {};
@@ -1,5 +1,3 @@
1
- module.exports = {
2
- setCustomUserData: () => {},
3
- setCustomVirtualPageName: () => {},
4
- startVirtualPageMonitoringWithAutoEnd: () => {},
5
- };
1
+ export const setCustomUserData = () => {};
2
+ export const setCustomVirtualPageName = () => {};
3
+ export const startVirtualPageMonitoringWithAutoEnd = () => {};
@@ -1,5 +1,3 @@
1
- module.exports = {
2
- attach: jest.fn(),
3
- detach: jest.fn(),
4
- getConfig: jest.fn(),
5
- };
1
+ export const attach = jest.fn();
2
+ export const detach = jest.fn();
3
+ export const getConfig = jest.fn();
@@ -1,3 +1,5 @@
1
- module.exports = {
2
- ReactComponent: 'IMAGE_MOCK',
3
- };
1
+ // eslint-disable-next-line no-unused-vars
2
+ import * as React from 'react';
3
+
4
+ export default 'SvgrURL';
5
+ export const ReactComponent = 'div';
@@ -0,0 +1 @@
1
+ exports.enableHotReloading = () => {};
@@ -0,0 +1,47 @@
1
+ const resolutions = [
2
+ {
3
+ matcher: /\.jsx?$/i,
4
+ extensions: ['.tsx', '.ts'],
5
+ },
6
+ {
7
+ matcher: /\.mjs$/i,
8
+ extensions: ['.mts'],
9
+ },
10
+ {
11
+ matcher: /\.cjs$/i,
12
+ extensions: ['.cts'],
13
+ },
14
+ ];
15
+
16
+ const resolveConfig = {
17
+ conditionNames: ['import', 'node', 'default'],
18
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.node'],
19
+ modules: ['node_modules', 'app', 'lib'],
20
+ };
21
+
22
+ const importResolver = require('enhanced-resolve').create.sync(resolveConfig);
23
+ const requireResolver = require('enhanced-resolve').create.sync({
24
+ ...resolveConfig,
25
+ conditionNames: ['require', 'node', 'default'],
26
+ });
27
+
28
+ module.exports = (request, options) => {
29
+ let resolver = requireResolver;
30
+ if (options.conditions?.includes('import')) {
31
+ resolver = importResolver;
32
+ }
33
+ const resolution = resolutions.find(({ matcher }) => matcher.test(request));
34
+ if (resolution) {
35
+ // eslint-disable-next-line no-restricted-syntax
36
+ for (const extension of resolution.extensions) {
37
+ try {
38
+ return resolver(
39
+ options.basedir,
40
+ request.replace(resolution.matcher, extension),
41
+ );
42
+ // eslint-disable-next-line no-empty
43
+ } catch {}
44
+ }
45
+ }
46
+ return resolver(options.basedir, request);
47
+ };
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import 'jest-styled-components';
3
+ global.React = React;
@@ -3,12 +3,36 @@
3
3
  import 'core-js/stable';
4
4
  import 'regenerator-runtime/runtime';
5
5
  import '@testing-library/jest-dom/extend-expect';
6
- import { toHaveNoViolations } from 'jest-axe';
6
+ import jestAxe from 'jest-axe';
7
7
  import ResizeObserver from 'resize-observer-polyfill';
8
- import addMatchMedia from './mocks/matchMedia';
9
- import { logger } from './mocks/pui-diagnostics';
8
+ import addMatchMedia from './mocks/matchMedia.js';
9
+ import { logger } from './mocks/pui-diagnostics.js';
10
10
 
11
- if (expect) expect.extend(toHaveNoViolations);
11
+ // eslint-disable-next-line no-console
12
+ const originalError = console.error;
13
+ // eslint-disable-next-line no-console
14
+ console.error = (...args) => {
15
+ const ignoreList = [
16
+ `Warning: Can't perform a React state update on an unmounted component`,
17
+ `Warning: Function components cannot be given refs`,
18
+ `Warning: Failed %s type:`,
19
+ `Warning: Invalid DOM property`,
20
+ `Warning: Each child in a list should have a unique`,
21
+ 'Warning: Received `%s` for a non-boolean attribute',
22
+ 'Warning: <%s /> is using incorrect casing.',
23
+ 'Warning: The tag <%s> is unrecognized in this browser',
24
+ 'Warning: Invalid arguments supplied to oneOf',
25
+ ];
26
+ if (
27
+ ignoreList.find(
28
+ (ignoreMsg) => !!args.find((arg) => arg?.includes?.(ignoreMsg)),
29
+ )
30
+ )
31
+ return false;
32
+ return originalError(...args);
33
+ };
34
+
35
+ if (expect) expect.extend(jestAxe.toHaveNoViolations);
12
36
  jest.setTimeout(60000);
13
37
 
14
38
  const addElementToBody = (element) => {
@@ -0,0 +1,16 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite';
3
+ import path from 'path';
4
+
5
+ export default defineConfig({
6
+ test: {
7
+ global: true,
8
+ root: process.cwd(),
9
+ exclude: ['node_modules', 'dist', '.idea', '.git', '.cache', 'e2e'],
10
+ setupFiles: [path.resolve(__dirname, './vitest.setup.ts')],
11
+ coverage: {
12
+ reportsDirectory: './reports/coverage',
13
+ },
14
+ environment: 'happy-dom',
15
+ },
16
+ });
File without changes
@@ -0,0 +1,11 @@
1
+ {
2
+ "jsc": {
3
+ "parser": {
4
+ "syntax": "typescript",
5
+ "jsx": true,
6
+ "tsx": true,
7
+ "dynamicImport": true
8
+ },
9
+ "target": "es2020"
10
+ }
11
+ }
@@ -0,0 +1,116 @@
1
+ const { build } = require('esbuild');
2
+ const fg = require('fast-glob');
3
+ const { writeFile, copyFile, readFile, mkdir } = require('fs/promises');
4
+ const path = require('path');
5
+ const browserslistToEsbuild = require('browserslist-to-esbuild');
6
+
7
+ const TARGETS = {
8
+ browserslist: browserslistToEsbuild(),
9
+ web: 'es2020',
10
+ node: 'node14',
11
+ };
12
+
13
+ const ESBUILD_FORMAT = {
14
+ CJS: 'cjs',
15
+ ESM: 'esm',
16
+ };
17
+
18
+ const NODE_MODULE_TYPES = {
19
+ CJS: 'commonjs',
20
+ ESM: 'module',
21
+ };
22
+
23
+ const getCommonConfig = ({ injectReactShim }) => ({
24
+ bundle: false,
25
+ loader: { '.js': 'jsx' },
26
+ mainFields: ['module', 'browser', 'main'],
27
+ inject: [
28
+ injectReactShim ? path.resolve(__dirname, './react-shim.js') : '',
29
+ ].filter(Boolean),
30
+ });
31
+
32
+ const copyFiles = async ({ srcdir, outdir }) => {
33
+ const files = await fg([
34
+ `${srcdir}/**/*.*`,
35
+ `!${srcdir}/**/*.{js,jsx,ts,tsx,cjs,mjs}`,
36
+ ]);
37
+ await Promise.all(
38
+ files.map(async (srcFilePath) => {
39
+ const destFilePath = srcFilePath.replace(srcdir, outdir);
40
+ const fileDir = path.dirname(destFilePath);
41
+ await mkdir(fileDir, { recursive: true });
42
+ await copyFile(srcFilePath, destFilePath);
43
+ }),
44
+ );
45
+ };
46
+
47
+ const getSideEffects = async () => {
48
+ const data = await readFile(path.join(process.cwd(), './package.json'));
49
+ const packageJSON = JSON.parse(data);
50
+ return packageJSON?.sideEffects || false;
51
+ };
52
+
53
+ const createPackageJson = async ({ outdir, type = NODE_MODULE_TYPES.ESM }) => {
54
+ const filePath = path.join(process.cwd(), outdir, 'package.json');
55
+ const packageJSON = JSON.stringify(
56
+ {
57
+ type,
58
+ sideEffects: await getSideEffects(),
59
+ },
60
+ null,
61
+ 2,
62
+ );
63
+ await writeFile(filePath, packageJSON);
64
+ };
65
+
66
+ exports.esBuild = async ({
67
+ srcdir,
68
+ outdir = 'dist',
69
+ esmOnly = false,
70
+ target = TARGETS.browserslist,
71
+ injectReactShim = true,
72
+ skipNestedPackageJSON = false,
73
+ }) => {
74
+ const inputFiles = [
75
+ `${srcdir}/**/*.{js,jsx,ts,tsx}`,
76
+ `!${srcdir}/**/*.d.ts`,
77
+ `!${srcdir}/**/*.test.{js,jsx,ts,tsx}`,
78
+ `!${srcdir}/**/*.stories.{js,jsx,ts,tsx}`,
79
+ `!${srcdir}/**/*.endpoint.{js,jsx,ts,tsx}`,
80
+ ];
81
+
82
+ // build commonjs
83
+ if (!esmOnly) {
84
+ const cjsOutdir = `${outdir}/cjs`;
85
+ const commonJSEntryPoints = await fg(inputFiles);
86
+ await build({
87
+ entryPoints: commonJSEntryPoints,
88
+ ...getCommonConfig({ injectReactShim }),
89
+ outdir: cjsOutdir,
90
+ format: ESBUILD_FORMAT.CJS,
91
+ target,
92
+ });
93
+ // copy files that are not built by esbuild
94
+ await copyFiles({ srcdir, outdir: cjsOutdir });
95
+ await createPackageJson({ outdir: cjsOutdir, type: NODE_MODULE_TYPES.CJS });
96
+ }
97
+
98
+ // build esm
99
+ const esmOutdir = esmOnly ? outdir : `${outdir}/esm`;
100
+ const entryPoints = await fg(
101
+ inputFiles.concat([`!${srcdir}/**/cjs/**/*.{js,jsx,ts,tsx}`]),
102
+ );
103
+ await build({
104
+ entryPoints,
105
+ ...getCommonConfig({ injectReactShim }),
106
+ outdir: esmOutdir,
107
+ format: ESBUILD_FORMAT.ESM,
108
+ target,
109
+ });
110
+ // copy files that are not built by esbuild
111
+ await copyFiles({ srcdir, outdir: esmOutdir });
112
+ if (!skipNestedPackageJSON)
113
+ await createPackageJson({ outdir: esmOutdir, type: NODE_MODULE_TYPES.ESM });
114
+ };
115
+
116
+ exports.TARGETS = TARGETS;
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export { React };
@@ -0,0 +1,13 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { merge } = require('lodash');
4
+
5
+ let projectConfig = {};
6
+ const projectPath = path.join(process.cwd(), '.swcrc');
7
+ if (fs.existsSync(projectPath)) {
8
+ projectConfig = JSON.parse(fs.readFileSync(projectPath, 'utf-8'));
9
+ }
10
+ const localConfig = JSON.parse(
11
+ fs.readFileSync(path.join(__dirname, '.swcrc'), 'utf-8'),
12
+ );
13
+ module.exports = merge(localConfig, projectConfig);
@@ -0,0 +1,66 @@
1
+ const execa = require('execa');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const { randomChars, resolveFromRoot } = require('./utils');
6
+
7
+ const args = process.argv.slice(2);
8
+ const argsProjectIndex = args.findIndex((arg) =>
9
+ ['-p', '--project'].includes(arg),
10
+ );
11
+ const argsProjectValue =
12
+ argsProjectIndex !== -1 ? args[argsProjectIndex + 1] : undefined;
13
+
14
+ const files = args.filter((file) => /\.(ts|tsx)$/.test(file));
15
+ if (files.length === 0) {
16
+ process.exit(0);
17
+ }
18
+
19
+ const remainingArgsToForward = args
20
+ .slice()
21
+ .filter((arg) => !files.includes(arg));
22
+
23
+ if (argsProjectIndex !== -1) {
24
+ remainingArgsToForward.splice(argsProjectIndex, 2);
25
+ }
26
+
27
+ // Load existing config
28
+ const tsconfigPath = argsProjectValue || resolveFromRoot('tsconfig.json');
29
+ const tsconfigContent = fs.readFileSync(tsconfigPath).toString();
30
+ // Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
31
+ // eslint-disable-next-line prefer-const
32
+ let tsconfig = {};
33
+ // eslint-disable-next-line no-eval
34
+ eval(`tsconfig = ${tsconfigContent}`);
35
+
36
+ // Write a temp config file
37
+ const tmpTsconfigPath = resolveFromRoot(`tsconfig.${randomChars()}.json`);
38
+ const tmpTsconfig = {
39
+ ...tsconfig,
40
+ compilerOptions: {
41
+ ...tsconfig.compilerOptions,
42
+ skipLibCheck: true,
43
+ },
44
+ files,
45
+ include: ['app', 'lib'],
46
+ };
47
+ fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2));
48
+
49
+ // Type-check our files
50
+ let status = 0;
51
+ try {
52
+ execa.sync(
53
+ path.resolve(
54
+ process.cwd(),
55
+ `./node_modules/.bin/tsc${process.platform === 'win32' ? '.cmd' : ''}`,
56
+ ),
57
+ ['-p', tmpTsconfigPath, ...remainingArgsToForward],
58
+ { stdio: 'inherit' },
59
+ );
60
+ } catch (ex) {
61
+ status = ex.exitCode;
62
+ }
63
+
64
+ // Delete temp config file
65
+ fs.unlinkSync(tmpTsconfigPath);
66
+ process.exit(status);
@@ -0,0 +1,16 @@
1
+ const { dirname, join } = require('path');
2
+
3
+ const randomChars = () => Math.random().toString(36).slice(2);
4
+
5
+ const resolveFromModule = (moduleName, ...paths) => {
6
+ const modulePath = dirname(require.resolve(`${moduleName}/package.json`));
7
+ return join(modulePath, ...paths);
8
+ };
9
+
10
+ const resolveFromRoot = (...paths) => join(process.cwd(), ...paths);
11
+
12
+ module.exports = {
13
+ randomChars,
14
+ resolveFromModule,
15
+ resolveFromRoot,
16
+ };
@@ -1,6 +1,9 @@
1
+ /* eslint-disable max-lines */
1
2
  const path = require('path');
2
3
  const fs = require('fs');
3
4
  const _ = require('lodash');
5
+ const CompressionPlugin = require('compression-webpack-plugin');
6
+ const zlib = require('zlib');
4
7
 
5
8
  let pathSep = path.sep;
6
9
  if (pathSep === '\\')
@@ -69,13 +72,11 @@ const getAlias = () =>
69
72
  '@babel/runtime',
70
73
  'react',
71
74
  'react-dom',
72
- 'react-router-dom',
73
75
  'react-redux',
74
76
  'redux',
75
77
  'redux-saga',
76
78
  'moment',
77
79
  'lodash',
78
- 'connected-react-router',
79
80
  'styled-components',
80
81
  'immer',
81
82
  'react-dates',
@@ -122,7 +123,6 @@ const getAppLoaderFileName = () => {
122
123
 
123
124
  const getDiagnosticsFileName = () => {
124
125
  const libName = 'emuiDiagnostics';
125
- // eslint-disable-next-line max-lines
126
126
  const libPath = path.join(
127
127
  process.cwd(),
128
128
  'node_modules/@elliemae/pui-diagnostics/dist/public/js',
@@ -185,6 +185,45 @@ const isGoogleTagManagerEnabled = () => {
185
185
  return !!appConfig?.googleTagManager;
186
186
  };
187
187
 
188
+ const getCompressionPlugins = (isLibrary = false) => {
189
+ const excludeList = [
190
+ /\/adrum-ext/,
191
+ /\/emuiUserMonitoring/,
192
+ /\/emuiDiagnostics/,
193
+ /\/emuiAppLoader/,
194
+ /\/encwLoader/,
195
+ ];
196
+ const commonConfig = {
197
+ test: /\.(js|css)$/,
198
+ exclude: !isLibrary ? excludeList : [],
199
+ // we are compressing all files since in aws cloudfront edge lambda, we don't want to whitelist files that are not compressed due to below limits
200
+ minRatio: Number.MAX_SAFE_INTEGER,
201
+ };
202
+ return [
203
+ new CompressionPlugin({
204
+ filename: '[path][base].gz',
205
+ algorithm: 'gzip',
206
+ ...commonConfig,
207
+ }),
208
+ new CompressionPlugin({
209
+ filename: '[path][base].br',
210
+ algorithm: 'brotliCompress',
211
+ ...commonConfig,
212
+ compressionOptions: {
213
+ params: {
214
+ [zlib.constants.BROTLI_PARAM_QUALITY]: 11,
215
+ },
216
+ },
217
+ }),
218
+ ];
219
+ };
220
+
221
+ const filterByFilePresence = (patterns) =>
222
+ patterns.filter(
223
+ ({ from, noErrorOnMissing }) =>
224
+ !noErrorOnMissing || fs.existsSync(path.resolve(process.cwd(), from)),
225
+ );
226
+
188
227
  exports.excludeNodeModulesExcept = excludeNodeModulesExcept;
189
228
  exports.getLibraryName = getLibraryName;
190
229
  exports.getAppConfig = getAppConfig;
@@ -209,3 +248,5 @@ exports.resolveExtensions = [
209
248
  ];
210
249
  exports.mainFields = ['browser', 'module', 'main'];
211
250
  exports.isGoogleTagManagerEnabled = isGoogleTagManagerEnabled;
251
+ exports.getCompressionPlugins = getCompressionPlugins;
252
+ exports.filterByFilePresence = filterByFilePresence;