@akanjs/devkit 0.9.41 → 0.9.42

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.
@@ -0,0 +1,487 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var scanInfo_exports = {};
29
+ __export(scanInfo_exports, {
30
+ AppInfo: () => AppInfo,
31
+ LibInfo: () => LibInfo,
32
+ PkgInfo: () => PkgInfo,
33
+ WorkspaceInfo: () => WorkspaceInfo
34
+ });
35
+ module.exports = __toCommonJS(scanInfo_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_dependencyScanner = require("./dependencyScanner");
38
+ var import_executors = require("./executors");
39
+ const scalarFileTypes = ["constant", "dictionary", "document", "template", "unit", "util", "view", "zone"];
40
+ const serviceFileTypes = [
41
+ "dictionary",
42
+ "service",
43
+ "signal",
44
+ "store",
45
+ "template",
46
+ "unit",
47
+ "util",
48
+ "view",
49
+ "zone"
50
+ ];
51
+ const databaseFileTypes = [
52
+ "constant",
53
+ "dictionary",
54
+ "document",
55
+ "service",
56
+ "signal",
57
+ "store",
58
+ "template",
59
+ "unit",
60
+ "util",
61
+ "view",
62
+ "zone"
63
+ ];
64
+ class ScanInfo {
65
+ scanResult;
66
+ name;
67
+ scalar = /* @__PURE__ */ new Map();
68
+ service = /* @__PURE__ */ new Map();
69
+ database = /* @__PURE__ */ new Map();
70
+ file = Object.fromEntries(
71
+ databaseFileTypes.map((type) => [
72
+ type,
73
+ { all: /* @__PURE__ */ new Set(), databases: /* @__PURE__ */ new Set(), services: /* @__PURE__ */ new Set(), scalars: /* @__PURE__ */ new Set() }
74
+ ])
75
+ );
76
+ constants = /* @__PURE__ */ new Set();
77
+ dictionaries = /* @__PURE__ */ new Set();
78
+ documents = /* @__PURE__ */ new Set();
79
+ services = /* @__PURE__ */ new Set();
80
+ signals = /* @__PURE__ */ new Set();
81
+ stores = /* @__PURE__ */ new Set();
82
+ templates = /* @__PURE__ */ new Set();
83
+ units = /* @__PURE__ */ new Set();
84
+ utils = /* @__PURE__ */ new Set();
85
+ views = /* @__PURE__ */ new Set();
86
+ zones = /* @__PURE__ */ new Set();
87
+ static async getScanResult(exec) {
88
+ const akanConfig = await exec.getConfig();
89
+ const tsconfig = exec.getTsConfig();
90
+ const rootPackageJson = exec.workspace.getPackageJson();
91
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(exec.cwdPath, { tsconfig, rootPackageJson });
92
+ const { pkgDeps, libDeps, npmDeps } = await scanner.getMonorepoDependencies(exec.name);
93
+ const files = {
94
+ constant: { databases: [], scalars: [] },
95
+ dictionary: { databases: [], services: [], scalars: [] },
96
+ document: { databases: [], scalars: [] },
97
+ service: { databases: [], services: [] },
98
+ signal: { databases: [], services: [] },
99
+ store: { databases: [], services: [] },
100
+ template: { databases: [], services: [], scalars: [] },
101
+ unit: { databases: [], services: [], scalars: [] },
102
+ util: { databases: [], services: [], scalars: [] },
103
+ view: { databases: [], services: [], scalars: [] },
104
+ zone: { databases: [], services: [], scalars: [] }
105
+ };
106
+ const [{ dirs: dirnames }, scalarDirs] = await Promise.all([
107
+ exec.getFilesAndDirs("lib"),
108
+ exec.readdir("lib/__scalar")
109
+ ]);
110
+ const databaseDirs = [];
111
+ const serviceDirs = [];
112
+ dirnames.forEach((name) => {
113
+ if (name.startsWith("_")) {
114
+ if (name.startsWith("__"))
115
+ return;
116
+ else
117
+ serviceDirs.push(name);
118
+ } else
119
+ databaseDirs.push(name);
120
+ });
121
+ await Promise.all([
122
+ ...databaseDirs.map(async (name) => {
123
+ const filenames = await exec.readdir(import_path.default.join("lib", name));
124
+ filenames.forEach((filename) => {
125
+ if (filename.endsWith(".constant.ts"))
126
+ files.constant.databases.push(name);
127
+ else if (filename.endsWith(".dictionary.ts"))
128
+ files.dictionary.databases.push(name);
129
+ else if (filename.endsWith(".document.ts"))
130
+ files.document.databases.push(name);
131
+ else if (filename.endsWith(".service.ts"))
132
+ files.service.databases.push(name);
133
+ else if (filename.endsWith(".signal.ts"))
134
+ files.signal.databases.push(name);
135
+ else if (filename.endsWith(".store.ts"))
136
+ files.store.databases.push(name);
137
+ else if (filename.endsWith(".Template.tsx"))
138
+ files.template.databases.push(name);
139
+ else if (filename.endsWith(".Unit.tsx"))
140
+ files.unit.databases.push(name);
141
+ else if (filename.endsWith(".Util.tsx"))
142
+ files.util.databases.push(name);
143
+ else if (filename.endsWith(".View.tsx"))
144
+ files.view.databases.push(name);
145
+ else if (filename.endsWith(".Zone.tsx"))
146
+ files.zone.databases.push(name);
147
+ });
148
+ }),
149
+ ...serviceDirs.map(async (dirname) => {
150
+ const name = dirname.slice(1);
151
+ const filenames = await exec.readdir(import_path.default.join("lib", dirname));
152
+ filenames.forEach((filename) => {
153
+ if (filename.endsWith(".dictionary.ts"))
154
+ files.dictionary.services.push(name);
155
+ else if (filename.endsWith(".service.ts"))
156
+ files.service.services.push(name);
157
+ else if (filename.endsWith(".signal.ts"))
158
+ files.signal.services.push(name);
159
+ else if (filename.endsWith(".store.ts"))
160
+ files.store.services.push(name);
161
+ else if (filename.endsWith(".Template.tsx"))
162
+ files.template.services.push(name);
163
+ else if (filename.endsWith(".Unit.tsx"))
164
+ files.unit.services.push(name);
165
+ else if (filename.endsWith(".Util.tsx"))
166
+ files.util.services.push(name);
167
+ else if (filename.endsWith(".View.tsx"))
168
+ files.view.services.push(name);
169
+ else if (filename.endsWith(".Zone.tsx"))
170
+ files.zone.services.push(name);
171
+ });
172
+ }),
173
+ ...scalarDirs.map(async (name) => {
174
+ const filenames = await exec.readdir(import_path.default.join("lib/__scalar", name));
175
+ filenames.forEach((filename) => {
176
+ if (filename.endsWith(".constant.ts"))
177
+ files.constant.scalars.push(name);
178
+ else if (filename.endsWith(".dictionary.ts"))
179
+ files.dictionary.scalars.push(name);
180
+ else if (filename.endsWith(".document.ts"))
181
+ files.document.scalars.push(name);
182
+ else if (filename.endsWith(".Template.tsx"))
183
+ files.template.scalars.push(name);
184
+ else if (filename.endsWith(".Unit.tsx"))
185
+ files.unit.scalars.push(name);
186
+ else if (filename.endsWith(".Util.tsx"))
187
+ files.util.scalars.push(name);
188
+ else if (filename.endsWith(".View.tsx"))
189
+ files.view.scalars.push(name);
190
+ else if (filename.endsWith(".Zone.tsx"))
191
+ files.zone.scalars.push(name);
192
+ });
193
+ })
194
+ ]);
195
+ const missingLibDeps = [];
196
+ libDeps.forEach((libName) => {
197
+ if (!akanConfig.libs.includes(libName))
198
+ missingLibDeps.push(libName);
199
+ });
200
+ if (missingLibDeps.length)
201
+ throw new Error(
202
+ `Missing libs: ${missingLibDeps.join(", ")}, add these dependencies in akan.config.ts as { libs: [...other deps, ${missingLibDeps.join(", ")}] }`
203
+ );
204
+ const scanResult = {
205
+ name: exec.name,
206
+ type: exec.type,
207
+ repoName: exec.workspace.repoName,
208
+ serveDomain: exec.workspace.getBaseDevEnv().serveDomain,
209
+ akanConfig,
210
+ files,
211
+ libDeps,
212
+ pkgDeps,
213
+ dependencies: npmDeps.filter((dep) => !dep.startsWith("@akanjs"))
214
+ };
215
+ return scanResult;
216
+ }
217
+ constructor(scanResult) {
218
+ this.name = scanResult.name;
219
+ this.scanResult = scanResult;
220
+ Object.entries(scanResult.files).forEach(
221
+ ([key, value]) => {
222
+ const { databases, services, scalars } = value;
223
+ databases.forEach((modelName) => {
224
+ const model = this.database.get(modelName) ?? /* @__PURE__ */ new Set();
225
+ model.add(key);
226
+ this.database.set(modelName, model);
227
+ this.file[key].all.add(modelName);
228
+ this.file[key].databases.add(modelName);
229
+ });
230
+ services?.forEach((serviceName) => {
231
+ const service = this.service.get(serviceName) ?? /* @__PURE__ */ new Set();
232
+ service.add(key);
233
+ this.service.set(serviceName, service);
234
+ this.file[key].all.add(serviceName);
235
+ this.file[key].services.add(serviceName);
236
+ });
237
+ scalars?.forEach((scalarName) => {
238
+ const scalar = this.scalar.get(scalarName) ?? /* @__PURE__ */ new Set();
239
+ scalar.add(key);
240
+ this.scalar.set(scalarName, scalar);
241
+ this.file[key].all.add(scalarName);
242
+ this.file[key].scalars.add(scalarName);
243
+ });
244
+ }
245
+ );
246
+ }
247
+ getScanResult() {
248
+ return this.scanResult;
249
+ }
250
+ getDatabaseModules() {
251
+ return [...this.database.keys()];
252
+ }
253
+ getServiceModules() {
254
+ return [...this.service.keys()];
255
+ }
256
+ getScalarModules() {
257
+ return [...this.scalar.keys()];
258
+ }
259
+ }
260
+ class AppInfo extends ScanInfo {
261
+ type = "app";
262
+ exec;
263
+ akanConfig;
264
+ static appInfos = /* @__PURE__ */ new Map();
265
+ static async fromExecutor(exec, options = {}) {
266
+ const existingAppInfo = this.appInfos.get(exec.name);
267
+ if (existingAppInfo && !options.refresh)
268
+ return existingAppInfo;
269
+ const scanResult = await super.getScanResult(exec);
270
+ await Promise.all(
271
+ scanResult.libDeps.map(async (libName) => {
272
+ LibInfo.loadedLibs.add(libName);
273
+ const libExecutor = import_executors.LibExecutor.from(exec, libName);
274
+ LibInfo.libInfos.set(libName, await LibInfo.fromExecutor(libExecutor));
275
+ })
276
+ );
277
+ const appInfo = new AppInfo(exec, scanResult);
278
+ this.appInfos.set(exec.name, appInfo);
279
+ return appInfo;
280
+ }
281
+ constructor(exec, scanResult) {
282
+ super(scanResult);
283
+ this.exec = exec;
284
+ this.akanConfig = scanResult.akanConfig;
285
+ }
286
+ getScanResult() {
287
+ return this.scanResult;
288
+ }
289
+ #sortedLibs = null;
290
+ #getSortedLibs() {
291
+ if (this.#sortedLibs)
292
+ return this.#sortedLibs;
293
+ const libIndices = LibInfo.getSortedLibIndices();
294
+ this.#sortedLibs = this.akanConfig.libs.sort((libNameA, libNameB) => {
295
+ const indexA = libIndices.get(libNameA);
296
+ const indexB = libIndices.get(libNameB);
297
+ if (indexA === void 0 || indexB === void 0)
298
+ throw new Error(`LibInfo not found: ${libNameA} or ${libNameB}`);
299
+ return indexA - indexB;
300
+ });
301
+ return this.#sortedLibs;
302
+ }
303
+ getLibs() {
304
+ return this.#getSortedLibs();
305
+ }
306
+ getLibInfo(libName) {
307
+ const libSet = new Set(this.#getSortedLibs());
308
+ if (!libSet.has(libName))
309
+ throw new Error(`LibInfo is invalid: ${libName}`);
310
+ return LibInfo.libInfos.get(libName);
311
+ }
312
+ getLibInfos() {
313
+ return new Map(
314
+ this.#getSortedLibs().map((libName) => {
315
+ const libInfo = LibInfo.libInfos.get(libName);
316
+ if (!libInfo)
317
+ throw new Error(`LibInfo not found: ${libName}`);
318
+ return [libName, libInfo];
319
+ })
320
+ );
321
+ }
322
+ }
323
+ class LibInfo extends ScanInfo {
324
+ type = "lib";
325
+ exec;
326
+ akanConfig;
327
+ static loadedLibs = /* @__PURE__ */ new Set();
328
+ static libInfos = /* @__PURE__ */ new Map();
329
+ static #sortedLibIndices = null;
330
+ static getSortedLibIndices() {
331
+ if (this.#sortedLibIndices)
332
+ return this.#sortedLibIndices;
333
+ this.#sortedLibIndices = new Map(
334
+ [...this.libInfos.entries()].sort(([_, libInfoA], [__, libInfoB]) => libInfoA.akanConfig.libs.includes(libInfoB.name) ? 1 : -1).map(([libName], index) => [libName, index])
335
+ );
336
+ return this.#sortedLibIndices;
337
+ }
338
+ static async fromExecutor(exec, { refresh } = {}) {
339
+ const existingLibInfo = this.libInfos.get(exec.name);
340
+ if (existingLibInfo && !refresh)
341
+ return existingLibInfo;
342
+ const scanResult = await super.getScanResult(exec);
343
+ await Promise.all(
344
+ scanResult.libDeps.filter((libName) => !this.loadedLibs.has(libName)).map(async (libName) => {
345
+ this.loadedLibs.add(libName);
346
+ this.libInfos.set(libName, await LibInfo.fromExecutor(exec));
347
+ })
348
+ );
349
+ const libInfo = new LibInfo(exec, scanResult);
350
+ this.libInfos.set(exec.name, libInfo);
351
+ this.#sortedLibIndices = null;
352
+ return libInfo;
353
+ }
354
+ constructor(exec, scanResult) {
355
+ super(scanResult);
356
+ this.exec = exec;
357
+ this.akanConfig = scanResult.akanConfig;
358
+ }
359
+ getScanResult() {
360
+ return this.scanResult;
361
+ }
362
+ #sortedLibs = null;
363
+ #getSortedLibs() {
364
+ if (this.#sortedLibs)
365
+ return this.#sortedLibs;
366
+ const libs = LibInfo.getSortedLibIndices();
367
+ this.#sortedLibs = this.akanConfig.libs.sort((libNameA, libNameB) => {
368
+ const indexA = libs.get(libNameA);
369
+ const indexB = libs.get(libNameB);
370
+ if (indexA === void 0 || indexB === void 0)
371
+ throw new Error(`LibInfo not found: ${libNameA} or ${libNameB}`);
372
+ return indexA - indexB;
373
+ });
374
+ return this.#sortedLibs;
375
+ }
376
+ getLibs() {
377
+ return this.#getSortedLibs();
378
+ }
379
+ getLibInfo(libName) {
380
+ if (!this.getScanResult().akanConfig.libs.includes(libName))
381
+ return void 0;
382
+ const libSet = new Set(this.#getSortedLibs());
383
+ if (!libSet.has(libName))
384
+ throw new Error(`LibInfo is invalid: ${libName}`);
385
+ return LibInfo.libInfos.get(libName);
386
+ }
387
+ getLibInfos() {
388
+ return new Map(
389
+ this.#getSortedLibs().map((libName) => {
390
+ const libInfo = LibInfo.libInfos.get(libName);
391
+ if (!libInfo)
392
+ throw new Error(`LibInfo not found: ${libName}`);
393
+ return [libName, libInfo];
394
+ })
395
+ );
396
+ }
397
+ }
398
+ class PkgInfo {
399
+ exec;
400
+ name;
401
+ scanResult;
402
+ static async getScanResult(exec) {
403
+ const tsconfig = exec.getTsConfig();
404
+ const rootPackageJson = exec.workspace.getPackageJson();
405
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(exec.cwdPath, { tsconfig, rootPackageJson });
406
+ const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
407
+ const pkgPathSet = new Set(
408
+ Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path2) => tsconfig.compilerOptions.paths?.[path2]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", ""))
409
+ );
410
+ const [npmDepSet, pkgPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet]);
411
+ const pkgDeps = [...pkgPathDepSet].map((path2) => {
412
+ const pathSplitLength = path2.split("/").length;
413
+ return (tsconfig.compilerOptions.paths?.[path2]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
414
+ }).filter((pkg) => pkg !== this.name);
415
+ const pkgScanResult = {
416
+ name: this.name,
417
+ pkgDeps,
418
+ dependencies: [...npmDepSet]
419
+ };
420
+ return pkgScanResult;
421
+ }
422
+ static #pkgInfos = /* @__PURE__ */ new Map();
423
+ static async fromExecutor(exec, options = {}) {
424
+ const existingPkgInfo = this.#pkgInfos.get(exec.name);
425
+ if (existingPkgInfo && !options.refresh)
426
+ return existingPkgInfo;
427
+ const scanResult = await this.getScanResult(exec);
428
+ const pkgInfo = new PkgInfo(exec, scanResult);
429
+ this.#pkgInfos.set(exec.name, pkgInfo);
430
+ return pkgInfo;
431
+ }
432
+ constructor(exec, scanResult) {
433
+ this.exec = exec;
434
+ this.name = exec.name;
435
+ this.scanResult = scanResult;
436
+ }
437
+ getScanResult() {
438
+ return this.scanResult;
439
+ }
440
+ }
441
+ class WorkspaceInfo {
442
+ constructor(appInfos = /* @__PURE__ */ new Map(), libInfos = /* @__PURE__ */ new Map(), pkgInfos = /* @__PURE__ */ new Map()) {
443
+ this.appInfos = appInfos;
444
+ this.libInfos = libInfos;
445
+ this.pkgInfos = pkgInfos;
446
+ }
447
+ static #workspaceInfos = /* @__PURE__ */ new Map();
448
+ static async fromExecutor(exec, options = {}) {
449
+ const existingWorkspaceInfo = this.#workspaceInfos.get(exec.name);
450
+ if (existingWorkspaceInfo && !options.refresh)
451
+ return existingWorkspaceInfo;
452
+ const [appNames, libNames, pkgNames] = await Promise.all([exec.getApps(), exec.getLibs(), exec.getPkgs()]);
453
+ const [appInfos, libInfos, pkgInfos] = await Promise.all([
454
+ Promise.all(
455
+ appNames.map(async (appName) => {
456
+ const app = import_executors.AppExecutor.from(exec, appName);
457
+ return await app.scan();
458
+ })
459
+ ),
460
+ Promise.all(
461
+ libNames.map(async (libName) => {
462
+ const lib = import_executors.LibExecutor.from(exec, libName);
463
+ return await lib.scan();
464
+ })
465
+ ),
466
+ Promise.all(
467
+ pkgNames.map(async (pkgName) => {
468
+ return await import_executors.PkgExecutor.from(exec, pkgName).scan();
469
+ })
470
+ )
471
+ ]);
472
+ const workspaceInfo = new WorkspaceInfo(
473
+ new Map(appInfos.map((app) => [app.exec.name, app])),
474
+ new Map(libInfos.map((lib) => [lib.exec.name, lib])),
475
+ new Map(pkgInfos.map((pkg) => [pkg.exec.name, pkg]))
476
+ );
477
+ this.#workspaceInfos.set(exec.name, workspaceInfo);
478
+ return workspaceInfo;
479
+ }
480
+ }
481
+ // Annotate the CommonJS export names for ESM import in node:
482
+ 0 && (module.exports = {
483
+ AppInfo,
484
+ LibInfo,
485
+ PkgInfo,
486
+ WorkspaceInfo
487
+ });
@@ -72,8 +72,8 @@ class Builder {
72
72
  }
