@akanjs/devkit 0.0.54 → 0.0.55

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,592 @@
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 executors_exports = {};
29
+ __export(executors_exports, {
30
+ AppExecutor: () => AppExecutor,
31
+ DistAppExecutor: () => DistAppExecutor,
32
+ DistLibExecutor: () => DistLibExecutor,
33
+ DistPkgExecutor: () => DistPkgExecutor,
34
+ Executor: () => Executor,
35
+ LibExecutor: () => LibExecutor,
36
+ PkgExecutor: () => PkgExecutor,
37
+ SysExecutor: () => SysExecutor,
38
+ WorkspaceExecutor: () => WorkspaceExecutor
39
+ });
40
+ module.exports = __toCommonJS(executors_exports);
41
+ var import_common = require("@akanjs/common");
42
+ var import_config = require("@akanjs/config");
43
+ var import_child_process = require("child_process");
44
+ var import_fs = __toESM(require("fs"), 1);
45
+ var import_promises = __toESM(require("fs/promises"), 1);
46
+ var import_path = __toESM(require("path"), 1);
47
+ var import_baseDevEnv = require("./baseDevEnv");
48
+ var import_dependencyScanner = require("./dependencyScanner");
49
+ class Executor {
50
+ logger;
51
+ cwdPath;
52
+ constructor(name, cwdPath) {
53
+ this.logger = new import_common.Logger(name);
54
+ this.cwdPath = cwdPath;
55
+ if (!import_fs.default.existsSync(cwdPath))
56
+ import_fs.default.mkdirSync(cwdPath, { recursive: true });
57
+ }
58
+ exec(command, options = {}) {
59
+ const proc = (0, import_child_process.exec)(command, { cwd: this.cwdPath, ...options });
60
+ proc.stdout?.on("data", (data) => {
61
+ import_common.Logger.raw(data.toString());
62
+ });
63
+ proc.stderr?.on("data", (data) => {
64
+ import_common.Logger.raw(data.toString());
65
+ });
66
+ return new Promise((resolve, reject) => {
67
+ proc.on("exit", (code, signal) => {
68
+ if (!!code || signal)
69
+ reject({ code, signal });
70
+ else
71
+ resolve({ code, signal });
72
+ });
73
+ });
74
+ }
75
+ spawn(command, args = [], options = {}) {
76
+ const proc = (0, import_child_process.spawn)(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
77
+ proc.stderr?.on("data", (data) => {
78
+ import_common.Logger.raw(data.toString());
79
+ });
80
+ return new Promise((resolve, reject) => {
81
+ proc.on("exit", (code, signal) => {
82
+ if (!!code || signal)
83
+ reject({ code, signal });
84
+ else
85
+ resolve({ code, signal });
86
+ });
87
+ });
88
+ }
89
+ fork(modulePath, args = [], options = {}) {
90
+ const proc = (0, import_child_process.fork)(modulePath, args, {
91
+ cwd: this.cwdPath,
92
+ stdio: ["ignore", "inherit", "inherit", "ipc"],
93
+ ...options
94
+ });
95
+ proc.stdout?.on("data", (data) => {
96
+ import_common.Logger.raw(data.toString());
97
+ });
98
+ proc.stderr?.on("data", (data) => {
99
+ import_common.Logger.raw(data.toString());
100
+ });
101
+ return new Promise((resolve, reject) => {
102
+ proc.on("exit", (code, signal) => {
103
+ if (!!code || signal)
104
+ reject({ code, signal });
105
+ else
106
+ resolve({ code, signal });
107
+ });
108
+ });
109
+ }
110
+ mkdir(dirPath) {
111
+ const writePath = import_path.default.isAbsolute(dirPath) ? dirPath : `${this.cwdPath}/${dirPath}`;
112
+ if (!import_fs.default.existsSync(writePath))
113
+ import_fs.default.mkdirSync(writePath, { recursive: true });
114
+ this.logger.verbose(`Make directory ${writePath}`);
115
+ return this;
116
+ }
117
+ writeFile(filePath, content) {
118
+ const writePath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
119
+ const dir = import_path.default.dirname(writePath);
120
+ if (!import_fs.default.existsSync(dir))
121
+ import_fs.default.mkdirSync(dir, { recursive: true });
122
+ const contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
123
+ if (import_fs.default.existsSync(writePath)) {
124
+ const currentContent = import_fs.default.readFileSync(writePath, "utf8");
125
+ if (currentContent === contentStr)
126
+ this.logger.verbose(`File ${writePath} is unchanged`);
127
+ else {
128
+ import_fs.default.writeFileSync(writePath, contentStr, "utf8");
129
+ this.logger.verbose(`File ${writePath} is changed`);
130
+ }
131
+ } else {
132
+ import_fs.default.writeFileSync(writePath, contentStr, "utf8");
133
+ this.logger.verbose(`File ${writePath} is created`);
134
+ }
135
+ return this;
136
+ }
137
+ writeJson(filePath, content) {
138
+ this.writeFile(filePath, JSON.stringify(content, null, 2));
139
+ return this;
140
+ }
141
+ readFile(filePath) {
142
+ const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
143
+ return import_fs.default.readFileSync(readPath, "utf8");
144
+ }
145
+ readJson(filePath) {
146
+ const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
147
+ return JSON.parse(import_fs.default.readFileSync(readPath, "utf8"));
148
+ }
149
+ async cp(srcPath, destPath) {
150
+ const src = import_path.default.isAbsolute(srcPath) ? srcPath : `${this.cwdPath}/${srcPath}`;
151
+ const dest = import_path.default.isAbsolute(destPath) ? destPath : `${this.cwdPath}/${destPath}`;
152
+ await import_promises.default.cp(src, dest, { recursive: true });
153
+ }
154
+ log(msg) {
155
+ this.logger.info(msg);
156
+ return this;
157
+ }
158
+ verbose(msg) {
159
+ this.logger.verbose(msg);
160
+ return this;
161
+ }
162
+ getTsConfig(pathname) {
163
+ const tsconfig = this.readJson(pathname);
164
+ if (tsconfig.extends) {
165
+ const extendsTsconfig = this.getTsConfig(tsconfig.extends);
166
+ return {
167
+ ...extendsTsconfig,
168
+ ...tsconfig,
169
+ compilerOptions: { ...extendsTsconfig.compilerOptions, ...tsconfig.compilerOptions }
170
+ };
171
+ }
172
+ return tsconfig;
173
+ }
174
+ async #applyTemplateFile({
175
+ templatePath,
176
+ targetPath,
177
+ scanResult
178
+ }, dict = {}) {
179
+ if (targetPath.endsWith(".js")) {
180
+ const getContent = await import(templatePath);
181
+ const content = getContent.default(scanResult ?? null, dict);
182
+ const convertedTargetPath = Object.entries(dict).reduce(
183
+ (path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
184
+ targetPath.replace(".js", ".ts")
185
+ );
186
+ if (content === null)
187
+ return;
188
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
189
+ this.writeFile(convertedTargetPath, content);
190
+ } else if (targetPath.endsWith(".template")) {
191
+ const content = await import_promises.default.readFile(templatePath, "utf8");
192
+ const convertedTargetPath = Object.entries(dict).reduce(
193
+ (path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
194
+ targetPath.slice(0, -9)
195
+ );
196
+ const convertedContent = Object.entries(dict).reduce(
197
+ (content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value),
198
+ content
199
+ );
200
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
201
+ this.writeFile(convertedTargetPath, convertedContent);
202
+ }
203
+ }
204
+ async applyTemplate({
205
+ basePath,
206
+ template,
207
+ scanResult,
208
+ dict = {}
209
+ }) {
210
+ const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
211
+ if (import_fs.default.statSync(templatePath).isFile()) {
212
+ const filename = import_path.default.basename(templatePath);
213
+ await this.#applyTemplateFile({ templatePath, targetPath: import_path.default.join(basePath, filename), scanResult }, dict);
214
+ } else {
215
+ if (!import_fs.default.existsSync(basePath))
216
+ await import_promises.default.mkdir(basePath, { recursive: true });
217
+ const subdirs = await import_promises.default.readdir(templatePath);
218
+ await Promise.all(
219
+ subdirs.map(async (subdir) => {
220
+ const subpath = import_path.default.join(templatePath, subdir);
221
+ if (import_fs.default.statSync(subpath).isFile())
222
+ await this.#applyTemplateFile(
223
+ { templatePath: subpath, targetPath: import_path.default.join(basePath, subdir), scanResult },
224
+ dict
225
+ );
226
+ else
227
+ await this.applyTemplate({
228
+ basePath: import_path.default.join(basePath, subdir),
229
+ template: import_path.default.join(template, subdir),
230
+ scanResult,
231
+ dict
232
+ });
233
+ })
234
+ );
235
+ }
236
+ }
237
+ }
238
+ class WorkspaceExecutor extends Executor {
239
+ workspaceRoot;
240
+ repoName;
241
+ constructor({ workspaceRoot, repoName }) {
242
+ super(`${repoName} Executor`, workspaceRoot);
243
+ this.workspaceRoot = workspaceRoot;
244
+ this.repoName = repoName;
245
+ }
246
+ static fromRoot() {
247
+ const repoName = import_path.default.basename(process.cwd());
248
+ return new WorkspaceExecutor({ workspaceRoot: process.cwd(), repoName });
249
+ }
250
+ async scan() {
251
+ const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
252
+ const [appScanResults, libScanResults, pkgScanResults] = await Promise.all([
253
+ Promise.all(
254
+ appNames.map(async (appName) => {
255
+ const app = AppExecutor.from(this, appName);
256
+ const akanConfig = await app.getConfig("scan");
257
+ return await app.scan({ akanConfig });
258
+ })
259
+ ),
260
+ Promise.all(
261
+ libNames.map(async (libName) => {
262
+ const lib = LibExecutor.from(this, libName);
263
+ const akanConfig = await lib.getConfig("scan");
264
+ return await lib.scan({ akanConfig });
265
+ })
266
+ ),
267
+ Promise.all(
268
+ pkgNames.map(async (pkgName) => {
269
+ return await PkgExecutor.from(this, pkgName).scan();
270
+ })
271
+ )
272
+ ]);
273
+ return {
274
+ appNames,
275
+ libNames,
276
+ pkgNames,
277
+ apps: Object.fromEntries(appScanResults.map((app) => [app.name, app])),
278
+ libs: Object.fromEntries(libScanResults.map((lib) => [lib.name, lib])),
279
+ pkgs: Object.fromEntries(pkgScanResults.map((pkg) => [pkg.name, pkg]))
280
+ };
281
+ }
282
+ async getApps() {
283
+ return await this.#getDirHasFile(`${this.workspaceRoot}/apps`, "akan.config.ts");
284
+ }
285
+ async getLibs() {
286
+ return await this.#getDirHasFile(`${this.workspaceRoot}/libs`, "akan.config.ts");
287
+ }
288
+ async getSyss() {
289
+ const [appNames, libNames] = await Promise.all([this.getApps(), this.getLibs()]);
290
+ return [appNames, libNames];
291
+ }
292
+ async getPkgs() {
293
+ return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
294
+ }
295
+ async #getDirHasFile(basePath, targetFilename) {
296
+ const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
297
+ const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
298
+ const dirs = await import_promises.default.readdir(dirname);
299
+ await Promise.all(
300
+ dirs.map(async (dir) => {
301
+ if (AVOID_DIRS.includes(dir))
302
+ return;
303
+ const dirPath = import_path.default.join(dirname, dir);
304
+ if (import_fs.default.lstatSync(dirPath).isDirectory()) {
305
+ const hasTargetFile = import_fs.default.existsSync(import_path.default.join(dirPath, targetFilename));
306
+ if (hasTargetFile)
307
+ results.push(`${prefix}${dir}`);
308
+ if (maxDepth > 0)
309
+ await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
310
+ }
311
+ })
312
+ );
313
+ return results;
314
+ };
315
+ return await getDirs(basePath);
316
+ }
317
+ }
318
+ class SysExecutor extends Executor {
319
+ workspace;
320
+ name;
321
+ type;
322
+ constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
323
+ super(`${name} Sys Executor`, `${workspace.workspaceRoot}/${type}s/${name}`);
324
+ this.workspace = workspace;
325
+ this.name = name;
326
+ this.type = type;
327
+ }
328
+ async getConfig(command) {
329
+ return this.type === "app" ? await (0, import_config.getAppConfig)(this.cwdPath, { ...(0, import_baseDevEnv.getBaseDevEnv)(), appName: this.name, command }) : await (0, import_config.getLibConfig)(this.cwdPath, { ...(0, import_baseDevEnv.getBaseDevEnv)(), appName: this.name, command });
330
+ }
331
+ async scan({
332
+ tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`),
333
+ akanConfig
334
+ }, libScanResults = {}) {
335
+ if (libScanResults[this.name])
336
+ return libScanResults[this.name];
337
+ const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
338
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(this.cwdPath);
339
+ const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
340
+ const pkgPathSet = new Set(
341
+ Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", ""))
342
+ );
343
+ const libPathSet = new Set(
344
+ Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("libs/"))).map((path2) => path2.replace("/*", ""))
345
+ );
346
+ const [npmDepSet, pkgPathDepSet, libPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet, libPathSet]);
347
+ const pkgDeps = [...pkgPathDepSet].map((path2) => {
348
+ const pathSplitLength = path2.split("/").length;
349
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
350
+ });
351
+ const libDeps = [...libPathDepSet].map((path2) => {
352
+ const pathSplitLength = path2.split("/").length;
353
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
354
+ }).filter((libName) => libName !== this.name);
355
+ if (!import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar`))
356
+ import_fs.default.mkdirSync(`${this.cwdPath}/lib/__scalar`, { recursive: true });
357
+ const files = (0, import_config.getDefaultFileScan)();
358
+ const dirnames = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter(
359
+ (name) => import_fs.default.lstatSync(`${this.cwdPath}/lib/${name}`).isDirectory()
360
+ );
361
+ const databaseDirs = dirnames.filter((name) => !name.startsWith("_"));
362
+ const serviceDirs = dirnames.filter((name) => name.startsWith("_") && !name.startsWith("__"));
363
+ await Promise.all(
364
+ databaseDirs.map(async (name) => {
365
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", name));
366
+ filenames.forEach((filename) => {
367
+ if (filename.endsWith(".constant.ts"))
368
+ files.constants.databases.push(name);
369
+ else if (filename.endsWith(".dictionary.ts"))
370
+ files.dictionary.databases.push(name);
371
+ else if (filename.endsWith(".document.ts"))
372
+ files.documents.databases.push(name);
373
+ else if (filename.endsWith(".service.ts"))
374
+ files.services.databases.push(name);
375
+ else if (filename.endsWith(".signal.ts"))
376
+ files.signal.databases.push(name);
377
+ else if (filename.endsWith(".store.ts"))
378
+ files.store.databases.push(name);
379
+ else if (filename === "index.tsx")
380
+ files.components.databases.push(name);
381
+ });
382
+ })
383
+ );
384
+ await Promise.all(
385
+ serviceDirs.map(async (dirname) => {
386
+ const name = dirname.slice(1);
387
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", dirname));
388
+ filenames.forEach((filename) => {
389
+ if (filename.endsWith(".dictionary.ts"))
390
+ files.dictionary.services.push(name);
391
+ else if (filename.endsWith(".service.ts"))
392
+ files.services.services.push(name);
393
+ else if (filename.endsWith(".signal.ts"))
394
+ files.signal.services.push(name);
395
+ else if (filename.endsWith(".store.ts"))
396
+ files.store.services.push(name);
397
+ else if (filename === "index.tsx")
398
+ files.components.services.push(name);
399
+ });
400
+ })
401
+ );
402
+ const scalarDirs = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter(
403
+ (name) => !name.startsWith("_")
404
+ );
405
+ await Promise.all(
406
+ scalarDirs.map(async (name) => {
407
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib/__scalar", name));
408
+ filenames.forEach((filename) => {
409
+ if (filename.endsWith(".constant.ts"))
410
+ files.constants.scalars.push(name);
411
+ else if (filename.endsWith(".dictionary.ts"))
412
+ files.dictionary.scalars.push(name);
413
+ else if (filename.endsWith(".document.ts"))
414
+ files.documents.scalars.push(name);
415
+ else if (filename.endsWith(".service.ts"))
416
+ files.services.scalars.push(name);
417
+ else if (filename.endsWith(".signal.ts"))
418
+ files.signal.scalars.push(name);
419
+ else if (filename.endsWith(".store.ts"))
420
+ files.store.scalars.push(name);
421
+ else if (filename === "index.ts")
422
+ files.components.scalars.push(name);
423
+ });
424
+ })
425
+ );
426
+ const missingLibDeps = [];
427
+ libDeps.forEach((libName) => {
428
+ if (!akanConfig.libs.includes(libName))
429
+ missingLibDeps.push(libName);
430
+ });
431
+ if (missingLibDeps.length)
432
+ throw new Error(
433
+ `Missing libs: ${missingLibDeps.join(", ")}, add these dependencies in akan.config.ts as { libs: [...other deps, ${missingLibDeps.join(", ")}] }`
434
+ );
435
+ for (const libName of libDeps) {
436
+ if (libScanResults[libName])
437
+ continue;
438
+ const lib = new LibExecutor({ workspace: this.workspace, name: libName });
439
+ const akanConfig2 = await lib.getConfig();
440
+ libScanResults[libName] = await lib.scan({ akanConfig: akanConfig2 }, libScanResults);
441
+ }
442
+ const scanResult = {
443
+ name: this.name,
444
+ type: this.type,
445
+ akanConfig,
446
+ files,
447
+ libDeps,
448
+ pkgDeps,
449
+ dependencies: [...npmDepSet],
450
+ libs: Object.fromEntries(libDeps.map((libName) => [libName, libScanResults[libName]]))
451
+ };
452
+ await this.applyTemplate({ basePath: "lib", template: "lib", scanResult });
453
+ await this.applyTemplate({ basePath: ".", template: "server.ts", scanResult });
454
+ await this.applyTemplate({ basePath: ".", template: "client.ts", scanResult });
455
+ if (this.type === "lib")
456
+ await this.applyTemplate({ basePath: ".", template: "index.ts", scanResult });
457
+ this.writeJson(`akan.${this.type}.json`, scanResult);
458
+ return scanResult;
459
+ }
460
+ async getDatabaseModules() {
461
+ const databaseModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
462
+ return databaseModules;
463
+ }
464
+ async getServiceModules() {
465
+ const serviceModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
466
+ return serviceModules;
467
+ }
468
+ async getScalarModules() {
469
+ const scalarModules = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
470
+ return scalarModules;
471
+ }
472
+ }
473
+ class AppExecutor extends SysExecutor {
474
+ constructor({ workspace, name }) {
475
+ super({ workspace, name, type: "app" });
476
+ }
477
+ static from(executor, name) {
478
+ if (executor instanceof WorkspaceExecutor)
479
+ return new AppExecutor({ workspace: executor, name });
480
+ return new AppExecutor({ workspace: executor.workspace, name });
481
+ }
482
+ async getConfig(command) {
483
+ return await (0, import_config.getAppConfig)(this.cwdPath, { ...(0, import_baseDevEnv.getBaseDevEnv)(), appName: this.name, command });
484
+ }
485
+ async syncAssets(libDeps) {
486
+ const projectPublicLibPath = `${this.cwdPath}/public/libs`;
487
+ if (import_fs.default.existsSync(projectPublicLibPath))
488
+ await import_promises.default.rm(projectPublicLibPath, { recursive: true });
489
+ const targetDeps = libDeps.filter((dep) => import_fs.default.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
490
+ await Promise.all(targetDeps.map((dep) => import_promises.default.mkdir(`${projectPublicLibPath}/${dep}`, { recursive: true })));
491
+ await Promise.all(
492
+ targetDeps.map(
493
+ (dep) => import_promises.default.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`, {
494
+ recursive: true
495
+ })
496
+ )
497
+ );
498
+ }
499
+ }
500
+ class DistAppExecutor extends Executor {
501
+ name;
502
+ constructor({ workspace, name }) {
503
+ super(`${name} Dist App Executor`, `${workspace.workspaceRoot}/dist/apps/${name}`);
504
+ this.name = name;
505
+ }
506
+ static from(executor, name) {
507
+ if (executor instanceof WorkspaceExecutor)
508
+ return new DistAppExecutor({ workspace: executor, name });
509
+ return new DistAppExecutor({ workspace: executor.workspace, name });
510
+ }
511
+ }
512
+ class LibExecutor extends SysExecutor {
513
+ workspaceRoot;
514
+ repoName;
515
+ constructor({ workspace, name }) {
516
+ super({ workspace, name, type: "lib" });
517
+ }
518
+ static from(executor, name) {
519
+ if (executor instanceof WorkspaceExecutor)
520
+ return new LibExecutor({ workspace: executor, name });
521
+ return new LibExecutor({ workspace: executor.workspace, name });
522
+ }
523
+ async getConfig(command) {
524
+ return await (0, import_config.getLibConfig)(this.cwdPath, { ...(0, import_baseDevEnv.getBaseDevEnv)(), appName: this.name, command });
525
+ }
526
+ }
527
+ class DistLibExecutor extends Executor {
528
+ name;
529
+ constructor({ workspace, name }) {
530
+ super(`${name} Dist Lib Executor`, `${workspace.workspaceRoot}/dist/libs/${name}`);
531
+ this.name = name;
532
+ }
533
+ static from(executor, name) {
534
+ if (executor instanceof WorkspaceExecutor)
535
+ return new DistAppExecutor({ workspace: executor, name });
536
+ return new DistLibExecutor({ workspace: executor.workspace, name });
537
+ }
538
+ }
539
+ class PkgExecutor extends Executor {
540
+ workspace;
541
+ name;
542
+ constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
543
+ super(`${name} Pkg Executor`, `${workspace.workspaceRoot}/pkgs/${name}`);
544
+ this.workspace = workspace;
545
+ this.name = name;
546
+ }
547
+ static from(executor, name) {
548
+ if (executor instanceof WorkspaceExecutor)
549
+ return new PkgExecutor({ workspace: executor, name });
550
+ return new PkgExecutor({ workspace: executor.workspace, name });
551
+ }
552
+ async scan({
553
+ packageJson = this.readJson(`${this.cwdPath}/package.json`),
554
+ tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`)
555
+ } = {}) {
556
+ const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
557
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(this.cwdPath);
558
+ const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
559
+ const pkgPathSet = new Set(
560
+ Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", ""))
561
+ );
562
+ const [npmDepSet, pkgPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet]);
563
+ const pkgDeps = [...pkgPathDepSet].map((path2) => {
564
+ const pathSplitLength = path2.split("/").length;
565
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
566
+ }).filter((pkg) => pkg !== this.name);
567
+ const pkgScanResult = {
568
+ name: this.name,
569
+ pkgDeps,
570
+ dependencies: [...npmDepSet]
571
+ };
572
+ return pkgScanResult;
573
+ }
574
+ }
575
+ class DistPkgExecutor extends Executor {
576
+ workspaceRoot;
577
+ repoName;
578
+ name;
579
+ constructor({ workspaceRoot, repoName, name }) {
580
+ super(`${name} Dist Pkg Executor`, `${workspaceRoot}/dist/pkgs/${name}`);
581
+ this.workspaceRoot = workspaceRoot;
582
+ this.repoName = repoName;
583
+ this.name = name;
584
+ }
585
+ static from(workspaceExecutor, name) {
586
+ return new DistPkgExecutor({
587
+ workspaceRoot: workspaceExecutor.workspaceRoot,
588
+ repoName: workspaceExecutor.repoName,
589
+ name
590
+ });
591
+ }
592
+ }
@@ -0,0 +1,99 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var extractDeps_exports = {};
19
+ __export(extractDeps_exports, {
20
+ extractDependencies: () => extractDependencies
21
+ });
22
+ module.exports = __toCommonJS(extractDeps_exports);
23
+ const NODE_NATIVE_MODULE_SET = /* @__PURE__ */ new Set([
24
+ "assert",
25
+ "async_hooks",
26
+ "buffer",
27
+ "child_process",
28
+ "cluster",
29
+ "console",
30
+ "constants",
31
+ "crypto",
32
+ "dgram",
33
+ "dns",
34
+ "domain",
35
+ "events",
36
+ "fs",
37
+ "http",
38
+ "http2",
39
+ "https",
40
+ "inspector",
41
+ "module",
42
+ "net",
43
+ "os",
44
+ "path",
45
+ "perf_hooks",
46
+ "process",
47
+ "punycode",
48
+ "querystring",
49
+ "readline",
50
+ "repl",
51
+ "stream",
52
+ "string_decoder",
53
+ "timers",
54
+ "tls",
55
+ "trace_events",
56
+ "tty",
57
+ "url",
58
+ "util",
59
+ "v8",
60
+ "vm",
61
+ "wasi",
62
+ "worker_threads",
63
+ "zlib"
64
+ ]);
65
+ const extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) => {
66
+ if (!pacakgeJson.dependencies)
67
+ throw new Error("No dependencies found in package.json");
68
+ const dependencies = new Set(defaultDependencies);
69
+ const existingDependencies = /* @__PURE__ */ new Set([
70
+ ...Object.keys(pacakgeJson.dependencies ?? {}),
71
+ ...Object.keys(pacakgeJson.devDependencies ?? {})
72
+ ]);
73
+ const versionObj = {
74
+ ...pacakgeJson.dependencies ?? {},
75
+ ...pacakgeJson.devDependencies ?? {}
76
+ };
77
+ const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
78
+ for (const { text } of filepaths) {
79
+ let requireMatch;
80
+ while ((requireMatch = requireRegex.exec(text)) !== null) {
81
+ const moduleName = requireMatch[1];
82
+ const moduleNameParts = moduleName.split("/");
83
+ const subModuleLength = moduleNameParts.length;
84
+ for (let i = 0; i < subModuleLength; i++) {
85
+ const libName = moduleNameParts.slice(0, i + 1).join("/");
86
+ if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
87
+ dependencies.add(libName);
88
+ }
89
+ }
90
+ }
91
+ return Object.fromEntries(
92
+ [...dependencies].sort().map((dep) => {
93
+ const version = versionObj[dep];
94
+ if (!version)
95
+ throw new Error(`No version found for ${dep}`);
96
+ return [dep, version];
97
+ })
98
+ );
99
+ };