pdf-poppler-binaries-linux-fonts 0.1.0-beta → 0.1.2-beta
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.
- package/index.js +49 -3
- package/lib/fontconfig/fonts.conf +4 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,57 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const PACKAGE_NAME = 'pdf-poppler-binaries-linux-fonts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Finds the actual package location, handling bundled environments.
|
|
8
|
+
* When code is bundled by esbuild/webpack, __dirname points to the bundled location,
|
|
9
|
+
* not the original package location. This function checks multiple fallback paths.
|
|
10
|
+
* @returns {string} The base path to the package's lib directory
|
|
11
|
+
*/
|
|
12
|
+
function findLibPath() {
|
|
13
|
+
// Try __dirname first (works in non-bundled environments)
|
|
14
|
+
const localLib = path.join(__dirname, 'lib');
|
|
15
|
+
if (fs.existsSync(localLib)) {
|
|
16
|
+
return localLib;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Fallback paths for bundled environments (Lambda, containers)
|
|
20
|
+
const fallbackPaths = [
|
|
21
|
+
// Standard Lambda node_modules location
|
|
22
|
+
`/var/task/node_modules/${PACKAGE_NAME}/lib`,
|
|
23
|
+
// Lambda layer location
|
|
24
|
+
`/opt/nodejs/node_modules/${PACKAGE_NAME}/lib`,
|
|
25
|
+
// Alternative layer path
|
|
26
|
+
`/opt/node_modules/${PACKAGE_NAME}/lib`,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
for (const fallbackPath of fallbackPaths) {
|
|
30
|
+
if (fs.existsSync(fallbackPath)) {
|
|
31
|
+
return fallbackPath;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// If nothing found, return the __dirname path (will show in error messages)
|
|
36
|
+
return localLib;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Cache the lib path
|
|
40
|
+
let cachedLibPath = null;
|
|
41
|
+
|
|
42
|
+
function getLibPath() {
|
|
43
|
+
if (cachedLibPath === null) {
|
|
44
|
+
cachedLibPath = findLibPath();
|
|
45
|
+
}
|
|
46
|
+
return cachedLibPath;
|
|
47
|
+
}
|
|
2
48
|
|
|
3
49
|
/**
|
|
4
50
|
* Returns the base path where Linux poppler binaries are located
|
|
5
51
|
* @returns {string} The base path to the Linux binaries directory
|
|
6
52
|
*/
|
|
7
53
|
function getBinaryPath() {
|
|
8
|
-
return path.join(
|
|
54
|
+
return path.join(getLibPath(), 'linux');
|
|
9
55
|
}
|
|
10
56
|
|
|
11
57
|
/**
|
|
@@ -13,7 +59,7 @@ function getBinaryPath() {
|
|
|
13
59
|
* @returns {string} The path to fontconfig configuration
|
|
14
60
|
*/
|
|
15
61
|
function getFontconfigPath() {
|
|
16
|
-
return path.join(
|
|
62
|
+
return path.join(getLibPath(), 'fontconfig');
|
|
17
63
|
}
|
|
18
64
|
|
|
19
65
|
/**
|
|
@@ -21,7 +67,7 @@ function getFontconfigPath() {
|
|
|
21
67
|
* @returns {string} The path to fonts directory
|
|
22
68
|
*/
|
|
23
69
|
function getFontsPath() {
|
|
24
|
-
return path.join(
|
|
70
|
+
return path.join(getLibPath(), 'fonts');
|
|
25
71
|
}
|
|
26
72
|
|
|
27
73
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
|
|
3
3
|
<fontconfig>
|
|
4
|
-
<!-- Bundled fonts directory -->
|
|
4
|
+
<!-- Bundled fonts directory - relative to this fonts.conf file -->
|
|
5
|
+
<dir prefix="relative">../fonts</dir>
|
|
6
|
+
|
|
7
|
+
<!-- Fallback to common absolute locations -->
|
|
5
8
|
<dir>/var/task/node_modules/pdf-poppler-binaries-linux-fonts/lib/fonts</dir>
|
|
6
9
|
<dir>/opt/nodejs/node_modules/pdf-poppler-binaries-linux-fonts/lib/fonts</dir>
|
|
7
|
-
|
|
8
|
-
<!-- Fallback to common locations -->
|
|
9
|
-
<dir prefix="cwd">lib/fonts</dir>
|
|
10
10
|
<dir>/usr/share/fonts</dir>
|
|
11
11
|
<dir>/usr/local/share/fonts</dir>
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-poppler-binaries-linux-fonts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-beta",
|
|
4
4
|
"description": "Linux binaries for pdf-poppler with bundled fonts. Includes Poppler utilities, fontconfig, and Liberation Sans fonts for environments without system fonts (Lambda, containers).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|