2021-05-09 07:22:41 -05:00
|
|
|
import FileHound from 'filehound';
|
|
|
|
import fs from 'fs';
|
|
|
|
|
2023-02-15 13:39:28 +01:00
|
|
|
const files = FileHound.create().paths('./lib').ext(['js', 'ts']).find();
|
2021-05-09 07:22:41 -05:00
|
|
|
|
|
|
|
files.then((filePaths) => {
|
|
|
|
filePaths.forEach((filepath) => {
|
|
|
|
fs.readFile(filepath, 'utf8', (err, text) => {
|
|
|
|
if (!text.match(/import .* from/g)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
text = text.replace(/(import .* from\s+['"])(.*)(?=['"])/g, '$1$2.js');
|
|
|
|
if (text.match(/export .* from/g)) {
|
|
|
|
text = text.replace(/(export .* from\s+['"])(.*)(?=['"])/g, '$1$2.js');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
// stupid replacement back
|
|
|
|
text = text.replace(
|
2021-05-09 08:11:42 -05:00
|
|
|
"import * as Canvas from 'canvas.js';",
|
|
|
|
"import * as Canvas from 'canvas';"
|
2021-05-09 07:22:41 -05:00
|
|
|
);
|
|
|
|
|
2023-02-15 13:39:28 +01:00
|
|
|
// Handle import("./x/y/z") syntax.
|
|
|
|
text = text.replace(/(import\s*\(\s*['"])(.*)(?=['"])/g, '$1$2.js');
|
|
|
|
|
2021-05-09 07:22:41 -05:00
|
|
|
fs.writeFile(filepath, text, function (err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-04-13 23:27:56 -05:00
|
|
|
|
2025-08-10 22:10:55 +09:00
|
|
|
// Removed CommonJS export rewriting to keep ESM output intact
|