feat(cjs-to-esm): update package.jsons#400
feat(cjs-to-esm): update package.jsons#400AugustinMauroy wants to merge 4 commits intowip/cjs-to-esmfrom
package.jsons#400Conversation
avivkeller
left a comment
There was a problem hiding this comment.
Can't we just modify JSON, rather than use Codemod for simple JSON transforms?
|
Yeah, I would expect:
|
|
you mean something like that ? const source = root.text();
const pjsonData = JSON.parse(source); |
|
Like const rawSource = readFile(…)
const pjson = JSON.parse(rawSource) |
|
if we do that we need to enable fs on jssg context which trow a warn so user can be afraid. Why I use full ast ?
|
+1 - I don’t think it’s worth using But yeah, if I’m not wrong, you can just return a string and it will replace the entire file. So something like the example below could be an easier way to achieve the same result: const pjson = JSON.parse(root.source())
// manipulate pjson as a JS object
return JSON.stringify(pjson)The only drawback I can think of is that formatting might be lost, but even the key order is preserved in most cases. |
|
I'm going to take a look at sting -> json parse -> js object manipulation -> json string -> string back to modemode @alexbit-codemod & @mohebifar what is the recommandation from Codemod team when a codemod should update json file in a JSSG step ? |
cjs-to-esm/package-json): introducecjs-to-esm): update package.jsons
cjs-to-esm): update package.jsonspackage.jsons
|
We have cross file transformations feature (a new one). Also, we do have json support. So you should be good. Let me know if you have other questions. https://docs.codemod.com/jssg/reference#multi-file-transforms-with-jssgtransform |
close #342