@elliemae/pui-cli 6.0.0-beta.5 → 6.0.0-beta.50

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 (45) hide show
  1. package/lib/cli-commands/pack.js +1 -1
  2. package/lib/cli-commands/test.js +1 -12
  3. package/lib/cli-commands/tsc.js +103 -0
  4. package/lib/cli-commands/utils.js +9 -4
  5. package/lib/cli-commands/vitest.js +66 -0
  6. package/lib/cli.js +2 -0
  7. package/lib/lint/eslint/common.js +16 -8
  8. package/lib/lint/eslint/typescript/common.js +6 -1
  9. package/lib/lint/eslint/typescript/non-react.js +1 -1
  10. package/lib/lint/eslint/typescript/react.js +6 -1
  11. package/lib/lint/lint-staged.config.js +8 -1
  12. package/lib/lint/stylelint.config.js +0 -1
  13. package/lib/pui-config/index.js +18 -0
  14. package/lib/server/index.js +5 -9
  15. package/lib/server/middlewares/addDevMiddlewares.js +2 -2
  16. package/lib/server/middlewares/addProdMiddlewares.js +10 -3
  17. package/lib/testing/jest.config.js +26 -7
  18. package/lib/testing/mocks/matchMedia.js +12 -6
  19. package/lib/testing/mocks/pui-app-loader.js +1 -3
  20. package/lib/testing/mocks/pui-diagnostics.js +27 -35
  21. package/lib/testing/mocks/pui-user-monitoring.js +3 -5
  22. package/lib/testing/mocks/retry-axios.js +3 -5
  23. package/lib/testing/mocks/svg.js +5 -3
  24. package/lib/testing/resolver.js +47 -0
  25. package/lib/testing/setup-react-env.js +3 -0
  26. package/lib/testing/setup-tests.js +28 -4
  27. package/lib/testing/vitest.config.ts +16 -0
  28. package/lib/testing/vitest.setup.ts +0 -0
  29. package/lib/transpile/.swcrc +11 -0
  30. package/lib/transpile/esbuild.js +63 -0
  31. package/lib/transpile/react-shim.js +2 -0
  32. package/lib/transpile/swcrc.config.js +13 -0
  33. package/lib/typescript/tsc-files/index.js +66 -0
  34. package/lib/typescript/tsc-files/utils.js +16 -0
  35. package/lib/webpack/helpers.js +37 -3
  36. package/lib/webpack/webpack.base.babel.js +38 -93
  37. package/lib/webpack/webpack.dev.babel.js +6 -3
  38. package/lib/webpack/webpack.lib.base.babel.js +25 -64
  39. package/lib/webpack/webpack.lib.dev.babel.js +1 -2
  40. package/lib/webpack/webpack.lib.prod.babel.js +6 -11
  41. package/lib/webpack/webpack.prod.babel.js +30 -24
  42. package/lib/webpack/webpack.storybook.js +18 -103
  43. package/package.json +119 -108
  44. package/lib/esbuild.js +0 -39
  45. package/lib/testing/setup-styled-components-tests.js +0 -1
@@ -3,14 +3,13 @@ const path = require('path');
3
3
  const webpack = require('webpack');
4
4
  const {
5
5
  optimize: { LimitChunkCountPlugin },
6
+ ProgressPlugin,
6
7
  } = require('webpack');
7
8
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8
9
  const CopyWebpackPlugin = require('copy-webpack-plugin');
9
10
  const PostcssPresetEnv = require('postcss-preset-env');
10
11
  const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
11
- const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
12
12
  const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
13
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
14
13
 
