@akanjs/devkit 1.0.20 → 2.1.0-rc.1
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.
- package/README.ko.md +65 -0
- package/README.md +62 -6
- package/aiEditor.ts +304 -0
- package/akanApp/akanApp.host.ts +393 -0
- package/akanApp/index.ts +1 -0
- package/akanConfig/akanConfig.test.ts +236 -0
- package/akanConfig/akanConfig.ts +384 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/types.ts +23 -0
- package/applicationBuildReporter.ts +69 -0
- package/applicationBuildRunner.ts +302 -0
- package/applicationReleasePackager.ts +206 -0
- package/artifact/implicitRootLayout.ts +155 -0
- package/artifact/index.ts +1 -0
- package/artifact/routeSeedIndex.test.ts +98 -0
- package/artifact/routeSeedIndex.ts +130 -0
- package/auth.ts +41 -0
- package/builder.ts +164 -0
- package/capacitor.base.config.ts +88 -0
- package/capacitorApp.ts +440 -0
- package/commandDecorators/argMeta.ts +102 -0
- package/commandDecorators/command.ts +351 -0
- package/commandDecorators/commandBuilder.ts +224 -0
- package/commandDecorators/commandDecorators.test.ts +212 -0
- package/commandDecorators/commandMeta.ts +7 -0
- package/commandDecorators/dependencyBuilder.ts +100 -0
- package/{esm/src/commandDecorators/helpFormatter.js → commandDecorators/helpFormatter.ts} +100 -47
- package/{esm/src/commandDecorators/index.js → commandDecorators/index.ts} +4 -2
- package/commandDecorators/targetMeta.ts +31 -0
- package/commandDecorators/types.ts +10 -0
- package/constants.ts +25 -0
- package/createTunnel.ts +36 -0
- package/dependencyScanner.ts +357 -0
- package/devkitUtils.test.ts +259 -0
- package/executors.test.ts +315 -0
- package/executors.ts +1390 -0
- package/{esm/src/extractDeps.js → extractDeps.ts} +26 -20
- package/{esm/src/fileEditor.js → fileEditor.ts} +51 -32
- package/fileSys.ts +39 -0
- package/frontendBuild/allRoutesBuilder.ts +103 -0
- package/frontendBuild/buildRouteClient.test.ts +190 -0
- package/frontendBuild/clientBuildTypes.ts +114 -0
- package/frontendBuild/clientEntriesBundler.ts +303 -0
- package/frontendBuild/clientEntryDiscovery.ts +199 -0
- package/frontendBuild/csrArtifactBuilder.ts +237 -0
- package/frontendBuild/cssCompiler.ts +286 -0
- package/frontendBuild/cssImportResolver.ts +116 -0
- package/frontendBuild/fontOptimizer.ts +427 -0
- package/frontendBuild/frontendBuild.test.ts +204 -0
- package/frontendBuild/hmrChangeClassifier.ts +28 -0
- package/frontendBuild/hmrWatcher.ts +102 -0
- package/frontendBuild/index.ts +18 -0
- package/frontendBuild/pagesBundleBuilder.ts +137 -0
- package/frontendBuild/pagesEntrySourceGenerator.ts +37 -0
- package/frontendBuild/precompressArtifacts.ts +59 -0
- package/frontendBuild/routeClientBuilder.ts +290 -0
- package/frontendBuild/routesManifestArtifactSerializer.ts +62 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +139 -0
- package/frontendBuild/vendorSpecifiers.ts +16 -0
- package/frontendBuild/watchRootResolver.ts +28 -0
- package/getCredentials.ts +19 -0
- package/getDirname.ts +3 -0
- package/getModelFileData.ts +59 -0
- package/getRelatedCnsts.ts +313 -0
- package/guideline.ts +19 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +51 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +152 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +331 -0
- package/incrementalBuilder/index.ts +1 -0
- package/{esm/src/index.js → index.ts} +28 -15
- package/lint/no-deep-internal-import.grit +25 -0
- package/lint/no-import-client-functions.grit +32 -0
- package/lint/no-import-external-library.grit +21 -0
- package/lint/no-js-private-class-method.grit +42 -0
- package/lint/no-use-client-in-server.grit +7 -0
- package/lint/non-scalar-props-restricted.grit +13 -0
- package/linter.ts +271 -0
- package/mobile/index.ts +1 -0
- package/mobile/mobileTarget.test.ts +53 -0
- package/mobile/mobileTarget.ts +88 -0
- package/package.json +48 -31
- package/prompter.ts +72 -0
- package/scanInfo.ts +606 -0
- package/selectModel.ts +11 -0
- package/{esm/src/spinner.js → spinner.ts} +22 -28
- package/{esm/src/capacitorApp.js → src/capacitorApp.ts} +82 -81
- package/sshTunnel.ts +152 -0
- package/{esm/src/streamAi.js → streamAi.ts} +18 -12
- package/transforms/barrelAnalyzer.ts +278 -0
- package/transforms/barrelImportsPlugin.ts +504 -0
- package/transforms/externalizeFrameworkPlugin.ts +185 -0
- package/transforms/index.ts +5 -0
- package/transforms/rscUseClientTransform.ts +59 -0
- package/transforms/transforms.test.ts +208 -0
- package/transforms/useClientBundlePlugin.ts +47 -0
- package/tsconfig.json +37 -0
- package/typeChecker.ts +264 -0
- package/types.ts +44 -0
- package/ui/MultiScrollList.tsx +242 -0
- package/ui/ScrollList.tsx +107 -0
- package/ui/index.ts +2 -0
- package/{esm/src/uploadRelease.js → uploadRelease.ts} +50 -34
- package/{esm/src/useStdoutDimensions.js → useStdoutDimensions.ts} +5 -5
- package/cjs/index.js +0 -21
- package/cjs/src/aiEditor.js +0 -311
- package/cjs/src/auth.js +0 -72
- package/cjs/src/builder.js +0 -114
- package/cjs/src/capacitorApp.js +0 -313
- package/cjs/src/commandDecorators/argMeta.js +0 -88
- package/cjs/src/commandDecorators/command.js +0 -324
- package/cjs/src/commandDecorators/commandMeta.js +0 -30
- package/cjs/src/commandDecorators/helpFormatter.js +0 -211
- package/cjs/src/commandDecorators/index.js +0 -31
- package/cjs/src/commandDecorators/targetMeta.js +0 -57
- package/cjs/src/commandDecorators/types.js +0 -15
- package/cjs/src/constants.js +0 -46
- package/cjs/src/createTunnel.js +0 -49
- package/cjs/src/dependencyScanner.js +0 -220
- package/cjs/src/executors.js +0 -964
- package/cjs/src/extractDeps.js +0 -103
- package/cjs/src/fileEditor.js +0 -120
- package/cjs/src/getCredentials.js +0 -44
- package/cjs/src/getDirname.js +0 -38
- package/cjs/src/getModelFileData.js +0 -66
- package/cjs/src/getRelatedCnsts.js +0 -260
- package/cjs/src/guideline.js +0 -15
- package/cjs/src/index.js +0 -65
- package/cjs/src/linter.js +0 -238
- package/cjs/src/prompter.js +0 -85
- package/cjs/src/scanInfo.js +0 -491
- package/cjs/src/selectModel.js +0 -46
- package/cjs/src/spinner.js +0 -93
- package/cjs/src/streamAi.js +0 -62
- package/cjs/src/typeChecker.js +0 -207
- package/cjs/src/types.js +0 -15
- package/cjs/src/uploadRelease.js +0 -112
- package/cjs/src/useStdoutDimensions.js +0 -43
- package/esm/index.js +0 -1
- package/esm/src/aiEditor.js +0 -282
- package/esm/src/auth.js +0 -42
- package/esm/src/builder.js +0 -81
- package/esm/src/commandDecorators/argMeta.js +0 -54
- package/esm/src/commandDecorators/command.js +0 -290
- package/esm/src/commandDecorators/commandMeta.js +0 -7
- package/esm/src/commandDecorators/targetMeta.js +0 -33
- package/esm/src/commandDecorators/types.js +0 -0
- package/esm/src/constants.js +0 -17
- package/esm/src/createTunnel.js +0 -26
- package/esm/src/dependencyScanner.js +0 -187
- package/esm/src/executors.js +0 -928
- package/esm/src/getCredentials.js +0 -11
- package/esm/src/getDirname.js +0 -5
- package/esm/src/getModelFileData.js +0 -33
- package/esm/src/getRelatedCnsts.js +0 -221
- package/esm/src/guideline.js +0 -0
- package/esm/src/linter.js +0 -205
- package/esm/src/prompter.js +0 -51
- package/esm/src/scanInfo.js +0 -455
- package/esm/src/selectModel.js +0 -13
- package/esm/src/typeChecker.js +0 -174
- package/esm/src/types.js +0 -0
- package/index.d.ts +0 -1
- package/src/aiEditor.d.ts +0 -50
- package/src/auth.d.ts +0 -9
- package/src/builder.d.ts +0 -18
- package/src/capacitorApp.d.ts +0 -39
- package/src/commandDecorators/argMeta.d.ts +0 -67
- package/src/commandDecorators/command.d.ts +0 -2
- package/src/commandDecorators/commandMeta.d.ts +0 -2
- package/src/commandDecorators/helpFormatter.d.ts +0 -3
- package/src/commandDecorators/index.d.ts +0 -6
- package/src/commandDecorators/targetMeta.d.ts +0 -19
- package/src/commandDecorators/types.d.ts +0 -1
- package/src/constants.d.ts +0 -26
- package/src/createTunnel.d.ts +0 -8
- package/src/dependencyScanner.d.ts +0 -23
- package/src/executors.d.ts +0 -296
- package/src/extractDeps.d.ts +0 -7
- package/src/fileEditor.d.ts +0 -16
- package/src/getCredentials.d.ts +0 -12
- package/src/getDirname.d.ts +0 -1
- package/src/getModelFileData.d.ts +0 -16
- package/src/getRelatedCnsts.d.ts +0 -53
- package/src/guideline.d.ts +0 -19
- package/src/index.d.ts +0 -23
- package/src/linter.d.ts +0 -109
- package/src/prompter.d.ts +0 -14
- package/src/scanInfo.d.ts +0 -82
- package/src/selectModel.d.ts +0 -1
- package/src/spinner.d.ts +0 -20
- package/src/streamAi.d.ts +0 -6
- package/src/typeChecker.d.ts +0 -52
- package/src/types.d.ts +0 -31
- package/src/uploadRelease.d.ts +0 -10
- package/src/useStdoutDimensions.d.ts +0 -1
package/cjs/src/constants.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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 constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
akanCloudBackendUrl: () => akanCloudBackendUrl,
|
|
21
|
-
akanCloudClientUrl: () => akanCloudClientUrl,
|
|
22
|
-
akanCloudHost: () => akanCloudHost,
|
|
23
|
-
basePath: () => basePath,
|
|
24
|
-
configPath: () => configPath,
|
|
25
|
-
defaultAkanGlobalConfig: () => defaultAkanGlobalConfig,
|
|
26
|
-
defaultHostConfig: () => defaultHostConfig
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(constants_exports);
|
|
29
|
-
var import_os = require("os");
|
|
30
|
-
const basePath = `${(0, import_os.homedir)()}/.akan`;
|
|
31
|
-
const configPath = `${basePath}/config.json`;
|
|
32
|
-
const akanCloudHost = process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? "http://localhost" : "https://cloud.akanjs.com";
|
|
33
|
-
const akanCloudBackendUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":8080" : ""}/backend`;
|
|
34
|
-
const akanCloudClientUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":4200" : ""}`;
|
|
35
|
-
const defaultHostConfig = {};
|
|
36
|
-
const defaultAkanGlobalConfig = { cloudHost: {}, llm: null };
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
akanCloudBackendUrl,
|
|
40
|
-
akanCloudClientUrl,
|
|
41
|
-
akanCloudHost,
|
|
42
|
-
basePath,
|
|
43
|
-
configPath,
|
|
44
|
-
defaultAkanGlobalConfig,
|
|
45
|
-
defaultHostConfig
|
|
46
|
-
});
|
package/cjs/src/createTunnel.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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 createTunnel_exports = {};
|
|
19
|
-
__export(createTunnel_exports, {
|
|
20
|
-
createTunnel: () => createTunnel
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(createTunnel_exports);
|
|
23
|
-
var import_tunnel_ssh = require("tunnel-ssh");
|
|
24
|
-
const getSshTunnelOptions = (app, environment) => {
|
|
25
|
-
const { serveDomain, repoName } = app.workspace.getBaseDevEnv();
|
|
26
|
-
return {
|
|
27
|
-
host: `${app.name}-${environment}.${serveDomain}`,
|
|
28
|
-
port: process.env.SSH_TUNNEL_PORT ? parseInt(process.env.SSH_TUNNEL_PORT) : 32767,
|
|
29
|
-
username: process.env.SSH_TUNNEL_USERNAME ?? "root",
|
|
30
|
-
password: process.env.SSH_TUNNEL_PASSWORD ?? repoName
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const createTunnel = async ({ app, environment, port = 27017 }) => {
|
|
34
|
-
const tunnelOptions = { autoClose: true, reconnectOnError: true };
|
|
35
|
-
const sshOptions = getSshTunnelOptions(app, environment);
|
|
36
|
-
const serverOptions = { port };
|
|
37
|
-
const forwardOptions = {
|
|
38
|
-
srcAddr: "0.0.0.0",
|
|
39
|
-
srcPort: port,
|
|
40
|
-
dstAddr: `mongo-0.mongo-svc.${app.name}-${environment}`,
|
|
41
|
-
dstPort: 27017
|
|
42
|
-
};
|
|
43
|
-
const [server, client] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
44
|
-
return `localhost:${port}`;
|
|
45
|
-
};
|
|
46
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
createTunnel
|
|
49
|
-
});
|
|
@@ -1,220 +0,0 @@
|
|
|
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 dependencyScanner_exports = {};
|
|
29
|
-
__export(dependencyScanner_exports, {
|
|
30
|
-
TypeScriptDependencyScanner: () => TypeScriptDependencyScanner
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(dependencyScanner_exports);
|
|
33
|
-
var fs = __toESM(require("fs"));
|
|
34
|
-
var import_ignore = __toESM(require("ignore"));
|
|
35
|
-
var path = __toESM(require("path"));
|
|
36
|
-
var ts = __toESM(require("typescript"));
|
|
37
|
-
class TypeScriptDependencyScanner {
|
|
38
|
-
#fileDependencies = /* @__PURE__ */ new Map();
|
|
39
|
-
#visitedFiles = /* @__PURE__ */ new Set();
|
|
40
|
-
directory;
|
|
41
|
-
tsconfig;
|
|
42
|
-
rootPackageJson;
|
|
43
|
-
ig;
|
|
44
|
-
workspaceRoot;
|
|
45
|
-
constructor(directory, {
|
|
46
|
-
workspaceRoot,
|
|
47
|
-
tsconfig,
|
|
48
|
-
rootPackageJson,
|
|
49
|
-
gitignorePatterns = []
|
|
50
|
-
}) {
|
|
51
|
-
this.directory = directory;
|
|
52
|
-
this.tsconfig = tsconfig;
|
|
53
|
-
this.rootPackageJson = rootPackageJson;
|
|
54
|
-
this.ig = (0, import_ignore.default)().add(gitignorePatterns);
|
|
55
|
-
this.workspaceRoot = workspaceRoot;
|
|
56
|
-
}
|
|
57
|
-
async getMonorepoDependencies(projectName) {
|
|
58
|
-
const npmSet = new Set(
|
|
59
|
-
Object.keys({ ...this.rootPackageJson.dependencies, ...this.rootPackageJson.devDependencies })
|
|
60
|
-
);
|
|
61
|
-
const pkgPathSet = new Set(
|
|
62
|
-
Object.keys(this.tsconfig.compilerOptions.paths ?? {}).filter((path2) => this.tsconfig.compilerOptions.paths?.[path2]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", ""))
|
|
63
|
-
);
|
|
64
|
-
const libPathSet = new Set(
|
|
65
|
-
Object.keys(this.tsconfig.compilerOptions.paths ?? {}).filter((path2) => this.tsconfig.compilerOptions.paths?.[path2]?.some((resolve) => resolve.startsWith("libs/"))).map((path2) => path2.replace("/*", ""))
|
|
66
|
-
);
|
|
67
|
-
const [npmDepSet, pkgPathDepSet, libPathDepSet] = await this.getImportSets([npmSet, pkgPathSet, libPathSet]);
|
|
68
|
-
const pkgDeps = [...pkgPathDepSet].map((path2) => {
|
|
69
|
-
const pathSplitLength = path2.split("/").length;
|
|
70
|
-
return (this.tsconfig.compilerOptions.paths?.[path2]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
71
|
-
});
|
|
72
|
-
const libDeps = [...libPathDepSet].map((path2) => {
|
|
73
|
-
const pathSplitLength = path2.split("/").length;
|
|
74
|
-
return (this.tsconfig.compilerOptions.paths?.[path2]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
75
|
-
}).filter((libName) => libName !== projectName);
|
|
76
|
-
return { pkgDeps, libDeps, npmDeps: [...npmDepSet] };
|
|
77
|
-
}
|
|
78
|
-
async getImportSets(depSets) {
|
|
79
|
-
const fileDependencies = await this.getDependencies();
|
|
80
|
-
const importedDepSets = new Array(depSets.length);
|
|
81
|
-
for (let i = 0; i < depSets.length; i++)
|
|
82
|
-
importedDepSets[i] = /* @__PURE__ */ new Set();
|
|
83
|
-
fileDependencies.forEach((imps) => {
|
|
84
|
-
imps.forEach((imp) => {
|
|
85
|
-
if (imp.startsWith("."))
|
|
86
|
-
return;
|
|
87
|
-
const moduleName = imp;
|
|
88
|
-
const moduleNameParts = moduleName.split("/");
|
|
89
|
-
const subModuleLength = moduleNameParts.length;
|
|
90
|
-
for (let i = 0; i < subModuleLength; i++) {
|
|
91
|
-
const importName = moduleNameParts.slice(0, i + 1).join("/");
|
|
92
|
-
for (let j = 0; j < depSets.length; j++) {
|
|
93
|
-
if (depSets[j].has(importName)) {
|
|
94
|
-
importedDepSets[j].add(importName);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
return importedDepSets;
|
|
102
|
-
}
|
|
103
|
-
async getDependencies() {
|
|
104
|
-
this.#fileDependencies.clear();
|
|
105
|
-
this.#visitedFiles.clear();
|
|
106
|
-
const files = await this.#findTypeScriptFiles(this.directory);
|
|
107
|
-
for (const file of files)
|
|
108
|
-
await this.#analyzeFile(file, this.directory);
|
|
109
|
-
return this.#fileDependencies;
|
|
110
|
-
}
|
|
111
|
-
async #findTypeScriptFiles(directory) {
|
|
112
|
-
const files = [];
|
|
113
|
-
const processDirectory = async (dir) => {
|
|
114
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
115
|
-
for (const entry of entries) {
|
|
116
|
-
const fullPath = path.join(dir, entry.name);
|
|
117
|
-
const relativePath = path.relative(this.workspaceRoot, fullPath);
|
|
118
|
-
if (this.ig.ignores(relativePath))
|
|
119
|
-
continue;
|
|
120
|
-
if (entry.isDirectory()) {
|
|
121
|
-
if (!["node_modules", "dist", "build", ".git", ".next", "public", "ios", "android"].includes(entry.name))
|
|
122
|
-
await processDirectory(fullPath);
|
|
123
|
-
} else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")))
|
|
124
|
-
files.push(fullPath);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
await processDirectory(directory);
|
|
128
|
-
return files;
|
|
129
|
-
}
|
|
130
|
-
async #analyzeFile(filePath, baseDir) {
|
|
131
|
-
if (this.#visitedFiles.has(filePath))
|
|
132
|
-
return;
|
|
133
|
-
this.#visitedFiles.add(filePath);
|
|
134
|
-
try {
|
|
135
|
-
const fileContent = await fs.promises.readFile(filePath, "utf-8");
|
|
136
|
-
const imports = this.#extractImports(fileContent, filePath);
|
|
137
|
-
const resolvedImports = imports.map((importPath) => {
|
|
138
|
-
if (importPath.startsWith(".")) {
|
|
139
|
-
const resolvedPath = "./" + path.join(path.relative(baseDir, filePath), importPath);
|
|
140
|
-
return this.#ensureExtension(resolvedPath);
|
|
141
|
-
}
|
|
142
|
-
return importPath;
|
|
143
|
-
});
|
|
144
|
-
const relativePath = path.relative(baseDir, filePath);
|
|
145
|
-
this.#fileDependencies.set(relativePath, resolvedImports);
|
|
146
|
-
} catch (error) {
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
#ensureExtension(filePath) {
|
|
150
|
-
if (fs.existsSync(`${filePath}.ts`))
|
|
151
|
-
return `${filePath}.ts`;
|
|
152
|
-
else if (fs.existsSync(`${filePath}.tsx`))
|
|
153
|
-
return `${filePath}.tsx`;
|
|
154
|
-
else if (fs.existsSync(filePath))
|
|
155
|
-
return filePath;
|
|
156
|
-
return `${filePath}.ts`;
|
|
157
|
-
}
|
|
158
|
-
#extractImports(source, filePath) {
|
|
159
|
-
const imports = [];
|
|
160
|
-
const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);
|
|
161
|
-
const visit = (node) => {
|
|
162
|
-
if (ts.isImportDeclaration(node)) {
|
|
163
|
-
const moduleSpecifier = node.moduleSpecifier;
|
|
164
|
-
if (ts.isStringLiteral(moduleSpecifier))
|
|
165
|
-
imports.push(moduleSpecifier.text);
|
|
166
|
-
}
|
|
167
|
-
if (ts.isCallExpression(node)) {
|
|
168
|
-
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
169
|
-
if (node.arguments.length > 0) {
|
|
170
|
-
const arg = node.arguments[0];
|
|
171
|
-
if (ts.isStringLiteral(arg))
|
|
172
|
-
imports.push(arg.text);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (ts.isArrowFunction(node.expression)) {
|
|
176
|
-
const body = node.expression.body;
|
|
177
|
-
if (ts.isCallExpression(body) && body.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
178
|
-
if (body.arguments.length > 0) {
|
|
179
|
-
const arg = body.arguments[0];
|
|
180
|
-
if (ts.isStringLiteral(arg))
|
|
181
|
-
imports.push(arg.text);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
ts.forEachChild(node, visit);
|
|
187
|
-
};
|
|
188
|
-
visit(sourceFile);
|
|
189
|
-
return [...new Set(imports)];
|
|
190
|
-
}
|
|
191
|
-
generateDependencyGraph() {
|
|
192
|
-
let graph = "Dependency Graph:\n\n";
|
|
193
|
-
for (const [file, imports] of this.#fileDependencies.entries()) {
|
|
194
|
-
graph += `${file}:
|
|
195
|
-
`;
|
|
196
|
-
const projectImports = imports.filter((i) => !i.startsWith("react") && !i.startsWith("@"));
|
|
197
|
-
const externalImports = imports.filter((i) => i.startsWith("react") || i.startsWith("@"));
|
|
198
|
-
if (projectImports.length > 0) {
|
|
199
|
-
graph += " Project dependencies:\n";
|
|
200
|
-
projectImports.forEach((imp) => {
|
|
201
|
-
graph += ` \u2192 ${imp}
|
|
202
|
-
`;
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
if (externalImports.length > 0) {
|
|
206
|
-
graph += " External dependencies:\n";
|
|
207
|
-
externalImports.forEach((imp) => {
|
|
208
|
-
graph += ` \u2192 ${imp}
|
|
209
|
-
`;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
graph += "\n";
|
|
213
|
-
}
|
|
214
|
-
return graph;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
218
|
-
0 && (module.exports = {
|
|
219
|
-
TypeScriptDependencyScanner
|
|
220
|
-
});
|