feat: batch decompress and URL input for WOFF/WOFF2#691
Merged
Conversation
Allow multiple local paths, globs, or http(s) URLs in one webfont decompress run with per-input TTF/OTF output on result.decompressedFonts. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR expands the “webfont decompress” pipeline to support batch .woff/.woff2 inputs (including http(s) URLs), returning per-input outputs via result.decompressedFonts while preserving backward compatibility for single-input runs (result.ttf / result.otf). It also updates the CLI to write one decompressed output per input and refreshes user-facing documentation and tests accordingly.
Changes:
- Add batch + URL input resolution for WOFF/WOFF2 decompression, including new URL fetch helper with container validation.
- Introduce
DecompressedFontand surface batch results viaresult.decompressedFonts, keeping single-input root outputs for compatibility. - Update CLI output naming/writing for batch runs and update docs/tests to cover the new behavior.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| types/is-woff.d.ts | Adds TS module declarations for is-woff / is-woff2. |
| src/types/Result.ts | Extends Result with optional decompressedFonts and re-exports DecompressedFont. |
| src/types/DecompressedFont.ts | Introduces DecompressedFont shape for per-input decompression results. |
| src/standalone/webfontConversion.integration.test.ts | Updates integration coverage for multi-input decompression and HTTPS URL input. |
| src/standalone/inputMode.ts | Uses URL-aware extension parsing for input classification/filtering. |
| src/standalone/index.ts | Switches from raw globby to resolveInputSources to support URLs. |
| src/standalone/fetchWebfontUrl.ts | Adds fetchWebfontFromUrl for downloading and validating remote WOFF/WOFF2. |
| src/standalone/fetchWebfontUrl.test.ts | Adds unit tests for fetchWebfontFromUrl. |
| src/standalone/convertWebfontInput.ts | Implements multi-source decompression and populates decompressedFonts (+ single-input compatibility). |
| src/standalone/convertWebfontInput.test.ts | Updates unit tests for batch decompression and backward compatibility behavior. |
| src/lib/inputSource.ts | Adds URL detection, URL-safe extension parsing, and basename disambiguation helpers for batch outputs. |
| src/lib/inputSource.test.ts | Adds unit tests for URL/extension parsing and basename collision handling. |
| src/cli/program.ts | Writes per-input decompressed outputs for batch runs and adds basename resolution helper(s). |
| src/cli/program.test.ts | Adds tests for basename resolution and batch decompressed output writing. |
| src/cli/meow/cliOptions.ts | Updates CLI help text to describe batch + URL decompression inputs. |
| src/cli/index.test.ts | Adds CLI integration test for batch decompression output files. |
| README.md | Updates docs/examples to describe batch + URL decompression behavior and outputs. |
| NOTICE.md | Updates legal notice text to cover batch + URL decompression implications. |
| FEATURES.md | Updates feature spec + test criteria for batch + URL decompression support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+5
to
+19
| const assertWebfontContainer = (buffer: Buffer, source: string): void => { | ||
| const extension = getInputExtension(source); | ||
|
|
||
| if (extension === ".woff2" && !isWoff2(buffer)) { | ||
| throw new Error(`URL did not return a valid WOFF2 font: ${source}`); | ||
| } | ||
|
|
||
| if (extension === ".woff" && !isWoff(buffer)) { | ||
| throw new Error(`URL did not return a valid WOFF font: ${source}`); | ||
| } | ||
|
|
||
| if (buffer.length === 0) { | ||
| throw new Error(`URL returned an empty response: ${source}`); | ||
| } | ||
| }; |
Comment on lines
+37
to
+39
| if (isHttpUrl(source)) { | ||
| pathname = new URL(source).pathname; | ||
| } |
Comment on lines
91
to
+94
| const formats = resolveWebfontConversionFormats(options.formats); | ||
| const decompressedFonts = await Promise.all( | ||
| fontFiles.map((source) => decompressWebfontSource(source, formats, options.verbose)), | ||
| ); |
Comment on lines
+273
to
+294
| export const writeDecompressedFontFiles = async ( | ||
| fonts: readonly DecompressedFont[], | ||
| config: ResultConfig, | ||
| dest: string, | ||
| ): Promise<void> => { | ||
| await Promise.all( | ||
| fonts.flatMap((font) => { | ||
| const basename = getDecompressedFontOutputBasename(fonts, font, config); | ||
| const writes: Promise<void>[] = []; | ||
|
|
||
| if (font.ttf) { | ||
| writes.push(fs.promises.writeFile(path.resolve(path.join(dest, `${basename}.ttf`)), font.ttf)); | ||
| } | ||
|
|
||
| if (font.otf) { | ||
| writes.push(fs.promises.writeFile(path.resolve(path.join(dest, `${basename}.otf`)), font.otf)); | ||
| } | ||
|
|
||
| return writes; | ||
| }), | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Proposed changes
This PR brings the following changes:
.woff/.woff2inputs in one webfont decompress run (paths, globs, and/orhttp(s)URLs).result.decompressedFonts({ source, ttf?, otf? }[]); a single input still setsresult.ttf/result.otfat the top level for backward compatibility.fetchWebfontFromUrlwith WOFF/WOFF2 validation for remote sources (query strings in URLs supported).{basename}.ttf/.otfper input; colliding basenames get-woff/-woff2suffixes. Single-input runs still honor-u/fontName.FEATURES.md,README.md,NOTICE.md, and CLI help for batch + URL behavior.Related issue
N/A
Dependencies added/removed (if applicable)
N/A
Testing
How to test
npm test— 271 tests pass.node dist/cli.mjs "src/fixtures/fonts/*.woff2" -f ttf— one.ttfper matched file.webfont({ files: "https://…/font.woff2", formats: ["ttf"] }).Test configuration
N/A
Checklist
Made with Cursor