mirror of
https://github.com/developit/microbundle.git
synced 2026-01-25 14:06:50 +00:00
Fix mangle.json indentation style not preserved (#999)
This commit is contained in:
parent
124c9c607c
commit
22187fba8a
5
.changeset/gold-berries-march.md
Normal file
5
.changeset/gold-berries-march.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'microbundle': patch
|
||||
---
|
||||
|
||||
Fix indentation style in `mangle.json` not preserved
|
||||
@ -408,9 +408,11 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
|
||||
let endsWithNewLine = false;
|
||||
|
||||
let nameCacheIndentTabs = false;
|
||||
function loadNameCache() {
|
||||
try {
|
||||
const data = fs.readFileSync(getNameCachePath(), 'utf8');
|
||||
nameCacheIndentTabs = /^\t+/gm.test(data);
|
||||
endsWithNewLine = data.endsWith(EOL);
|
||||
nameCache = JSON.parse(data);
|
||||
// mangle.json can contain a "minify" field, same format as the pkg.mangle:
|
||||
@ -628,7 +630,11 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
writeBundle() {
|
||||
if (writeMeta && nameCache) {
|
||||
let filename = getNameCachePath();
|
||||
let json = JSON.stringify(nameCache, null, 2);
|
||||
let json = JSON.stringify(
|
||||
nameCache,
|
||||
null,
|
||||
nameCacheIndentTabs ? '\t' : 2,
|
||||
);
|
||||
if (endsWithNewLine) json += EOL;
|
||||
fs.writeFile(filename, json, () => {});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user