@pproenca/webcodecs-ffmpeg 0.1.0 → 0.1.3
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/install.js +56 -4
- package/package.json +6 -5
- package/resolve.js +69 -8
package/install.js
CHANGED
|
@@ -1,32 +1,84 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Fallback installer for when optionalDependencies are disabled.
|
|
4
|
-
*
|
|
4
|
+
* @module install
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
7
9
|
const os = require('os');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
|
|
12
|
+
// ----- Type Definitions -----
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} PlatformInfo
|
|
16
|
+
* @property {string} os
|
|
17
|
+
* @property {string} cpu
|
|
18
|
+
* @property {string} [libc]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** @typedef {'darwin-arm64' | 'darwin-x64' | 'linux-x64' | 'linux-x64-musl' | 'linux-arm64' | 'win32-x64' | 'win32-arm64'} PlatformKey */
|
|
22
|
+
|
|
23
|
+
// ----- Constants -----
|
|
8
24
|
|
|
9
25
|
const TIER_SUFFIX = '';
|
|
26
|
+
const PACKAGE_SCOPE = '@pproenca/webcodecs-ffmpeg';
|
|
10
27
|
|
|
28
|
+
/** @type {Record<PlatformKey, PlatformInfo>} */
|
|
11
29
|
const PLATFORMS = {
|
|
12
30
|
'darwin-arm64': { os: 'darwin', cpu: 'arm64' },
|
|
13
31
|
'darwin-x64': { os: 'darwin', cpu: 'x64' },
|
|
14
32
|
'linux-x64': { os: 'linux', cpu: 'x64' },
|
|
33
|
+
'linux-x64-musl': { os: 'linux', cpu: 'x64', libc: 'musl' },
|
|
15
34
|
'linux-arm64': { os: 'linux', cpu: 'arm64' },
|
|
16
35
|
'win32-x64': { os: 'win32', cpu: 'x64' },
|
|
17
36
|
'win32-arm64': { os: 'win32', cpu: 'arm64' },
|
|
18
37
|
};
|
|
19
38
|
|
|
39
|
+
// ----- Platform Detection -----
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Detects if the current system uses musl libc (Alpine Linux, etc.)
|
|
43
|
+
* @returns {boolean} True if running on musl libc
|
|
44
|
+
*/
|
|
45
|
+
function isMusl() {
|
|
46
|
+
if (os.platform() !== 'linux') return false;
|
|
47
|
+
try {
|
|
48
|
+
const muslArch = os.arch() === 'x64' ? 'x86_64' : os.arch();
|
|
49
|
+
return fs.existsSync(`/lib/ld-musl-${muslArch}.so.1`);
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Gets the platform key for the current system
|
|
57
|
+
* @returns {string} Platform key (e.g., 'darwin-arm64', 'linux-x64-musl')
|
|
58
|
+
*/
|
|
20
59
|
function getPlatformKey() {
|
|
21
60
|
const platform = os.platform();
|
|
22
61
|
const arch = os.arch();
|
|
62
|
+
if (platform === 'linux' && arch === 'x64' && isMusl()) {
|
|
63
|
+
return 'linux-x64-musl';
|
|
64
|
+
}
|
|
23
65
|
return `${platform}-${arch}`;
|
|
24
66
|
}
|
|
25
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Gets the package name for a platform key
|
|
70
|
+
* @param {string} platformKey
|
|
71
|
+
* @returns {string} Full package name
|
|
72
|
+
*/
|
|
26
73
|
function getPackageName(platformKey) {
|
|
27
|
-
return
|
|
74
|
+
return `${PACKAGE_SCOPE}-${platformKey}${TIER_SUFFIX}`;
|
|
28
75
|
}
|
|
29
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a package is installed
|
|
79
|
+
* @param {string} packageName
|
|
80
|
+
* @returns {boolean} True if the package can be resolved
|
|
81
|
+
*/
|
|
30
82
|
function checkInstalled(packageName) {
|
|
31
83
|
try {
|
|
32
84
|
require.resolve(packageName);
|
|
@@ -36,6 +88,8 @@ function checkInstalled(packageName) {
|
|
|
36
88
|
}
|
|
37
89
|
}
|
|
38
90
|
|
|
91
|
+
// ----- Main -----
|
|
92
|
+
|
|
39
93
|
function main() {
|
|
40
94
|
const platformKey = getPlatformKey();
|
|
41
95
|
|
|
@@ -48,11 +102,9 @@ function main() {
|
|
|
48
102
|
const packageName = getPackageName(platformKey);
|
|
49
103
|
|
|
50
104
|
if (checkInstalled(packageName)) {
|
|
51
|
-
// Package was installed via optionalDependencies - all good
|
|
52
105
|
process.exit(0);
|
|
53
106
|
}
|
|
54
107
|
|
|
55
|
-
// Package not found - provide guidance
|
|
56
108
|
console.warn(`[ffmpeg] Warning: Platform package not found: ${packageName}`);
|
|
57
109
|
console.warn('[ffmpeg] This usually happens when --no-optional or --ignore-optional is used.');
|
|
58
110
|
console.warn(`[ffmpeg] To install manually: npm install ${packageName}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pproenca/webcodecs-ffmpeg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Prebuilt FFmpeg with LGPL-safe codecs (VP8/9, AV1, Opus, Vorbis, MP3) - auto-selects platform",
|
|
5
5
|
"author": "Pedro Proenca",
|
|
6
6
|
"homepage": "https://github.com/pproenca/webcodecs-ffmpeg",
|
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
"./package": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"optionalDependencies": {
|
|
26
|
-
"@pproenca/webcodecs-ffmpeg-
|
|
27
|
-
"@pproenca/webcodecs-ffmpeg-darwin-
|
|
28
|
-
"@pproenca/webcodecs-ffmpeg-
|
|
29
|
-
"@pproenca/webcodecs-ffmpeg-linux-x64": "0.1.
|
|
26
|
+
"@pproenca/webcodecs-ffmpeg-darwin-arm64": "0.1.3",
|
|
27
|
+
"@pproenca/webcodecs-ffmpeg-darwin-x64": "0.1.3",
|
|
28
|
+
"@pproenca/webcodecs-ffmpeg-linux-arm64": "0.1.3",
|
|
29
|
+
"@pproenca/webcodecs-ffmpeg-linux-x64": "0.1.3",
|
|
30
|
+
"@pproenca/webcodecs-ffmpeg-linux-x64-musl": "0.1.3"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"postinstall": "node install.js"
|
package/resolve.js
CHANGED
|
@@ -1,31 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolves platform-specific package paths for binding.gyp.
|
|
3
|
+
* @module resolve
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* @example
|
|
6
|
+
* // In binding.gyp:
|
|
7
|
+
* "library_dirs": ["<!(node -p \"require('@pproenca/webcodecs-ffmpeg/resolve').lib\")"]
|
|
8
|
+
* "PKG_CONFIG_PATH": "<!(node -p \"require('@pproenca/webcodecs-ffmpeg/resolve').pkgconfig\")"
|
|
7
9
|
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
8
13
|
const os = require('os');
|
|
14
|
+
const fs = require('fs');
|
|
9
15
|
const path = require('path');
|
|
10
16
|
|
|
17
|
+
// ----- Constants -----
|
|
18
|
+
|
|
11
19
|
const TIER_SUFFIX = '';
|
|
20
|
+
const PACKAGE_SCOPE = '@pproenca/webcodecs-ffmpeg';
|
|
21
|
+
|
|
22
|
+
// ----- Platform Detection -----
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Detects if the current system uses musl libc (Alpine Linux, etc.)
|
|
26
|
+
* @returns {boolean} True if running on musl libc
|
|
27
|
+
*/
|
|
28
|
+
function isMusl() {
|
|
29
|
+
if (os.platform() !== 'linux') return false;
|
|
30
|
+
try {
|
|
31
|
+
const muslArch = os.arch() === 'x64' ? 'x86_64' : os.arch();
|
|
32
|
+
return fs.existsSync(`/lib/ld-musl-${muslArch}.so.1`);
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @type {string | null} */
|
|
39
|
+
let cachedPkgPath = null;
|
|
12
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the platform-specific package path
|
|
43
|
+
* @returns {string} Absolute path to the platform package directory
|
|
44
|
+
* @throws {Error} If no suitable platform package is found
|
|
45
|
+
*/
|
|
13
46
|
function getPlatformPkgPath() {
|
|
47
|
+
if (cachedPkgPath) return cachedPkgPath;
|
|
48
|
+
|
|
14
49
|
const platform = os.platform();
|
|
15
50
|
const arch = os.arch();
|
|
16
|
-
|
|
51
|
+
|
|
52
|
+
// Try musl-specific package first on Linux x64
|
|
53
|
+
if (platform === 'linux' && arch === 'x64' && isMusl()) {
|
|
54
|
+
const muslPkg = `${PACKAGE_SCOPE}-linux-x64-musl${TIER_SUFFIX}`;
|
|
55
|
+
try {
|
|
56
|
+
cachedPkgPath = path.dirname(require.resolve(`${muslPkg}/lib`));
|
|
57
|
+
return cachedPkgPath;
|
|
58
|
+
} catch {
|
|
59
|
+
// Fall through to glibc package
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pkgName = `${PACKAGE_SCOPE}-${platform}-${arch}${TIER_SUFFIX}`;
|
|
17
64
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
65
|
+
cachedPkgPath = path.dirname(require.resolve(`${pkgName}/lib`));
|
|
66
|
+
return cachedPkgPath;
|
|
67
|
+
} catch {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Platform package not found: ${pkgName}. Install it with: npm install ${pkgName}`
|
|
70
|
+
);
|
|
21
71
|
}
|
|
22
72
|
}
|
|
23
73
|
|
|
74
|
+
// ----- Exports -----
|
|
75
|
+
|
|
24
76
|
module.exports = {
|
|
77
|
+
/**
|
|
78
|
+
* Path to the lib directory containing FFmpeg static libraries
|
|
79
|
+
* @type {string}
|
|
80
|
+
*/
|
|
25
81
|
get lib() {
|
|
26
82
|
return path.join(getPlatformPkgPath(), 'lib');
|
|
27
83
|
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Path to the pkgconfig directory for pkg-config integration
|
|
87
|
+
* @type {string}
|
|
88
|
+
*/
|
|
28
89
|
get pkgconfig() {
|
|
29
90
|
return path.join(getPlatformPkgPath(), 'lib', 'pkgconfig');
|
|
30
|
-
}
|
|
91
|
+
},
|
|
31
92
|
};
|