73
73
  };
74
74
  buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
75
- this.#distExecutor.writeJson("package.json", pkgPackageJson);
76
- this.#executor.writeJson("package.json", pkgPackageJson);
75
+ this.#distExecutor.setPackageJson(pkgPackageJson);
76
+ this.#executor.setPackageJson(pkgPackageJson);
77
77
  }
78
78
  }
79
79
  export {
@@ -184,8 +184,18 @@ const runCommands = async (...commands) => {
184
184
  });
185
185
  const __dirname = getDirname(import.meta.url);
186
186
  const hasPackageJson = fs.existsSync(`${__dirname}/../package.json`);
187
- const version = hasPackageJson ? JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, "utf8")).version : "0.0.1";
188
- program.version(version).description("Akan CLI");
187
+ process.env.AKAN_VERSION = hasPackageJson ? JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, "utf8")).version : "0.0.1";
188
+ program.version(process.env.AKAN_VERSION).description("Akan CLI");
189
+ const akanBasePackageJson = fs.existsSync("./node_modules/@akanjs/base/package.json") ? JSON.parse(fs.readFileSync("./node_modules/@akanjs/base/package.json", "utf8")) : null;
190
+ if (akanBasePackageJson && akanBasePackageJson.version !== process.env.AKAN_VERSION) {
191
+ Logger.rawLog(
192
+ chalk.yellow(
193
+ `
194
+ Akan CLI version is mismatch with installed package. ${process.env.AKAN_VERSION} (global) vs ${akanBasePackageJson.version} (base)
195
+ It may cause unexpected behavior. Run \`akan update\` to update latest akanjs.`
196
+ )
197
+ );
198
+ }
189
199
  for (const command of commands) {
190
200
  const targetMetas = getTargetMetas(command);
191
201
  for (const targetMeta of targetMetas) {
@@ -248,7 +258,8 @@ const runCommands = async (...commands) => {
248
258
  Logger.rawLog();
249
259
  } catch (e) {
250
260
  const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
251
- Logger.error(`Command Error: ${chalk.red(errMsg)}`);
261
+ Logger.rawLog(`
262
+ ${chalk.red(errMsg)}`);
252
263
  throw e;
253
264
  }
254
265
  });
