Showing 2 of 7 files from the diff.

@@ -29,6 +29,7 @@
Loading
29 29
    lstat: util.promisify(fs.lstat),
30 30
    readdir: util.promisify(fs.readdir),
31 31
    exists: util.promisify(fs.exists),
32 +
    unlink: util.promisify(fs.unlink),
32 33
  };
33 34
  private readonly nativeStream = {
34 35
    pipeline: util.promisify(stream.pipeline),
@@ -167,13 +168,16 @@
Loading
167 168
          }
168 169
169 170
          const hrtimeStart = process.hrtime();
170 -
          compressedFiles.push(filePath);
171 171
          const fileInfo = await this.compressFile(
172 172
            file,
173 173
            target,
174 174
            this.outputPath,
175 175
          );
176 176
177 +
          if (!(fileInfo as CompressedFile).removeCompiled) {
178 +
            compressedFiles.push(filePath);
179 +
          }
180 +
177 181
          if (this.options.verbose) {
178 182
            const hrTimeEnd = process.hrtime(hrtimeStart);
179 183
            this.logger.log(
@@ -250,10 +254,16 @@
Loading
250 254
      );
251 255
    }
252 256
253 -
    if (this.options.verbose) {
257 +
    if (this.options.verbose || this.options.removeLarger) {
254 258
      const beforeSize = (await this.nativeFs.lstat(inputPath)).size;
255 259
      const afterSize = (await this.nativeFs.lstat(outputPath)).size;
256 -
      return { beforeSize, afterSize, isCached };
260 +
261 +
      const removeCompiled =
262 +
        this.options.removeLarger && beforeSize < afterSize;
263 +
      if (removeCompiled) {
264 +
        await this.nativeFs.unlink(outputPath);
265 +
      }
266 +
      return { beforeSize, afterSize, isCached, removeCompiled };
257 267
    }
258 268
259 269
    return { isCached };

@@ -72,6 +72,10 @@
Loading
72 72
        '--output-file-format <value>',
73 73
        'output file format with default artifacts [filename].[ext].[compressExt]',
74 74
      )
75 +
      .option(
76 +
        '--remove-larger',
77 +
        'remove compressed files if they larger than uncompressed originals',
78 +
      )
75 79
      .action(this.compress.bind(this));
76 80
77 81
    const cache = this.commander
@@ -135,6 +139,9 @@
Loading
135 139
        options.brotliSizeHint,
136 140
      outputFileFormat:
137 141
        this.env.GZIPPER_OUTPUT_FILE_FORMAT || options.outputFileFormat,
142 +
      removeLarger: this.env.GZIPPER_REMOVE_LARGER
143 +
        ? !!parseInt(this.env.GZIPPER_REMOVE_LARGER as string)
144 +
        : options.removeLarger,
138 145
    };
139 146
140 147
    await this.runCompress(target, outputPath, adjustedOptions);
Files Coverage
src 96.60%
Project Totals (13 files) 96.60%
338204980
338204980
338204980
338204980

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading