@ohos-ports/sharp 0.34.5-beta.10 → 0.34.5-beta.12

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/lib/sharp.js CHANGED
@@ -10,7 +10,61 @@ const { familySync, versionSync } = require('detect-libc');
10
10
  const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
11
11
  const runtimePlatform = runtimePlatformArch();
12
12
 
13
- // OpenHarmony patch disabled — RPATH + symlinks handle libvips resolution
13
+ // OpenHarmony: set LD_LIBRARY_PATH for libvips before loading native binary
14
+ // The .node binary's RPATH references @img/ namespace but the actual .so
15
+ // files are installed under @ohos-ports/img-sharp-libvips-{platform}/lib
16
+ try {
17
+ const libvipsLibPath = require(`@ohos-ports/img-sharp-libvips-${runtimePlatform}/lib`);
18
+ if (libvipsLibPath) {
19
+ const path = require('node:path');
20
+ const fs = require('node:fs');
21
+ // Create soname symlinks: libXXX.so.Y.Z.W → libXXX.so.Y
22
+ // The .node binary NEEDED entries request sonames (e.g. libvips-cpp.so.42)
23
+ // but the libvips package only ships full-version files (e.g. libvips-cpp.so.42.20.3)
24
+ // HarmonyOS fix: some libs carry 2-component sonames (e.g. libbz2.so.1.0,
25
+ // per embedded SONAME) — create a symlink for every soname prefix variant
26
+ // so both 1- and 2-component NEEDED requests resolve.
27
+ try {
28
+ for (const file of fs.readdirSync(libvipsLibPath)) {
29
+ const m = file.match(/^(.+\.so)\.(\d[\w.]*)$/);
30
+ if (m) {
31
+ const base = m[1];
32
+ const parts = m[2].split('.');
33
+ for (let i = 1; i < parts.length; i++) {
34
+ const soname = `${base}.${parts.slice(0, i).join('.')}`;
35
+ const sonamePath = path.join(libvipsLibPath, soname);
36
+ if (!fs.existsSync(sonamePath)) {
37
+ try { fs.symlinkSync(file, sonamePath); } catch (_) {
38
+ try { fs.copyFileSync(path.join(libvipsLibPath, file), sonamePath); } catch (_) {}
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ } catch (_) {}
45
+ const currentLdPath = process.env.LD_LIBRARY_PATH || '';
46
+ if (!currentLdPath.includes(libvipsLibPath)) {
47
+ process.env.LD_LIBRARY_PATH = `${libvipsLibPath}:${currentLdPath}`;
48
+ }
49
+ // HarmonyOS RPATH fix: the prebuilt .node carries RPATH
50
+ // $ORIGIN/../../sharp-libvips-openharmony-arm64/lib (the @img/ namespace
51
+ // layout), but the libvips package is installed as
52
+ // @ohos-ports/img-sharp-libvips-<platform>. JS-side LD_LIBRARY_PATH is
53
+ // invisible to the dynamic loader, so create a compatibility symlink at
54
+ // node_modules/@ohos-ports/sharp-libvips-<platform> -> img-sharp-libvips-<platform>
55
+ // so dlopen resolves libvips-cpp.so.42 via the original RPATH.
56
+ try {
57
+ const scopedDir = path.resolve(libvipsLibPath, '..', '..');
58
+ const linkPath = path.join(scopedDir, `sharp-libvips-${runtimePlatform}`);
59
+ const linkTarget = `img-sharp-libvips-${runtimePlatform}`;
60
+ if (!fs.existsSync(linkPath)) {
61
+ try { fs.symlinkSync(linkTarget, linkPath, 'dir'); } catch (_) {
62
+ try { fs.mkdirSync(linkPath, { recursive: true }); } catch (_) {}
63
+ }
64
+ }
65
+ } catch (_) {}
66
+ }
67
+ } catch (_e) { /* libvips not available as separate package, skip */ }
14
68
 
15
69
  const paths = [
16
70
  `../src/build/Release/sharp-${runtimePlatform}.node`,
package/lib/utility.js CHANGED
@@ -21,10 +21,6 @@ const libvipsVersion = sharp.libvipsVersion();
21
21
  * @returns {Object}
22
22
  */
23
23
  const format = sharp.format();
24
- /* @ohos-ports patch: native module returns 'jp2' instead of 'jp2k' */
25
- if (!format.jp2k && format.jp2) {
26
- format.jp2k = format.jp2;
27
- }
28
24
  format.heif.output.alias = ['avif', 'heic'];
29
25
  format.jpeg.output.alias = ['jpe', 'jpg'];
30
26
  format.tiff.output.alias = ['tif'];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ohos-ports/sharp",
3
- "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
- "version": "0.34.5-beta.10",
3
+ "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images [ohos-ports: openharmony-arm64 native (libvips 8.18.3) + soname-variant/RPATH symlink self-healing]",
4
+ "version": "0.34.5-beta.12",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -118,7 +118,8 @@
118
118
  ],
119
119
  "repository": {
120
120
  "type": "git",
121
- "url": "git://github.com/lovell/sharp.git"
121
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
122
+ "directory": "ports/sharp/0.34.5"
122
123
  },
123
124
  "keywords": [
124
125
  "jpeg",
@@ -168,7 +169,7 @@
168
169
  "@img/sharp-win32-arm64": "0.34.5",
169
170
  "@img/sharp-win32-ia32": "0.34.5",
170
171
  "@img/sharp-win32-x64": "0.34.5",
171
- "@ohos-ports/img-sharp-openharmony-arm64": "0.34.5-beta.3"
172
+ "@ohos-ports/img-sharp-openharmony-arm64": "0.34.5-beta.4"
172
173
  },
173
174
  "devDependencies": {
174
175
  "@ohos-ports/biomejs-biome": "^2.3.4-beta.0",
@@ -199,5 +200,8 @@
199
200
  },
200
201
  "funding": {
201
202
  "url": "https://opencollective.com/libvips"
203
+ },
204
+ "bugs": {
205
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
202
206
  }
203
207
  }