@pproenca/webcodecs-ffmpeg-non-free 0.1.2 → 0.1.4

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