@@ -2,11 +2,37 @@ import * as fs from "fs";
2
2
  import * as path from "path";
3
3
  import * as ts from "typescript";
4
4
  class TypeScriptDependencyScanner {
5
- constructor(directory) {
6
- this.directory = directory;
7
- }
8
5
  #fileDependencies = /* @__PURE__ */ new Map();
9
6
  #visitedFiles = /* @__PURE__ */ new Set();
7
+ directory;
8
+ tsconfig;
9
+ rootPackageJson;
10
+ constructor(directory, { tsconfig, rootPackageJson }) {
11
+ this.directory = directory;
12
+ this.tsconfig = tsconfig;
13
+ this.rootPackageJson = rootPackageJson;
14
+ }
15
+ async getMonorepoDependencies(projectName) {
16
+ const npmSet = new Set(
17
+ Object.keys({ ...this.rootPackageJson.dependencies, ...this.rootPackageJson.devDependencies })
18
+ );
19
+ const pkgPathSet = new Set(
20
+ Object.keys(this.tsconfig.compilerOptions.paths ?? {}).filter((path2) => this.tsconfig.compilerOptions.paths?.[path2]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", ""))
21
+ );
22
+ const libPathSet = new Set(
23
+ Object.keys(this.tsconfig.compilerOptions.paths ?? {}).filter((path2) => this.tsconfig.compilerOptions.paths?.[path2]?.some((resolve) => resolve.startsWith("libs/"))).map((path2) => path2.replace("/*", ""))
24
+ );
25
+ const [npmDepSet, pkgPathDepSet, libPathDepSet] = await this.getImportSets([npmSet, pkgPathSet, libPathSet]);
26
+ const pkgDeps = [...pkgPathDepSet].map((path2) => {
27
+ const pathSplitLength = path2.split("/").length;
28
+ return (this.tsconfig.compilerOptions.paths?.[path2]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
29
+ });
30
+ const libDeps = [...libPathDepSet].map((path2) => {
31
+ const pathSplitLength = path2.split("/").length;
32
+ return (this.tsconfig.compilerOptions.paths?.[path2]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
33
+ }).filter((libName) => libName !== projectName);
34
+ return { pkgDeps, libDeps, npmDeps: [...npmDepSet] };
35
+ }
10
36
  async getImportSets(depSets) {
11
37
  const fileDependencies = await this.getDependencies();
12
38
  const importedDepSets = new Array(depSets.length);