refactor and clean up and reenter v3 module loading

This commit is contained in:
Jacob Nguyen
2024-05-13 15:27:12 -05:00
parent 8554eeaef4
commit 6e2f4b616f
13 changed files with 152 additions and 101 deletions

View File

@@ -1,5 +1,6 @@
import path from 'node:path';
import { existsSync } from 'fs';
import assert from 'node:assert';
export const parseCallsite = (site: string) => {
@@ -33,17 +34,17 @@ export const shouldHandle = (pth: string, filenam: string) => {
* esm javascript, typescript, and commonjs typescript
* export default commandModule({})
*/
//async function importModule<T>(absPath: string) {
// let fileModule = await import(absPath);
//
// let commandModule = fileModule.default;
//
// assert(commandModule , `No export @ ${absPath}. Forgot to ignore with "!"? (!${path.basename(absPath)})?`);
// if ('default' in commandModule) {
// commandModule = commandModule.default;
// }
// return { module: commandModule } as T;
//}
export async function importModule<T>(absPath: string) {
let fileModule = await import(absPath);
let commandModule = fileModule.default;
assert(commandModule , `No export @ ${absPath}. Forgot to ignore with "!"? (!${path.basename(absPath)})?`);
if ('default' in commandModule) {
commandModule = commandModule.default;
}
return { module: commandModule } as T;
}
export const fmtFileName = (fileName: string) => path.parse(fileName).name;