Skip to content

Commit

Permalink
fix: presence feature not workign on cjs applications (#351)
Browse files Browse the repository at this point in the history
* start fix

* fix on unix

* better solution
  • Loading branch information
jacoobes authored Jan 8, 2024
1 parent a6fa4e3 commit 4f23871
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/core/module-loading.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Result } from 'ts-results-es';
import { type Observable, from, mergeMap, ObservableInput } from 'rxjs';
import { readdir, stat } from 'fs/promises';
import { basename, extname, join, resolve, parse } from 'path';
import { basename, extname, join, resolve, parse, dirname } from 'path';
import assert from 'assert';
import { createRequire } from 'node:module';
import type { ImportPayload, Wrapper } from '../types/core';
import type { Module } from '../types/core-modules';
import { existsSync } from 'fs';
import { fileURLToPath } from 'node:url';

export const shouldHandle = (path: string, fpath: string) => {
const newPath = new URL(fpath+extname(path), path).href;
return {
exists: existsSync(fileURLToPath(newPath)),
path: newPath
}
const file_name = fpath+extname(path);
let newPath = join(dirname(path), file_name)
.replace(/file:\\?/, "");
return { exists: existsSync(newPath),
path: 'file:///'+newPath };
}


Expand Down Expand Up @@ -79,11 +78,9 @@ const isSkippable = (filename: string) => {

async function deriveFileInfo(dir: string, file: string) {
const fullPath = join(dir, file);
return {
fullPath,
fileStats: await stat(fullPath),
base: basename(file),
};
return { fullPath,
fileStats: await stat(fullPath),
base: basename(file) };
}

async function* readPaths(dir: string): AsyncGenerator<string> {
Expand Down Expand Up @@ -131,10 +128,8 @@ export function loadConfig(wrapper: Wrapper | 'file'): Wrapper {
console.log('Events path is set to', eventsPath);
}

return {
defaultPrefix: config.defaultPrefix,
commands: commandsPath,
events: eventsPath,
};
return { defaultPrefix: config.defaultPrefix,
commands: commandsPath,
events: eventsPath };

}
1 change: 1 addition & 0 deletions src/sern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function init(maybeWrapper: Wrapper | 'file') {
if (wrapper.events !== undefined) {
eventsHandler(dependencies, Files.getFullPathTree(wrapper.events));
}

const initCallsite = callsites()[1].getFileName();
const presencePath = Files.shouldHandle(initCallsite!, "presence");
//Ready event: load all modules and when finished, time should be taken and logged
Expand Down

0 comments on commit 4f23871

Please sign in to comment.