@e-mc/compress 0.13.6 → 0.13.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +5 -5
  2. package/index.js +10 -12
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @e-mc/compress
2
2
 
3
- * NodeJS 18.20.5 LTS
3
+ * NodeJS 18.20 LTS
4
4
  * ES2022
5
5
 
6
6
  ## General Usage
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.13.6/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.8/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -125,11 +125,11 @@ instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
125
125
 
126
126
  ## References
127
127
 
128
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/squared.d.ts
129
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/compress.d.ts
130
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/settings.d.ts
128
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/compress.d.ts
129
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/settings.d.ts
131
130
 
132
131
  * https://www.npmjs.com/package/@types/node
132
+ * https://www.npmjs.com/package/@types/node-zopfli
133
133
 
134
134
  ## LICENSE
135
135
 
package/index.js CHANGED
@@ -13,13 +13,10 @@ function createWorker(filename) {
13
13
  }
14
14
  const SUPPORTED_NODE21 = (0, types_1.supported)(21);
15
15
  const CACHE_IMAGE = Object.create(null);
16
- const CACHE_FONT = Object.create(null);
16
+ const CACHE_FONT = new Map();
17
17
  const CACHE_FONTFROM = Object.create(null);
18
18
  const CACHE_FONTTO = Object.create(null);
19
- const CACHE_TEMP = {
20
- font: undefined,
21
- image: undefined
22
- };
19
+ const CACHE_TEMP = { font: undefined, image: undefined };
23
20
  let SINGLETON_INSTANCE;
24
21
  const WORKER = new core_1.WorkerGroup(parseInt(process.env.EMC_COMPRESS_WORKER_GROUP_MAX || '0'));
25
22
  WORKER
@@ -348,7 +345,7 @@ class Compress extends core_1.Module {
348
345
  }
349
346
  fs.writeFile(tempFont, data, err => {
350
347
  if (!err) {
351
- CACHE_FONT[from + '_' + ext + '_' + hash] = [tempFont, new Date()];
348
+ CACHE_FONT.set(from + '_' + ext + '_' + hash, [tempFont, new Date()]);
352
349
  CACHE_FONTTO[hash] = ext;
353
350
  }
354
351
  });
@@ -373,7 +370,7 @@ class Compress extends core_1.Module {
373
370
  const to = CACHE_FONTTO[hash];
374
371
  if (from && to) {
375
372
  const cacheKey = from + `_${to}_` + hash;
376
- const tempFont = CACHE_FONT[cacheKey];
373
+ const tempFont = CACHE_FONT.get(cacheKey);
377
374
  if (tempFont) {
378
375
  if (core_1.Module.isPath(tempFont[0])) {
379
376
  try {
@@ -392,7 +389,7 @@ class Compress extends core_1.Module {
392
389
  catch {
393
390
  }
394
391
  }
395
- delete CACHE_FONT[cacheKey];
392
+ CACHE_FONT.delete(cacheKey);
396
393
  }
397
394
  return false;
398
395
  }
@@ -698,7 +695,8 @@ class Compress extends core_1.Module {
698
695
  complete(null, result, worker, ctime);
699
696
  }
700
697
  };
701
- if (tempDir = this.#getCacheDir('image')) {
698
+ tempDir = this.#getCacheDir('image');
699
+ if (tempDir) {
702
700
  let stored;
703
701
  try {
704
702
  hash = core_1.Module.asHash(data);
@@ -807,7 +805,7 @@ class Compress extends core_1.Module {
807
805
  (function recurse(paths) {
808
806
  try {
809
807
  const srcDir = path.join(tempDir, ...paths);
810
- fs.readdirSync(srcDir, { withFileTypes: true }).forEach(item => {
808
+ for (const item of fs.readdirSync(srcDir, { withFileTypes: true })) {
811
809
  const filename = item.name;
812
810
  if (item.isFile()) {
813
811
  const target = path.join(srcDir, filename);
@@ -816,7 +814,7 @@ class Compress extends core_1.Module {
816
814
  const stat = fs.lstatSync(target);
817
815
  if (stat.atimeMs + expires > current) {
818
816
  if (type === 'font') {
819
- CACHE_FONT[paths.concat(filename).join('_')] = [target, stat.ctime];
817
+ CACHE_FONT.set(paths.concat(filename).join('_'), [target, stat.ctime]);
820
818
  CACHE_FONTFROM[filename] = paths[0];
821
819
  CACHE_FONTTO[filename] = paths[1];
822
820
  }
@@ -834,7 +832,7 @@ class Compress extends core_1.Module {
834
832
  else if (item.isDirectory()) {
835
833
  recurse(paths.concat(filename));
836
834
  }
837
- });
835
+ }
838
836
  }
839
837
  catch {
840
838
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/compress",
3
- "version": "0.13.6",
3
+ "version": "0.13.8",
4
4
  "description": "Compress constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "license": "BSD-3-Clause",
23
23
  "homepage": "https://github.com/anpham6/e-mc#readme",
24
24
  "dependencies": {
25
- "@e-mc/core": "0.13.6",
26
- "@e-mc/types": "0.13.6",
25
+ "@e-mc/core": "0.13.8",
26
+ "@e-mc/types": "0.13.8",
27
27
  "wawoff2": "^2.0.1",
28
28
  "woff2sfnt-sfnt2woff": "^1.0.0"
29
29
  }