@turntrout/subfont 1.3.3 → 1.4.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
@@ -71,6 +71,7 @@ subfont path/to/index.html -i --cache
71
71
  | `--concurrency N` | | Max worker threads (capped by available memory, ~50 MB each) |
72
72
  | `--chrome-flags` | | Custom Chrome flags for `--dynamic` |
73
73
  | `--source-maps` | off | Preserve CSS source maps (slower) |
74
+ | `--strict` | off | Exit non-zero if any warnings are emitted |
74
75
  | `-s, --silent` | off | Suppress all console output |
75
76
  | `-d, --debug` | off | Verbose timing and font glyph detection info |
76
77
  | `--relative-urls` | off | Emit relative URLs instead of root-relative |
@@ -132,6 +132,12 @@ module.exports = function parseCommandLineOptions(argv) {
132
132
  type: 'boolean',
133
133
  default: false,
134
134
  })
135
+ .options('strict', {
136
+ describe:
137
+ 'Exit with a non-zero status code if any warnings are emitted during the run',
138
+ type: 'boolean',
139
+ default: false,
140
+ })
135
141
  .wrap(require('yargs').terminalWidth());
136
142
 
137
143
  const { _: inputFiles, ...rest } = yargs.argv;
package/lib/subfont.js CHANGED
@@ -36,6 +36,7 @@ module.exports = async function subfont(
36
36
  concurrency,
37
37
  chromeFlags = [],
38
38
  cache = false,
39
+ strict = false,
39
40
  },
40
41
  console
41
42
  ) {
@@ -174,17 +175,19 @@ module.exports = async function subfont(
174
175
  );
175
176
  }
176
177
 
178
+ let sawWarning = false;
179
+ const origEmit = assetGraph.emit;
180
+ assetGraph.emit = function (event, err, ...rest) {
181
+ if (event === 'warn') {
182
+ if (isExtensionlessEnoent(err)) return false;
183
+ sawWarning = true;
184
+ }
185
+ return origEmit.call(this, event, err, ...rest);
186
+ };
177
187
  if (silent) {
178
188
  assetGraph.on('warn', () => {});
179
189
  } else {
180
- const origEmit = assetGraph.emit;
181
- assetGraph.emit = function (event, err, ...rest) {
182
- if (event === 'warn' && isExtensionlessEnoent(err)) {
183
- return false;
184
- }
185
- return origEmit.call(this, event, err, ...rest);
186
- };
187
- await assetGraph.logEvents({ console });
190
+ await assetGraph.logEvents({ console, stopOnWarning: strict });
188
191
  }
189
192
 
190
193
  const outerTimings = {};
@@ -346,6 +349,15 @@ module.exports = async function subfont(
346
349
  `[subfont timing] post-subsetFonts processing: ${outerTimings['post-subsetFonts processing']}ms`
347
350
  );
348
351
 
352
+ if (strict && sawWarning) {
353
+ // In non-silent mode, assetgraph's logEvents normally exits earlier via
354
+ // stopOnWarning. This guard covers silent mode and warnings that slipped
355
+ // past a transform boundary.
356
+ throw new Error(
357
+ 'subfont: --strict was set and one or more warnings were emitted; refusing to write output.'
358
+ );
359
+ }
360
+
349
361
  phaseStart = Date.now();
350
362
  if (!dryRun) {
351
363
  await assetGraph.writeAssetsToDisc(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turntrout/subfont",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
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"