From 3c703fe93d5df1c8601d5b4c78992806b80b5a73 Mon Sep 17 00:00:00 2001 From: Modesty Zhang Date: Tue, 30 Apr 2024 18:17:29 -0700 Subject: [PATCH] build: restore default export, also minify the output bundles (#341) * build: fix issues of v3.1.0, bring back the default export of PDFParser to avoid breaking changes * build: minify the output bundles * build: keep test as jest tests --- .npmignore | 2 +- lib/p2jcmd.js | 10 +- lib/p2jcmdarg.js | 3 +- package-lock.json | 236 ++++++++++++++++++++++++++++++++-------------- package.json | 6 +- pdfparser.js | 50 +++++++--- readme.md | 74 ++++++++------- rollup.config.js | 38 ++++---- test/_test_.cjs | 2 +- 9 files changed, 271 insertions(+), 150 deletions(-) diff --git a/.npmignore b/.npmignore index 9d9ce474..1484384c 100644 --- a/.npmignore +++ b/.npmignore @@ -8,6 +8,6 @@ node_modules/ target/ .gitignore -test +test/ .vscode/ diff --git a/lib/p2jcmd.js b/lib/p2jcmd.js index 5a59c3d0..86edf78e 100644 --- a/lib/p2jcmd.js +++ b/lib/p2jcmd.js @@ -2,13 +2,9 @@ import nodeUtil from "util"; import fs from "fs"; import path from "path"; -import { - PDFParser, - ParserStream, - StringifyStream, - pkInfo, - _PARSER_SIG as _PRO_TIMER, -} from "../dist/pdfparser.js"; +import PDFParser from "../dist/pdfparser.js"; + +const { ParserStream, StringifyStream, pkInfo, _PARSER_SIG: _PRO_TIMER } = PDFParser; import { yargs } from "./p2jcmdarg.js"; diff --git a/lib/p2jcmdarg.js b/lib/p2jcmdarg.js index aaf4c0e0..83272582 100644 --- a/lib/p2jcmdarg.js +++ b/lib/p2jcmdarg.js @@ -1,4 +1,5 @@ -import { pkInfo, _PARSER_SIG as _PRO_TIMER } from "../dist/pdfparser.js"; +import PDFParser from "../dist/pdfparser.js"; +const { pkInfo, _PARSER_SIG: _PRO_TIMER } = PDFParser; class CLIArgParser { args = []; diff --git a/package-lock.json b/package-lock.json index 94b61b61..2d83e5cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,9 +21,10 @@ "@rollup/plugin-commonjs": "^25.0.4", "@rollup/plugin-node-resolve": "^15.2.1", "@rollup/plugin-replace": "^5.0.2", + "@rollup/plugin-terser": "^0.4.4", "@types/node": "^20.12.7", "jest": "^29.7.0", - "rollup": "^4.17.0", + "rollup": "^4.17.2", "rollup-plugin-inject": "^3.0.2", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-sourcemaps": "^0.6.3" @@ -975,6 +976,16 @@ "node": ">=6.0.0" } }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", + "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.25" + } + }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", @@ -1062,6 +1073,28 @@ } } }, + "node_modules/@rollup/plugin-terser": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz", + "integrity": "sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==", + "dev": true, + "dependencies": { + "serialize-javascript": "^6.0.1", + "smob": "^1.0.0", + "terser": "^5.17.4" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", @@ -1085,9 +1118,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.17.1.tgz", - "integrity": "sha512-P6Wg856Ou/DLpR+O0ZLneNmrv7QpqBg+hK4wE05ijbC/t349BRfMfx+UFj5Ha3fCFopIa6iSZlpdaB4agkWp2Q==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.17.2.tgz", + "integrity": "sha512-NM0jFxY8bB8QLkoKxIQeObCaDlJKewVlIEkuyYKm5An1tdVZ966w2+MPQ2l8LBZLjR+SgyV+nRkTIunzOYBMLQ==", "cpu": [ "arm" ], @@ -1098,9 +1131,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.17.1.tgz", - "integrity": "sha512-piwZDjuW2WiHr05djVdUkrG5JbjnGbtx8BXQchYCMfib/nhjzWoiScelZ+s5IJI7lecrwSxHCzW026MWBL+oJQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.17.2.tgz", + "integrity": "sha512-yeX/Usk7daNIVwkq2uGoq2BYJKZY1JfyLTaHO/jaiSwi/lsf8fTFoQW/n6IdAsx5tx+iotu2zCJwz8MxI6D/Bw==", "cpu": [ "arm64" ], @@ -1111,9 +1144,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.17.1.tgz", - "integrity": "sha512-LsZXXIsN5Q460cKDT4Y+bzoPDhBmO5DTr7wP80d+2EnYlxSgkwdPfE3hbE+Fk8dtya+8092N9srjBTJ0di8RIA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.17.2.tgz", + "integrity": "sha512-kcMLpE6uCwls023+kknm71ug7MZOrtXo+y5p/tsg6jltpDtgQY1Eq5sGfHcQfb+lfuKwhBmEURDga9N0ol4YPw==", "cpu": [ "arm64" ], @@ -1124,9 +1157,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.17.1.tgz", - "integrity": "sha512-S7TYNQpWXB9APkxu/SLmYHezWwCoZRA9QLgrDeml+SR2A1LLPD2DBUdUlvmCF7FUpRMKvbeeWky+iizQj65Etw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.17.2.tgz", + "integrity": "sha512-AtKwD0VEx0zWkL0ZjixEkp5tbNLzX+FCqGG1SvOu993HnSz4qDI6S4kGzubrEJAljpVkhRSlg5bzpV//E6ysTQ==", "cpu": [ "x64" ], @@ -1137,9 +1170,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.17.1.tgz", - "integrity": "sha512-Lq2JR5a5jsA5um2ZoLiXXEaOagnVyCpCW7xvlcqHC7y46tLwTEgUSTM3a2TfmmTMmdqv+jknUioWXlmxYxE9Yw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.17.2.tgz", + "integrity": "sha512-3reX2fUHqN7sffBNqmEyMQVj/CKhIHZd4y631duy0hZqI8Qoqf6lTtmAKvJFYa6bhU95B1D0WgzHkmTg33In0A==", "cpu": [ "arm" ], @@ -1150,9 +1183,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.17.1.tgz", - "integrity": "sha512-9BfzwyPNV0IizQoR+5HTNBGkh1KXE8BqU0DBkqMngmyFW7BfuIZyMjQ0s6igJEiPSBvT3ZcnIFohZ19OqjhDPg==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.17.2.tgz", + "integrity": "sha512-uSqpsp91mheRgw96xtyAGP9FW5ChctTFEoXP0r5FAzj/3ZRv3Uxjtc7taRQSaQM/q85KEKjKsZuiZM3GyUivRg==", "cpu": [ "arm" ], @@ -1163,9 +1196,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.17.1.tgz", - "integrity": "sha512-e2uWaoxo/rtzA52OifrTSXTvJhAXb0XeRkz4CdHBK2KtxrFmuU/uNd544Ogkpu938BzEfvmWs8NZ8Axhw33FDw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.17.2.tgz", + "integrity": "sha512-EMMPHkiCRtE8Wdk3Qhtciq6BndLtstqZIroHiiGzB3C5LDJmIZcSzVtLRbwuXuUft1Cnv+9fxuDtDxz3k3EW2A==", "cpu": [ "arm64" ], @@ -1176,9 +1209,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.17.1.tgz", - "integrity": "sha512-ekggix/Bc/d/60H1Mi4YeYb/7dbal1kEDZ6sIFVAE8pUSx7PiWeEh+NWbL7bGu0X68BBIkgF3ibRJe1oFTksQQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.17.2.tgz", + "integrity": "sha512-NMPylUUZ1i0z/xJUIx6VUhISZDRT+uTWpBcjdv0/zkp7b/bQDF+NfnfdzuTiB1G6HTodgoFa93hp0O1xl+/UbA==", "cpu": [ "arm64" ], @@ -1189,9 +1222,9 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.17.1.tgz", - "integrity": "sha512-UGV0dUo/xCv4pkr/C8KY7XLFwBNnvladt8q+VmdKrw/3RUd3rD0TptwjisvE2TTnnlENtuY4/PZuoOYRiGp8Gw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.17.2.tgz", + "integrity": "sha512-T19My13y8uYXPw/L/k0JYaX1fJKFT/PWdXiHr8mTbXWxjVF1t+8Xl31DgBBvEKclw+1b00Chg0hxE2O7bTG7GQ==", "cpu": [ "ppc64" ], @@ -1202,9 +1235,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.17.1.tgz", - "integrity": "sha512-gEYmYYHaehdvX46mwXrU49vD6Euf1Bxhq9pPb82cbUU9UT2NV+RSckQ5tKWOnNXZixKsy8/cPGtiUWqzPuAcXQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.17.2.tgz", + "integrity": "sha512-BOaNfthf3X3fOWAB+IJ9kxTgPmMqPPH5f5k2DcCsRrBIbWnaJCgX2ll77dV1TdSy9SaXTR5iDXRL8n7AnoP5cg==", "cpu": [ "riscv64" ], @@ -1215,9 +1248,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.17.1.tgz", - "integrity": "sha512-xeae5pMAxHFp6yX5vajInG2toST5lsCTrckSRUFwNgzYqnUjNBcQyqk1bXUxX5yhjWFl2Mnz3F8vQjl+2FRIcw==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.17.2.tgz", + "integrity": "sha512-W0UP/x7bnn3xN2eYMql2T/+wpASLE5SjObXILTMPUBDB/Fg/FxC+gX4nvCfPBCbNhz51C+HcqQp2qQ4u25ok6g==", "cpu": [ "s390x" ], @@ -1228,9 +1261,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.17.1.tgz", - "integrity": "sha512-AsdnINQoDWfKpBzCPqQWxSPdAWzSgnYbrJYtn6W0H2E9It5bZss99PiLA8CgmDRfvKygt20UpZ3xkhFlIfX9zQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.17.2.tgz", + "integrity": "sha512-Hy7pLwByUOuyaFC6mAr7m+oMC+V7qyifzs/nW2OJfC8H4hbCzOX07Ov0VFk/zP3kBsELWNFi7rJtgbKYsav9QQ==", "cpu": [ "x64" ], @@ -1241,9 +1274,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.17.1.tgz", - "integrity": "sha512-KoB4fyKXTR+wYENkIG3fFF+5G6N4GFvzYx8Jax8BR4vmddtuqSb5oQmYu2Uu067vT/Fod7gxeQYKupm8gAcMSQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.17.2.tgz", + "integrity": "sha512-h1+yTWeYbRdAyJ/jMiVw0l6fOOm/0D1vNLui9iPuqgRGnXA0u21gAqOyB5iHjlM9MMfNOm9RHCQ7zLIzT0x11Q==", "cpu": [ "x64" ], @@ -1254,9 +1287,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.17.1.tgz", - "integrity": "sha512-J0d3NVNf7wBL9t4blCNat+d0PYqAx8wOoY+/9Q5cujnafbX7BmtYk3XvzkqLmFECaWvXGLuHmKj/wrILUinmQg==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.17.2.tgz", + "integrity": "sha512-tmdtXMfKAjy5+IQsVtDiCfqbynAQE/TQRpWdVataHmhMb9DCoJxp9vLcCBjEQWMiUYxO1QprH/HbY9ragCEFLA==", "cpu": [ "arm64" ], @@ -1267,9 +1300,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.17.1.tgz", - "integrity": "sha512-xjgkWUwlq7IbgJSIxvl516FJ2iuC/7ttjsAxSPpC9kkI5iQQFHKyEN5BjbhvJ/IXIZ3yIBcW5QDlWAyrA+TFag==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.17.2.tgz", + "integrity": "sha512-7II/QCSTAHuE5vdZaQEwJq2ZACkBpQDOmQsE6D6XUbnBHW8IAhm4eTufL6msLJorzrHDFv3CF8oCA/hSIRuZeQ==", "cpu": [ "ia32" ], @@ -1280,9 +1313,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.17.1.tgz", - "integrity": "sha512-0QbCkfk6cnnVKWqqlC0cUrrUMDMfu5ffvYMTUHf+qMN2uAb3MKP31LPcwiMXBNsvoFGs/kYdFOsuLmvppCopXA==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.17.2.tgz", + "integrity": "sha512-TGGO7v7qOq4CYmSBVEYpI1Y5xDuCEnbVC5Vth8mOsW0gDSzxNrVERPc790IGHsrT2dQSimgMr9Ub3Y1Jci5/8w==", "cpu": [ "x64" ], @@ -1459,6 +1492,18 @@ "node": ">=0.4" } }, + "node_modules/acorn": { + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", + "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -2029,6 +2074,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -2272,9 +2323,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.751", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.751.tgz", - "integrity": "sha512-2DEPi++qa89SMGRhufWTiLmzqyuGmNF3SK4+PQetW1JKiZdEpF4XQonJXJCzyuYSA6mauiMhbyVhqYAP45Hvfw==", + "version": "1.4.752", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.752.tgz", + "integrity": "sha512-P3QJreYI/AUTcfBVrC4zy9KvnZWekViThgQMX/VpJ+IsOBbcX5JFpORM4qWapwWQ+agb2nYAOyn/4PMXOk0m2Q==", "dev": true }, "node_modules/elliptic": { @@ -4550,9 +4601,9 @@ } }, "node_modules/rollup": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.17.1.tgz", - "integrity": "sha512-0gG94inrUtg25sB2V/pApwiv1lUb0bQ25FPNuzO89Baa+B+c0ccaaBKM5zkZV/12pUUdH+lWCSm9wmHqyocuVQ==", + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.17.2.tgz", + "integrity": "sha512-/9ClTJPByC0U4zNLowV1tMBe8yMEAxewtR3cUNX5BoEpGH3dQEWpJLr6CLp0fPdYRF/fzVOgvDb1zXuakwF5kQ==", "dev": true, "dependencies": { "@types/estree": "1.0.5" @@ -4565,22 +4616,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.17.1", - "@rollup/rollup-android-arm64": "4.17.1", - "@rollup/rollup-darwin-arm64": "4.17.1", - "@rollup/rollup-darwin-x64": "4.17.1", - "@rollup/rollup-linux-arm-gnueabihf": "4.17.1", - "@rollup/rollup-linux-arm-musleabihf": "4.17.1", - "@rollup/rollup-linux-arm64-gnu": "4.17.1", - "@rollup/rollup-linux-arm64-musl": "4.17.1", - "@rollup/rollup-linux-powerpc64le-gnu": "4.17.1", - "@rollup/rollup-linux-riscv64-gnu": "4.17.1", - "@rollup/rollup-linux-s390x-gnu": "4.17.1", - "@rollup/rollup-linux-x64-gnu": "4.17.1", - "@rollup/rollup-linux-x64-musl": "4.17.1", - "@rollup/rollup-win32-arm64-msvc": "4.17.1", - "@rollup/rollup-win32-ia32-msvc": "4.17.1", - "@rollup/rollup-win32-x64-msvc": "4.17.1", + "@rollup/rollup-android-arm-eabi": "4.17.2", + "@rollup/rollup-android-arm64": "4.17.2", + "@rollup/rollup-darwin-arm64": "4.17.2", + "@rollup/rollup-darwin-x64": "4.17.2", + "@rollup/rollup-linux-arm-gnueabihf": "4.17.2", + "@rollup/rollup-linux-arm-musleabihf": "4.17.2", + "@rollup/rollup-linux-arm64-gnu": "4.17.2", + "@rollup/rollup-linux-arm64-musl": "4.17.2", + "@rollup/rollup-linux-powerpc64le-gnu": "4.17.2", + "@rollup/rollup-linux-riscv64-gnu": "4.17.2", + "@rollup/rollup-linux-s390x-gnu": "4.17.2", + "@rollup/rollup-linux-x64-gnu": "4.17.2", + "@rollup/rollup-linux-x64-musl": "4.17.2", + "@rollup/rollup-win32-arm64-msvc": "4.17.2", + "@rollup/rollup-win32-ia32-msvc": "4.17.2", + "@rollup/rollup-win32-x64-msvc": "4.17.2", "fsevents": "~2.3.2" } }, @@ -4718,6 +4769,15 @@ "semver": "bin/semver.js" } }, + "node_modules/serialize-javascript": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, "node_modules/sha.js": { "version": "2.4.11", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", @@ -4773,6 +4833,12 @@ "node": ">=8" } }, + "node_modules/smob": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/smob/-/smob-1.5.0.tgz", + "integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==", + "dev": true + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -4942,6 +5008,34 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/terser": { + "version": "5.31.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.0.tgz", + "integrity": "sha512-Q1JFAoUKE5IMfI4Z/lkE/E6+SwgzO+x4tq4v1AyBLRj8VSYvRO6A/rQrPg1yud4g0En9EKI1TvFRF2tQFcoUkg==", + "dev": true, + "dependencies": { + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + }, + "bin": { + "terser": "bin/terser" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/terser/node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", diff --git a/package.json b/package.json index 1a0e9594..f09f69a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pdf2json", - "version": "3.1.0", + "version": "3.1.1", "description": "PDF file parser that converts PDF binaries to text based JSON, powered by porting a fork of PDF.JS to Node.js", "keywords": [ "pdf", @@ -33,6 +33,7 @@ "typings": "./pdfparser.d.ts", "scripts": { "pretest": "npm run build", + "test:jest": "jest --config ./jest.config.json", "test": "jest --config ./jest.config.json", "test:forms": "cd ./test && sh p2j.forms.sh", "test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 7 success, 3 fail exception with stack trace\" ", @@ -69,7 +70,8 @@ "@rollup/plugin-commonjs": "^25.0.4", "@rollup/plugin-node-resolve": "^15.2.1", "@rollup/plugin-replace": "^5.0.2", - "rollup": "^4.17.0", + "@rollup/plugin-terser": "^0.4.4", + "rollup": "^4.17.2", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-inject": "^3.0.2", "rollup-plugin-sourcemaps": "^0.6.3", diff --git a/pdfparser.js b/pdfparser.js index 27929ad4..53b52a2d 100644 --- a/pdfparser.js +++ b/pdfparser.js @@ -7,12 +7,13 @@ import PDFJS from "./lib/pdf.js"; import { ParserStream, StringifyStream } from "./lib/parserstream.js"; import { kColors, kFontFaces, kFontStyles } from "./lib/pdfconst.js"; import { pkInfo, _PARSER_SIG } from "./lib/pkinfo.js"; +import PDFUnit from "./lib/pdfunit.js"; /** * Class representing a PDF Parser. * @extends EventEmitter */ -class PDFParser extends EventEmitter { +export default class PDFParser extends EventEmitter { /** * Static method to retrieve color dictionary. * @returns {object} Color dictionary @@ -37,6 +38,42 @@ class PDFParser extends EventEmitter { return kFontStyles; } + /** + * static property to expose PDFUnit class + * @returns {PDFUnit} PDFUnit class + */ + static get PDFUnit() { + return PDFUnit; + } + + /** + * static property to expose ParserStream class + */ + static get ParserStream() { + return ParserStream; + } + + /** + * static property to expose StringifyStream class + */ + static get StringifyStream() { + return StringifyStream; + } + + /** + * static property to expose pkInfo function + */ + static get pkInfo() { + return pkInfo; + } + + /** + * static property to expose _PARSER_SIG function + */ + static get _PARSER_SIG() { + return _PARSER_SIG; + } + static #maxBinBufferCount = 10; static #binBuffer = {}; @@ -268,14 +305,3 @@ class PDFParser extends EventEmitter { this.#PDFJS = null; } } - -export { - PDFParser, - ParserStream, - StringifyStream, - kColors, - kFontFaces, - kFontStyles, - pkInfo, - _PARSER_SIG, -}; diff --git a/readme.md b/readme.md index c54cf9cc..923165fc 100644 --- a/readme.md +++ b/readme.md @@ -29,11 +29,11 @@ To Run in RESTful Web Service or as command line Utility After install, run command line: -> npm test +> npm test:jest It'll build bundles and source maps for both ES Module and CommonJS, output to `./dist` directory, and run Jest test suit defined in `./test/_test_.cjs`. -The default test suits are eseential tests for all PRs. But it only covers a portion of all tesing PDFs, for more broader converage, run: +The default test suits are essential tests for all PRs. But it only covers a portion of all testing PDFs, for more broader coverage, run: > npm run test:forms @@ -41,6 +41,10 @@ It'll scan and parse _260_ PDF AcroForm files under _*./test/pdf*_, runs with _* _update on 4/27/2024_: parsing 260 PDFs by `npm run test:forms` on M2 Mac takes 7~8s +To run full test suits: + +> npm test + ### Test Exception Handlings After install, run command line: @@ -80,7 +84,7 @@ To disable the first type, you could mock the console.log and console.warn APIs, ```javascript import fs from "fs"; -import { PDFParser } from "pdf2json"; // starting v3.1.0, PDFParser is no longer the default export +import PDFParser from "pdf2json"; const pdfParser = new PDFParser(); @@ -122,7 +126,7 @@ pdfParser.on("error", (err) => console.error("Parser Error", err)); ```javascript import fs from "fs"; -import { PDFParser } from "pdf2json"; // starting v3.1.0, PDFParser is no longer the default export +import PDFParser from "pdf2json"; const pdfParser = new PDFParser(this, 1); @@ -146,7 +150,7 @@ pdfParser.loadPDF("./pdf2json/test/pdf/fd/form/F1040EZ.pdf"); ```javascript import fs from "fs"; -import { PDFParser } from "pdf2json"; // starting v3.1.0, PDFParser is no longer the default export +import PDFParser from "pdf2json"; const pdfParser = new PDFParser(); @@ -170,7 +174,7 @@ Alternatively, you can pipe input and output streams: (requires v1.1.4) ```javascript import fs from "fs"; -import { PDFParser } from "pdf2json"; // starting v3.1.0, no default export of PDFParser +import PDFParser from "pdf2json"; const inputStream = fs.createReadStream( "./pdf2json/test/pdf/fd/form/F1040EZ.pdf", @@ -248,8 +252,8 @@ See [p2jcmd.js](https://github.com/modesty/pdf2json/blob/master/lib/p2jcmd.js) f - alternative events: (v2.0.0) - readable: first event dispatched after PDF file metadata is parsed and before processing any page - - data: one parsed page succeeded, null means last page has been processed, signle end of data stream - - error: exception or error occured + - data: one parsed page succeeded, null means last page has been processed, single end of data stream + - error: exception or error occurred - start to parse PDF file from specified file path asynchronously: @@ -293,33 +297,33 @@ Current parsed data has four main sub objects to describe the PDF document. - Parent: parent name, default "unknown"; - _*v2.0.0*_: 'Agency' and 'Id' are replaced with full metadata, example: for `./test/pdf/fd/form/F1040.pdf`, full metadata is: - ```json - Meta: { - PDFFormatVersion: '1.7', - IsAcroFormPresent: true, - IsXFAPresent: false, - Author: 'SE:W:CAR:MP', - Subject: 'U.S. Individual Income Tax Return', - Creator: 'Adobe Acrobat Pro 10.1.8', - Producer: 'Adobe Acrobat Pro 10.1.8', - CreationDate: "D:20131203133943-08'00'", - ModDate: "D:20140131180702-08'00'", - Metadata: { - 'xmp:modifydate': '2014-01-31T18:07:02-08:00', - 'xmp:createdate': '2013-12-03T13:39:43-08:00', - 'xmp:metadatadate': '2014-01-31T18:07:02-08:00', - 'xmp:creatortool': 'Adobe Acrobat Pro 10.1.8', - 'dc:format': 'application/pdf', - 'dc:description': 'U.S. Individual Income Tax Return', - 'dc:creator': 'SE:W:CAR:MP', - 'xmpmm:documentid': 'uuid:4d81e082-7ef2-4df7-b07b-8190e5d3eadf', - 'xmpmm:instanceid': 'uuid:7ea96d1c-3d2f-284a-a469-f0f284a093de', - 'pdf:producer': 'Adobe Acrobat Pro 10.1.8', - 'adhocwf:state': '1', - 'adhocwf:version': '1.1' - } - } - ``` +```javascript +Meta: { + PDFFormatVersion: '1.7', + IsAcroFormPresent: true, + IsXFAPresent: false, + Author: 'SE:W:CAR:MP', + Subject: 'U.S. Individual Income Tax Return', + Creator: 'Adobe Acrobat Pro 10.1.8', + Producer: 'Adobe Acrobat Pro 10.1.8', + CreationDate: "D:20131203133943-08'00'", + ModDate: "D:20140131180702-08'00'", + Metadata: { + 'xmp:modifydate': '2014-01-31T18:07:02-08:00', + 'xmp:createdate': '2013-12-03T13:39:43-08:00', + 'xmp:metadatadate': '2014-01-31T18:07:02-08:00', + 'xmp:creatortool': 'Adobe Acrobat Pro 10.1.8', + 'dc:format': 'application/pdf', + 'dc:description': 'U.S. Individual Income Tax Return', + 'dc:creator': 'SE:W:CAR:MP', + 'xmpmm:documentid': 'uuid:4d81e082-7ef2-4df7-b07b-8190e5d3eadf', + 'xmpmm:instanceid': 'uuid:7ea96d1c-3d2f-284a-a469-f0f284a093de', + 'pdf:producer': 'Adobe Acrobat Pro 10.1.8', + 'adhocwf:state': '1', + 'adhocwf:version': '1.1' + } +} +``` - 'Pages': array of 'Page' object that describes each page in the PDF, including sizes, lines, fills and texts within the page. More info about 'Page' object can be found at 'Page Object Reference' section - 'Width': the PDF page width in page unit diff --git a/rollup.config.js b/rollup.config.js index ea3a419a..4d474ac2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,23 +1,26 @@ +import path from "path"; import nodeResolve from "@rollup/plugin-node-resolve"; import builtins from "rollup-plugin-node-builtins"; -import path from "path"; import inject from "rollup-plugin-inject"; +import terser from "@rollup/plugin-terser"; import sourcemaps from "rollup-plugin-sourcemaps"; +const external = [ + "fs", + "util", + "fs/promises", + "events", + "path", + "url", + "buffer", + "stream", + "@xmldom/xmldom", +]; + export default [ { input: "./pdfparser.js", - external: [ - "fs", - "util", - "fs/promises", - "events", - "path", - "url", - "buffer", - "stream", - "@xmldom/xmldom", - ], + external, output: [ { file: "dist/pdfparser.cjs", @@ -41,15 +44,10 @@ export default [ path.resolve("lib/pdfcanvas.js"), "createScratchCanvas", ], - PDFAnno: [ - path.resolve("lib/pdfanno.js"), - "PDFAnno", - ], - Image: [ - path.resolve("lib/pdfimage.js"), - "Image", - ], + PDFAnno: [path.resolve("lib/pdfanno.js"), "PDFAnno"], + Image: [path.resolve("lib/pdfimage.js"), "Image"], }), + terser(), sourcemaps(), ], }, diff --git a/test/_test_.cjs b/test/_test_.cjs index 84af4b56..487e0477 100644 --- a/test/_test_.cjs +++ b/test/_test_.cjs @@ -1,7 +1,7 @@ const assert = require("assert"); const fs = require("fs"); -const { PDFParser } = require("../dist/pdfparser.cjs"); +const PDFParser = require("../dist/pdfparser.cjs"); function pdfParserRunner(fileName, fromBuffer) { const pdfParser = new PDFParser();