From 3b5e24ed6b2c253b8078b28503b7cde211db8117 Mon Sep 17 00:00:00 2001 From: remotesc2 Date: Thu, 24 Jan 2019 11:53:01 +0800 Subject: [PATCH 1/2] [fix] When called in a loop, the output content is repeated --- src/lib/compressor.ts | 3 ++- src/lib/globals.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/compressor.ts b/src/lib/compressor.ts index bec276b..8ad5fcf 100644 --- a/src/lib/compressor.ts +++ b/src/lib/compressor.ts @@ -37,6 +37,7 @@ function compress(config?: globals.IConfig) { writers = globals.writers, output = globals.output, dest = globals.config.dest, + clear = globals.clear, version = globals.config.version, license = globals.config.license; @@ -127,7 +128,7 @@ function compress(config?: globals.IConfig) { .catch(error => reject(error)); }); } - + clear(); resolve(output.join('\n')); }); }); diff --git a/src/lib/globals.ts b/src/lib/globals.ts index d50003e..c354069 100644 --- a/src/lib/globals.ts +++ b/src/lib/globals.ts @@ -32,6 +32,11 @@ export interface IConfig { * license will be replaced with the version. */ license?: string; + + /** + * Clear global cache var + */ + clear?: Function; } export interface IObject { @@ -85,6 +90,15 @@ export function initialize(cfg: IConfig) { return config; } +/** + * Clear cache + */ +export function clear() { + writers = []; + output = []; + imports = {}; +} + export var config: IConfig, writers: Array = [], output: Array = [], From d03f347e72f62062d17c87dc1c551ec9140239c6 Mon Sep 17 00:00:00 2001 From: remotesc2 Date: Thu, 24 Jan 2019 11:55:17 +0800 Subject: [PATCH 2/2] [fix] When called in a loop, the output content is repeated --- src/lib/generateoutput.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/generateoutput.ts b/src/lib/generateoutput.ts index 01439e5..8c02322 100644 --- a/src/lib/generateoutput.ts +++ b/src/lib/generateoutput.ts @@ -1,7 +1,5 @@ import globals = require('./globals'); -var output = globals.output; - function removeEmptyStringsFromEnd(output: Array) { while (!output[output.length - 1]) { output.pop(); @@ -13,8 +11,10 @@ function removeEmptyStringsFromEnd(output: Array) { * function, building the output array. */ function generateOutput() { + var output = globals.output; var writers = globals.writers, previousLine = ''; + writers.forEach((writer) => { previousLine = writer.write(output, previousLine);