// GPL-3.0-only. Wrapper du build amont : bloque le code commercial, relève les modules réels. // Même garde-fou que extensions/webpack-oss.cjs, pour les trois configs du bureau // (main, renderer, preload). const fs = require('fs'); const path = require('path'); const root = __dirname; const { tag } = require('./upstream.json'); const source = path.join(root, '.cache', `clients-${tag}`); class OssBoundaryPlugin { apply(compiler) { compiler.hooks.compilation.tap('LoksiOssBoundary', compilation => { compilation.hooks.finishModules.tap('LoksiOssBoundary', modules => { const resources = [...modules].map(m => m.resource).filter(Boolean).sort(); const forbidden = resources.filter(p => /[/\\]bitwarden_license[/\\]|[/\\]commercial-sdk-internal[/\\]/.test(p)); if (forbidden.length) throw new Error(`Code commercial interdit : ${forbidden.join(', ')}`); const name = `desktop-${compiler.options.name}`.replace(/[^a-zA-Z0-9.-]/g, '_'); fs.mkdirSync(path.join(root, 'reports'), { recursive: true }); fs.writeFileSync(path.join(root, 'reports', `${name}-modules.json`), JSON.stringify(resources.map(p => path.relative(source, p)), null, 2)); }); }); } } module.exports = (...args) => { const configs = require(path.join(source, 'apps/desktop/webpack.config.js'))(...args); for (const config of configs) config.plugins.push(new OssBoundaryPlugin()); return configs; };