vite-plugin-compression
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -0,1 +1,10 @@ | ||
## [0.3.5](https://github.com/anncwb/vite-plugin-compression/compare/v0.2.4...v0.3.5) (2021-11-25) | ||
### Bug Fixes | ||
* type error,fix [#5](https://github.com/anncwb/vite-plugin-compression/issues/5) ([cd6c313](https://github.com/anncwb/vite-plugin-compression/commit/cd6c313f63b4a8147d518e17c887049cdae6f1b7)) | ||
## [0.3.4](https://github.com/anncwb/vite-plugin-compression/compare/v0.2.4...v0.3.4) (2021-08-23) | ||
@@ -2,0 +11,0 @@ |
@@ -1,5 +0,9 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -20,10 +24,30 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
// src/index.ts | ||
var _path = require('path'); var _path2 = _interopRequireDefault(_path); | ||
var _vite = require('vite'); | ||
__export(exports, { | ||
default: () => src_default | ||
}); | ||
var import_path2 = __toModule(require("path")); | ||
var import_vite = __toModule(require("vite")); | ||
// src/utils.ts | ||
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); | ||
var import_fs = __toModule(require("fs")); | ||
var import_path = __toModule(require("path")); | ||
var isFunction = (arg) => typeof arg === "function"; | ||
@@ -34,8 +58,8 @@ var isRegExp = (arg) => Object.prototype.toString.call(arg) === "[object RegExp]"; | ||
try { | ||
if (_fs2.default.existsSync(root)) { | ||
const stat = _fs2.default.lstatSync(root); | ||
if (import_fs.default.existsSync(root)) { | ||
const stat = import_fs.default.lstatSync(root); | ||
if (stat.isDirectory()) { | ||
const files = _fs2.default.readdirSync(root); | ||
const files = import_fs.default.readdirSync(root); | ||
files.forEach(function(file) { | ||
const t = readAllFile(_path2.default.join(root, "/", file), reg); | ||
const t = readAllFile(import_path.default.join(root, "/", file), reg); | ||
resultArr = resultArr.concat(t); | ||
@@ -59,7 +83,7 @@ }); | ||
// src/index.ts | ||
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra); | ||
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); | ||
var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib); | ||
var _debug = require('debug'); | ||
var debug = _debug.debug.call(void 0, "vite-plugin-compression"); | ||
var import_fs_extra = __toModule(require("fs-extra")); | ||
var import_chalk = __toModule(require("chalk")); | ||
var import_zlib = __toModule(require("zlib")); | ||
var import_debug = __toModule(require("debug")); | ||
var debug = (0, import_debug.debug)("vite-plugin-compression"); | ||
var extRE = /\.(js|mjs|json|css|html)$/i; | ||
@@ -94,3 +118,3 @@ var mtimeCache = new Map(); | ||
config = resolvedConfig; | ||
outputPath = _path2.default.isAbsolute(config.build.outDir) ? config.build.outDir : _path2.default.join(config.root, config.build.outDir); | ||
outputPath = import_path2.default.isAbsolute(config.build.outDir) ? config.build.outDir : import_path2.default.join(config.root, config.build.outDir); | ||
debug("resolvedConfig:", resolvedConfig); | ||
@@ -107,8 +131,8 @@ }, | ||
const handles = files.map(async (filePath) => { | ||
let { mtimeMs, size: oldSize } = await _fsextra2.default.stat(filePath); | ||
let { mtimeMs, size: oldSize } = await import_fs_extra.default.stat(filePath); | ||
if (mtimeMs <= (mtimeCache.get(filePath) || 0) || oldSize < threshold) | ||
return; | ||
let content = await _fsextra2.default.readFile(filePath); | ||
let content = await import_fs_extra.default.readFile(filePath); | ||
if (deleteOriginFile) { | ||
_fsextra2.default.remove(filePath); | ||
import_fs_extra.default.remove(filePath); | ||
} | ||
@@ -127,3 +151,3 @@ try { | ||
}); | ||
await _fsextra2.default.writeFile(cname, content); | ||
await import_fs_extra.default.writeFile(cname, content); | ||
mtimeCache.set(filePath, Date.now()); | ||
@@ -159,14 +183,14 @@ }); | ||
gzip: { | ||
level: _zlib2.default.constants.Z_BEST_COMPRESSION | ||
level: import_zlib.default.constants.Z_BEST_COMPRESSION | ||
}, | ||
deflate: { | ||
level: _zlib2.default.constants.Z_BEST_COMPRESSION | ||
level: import_zlib.default.constants.Z_BEST_COMPRESSION | ||
}, | ||
deflateRaw: { | ||
level: _zlib2.default.constants.Z_BEST_COMPRESSION | ||
level: import_zlib.default.constants.Z_BEST_COMPRESSION | ||
}, | ||
brotliCompress: { | ||
params: { | ||
[_zlib2.default.constants.BROTLI_PARAM_QUALITY]: _zlib2.default.constants.BROTLI_MAX_QUALITY, | ||
[_zlib2.default.constants.BROTLI_PARAM_MODE]: _zlib2.default.constants.BROTLI_MODE_TEXT | ||
[import_zlib.default.constants.BROTLI_PARAM_QUALITY]: import_zlib.default.constants.BROTLI_MAX_QUALITY, | ||
[import_zlib.default.constants.BROTLI_PARAM_MODE]: import_zlib.default.constants.BROTLI_MODE_TEXT | ||
} | ||
@@ -179,3 +203,3 @@ } | ||
return new Promise((resolve, reject) => { | ||
_zlib2.default[algorithm](content, options, (err, result) => err ? reject(err) : resolve(result)); | ||
import_zlib.default[algorithm](content, options, (err, result) => err ? reject(err) : resolve(result)); | ||
}); | ||
@@ -189,3 +213,3 @@ } | ||
config.logger.info(` | ||
${_chalk2.default.cyan("\u2728 [vite-plugin-compression]:algorithm=" + algorithm)} - compressed file successfully: `); | ||
${import_chalk.default.cyan("\u2728 [vite-plugin-compression]:algorithm=" + algorithm)} - compressed file successfully: `); | ||
const keyLengths = Array.from(compressMap.keys(), (name) => name.length); | ||
@@ -195,5 +219,5 @@ const maxKeyLength = Math.max(...keyLengths); | ||
let { size, oldSize, cname } = value; | ||
const rName = _vite.normalizePath.call(void 0, cname).replace(_vite.normalizePath.call(void 0, `${config.root}/${config.build.outDir}/`), ""); | ||
const rName = (0, import_vite.normalizePath)(cname).replace((0, import_vite.normalizePath)(`${config.root}/${config.build.outDir}/`), ""); | ||
const sizeStr = `${oldSize.toFixed(2)}kb / ${algorithm}: ${size.toFixed(2)}kb`; | ||
config.logger.info(_chalk2.default.dim(config.build.outDir + "/") + _chalk2.default.blueBright(rName) + " ".repeat(2 + maxKeyLength - name.length) + " " + _chalk2.default.dim(sizeStr)); | ||
config.logger.info(import_chalk.default.dim(config.build.outDir + "/") + import_chalk.default.blueBright(rName) + " ".repeat(2 + maxKeyLength - name.length) + " " + import_chalk.default.dim(sizeStr)); | ||
}); | ||
@@ -204,4 +228,3 @@ config.logger.info("\n"); | ||
var src_default = exportFn; | ||
exports.default = src_default; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
{ | ||
"name": "vite-plugin-compression", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Use gzip or brotli to compress resources.", | ||
@@ -46,12 +46,12 @@ "main": "dist/index.js", | ||
"@types/debug": "^4.1.7", | ||
"@types/fs-extra": "^9.0.12", | ||
"@types/node": "^16.7.1", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/node": "^16.11.10", | ||
"conventional-changelog-cli": "^2.1.1", | ||
"ini": "^2.0.0", | ||
"prettier": "^2.3.2", | ||
"prettier": "^2.5.0", | ||
"rimraf": "^3.0.2", | ||
"tsup": "^4.14.0", | ||
"typescript": "^4.3.5", | ||
"vite": "^2.5.0" | ||
"tsup": "^5.9.2", | ||
"typescript": "^4.5.2", | ||
"vite": "^2.6.14" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
24893
460