@turntrout/subfont 1.7.0 → 1.7.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.
@@ -0,0 +1,37 @@
1
+ interface StylesheetWithPredicates {
2
+ text?: string;
3
+ asset?: {
4
+ text?: string;
5
+ };
6
+ predicates?: Record<string, unknown>;
7
+ }
8
+ interface FontTracerPoolOptions {
9
+ taskTimeoutMs?: number;
10
+ }
11
+ declare class FontTracerPool {
12
+ private _workerPath;
13
+ private _numWorkers;
14
+ private _taskTimeoutMs;
15
+ private _workers;
16
+ private _idle;
17
+ private _pendingTasks;
18
+ private _taskCallbacks;
19
+ private _taskTimers;
20
+ private _taskByWorker;
21
+ private _nextTaskId;
22
+ constructor(numWorkers: number, { taskTimeoutMs }?: FontTracerPoolOptions);
23
+ init(): Promise<void>;
24
+ private _clearTaskTimer;
25
+ private _onWorkerMessage;
26
+ private _onWorkerExit;
27
+ private _startTaskTimer;
28
+ private _dispatchPending;
29
+ /**
30
+ * Run fontTracer on the given HTML text + stylesheets in a worker.
31
+ * Returns a promise that resolves to textByProps.
32
+ */
33
+ trace(htmlText: string, stylesheetsWithPredicates: StylesheetWithPredicates[]): Promise<unknown>;
34
+ destroy(): Promise<void>;
35
+ }
36
+ export = FontTracerPool;
37
+ //# sourceMappingURL=FontTracerPool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontTracerPool.d.ts","sourceRoot":"","sources":["../src/FontTracerPool.ts"],"names":[],"mappings":"AAkBA,UAAU,wBAAwB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAI1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAqCD,UAAU,qBAAqB;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,WAAW,CAAS;gBAG1B,UAAU,EAAE,MAAM,EAClB,EAAE,aAAuC,EAAE,GAAE,qBAA0B;IAcnE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiC3B,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,aAAa;IAwCrB,OAAO,CAAC,eAAe;IA2BvB,OAAO,CAAC,gBAAgB;IAsBxB;;;OAGG;IAGH,KAAK,CACH,QAAQ,EAAE,MAAM,EAChB,yBAAyB,EAAE,wBAAwB,EAAE,GAEpD,OAAO,CAAC,OAAO,CAAC;IAsBb,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA4C/B;AAED,SAAS,cAAc,CAAC"}
@@ -1,239 +1,230 @@
1
- const pathModule = require('path');
2
- const { Worker } = require('worker_threads');
3
-
1
+ "use strict";
2
+ const pathModule = require("path");
3
+ const worker_threads_1 = require("worker_threads");
4
4
  /**
5
5
  * Worker pool for running fontTracer in parallel across pages.
6
6
  * Each worker re-parses HTML with jsdom and runs fontTracer independently.
7
7
  */
8
8
  const DEFAULT_TASK_TIMEOUT_MS = 60_000;
