@intuned/runtime-dev 0.1.0-test.11 → 0.1.0-test.13

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.
Files changed (100) hide show
  1. package/.babelrc +0 -1
  2. package/dist/commands/api/run.js +156 -83
  3. package/dist/commands/api/run.ts +105 -0
  4. package/dist/commands/auth-sessions/load.js +20 -20
  5. package/dist/commands/auth-sessions/load.ts +30 -0
  6. package/dist/commands/auth-sessions/run-check.js +45 -39
  7. package/dist/commands/auth-sessions/run-check.ts +51 -0
  8. package/dist/commands/auth-sessions/run-create.js +84 -74
  9. package/dist/commands/auth-sessions/run-create.ts +91 -0
  10. package/dist/commands/browser/save-state.js +12 -7
  11. package/dist/commands/browser/save-state.ts +14 -0
  12. package/dist/commands/browser/start-browser.js +7 -4
  13. package/dist/commands/browser/start-browser.ts +11 -0
  14. package/dist/commands/build.js +97 -61
  15. package/dist/commands/build.ts +78 -0
  16. package/dist/commands/common/browserUtils.js +42 -31
  17. package/dist/commands/common/browserUtils.ts +45 -0
  18. package/dist/commands/common/getDefaultExportFromFile.js +11 -10
  19. package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
  20. package/dist/commands/common/getFirstLineNumber.js +90 -83
  21. package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +2 -2
  22. package/dist/commands/common/getFirstLineNumber.ts +96 -0
  23. package/dist/commands/common/sendMessageToClient.js +4 -2
  24. package/dist/commands/common/sendMessageToClient.ts +3 -0
  25. package/dist/commands/common/utils/fileUtils.js +16 -16
  26. package/dist/commands/common/utils/fileUtils.ts +23 -0
  27. package/dist/commands/common/utils/settings.js +17 -19
  28. package/dist/commands/common/utils/settings.ts +22 -0
  29. package/dist/commands/common/utils/unixSocket.js +43 -36
  30. package/dist/commands/common/utils/unixSocket.ts +38 -0
  31. package/dist/commands/common/utils/webTemplate.js +25 -18
  32. package/dist/commands/common/utils/webTemplate.ts +22 -0
  33. package/dist/commands/interface/run.js +139 -133
  34. package/dist/commands/interface/run.ts +156 -0
  35. package/dist/commands/ts-check.js +45 -41
  36. package/dist/commands/ts-check.ts +50 -0
  37. package/dist/common/Logger/Logger/index.d.ts +1 -1
  38. package/dist/common/Logger/Logger/index.js +40 -46
  39. package/dist/common/Logger/Logger/index.ts +53 -0
  40. package/dist/common/Logger/Logger/types.js +1 -1
  41. package/dist/common/Logger/index.d.ts +1 -1
  42. package/dist/common/Logger/index.js +40 -46
  43. package/dist/common/Logger/index.ts +53 -0
  44. package/dist/common/Logger/types.js +1 -1
  45. package/dist/common/asyncLocalStorage/index.js +4 -4
  46. package/dist/common/asyncLocalStorage/index.ts +9 -0
  47. package/dist/common/cleanEnvironmentVariables.js +11 -9
  48. package/dist/common/cleanEnvironmentVariables.ts +10 -0
  49. package/dist/common/constants.js +1 -1
  50. package/dist/common/constants.ts +1 -0
  51. package/dist/common/contextStorageStateHelpers.js +36 -38
  52. package/dist/common/contextStorageStateHelpers.ts +43 -0
  53. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  54. package/dist/common/getPlaywrightConstructs.js +187 -157
  55. package/dist/common/getPlaywrightConstructs.ts +181 -0
  56. package/dist/common/jwtTokenManager.js +74 -61
  57. package/dist/common/jwtTokenManager.ts +71 -0
  58. package/dist/common/runApi/errors.d.ts +1 -1
  59. package/dist/common/runApi/errors.js +130 -121
  60. package/dist/common/runApi/errors.ts +154 -0
  61. package/dist/common/runApi/index.d.ts +4 -4
  62. package/dist/common/runApi/index.js +219 -233
  63. package/dist/common/runApi/index.ts +253 -0
  64. package/dist/common/runApi/types.d.ts +1 -1
  65. package/dist/common/runApi/types.js +55 -41
  66. package/dist/common/runApi/types.ts +43 -0
  67. package/dist/common/settingsSchema.js +9 -6
  68. package/dist/common/settingsSchema.ts +9 -0
  69. package/dist/common/telemetry.js +27 -16
  70. package/dist/common/telemetry.ts +23 -0
  71. package/dist/index.d.ts +4 -4
  72. package/dist/index.js +4 -4
  73. package/dist/index.ts +4 -0
  74. package/dist/runtime/RunError.d.ts +1 -1
  75. package/dist/runtime/RunError.js +10 -10
  76. package/dist/runtime/RunError.ts +12 -0
  77. package/dist/runtime/downloadDirectory.js +10 -10
  78. package/dist/runtime/downloadDirectory.ts +13 -0
  79. package/dist/runtime/enums.d.ts +1 -11
  80. package/dist/runtime/enums.js +12 -12
  81. package/dist/runtime/enums.ts +12 -0
  82. package/dist/runtime/{executionHelpers.test.js → executionHelpers.test.ts} +2 -2
  83. package/dist/runtime/export.d.ts +1 -202
  84. package/dist/runtime/extendPayload.d.ts +1 -1
  85. package/dist/runtime/extendPayload.js +13 -13
  86. package/dist/runtime/extendPayload.ts +15 -0
  87. package/dist/runtime/extendTimeout.js +19 -20
  88. package/dist/runtime/extendTimeout.ts +24 -0
  89. package/dist/runtime/index.d.ts +7 -7
  90. package/dist/runtime/index.js +6 -6
  91. package/dist/runtime/index.ts +6 -0
  92. package/dist/runtime/requestMoreInfo.js +14 -14
  93. package/dist/runtime/requestMoreInfo.ts +18 -0
  94. package/dist/runtime/runInfo.d.ts +1 -1
  95. package/dist/runtime/runInfo.js +12 -13
  96. package/dist/runtime/runInfo.ts +15 -0
  97. package/package.json +3 -2
  98. package/tsconfig.json +1 -1
  99. /package/dist/{runtime/enums.d.js → common/Logger/Logger/types.ts} +0 -0
  100. /package/dist/{runtime/export.d.js → common/Logger/types.ts} +0 -0
