@xh/hoist-dev-utils 6.1.2 → 6.3.0

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.
package/README.md CHANGED
@@ -116,8 +116,14 @@ own ESLint config by specifying their `.eslintrc` file as simply:
116
116
  If required, rules and other settings extended from this base configuration can be overridden at the
117
117
  app level.
118
118
 
119
+ ### Hoist Dev Utils Development
120
+
121
+ To develop improvements to this library, clone its repo into your workspace alongside a project
122
+ that uses Hoist-React, like [Toolbox](https://github.com/xh/toolbox). Then follow the instructions for
123
+ [yarn link](https://classic.yarnpkg.com/lang/en/docs/cli/link/) to symlink to this repo.
124
+
119
125
  ------------------------------------------
120
126
 
121
127
  ☎️ info@xh.io | <https://xh.io>
122
128
 
123
- Copyright © 2022 Extremely Heavy Industries Inc.
129
+ Copyright © 2023 Extremely Heavy Industries Inc.
@@ -2,7 +2,7 @@
2
2
  * This file belongs to Hoist, an application development toolkit
3
3
  * developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
4
4
  *
5
- * Copyright © 2022 Extremely Heavy Industries Inc.
5
+ * Copyright © 2023 Extremely Heavy Industries Inc.
6
6
  */
7
7
  'use strict';
8
8
 
@@ -28,8 +28,16 @@ const _ = require('lodash'),
28
28
  // These are not direct deps of hoist-dev-utils, so might be undefined - e.g. when running
29
29
  // this script locally to debug via `yarn link`.
30
30
  let hoistReactPkg, reactPkg;
31
- try {hoistReactPkg = require('@xh/hoist/package')} catch (e) {hoistReactPkg = {version: 'NOT_FOUND'}}
32
- try {reactPkg = require('react')} catch (e) {reactPkg = {version: 'NOT_FOUND'}}
31
+ try {
32
+ hoistReactPkg = require('@xh/hoist/package');
33
+ } catch (e) {
34
+ hoistReactPkg = {version: 'NOT_FOUND'};
35
+ }
36
+ try {
37
+ reactPkg = require('react');
38
+ } catch (e) {
39
+ reactPkg = {version: 'NOT_FOUND'};
40
+ }
33
41
 
34
42
  /**
35
43
  * Consolidated Webpack configuration for both dev-time and production builds of Hoist React web
@@ -40,16 +48,13 @@ try {reactPkg = require('react')} catch (e) {reactPkg = {version: 'NOT_FOUND'}}
40
48
  * `webpack-dev-server --env inlineHoist` to run dev server w/hoist-react in inline mode
41
49
  *
42
50
  * @param {Object} env - config passed in from app webpack config or the CLI via --env flags.
43
- * @param {string} env.appCode - short, internal code for the application - baked into client as
44
- * XH.appCode. Should be lowercase, dash-separated, and should match the Gradle project name
45
- * (e.g. portfolio-manager).
46
- * @param {string} [env.appName] - user-facing display name for the application - baked into client
47
- * as XH.appName. Should be title cased and space-separated. If null, will be defaulted based
48
- * on appCode (e.g. portfolio-manager -> Portfolio Manager).
51
+ * @param {string} env.appCode - short, internal code for the application - baked into client as XH.appCode. Should be
52
+ * lowercase, dash-separated, and should match the Gradle project name (e.g. portfolio-manager).
53
+ * @param {string} [env.appName] - user-facing display name for the application - baked into client as XH.appName.
54
+ * Title cased and space-separated. If null, defaulted from appCode (portfolio-manager -> Portfolio Manager).
49
55
  * @param {string} [env.appVersion] - client version - baked into client as XH.appVersion
50
56
  * @param {string} [env.appBuild] - build/git tag - baked into client as XH.appBuild
51
- * @param {boolean} [env.prodBuild=false] - true to indicate this is a build (as opposed to run of
52
- * webpack-dev-server)
57
+ * @param {boolean} [env.prodBuild=false] - true to indicate this is a build (as opposed to run of webpack-dev-server)
53
58
  * @param {boolean} [env.inlineHoist=false] - true to use a locally checked-out copy of hoist-react
54
59
  * when running the dev server, as opposed to using the downloaded dependency. This allows
55
60
  * hoist-react developers to test plugin changes. Dev-mode only.
@@ -57,61 +62,52 @@ try {reactPkg = require('react')} catch (e) {reactPkg = {version: 'NOT_FOUND'}}
57
62
  * when running the dev server.
58
63
  * @param {Object} [env.resolveAliases] - object mapping for custom webpack module resolution.
59
64
  * When inlineHoist=true, a mapping between @xh/hoist and the local path will be added.
60
- * @param {boolean} [env.analyzeBundles] - true to launch an interactive bundle analyzer to
61
- * review output bundles, contents, and sizes.
62
- * @param {boolean} [env.checkForDupePackages] - true (default) to run build through
63
- * DuplicatePackageCheckerPlugin and output a build-time console warning if duplicate packages
64
- * have been resolved due to non-overlapping dependencies. Set to false to disable if dupe
65
- * warnings are not desired / distracting.
66
- * @param {string[]} [env.dupePackageCheckExcludes] - optional list of string package names to
67
- * exclude from dupe package checking. Defaults to ['tslib'].
68
- * @param {string} [env.baseUrl] - root path prepended to all relative URLs called via FetchService.
69
- * Defaults to `/api/` in production mode to work with proxy-based deployments and to
70
- * `$devHost:$devGrailsPort` in dev mode.
71
- * @param {string[]} [env.babelIncludePaths] - additional paths to pass Babel for transpiling via
72
- * settings shared with app-level and @xh/hoist code. Intended for custom packages.
73
- * @param {string[]} [env.babelExcludePaths] - paths to exclude from Babel transpilation. An
74
- * example use would be a local package with a nested node_modules folder.
75
- * @param {string} [env.contextRoot] - root path for where the app will be served, used as the base
76
- * path for static files.
77
- * @param {boolean} [env.copyPublicAssets] - true (default) to copy the /client-app/public
78
- * contents into the root of the build. Note that files within this directory will not be
79
- * processed, named with a hash, etc. Use for static assets you wish to link to without using
80
- * an import to run through the url or file-loader. Required for favicons.
81
- * @param {boolean} [env.parseChangelog] - true (default) to parse a `CHANGELOG.md` file in the
82
- * project root directory into JSON and make available for import by `XH.changelogService`.
65
+ * @param {boolean} [env.checkForDupePackages=true] - true to run build throughDuplicatePackageCheckerPlugin and output
66
+ * a build-time warning if duplicate packages have been resolved due to non-overlapping dependencies.
67
+ * @param {string[]} [env.dupePackageCheckExcludes] - optional list of string package names to exclude from dupe package
68
+ * checking. Defaults to ['tslib'].
69
+ * @param {string} [env.baseUrl] - root path prepended to all relative URLs called via FetchService. Defaults to
70
+ * `/api/` in production mode to work with proxy-based deployments and to `$devHost:$devGrailsPort` in dev mode.
71
+ * @param {string[]} [env.babelIncludePaths] - additional paths to pass Babel for transpiling via settings shared with
72
+ * app-level and @xh/hoist code. Intended for custom packages.
73
+ * @param {string[]} [env.babelExcludePaths] - paths to exclude from Babel transpiling. An example use would be a local
74
+ * package with a nested node_modules folder.
75
+ * @param {string} [env.contextRoot] - root path from which app will be served, used as the base path for static files.
76
+ * @param {boolean} [env.copyPublicAssets=true] - true to copy the /client-app/public contents into the root of the
77
+ * build. Note that files within this directory will not be processed, named with a hash, etc. Use for static
78
+ * assets you wish to link to without using an import to run through the url or file-loader. Required for favicons.
79
+ * @param {boolean} [env.parseChangelog=true] - true to parse a `CHANGELOG.md` file in the project root directory into
80
+ * JSON and make available for import by `XH.changelogService`.
83
81
  * @param {string} [env.favicon] - relative path to a primary favicon source image.
84
- * @param {Object} [env.manifestConfig] - override values for manifest.json file. This controls
85
- * certain options related to adding a mobile app to a device home screen, as well as
86
- * "installing" an app via Chrome's "create shortcut" option. See
87
- * https://developer.mozilla.org/en-US/docs/Web/Manifest for options.
82
+ * @param {Object} [env.manifestConfig] - override values for manifest.json file. This controls options related to
83
+ * adding a mobile app to a device home screen, as well as "installing" an app via Chrome's "create shortcut"
84
+ * option. See https://developer.mozilla.org/en-US/docs/Web/Manifest for options.
85
+ * @param {string[]} [env.targetBrowsers] - array of browserslist queries specifying target browsers for Babel and CSS
86
+ * transpiling and processing.
87
+ * @param {Object} [env.babelPresetEnvOptions] - options to spread onto / override defaults passed here to the Babel
88
+ * loader preset-env preset config.
89
+ * @param {Object} [env.terserOptions] - options to spread onto / override defaults passed here to the Terser
90
+ * minification plugin for production builds.
91
+ * @param {(boolean|string)} [env.sourceMaps=true] - control sourceMap generation. Set to `true` to enable defaults
92
+ * specific to dev vs. prod builds, `false` to disable source maps entirely, special string `'devOnly'` to enable
93
+ * default for dev and disable in prod, or any other valid Webpack `devtool` string to specify a mode directly.
94
+ * @param {boolean} [env.loadAllBlueprintJsIcons=false] - false to only load the BlueprintJs icons required by Hoist
95
+ * React, resulting in a much smaller bundle size. Set to true if your app wishes to access all the BP icons.
88
96
  * @param {string} [env.stats] - stats output - see https://webpack.js.org/configuration/stats/.
89
- * @param {string} [env.infrastructureLoggingLevel] - default 'error' to quiet chatty devServer.
90
- * @param {string} [env.devHost] - hostname for both local Grails and Webpack dev servers.
91
- * Defaults to localhost, but may be overridden to a proper hostname for testing on alternate
92
- * workstations or devices. Will be automatically set to lowercase to comply with
97
+ * @param {boolean} [env.analyzeBundles] - true to launch an interactive bundle analyzer to review output bundle sizes.
98
+ * @param {string} [env.infrastructureLoggingLevel=error] - logging level for devServer.
99
+ * @param {boolean|Object} [env.devClientOverlay] - customize devServer overlay behavior. Set to show only compilation
100
+ * errors by default. See https://webpack.js.org/configuration/dev-server/#overlay. Dev-mode only.
101
+ * @param {string} [env.devHost=localhost] - hostname for both local Grails and Webpack dev servers. Override for
102
+ * testing on alternate workstations or devices. Will be automatically set to lowercase to comply with
93
103
  * webpack-dev-server's host checking. Dev-mode only.
94
104
  * @param {number} [env.devGrailsPort] - port of local Grails server. Dev-mode only.
95
105
  * @param {number} [env.devWebpackPort] - port on which to start webpack-dev server. Dev-mode only.
96
- * @param {string} [env.devServerOpenPage] - path to auto-open when webpack-dev-server starts.
97
- * Leave null to disable automatic page open on startup.
98
- * @param {string[]} [env.targetBrowsers] - array of browserslist queries specifying target
99
- * browsers for Babel and CSS transpilation and processing.
100
- * @param {Object} [env.babelPresetEnvOptions] - options to spread onto / override defaults passed
101
- * here to the Babel loader preset-env preset config.
102
- * @param {Object} [env.terserOptions] - options to spread onto / override defaults passed here to
103
- * the Terser minification plugin for production builds.
104
- * @param {(boolean|string)} [env.sourceMaps] - control sourceMap generation. Set to `true`
105
- * (default) to enable defaults specific to dev vs. prod builds, `false` to disable source
106
- * maps entirely, special string `'devOnly'` to enable default for dev and disable in prod, or
107
- * any other valid Webpack `devtool` string to specify a mode directly.
108
- * @param {boolean} [env.loadAllBlueprintJsIcons] - false (default) to only load the BlueprintJs
109
- * icons required by Hoist React components, resulting in a much smaller bundle size. Set to
110
- * true if your app wishes to access all the BP icons (but consider FontAwesome instead!).
111
- * @param {(Object|boolean)} [env.devHttps] - Object of the form `{ca, cert, key}`, with each
112
- * key pointing to the required resource for a full SSL config. Pass `true` to serve locally
113
- * over SSL w/o providing a cert (browser will warn). Applies to local dev only, no effect on
114
- * production builds.
106
+ * @param {string} [env.devServerOpenPage] - path to auto-open when webpack-dev-server starts. Leave null to disable
107
+ * automatic page open on startup. Dev-mode only.
108
+ * @param {(Object|boolean)} [env.devHttps] - Object of the form `{ca, cert, key}`, with each key pointing to the
109
+ * required resource for a full SSL config. Pass `true` to serve locally over SSL w/o providing a cert (browser
110
+ * will warn). Dev-mode only.
115
111
  */
116
112
  async function configureWebpack(env) {
117
113
  if (!env.appCode) throw 'Missing required "appCode" config - cannot proceed';
@@ -127,15 +123,21 @@ async function configureWebpack(env) {
127
123
  analyzeBundles = env.analyzeBundles === true,
128
124
  checkForDupePackages = env.checkForDupePackages !== false,
129
125
  dupePackageCheckExcludes = env.dupePackageCheckExcludes || ['tslib'],
130
- devHost = (env.devHost ? env.devHost.toLowerCase() : 'localhost'),
131
- devHttps = prodBuild ?
132
- null :
133
- _.isPlainObject(env.devHttps) ?
134
- {
135
- ca: fs.readFileSync(env.devHttps.ca),
136
- cert: fs.readFileSync(env.devHttps.cert),
137
- key: fs.readFileSync(env.devHttps.key)
138
- } : !!env.devHttps,
126
+ devClientOverlay = env.devClientOverlay ?? {
127
+ errors: true,
128
+ warnings: false,
129
+ runtimeErrors: false
130
+ },
131
+ devHost = env.devHost ? env.devHost.toLowerCase() : 'localhost',
132
+ devHttps = prodBuild
133
+ ? null
134
+ : _.isPlainObject(env.devHttps)
135
+ ? {
136
+ ca: fs.readFileSync(env.devHttps.ca),
137
+ cert: fs.readFileSync(env.devHttps.cert),
138
+ key: fs.readFileSync(env.devHttps.key)
139
+ }
140
+ : !!env.devHttps,
139
141
  devGrailsPort = env.devGrailsPort || 8080,
140
142
  devWebpackPort = env.devWebpackPort || 3000,
141
143
  baseUrl = env.baseUrl || (prodBuild ? '/api/' : `http://${devHost}:${devGrailsPort}/`),
@@ -187,12 +189,13 @@ async function configureWebpack(env) {
187
189
 
188
190
  const srcPath = path.resolve(basePath, 'src'),
189
191
  outPath = path.resolve(basePath, 'build'),
190
- publicAssetsPath = path.resolve(basePath, 'public');
192
+ publicAssetsPath = path.resolve(basePath, 'public'),
193
+ hoistDevUtilsPath = path.resolve(basePath, 'node_modules/@xh/hoist-dev-utils');
191
194
 
192
195
  // Resolve Hoist as either a sibling (inline, checked-out) project or a downloaded package
193
- const hoistPath = inlineHoist ?
194
- path.resolve(basePath, '../../hoist-react') :
195
- path.resolve(basePath, 'node_modules/@xh/hoist');
196
+ const hoistPath = inlineHoist
197
+ ? path.resolve(basePath, '../../hoist-react')
198
+ : path.resolve(basePath, 'node_modules/@xh/hoist');
196
199
 
197
200
  // Check for and resolve standard/expected favicons.
198
201
  const manifestIcons = [];
@@ -203,22 +206,29 @@ async function configureWebpack(env) {
203
206
  logMsg(` > ${path.basename(favicon)}`);
204
207
  }
205
208
  if (fs.existsSync(path.resolve(publicAssetsPath, 'favicon-192.png'))) {
206
- manifestIcons.push({src: '/public/favicon-192.png', sizes: '192x192', type: 'image/png'});
209
+ manifestIcons.push({
210
+ src: '/public/favicon-192.png',
211
+ sizes: '192x192',
212
+ type: 'image/png'
213
+ });
207
214
  logMsg(` > favicon-192.png`);
208
215
  }
209
216
  if (fs.existsSync(path.resolve(publicAssetsPath, 'favicon-512.png'))) {
210
- manifestIcons.push({src: '/public/favicon-512.png', sizes: '512x512', type: 'image/png'});
217
+ manifestIcons.push({
218
+ src: '/public/favicon-512.png',
219
+ sizes: '512x512',
220
+ type: 'image/png'
221
+ });
211
222
  logMsg(` > favicon-512.png`);
212
223
  }
213
224
  }
214
- const appleTouchIconExists = copyPublicAssets && fs.existsSync(path.resolve(publicAssetsPath, 'apple-touch-icon.png'));
225
+ const appleTouchIconExists =
226
+ copyPublicAssets && fs.existsSync(path.resolve(publicAssetsPath, 'apple-touch-icon.png'));
215
227
  if (appleTouchIconExists) logMsg(` > apple-touch-icon.png`);
216
228
 
217
-
218
- // Resolve Hoist-based path to replacement Blueprint icons (if available, requires HR >= v35.2.
219
- const bpIconStubsPath = path.resolve(hoistPath, 'static/requiredBlueprintIcons.js'),
220
- bpIconStubsExist = fs.existsSync(bpIconStubsPath),
221
- loadAllBlueprintJsIcons = env.loadAllBlueprintJsIcons === true || !bpIconStubsExist;
229
+ // Resolve path to lightweight shim for Blueprint icons bundled with this project.
230
+ const bpIconStubsPath = path.resolve(hoistDevUtilsPath, 'static/requiredBlueprintIcons.js'),
231
+ loadAllBlueprintJsIcons = env.loadAllBlueprintJsIcons === true;
222
232
 
223
233
  // Resolve path to script for preflight checks. With HR >= v36.1 this routine has been broken
224
234
  // out into a standalone JS file to avoid the use of inline script tags. Script will be left
@@ -242,13 +252,11 @@ async function configureWebpack(env) {
242
252
  }
243
253
 
244
254
  // When running inline, resolve inline Hoist's own node_modules package so we can tell Babel to exclude
245
- const hoistNodeModulesPath = inlineHoist ?
246
- path.resolve(hoistPath, 'node_modules') :
247
- null;
255
+ const hoistNodeModulesPath = inlineHoist ? path.resolve(hoistPath, 'node_modules') : null;
248
256
 
249
257
  // Also get a handle on the nested @xh/hoist-dev-utils/node_modules path - dev-utils dependencies
250
258
  // (namely loaders) can be installed here due to the vagaries of node module version / conflict resolution.
251
- const devUtilsNodeModulesPath = path.resolve(basePath, 'node_modules/@xh/hoist-dev-utils/node_modules');
259
+ const devUtilsNodeModulesPath = path.resolve(hoistDevUtilsPath, 'node_modules');
252
260
 
253
261
  // Determine source map (devtool) mode.
254
262
  let devtool;
@@ -263,7 +271,10 @@ async function configureWebpack(env) {
263
271
  }
264
272
 
265
273
  // Ignore DefinePlugin warnings on mis-matched process.env when reactProdMode enabled during local development.
266
- const ignoreWarnings = (prodBuild !== reactProdMode) ? [{message: /Conflicting values for 'process.env.NODE_ENV'/}] : [];
274
+ const ignoreWarnings =
275
+ prodBuild !== reactProdMode
276
+ ? [{message: /Conflicting values for 'process.env.NODE_ENV'/}]
277
+ : [];
267
278
 
268
279
  // Parse CHANGELOG.md and write to tmp .json file, if requested. Write fallback file if disabled
269
280
  // or parsing fails, then install a resolver alias to support import from XH.changelogService.
@@ -316,10 +327,7 @@ async function configureWebpack(env) {
316
327
  apps.forEach(app => {
317
328
  // Ensure core-js and regenerator-runtime both imported for every app bundle - they are
318
329
  // specified as dependencies by Hoist and imported once in its polyfills.js file.
319
- appEntryPoints[app.name] = [
320
- path.resolve(hoistPath, 'static/polyfills.js'),
321
- app.path
322
- ];
330
+ appEntryPoints[app.name] = [path.resolve(hoistPath, 'static/polyfills.js'), app.path];
323
331
  });
324
332
 
325
333
  logSep();
@@ -340,7 +348,9 @@ async function configureWebpack(env) {
340
348
  output: {
341
349
  // Output built assets in directories per entry point / chunk.
342
350
  // Use chunkhash in prod to get distinct hashes for app vs. common chunks (throws error in dev - investigate)
343
- filename: prodBuild ? '[name]/[name].[chunkhash:8].js' : '[name]/[name].[fullhash:8].js',
351
+ filename: prodBuild
352
+ ? '[name]/[name].[chunkhash:8].js'
353
+ : '[name]/[name].[fullhash:8].js',
344
354
  path: outPath,
345
355
  // (URL) path on which fully built app is served - i.e. root context
346
356
  publicPath: contextRoot,
@@ -361,7 +371,11 @@ async function configureWebpack(env) {
361
371
  // e.g. `app.js`, `admin.js`, and `admin~app.js` for code shared by both apps.
362
372
  splitChunks: {
363
373
  chunks: 'all',
364
- name: (module, chunks) => chunks.sort().map(it => it.name).join('~')
374
+ name: (module, chunks) =>
375
+ chunks
376
+ .sort()
377
+ .map(it => it.name)
378
+ .join('~')
365
379
  },
366
380
 
367
381
  // Improved debugging with readable module/chunk names.
@@ -397,7 +411,6 @@ async function configureWebpack(env) {
397
411
  rules: [
398
412
  {
399
413
  oneOf: [
400
-
401
414
  //------------------------
402
415
  // Type mapping for .mjs files, used by the stylis library distribution.
403
416
  // We have a transitive dep on stylis via: react-select > emotion > stylis
@@ -451,6 +464,16 @@ async function configureWebpack(env) {
451
464
  // not required. See https://babeljs.io/docs/en/babel-preset-env#bugfixes.
452
465
  bugfixes: true,
453
466
 
467
+ // Ensure expected transform plugins are enabled for latest features.
468
+ // (Note these plugins are all generally bundled with preset-env.)
469
+ include: [
470
+ 'transform-class-properties',
471
+ 'transform-nullish-coalescing-operator',
472
+ 'transform-optional-chaining',
473
+ 'transform-private-methods',
474
+ 'transform-private-property-in-object'
475
+ ],
476
+
454
477
  // Allow direct overrides from env config.
455
478
  ...babelPresetEnvOptions
456
479
  }
@@ -460,47 +483,48 @@ async function configureWebpack(env) {
460
483
  // Support Typescript via Babel. `isTSX` option allows use of JSX inline with
461
484
  // .js files for older JS apps. Typescript apps must use the .tsx extension for
462
485
  // any files containing JSX syntax.
463
- ['@babel/plugin-transform-typescript', {allowDeclareFields: true, isTSX: true}],
486
+ [
487
+ '@babel/plugin-transform-typescript',
488
+ {allowDeclareFields: true, isTSX: true}
489
+ ],
464
490
 
465
491
  // Support our current decorator syntax, for MobX and Hoist decorators.
466
492
  // See notes @ https://babeljs.io/docs/en/babel-plugin-proposal-decorators#legacy
467
493
  // and https://mobx.js.org/enabling-decorators.html#babel-7
468
494
  ['@babel/plugin-proposal-decorators', {version: 'legacy'}],
469
495
 
470
- // Support class-level fields.
471
- // Must come after decorators plugin as per Babel docs linked above.
472
- ['@babel/plugin-proposal-class-properties'],
473
-
474
- // Support private methods + properties.
475
- ['@babel/plugin-proposal-private-methods'],
476
- ['@babel/plugin-proposal-private-property-in-object'],
477
-
478
- // Support `let x = foo?.bar`.
479
- ['@babel/plugin-proposal-optional-chaining'],
480
-
481
- // Support `let x = foo.bar ?? 'default'`.
482
- ['@babel/plugin-proposal-nullish-coalescing-operator'],
483
-
484
496
  // Avoid importing every FA icon ever made.
485
497
  // See https://github.com/FortAwesome/react-fontawesome/issues/70
486
- [require('babel-plugin-transform-imports'), {
487
- '@fortawesome/pro-light-svg-icons': {
488
- transform: '@fortawesome/pro-light-svg-icons/${member}',
489
- skipDefaultConversion: true
490
- },
491
- '@fortawesome/pro-regular-svg-icons': {
492
- transform: '@fortawesome/pro-regular-svg-icons/${member}',
493
- skipDefaultConversion: true
494
- },
495
- '@fortawesome/pro-solid-svg-icons': {
496
- transform: '@fortawesome/pro-solid-svg-icons/${member}',
497
- skipDefaultConversion: true
498
- },
499
- '@fortawesome/free-brands-svg-icons': {
500
- transform: '@fortawesome/free-brands-svg-icons/${member}',
501
- skipDefaultConversion: true
498
+ [
499
+ require('babel-plugin-transform-imports'),
500
+ {
501
+ '@fortawesome/pro-light-svg-icons': {
502
+ transform:
503
+ '@fortawesome/pro-light-svg-icons/${member}',
504
+ skipDefaultConversion: true
505
+ },
506
+ '@fortawesome/pro-regular-svg-icons': {
507
+ transform:
508
+ '@fortawesome/pro-regular-svg-icons/${member}',
509
+ skipDefaultConversion: true
510
+ },
511
+ '@fortawesome/pro-solid-svg-icons': {
512
+ transform:
513
+ '@fortawesome/pro-solid-svg-icons/${member}',
514
+ skipDefaultConversion: true
515
+ },
516
+ '@fortawesome/pro-thin-svg-icons': {
517
+ transform:
518
+ '@fortawesome/pro-thin-svg-icons/${member}',
519
+ skipDefaultConversion: true
520
+ },
521
+ '@fortawesome/free-brands-svg-icons': {
522
+ transform:
523
+ '@fortawesome/free-brands-svg-icons/${member}',
524
+ skipDefaultConversion: true
525
+ }
502
526
  }
503
- }]
527
+ ]
504
528
  ],
505
529
  // Cache for dev builds, don't bother compressing.
506
530
  cacheDirectory: !prodBuild,
@@ -513,7 +537,9 @@ async function configureWebpack(env) {
513
537
  include: [srcPath, hoistPath, ...babelIncludePaths],
514
538
  // In inline mode also *avoid* transpiling inline hoist's own
515
539
  // node_modules libraries.
516
- exclude: inlineHoist ? [hoistNodeModulesPath, ...babelExcludePaths] : babelExcludePaths
540
+ exclude: inlineHoist
541
+ ? [hoistNodeModulesPath, ...babelExcludePaths]
542
+ : babelExcludePaths
517
543
  },
518
544
 
519
545
  //------------------------
@@ -545,13 +571,16 @@ async function configureWebpack(env) {
545
571
  options: {
546
572
  postcssOptions: {
547
573
  plugins: [
548
- require('postcss-flexbugs-fixes'), // Inclusion of postcss-flexbugs-fixes is from CRA.
549
- ['autoprefixer', {
550
- // We still want to provide an array of target browsers
551
- // that can be passed to / managed centrally by this script.
552
- overrideBrowserslist: targetBrowsers,
553
- flexbox: 'no-2009'
554
- }]
574
+ require('postcss-flexbugs-fixes'), // Inclusion of postcss-flexbugs-fixes is from CRA.
575
+ [
576
+ 'autoprefixer',
577
+ {
578
+ // We still want to provide an array of target browsers
579
+ // that can be passed to / managed centrally by this script.
580
+ overrideBrowserslist: targetBrowsers,
581
+ flexbox: 'no-2009'
582
+ }
583
+ ]
555
584
  ]
556
585
  }
557
586
  }
@@ -562,7 +591,6 @@ async function configureWebpack(env) {
562
591
  ]
563
592
  },
564
593
 
565
-
566
594
  //------------------------
567
595
  // Fall-through entry to process all other assets via a file-loader.
568
596
  // (Exclude config here is from CRA source config - commented there, but didn't understand).
@@ -584,10 +612,12 @@ async function configureWebpack(env) {
584
612
  new CleanWebpackPlugin(),
585
613
 
586
614
  // Load only the BlueprintJS icons used by Hoist-React components.
587
- !loadAllBlueprintJsIcons ? new webpack.NormalModuleReplacementPlugin(
588
- /.*\/generated\/iconSvgPaths.*/,
589
- bpIconStubsPath
590
- ) : undefined,
615
+ !loadAllBlueprintJsIcons
616
+ ? new webpack.NormalModuleReplacementPlugin(
617
+ /.*\/@blueprintjs\/icons\/lib\/esm\/iconSvgPaths.*/,
618
+ bpIconStubsPath
619
+ )
620
+ : undefined,
591
621
 
592
622
  // Inject global constants at compile time.
593
623
  new webpack.DefinePlugin({
@@ -614,9 +644,9 @@ async function configureWebpack(env) {
614
644
  patterns: _.compact([
615
645
  {from: preflightScriptPath, to: 'public'},
616
646
  {from: preloadSpinnerPath, to: 'public'},
617
- copyPublicAssets ?
618
- {from: path.resolve(basePath, 'public'), to: 'public'} :
619
- undefined
647
+ copyPublicAssets
648
+ ? {from: path.resolve(basePath, 'public'), to: 'public'}
649
+ : undefined
620
650
  ])
621
651
  }),
622
652
 
@@ -662,17 +692,21 @@ async function configureWebpack(env) {
662
692
  }),
663
693
 
664
694
  // Support an optional post-build/run interactive treemap of output bundles and their sizes / contents.
665
- analyzeBundles ? new BundleAnalyzerPlugin({
666
- analyzerMode: 'server'
667
- }) : undefined,
695
+ analyzeBundles
696
+ ? new BundleAnalyzerPlugin({
697
+ analyzerMode: 'server'
698
+ })
699
+ : undefined,
668
700
 
669
701
  // Warn on dupe package included in bundle due to multiple, conflicting versions.
670
- checkForDupePackages ? new DuplicatePackageCheckerPlugin({
671
- verbose: true,
672
- showHelp: false,
673
- strict: false,
674
- exclude: (instance) => dupePackageCheckExcludes.includes(instance.name)
675
- }) : undefined,
702
+ checkForDupePackages
703
+ ? new DuplicatePackageCheckerPlugin({
704
+ verbose: true,
705
+ showHelp: false,
706
+ strict: false,
707
+ exclude: instance => dupePackageCheckExcludes.includes(instance.name)
708
+ })
709
+ : undefined,
676
710
 
677
711
  // Display build progress - enable profile for per-loader/file type stats.
678
712
  new WebpackBar({
@@ -682,7 +716,6 @@ async function configureWebpack(env) {
682
716
 
683
717
  // Environment-specific plugins.
684
718
  ...(prodBuild ? extraPluginsProd(terserOptions) : extraPluginsDev())
685
-
686
719
  ].filter(Boolean),
687
720
 
688
721
  devtool: devtool,
@@ -690,23 +723,25 @@ async function configureWebpack(env) {
690
723
  ignoreWarnings: ignoreWarnings,
691
724
 
692
725
  // Inline dev-time configuration for webpack-dev-server.
693
- devServer: prodBuild ? undefined : {
694
- https: devHttps,
695
- host: devHost,
696
- port: devWebpackPort,
697
- hot: true,
698
- client: {overlay: true},
699
- open: env.devServerOpenPage ? [env.devServerOpenPage] : false,
700
- // Support HTML5 history routes for apps, with /appName/ as the base route for each
701
- historyApiFallback: {
702
- rewrites: appNames.map(appName => {
703
- return {
704
- from: new RegExp(`^/${appName}`),
705
- to: `/${appName}/index.html`
706
- };
707
- })
708
- }
709
- }
726
+ devServer: prodBuild
727
+ ? undefined
728
+ : {
729
+ https: devHttps,
730
+ host: devHost,
731
+ port: devWebpackPort,
732
+ hot: true,
733
+ client: {overlay: devClientOverlay},
734
+ open: env.devServerOpenPage ? [env.devServerOpenPage] : false,
735
+ // Support HTML5 history routes for apps, with /appName/ as the base route for each
736
+ historyApiFallback: {
737
+ rewrites: appNames.map(appName => {
738
+ return {
739
+ from: new RegExp(`^/${appName}`),
740
+ to: `/${appName}/index.html`
741
+ };
742
+ })
743
+ }
744
+ }
710
745
  };
711
746
  }
712
747
 
@@ -714,7 +749,6 @@ async function configureWebpack(env) {
714
749
  // Implementation
715
750
  //------------------------
716
751
  class HoistManifestPlugin {
717
-
718
752
  constructor(content = {}) {
719
753
  this.content = content;
720
754
  }
@@ -725,22 +759,24 @@ class HoistManifestPlugin {
725
759
  {RawSource} = compiler.webpack.sources;
726
760
 
727
761
  // Tap into compilation hook which gives compilation as argument to the callback function
728
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
729
- compilation.hooks.processAssets.tap({
730
- name: pluginName,
731
- stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
732
- }, () => {
733
- compilation.emitAsset(
734
- '/public/manifest.json',
735
- new RawSource(JSON.stringify(this.content))
736
- );
737
- });
762
+ compiler.hooks.compilation.tap(pluginName, compilation => {
763
+ compilation.hooks.processAssets.tap(
764
+ {
765
+ name: pluginName,
766
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
767
+ },
768
+ () => {
769
+ compilation.emitAsset(
770
+ '/public/manifest.json',
771
+ new RawSource(JSON.stringify(this.content))
772
+ );
773
+ }
774
+ );
738
775
  });
739
776
  }
740
777
  }
741
778
 
742
-
743
- const extraPluginsProd = (terserOptions) => {
779
+ const extraPluginsProd = terserOptions => {
744
780
  return [
745
781
  // Extract built CSS files into subdirectories by chunk / entry point name.
746
782
  new MiniCssExtractPlugin({
@@ -793,7 +829,12 @@ function getChunkCombinations(appNames) {
793
829
  return ret;
794
830
  }
795
831
 
796
- function logSep() {console.log(':------------------------------------')}
797
- function logMsg(msg) {console.log(`: ${msg}`)}
832
+ function logSep() {
833
+ console.log(':------------------------------------');
834
+ }
835
+
836
+ function logMsg(msg) {
837
+ console.log(`: ${msg}`);
838
+ }
798
839
 
799
840
  module.exports = configureWebpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist-dev-utils",
3
- "version": "6.1.2",
3
+ "version": "6.3.0",
4
4
  "description": "Utilities for configuring builds of Hoist-React client applications.",
5
5
  "repository": "github:xh/hoist-dev-utils",
6
6
  "homepage": "https://github.com/xh/hoist-dev-utils",
@@ -8,17 +8,18 @@
8
8
  "author": "Extremely Heavy Industries, Inc.",
9
9
  "license": "Apache-2.0",
10
10
  "files": [
11
- "configureWebpack.js"
11
+ "configureWebpack.js",
12
+ "static/**/*"
12
13
  ],
13
14
  "dependencies": {
14
- "@babel/core": "^7.21",
15
- "@babel/plugin-proposal-decorators": "^7.21",
16
- "@babel/preset-env": "^7.20",
17
- "@babel/preset-react": "^7.18",
18
- "@babel/preset-typescript": "^7.21",
15
+ "@babel/core": "^7.22.1",
16
+ "@babel/plugin-proposal-decorators": "^7.22.3",
17
+ "@babel/preset-env": "^7.22.4",
18
+ "@babel/preset-react": "^7.22.3",
19
+ "@babel/preset-typescript": "^7.22.5",
19
20
  "@cerner/duplicate-package-checker-webpack-plugin": "~2.3.0",
20
- "@types/lodash": "^4.0",
21
- "@types/react": "^18.0",
21
+ "@types/lodash": "4.x",
22
+ "@types/react": "18.x",
22
23
  "@xh/eslint-config": "^5.0",
23
24
  "autoprefixer": "~10.4.14",
24
25
  "babel-loader": "~9.1.2",
@@ -27,7 +28,7 @@
27
28
  "changelog-parser": "~3.0.1",
28
29
  "clean-webpack-plugin": "~4.0.0",
29
30
  "copy-webpack-plugin": "~11.0.0",
30
- "css-loader": "~6.7.3",
31
+ "css-loader": "~6.8.1",
31
32
  "file-loader": "~6.2.0",
32
33
  "html-webpack-plugin": "~5.5.0",
33
34
  "html-webpack-tags-plugin": "~3.0.2",
@@ -35,18 +36,21 @@
35
36
  "mini-css-extract-plugin": "~2.7.5",
36
37
  "postcss": "~8.4.21",
37
38
  "postcss-flexbugs-fixes": "~5.0.2",
38
- "postcss-loader": "~7.1.0",
39
+ "postcss-loader": "~7.3.0",
39
40
  "rimraf": "~4.4.0",
40
- "sass": "~1.59.3",
41
- "sass-loader": "~13.2.1",
41
+ "sass": "~1.63.4",
42
+ "sass-loader": "~13.3.0",
42
43
  "sass-material-colors": "~0.0.5",
43
44
  "style-loader": "~3.3.2",
44
45
  "terser-webpack-plugin": "~5.3.7",
45
46
  "url-loader": "~4.1.1",
46
- "webpack": "~5.76.3",
47
- "webpack-bundle-analyzer": "~4.8.0",
48
- "webpack-cli": "~5.0.1",
49
- "webpack-dev-server": "~4.13.1",
47
+ "webpack": "~5.87.0",
48
+ "webpack-bundle-analyzer": "~4.9.0",
49
+ "webpack-cli": "~5.1.4",
50
+ "webpack-dev-server": "~4.15.0",
50
51
  "webpackbar": "~5.0.2"
52
+ },
53
+ "devDependencies": {
54
+ "prettier": "^2.8.8"
51
55
  }
52
56
  }
@@ -0,0 +1,5 @@
1
+ # Build-related files
2
+
3
+ * `requiredBlueprintIcons.js` - included by hoist-dev-utils >= v6.2 as a (very) streamlined replacement for the
4
+ full set of Blueprint JS icons otherwise required by that library. See the comment at the top of the file for
5
+ additional details and links.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * This file replaces the MUCH larger versions included within the blueprintjs/icons dependency,
3
+ * which itself is required by Blueprint core. This file is swapped in at build-time by the
4
+ * `@xh/hoist-dev-utils` webpack config to only bundle the icons required by BP-based Hoist React
5
+ * components, nicely reducing overall app bundle size.
6
+ *
7
+ * For further details, see https://github.com/xh/hoist-react/issues/1963,
8
+ * and https://github.com/xh/hoist-dev-utils/issues/44.
9
+ * See the dev-utils `configureWebpack()` method for the implementation referencing this file.
10
+ */
11
+ export const IconSvgPaths16 = {
12
+ // used on context menu menuItem when a menu has submenus
13
+ 'caret-right': ['M11 8c0-.15-.07-.28-.17-.37l-4-3.5A.495.495 0 006 4.5v7a.495.495 0 00.83.37l4-3.5c.1-.09.17-.22.17-.37z'],
14
+ // used in datepicker's calendar scroll
15
+ 'chevron-left': ['M7.41 8l3.29-3.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71l-4 4C5.11 7.47 5 7.72 5 8c0 .28.11.53.29.71l4 4a1.003 1.003 0 001.42-1.42L7.41 8z'],
16
+ 'chevron-right': ['M10.71 7.29l-4-4a1.003 1.003 0 00-1.42 1.42L8.59 8 5.3 11.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71l4-4c.18-.18.29-.43.29-.71 0-.28-.11-.53-.29-.71z'],
17
+ // used on toast close buttons
18
+ 'cross': ['M9.41 8l3.29-3.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71L8 6.59l-3.29-3.3a1.003 1.003 0 00-1.42 1.42L6.59 8 3.3 11.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71L8 9.41l3.29 3.29c.18.19.43.3.71.3a1.003 1.003 0 00.71-1.71L9.41 8z'],
19
+ // used on datepicker's month picker
20
+ 'double-caret-vertical': ['M5 7h6a1.003 1.003 0 00.71-1.71l-3-3C8.53 2.11 8.28 2 8 2s-.53.11-.71.29l-3 3A1.003 1.003 0 005 7zm6 2H5a1.003 1.003 0 00-.71 1.71l3 3c.18.18.43.29.71.29s.53-.11.71-.29l3-3A1.003 1.003 0 0011 9z'],
21
+ // used on dialog close buttons
22
+ 'small-cross': ['M9.41 8l2.29-2.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71L8 6.59l-2.29-2.3a1.003 1.003 0 00-1.42 1.42L6.59 8 4.3 10.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71L8 9.41l2.29 2.29c.18.19.43.3.71.3a1.003 1.003 0 00.71-1.71L9.41 8z']
23
+
24
+ };
25
+ export const IconSvgPaths20 = {
26
+ 'caret-right': ['M14 10c0-.31-.15-.57-.37-.76l.01-.01-6-5-.01.01C7.46 4.1 7.24 4 7 4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1 .24 0 .46-.1.63-.24l.01.01 6-5-.01-.01c.22-.19.37-.45.37-.76z'],
27
+ 'chevron-left': ['M8.41 10l5.29-5.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71l-6 6c-.18.18-.29.43-.29.71 0 .28.11.53.29.71l6 6a1.003 1.003 0 001.42-1.42L8.41 10z'],
28
+ 'chevron-right': ['M13.71 9.29l-6-6a1.003 1.003 0 00-1.42 1.42l5.3 5.29-5.29 5.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71l6-6c.18-.18.29-.43.29-.71 0-.28-.11-.53-.29-.71z'],
29
+ 'cross': ['M11.41 10l4.29-4.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71L10 8.59l-4.29-4.3a1.003 1.003 0 00-1.42 1.42L8.59 10 4.3 14.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71l4.29-4.3 4.29 4.29c.18.19.43.3.71.3a1.003 1.003 0 00.71-1.71L11.41 10z'],
30
+ 'double-caret-vertical': ['M5 9h10c.55 0 1-.45 1-1 0-.24-.1-.46-.24-.63l.01-.01-5-6-.01.01C10.57 1.15 10.31 1 10 1s-.57.15-.76.37l-.01-.01-5 6 .01.01C4.1 7.54 4 7.76 4 8c0 .55.45 1 1 1zm10 2H5c-.55 0-1 .45-1 1 0 .24.1.46.24.63l-.01.01 5 6 .01-.01c.19.22.45.37.76.37s.57-.15.76-.37l.01.01 5-6-.01-.01c.14-.17.24-.39.24-.63 0-.55-.45-1-1-1z'],
31
+ 'small-cross': ['M11.41 10l3.29-3.29c.19-.18.3-.43.3-.71a1.003 1.003 0 00-1.71-.71L10 8.59l-3.29-3.3a1.003 1.003 0 00-1.42 1.42L8.59 10 5.3 13.29c-.19.18-.3.43-.3.71a1.003 1.003 0 001.71.71l3.29-3.3 3.29 3.29c.18.19.43.3.71.3a1.003 1.003 0 00.71-1.71L11.41 10z']
32
+ };
33
+
34
+ export function iconNameToPathsRecordKey(name) {
35
+ return name
36
+ }