9
-
10
9
  class FontTracerPool {
11
- constructor(numWorkers, { taskTimeoutMs = DEFAULT_TASK_TIMEOUT_MS } = {}) {
12
- this._workerPath = pathModule.join(__dirname, 'fontTracerWorker.js');
13
- this._numWorkers = numWorkers;
14
- this._taskTimeoutMs = taskTimeoutMs;
15
- this._workers = [];
16
- this._idle = [];
17
- this._pendingTasks = [];
18
- this._taskCallbacks = new Map();
19
- this._taskTimers = new Map();
20
- this._taskByWorker = new Map(); // track which taskId each worker is processing
21
- this._nextTaskId = 0;
22
- }
23
-
24
- async init() {
25
- const initPromises = [];
26
- for (let i = 0; i < this._numWorkers; i++) {
27
- const worker = new Worker(this._workerPath);
28
- this._workers.push(worker);
29
-
30
- const initPromise = new Promise((resolve, reject) => {
31
- const onError = reject;
32
- const onMessage = (msg) => {
33
- if (msg.type === 'ready') {
34
- worker.off('message', onMessage);
35
- worker.off('error', onError);
36
- worker.on('message', (msg) => this._onWorkerMessage(worker, msg));
37
- worker.on('exit', (code) => this._onWorkerExit(worker, code));
38
- this._idle.push(worker);
39
- resolve();
40
- }
41
- };
42
- worker.on('message', onMessage);
43
- worker.on('error', onError);
44
- });
45
-
46
- worker.postMessage({ type: 'init' });
47
-
48
- initPromises.push(initPromise);
49
- }
50
- await Promise.all(initPromises);
51
- }
52
-
53
- _clearTaskTimer(taskId) {
54
- const timer = this._taskTimers.get(taskId);
55
- if (timer) {
56
- clearTimeout(timer);
57
- this._taskTimers.delete(taskId);
58
- }
59
- }
60
-
61
- _onWorkerMessage(worker, msg) {
62
- this._taskByWorker.delete(worker);
63
- this._clearTaskTimer(msg.taskId);
64
- const cb = this._taskCallbacks.get(msg.taskId);
65
- if (cb) {
66
- this._taskCallbacks.delete(msg.taskId);
67
- if (msg.type === 'result') {
68
- cb.resolve(msg.textByProps);
69
- } else if (msg.type === 'error') {
70
- cb.reject(new Error(`Worker error: ${msg.error}\n${msg.stack}`));
71
- }
10
+ _workerPath;
11
+ _numWorkers;
12
+ _taskTimeoutMs;
13
+ _workers;
14
+ _idle;
15
+ _pendingTasks;
16
+ _taskCallbacks;
17
+ _taskTimers;
18
+ _taskByWorker;
19
+ _nextTaskId;
20
+ constructor(numWorkers, { taskTimeoutMs = DEFAULT_TASK_TIMEOUT_MS } = {}) {
21
+ this._workerPath = pathModule.join(__dirname, 'fontTracerWorker.js');
22
+ this._numWorkers = numWorkers;
23
+ this._taskTimeoutMs = taskTimeoutMs;
24
+ this._workers = [];
25
+ this._idle = [];
26
+ this._pendingTasks = [];
27
+ this._taskCallbacks = new Map();
28
+ this._taskTimers = new Map();
29
+ this._taskByWorker = new Map();
30
+ this._nextTaskId = 0;
72
31
  }
73
- // Worker is now idle, check for pending tasks
74
- this._idle.push(worker);
75
- this._dispatchPending();
76
- }
77
-
78
- _onWorkerExit(worker, code) {
79
- // Remove crashed worker from tracking
80
- const workerIdx = this._workers.indexOf(worker);
81
- if (workerIdx !== -1) {
82
- this._workers.splice(workerIdx, 1);
32
+ async init() {
33
+ const initPromises = [];
34
+ for (let i = 0; i < this._numWorkers; i++) {
35
+ const worker = new worker_threads_1.Worker(this._workerPath);
36
+ this._workers.push(worker);
37
+ const initPromise = new Promise((resolve, reject) => {
38
+ const onError = reject;
39
+ const onMessage = (msg) => {
40
+ if (msg.type === 'ready') {
41
+ worker.off('message', onMessage);
42
+ worker.off('error', onError);
43
+ worker.on('message', (msg) => this._onWorkerMessage(worker, msg));
44
+ worker.on('exit', (code) => this._onWorkerExit(worker, code));
45
+ this._idle.push(worker);
46
+ resolve();
47
+ }
48
+ };
49
+ worker.on('message', onMessage);
50
+ worker.on('error', onError);
51
+ });
52
+ worker.postMessage({ type: 'init' });
53
+ initPromises.push(initPromise);
54
+ }
55
+ await Promise.all(initPromises);
83
56
  }
84
- const idleIdx = this._idle.indexOf(worker);
85
- if (idleIdx !== -1) {
86
- this._idle.splice(idleIdx, 1);
57
+ _clearTaskTimer(taskId) {
58
+ const timer = this._taskTimers.get(taskId);
59
+ if (timer) {
60
+ clearTimeout(timer);
61
+ this._taskTimers.delete(taskId);
62
+ }
87
63
  }
88
-
89
- if (code !== 0) {
90
- // Reject the task that was in-flight on this worker
91
- const taskId = this._taskByWorker.get(worker);
92
- this._taskByWorker.delete(worker);
93
- if (taskId !== undefined) {
94
- this._clearTaskTimer(taskId);
95
- const cb = this._taskCallbacks.get(taskId);
64
+ _onWorkerMessage(worker, msg) {
65
+ if (msg.type === 'ready')
66
+ return;
67
+ this._taskByWorker.delete(worker);
68
+ this._clearTaskTimer(msg.taskId);
69
+ const cb = this._taskCallbacks.get(msg.taskId);
96
70
  if (cb) {
97
- this._taskCallbacks.delete(taskId);
98
- cb.reject(new Error(`Worker exited with code ${code}`));
99
- }
100
- }
101
-
102
- // If no workers remain, reject all pending tasks
103
- if (this._workers.length === 0) {
104
- for (const task of this._pendingTasks) {
105
- const cb = this._taskCallbacks.get(task.message.taskId);
106
- if (cb) {
107
- this._taskCallbacks.delete(task.message.taskId);
108
- cb.reject(
109
- new Error('All workers have crashed, no workers available')
110
- );
111
- }
71
+ this._taskCallbacks.delete(msg.taskId);
72
+ if (msg.type === 'result') {
73
+ cb.resolve(msg.textByProps);
74
+ }
75
+ else if (msg.type === 'error') {
76
+ cb.reject(new Error(`Worker error: ${msg.error}\n${msg.stack}`));
77
+ }
112
78
  }
113
- this._pendingTasks = [];
114
- }
79
+ // Worker is now idle, check for pending tasks
80
+ this._idle.push(worker);
81
+ this._dispatchPending();
115
82
  }
116
- }
117
-
118
- _startTaskTimer(taskId) {
119
- if (this._taskTimeoutMs <= 0) return;
120
- const timer = setTimeout(() => {
121
- this._taskTimers.delete(taskId);
122
- const cb = this._taskCallbacks.get(taskId);
123
- if (cb) {
124
- this._taskCallbacks.delete(taskId);
125
- cb.reject(
126
- new Error(
127
- `Font tracing task ${taskId} timed out after ${this._taskTimeoutMs}ms`
128
- )
129
- );
130
- }
131
- // Terminate the hung worker so it doesn't permanently consume a pool
132
- // slot. _onWorkerExit will remove it from _workers and _idle.
133
- for (const [worker, tid] of this._taskByWorker) {
134
- if (tid === taskId) {
135
- this._taskByWorker.delete(worker);
136
- worker.terminate();
137
- break;
83
+ _onWorkerExit(worker, code) {
84
+ // Remove crashed worker from tracking
85
+ const workerIdx = this._workers.indexOf(worker);
86
+ if (workerIdx !== -1) {
87
+ this._workers.splice(workerIdx, 1);
138
88
  }
139
- }
140
- }, this._taskTimeoutMs);
141
- timer.unref();
142
- this._taskTimers.set(taskId, timer);
143
- }
144
-
145
- _dispatchPending() {
146
- while (this._idle.length > 0 && this._pendingTasks.length > 0) {
147
- const worker = this._idle.pop();
148
- const task = this._pendingTasks.shift();
149
- this._taskByWorker.set(worker, task.message.taskId);
150
- try {
151
- worker.postMessage(task.message);
152
- this._startTaskTimer(task.message.taskId);
153
- } catch (err) {
154
- // postMessage can fail synchronously (e.g. structured clone error).
155
- // Return the worker to the idle pool and reject the task.
156
- this._taskByWorker.delete(worker);
157
- this._idle.push(worker);
158
- const cb = this._taskCallbacks.get(task.message.taskId);
159
- if (cb) {
160
- this._taskCallbacks.delete(task.message.taskId);
161
- cb.reject(err);
89
+ const idleIdx = this._idle.indexOf(worker);
90
+ if (idleIdx !== -1) {
91
+ this._idle.splice(idleIdx, 1);
92
+ }
93
+ if (code !== 0) {
94
+ // Reject the task that was in-flight on this worker
95
+ const taskId = this._taskByWorker.get(worker);
96
+ this._taskByWorker.delete(worker);
97
+ if (taskId !== undefined) {
98
+ this._clearTaskTimer(taskId);
99
+ const cb = this._taskCallbacks.get(taskId);
100
+ if (cb) {
101
+ this._taskCallbacks.delete(taskId);
102
+ cb.reject(new Error(`Worker exited with code ${code}`));
103
+ }
104
+ }
105
+ // If no workers remain, reject all pending tasks
106
+ if (this._workers.length === 0) {
107
+ for (const task of this._pendingTasks) {
108
+ const cb = this._taskCallbacks.get(task.message.taskId);
109
+ if (cb) {
110
+ this._taskCallbacks.delete(task.message.taskId);
111
+ cb.reject(new Error('All workers have crashed, no workers available'));
112
+ }
113
+ }
114
+ this._pendingTasks = [];
115
+ }
162
116
  }
163
- }
164
117
  }
165
- }
166
-
167
- /**
168
- * Run fontTracer on the given HTML text + stylesheets in a worker.
169
- * Returns a promise that resolves to textByProps.
170
- */
171
- trace(htmlText, stylesheetsWithPredicates) {
172
- const taskId = this._nextTaskId++;
173
- // Serialize stylesheets to plain data asset objects contain DOM/PostCSS
174
- // trees that cannot be transferred via structured clone.
175
- const serializedStylesheets = stylesheetsWithPredicates.map((entry) => ({
176
- text: entry.text || (entry.asset && entry.asset.text) || '',
177
- predicates: entry.predicates || {},
178
- }));
179
- const message = {
180
- type: 'trace',
181
- taskId,
182
- htmlText,
183
- stylesheetsWithPredicates: serializedStylesheets,
184
- };
185
-
186
- return new Promise((resolve, reject) => {
187
- this._taskCallbacks.set(taskId, { resolve, reject });
188
- this._pendingTasks.push({ message });
189
- this._dispatchPending();
190
- });
191
- }
192
-
193
- async destroy() {
194
- // Clear all task timers
195
- for (const timer of this._taskTimers.values()) {
196
- clearTimeout(timer);
118
+ _startTaskTimer(taskId) {
119
+ if (this._taskTimeoutMs <= 0)
120
+ return;
121
+ const timer = setTimeout(() => {
122
+ this._taskTimers.delete(taskId);
123
+ const cb = this._taskCallbacks.get(taskId);
124
+ if (cb) {
125
+ this._taskCallbacks.delete(taskId);
126
+ cb.reject(new Error(`Font tracing task ${taskId} timed out after ${this._taskTimeoutMs}ms`));
127
+ }
128
+ // Terminate the hung worker so it doesn't permanently consume a pool
129
+ // slot. _onWorkerExit will remove it from _workers and _idle.
130
+ for (const [worker, tid] of this._taskByWorker) {
131
+ if (tid === taskId) {
132
+ this._taskByWorker.delete(worker);
133
+ worker.terminate();
134
+ break;
135
+ }
136
+ }
137
+ }, this._taskTimeoutMs);
138
+ timer.unref();
139
+ this._taskTimers.set(taskId, timer);
197
140
  }
198
- this._taskTimers.clear();
199
-
200
- // Reject any tasks still waiting in the queue
201
- for (const task of this._pendingTasks) {
202
- const cb = this._taskCallbacks.get(task.message.taskId);
203
- if (cb) {
204
- this._taskCallbacks.delete(task.message.taskId);
205
- cb.reject(new Error('Worker pool destroyed'));
206
- }
141
+ _dispatchPending() {
142
+ while (this._idle.length > 0 && this._pendingTasks.length > 0) {
143
+ const worker = this._idle.pop();
144
+ const task = this._pendingTasks.shift();
145
+ this._taskByWorker.set(worker, task.message.taskId);
146
+ try {
147
+ worker.postMessage(task.message);
148
+ this._startTaskTimer(task.message.taskId);
149
+ }
150
+ catch (err) {
151
+ // postMessage can fail synchronously (e.g. structured clone error).
152
+ // Return the worker to the idle pool and reject the task.
153
+ this._taskByWorker.delete(worker);
154
+ this._idle.push(worker);
155
+ const cb = this._taskCallbacks.get(task.message.taskId);
156
+ if (cb) {
157
+ this._taskCallbacks.delete(task.message.taskId);
158
+ cb.reject(err);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ /**
164
+ * Run fontTracer on the given HTML text + stylesheets in a worker.
165
+ * Returns a promise that resolves to textByProps.
166
+ */
167
+ // The pool is payload-agnostic; callers (subsetFonts.ts) interpret the
168
+ // returned textByProps according to font-tracer's contract.
169
+ trace(htmlText, stylesheetsWithPredicates
170
+ // eslint-disable-next-line no-restricted-syntax
171
+ ) {
172
+ const taskId = this._nextTaskId++;
173
+ // Serialize stylesheets to plain data — asset objects contain DOM/PostCSS
174
+ // trees that cannot be transferred via structured clone.
175
+ const serializedStylesheets = stylesheetsWithPredicates.map((entry) => ({
176
+ text: entry.text || (entry.asset && entry.asset.text) || '',
177
+ predicates: entry.predicates || {},
178
+ }));
179
+ const message = {
180
+ type: 'trace',
181
+ taskId,
182
+ htmlText,
183
+ stylesheetsWithPredicates: serializedStylesheets,
184
+ };
185
+ return new Promise((resolve, reject) => {
186
+ this._taskCallbacks.set(taskId, { resolve, reject });
187
+ this._pendingTasks.push({ message });
188
+ this._dispatchPending();
189
+ });
207
190
  }
208
- this._pendingTasks = [];
209
-
210
- // Reject any in-flight tasks still assigned to workers.
211
- // Clear _taskByWorker before terminate() so _onWorkerExit won't double-reject.
212
- for (const [, taskId] of this._taskByWorker) {
213
- const cb = this._taskCallbacks.get(taskId);
214
- if (cb) {
215
- this._taskCallbacks.delete(taskId);
216
- cb.reject(new Error('Worker pool destroyed'));
217
- }
191
+ async destroy() {
192
+ // Clear all task timers
193
+ for (const timer of this._taskTimers.values()) {
194
+ clearTimeout(timer);
195
+ }
196
+ this._taskTimers.clear();
197
+ // Reject any tasks still waiting in the queue
198
+ for (const task of this._pendingTasks) {
199
+ const cb = this._taskCallbacks.get(task.message.taskId);
200
+ if (cb) {
201
+ this._taskCallbacks.delete(task.message.taskId);
202
+ cb.reject(new Error('Worker pool destroyed'));
203
+ }
204
+ }
205
+ this._pendingTasks = [];
206
+ // Reject any in-flight tasks still assigned to workers.
207
+ // Clear _taskByWorker before terminate() so _onWorkerExit won't double-reject.
208
+ for (const [, taskId] of this._taskByWorker) {
209
+ const cb = this._taskCallbacks.get(taskId);
210
+ if (cb) {
211
+ this._taskCallbacks.delete(taskId);
212
+ cb.reject(new Error('Worker pool destroyed'));
213
+ }
214
+ }
215
+ this._taskByWorker.clear();
216
+ // Terminate workers with a 5-second timeout to prevent hanging
217
+ const TERMINATE_TIMEOUT_MS = 5000;
218
+ await Promise.all(this._workers.map((w) => Promise.race([
219
+ w.terminate(),
220
+ new Promise((resolve) => {
221
+ const timer = setTimeout(resolve, TERMINATE_TIMEOUT_MS);
222
+ timer.unref();
223
+ }),
224
+ ])));
225
+ this._workers = [];
226
+ this._idle = [];
218
227
  }
219
- this._taskByWorker.clear();
220
-
221
- // Terminate workers with a 5-second timeout to prevent hanging
222
- const TERMINATE_TIMEOUT_MS = 5000;
223
- await Promise.all(
224
- this._workers.map((w) =>
225
- Promise.race([
226
- w.terminate(),
227
- new Promise((resolve) => {
228
- const timer = setTimeout(resolve, TERMINATE_TIMEOUT_MS);
229
- timer.unref();
230
- }),
231
- ])
232
- )
233
- );
234
- this._workers = [];
235
- this._idle = [];
236
- }
237
228
  }
238
-
239
229
  module.exports = FontTracerPool;
230
+ //# sourceMappingURL=FontTracerPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontTracerPool.js","sourceRoot":"","sources":["../src/FontTracerPool.ts"],"names":[],"mappings":";AAAA,mCAAoC;AACpC,mDAAwC;AAExC;;;GAGG;AACH,MAAM,uBAAuB,GAAG,MAAM,CAAC;AA2DvC,MAAM,cAAc;IACV,WAAW,CAAS;IACpB,WAAW,CAAS;IACpB,cAAc,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C,uBAAuB,CAAC,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAE3B,+DAA+D;QAC/D,MAAM,oBAAoB,GAAG,IAAI,CAAC;QAClC,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtB,OAAO,CAAC,IAAI,CAAC;YACX,CAAC,CAAC,SAAS,EAAE;YACb,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;gBACxD,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC,CAAC;SACH,CAAC,CACH,CACF,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AAED,iBAAS,cAAc,CAAC"}
package/lib/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js CHANGED
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env node
2
-
3
- const { yargs, help, ...options } = require('./parseCommandLineOptions')();
4
-
5
- require('@gustavnikolaj/async-main-wrap')(require('./subfont'), {
6
- processError(err) {
7
- yargs.showHelp();
8
- if (err.name === 'UsageError') {
9
- // Avoid rendering a stack trace for the wrong usage errors
10
- err.customOutput = err.message;
11
- }
12
- return err;
13
- },
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const parseCommandLineOptions = require("./parseCommandLineOptions");
5
+ const asyncMainWrap = require("@gustavnikolaj/async-main-wrap");
6
+ const subfont = require("./subfont");
7
+ const { yargs, help: _help, ...options } = parseCommandLineOptions();
8
+ asyncMainWrap(subfont, {
9
+ processError(err) {
10
+ yargs.showHelp();
11
+ if (err.name === 'UsageError') {
12
+ err.customOutput = err.message;
13
+ }
14
+ return err;
15
+ },
14
16
  })(options, console);
17
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qEAAsE;AACtE,gEAAiE;AACjE,qCAAsC;AAEtC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,uBAAuB,EAAE,CAAC;AAIrE,aAAa,CAAC,OAAO,EAAE;IACrB,YAAY,CAAC,GAA0B;QACrC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC9B,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import AssetGraph = require('assetgraph');
2
+ declare class UsageError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ interface SubfontOptions {
6
+ root?: string;
7
+ canonicalRoot?: string;
8
+ output?: string;
9
+ debug?: boolean;
10
+ dryRun?: boolean;
11
+ silent?: boolean;
12
+ inlineCss?: boolean;
13
+ fontDisplay?: string;
14
+ inPlace?: boolean;
15
+ inputFiles?: Array<string | URL>;
16
+ recursive?: boolean;
17
+ relativeUrls?: boolean;
18
+ dynamic?: boolean;
19
+ fallbacks?: boolean;
20
+ text?: string;
21
+ sourceMaps?: boolean;
22
+ concurrency?: number;
23
+ chromeFlags?: string[];
24
+ cache?: boolean | string;
25
+ strict?: boolean;
26
+ }
27
+ interface SubfontFn {
28
+ (options: SubfontOptions, console?: Console): Promise<InstanceType<typeof AssetGraph>>;
29
+ UsageError: typeof UsageError;
30
+ }
31
+ declare const subfont: SubfontFn;
32
+ export = subfont;
33
+ //# sourceMappingURL=subfont.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subfont.d.ts","sourceRoot":"","sources":["../src/subfont.ts"],"names":[],"mappings":"AAKA,OAAO,UAAU,GAAG,QAAQ,YAAY,CAAC,CAAC;AAQ1C,cAAM,UAAW,SAAQ,KAAK;gBAChB,OAAO,EAAE,MAAM;CAI5B;AAED,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAqBD,UAAU,SAAS;IACjB,CACE,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,YAA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