index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var pluginutils = require('@rollup/pluginutils');
  3. function json(options) {
  4. if ( options === void 0 ) options = {};
  5. var filter = pluginutils.createFilter(options.include, options.exclude);
  6. var indent = 'indent' in options ? options.indent : '\t';
  7. return {
  8. name: 'json',
  9. // eslint-disable-next-line no-shadow
  10. transform: function transform(json, id) {
  11. if (id.slice(-5) !== '.json' || !filter(id)) { return null; }
  12. try {
  13. var parsed = JSON.parse(json);
  14. return {
  15. code: pluginutils.dataToEsm(parsed, {
  16. preferConst: options.preferConst,
  17. compact: options.compact,
  18. namedExports: options.namedExports,
  19. indent: indent
  20. }),
  21. map: { mappings: '' }
  22. };
  23. } catch (err) {
  24. var message = 'Could not parse JSON file';
  25. var position = parseInt(/[\d]/.exec(err.message)[0], 10);
  26. this.warn({ message: message, id: id, position: position });
  27. return null;
  28. }
  29. }
  30. };
  31. }
  32. module.exports = json;
  33. //# sourceMappingURL=index.js.map