Skip to content

Commit 329db5b

Browse files
committed
Improve package loading and config in core and example
Updated the express example config to reference the project management package by name instead of importing its params directly. Enhanced ObjectQL's loadFromDirectory to resolve module names to their directory paths, improving flexibility in loading packages.
1 parent 1212982 commit 329db5b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

examples/servers/express/src/objectql.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { MongoDriver } from '@objectql/driver-mongo';
2-
import { packageDir as projectManagementParams } from '../../../apps/project-management/dist';
32
import path from 'path';
43

54
export default {
@@ -10,6 +9,6 @@ export default {
109
})
1110
},
1211
packages: [
13-
projectManagementParams
12+
'@example/project-management'
1413
]
1514
};

packages/core/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as path from 'path';
2+
13
export * from './metadata';
24
export * from './types';
35
export * from './driver';
@@ -29,7 +31,16 @@ export class ObjectQL implements IObjectQL {
2931
}
3032

3133
loadFromDirectory(dir: string) {
32-
const objects = loadObjectConfigs(dir);
34+
let packageDir = dir;
35+
try {
36+
// Try to resolve as a module
37+
const entryPath = require.resolve(dir, { paths: [process.cwd()] });
38+
packageDir = path.dirname(entryPath);
39+
} catch (e) {
40+
// Ignore error, assume it is a path
41+
}
42+
43+
const objects = loadObjectConfigs(packageDir);
3344
for (const obj of Object.values(objects)) {
3445
this.registerObject(obj);
3546
}

0 commit comments

Comments
 (0)