Skip to content

Commit

Permalink
Avoids trying to stringify a huge array
Browse files Browse the repository at this point in the history
When using `JSON.stringify` on a large array (200k items), it may
run out of memory and give an error. We run into this error at the
end of generation when we write to `build/json/_metadata.json`.

This commit makes it only stringify one item at a time, which is
probably slower, but avoids the error (could probably add logic to
only do this if needed).
  • Loading branch information
bolshoytoster committed Dec 14, 2022
1 parent 132f986 commit 0f8ef6d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ const startCreating = () => {

return true;
});
writeMetaData(JSON.stringify(metadataList, null, 2));
writeMetaData(`[${metadataList.map(e => JSON.stringify(e, null, 2)).join(',')}]`);
};

module.exports = { startCreating, buildSetup, getElements };

0 comments on commit 0f8ef6d

Please sign in to comment.