/ vidolib / scripts / check-licensing.js
swadhinbiswas chore: rename monorepo and package scopes to VidoLib (@vidolib/*) · 7/23/2026
11fee02
67 lines · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');

const ROYALTY_FREE_ALLOWLIST = new Set([
  'av1', 'vp8', 'vp9', 'opus', 'flac', 'vorbis', 'theora', 'pcm', 'pcm-u8', 'pcm-s16le', 'pcm-f32le'
]);

const PROHIBITED_WASM_CODECS = ['h264', 'avc', 'hevc', 'h265', 'ac3', 'eac3', 'dts'];

function scanDirectory(dirPath) {
  let errors = [];
  const entries = fs.readdirSync(dirPath, { withFileTypes: true });

  for (const entry of entries) {
    const fullPath = path.join(dirPath, entry.name);

    if (entry.isDirectory()) {
      if (entry.name !== 'node_modules' && entry.name !== 'dist' && entry.name !== '.git') {
        errors = errors.concat(scanDirectory(fullPath));
      }
    } else if (entry.isFile()) {
      const lowerName = entry.name.toLowerCase();

      if (lowerName.endsWith('.wasm')) {
        let isAllowed = false;
        for (const allowed of ROYALTY_FREE_ALLOWLIST) {
          if (lowerName.includes(allowed)) {
            isAllowed = true;
            break;
          }
        }
        if (!isAllowed) {
          errors.push(`[LICENSING FAILURE] Disallowed WASM binary found: ${fullPath}. Only royalty-free decoders (${[...ROYALTY_FREE_ALLOWLIST].join(', ')}) are permitted as WASM.`);
        }
      }

      if ((lowerName.endsWith('.ts') || lowerName.endsWith('.js')) && fullPath.includes('packages/codecs/src/software')) {
        const content = fs.readFileSync(fullPath, 'utf8').toLowerCase();
        for (const prohibited of PROHIBITED_WASM_CODECS) {
          if (content.includes(`software_${prohibited}_decoder`) || content.includes(`wasm_${prohibited}`)) {
            errors.push(`[LICENSING FAILURE] Software/WASM decoder logic for patented codec '${prohibited}' detected in ${fullPath}. Software decoding of patented codecs is strictly forbidden by policy.`);
          }
        }
      }
    }
  }

  return errors;
}

const packagesDir = path.join(rootDir, 'packages');
console.log('Running VidoLib Codec Licensing Audit...');
const errors = scanDirectory(packagesDir);

if (errors.length > 0) {
  console.error('\n=== LICENSING CHECK FAILED ===');
  errors.forEach(err => console.error(err));
  process.exit(1);
} else {
  console.log('✅ Licensing Audit Passed: All decoders comply with LICENSING.md royalty-free & hardware-first policy.');
}