@@ -1,45 +1,56 @@
1
+ // this file is to make testing easier only.
1
2
  import { spawn } from "child_process";
2
3
  import * as playwright from "@intuned/playwright-core";
3
4
  import * as fs from "fs-extra";
4
- import { getFullPathInProject } from "./utils/fileUtils";
5
+ import { getFullPathInProject } from "./utils/fileUtils.js";
5
6
  import { getContextStorageState } from "../../common/contextStorageStateHelpers";
6
7
  export const REMOTE_DEBUGGING_PORT = 9222;
7
- export const getChromiumLaunchArgs = () => ["--no-sandbox", `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`, `--user-data-dir=/tmp/${Date.now()}`, "--new-window", "--start-maximized", "--disable-popup-blocking"];
8
+ export const getChromiumLaunchArgs = () => [
9
+ "--no-sandbox",
10
+ `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
11
+ `--user-data-dir=/tmp/${Date.now()}`,
12
+ "--new-window",
13
+ "--start-maximized",
14
+ "--disable-popup-blocking",
15
+ ];
16
+ // this is needed cause we need to keep the same browser instance alive between start recording and stop recording calls.
8
17
  async function getBrowser() {
9
- let playwrightBrowser = null;
10
- try {
11
- playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
12
- } catch (e) {
13
- throw new Error("Browser is not running");
14
- }
15
- return playwrightBrowser;
18
+ let playwrightBrowser = null;
19
+ try {
20
+ playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
21
+ }
22
+ catch (e) {
23
+ throw new Error("Browser is not running");
24
+ }
25
+ return playwrightBrowser;
16
26
  }
17
27
  export async function startOrRestartBrowser() {
18
- const chromiumPath = await playwright.chromium.executablePath();
19
- const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
20
- chromeInstanceProcess.stdout.on("data", data => {
21
- console.log(`Chrome stdout: ${data}`);
22
- });
23
- chromeInstanceProcess.stderr.on("data", data => {
24
- console.error(`Chrome stderr: ${data}`);
25
- });
28
+ const chromiumPath = await playwright.chromium.executablePath();
29
+ const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
30
+ chromeInstanceProcess.stdout.on("data", (data) => {
31
+ console.log(`Chrome stdout: ${data}`);
32
+ });
33
+ chromeInstanceProcess.stderr.on("data", (data) => {
34
+ console.error(`Chrome stderr: ${data}`);
35
+ });
26
36
  }
27
37
  export async function saveSessionFromOpenedBrowser(path) {
28
- const browser = await getBrowser();
29
- const context = await browser.contexts()[0];
30
- return saveSession(path, context);
38
+ const browser = await getBrowser();
39
+ const context = await browser.contexts()[0];
40
+ return saveSession(path, context);
31
41
  }
32
42
  export async function loadState(path, context) {
33
- const fullPath = getFullPathInProject(path);
34
- if (!(await fs.pathExists(fullPath))) {
35
- throw new Error("session file does not exist");
36
- }
37
- const data = await fs.readJson(fullPath);
38
- await context.addCookies(data.cookies);
43
+ const fullPath = getFullPathInProject(path);
44
+ if (!(await fs.pathExists(fullPath))) {
45
+ throw new Error("session file does not exist");
46
+ }
47
+ const data = await fs.readJson(fullPath);
48
+ await context.addCookies(data.cookies);
49
+ // ToDo: logic to load storage without using the page.
39
50
  }
40
51
  export async function saveSession(path, context) {
41
- const fullState = await getContextStorageState(context);
42
- const fullPath = getFullPathInProject(path);
43
- fs.ensureFileSync(fullPath);
44
- await fs.writeJSON(fullPath, fullState);
45
- }
52
+ const fullState = await getContextStorageState(context);
53
+ const fullPath = getFullPathInProject(path);
54
+ fs.ensureFileSync(fullPath);
55
+ await fs.writeJSON(fullPath, fullState);
56
+ }
@@ -0,0 +1,45 @@
1
+ import { spawn } from "child_process";
2
+ import * as playwright from "@intuned/playwright-core";
3
+ import * as fs from "fs-extra";
4
+ import { getFullPathInProject } from "./utils/fileUtils.js";
5
+ import { getContextStorageState } from "../../common/contextStorageStateHelpers";
6
+ export const REMOTE_DEBUGGING_PORT = 9222;
7
+ export const getChromiumLaunchArgs = () => ["--no-sandbox", `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`, `--user-data-dir=/tmp/${Date.now()}`, "--new-window", "--start-maximized", "--disable-popup-blocking"];
8
+ async function getBrowser() {
9
+ let playwrightBrowser = null;
10
+ try {
11
+ playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
12
+ } catch (e) {
13
+ throw new Error("Browser is not running");
14
+ }
15
+ return playwrightBrowser;
16
+ }
17
+ export async function startOrRestartBrowser() {
18
+ const chromiumPath = await playwright.chromium.executablePath();
19
+ const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
20
+ chromeInstanceProcess.stdout.on("data", data => {
21
+ console.log(`Chrome stdout: ${data}`);
22
+ });
23
+ chromeInstanceProcess.stderr.on("data", data => {
24
+ console.error(`Chrome stderr: ${data}`);
25
+ });
26
+ }
27
+ export async function saveSessionFromOpenedBrowser(path) {
28
+ const browser = await getBrowser();
29
+ const context = await browser.contexts()[0];
30
+ return saveSession(path, context);
31
+ }
32
+ export async function loadState(path, context) {
33
+ const fullPath = getFullPathInProject(path);
34
+ if (!(await fs.pathExists(fullPath))) {
35
+ throw new Error("session file does not exist");
36
+ }
37
+ const data = await fs.readJson(fullPath);
38
+ await context.addCookies(data.cookies);
39
+ }
40
+ export async function saveSession(path, context) {
41
+ const fullState = await getContextStorageState(context);
42
+ const fullPath = getFullPathInProject(path);
43
+ fs.ensureFileSync(fullPath);
44
+ await fs.writeJSON(fullPath, fullState);
45
+ }
@@ -1,11 +1,12 @@
1
1
  export async function getDefaultExportFromFile(apiFilePath) {
2
- require("ts-node").register({
3
- transpileOnly: true,
4
- compilerOptions: {
5
- lib: ["dom", "es2020"]
6
- }
7
- });
8
- const imported = await import(apiFilePath);
9
- const defaultExport = imported.default;
10
- return defaultExport;
11
- }
2
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
3
+ require("ts-node").register({
4
+ transpileOnly: true,
5
+ compilerOptions: {
6
+ lib: ["dom", "es2020"],
7
+ },
8
+ });
9
+ const imported = await import(apiFilePath);
10
+ const defaultExport = imported.default;
11
+ return defaultExport;
12
+ }
@@ -0,0 +1,11 @@
1
+ export async function getDefaultExportFromFile(apiFilePath) {
2
+ require("ts-node").register({
3
+ transpileOnly: true,
4
+ compilerOptions: {
5
+ lib: ["dom", "es2020"]
6
+ }
7
+ });
8
+ const imported = await import(apiFilePath);
9
+ const defaultExport = imported.default;
10
+ return defaultExport;
11
+ }
@@ -1,96 +1,103 @@
1
- import { ts, Project, ModuleKind, ScriptTarget, Node } from "ts-morph";
1
+ import { ts, Project, ModuleKind, ScriptTarget, Node, } from "ts-morph";
2
2
  import { SourceMapConsumer } from "source-map";
3
3
  function compileTypeScript(apiFilePath) {
4
- const compilerOptions = {
5
- lib: ["dom", "es2020"],
6
- sourceMap: true,
7
- inlineSourceMap: true,
8
- inlineSources: true,
9
- declaration: false,
10
- noEmit: false,
11
- module: ModuleKind.CommonJS,
12
- target: ScriptTarget.ES2020
13
- };
14
- const project = new Project({
15
- compilerOptions
16
- });
17
- const sourceFile = project.addSourceFileAtPath(apiFilePath);
18
- const outputJS = project.emitToMemory({
19
- targetSourceFile: sourceFile
20
- });
21
- const outputJSText = outputJS.getFiles()[0].text;
22
- return {
23
- sourceFile,
24
- outputJSText
25
- };
4
+ const compilerOptions = {
5
+ lib: ["dom", "es2020"],
6
+ sourceMap: true,
7
+ inlineSourceMap: true,
8
+ inlineSources: true,
9
+ declaration: false,
10
+ noEmit: false,
11
+ module: ModuleKind.CommonJS,
12
+ target: ScriptTarget.ES2020,
13
+ };
14
+ const project = new Project({
15
+ compilerOptions,
16
+ });
17
+ const sourceFile = project.addSourceFileAtPath(apiFilePath);
18
+ const outputJS = project.emitToMemory({ targetSourceFile: sourceFile });
19
+ const outputJSText = outputJS.getFiles()[0].text;
20
+ return { sourceFile, outputJSText };
26
21
  }
27
22
  export function findFirstExecutableLine(sourceFile) {
28
- var _defaultExportSymbol$;
29
- let functionBody;
30
- const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
31
- const defaultExportDeclaration = defaultExportSymbol === null || defaultExportSymbol === void 0 || (_defaultExportSymbol$ = defaultExportSymbol.getDeclarations()) === null || _defaultExportSymbol$ === void 0 ? void 0 : _defaultExportSymbol$[0];
32
- if (defaultExportDeclaration) {
33
- if (defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration) {
34
- functionBody = defaultExportDeclaration.getBody();
35
- } else {
36
- const exportAssignments = sourceFile.getExportAssignments();
37
- for (const exportAssignment of exportAssignments) {
38
- const expression = exportAssignment.getExpression();
39
- if (!expression) continue;
40
- if (expression.getKind() === ts.SyntaxKind.Identifier || expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction) {
41
- var _sourceFile$getVariab;
42
- const identifier = expression.getText();
43
- const possiblyExportedFunction = sourceFile.getFunction(identifier) || ((_sourceFile$getVariab = sourceFile.getVariableStatement(identifier)) === null || _sourceFile$getVariab === void 0 ? void 0 : _sourceFile$getVariab.getDescendants().find(node => node.getKind() === ts.SyntaxKind.FunctionExpression || node.getKind() === ts.SyntaxKind.ArrowFunction));
44
- if (possiblyExportedFunction) {
45
- functionBody = possiblyExportedFunction.getBody();
46
- break;
47
- }
23
+ let functionBody;
24
+ // Directly find the default exported function's body
25
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
26
+ const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
27
+ if (defaultExportDeclaration) {
28
+ // Check if the default export is a function
29
+ if (defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration) {
30
+ functionBody = defaultExportDeclaration.getBody();
48
31
  }
49
- if (Node.hasBody(expression) && (expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction)) {
50
- functionBody = expression.getBody();
51
- break;
32
+ else {
33
+ // Handle ExportAssignment specifically for cases like `export default identifier;`
34
+ const exportAssignments = sourceFile.getExportAssignments();
35
+ for (const exportAssignment of exportAssignments) {
36
+ const expression = exportAssignment.getExpression();
37
+ if (!expression)
38
+ continue;
39
+ if (expression.getKind() === ts.SyntaxKind.Identifier ||
40
+ expression.getKind() === ts.SyntaxKind.FunctionExpression ||
41
+ expression.getKind() === ts.SyntaxKind.ArrowFunction) {
42
+ const identifier = expression.getText();
43
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) ||
44
+ sourceFile
45
+ .getVariableStatement(identifier)
46
+ ?.getDescendants()
47
+ .find((node) => node.getKind() === ts.SyntaxKind.FunctionExpression ||
48
+ node.getKind() === ts.SyntaxKind.ArrowFunction);
49
+ if (possiblyExportedFunction) {
50
+ functionBody = possiblyExportedFunction.getBody();
51
+ break;
52
+ }
53
+ }
54
+ if (Node.hasBody(expression) &&
55
+ (expression.getKind() === ts.SyntaxKind.FunctionExpression ||
56
+ expression.getKind() === ts.SyntaxKind.ArrowFunction)) {
57
+ // As these are anonymous, we directly access their body
58
+ functionBody = expression.getBody();
59
+ break;
60
+ }
61
+ }
52
62
  }
53
- }
54
63
  }
55
- }
56
- if (!functionBody || !Node.isStatemented(functionBody)) {
57
- return -1;
58
- }
59
- if (functionBody.getStatements().length === 0) {
60
- return -1;
61
- }
62
- const position = functionBody.getStatements()[0].getStart();
63
- return sourceFile.getLineAndColumnAtPos(position);
64
+ if (!functionBody || !Node.isStatemented(functionBody)) {
65
+ return -1;
66
+ }
67
+ if (functionBody.getStatements().length === 0) {
68
+ return -1;
69
+ }
70
+ const position = functionBody.getStatements()[0].getStart();
71
+ return sourceFile.getLineAndColumnAtPos(position);
64
72
  }
65
73
  async function getSourceMap(jsCode) {
66
- const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") + "//# sourceMappingURL=data:application/json;base64,".length);
67
- const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
68
- const sourceMap = JSON.parse(sourceMapText);
69
- return new SourceMapConsumer(sourceMap);
74
+ const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") +
75
+ "//# sourceMappingURL=data:application/json;base64,".length);
76
+ const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
77
+ const sourceMap = JSON.parse(sourceMapText);
78
+ return new SourceMapConsumer(sourceMap);
70
79
  }
71
80
  async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
72
- const sourceMap = await getSourceMap(jsCode);
73
- const generatedLineNumber = sourceMap.generatedPositionFor({
74
- source: sourceFileName,
75
- line,
76
- column
77
- }).line;
78
- if (!generatedLineNumber) return -1;
79
- return generatedLineNumber;
81
+ const sourceMap = await getSourceMap(jsCode);
82
+ const generatedLineNumber = sourceMap.generatedPositionFor({
83
+ source: sourceFileName,
84
+ line,
85
+ column,
86
+ }).line;
87
+ if (!generatedLineNumber)
88
+ return -1;
89
+ return generatedLineNumber;
80
90
  }
81
91
  export default async function getFirstLineNumber(apiFilePath) {
82
- const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
83
- const {
84
- sourceFile,
85
- outputJSText
86
- } = compileTypeScript(apiFilePath);
87
- const result = findFirstExecutableLine(sourceFile);
88
- if (result === -1) return {
89
- sourceFileName,
90
- lineNumber: -1
91
- };
92
- return {
93
- sourceFileName,
94
- lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column)
95
- };
96
- }
92
+ const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
93
+ // Compile TypeScript to JavaScript and get the Typescript AST
94
+ const { sourceFile, outputJSText } = compileTypeScript(apiFilePath);
95
+ // Find the first line of code in the default export ts code
96
+ const result = findFirstExecutableLine(sourceFile);
97
+ if (result === -1)
98
+ return { sourceFileName, lineNumber: -1 };
99
+ return {
100
+ sourceFileName,
101
+ lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column),
102
+ };
103
+ }
@@ -1,9 +1,9 @@
1
1
  import { expect, describe, it, beforeAll, afterAll } from "vitest";
2
- import getFirstLineNumber from "./getFirstLineNumber";
2
+ import getFirstLineNumber from "./getFirstLineNumber.js";
3
3
  import * as fs from "fs";
4
4
  import * as path from "path";
5
5
  describe("getFirstLineNumber", () => {
6
- const testFilesDir = path.join(__dirname, "testFiles");
6
+ const testFilesDir = path.join(path.dirname(import.meta.url), "testFiles");
7
7
  const createTestFile = (fileName, content) => {
8
8
  const filePath = path.join(testFilesDir, fileName);
9
9
  fs.writeFileSync(filePath, content);
@@ -0,0 +1,96 @@
1
+ import { ts, Project, ModuleKind, ScriptTarget, Node } from "ts-morph";
2
+ import { SourceMapConsumer } from "source-map";
3
+ function compileTypeScript(apiFilePath) {
4
+ const compilerOptions = {
5
+ lib: ["dom", "es2020"],
6
+ sourceMap: true,
7
+ inlineSourceMap: true,
8
+ inlineSources: true,
9
+ declaration: false,
10
+ noEmit: false,
11
+ module: ModuleKind.CommonJS,
12
+ target: ScriptTarget.ES2020
13
+ };
14
+ const project = new Project({
15
+ compilerOptions
16
+ });
17
+ const sourceFile = project.addSourceFileAtPath(apiFilePath);
18
+ const outputJS = project.emitToMemory({
19
+ targetSourceFile: sourceFile
20
+ });
21
+ const outputJSText = outputJS.getFiles()[0].text;
22
+ return {
23
+ sourceFile,
24
+ outputJSText
25
+ };
26
+ }
27
+ export function findFirstExecutableLine(sourceFile) {
28
+ var _defaultExportSymbol$;
29
+ let functionBody;
30
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
31
+ const defaultExportDeclaration = defaultExportSymbol === null || defaultExportSymbol === void 0 || (_defaultExportSymbol$ = defaultExportSymbol.getDeclarations()) === null || _defaultExportSymbol$ === void 0 ? void 0 : _defaultExportSymbol$[0];
32
+ if (defaultExportDeclaration) {
33
+ if (defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration) {
34
+ functionBody = defaultExportDeclaration.getBody();
35
+ } else {
36
+ const exportAssignments = sourceFile.getExportAssignments();
37
+ for (const exportAssignment of exportAssignments) {
38
+ const expression = exportAssignment.getExpression();
39
+ if (!expression) continue;
40
+ if (expression.getKind() === ts.SyntaxKind.Identifier || expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction) {
41
+ var _sourceFile$getVariab;
42
+ const identifier = expression.getText();
43
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) || ((_sourceFile$getVariab = sourceFile.getVariableStatement(identifier)) === null || _sourceFile$getVariab === void 0 ? void 0 : _sourceFile$getVariab.getDescendants().find(node => node.getKind() === ts.SyntaxKind.FunctionExpression || node.getKind() === ts.SyntaxKind.ArrowFunction));
44
+ if (possiblyExportedFunction) {
45
+ functionBody = possiblyExportedFunction.getBody();
46
+ break;
47
+ }
48
+ }
49
+ if (Node.hasBody(expression) && (expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction)) {
50
+ functionBody = expression.getBody();
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ if (!functionBody || !Node.isStatemented(functionBody)) {
57
+ return -1;
58
+ }
59
+ if (functionBody.getStatements().length === 0) {
60
+ return -1;
61
+ }
62
+ const position = functionBody.getStatements()[0].getStart();
63
+ return sourceFile.getLineAndColumnAtPos(position);
64
+ }
65
+ async function getSourceMap(jsCode) {
66
+ const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") + "//# sourceMappingURL=data:application/json;base64,".length);
67
+ const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
68
+ const sourceMap = JSON.parse(sourceMapText);
69
+ return new SourceMapConsumer(sourceMap);
70
+ }
71
+ async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
72
+ const sourceMap = await getSourceMap(jsCode);
73
+ const generatedLineNumber = sourceMap.generatedPositionFor({
74
+ source: sourceFileName,
75
+ line,
76
+ column
77
+ }).line;
78
+ if (!generatedLineNumber) return -1;
79
+ return generatedLineNumber;
80
+ }
81
+ export default async function getFirstLineNumber(apiFilePath) {
82
+ const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
83
+ const {
84
+ sourceFile,
85
+ outputJSText
86
+ } = compileTypeScript(apiFilePath);
87
+ const result = findFirstExecutableLine(sourceFile);
88
+ if (result === -1) return {
89
+ sourceFileName,
90
+ lineNumber: -1
91
+ };
92
+ return {
93
+ sourceFileName,
94
+ lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column)
95
+ };
96
+ }
@@ -1,3 +1,5 @@
1
+ // Send information to the parent process where it should continue the debugger
2
+ // This is handled by DebuggingProcessManager
1
3
  export const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
2
- console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
3
- };
4
+ console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
5
+ };
@@ -0,0 +1,3 @@
1
+ export const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
2
+ console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
3
+ };
@@ -2,22 +2,22 @@ import * as path from "path";
2
2
  import * as fs from "fs-extra";
3
3
  import dotenv from "dotenv";
4
4
  dotenv.config();
5
+ // TODO: todo-identity handle identity instances
5
6
  export function getFullPathInProject(...paths) {
6
- return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
7
+ return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
7
8
  }
8
9
  export async function listProjectFilesAndFolders() {
9
- const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
10
- try {
11
- const files = await fs.readdir(projectPath, {
12
- withFileTypes: true
13
- });
14
- return files.map(file => ({
15
- type: file.isDirectory() ? "Folder" : "File",
16
- fullPath: path.join(projectPath, file.name),
17
- name: file.name
18
- }));
19
- } catch (err) {
20
- console.error("Error reading the directory:", err);
21
- throw err;
22
- }
23
- }
10
+ const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
11
+ try {
12
+ const files = await fs.readdir(projectPath, { withFileTypes: true });
13
+ return files.map((file) => ({
14
+ type: file.isDirectory() ? "Folder" : "File",
15
+ fullPath: path.join(projectPath, file.name),
16
+ name: file.name,
17
+ }));
18
+ }
19
+ catch (err) {
20
+ console.error("Error reading the directory:", err);
21
+ throw err;
22
+ }
23
+ }
@@ -0,0 +1,23 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs-extra";
3
+ import dotenv from "dotenv";
4
+ dotenv.config();
5
+ export function getFullPathInProject(...paths) {
6
+ return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
7
+ }
8
+ export async function listProjectFilesAndFolders() {
9
+ const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
10
+ try {
11
+ const files = await fs.readdir(projectPath, {
12
+ withFileTypes: true
13
+ });
14
+ return files.map(file => ({
15
+ type: file.isDirectory() ? "Folder" : "File",
16
+ fullPath: path.join(projectPath, file.name),
17
+ name: file.name
18
+ }));
19
+ } catch (err) {
20
+ console.error("Error reading the directory:", err);
21
+ throw err;
22
+ }
23
+ }
@@ -1,22 +1,20 @@
1
- import { getFullPathInProject } from "./fileUtils";
2
- import { settingsSchema } from "../../../common/settingsSchema";
1
+ import { getFullPathInProject } from "./fileUtils.js";
2
+ import { settingsSchema, } from "../../../common/settingsSchema";
3
3
  import { readJSON } from "fs-extra";
4
4
  export async function getSettings() {
5
- const settingsFilePath = getFullPathInProject("Intuned.json");
6
- console.log("loading settings");
7
- const settings = await readJSON(settingsFilePath);
8
- if (settings) {
9
- const parsed = settingsSchema.safeParse(settings);
10
- console.log(parsed);
11
- if (parsed.success) {
12
- return parsed.data;
13
- } else {
14
- throw new Error(parsed.error.message);
5
+ const settingsFilePath = getFullPathInProject("Intuned.json");
6
+ console.log("loading settings");
7
+ const settings = await readJSON(settingsFilePath);
8
+ if (settings) {
9
+ const parsed = settingsSchema.safeParse(settings);
10
+ console.log(parsed);
11
+ if (parsed.success) {
12
+ return parsed.data;
13
+ }
14
+ else {
15
+ // ToDo: why does the type not work here?
16
+ throw new Error(parsed.error.message);
17
+ }
15
18
  }
16
- }
17
- return {
18
- authSessions: {
19
- enabled: false
20
- }
21
- };
22
- }
19
+ return { authSessions: { enabled: false } };
20
+ }
@@ -0,0 +1,22 @@
1
+ import { getFullPathInProject } from "./fileUtils.js";
2
+ import { settingsSchema } from "../../../common/settingsSchema";
3
+ import { readJSON } from "fs-extra";
4
+ export async function getSettings() {
5
+ const settingsFilePath = getFullPathInProject("Intuned.json");
6
+ console.log("loading settings");
7
+ const settings = await readJSON(settingsFilePath);
8
+ if (settings) {
9
+ const parsed = settingsSchema.safeParse(settings);
10
+ console.log(parsed);
11
+ if (parsed.success) {
12
+ return parsed.data;
13
+ } else {
14
+ throw new Error(parsed.error.message);
15
+ }
16
+ }
17
+ return {
18
+ authSessions: {
19
+ enabled: false
20
+ }
21
+ };
22
+ }