mirror of
https://github.com/developit/microbundle.git
synced 2026-01-25 14:06:50 +00:00
Co-authored-by: Leah <github.leah@hrmny.sh>
This commit is contained in:
parent
26f382a989
commit
2a0ca8843f
5
.changeset/quick-wasps-itch.md
Normal file
5
.changeset/quick-wasps-itch.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"microbundle": patch
|
||||
---
|
||||
|
||||
feat: :sparkles: Closes #497: preserve trailing newline in mangle.json
|
||||
13
src/index.js
13
src/index.js
@ -30,6 +30,7 @@ import {
|
||||
} from './lib/option-normalization';
|
||||
import { getConfigFromPkgJson, getName } from './lib/package-info';
|
||||
import { shouldCssModules, cssModulesConfig } from './lib/css-modules';
|
||||
import { EOL } from 'os';
|
||||
|
||||
// Extensions to use when resolving modules
|
||||
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs'];
|
||||
@ -403,9 +404,13 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
const externalTest =
|
||||
external.length === 0 ? id => false : id => externalPredicate.test(id);
|
||||
|
||||
let endsWithNewLine = false;
|
||||
|
||||
function loadNameCache() {
|
||||
try {
|
||||
nameCache = JSON.parse(fs.readFileSync(getNameCachePath(), 'utf8'));
|
||||
const data = fs.readFileSync(getNameCachePath(), 'utf8');
|
||||
endsWithNewLine = data.endsWith(EOL);
|
||||
nameCache = JSON.parse(data);
|
||||
// mangle.json can contain a "minify" field, same format as the pkg.mangle:
|
||||
if (nameCache.minify) {
|
||||
minifyOptions = Object.assign(
|
||||
@ -618,7 +623,11 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
if (writeMeta && nameCache) {
|
||||
fs.writeFile(
|
||||
getNameCachePath(),
|
||||
JSON.stringify(nameCache, null, 2),
|
||||
JSON.stringify(
|
||||
endsWithNewLine ? `${nameCache}${EOL}` : nameCache,
|
||||
null,
|
||||
2,
|
||||
),
|
||||
() => {},
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user