Skip to content

Commit

Permalink
refactor(json): simplify default options handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Dec 7, 2024
1 parent 92daef0 commit 6f34d45
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/json/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { createFilter, dataToEsm } from '@rollup/pluginutils';

export default function json(options = {}) {
const filter = createFilter(options.include, options.exclude);
const indent = 'indent' in options ? options.indent : '\t';
const {
include,
exclude,
indent = '\t',
preferConst,
compact,
namedExports,
includeArbitraryNames
} = options;
const filter = createFilter(include, exclude);

return {
name: 'json',
Expand All @@ -15,10 +23,10 @@ export default function json(options = {}) {
const parsed = JSON.parse(code);
return {
code: dataToEsm(parsed, {
preferConst: options.preferConst,
compact: options.compact,
namedExports: options.namedExports,
includeArbitraryNames: options.includeArbitraryNames,
preferConst,
compact,
namedExports,
includeArbitraryNames,
indent
}),
map: { mappings: '' }
Expand Down

0 comments on commit 6f34d45

Please sign in to comment.