-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathpost-build.js
More file actions
executable file
·34 lines (27 loc) · 1.22 KB
/
post-build.js
File metadata and controls
executable file
·34 lines (27 loc) · 1.22 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
#!/usr/bin/env node
// Simple script to fix CommonJS exports
const fs = require('fs');
const path = require('path');
// Path to the CJS output file
const cjsFilePath = path.resolve('./plugin/build/cjs/index.js');
console.log('📝 Processing CommonJS output...');
try {
let content = fs.readFileSync(cjsFilePath, 'utf8');
// Replace exports.default with module.exports
content = content.replace(/exports\.default = (\w+);/, 'module.exports = $1;');
// Make sure there's no duplicate module.exports
if (!content.includes('module.exports =')) {
// Add module.exports if it doesn't exist
const lastExportLine = content.lastIndexOf('exports.default =');
if (lastExportLine !== -1) {
const withRecordingPermissionName = content.match(/exports\.default = (\w+);/)[1];
content = content.replace(/exports\.default = (\w+);/,
`module.exports = ${withRecordingPermissionName};\n// For backwards compatibility\nexports.default = ${withRecordingPermissionName};`);
}
}
fs.writeFileSync(cjsFilePath, content);
console.log('✅ Successfully updated CommonJS exports in:', cjsFilePath);
} catch (error) {
console.error('❌ Error processing CommonJS output:', error.message);
process.exit(1);
}