@turntrout/subfont 1.3.2 → 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 +1 -0
- package/lib/parseCommandLineOptions.js +6 -0
- package/lib/subfont.js +30 -8
- package/lib/warnAboutMissingGlyphs.js +30 -28
- package/package.json +1 -1
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
|
) {
|
|
@@ -52,6 +53,16 @@ module.exports = async function subfont(
|
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
// Prevent postcss plugins (colormin, convert-values, etc.) invoked by
|
|
57
|
+
// cssnano from walking the filesystem for a "browserslist" config.
|
|
58
|
+
// Under pnpm, `node_modules/.bin/browserslist` is a shell shim that
|
|
59
|
+
// browserslist mis-parses as browser queries, throwing
|
|
60
|
+
// BrowserslistError and silently aborting CSS minification.
|
|
61
|
+
// Setting BROWSERSLIST short-circuits the walk entirely.
|
|
62
|
+
if (!process.env.BROWSERSLIST && !process.env.BROWSERSLIST_CONFIG) {
|
|
63
|
+
process.env.BROWSERSLIST = 'defaults';
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
const formats = ['woff2'];
|
|
56
67
|
|
|
57
68
|
function logToConsole(severity, ...args) {
|
|
@@ -164,17 +175,19 @@ module.exports = async function subfont(
|
|
|
164
175
|
);
|
|
165
176
|
}
|
|
166
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
|
+
};
|
|
167
187
|
if (silent) {
|
|
168
188
|
assetGraph.on('warn', () => {});
|
|
169
189
|
} else {
|
|
170
|
-
|
|
171
|
-
assetGraph.emit = function (event, err, ...rest) {
|
|
172
|
-
if (event === 'warn' && isExtensionlessEnoent(err)) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
return origEmit.call(this, event, err, ...rest);
|
|
176
|
-
};
|
|
177
|
-
await assetGraph.logEvents({ console });
|
|
190
|
+
await assetGraph.logEvents({ console, stopOnWarning: strict });
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
const outerTimings = {};
|
|
@@ -336,6 +349,15 @@ module.exports = async function subfont(
|
|
|
336
349
|
`[subfont timing] post-subsetFonts processing: ${outerTimings['post-subsetFonts processing']}ms`
|
|
337
350
|
);
|
|
338
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
|
+
|
|
339
361
|
phaseStart = Date.now();
|
|
340
362
|
if (!dryRun) {
|
|
341
363
|
await assetGraph.writeAssetsToDisc(
|
|
@@ -60,43 +60,43 @@ async function warnAboutMissingGlyphs(
|
|
|
60
60
|
const isMissing = !characterSetLookup.has(codePoint);
|
|
61
61
|
|
|
62
62
|
if (isMissing) {
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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 (
|
|
86
|
-
|
|
87
|
-
`${htmlOrSvgAsset.urlOrDescription} (generated content)`
|
|
88
|
-
);
|
|
88
|
+
if (!firstLocation) {
|
|
89
|
+
firstLocation = `${htmlOrSvgAsset.urlOrDescription} (generated content)`;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
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