cobalt-ui
cobalt-ui copied to clipboard
If a file Buffer is passed to the parser 0 tokens is found without error
Versions
- terrazzo/parser: 0.10.3
Node.js version
24.4.1
OS + version
macOS 26
Description
Seems that the parser handles Buffer differently than the cli. But if it gets one it executes itself without an error.
As seen in the documentation :
const filename = new URL("./tokens/my-tokens.json", import.meta.url);
const { tokens, sources } = await parse(
[{ filename, src: await fs.readFile(filename) }],
{ config }
);
This runs without any error but do not find any error
The idea here is to update documentation to go from await fs.readFile(filename) to await fs.readFile(filename, 'utf-8') and add an error handling if a buffer is found in the parser.
Reproduction
Use JS API to generate tokens using the doc.
Expected result
If the tokens.json input is filled with DTCG compliant tokens it builds tokens without error
Extra
- [x] I’m willing to open a PR (see CONTRIBUTING.md)
Thank you! Would love a PR if you have time. I think there are 2 parts here:
- In
@terrazzo/cli, we check forsrc instanceof Bufferand convert - In
parser, we should make some loose check for “object in memory that’s a binary” (maybesrc && typeof src === 'object' && !Object.keys.length(src)?) and throw an error. Remember that the parser can run in a browser so we can’t runinstanceof Bufferthere, or use Node libraries to check it.