Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] When called in a loop, the output is repeated #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/compressor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -127,7 +128,7 @@ function compress(config?: globals.IConfig) {
.catch(error => reject(error));
});
}

clear();
resolve(output.join('\n'));
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/generateoutput.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import globals = require('./globals');

var output = globals.output;

function removeEmptyStringsFromEnd(output: Array<string>) {
while (!output[output.length - 1]) {
output.pop();
Expand All @@ -13,8 +11,10 @@ function removeEmptyStringsFromEnd(output: Array<string>) {
* function, building the output array.
*/
function generateOutput() {
var output = globals.output;
var writers = globals.writers,
previousLine = '';


writers.forEach((writer) => {
previousLine = writer.write(output, previousLine);
Expand Down
14 changes: 14 additions & 0 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down Expand Up @@ -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<Writer> = [],
output: Array<string> = [],
Expand Down