@xh/hoist-dev-utils 14.0.0-SNAPSHOT.1786233761268 → 14.0.1

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.
@@ -232,9 +232,9 @@ async function configureWebpack(env) {
232
232
  copyPublicAssets && fs.existsSync(path.resolve(publicAssetsPath, 'apple-touch-icon.png'));
233
233
  if (appleTouchIconExists) logMsg(` > apple-touch-icon.png`);
234
234
 
235
- // Resolve path to lightweight shim for Blueprint icons bundled with this project.
236
- const bpIconStubsPath = path.resolve(hoistDevUtilsPath, 'static/requiredBlueprintIcons.js'),
237
- loadAllBlueprintJsIcons = env.loadAllBlueprintJsIcons === true;
235
+ // Generate lightweight stub modules for Blueprint icons, unless app opts into the full set.
236
+ const loadAllBlueprintJsIcons = env.loadAllBlueprintJsIcons === true,
237
+ bpIconStubs = loadAllBlueprintJsIcons ? null : generateBlueprintIconStubs();
238
238
 
239
239
  // Tell webpack where to look for modules when resolving imports - this is the key to getting
240
240
  // inlineHoist mode to look in within the checked-out hoist-react project at hoistPath.
@@ -634,13 +634,24 @@ async function configureWebpack(env) {
634
634
  },
635
635
 
636
636
  plugins: [
637
- // Load only the BlueprintJS icons used by Hoist-React components.
638
- !loadAllBlueprintJsIcons
639
- ? new webpack.NormalModuleReplacementPlugin(
640
- /.*\/@blueprintjs\/icons\/lib\/esm\/iconSvgPaths.*/,
641
- bpIconStubsPath
642
- )
643
- : undefined,
637
+ // Load only the BlueprintJS icons used by Hoist-React components - swap the icon
638
+ // package entry and path barrels for generated stubs. See generateBlueprintIconStubs().
639
+ ...(bpIconStubs
640
+ ? [
641
+ new webpack.NormalModuleReplacementPlugin(
642
+ /@blueprintjs[\\/]icons[\\/]lib[\\/]esm[\\/]generated[\\/]index\.js$/,
643
+ bpIconStubs.entry
644
+ ),
645
+ new webpack.NormalModuleReplacementPlugin(
646
+ /@blueprintjs[\\/]icons[\\/]lib[\\/]esm[\\/]generated[\\/]16px[\\/]paths[\\/]index\.js$/,
647
+ bpIconStubs.paths16
648
+ ),
649
+ new webpack.NormalModuleReplacementPlugin(
650
+ /@blueprintjs[\\/]icons[\\/]lib[\\/]esm[\\/]generated[\\/]20px[\\/]paths[\\/]index\.js$/,
651
+ bpIconStubs.paths20
652
+ )
653
+ ]
654
+ : []),
644
655
 
645
656
  // Inject global constants at compile time.
646
657
  new webpack.DefinePlugin({
@@ -853,6 +864,106 @@ class HoistManifestPlugin {
853
864
  }
854
865
  }
855
866
 
867
+ //------------------------------------------------------------------------------------
868
+ // Blueprint icons
869
+ //------------------------------------------------------------------------------------
870
+ // Icons required by the Blueprint components used within Hoist React - the per-icon React
871
+ // components imported internally by @blueprintjs/core, @blueprintjs/datetime, and
872
+ // @blueprintjs/select (a transitive dep of datetime), plus the string-name icons those packages
873
+ // render via `<Icon icon="..."/>`. PascalCase, per the @blueprintjs/icons naming convention.
874
+ const requiredBlueprintIcons = [
875
+ 'ArrowDown',
876
+ 'ArrowLeft',
877
+ 'ArrowRight',
878
+ 'ArrowUp',
879
+ 'CaretDown',
880
+ 'CaretRight',
881
+ 'ChevronDown',
882
+ 'ChevronLeft',
883
+ 'ChevronRight',
884
+ 'ChevronUp',
885
+ 'Cross',
886
+ 'DoubleCaretVertical',
887
+ 'Error',
888
+ 'InfoSign',
889
+ 'KeyCommand',
890
+ 'KeyControl',
891
+ 'KeyDelete',
892
+ 'KeyEnter',
893
+ 'KeyOption',
894
+ 'KeyShift',
895
+ 'Search',
896
+ 'SmallCross',
897
+ 'SmallTick',
898
+ 'Square',
899
+ 'Tick',
900
+ 'WarningSign'
901
+ ];
902
+
903
+ /**
904
+ * Generate stub modules that re-export only the Blueprint icons required by Hoist React
905
+ * components. Swapped in via NormalModuleReplacementPlugin for:
906
+ *
907
+ * 1) The @blueprintjs/icons package entry point (`lib/esm/generated/index.js`), which
908
+ * statically re-exports all ~700 per-icon React components.
909
+ * 2) The 16px and 20px icon path barrels (`lib/esm/generated/{16px,20px}/paths/index.js`),
910
+ * statically imported by the entry point via its `allPaths` re-export and dynamically
911
+ * imported by the package's lazy path loaders.
912
+ *
913
+ * Without these stubs, the entire icon set (~2.4MB pre-minification) lands in the initial
914
+ * bundle of every app. Blueprint marks its JS side-effect-free, but this config disables
915
+ * webpack's `sideEffects`-based module pruning (see `optimization` above), so the unused
916
+ * re-exports ride the static import graph into the bundle.
917
+ *
918
+ * Stubs are generated at build time with absolute-path imports resolved against the app's own
919
+ * copy of @blueprintjs/icons, so they remain correct across package managers (including pnpm's
920
+ * isolated layout, where this package cannot resolve undeclared siblings) and across icon
921
+ * package versions. Any Blueprint component importing an icon outside the whitelist will fail
922
+ * the build loudly (`strictExportPresence`) - extend the list above, or have the app opt out
923
+ * via `env.loadAllBlueprintJsIcons`.
924
+ */
925
+ const generateBlueprintIconStubs = () => {
926
+ let iconsPath;
927
+ try {
928
+ iconsPath = path.dirname(
929
+ require.resolve('@blueprintjs/icons/package.json', {paths: [basePath]})
930
+ );
931
+ } catch (e) {
932
+ logMsg('⚠️ Could not resolve @blueprintjs/icons - Blueprint icon stubs disabled.');
933
+ return null;
934
+ }
935
+
936
+ // Forward slashes in import specifiers, valid on all platforms.
937
+ const esmPath = p => path.join(iconsPath, 'lib/esm', p).split(path.sep).join('/'),
938
+ outDir = path.join(basePath, 'node_modules', '.cache', 'hoist-dev-utils'),
939
+ writeStub = (filename, lines) => {
940
+ const ret = path.join(outDir, filename);
941
+ fs.writeFileSync(ret, lines.join('\n') + '\n');
942
+ return ret;
943
+ };
944
+
945
+ fs.mkdirSync(outDir, {recursive: true});
946
+
947
+ const componentExports = requiredBlueprintIcons.map(it => {
948
+ const mod = esmPath(`generated/components/${_.kebabCase(it)}.js`);
949
+ return `export {${it}Icon, ${it}} from '${mod}';`;
950
+ }),
951
+ pathExports = size =>
952
+ requiredBlueprintIcons.map(it => {
953
+ const mod = esmPath(`generated/${size}/paths/${_.kebabCase(it)}.js`);
954
+ return `export {default as ${it}} from '${mod}';`;
955
+ });
956
+
957
+ return {
958
+ entry: writeStub('bpIconsEntryStub.mjs', [
959
+ `export * from '${esmPath('index.js')}';`,
960
+ ...componentExports
961
+ ]),
962
+ paths16: writeStub('bpIconsPaths16Stub.mjs', pathExports('16px')),
963
+ paths20: writeStub('bpIconsPaths20Stub.mjs', pathExports('20px'))
964
+ };
965
+ };
966
+
856
967
  const extraPluginsProd = terserOptions => {
857
968
  return [
858
969
  // Extract built CSS files into subdirectories by chunk / entry point name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist-dev-utils",
3
- "version": "14.0.0-SNAPSHOT.1786233761268",
3
+ "version": "14.0.1",
4
4
  "description": "Utilities for configuring builds of Hoist-React client applications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,5 +55,5 @@
55
55
  "devDependencies": {
56
56
  "prettier": "3.x"
57
57
  },
58
- "packageManager": "pnpm@11.20.0+sha512.9a6f330a95b66446ea088faf1521405a8a01f07fde7124cc9958dfed52d4bb436737e65b08f85f37b46fcba375092558ac51262b816844b22f63406ed166bfee"
58
+ "packageManager": "pnpm@11.21.0+sha512.521705bce689924eac72f5a3587122f362689ef6571e55ba80076fd637c11132ecffada26fad4ea79c485bfddbfd3d5a2a5b05805a77e893de71ec8a6cca3bb1"
59
59
  }
package/static/README.md CHANGED
@@ -1,7 +1,4 @@
1
1
  # Build-related files
2
2
 
3
3
  * `index.html` - passed to `HtmlWebpackPlugin` to be the template index.html file for each client app. Note that this
4
- had been sourced from hoist-react, but as of hoist-dev-utils >= v8.1 is included with this project for simplicity.
5
- * `requiredBlueprintIcons.js` - included by hoist-dev-utils >= v6.2 as a (very) streamlined replacement for the
6
- full set of Blueprint JS icons otherwise required by that library. See the comment at the top of the file for
7
- additional details and links.
4
+ had been sourced from hoist-react, but as of hoist-dev-utils >= v8.1 is included with this project for simplicity.
@@ -1,36 +0,0 @@
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
- }