@turntrout/subfont 1.3.1 → 1.3.3

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.
@@ -231,7 +231,7 @@ function findFontFamiliesWithFeatureSettings(
231
231
 
232
232
  if (recorded === true) {
233
233
  result = true;
234
- } else {
234
+ } else if (result !== true) {
235
235
  if (!result) result = new Set();
236
236
  for (const family of recorded) {
237
237
  result.add(family.toLowerCase());
@@ -1214,3 +1214,5 @@ module.exports = collectTextsByPage;
1214
1214
  // Exported for testing only
1215
1215
  module.exports._extractFeatureTagsFromDecl = extractFeatureTagsFromDecl;
1216
1216
  module.exports._resolveFeatureSettings = resolveFeatureSettings;
1217
+ module.exports._findFontFamiliesWithFeatureSettings =
1218
+ findFontFamiliesWithFeatureSettings;
package/lib/subfont.js CHANGED
@@ -52,6 +52,16 @@ module.exports = async function subfont(
52
52
  );
53
53
  }
54
54
 
55
+ // Prevent postcss plugins (colormin, convert-values, etc.) invoked by
56
+ // cssnano from walking the filesystem for a "browserslist" config.
57
+ // Under pnpm, `node_modules/.bin/browserslist` is a shell shim that
58
+ // browserslist mis-parses as browser queries, throwing
59
+ // BrowserslistError and silently aborting CSS minification.
60
+ // Setting BROWSERSLIST short-circuits the walk entirely.
61
+ if (!process.env.BROWSERSLIST && !process.env.BROWSERSLIST_CONFIG) {
62
+ process.env.BROWSERSLIST = 'defaults';
63
+ }
64
+
55
65
  const formats = ['woff2'];
56
66
 
57
67
  function logToConsole(severity, ...args) {
@@ -60,43 +60,43 @@ async function warnAboutMissingGlyphs(
60
60
  const isMissing = !characterSetLookup.has(codePoint);
61
61
 
62
62
  if (isMissing) {
63
- // Find all occurrences of the missing character in the source,
64
- // not just the first, so that every location is reported.
65
- const locations = [];
66
- const sourceText = htmlOrSvgAsset.text;
63
+ // Report only the first location plus a count of remaining
64
+ // occurrences. A character like U+200B can appear thousands of
65
+ // times on a page and per-occurrence lines drown the log.
66
+ let firstLocation;
67
+ let occurrences = 0;
67
68
  if (char.length > 0) {
69
+ const sourceText = htmlOrSvgAsset.text;
68
70
  let searchIdx = 0;
69
71
  while (true) {
70
72
  const charIdx = sourceText.indexOf(char, searchIdx);
71
73
  if (charIdx === -1) break;
72
- if (!linesAndColumns) {
73
- linesAndColumns = new LinesAndColumns(sourceText);
74
+ occurrences++;
75
+ if (occurrences === 1) {
76
+ if (!linesAndColumns) {
77
+ linesAndColumns = new LinesAndColumns(sourceText);
78
+ }
79
+ const position = linesAndColumns.locationForIndex(charIdx);
80
+ firstLocation = `${htmlOrSvgAsset.urlOrDescription}:${
81
+ position.line + 1
82
+ }:${position.column + 1}`;
74
83
  }
75
- const position = linesAndColumns.locationForIndex(charIdx);
76
- locations.push(
77
- `${htmlOrSvgAsset.urlOrDescription}:${position.line + 1}:${
78
- position.column + 1
79
- }`
80
- );
81
84
  searchIdx = charIdx + char.length;
82
85
  }
83
86
  }
84
87
 
85
- if (locations.length === 0) {
86
- locations.push(
87
- `${htmlOrSvgAsset.urlOrDescription} (generated content)`
88
- );
88
+ if (!firstLocation) {
89
+ firstLocation = `${htmlOrSvgAsset.urlOrDescription} (generated content)`;
89
90
  }
90
91
 
91
- for (const location of locations) {
92
- missingGlyphsErrors.push({
93
- codePoint,
94
- char,
95
- htmlOrSvgAsset,
96
- fontUsage,
97
- location,
98
- });
99
- }
92
+ missingGlyphsErrors.push({
93
+ codePoint,
94
+ char,
95
+ htmlOrSvgAsset,
96
+ fontUsage,
97
+ location: firstLocation,
98
+ occurrences,
99
+ });
100
100
  missedAny = true;
101
101
  }
102
102
  }
@@ -123,12 +123,14 @@ async function warnAboutMissingGlyphs(
123
123
 
124
124
  if (missingGlyphsErrors.length) {
125
125
  const errorLog = missingGlyphsErrors.map(
126
- ({ char, fontUsage, location }) =>
127
- `- \\u{${char.codePointAt(0).toString(16)}} (${char}) in font-family '${
126
+ ({ char, fontUsage, location, occurrences }) => {
127
+ const extra = occurrences > 1 ? ` (+${occurrences - 1} more)` : '';
128
+ return `- \\u{${char.codePointAt(0).toString(16)}} (${char}) in font-family '${
128
129
  fontUsage.props['font-family']
129
130
  }' (${fontUsage.props['font-weight']}/${
130
131
  fontUsage.props['font-style']
131
- }) at ${location}`
132
+ }) at ${location}${extra}`;
133
+ }
132
134
  );
133
135
 
134
136
  const message = `Missing glyph fallback detected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turntrout/subfont",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Automatically subset web fonts to only the characters used on your pages. Fork of Munter/subfont with modern defaults.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"