Revisiting this issue, I don't think the raw config is quite the correct solution.
The original issue is that this plugin unquotes numeric keys:
❯ node
Welcome to Node.js v18.14.0.
Type ".help" for more information.
> yaml = require('@modyfi/vite-plugin-yaml')
{ default: [Function: src_default] }
> await yaml.default().transform(`
... '07': foo
... `, "foo.yaml")
{
code: 'const data = { 07:"foo" };\nexport default data;',
map: { mappings: '' }
}
>
Which, as the above issue notes, results in an error because of the leading 0.
The problem with raw mode is it fails on objects:
> await yaml.default({raw: true}).transform(`
... foo: bar
... `, "foo.yaml")
{
code: 'const data = [object Object];\nexport default data;',
map: { mappings: '' }
}
The above issue correctly identified tosource as the culprit here. Since js-yaml.load returns plain JSON, I'm not sure why tosource is necessary at all, as opposed to just JSON.stringify.
Happy to submit a PR if that sounds reasonable.
Revisiting this issue, I don't think the
rawconfig is quite the correct solution.The original issue is that this plugin unquotes numeric keys:
Which, as the above issue notes, results in an error because of the leading 0.
The problem with
rawmode is it fails on objects:The above issue correctly identified
tosourceas the culprit here. Sincejs-yaml.loadreturns plain JSON, I'm not sure whytosourceis necessary at all, as opposed to justJSON.stringify.Happy to submit a PR if that sounds reasonable.