@turntrout/subfont 1.5.0 → 1.5.1

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.
@@ -4,7 +4,9 @@ const os = require('os');
4
4
  const WORKER_MEMORY_BYTES = 50 * 1024 * 1024; // 50 MB
5
5
 
6
6
  function getMaxConcurrency() {
7
- return Math.max(1, Math.floor(os.totalmem() / WORKER_MEMORY_BYTES));
7
+ const byMemory = Math.floor(os.freemem() / WORKER_MEMORY_BYTES);
8
+ const byCpu = os.cpus().length * 4;
9
+ return Math.max(1, Math.min(byMemory, byCpu));
8
10
  }
9
11
 
10
12
  module.exports = { WORKER_MEMORY_BYTES, getMaxConcurrency };
@@ -111,7 +111,7 @@ module.exports = function parseCommandLineOptions(argv) {
111
111
  },
112
112
  })
113
113
  .options('concurrency', {
114
- describe: `Maximum number of worker threads for parallel font tracing. Defaults to the number of CPU cores (max 8). Upper bound: ${maxConcurrency} (based on available memory)`,
114
+ describe: `Maximum number of worker threads for parallel font tracing. Defaults to the number of CPU cores (max 8). Upper bound: ${maxConcurrency} (based on free memory and CPU count)`,
115
115
  type: 'number',
116
116
  })
117
117
  .check((argv) => {
@@ -121,7 +121,7 @@ module.exports = function parseCommandLineOptions(argv) {
121
121
  }
122
122
  if (argv.concurrency > maxConcurrency) {
123
123
  throw new Error(
124
- `--concurrency must not exceed ${maxConcurrency} (each worker uses ~50 MB; system has ${Math.round(os.totalmem() / (1024 * 1024 * 1024))} GB total)`
124
+ `--concurrency must not exceed ${maxConcurrency} (each worker uses ~50 MB; ${Math.round(os.freemem() / (1024 * 1024 * 1024))} GB free, ${os.cpus().length} CPUs)`
125
125
  );
126
126
  }
127
127
  }
package/lib/subfont.js CHANGED
@@ -49,7 +49,7 @@ module.exports = async function subfont(
49
49
  const maxConcurrency = getMaxConcurrency();
50
50
  if (concurrency !== undefined && concurrency > maxConcurrency) {
51
51
  throw new UsageError(
52
- `--concurrency must not exceed ${maxConcurrency} (each worker uses ~50 MB; system has ${Math.round(os.totalmem() / (1024 * 1024 * 1024))} GB total)`
52
+ `--concurrency must not exceed ${maxConcurrency} (each worker uses ~50 MB; ${Math.round(os.freemem() / (1024 * 1024 * 1024))} GB free, ${os.cpus().length} CPUs)`
53
53
  );
54
54
  }
55
55
 
@@ -263,6 +263,7 @@ async function getSubsetsForFontUsage(
263
263
  .catch((err) => {
264
264
  err.asset = err.asset || fontAssetsByUrl.get(fontUrl);
265
265
  assetGraph.warn(err);
266
+ return null;
266
267
  })
267
268
  );
268
269
  }
package/lib/wasmQueue.js CHANGED
@@ -5,7 +5,10 @@
5
5
  let queue = Promise.resolve();
6
6
 
7
7
  function enqueue(fn) {
8
- return (queue = queue.then(fn, fn));
8
+ return (queue = queue.then(
9
+ () => fn(),
10
+ () => fn()
11
+ ));
9
12
  }
10
13
 
11
14
  module.exports = enqueue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turntrout/subfont",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Automatically subset web fonts to only the characters used on your pages. Fork of Munter/subfont with modern defaults.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"