forked from maxdavidson/rollup-plugin-sourcemaps
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatch-paths.js
More file actions
21 lines (17 loc) · 665 Bytes
/
patch-paths.js
File metadata and controls
21 lines (17 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { readFileSync, writeFileSync } from 'node:fs';
import { sync } from 'glob';
// Function to update require statements in a file
const updateRequireStatements = filePath => {
const content = readFileSync(filePath, 'utf8');
const updatedContent = content.replace(
/require\((['"]\.\/[^'"]+)\.js(['"])\)/g,
'require($1.cjs$2)',
);
writeFileSync(filePath, updatedContent, 'utf8');
console.log(`Updated require statements in ${filePath}`);
};
// Find all .cjs files in the dist directory
const cjsFiles = sync('dist/**/*.cjs');
// Update each .cjs file
cjsFiles.forEach(updateRequireStatements);
console.log('Post-build script completed.');