@intuned/runtime-dev 0.1.0-test.13 → 0.1.0-test.15
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/bin/intuned-api-run +1 -1
- package/bin/intuned-auth-session-check +1 -1
- package/bin/intuned-auth-session-create +1 -1
- package/bin/intuned-auth-session-load +1 -1
- package/bin/intuned-auth-session-refresh +1 -1
- package/bin/intuned-browser-save-state +1 -1
- package/bin/intuned-browser-start +1 -1
- package/bin/intuned-build +1 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +83 -156
- package/dist/commands/auth-sessions/load.js +20 -20
- package/dist/commands/auth-sessions/run-check.js +39 -45
- package/dist/commands/auth-sessions/run-create.js +74 -84
- package/dist/commands/browser/save-state.js +7 -12
- package/dist/commands/browser/start-browser.js +4 -7
- package/dist/commands/build.js +62 -96
- package/dist/commands/common/browserUtils.js +30 -41
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -12
- package/dist/commands/common/getFirstLineNumber.js +83 -90
- package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +2 -1
- package/dist/commands/common/sendMessageToClient.js +2 -4
- package/dist/commands/common/utils/fileUtils.js +16 -16
- package/dist/commands/common/utils/settings.js +18 -16
- package/dist/commands/common/utils/unixSocket.js +36 -43
- package/dist/commands/common/utils/webTemplate.js +19 -25
- package/dist/commands/interface/run.js +133 -139
- package/dist/commands/ts-check.js +41 -44
- package/dist/common/Logger/Logger/index.js +46 -40
- package/dist/common/Logger/Logger/types.js +1 -1
- package/dist/common/Logger/index.js +46 -40
- package/dist/common/Logger/types.js +1 -1
- package/dist/common/asyncLocalStorage/index.js +4 -4
- package/dist/common/cleanEnvironmentVariables.js +9 -11
- package/dist/common/constants.js +1 -1
- package/dist/common/contextStorageStateHelpers.js +38 -36
- package/dist/common/getPlaywrightConstructs.js +158 -187
- package/dist/common/jwtTokenManager.js +61 -74
- package/dist/common/runApi/errors.js +121 -130
- package/dist/common/runApi/index.js +231 -217
- package/dist/common/runApi/types.js +41 -55
- package/dist/common/settingsSchema.js +6 -9
- package/dist/common/telemetry.js +16 -27
- package/dist/index.js +3 -3
- package/dist/runtime/RunError.js +10 -10
- package/dist/runtime/downloadDirectory.js +10 -10
- package/dist/runtime/enums.d.ts +11 -1
- package/dist/runtime/enums.js +12 -12
- package/dist/runtime/export.d.ts +202 -1
- package/dist/runtime/extendPayload.js +12 -12
- package/dist/runtime/extendTimeout.js +20 -19
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/requestMoreInfo.js +14 -14
- package/dist/runtime/runInfo.js +12 -11
- package/package.json +2 -3
- package/dist/commands/api/run.ts +0 -105
- package/dist/commands/auth-sessions/load.ts +0 -30
- package/dist/commands/auth-sessions/run-check.ts +0 -51
- package/dist/commands/auth-sessions/run-create.ts +0 -91
- package/dist/commands/browser/save-state.ts +0 -14
- package/dist/commands/browser/start-browser.ts +0 -11
- package/dist/commands/build.ts +0 -78
- package/dist/commands/common/browserUtils.ts +0 -45
- package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
- package/dist/commands/common/getFirstLineNumber.ts +0 -96
- package/dist/commands/common/sendMessageToClient.ts +0 -3
- package/dist/commands/common/utils/fileUtils.ts +0 -23
- package/dist/commands/common/utils/settings.ts +0 -22
- package/dist/commands/common/utils/unixSocket.ts +0 -38
- package/dist/commands/common/utils/webTemplate.ts +0 -22
- package/dist/commands/interface/run.ts +0 -156
- package/dist/commands/ts-check.ts +0 -50
- package/dist/common/Logger/Logger/index.ts +0 -53
- package/dist/common/Logger/index.ts +0 -53
- package/dist/common/asyncLocalStorage/index.ts +0 -9
- package/dist/common/cleanEnvironmentVariables.ts +0 -10
- package/dist/common/constants.ts +0 -1
- package/dist/common/contextStorageStateHelpers.ts +0 -43
- package/dist/common/getPlaywrightConstructs.ts +0 -181
- package/dist/common/jwtTokenManager.ts +0 -71
- package/dist/common/runApi/errors.ts +0 -154
- package/dist/common/runApi/index.ts +0 -253
- package/dist/common/runApi/types.ts +0 -43
- package/dist/common/settingsSchema.ts +0 -9
- package/dist/common/telemetry.ts +0 -23
- package/dist/index.ts +0 -4
- package/dist/runtime/RunError.ts +0 -12
- package/dist/runtime/downloadDirectory.ts +0 -13
- package/dist/runtime/enums.ts +0 -12
- package/dist/runtime/extendPayload.ts +0 -15
- package/dist/runtime/extendTimeout.ts +0 -24
- package/dist/runtime/index.ts +0 -6
- package/dist/runtime/requestMoreInfo.ts +0 -18
- package/dist/runtime/runInfo.ts +0 -15
- /package/dist/{common/Logger/Logger/types.ts → runtime/enums.d.js} +0 -0
- /package/dist/runtime/{executionHelpers.test.ts → executionHelpers.test.js} +0 -0
- /package/dist/{common/Logger/types.ts → runtime/export.d.js} +0 -0
package/dist/commands/build.js
CHANGED
|
@@ -9,106 +9,72 @@ import json from "@rollup/plugin-json";
|
|
|
9
9
|
import * as fs from "fs-extra";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import { moveWebTemplateFiles } from "./common/utils/webTemplate.js";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
12
13
|
function isThirdPartyWarning(warning) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
return false;
|
|
14
|
+
if (warning.id && /node_modules/.test(warning.id)) return true;
|
|
15
|
+
if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
|
|
16
|
+
return false;
|
|
18
17
|
}
|
|
19
18
|
import dotenv from "dotenv";
|
|
20
19
|
dotenv.config();
|
|
21
|
-
program
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.argOptional())
|
|
27
|
-
.argument("[outfile]", "output bundle", "./output/bundle_v2.js")
|
|
28
|
-
.allowUnknownOption()
|
|
29
|
-
.action(async (mode, outfile) => {
|
|
30
|
-
await moveWebTemplateFiles();
|
|
31
|
-
const currentTemplateTsConfig = path.resolve(path.dirname(import.meta.url), "..", "..", "template.tsconfig.json");
|
|
32
|
-
await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
|
|
33
|
-
await build(outfile, mode);
|
|
20
|
+
program.description("build the intuned server").addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile) => {
|
|
21
|
+
await moveWebTemplateFiles();
|
|
22
|
+
const currentTemplateTsConfig = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "template.tsconfig.json");
|
|
23
|
+
await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
|
|
24
|
+
await build(outfile, mode);
|
|
34
25
|
});
|
|
35
26
|
async function build(outfile, mode) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"applicationinsights",
|
|
89
|
-
"fingerprint-generator",
|
|
90
|
-
"fingerprint-injector",
|
|
91
|
-
],
|
|
92
|
-
});
|
|
93
|
-
console.log(`📦 Building ${outfile}`);
|
|
94
|
-
const outfileFolder = path.dirname(outfile);
|
|
95
|
-
// copy assets to outfile folder
|
|
96
|
-
const assetsDir = path.resolve(path.dirname(import.meta.url), "..", "common", "assets");
|
|
97
|
-
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
98
|
-
await bundle.write({
|
|
99
|
-
format: "cjs",
|
|
100
|
-
file: outfile,
|
|
101
|
-
inlineDynamicImports: true,
|
|
102
|
-
});
|
|
103
|
-
console.log(`✨ Build succeeded: ${outfile}`);
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
buildFailed = true;
|
|
107
|
-
console.error("error", error);
|
|
108
|
-
}
|
|
109
|
-
if (buildFailed) {
|
|
110
|
-
console.error("build failed");
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
27
|
+
let bundle = null;
|
|
28
|
+
let buildFailed = false;
|
|
29
|
+
try {
|
|
30
|
+
bundle = await rollup({
|
|
31
|
+
input: `./intuned/WebTemplate/index.${mode}.ts`,
|
|
32
|
+
output: {
|
|
33
|
+
globals: {
|
|
34
|
+
crypto: "crypto"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
plugins: [json(), nodeResolve({
|
|
38
|
+
exportConditions: ["node"],
|
|
39
|
+
preferBuiltins: true
|
|
40
|
+
}), typescript({
|
|
41
|
+
tsconfig: "./intuned/WebTemplate/tsconfig.json",
|
|
42
|
+
exclude: ["**/*.d.ts"]
|
|
43
|
+
}), commonjs({
|
|
44
|
+
include: ["node_modules/**", "intuned/WebTemplate/**", "dist", "../typescript-sdk/**"],
|
|
45
|
+
extensions: [".js"],
|
|
46
|
+
ignoreGlobal: false,
|
|
47
|
+
sourceMap: false,
|
|
48
|
+
dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
|
|
49
|
+
requireReturnsDefault: "auto",
|
|
50
|
+
transformMixedEsModules: true
|
|
51
|
+
}), dynamicImportVars({
|
|
52
|
+
include: ["**/*.js"],
|
|
53
|
+
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
54
|
+
})],
|
|
55
|
+
onwarn: (warning, warn) => {
|
|
56
|
+
if (isThirdPartyWarning(warning)) return;
|
|
57
|
+
warn(warning);
|
|
58
|
+
},
|
|
59
|
+
external: ["@intuned/playwright", "@intuned/playwright-core", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector"]
|
|
60
|
+
});
|
|
61
|
+
console.log(`📦 Building ${outfile}`);
|
|
62
|
+
const outfileFolder = path.dirname(outfile);
|
|
63
|
+
const assetsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "common", "assets");
|
|
64
|
+
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
65
|
+
await bundle.write({
|
|
66
|
+
format: "cjs",
|
|
67
|
+
file: outfile,
|
|
68
|
+
inlineDynamicImports: true
|
|
69
|
+
});
|
|
70
|
+
console.log(`✨ Build succeeded: ${outfile}`);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
buildFailed = true;
|
|
73
|
+
console.error("error", error);
|
|
74
|
+
}
|
|
75
|
+
if (buildFailed) {
|
|
76
|
+
console.error("build failed");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
113
79
|
}
|
|
114
|
-
program.parse(process.argv);
|
|
80
|
+
program.parse(process.argv);
|
|
@@ -1,56 +1,45 @@
|
|
|
1
|
-
// this file is to make testing easier only.
|
|
2
1
|
import { spawn } from "child_process";
|
|
3
2
|
import * as playwright from "@intuned/playwright-core";
|
|
4
3
|
import * as fs from "fs-extra";
|
|
5
4
|
import { getFullPathInProject } from "./utils/fileUtils.js";
|
|
6
5
|
import { getContextStorageState } from "../../common/contextStorageStateHelpers";
|
|
7
6
|
export const REMOTE_DEBUGGING_PORT = 9222;
|
|
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.
|
|
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"];
|
|
17
8
|
async function getBrowser() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return playwrightBrowser;
|
|
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;
|
|
26
16
|
}
|
|
27
17
|
export async function startOrRestartBrowser() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
});
|
|
36
26
|
}
|
|
37
27
|
export async function saveSessionFromOpenedBrowser(path) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
const browser = await getBrowser();
|
|
29
|
+
const context = await browser.contexts()[0];
|
|
30
|
+
return saveSession(path, context);
|
|
41
31
|
}
|
|
42
32
|
export async function loadState(path, context) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// ToDo: logic to load storage without using the page.
|
|
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);
|
|
50
39
|
}
|
|
51
40
|
export async function saveSession(path, context) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
41
|
+
const fullState = await getContextStorageState(context);
|
|
42
|
+
const fullPath = getFullPathInProject(path);
|
|
43
|
+
fs.ensureFileSync(fullPath);
|
|
44
|
+
await fs.writeJSON(fullPath, fullState);
|
|
45
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getDefaultExportFromFile(apiFilePath: string): Promise<any>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export async function getDefaultExportFromFile(apiFilePath) {
|
|
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
|
-
}
|
|
@@ -1,103 +1,96 @@
|
|
|
1
|
-
import { ts, Project, ModuleKind, ScriptTarget, Node
|
|
1
|
+
import { ts, Project, ModuleKind, ScriptTarget, Node } from "ts-morph";
|
|
2
2
|
import { SourceMapConsumer } from "source-map";
|
|
3
3
|
function compileTypeScript(apiFilePath) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
};
|
|
21
26
|
}
|
|
22
27
|
export function findFirstExecutableLine(sourceFile) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
48
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
}
|
|
49
|
+
if (Node.hasBody(expression) && (expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction)) {
|
|
50
|
+
functionBody = expression.getBody();
|
|
51
|
+
break;
|
|
62
52
|
}
|
|
53
|
+
}
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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);
|
|
72
64
|
}
|
|
73
65
|
async function getSourceMap(jsCode) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return new SourceMapConsumer(sourceMap);
|
|
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);
|
|
79
70
|
}
|
|
80
71
|
async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return generatedLineNumber;
|
|
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;
|
|
90
80
|
}
|
|
91
81
|
export default async function getFirstLineNumber(apiFilePath) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
@@ -2,8 +2,9 @@ import { expect, describe, it, beforeAll, afterAll } from "vitest";
|
|
|
2
2
|
import getFirstLineNumber from "./getFirstLineNumber.js";
|
|
3
3
|
import * as fs from "fs";
|
|
4
4
|
import * as path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
5
6
|
describe("getFirstLineNumber", () => {
|
|
6
|
-
const testFilesDir = path.join(path.dirname(import.meta.url), "testFiles");
|
|
7
|
+
const testFilesDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "testFiles");
|
|
7
8
|
const createTestFile = (fileName, content) => {
|
|
8
9
|
const filePath = path.join(testFilesDir, fileName);
|
|
9
10
|
fs.writeFileSync(filePath, content);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Send information to the parent process where it should continue the debugger
|
|
2
|
-
// This is handled by DebuggingProcessManager
|
|
3
1
|
export const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
|
|
4
|
-
|
|
5
|
-
};
|
|
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
|
|
6
5
|
export function getFullPathInProject(...paths) {
|
|
7
|
-
|
|
6
|
+
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
8
7
|
}
|
|
9
8
|
export async function listProjectFilesAndFolders() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
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,20 +1,22 @@
|
|
|
1
1
|
import { getFullPathInProject } from "./fileUtils.js";
|
|
2
|
-
import { settingsSchema
|
|
2
|
+
import { settingsSchema } from "../../../common/settingsSchema";
|
|
3
3
|
import { readJSON } from "fs-extra";
|
|
4
4
|
export async function getSettings() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// ToDo: why does the type not work here?
|
|
16
|
-
throw new Error(parsed.error.message);
|
|
17
|
-
}
|
|
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);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
authSessions: {
|
|
19
|
+
enabled: false
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
export class JSONUnixSocket {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
static LENGTH_HEADER_LENGTH = 4;
|
|
3
|
+
constructor(socket) {
|
|
4
|
+
this.socket = socket;
|
|
5
|
+
}
|
|
6
|
+
sendJSON(data) {
|
|
7
|
+
const dataToSend = JSON.stringify(data);
|
|
8
|
+
const length = Buffer.byteLength(dataToSend);
|
|
9
|
+
const buffer = Buffer.alloc(JSONUnixSocket.LENGTH_HEADER_LENGTH + length);
|
|
10
|
+
buffer.writeUInt32BE(length, 0);
|
|
11
|
+
buffer.write(dataToSend, JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
12
|
+
this.socket.write(buffer);
|
|
13
|
+
}
|
|
14
|
+
async *receiveJSON() {
|
|
15
|
+
let buffer = Buffer.alloc(0);
|
|
16
|
+
const endPromise = new Promise((resolve, reject) => {
|
|
17
|
+
this.socket.once("end", () => {
|
|
18
|
+
console.log("end");
|
|
19
|
+
resolve();
|
|
20
|
+
});
|
|
21
|
+
this.socket.once("error", reject);
|
|
22
|
+
});
|
|
23
|
+
while (true) {
|
|
24
|
+
const chunk = await Promise.race([new Promise(resolve => this.socket.once("data", data => resolve(data))), endPromise]);
|
|
25
|
+
if (!(chunk instanceof Buffer)) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
29
|
+
const length = buffer.readUInt32BE(0);
|
|
30
|
+
if (buffer.length < length + JSONUnixSocket.LENGTH_HEADER_LENGTH) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const data = buffer.subarray(JSONUnixSocket.LENGTH_HEADER_LENGTH, length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
34
|
+
buffer = buffer.subarray(length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
35
|
+
yield JSON.parse(data.toString());
|
|
4
36
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// calculate length
|
|
8
|
-
const length = Buffer.byteLength(dataToSend);
|
|
9
|
-
// create buffer
|
|
10
|
-
const buffer = Buffer.alloc(JSONUnixSocket.LENGTH_HEADER_LENGTH + length);
|
|
11
|
-
// write length in big endian
|
|
12
|
-
buffer.writeUInt32BE(length, 0);
|
|
13
|
-
// write data
|
|
14
|
-
buffer.write(dataToSend, JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
15
|
-
this.socket.write(buffer);
|
|
16
|
-
}
|
|
17
|
-
async *receiveJSON() {
|
|
18
|
-
let buffer = Buffer.alloc(0);
|
|
19
|
-
const endPromise = new Promise((resolve, reject) => {
|
|
20
|
-
this.socket.once("end", () => {
|
|
21
|
-
console.log("end");
|
|
22
|
-
resolve();
|
|
23
|
-
});
|
|
24
|
-
this.socket.once("error", reject);
|
|
25
|
-
});
|
|
26
|
-
while (true) {
|
|
27
|
-
const chunk = await Promise.race([
|
|
28
|
-
new Promise((resolve) => this.socket.once("data", (data) => resolve(data))),
|
|
29
|
-
endPromise,
|
|
30
|
-
]);
|
|
31
|
-
if (!(chunk instanceof Buffer)) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
buffer = Buffer.concat([buffer, chunk]);
|
|
35
|
-
const length = buffer.readUInt32BE(0);
|
|
36
|
-
if (buffer.length < length + JSONUnixSocket.LENGTH_HEADER_LENGTH) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const data = buffer.subarray(JSONUnixSocket.LENGTH_HEADER_LENGTH, length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
40
|
-
buffer = buffer.subarray(length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
|
|
41
|
-
yield JSON.parse(data.toString());
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
JSONUnixSocket.LENGTH_HEADER_LENGTH = 4;
|
|
37
|
+
}
|
|
38
|
+
}
|