@formepdf/core 0.9.2 → 0.10.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,479 @@
1
+ /* @ts-self-types="./forme.d.ts" */
2
+
3
+ /**
4
+ * Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
5
+ * @param {Uint8Array} pdf_bytes
6
+ * @param {string} config_json
7
+ * @returns {Uint8Array}
8
+ */
9
+ export function certify_pdf(pdf_bytes, config_json) {
10
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
+ const len1 = WASM_VECTOR_LEN;
14
+ const ret = wasm.certify_pdf(ptr0, len0, ptr1, len1);
15
+ if (ret[3]) {
16
+ throw takeFromExternrefTable0(ret[2]);
17
+ }
18
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
19
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
20
+ return v3;
21
+ }
22
+
23
+ /**
24
+ * Find text regions matching patterns in a PDF.
25
+ * Returns JSON string of Vec<RedactionRegion>.
26
+ * @param {Uint8Array} pdf_bytes
27
+ * @param {string} patterns_json
28
+ * @returns {string}
29
+ */
30
+ export function find_text_regions(pdf_bytes, patterns_json) {
31
+ let deferred4_0;
32
+ let deferred4_1;
33
+ try {
34
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
35
+ const len0 = WASM_VECTOR_LEN;
36
+ const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
37
+ const len1 = WASM_VECTOR_LEN;
38
+ const ret = wasm.find_text_regions(ptr0, len0, ptr1, len1);
39
+ var ptr3 = ret[0];
40
+ var len3 = ret[1];
41
+ if (ret[3]) {
42
+ ptr3 = 0; len3 = 0;
43
+ throw takeFromExternrefTable0(ret[2]);
44
+ }
45
+ deferred4_0 = ptr3;
46
+ deferred4_1 = len3;
47
+ return getStringFromWasm0(ptr3, len3);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
50
+ }
51
+ }
52
+
53
+ export function init_panic_hook() {
54
+ wasm.init_panic_hook();
55
+ }
56
+
57
+ /**
58
+ * Merge multiple PDFs into a single document.
59
+ * Accepts a JSON array of base64-encoded PDF strings.
60
+ * @param {string} pdfs_json
61
+ * @returns {Uint8Array}
62
+ */
63
+ export function merge_pdfs(pdfs_json) {
64
+ const ptr0 = passStringToWasm0(pdfs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.merge_pdfs(ptr0, len0);
67
+ if (ret[3]) {
68
+ throw takeFromExternrefTable0(ret[2]);
69
+ }
70
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
71
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
72
+ return v2;
73
+ }
74
+
75
+ /**
76
+ * Redact regions of a PDF by overlaying opaque rectangles.
77
+ * @param {Uint8Array} pdf_bytes
78
+ * @param {string} redactions_json
79
+ * @returns {Uint8Array}
80
+ */
81
+ export function redact_pdf(pdf_bytes, redactions_json) {
82
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ptr1 = passStringToWasm0(redactions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
85
+ const len1 = WASM_VECTOR_LEN;
86
+ const ret = wasm.redact_pdf(ptr0, len0, ptr1, len1);
87
+ if (ret[3]) {
88
+ throw takeFromExternrefTable0(ret[2]);
89
+ }
90
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
91
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
92
+ return v3;
93
+ }
94
+
95
+ /**
96
+ * Redact text matching patterns from a PDF.
97
+ * @param {Uint8Array} pdf_bytes
98
+ * @param {string} patterns_json
99
+ * @returns {Uint8Array}
100
+ */
101
+ export function redact_text(pdf_bytes, patterns_json) {
102
+ const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
103
+ const len0 = WASM_VECTOR_LEN;
104
+ const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
105
+ const len1 = WASM_VECTOR_LEN;
106
+ const ret = wasm.redact_text(ptr0, len0, ptr1, len1);
107
+ if (ret[3]) {
108
+ throw takeFromExternrefTable0(ret[2]);
109
+ }
110
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
111
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
112
+ return v3;
113
+ }
114
+
115
+ /**
116
+ * @param {string} json
117
+ * @returns {Uint8Array}
118
+ */
119
+ export function render_pdf(json) {
120
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
121
+ const len0 = WASM_VECTOR_LEN;
122
+ const ret = wasm.render_pdf(ptr0, len0);
123
+ if (ret[3]) {
124
+ throw takeFromExternrefTable0(ret[2]);
125
+ }
126
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
127
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
128
+ return v2;
129
+ }
130
+
131
+ /**
132
+ * @param {string} json
133
+ * @returns {any}
134
+ */
135
+ export function render_pdf_with_layout(json) {
136
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ret = wasm.render_pdf_with_layout(ptr0, len0);
139
+ if (ret[2]) {
140
+ throw takeFromExternrefTable0(ret[1]);
141
+ }
142
+ return takeFromExternrefTable0(ret[0]);
143
+ }
144
+
145
+ /**
146
+ * @param {string} template_json
147
+ * @param {string} data_json
148
+ * @returns {Uint8Array}
149
+ */
150
+ export function render_template_pdf(template_json, data_json) {
151
+ const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154
+ const len1 = WASM_VECTOR_LEN;
155
+ const ret = wasm.render_template_pdf(ptr0, len0, ptr1, len1);
156
+ if (ret[3]) {
157
+ throw takeFromExternrefTable0(ret[2]);
158
+ }
159
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
160
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
161
+ return v3;
162
+ }
163
+
164
+ /**
165
+ * @param {string} template_json
166
+ * @param {string} data_json
167
+ * @returns {any}
168
+ */
169
+ export function render_template_pdf_with_layout(template_json, data_json) {
170
+ const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
171
+ const len0 = WASM_VECTOR_LEN;
172
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
173
+ const len1 = WASM_VECTOR_LEN;
174
+ const ret = wasm.render_template_pdf_with_layout(ptr0, len0, ptr1, len1);
175
+ if (ret[2]) {
176
+ throw takeFromExternrefTable0(ret[1]);
177
+ }
178
+ return takeFromExternrefTable0(ret[0]);
179
+ }
180
+
181
+ function __wbg_get_imports() {
182
+ const import0 = {
183
+ __proto__: null,
184
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
185
+ const ret = String(arg1);
186
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ const len1 = WASM_VECTOR_LEN;
188
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
189
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
190
+ },
191
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
192
+ throw new Error(getStringFromWasm0(arg0, arg1));
193
+ },
194
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
195
+ let deferred0_0;
196
+ let deferred0_1;
197
+ try {
198
+ deferred0_0 = arg0;
199
+ deferred0_1 = arg1;
200
+ console.error(getStringFromWasm0(arg0, arg1));
201
+ } finally {
202
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
203
+ }
204
+ },
205
+ __wbg_new_361308b2356cecd0: function() {
206
+ const ret = new Object();
207
+ return ret;
208
+ },
209
+ __wbg_new_3eb36ae241fe6f44: function() {
210
+ const ret = new Array();
211
+ return ret;
212
+ },
213
+ __wbg_new_8a6f238a6ece86ea: function() {
214
+ const ret = new Error();
215
+ return ret;
216
+ },
217
+ __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
218
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
219
+ return ret;
220
+ },
221
+ __wbg_now_a3af9a2f4bbaa4d1: function() {
222
+ const ret = Date.now();
223
+ return ret;
224
+ },
225
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
226
+ arg0[arg1] = arg2;
227
+ },
228
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
229
+ const ret = Reflect.set(arg0, arg1, arg2);
230
+ return ret;
231
+ }, arguments); },
232
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
233
+ arg0[arg1 >>> 0] = arg2;
234
+ },
235
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
236
+ const ret = arg1.stack;
237
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
+ const len1 = WASM_VECTOR_LEN;
239
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
240
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
241
+ },
242
+ __wbindgen_cast_0000000000000001: function(arg0) {
243
+ // Cast intrinsic for `F64 -> Externref`.
244
+ const ret = arg0;
245
+ return ret;
246
+ },
247
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
248
+ // Cast intrinsic for `Ref(String) -> Externref`.
249
+ const ret = getStringFromWasm0(arg0, arg1);
250
+ return ret;
251
+ },
252
+ __wbindgen_init_externref_table: function() {
253
+ const table = wasm.__wbindgen_externrefs;
254
+ const offset = table.grow(4);
255
+ table.set(0, undefined);
256
+ table.set(offset + 0, undefined);
257
+ table.set(offset + 1, null);
258
+ table.set(offset + 2, true);
259
+ table.set(offset + 3, false);
260
+ },
261
+ };
262
+ return {
263
+ __proto__: null,
264
+ "./forme_bg.js": import0,
265
+ };
266
+ }
267
+
268
+ function addToExternrefTable0(obj) {
269
+ const idx = wasm.__externref_table_alloc();
270
+ wasm.__wbindgen_externrefs.set(idx, obj);
271
+ return idx;
272
+ }
273
+
274
+ function getArrayU8FromWasm0(ptr, len) {
275
+ ptr = ptr >>> 0;
276
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
277
+ }
278
+
279
+ let cachedDataViewMemory0 = null;
280
+ function getDataViewMemory0() {
281
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
282
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
283
+ }
284
+ return cachedDataViewMemory0;
285
+ }
286
+
287
+ function getStringFromWasm0(ptr, len) {
288
+ ptr = ptr >>> 0;
289
+ return decodeText(ptr, len);
290
+ }
291
+
292
+ let cachedUint8ArrayMemory0 = null;
293
+ function getUint8ArrayMemory0() {
294
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
295
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
296
+ }
297
+ return cachedUint8ArrayMemory0;
298
+ }
299
+
300
+ function handleError(f, args) {
301
+ try {
302
+ return f.apply(this, args);
303
+ } catch (e) {
304
+ const idx = addToExternrefTable0(e);
305
+ wasm.__wbindgen_exn_store(idx);
306
+ }
307
+ }
308
+
309
+ function passArray8ToWasm0(arg, malloc) {
310
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
311
+ getUint8ArrayMemory0().set(arg, ptr / 1);
312
+ WASM_VECTOR_LEN = arg.length;
313
+ return ptr;
314
+ }
315
+
316
+ function passStringToWasm0(arg, malloc, realloc) {
317
+ if (realloc === undefined) {
318
+ const buf = cachedTextEncoder.encode(arg);
319
+ const ptr = malloc(buf.length, 1) >>> 0;
320
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
321
+ WASM_VECTOR_LEN = buf.length;
322
+ return ptr;
323
+ }
324
+
325
+ let len = arg.length;
326
+ let ptr = malloc(len, 1) >>> 0;
327
+
328
+ const mem = getUint8ArrayMemory0();
329
+
330
+ let offset = 0;
331
+
332
+ for (; offset < len; offset++) {
333
+ const code = arg.charCodeAt(offset);
334
+ if (code > 0x7F) break;
335
+ mem[ptr + offset] = code;
336
+ }
337
+ if (offset !== len) {
338
+ if (offset !== 0) {
339
+ arg = arg.slice(offset);
340
+ }
341
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
342
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
343
+ const ret = cachedTextEncoder.encodeInto(arg, view);
344
+
345
+ offset += ret.written;
346
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
347
+ }
348
+
349
+ WASM_VECTOR_LEN = offset;
350
+ return ptr;
351
+ }
352
+
353
+ function takeFromExternrefTable0(idx) {
354
+ const value = wasm.__wbindgen_externrefs.get(idx);
355
+ wasm.__externref_table_dealloc(idx);
356
+ return value;
357
+ }
358
+
359
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
360
+ cachedTextDecoder.decode();
361
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
362
+ let numBytesDecoded = 0;
363
+ function decodeText(ptr, len) {
364
+ numBytesDecoded += len;
365
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
366
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
367
+ cachedTextDecoder.decode();
368
+ numBytesDecoded = len;
369
+ }
370
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
371
+ }
372
+
373
+ const cachedTextEncoder = new TextEncoder();
374
+
375
+ if (!('encodeInto' in cachedTextEncoder)) {
376
+ cachedTextEncoder.encodeInto = function (arg, view) {
377
+ const buf = cachedTextEncoder.encode(arg);
378
+ view.set(buf);
379
+ return {
380
+ read: arg.length,
381
+ written: buf.length
382
+ };
383
+ };
384
+ }
385
+
386
+ let WASM_VECTOR_LEN = 0;
387
+
388
+ let wasmModule, wasm;
389
+ function __wbg_finalize_init(instance, module) {
390
+ wasm = instance.exports;
391
+ wasmModule = module;
392
+ cachedDataViewMemory0 = null;
393
+ cachedUint8ArrayMemory0 = null;
394
+ wasm.__wbindgen_start();
395
+ return wasm;
396
+ }
397
+
398
+ async function __wbg_load(module, imports) {
399
+ if (typeof Response === 'function' && module instanceof Response) {
400
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
401
+ try {
402
+ return await WebAssembly.instantiateStreaming(module, imports);
403
+ } catch (e) {
404
+ const validResponse = module.ok && expectedResponseType(module.type);
405
+
406
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
407
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
408
+
409
+ } else { throw e; }
410
+ }
411
+ }
412
+
413
+ const bytes = await module.arrayBuffer();
414
+ return await WebAssembly.instantiate(bytes, imports);
415
+ } else {
416
+ const instance = await WebAssembly.instantiate(module, imports);
417
+
418
+ if (instance instanceof WebAssembly.Instance) {
419
+ return { instance, module };
420
+ } else {
421
+ return instance;
422
+ }
423
+ }
424
+
425
+ function expectedResponseType(type) {
426
+ switch (type) {
427
+ case 'basic': case 'cors': case 'default': return true;
428
+ }
429
+ return false;
430
+ }
431
+ }
432
+
433
+ function initSync(module) {
434
+ if (wasm !== undefined) return wasm;
435
+
436
+
437
+ if (module !== undefined) {
438
+ if (Object.getPrototypeOf(module) === Object.prototype) {
439
+ ({module} = module)
440
+ } else {
441
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
442
+ }
443
+ }
444
+
445
+ const imports = __wbg_get_imports();
446
+ if (!(module instanceof WebAssembly.Module)) {
447
+ module = new WebAssembly.Module(module);
448
+ }
449
+ const instance = new WebAssembly.Instance(module, imports);
450
+ return __wbg_finalize_init(instance, module);
451
+ }
452
+
453
+ async function __wbg_init(module_or_path) {
454
+ if (wasm !== undefined) return wasm;
455
+
456
+
457
+ if (module_or_path !== undefined) {
458
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
459
+ ({module_or_path} = module_or_path)
460
+ } else {
461
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
462
+ }
463
+ }
464
+
465
+ if (module_or_path === undefined) {
466
+ module_or_path = new URL('forme_bg.wasm', import.meta.url);
467
+ }
468
+ const imports = __wbg_get_imports();
469
+
470
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
471
+ module_or_path = fetch(module_or_path);
472
+ }
473
+
474
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
475
+
476
+ return __wbg_finalize_init(instance, module);
477
+ }
478
+
479
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,21 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const certify_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const find_text_regions: (a: number, b: number, c: number, d: number) => [number, number, number, number];
6
+ export const merge_pdfs: (a: number, b: number) => [number, number, number, number];
7
+ export const redact_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
+ export const redact_text: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const render_pdf: (a: number, b: number) => [number, number, number, number];
10
+ export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
11
+ export const render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
12
+ export const render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
13
+ export const init_panic_hook: () => void;
14
+ export const __wbindgen_malloc: (a: number, b: number) => number;
15
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
17
+ export const __wbindgen_exn_store: (a: number) => void;
18
+ export const __externref_table_alloc: () => number;
19
+ export const __wbindgen_externrefs: WebAssembly.Table;
20
+ export const __externref_table_dealloc: (a: number) => void;
21
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "forme-pdf",
3
+ "type": "module",
4
+ "description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
5
+ "version": "0.10.0",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/formepdf/forme"
10
+ },
11
+ "files": [
12
+ "forme_bg.wasm",
13
+ "forme.js",
14
+ "forme.d.ts"
15
+ ],
16
+ "main": "forme.js",
17
+ "homepage": "https://formepdf.com",
18
+ "types": "forme.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
21
+ ],
22
+ "keywords": [
23
+ "pdf",
24
+ "wasm",
25
+ "layout",
26
+ "document",
27
+ "report"
28
+ ]
29
+ }
@@ -0,0 +1,62 @@
1
+ #!/bin/bash
2
+ # Assert the @formepdf/core tarball ships every file the package's own
3
+ # entry points import. Catches the failure mode that shipped in 0.10.0
4
+ # — wasm-pack writes a `.gitignore` containing `*` inside each output
5
+ # dir, and `npm publish` silently drops the directory contents. The
6
+ # `build:wasm` script removes those gitignores, but if a future change
7
+ # adds a new pkg-* dir and forgets to add the matching `rm`, this
8
+ # script fails loudly during `npm publish` (it's wired up via
9
+ # `prepublishOnly`).
10
+ #
11
+ # Also runs as part of CI so we catch the regression at PR time, not
12
+ # release time.
13
+ set -euo pipefail
14
+
15
+ cd "$(dirname "$0")/.."
16
+
17
+ # Ask npm what it *would* publish. --ignore-scripts is critical: we're
18
+ # called from prepublishOnly, and npm pack itself fires prepublishOnly,
19
+ # which would recurse forever (or silently fail with an empty tarball
20
+ # name and a confusing `tar: Failed to open ''` error). --dry-run skips
21
+ # writing a real .tgz to disk. --json gives us structured output we
22
+ # don't need to parse out of human-readable notices.
23
+ FILES=$(npm pack --dry-run --json --ignore-scripts \
24
+ | sed -n 's/^[[:space:]]*"path": "\([^"]*\)".*/package\/\1/p')
25
+
26
+ REQUIRED=(
27
+ package/dist/index.js
28
+ package/dist/browser.js
29
+ package/dist/worker.js
30
+ package/pkg/forme.js
31
+ package/pkg/forme_bg.js
32
+ package/pkg/forme_bg.wasm
33
+ package/pkg-web/forme.js
34
+ package/pkg-web/forme_bg.wasm
35
+ package/pkg-node/forme.js
36
+ package/pkg-node/forme_bg.wasm
37
+ package/package.json
38
+ )
39
+
40
+ missing=0
41
+ for f in "${REQUIRED[@]}"; do
42
+ if ! printf '%s\n' "$FILES" | grep -qx "$f"; then
43
+ echo "MISSING from tarball: $f"
44
+ missing=1
45
+ fi
46
+ done
47
+
48
+ # Stray .gitignore inside any published pkg dir means wasm-pack's output
49
+ # slipped through — exactly the 0.10.0 regression.
50
+ if printf '%s\n' "$FILES" | grep -E '/pkg(-web|-node)?/\.gitignore$' >/dev/null; then
51
+ echo "Stray .gitignore inside a published pkg* dir — npm publish will drop directory contents. Add it to the build:wasm cleanup step."
52
+ printf '%s\n' "$FILES" | grep -E '/pkg(-web|-node)?/\.gitignore$' >&2
53
+ missing=1
54
+ fi
55
+
56
+ if [ "$missing" -ne 0 ]; then
57
+ echo
58
+ echo "Tarball is missing files. Refusing to publish."
59
+ exit 1
60
+ fi
61
+
62
+ echo "OK: tarball has all required files and no stray .gitignore files."