@wabot-dev/framework 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,7 @@ import { RepositoryAdapterRegistry } from '../repository/RepositoryAdapterRegist
36
36
 
37
37
  const logger = new Logger('wabot:project-runner');
38
38
  const TEST_FILE_PATTERNS = /\.(test|spec|unit|integration|e2e|multiprocess)\.(ts|js)$/;
39
+ const DEFAULT_EXCLUDE = ['run.ts', 'cmd.ts'];
39
40
  const DEFAULT_CHAT_ADAPTERS = [
40
41
  ['../../addon/chat-bot/openia', 'OpenaiChatAdapter'],
41
42
  ['../../addon/chat-bot/openrouter', 'OpenRouterChatAdapter'],
@@ -44,12 +45,14 @@ const DEFAULT_CHAT_ADAPTERS = [
44
45
  ];
45
46
  class ProjectRunner {
46
47
  directories;
48
+ exclude;
47
49
  chatAdapters;
48
50
  connectionString;
49
51
  isPg;
50
52
  pool = null;
51
53
  constructor(config = {}) {
52
54
  this.directories = config.directories ?? ['src'];
55
+ this.exclude = [...DEFAULT_EXCLUDE, ...(config.exclude ?? [])];
53
56
  this.chatAdapters = config.chatAdapters;
54
57
  this.connectionString = this.resolveConnectionString(config.connectionString);
55
58
  this.isPg = this.connectionString != null && isPostgresUrl(this.connectionString);
@@ -86,10 +89,30 @@ class ProjectRunner {
86
89
  seen.add(d);
87
90
  return true;
88
91
  });
89
- const results = await Promise.all(roots.map((dir) => scanDir(dir).catch((err) => {
90
- logger.warn(`Could not read directory ${dir}: ${err.message}`);
91
- return [];
92
- })));
92
+ const excludedNames = new Set();
93
+ const excludedPathsByRoot = new Map();
94
+ for (const entry of this.exclude) {
95
+ if (entry.includes('/') || entry.includes('\\')) {
96
+ for (const root of roots) {
97
+ let paths = excludedPathsByRoot.get(root);
98
+ if (!paths) {
99
+ paths = new Set();
100
+ excludedPathsByRoot.set(root, paths);
101
+ }
102
+ paths.add(resolve(root, entry));
103
+ }
104
+ }
105
+ else {
106
+ excludedNames.add(entry);
107
+ }
108
+ }
109
+ const results = await Promise.all(roots.map((dir) => {
110
+ const excludedPaths = excludedPathsByRoot.get(dir) ?? new Set();
111
+ return scanDir(dir, excludedNames, excludedPaths).catch((err) => {
112
+ logger.warn(`Could not read directory ${dir}: ${err.message}`);
113
+ return [];
114
+ });
115
+ }));
93
116
  return results.flat();
94
117
  }
95
118
  async importFiles(files) {
@@ -250,14 +273,19 @@ function run(config) {
250
273
  function isPostgresUrl(cs) {
251
274
  return cs.startsWith('postgres://') || cs.startsWith('postgresql://');
252
275
  }
253
- async function scanDir(dir) {
276
+ async function scanDir(dir, excludedNames, excludedPaths) {
254
277
  const entries = await readdir(dir, { withFileTypes: true });
255
278
  const subResults = await Promise.all(entries.map(async (entry) => {
256
279
  const name = entry.name;
280
+ const fullPath = join(dir, name);
281
+ if (excludedNames.has(name))
282
+ return [];
283
+ if (excludedPaths.has(fullPath))
284
+ return [];
257
285
  if (entry.isDirectory()) {
258
286
  if (name.startsWith('__'))
259
287
  return [];
260
- return scanDir(join(dir, name));
288
+ return scanDir(fullPath, excludedNames, excludedPaths);
261
289
  }
262
290
  if (!entry.isFile())
263
291
  return [];
@@ -265,7 +293,6 @@ async function scanDir(dir) {
265
293
  return [];
266
294
  if (name.endsWith('.d.ts'))
267
295
  return [];
268
- const fullPath = join(dir, name);
269
296
  if (TEST_FILE_PATTERNS.test(fullPath))
270
297
  return [];
271
298
  return [fullPath];
@@ -1125,11 +1125,13 @@ declare function safeJsonParse<T = unknown>(json: string | undefined | null, con
1125
1125
 
1126
1126
  interface IProjectRunnerConfig {
1127
1127
  directories?: string[];
1128
+ exclude?: string[];
1128
1129
  connectionString?: string;
1129
1130
  chatAdapters?: IConstructor<IChatAdapter>[];
1130
1131
  }
1131
1132
  declare class ProjectRunner {
1132
1133
  private directories;
1134
+ private exclude;
1133
1135
  private chatAdapters;
1134
1136
  private connectionString;
1135
1137
  private isPg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",