15
14
  const {
16
15
  excludeNodeModulesExcept,
@@ -19,12 +18,10 @@ const {
19
18
  modulesToTranspile,
20
19
  getAssetPath,
21
20
  getAlias,
22
- getMediaPath,
23
21
  } = require('./helpers');
24
- const { ESBUILD_TARGET } = require('../esbuild');
25
- const { isTypeScriptEnabled } = require('../typescript/util');
22
+ const { getPUIConfig } = require('../pui-config');
23
+ const { esBuild } = getPUIConfig();
26
24
 
27
- const devMode = process.env.NODE_ENV !== 'production';
28
25
  const minicssLoader = {
29
26
  loader: MiniCssExtractPlugin.loader,
30
27
  options: {},
@@ -42,7 +39,6 @@ const plugins = [
42
39
  new webpack.DefinePlugin({
43
40
  APP_CONFIG: getAppConfig(true),
44
41
  }),
45
- new CaseSensitivePathsPlugin(),
46
42
  new CopyWebpackPlugin({
47
43
  patterns: [
48
44
  {
@@ -60,20 +56,10 @@ const plugins = [
60
56
  new LimitChunkCountPlugin({
61
57
  maxChunks: 1,
62
58
  }),
63
- new MomentLocalesPlugin(),
59
+ new MomentLocalesPlugin({ localesToKeep: ['es-us'] }),
60
+ new ProgressPlugin(),
64
61
  ];
65
62
 
66
- if (isTypeScriptEnabled()) {
67
- plugins.push(
68
- new ForkTsCheckerWebpackPlugin({
69
- async: devMode,
70
- eslint: {
71
- files: './lib/**/*.{ts,js,tsx,jsx}',
72
- },
73
- }),
74
- );
75
- }
76
-
77
63
  module.exports = (options) => ({
78
64
  mode: options.mode,
79
65
  entry: [path.join(process.cwd(), 'lib/index')],
@@ -89,39 +75,21 @@ module.exports = (options) => ({
89
75
  module: {
90
76
  rules: [
91
77
  {
92
- test: /\.(jpe?g|png|gif|svg|ico)$/,
93
- use: [
94
- 'file-loader',
95
- {
96
- loader: 'image-webpack-loader',
97
- options: {
98
- gifsicle: {
99
- enabled: false,
100
- },
101
- },
102
- },
103
- ],
104
- enforce: 'pre',
105
- },
106
- {
107
- test: /^(?!.*\.exec\.js$).*\.(js|ts|jsx|tsx)$/,
108
- enforce: 'pre',
109
- exclude: /node_modules/,
78
+ test: /^(?!.*\.exec\.js$).*\.jsx?$/, // Transform all .js and .jsx files with Babel
79
+ exclude: excludeNodeModulesExcept(modulesToTranspile),
110
80
  resolve: {
111
81
  fullySpecified: false,
112
82
  },
113
- use: [
114
- {
115
- loader: 'webpack-strip-block',
116
- options: {
117
- start: 'TEST:START',
118
- end: 'TEST:END',
119
- },
83
+ use: {
84
+ loader: 'esbuild-loader',
85
+ options: {
86
+ loader: 'jsx',
87
+ target: esBuild.target,
120
88
  },
121
- ],
89
+ },
122
90
  },
123
91
  {
124
- test: /^(?!.*\.exec\.js$).*\.(js|ts|jsx|tsx)$/, // Transform all .js and .jsx files with Babel
92
+ test: /^(?!.*\.exec\.js$).*\.tsx?$/, // Transform all .js and .jsx files with Babel
125
93
  exclude: excludeNodeModulesExcept(modulesToTranspile),
126
94
  resolve: {
127
95
  fullySpecified: false,
@@ -129,8 +97,8 @@ module.exports = (options) => ({
129
97
  use: {
130
98
  loader: 'esbuild-loader',
131
99
  options: {
132
- loader: 'jsx',
133
- target: ESBUILD_TARGET,
100
+ loader: 'tsx',
101
+ target: esBuild.target,
134
102
  },
135
103
  },
136
104
  },
@@ -186,19 +154,10 @@ module.exports = (options) => ({
186
154
  type: 'asset/resource',
187
155
  },
188
156
  {
189
- test: /\.svg$/,
190
- exclude: excludeNodeModulesExcept(['@elliemae/*']),
191
- use: [
192
- {
193
- loader: '@svgr/webpack',
194
- },
195
- {
196
- loader: 'file-loader',
197
- options: {
198
- name: getMediaPath(),
199
- },
200
- },
201
- ],
157
+ test: /\.svg$/i,
158
+ issuer: /\.[jt]sx?$/,
159
+ resourceQuery: /^((?!url).)*$/,
160
+ use: ['@svgr/webpack'],
202
161
  },
203
162
  {
204
163
  test: /\.(jpe?g|png|gif|ico)$/i,
@@ -219,15 +178,18 @@ module.exports = (options) => ({
219
178
  resourceQuery: /resource/,
220
179
  type: 'asset/resource',
221
180
  },
181
+ {
182
+ type: 'asset',
183
+ resourceQuery: /url/,
184
+ },
222
185
  ],
223
186
  },
224
187
  plugins: plugins.concat(options.plugins || []),
225
188
  resolve: {
226
189
  modules: ['node_modules', 'app', 'lib'],
227
- extensions: ['.wasm', '.mjs', '.ts', '.tsx', '.js', '.jsx', '.json'],
190
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.wasm', '.mjs'],
228
191
  mainFields: ['browser', 'module', 'main'],
229
192
  alias: {
230
- 'lodash-es': 'lodash',
231
193
  ...getAlias(),
232
194
  ...((options.resolve || {}).alias || {}),
233
195
  },
@@ -238,6 +200,5 @@ module.exports = (options) => ({
238
200
  '@elliemae/pui-diagnostics': 'emuiDiagnostics',
239
201
  },
240
202
  devtool: options.devtool || 'eval-source-map',
241
- target: 'web', // Make web variables accessible to webpack, e.g. window
242
203
  performance: options.performance || {},
243
204
  });
@@ -28,6 +28,7 @@ module.exports = require('./webpack.lib.base.babel')({
28
28
  // Add development plugins
29
29
  plugins: [
30
30
  new HtmlWebpackPlugin({
31
+ scriptLoading: 'module',
31
32
  inject: true, // Inject all files that are generated by webpack, e.g. bundle.js
32
33
  template: 'lib/index.pug',
33
34
  filename: 'index.html',
@@ -43,8 +44,6 @@ module.exports = require('./webpack.lib.base.babel')({
43
44
  }),
44
45
  ],
45
46
 
46
- // Emit a source map for easier debugging
47
- // See https://webpack.js.org/configuration/devtool/#devtool
48
47
  devtool: 'eval-source-map',
49
48
 
50
49
  performance: {
@@ -1,11 +1,11 @@
1
1
  const path = require('path');
2
- const CompressionPlugin = require('compression-webpack-plugin');
3
2
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
3
  const HtmlWebpackPlugin = require('html-webpack-plugin');
5
4
  const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
6
5
  const { ESBuildMinifyPlugin } = require('esbuild-loader');
7
- const { getLibraryName } = require('./helpers');
8
- const { ESBUILD_TARGET } = require('../esbuild');
6
+ const { getLibraryName, getCompressionPlugins } = require('./helpers');
7
+ const { getPUIConfig } = require('../pui-config');
8
+ const { esBuild } = getPUIConfig();
9
9
 
10
10
  const libraryName = getLibraryName();
11
11
 
@@ -24,7 +24,7 @@ module.exports = require('./webpack.lib.base.babel')({
24
24
  minimize: true,
25
25
  minimizer: [
26
26
  new ESBuildMinifyPlugin({
27
- target: ESBUILD_TARGET,
27
+ target: esBuild.target,
28
28
  css: true,
29
29
  }),
30
30
  ],
@@ -39,6 +39,7 @@ module.exports = require('./webpack.lib.base.babel')({
39
39
  plugins: [
40
40
  // Minify and optimize the index.html
41
41
  new HtmlWebpackPlugin({
42
+ scriptLoading: 'module',
42
43
  template: 'lib/index.pug',
43
44
  filename: 'index.html',
44
45
  libraryName,
@@ -62,13 +63,7 @@ module.exports = require('./webpack.lib.base.babel')({
62
63
  chunkFilename: `css/${libraryName}.[contenthash].chunk.css`,
63
64
  }),
64
65
 
65
- new CompressionPlugin({
66
- filename: '[path][base].gz',
67
- algorithm: 'gzip',
68
- test: /\.js$|\.css$$/,
69
- // 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
70
- minRatio: Number.MAX_SAFE_INTEGER,
71
- }),
66
+ ...getCompressionPlugins(true),
72
67
 
73
68
  new BundleAnalyzerPlugin({
74
69
  analyzerMode: 'static',
@@ -2,10 +2,10 @@
2
2
  const path = require('path');
3
3
  const HtmlWebpackPlugin = require('html-webpack-plugin');
4
4
  const { GenerateSW } = require('workbox-webpack-plugin');
5
- const CompressionPlugin = require('compression-webpack-plugin');
6
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
6
  const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
8
7
  const { ESBuildMinifyPlugin } = require('esbuild-loader');
8
+ const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
9
9
 
10
10
  const baseConfigFactory = require('./webpack.base.babel');
11
11
  const {
@@ -15,8 +15,10 @@ const {
15
15
  getPaths,
16
16
  getAppVersion,
17
17
  isGoogleTagManagerEnabled,
18
+ getCompressionPlugins,
18
19
  } = require('./helpers');
19
- const { ESBUILD_TARGET } = require('../esbuild');
20
+ const { getPUIConfig } = require('../pui-config');
21
+ const { esBuild } = getPUIConfig();
20
22
 
21
23
  const getProdConfig = ({ latestVersion = true } = {}) => {
22
24
  const { buildPath, publicPath } = getPaths(latestVersion);
@@ -41,7 +43,7 @@ const getProdConfig = ({ latestVersion = true } = {}) => {
41
43
  moduleIds: 'deterministic',
42
44
  minimizer: [
43
45
  new ESBuildMinifyPlugin({
44
- target: ESBUILD_TARGET,
46
+ target: esBuild.target,
45
47
  css: true,
46
48
  }),
47
49
  ],
@@ -63,25 +65,12 @@ const getProdConfig = ({ latestVersion = true } = {}) => {
63
65
  },
64
66
 
65
67
  plugins: [
66
- new MiniCssExtractPlugin({
67
- filename: 'css/[name].[contenthash].css',
68
- chunkFilename: 'css/[name].[contenthash].chunk.css',
69
- }),
68
+ // new MiniCssExtractPlugin({
69
+ // filename: 'css/[name].[contenthash].css',
70
+ // chunkFilename: 'css/[name].[contenthash].chunk.css',
71
+ // }),
70
72
 
71
- new CompressionPlugin({
72
- filename: '[path][base].gz',
73
- algorithm: 'gzip',
74
- test: /\.js$|\.css$$/,
75
- exclude: [
76
- /\/adrum-ext/,
77
- /\/emuiUserMonitoring/,
78
- /\/emuiDiagnostics/,
79
- /\/emuiAppLoader/,
80
- /\/encwLoader/,
81
- ],
82
- // 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
83
- minRatio: Number.MAX_SAFE_INTEGER,
84
- }),
73
+ ...getCompressionPlugins(),
85
74
 
86
75
  new BundleAnalyzerPlugin({
87
76
  analyzerMode: 'static',
@@ -114,6 +103,7 @@ const {
114
103
  encwLoaderScriptPath,
115
104
  } = getPaths();
116
105
  const htmlWebpackPlugin = new HtmlWebpackPlugin({
106
+ scriptLoading: 'module',
117
107
  filename: '../index.html',
118
108
  inject: !isAppLoaderEnabled(),
119
109
  template: !isAppLoaderEnabled()
@@ -155,6 +145,22 @@ const appVersionConfig = baseConfigFactory(
155
145
  getProdConfig({ latestVersion: false }),
156
146
  );
157
147
 
158
- module.exports = isVersionedApp
159
- ? [latestVersionConfig, appVersionConfig]
160
- : latestVersionConfig;
148
+ const addSMPPlugin = (config) => {
149
+ const smpConfig = new SpeedMeasurePlugin({
150
+ disable: !process.env.MEASURE,
151
+ }).wrap(config);
152
+ // mini css extract plugin is not working fine with smp
153
+ smpConfig.plugins.push(
154
+ new MiniCssExtractPlugin({
155
+ filename: 'css/[name].[contenthash].css',
156
+ chunkFilename: 'css/[name].[contenthash].chunk.css',
157
+ }),
158
+ );
159
+ return smpConfig;
160
+ };
161
+
162
+ const config = isVersionedApp
163
+ ? [latestVersionConfig, appVersionConfig].map(addSMPPlugin)
164
+ : addSMPPlugin(latestVersionConfig);
165
+
166
+ module.exports = config;
@@ -1,20 +1,13 @@
1
- /* eslint-disable max-lines */
2
1
  const webpack = require('webpack');
3
2
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
3
  const CopyWebpackPlugin = require('copy-webpack-plugin');
5
- const CompressionPlugin = require('compression-webpack-plugin');
6
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
4
+ const ResolveTypeScriptPlugin = require('resolve-typescript-plugin').default;
7
5
  const {
8
6
  getAppConfig,
9
7
  isApp,
10
8
  getAlias,
11
- excludeNodeModulesExcept,
12
- modulesToTranspile,
13
- resolveExtensions,
14
- mainFields,
15
- getMediaPath,
9
+ getCompressionPlugins,
16
10
  } = require('./helpers');
17
- const { ESBUILD_TARGET } = require('../esbuild');
18
11
 
19
12
  const IS_APP = isApp();
20
13
  const CWD = process.cwd();
@@ -51,116 +44,38 @@ const getAdditionalPlugins = () => [
51
44
  }),
52
45
  ];
53
46
 
54
- const compressionPlugin = new CompressionPlugin({
55
- filename: '[path][base].gz',
56
- algorithm: 'gzip',
57
- test: /\.js$|\.css$$/,
58
- // 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
59
- minRatio: Number.MAX_SAFE_INTEGER,
60
- });
61
-
62
- const getModulePreRules = () => [
63
- {
64
- test: /\.(jpe?g|png|gif|svg|ico)$/,
65
- use: [
66
- 'file-loader',
67
- {
68
- loader: 'image-webpack-loader',
69
- options: {
70
- gifsicle: {
71
- enabled: false,
72
- },
73
- },
74
- },
75
- ],
76
- enforce: 'pre',
77
- },
78
- {
79
- test: /\.(js|ts|jsx|tsx)$/,
80
- enforce: 'pre',
81
- exclude: /node_modules/,
82
- resolve: {
83
- fullySpecified: false,
84
- },
85
- use: [
86
- {
87
- loader: 'webpack-strip-block',
88
- options: {
89
- start: 'TEST:START',
90
- end: 'TEST:END',
91
- },
92
- },
93
- ],
94
- },
95
- ];
96
-
97
47
  const getModuleRules = () => [
98
48
  {
99
- test: /\.(js|ts|jsx|tsx)$/,
100
- exclude: excludeNodeModulesExcept(modulesToTranspile),
101
- resolve: {
102
- fullySpecified: false,
103
- },
104
- use: {
105
- loader: 'esbuild-loader',
106
- options: {
107
- loader: 'jsx',
108
- target: ESBUILD_TARGET,
109
- },
110
- },
111
- },
112
- {
113
- test: /\.(woff|woff2)$/,
114
- exclude: excludeNodeModulesExcept(['@elliemae/*']),
115
- type: 'asset/resource',
116
- },
117
- {
118
- test: /\.svg$/,
119
- exclude: excludeNodeModulesExcept(['@elliemae/*']),
120
- use: [
121
- {
122
- loader: '@svgr/webpack',
123
- },
124
- {
125
- loader: 'file-loader',
126
- options: {
127
- name: getMediaPath(),
128
- },
129
- },
130
- ],
131
- },
132
- {
133
- test: /\.(jpe?g|png|gif|ico)$/i,
134
- exclude: excludeNodeModulesExcept(['@elliemae/*']),
135
49
  type: 'asset',
50
+ resourceQuery: /url/,
136
51
  },
137
52
  {
138
- test: /\.(mp4|webm)$/,
139
- exclude: excludeNodeModulesExcept(['@elliemae/*']),
140
- type: 'asset',
53
+ test: /\.svg$/i,
54
+ issuer: /\.[jt]sx?$/,
55
+ resourceQuery: /^((?!url).)*$/,
56
+ use: ['@svgr/webpack'],
141
57
  },
142
58
  ];
143
59
 
144
60
  exports.webpackFinal = async (config, { configType }) => {
145
61
  const isProd = configType === 'PRODUCTION';
146
- // remove asset processing that comes with storybook webpack, we will use ours
147
- config.module.rules = config.module.rules.filter(
148
- ({ type }) => type !== 'asset/resource',
62
+ const fileLoaderRule = config.module.rules.find((rule) =>
63
+ rule.test?.test?.('.svg'),
149
64
  );
150
- config.module.rules.push(...getModulePreRules());
151
- config.module.rules.unshift(...getModuleRules(isProd));
152
-
65
+ fileLoaderRule.exclude = /\.svg$/i;
66
+ config.module.rules.unshift(...getModuleRules());
153
67
  config.plugins.push(...getAdditionalPlugins());
154
68
  if (isProd) {
155
- config.plugins.push(compressionPlugin);
69
+ config.plugins = config.plugins.concat(getCompressionPlugins());
156
70
  }
157
71
 
158
72
  config.resolve.alias = { ...config.resolve.alias, ...getAlias() };
159
73
  config.resolve.fallback = { ...config.resolve.fallback, crypto: false };
160
- config.resolve.plugins = (config.resolve.plugins || []).concat([
161
- new TsconfigPathsPlugin({ extensions: resolveExtensions, mainFields }),
162
- ]);
163
-
74
+ config.resolve.extensions.push('.svg');
75
+ config.resolve.plugins = [
76
+ ...(config.resolve.plugins || []),
77
+ new ResolveTypeScriptPlugin(),
78
+ ];
164
79
  config.externals = config.externals || {};
165
80
  config.externals['@elliemae/pui-user-monitoring'] = 'emuiUserMonitoring';
166
81
  config.externals['@elliemae/pui-app-loader'] = 'emuiAppLoader';
@@ -170,7 +85,7 @@ exports.webpackFinal = async (config, { configType }) => {
170
85
 
171
86
  // storybook manager webpack
172
87
  exports.managerWebpack = async (config) => {
173
- config.plugins.push(compressionPlugin);
88
+ config.plugins = config.plugins.concat(getCompressionPlugins());
174
89
  config.resolve.alias = { ...config.resolve.alias, ...getAlias() };
175
90
  return config;
176
91
  };