@intuned/runtime-dev 1.3.18-interface.13 → 1.3.18-interface.16
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/.babelrc +27 -0
- package/.claude/settings.local.json +7 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/InterfaceTemplate/__utils.ts +3 -1
- package/WebTemplate.zip +0 -0
- package/dist/commands/api/run.d.ts +1 -3
- package/dist/commands/api/run.js +64 -2039
- package/dist/commands/auth-sessions/load.d.ts +1 -0
- package/dist/commands/auth-sessions/load.js +28 -1552
- package/dist/commands/auth-sessions/run-check.d.ts +1 -0
- package/dist/commands/auth-sessions/run-check.js +71 -1961
- package/dist/commands/auth-sessions/run-create.d.ts +1 -0
- package/dist/commands/auth-sessions/run-create.js +65 -1955
- package/dist/commands/browser/save-state.d.ts +1 -0
- package/dist/commands/browser/save-state.js +11 -102
- package/dist/commands/browser/start-browser.d.ts +1 -0
- package/dist/commands/browser/start-browser.js +9 -62
- package/dist/commands/build.d.ts +1 -2
- package/dist/commands/build.js +52 -172
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +57 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +101 -0
- package/dist/commands/common/getFirstLineNumber.test.js +227 -0
- package/dist/commands/common/projectExclusions.d.ts +2 -0
- package/dist/commands/common/projectExclusions.js +8 -0
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/tsNodeImport.d.ts +2 -5
- package/dist/commands/common/tsNodeImport.js +15 -55
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +32 -0
- package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
- package/dist/commands/common/utils/interfaceClient.js +98 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +31 -0
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/template.js +30 -0
- package/dist/commands/get-headless-user-agent.d.ts +1 -2
- package/dist/commands/get-headless-user-agent.js +12 -348
- package/dist/commands/interface/pingPong.d.ts +2 -0
- package/dist/commands/interface/pingPong.js +11 -0
- package/dist/commands/interface/run.d.ts +1 -3
- package/dist/commands/interface/run.js +139 -2034
- package/dist/commands/interface/runApi.d.ts +1 -0
- package/dist/commands/interface/runApi.js +102 -0
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
- package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/build.command.js +12 -0
- package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
- package/dist/commands/intuned-cli/commands/command.js +9 -0
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
- package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
- package/dist/commands/intuned-cli/commands/index.js +203 -0
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
- package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
- package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run.command.js +8 -0
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
- package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
- package/dist/commands/intuned-cli/commands/types.js +33 -0
- package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
- package/dist/commands/intuned-cli/constants/index.js +25 -0
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +398 -0
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1060 -0
- package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
- package/dist/commands/intuned-cli/controller/api.js +194 -0
- package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
- package/dist/commands/intuned-cli/controller/authSession.js +425 -0
- package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/build.js +35 -0
- package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
- package/dist/commands/intuned-cli/controller/deploy.js +317 -0
- package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/index.js +45 -0
- package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
- package/dist/commands/intuned-cli/controller/provision.js +299 -0
- package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
- package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/api.js +16 -0
- package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
- package/dist/commands/intuned-cli/helpers/auth.js +147 -0
- package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
- package/dist/commands/intuned-cli/helpers/backend.js +35 -0
- package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
- package/dist/commands/intuned-cli/helpers/browser.js +93 -0
- package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/context.js +33 -0
- package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
- package/dist/commands/intuned-cli/helpers/errors.js +44 -0
- package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
- package/dist/commands/intuned-cli/helpers/index.js +137 -0
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +39 -0
- package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
- package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
- package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
- package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/traces.js +32 -0
- package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/validation.js +14 -0
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
- package/dist/commands/intuned-cli/index.d.ts +1 -0
- package/dist/commands/intuned-cli/index.js +16 -0
- package/dist/commands/intuned-cli/main.d.ts +1 -2
- package/dist/commands/intuned-cli/main.js +24 -5392
- package/dist/commands/intuned-cli/types.d.ts +70 -0
- package/dist/commands/intuned-cli/types.js +22 -0
- package/dist/commands/ts-check.d.ts +1 -0
- package/dist/commands/ts-check.js +28 -131
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/dist/common/Logger/Logger/types.d.ts +8 -0
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/dist/common/Logger/types.d.ts +8 -0
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +8 -9
- package/dist/common/asyncLocalStorage/index.js +9 -33
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
- package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
- package/dist/common/binStartupScript.d.ts +1 -2
- package/dist/common/binStartupScript.js +10 -126
- package/dist/common/browserTabs.d.ts +72 -0
- package/dist/common/browserTabs.js +74 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -3
- package/dist/common/cleanEnvironmentVariables.js +7 -29
- package/dist/common/constants.d.ts +11 -13
- package/dist/common/constants.js +15 -57
- package/dist/common/contextStorageStateHelpers.d.ts +6 -8
- package/dist/common/contextStorageStateHelpers.js +22 -46
- package/dist/common/extension/extensionsHelpers.d.ts +11 -0
- package/dist/common/extension/extensionsHelpers.js +147 -0
- package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
- package/dist/common/extension/intunedExtensionServer.js +178 -0
- package/dist/common/extension/types.d.ts +219 -0
- package/dist/common/extension/types.js +51 -0
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/intunedJson.d.ts +229 -0
- package/dist/common/intunedJson.js +132 -0
- package/dist/common/jwtTokenManager.d.ts +4 -6
- package/dist/common/jwtTokenManager.js +40 -107
- package/dist/common/launchBrowser.d.ts +34 -0
- package/dist/common/launchBrowser.js +247 -0
- package/dist/common/playwrightContext.d.ts +29 -0
- package/dist/common/playwrightContext.js +148 -0
- package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
- package/dist/common/runApi/importUsingImportFunction.js +46 -0
- package/dist/common/runApi/index.d.ts +6 -9
- package/dist/common/runApi/index.js +70 -1765
- package/dist/common/settingsSchema.d.ts +6 -9
- package/dist/common/settingsSchema.js +18 -53
- package/dist/common/setupContextHook.d.ts +16 -0
- package/dist/common/setupContextHook.js +22 -0
- package/dist/common/telemetry.d.ts +3 -6
- package/dist/common/telemetry.js +8 -40
- package/dist/index.d.ts +4 -6
- package/dist/index.js +92 -783
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/attemptStore.d.ts +2 -0
- package/dist/runtime/attemptStore.js +23 -0
- package/dist/runtime/captcha.d.ts +15 -0
- package/dist/runtime/captcha.js +191 -0
- package/dist/runtime/captcha.test.js +821 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.d.ts +11 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +52 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/export.d.ts +284 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +23 -0
- package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
- package/dist/runtime/getAiGatewayConfig.js +16 -0
- package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
- package/dist/runtime/getAuthSessionParameters.js +20 -0
- package/dist/runtime/index.d.ts +10 -168
- package/dist/runtime/index.js +88 -778
- package/dist/runtime/persistentStore.d.ts +2 -0
- package/dist/runtime/persistentStore.js +37 -0
- package/dist/runtime/persistentStore.test.js +101 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/dist/vendor/runtime-interface.d.ts +1 -0
- package/dist/vendor/runtime-interface.js +474 -0
- package/package.json +18 -72
- package/template.tsconfig.json +11 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +49 -0
- package/dist/export.d-BAUMB-lG.d.ts +0 -140
|
@@ -1,108 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
2
|
+
"use strict";
|
|
24
3
|
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// src/commands/common/utils/fileUtils.ts
|
|
32
|
-
var path = __toESM(require("path"));
|
|
33
|
-
var fs = __toESM(require("fs-extra"));
|
|
34
|
-
var import_dotenv = __toESM(require("dotenv"));
|
|
35
|
-
import_dotenv.default.config();
|
|
36
|
-
function getFullPathInProject(...paths) {
|
|
37
|
-
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/common/contextStorageStateHelpers.ts
|
|
41
|
-
async function getStorageState(context) {
|
|
42
|
-
const result = {
|
|
43
|
-
cookies: [],
|
|
44
|
-
origins: []
|
|
45
|
-
};
|
|
46
|
-
const storageState = await context.storageState();
|
|
47
|
-
result.cookies = storageState.cookies;
|
|
48
|
-
result.origins = storageState.origins;
|
|
49
|
-
const sessionDataList = [];
|
|
50
|
-
const pages = await context.pages();
|
|
51
|
-
for (const page of pages) {
|
|
52
|
-
if (page.isClosed()) continue;
|
|
53
|
-
try {
|
|
54
|
-
const sessionData = await page.evaluate(() => {
|
|
55
|
-
const items = { ...window.sessionStorage };
|
|
56
|
-
return {
|
|
57
|
-
origin: window.location.origin,
|
|
58
|
-
sessionStorage: Object.entries(items).map(([name, value]) => ({
|
|
59
|
-
name,
|
|
60
|
-
value
|
|
61
|
-
}))
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
sessionDataList.push(sessionData);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error("Error getting sessionStorage:", error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
result["sessionStorage"] = sessionDataList;
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/commands/common/browserUtils.ts
|
|
74
|
-
var playwright = __toESM(require("playwright"));
|
|
75
|
-
var REMOTE_DEBUGGING_PORT = 9222;
|
|
76
|
-
async function getBrowser() {
|
|
77
|
-
let playwrightBrowser = null;
|
|
78
|
-
try {
|
|
79
|
-
playwrightBrowser = await playwright.chromium.connectOverCDP(
|
|
80
|
-
`http://localhost:${REMOTE_DEBUGGING_PORT}`
|
|
81
|
-
);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
throw new Error("Browser is not running");
|
|
84
|
-
}
|
|
85
|
-
return playwrightBrowser;
|
|
86
|
-
}
|
|
87
|
-
async function saveSessionFromOpenedBrowser(path2) {
|
|
88
|
-
const browser = await getBrowser();
|
|
89
|
-
const context = await browser.contexts()[0];
|
|
90
|
-
return saveSession(path2, context);
|
|
91
|
-
}
|
|
92
|
-
async function saveSession(path2, context) {
|
|
93
|
-
const fullState = await getStorageState(context);
|
|
94
|
-
const fullPath = getFullPathInProject(path2);
|
|
95
|
-
fs2.ensureFileSync(fullPath);
|
|
96
|
-
await fs2.writeJSON(fullPath, fullState);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// src/commands/browser/save-state.ts
|
|
100
|
-
var import_dotenv2 = __toESM(require("dotenv"));
|
|
101
|
-
import_dotenv2.default.config({
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _browserUtils = require("../common/browserUtils");
|
|
6
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
_dotenv.default.config({
|
|
102
9
|
path: `.env`
|
|
103
10
|
});
|
|
104
|
-
|
|
105
|
-
|
|
11
|
+
_commander.program.description("save browser state to file storage.json").option("-p, --path [file]", "path for file", "./localSessions/default.json").allowUnknownOption().action(async ({
|
|
12
|
+
path
|
|
13
|
+
}) => {
|
|
14
|
+
await (0, _browserUtils.saveSessionFromOpenedBrowser)(path);
|
|
106
15
|
process.exit(0);
|
|
107
16
|
});
|
|
108
|
-
|
|
17
|
+
_commander.program.parse(process.argv);
|
|
@@ -1,67 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
2
|
+
"use strict";
|
|
24
3
|
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var fs2 = __toESM(require("fs-extra"));
|
|
31
|
-
|
|
32
|
-
// src/commands/common/utils/fileUtils.ts
|
|
33
|
-
var fs = __toESM(require("fs-extra"));
|
|
34
|
-
var import_dotenv = __toESM(require("dotenv"));
|
|
35
|
-
import_dotenv.default.config();
|
|
36
|
-
|
|
37
|
-
// src/commands/common/browserUtils.ts
|
|
38
|
-
var playwright = __toESM(require("playwright"));
|
|
39
|
-
var REMOTE_DEBUGGING_PORT = 9222;
|
|
40
|
-
var getChromiumLaunchArgs = () => [
|
|
41
|
-
"--no-sandbox",
|
|
42
|
-
`--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
|
|
43
|
-
`--user-data-dir=/tmp/${Date.now()}`,
|
|
44
|
-
"--new-window",
|
|
45
|
-
"--start-maximized",
|
|
46
|
-
"--disable-popup-blocking"
|
|
47
|
-
];
|
|
48
|
-
async function startOrRestartBrowser() {
|
|
49
|
-
const chromiumPath = playwright.chromium.executablePath();
|
|
50
|
-
const chromeInstanceProcess = (0, import_child_process.spawn)(chromiumPath, getChromiumLaunchArgs());
|
|
51
|
-
chromeInstanceProcess.stdout.on("data", (data) => {
|
|
52
|
-
console.log(`Chrome stdout: ${data}`);
|
|
53
|
-
});
|
|
54
|
-
chromeInstanceProcess.stderr.on("data", (data) => {
|
|
55
|
-
console.error(`Chrome stderr: ${data}`);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/commands/browser/start-browser.ts
|
|
60
|
-
var import_dotenv2 = __toESM(require("dotenv"));
|
|
61
|
-
import_dotenv2.default.config({
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _browserUtils = require("../common/browserUtils");
|
|
6
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
_dotenv.default.config({
|
|
62
9
|
path: `.env`
|
|
63
10
|
});
|
|
64
|
-
|
|
65
|
-
await startOrRestartBrowser();
|
|
11
|
+
_commander.program.description("start browser testing purposes").allowUnknownOption().action(async () => {
|
|
12
|
+
await (0, _browserUtils.startOrRestartBrowser)();
|
|
66
13
|
});
|
|
67
|
-
|
|
14
|
+
_commander.program.parse(process.argv);
|
package/dist/commands/build.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export {};
|
package/dist/commands/build.js
CHANGED
|
@@ -1,196 +1,76 @@
|
|
|
1
|
-
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
|
|
24
|
-
// src/commands/build.ts
|
|
25
|
-
var import_commander = require("commander");
|
|
26
|
-
var import_rollup = require("rollup");
|
|
27
|
-
var import_plugin_typescript = __toESM(require("@rollup/plugin-typescript"));
|
|
28
|
-
var import_plugin_commonjs = __toESM(require("@rollup/plugin-commonjs"));
|
|
29
|
-
var import_plugin_node_resolve = require("@rollup/plugin-node-resolve");
|
|
30
|
-
var import_plugin_dynamic_import_vars = __toESM(require("@rollup/plugin-dynamic-import-vars"));
|
|
31
|
-
var import_plugin_json = __toESM(require("@rollup/plugin-json"));
|
|
32
|
-
var fs3 = __toESM(require("fs-extra"));
|
|
33
|
-
var path3 = __toESM(require("path"));
|
|
34
|
-
|
|
35
|
-
// src/commands/common/utils/template.ts
|
|
36
|
-
var fs2 = __toESM(require("fs-extra"));
|
|
37
|
-
var path2 = __toESM(require("path"));
|
|
1
|
+
"use strict";
|
|
38
2
|
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
type: file.isDirectory() ? "Folder" : "File",
|
|
53
|
-
fullPath: path.join(projectPath, file.name),
|
|
54
|
-
name: file.name
|
|
55
|
-
}));
|
|
56
|
-
} catch (err) {
|
|
57
|
-
console.error("Error reading the directory:", err);
|
|
58
|
-
throw err;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/commands/common/utils/template.ts
|
|
63
|
-
var moveTemplateFiles = async (templateName) => {
|
|
64
|
-
await fs2.remove("./intuned");
|
|
65
|
-
await fs2.ensureDir("./intuned");
|
|
66
|
-
const currentFileLocation = path2.resolve(
|
|
67
|
-
__dirname,
|
|
68
|
-
"..",
|
|
69
|
-
"..",
|
|
70
|
-
"..",
|
|
71
|
-
"..",
|
|
72
|
-
templateName
|
|
73
|
-
);
|
|
74
|
-
await fs2.copy(`${currentFileLocation}`, `./intuned/${templateName}`, {
|
|
75
|
-
filter: (src, _) => {
|
|
76
|
-
if (src.includes(".d.ts")) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
const filesAndFolders = await listProjectFilesAndFolders();
|
|
83
|
-
const pathsIgnoreList = [
|
|
84
|
-
getFullPathInProject("intuned"),
|
|
85
|
-
getFullPathInProject("node_modules"),
|
|
86
|
-
getFullPathInProject("package.json"),
|
|
87
|
-
getFullPathInProject("yarn.lock"),
|
|
88
|
-
getFullPathInProject(".env")
|
|
89
|
-
];
|
|
90
|
-
const filesToCopy = filesAndFolders.filter(
|
|
91
|
-
(file) => !pathsIgnoreList.includes(file.fullPath)
|
|
92
|
-
);
|
|
93
|
-
for (const file of filesToCopy) {
|
|
94
|
-
await fs2.copy(file.fullPath, `./intuned/${templateName}/${file.name}`);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/commands/build.ts
|
|
99
|
-
var import_dotenv2 = __toESM(require("dotenv"));
|
|
3
|
+
var _commander = require("commander");
|
|
4
|
+
var _rollup = require("rollup");
|
|
5
|
+
var _pluginTypescript = _interopRequireDefault(require("@rollup/plugin-typescript"));
|
|
6
|
+
var _pluginCommonjs = _interopRequireDefault(require("@rollup/plugin-commonjs"));
|
|
7
|
+
var _pluginNodeResolve = require("@rollup/plugin-node-resolve");
|
|
8
|
+
var _pluginDynamicImportVars = _interopRequireDefault(require("@rollup/plugin-dynamic-import-vars"));
|
|
9
|
+
var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
|
|
10
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
11
|
+
var path = _interopRequireWildcard(require("path"));
|
|
12
|
+
var _template = require("./common/utils/template");
|
|
13
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
100
16
|
function isThirdPartyWarning(warning) {
|
|
101
17
|
if (warning.id && /node_modules/.test(warning.id)) return true;
|
|
102
|
-
if (warning.ids && warning.ids.every(
|
|
103
|
-
return true;
|
|
18
|
+
if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
|
|
104
19
|
return false;
|
|
105
20
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
path3.dirname(__filename),
|
|
116
|
-
"..",
|
|
117
|
-
"..",
|
|
118
|
-
"template.tsconfig.json"
|
|
119
|
-
);
|
|
120
|
-
await fs3.copy(
|
|
121
|
-
currentTemplateTsConfig,
|
|
122
|
-
`./intuned/${template}/tsconfig.json`
|
|
123
|
-
);
|
|
124
|
-
await build(outfile, mode, template);
|
|
125
|
-
}
|
|
126
|
-
);
|
|
21
|
+
_dotenv.default.config();
|
|
22
|
+
_commander.program.description("build the intuned server").option("-t, --template <type>", "template to use", "InterfaceTemplate").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile, {
|
|
23
|
+
template
|
|
24
|
+
}) => {
|
|
25
|
+
await (0, _template.moveTemplateFiles)(template);
|
|
26
|
+
const currentTemplateTsConfig = path.resolve(path.dirname(__filename), "..", "..", "template.tsconfig.json");
|
|
27
|
+
await fs.copy(currentTemplateTsConfig, `./intuned/${template}/tsconfig.json`);
|
|
28
|
+
await build(outfile, mode, template);
|
|
29
|
+
});
|
|
127
30
|
async function build(outfile, mode, template) {
|
|
128
31
|
let bundle = null;
|
|
129
32
|
let buildFailed = false;
|
|
130
33
|
try {
|
|
131
|
-
bundle = await (0,
|
|
34
|
+
bundle = await (0, _rollup.rollup)({
|
|
132
35
|
input: `./intuned/${template}/index.${mode}.ts`,
|
|
133
36
|
output: {
|
|
134
|
-
globals: {
|
|
37
|
+
globals: {
|
|
38
|
+
crypto: "crypto"
|
|
39
|
+
}
|
|
135
40
|
},
|
|
136
|
-
plugins: [
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
requireReturnsDefault: "auto",
|
|
154
|
-
transformMixedEsModules: true
|
|
155
|
-
}),
|
|
156
|
-
(0, import_plugin_dynamic_import_vars.default)({
|
|
157
|
-
include: ["**/*.js", "**/*.ts"],
|
|
158
|
-
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
159
|
-
})
|
|
160
|
-
],
|
|
41
|
+
plugins: [(0, _pluginJson.default)(), (0, _pluginNodeResolve.nodeResolve)({
|
|
42
|
+
exportConditions: ["node"],
|
|
43
|
+
preferBuiltins: true
|
|
44
|
+
}), (0, _pluginTypescript.default)({
|
|
45
|
+
tsconfig: `./intuned/${template}/tsconfig.json`
|
|
46
|
+
}), (0, _pluginCommonjs.default)({
|
|
47
|
+
include: ["node_modules/**", `intuned/${template}/**`, "dist", "../typescript-runtime/**"],
|
|
48
|
+
extensions: [".js"],
|
|
49
|
+
ignoreGlobal: false,
|
|
50
|
+
sourceMap: false,
|
|
51
|
+
dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
|
|
52
|
+
requireReturnsDefault: "auto",
|
|
53
|
+
transformMixedEsModules: true
|
|
54
|
+
}), (0, _pluginDynamicImportVars.default)({
|
|
55
|
+
include: ["**/*.js", "**/*.ts"],
|
|
56
|
+
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
57
|
+
})],
|
|
161
58
|
onwarn: (warning, warn) => {
|
|
162
59
|
if (isThirdPartyWarning(warning)) return;
|
|
163
60
|
warn(warning);
|
|
164
61
|
},
|
|
165
|
-
external: [
|
|
166
|
-
"playwright",
|
|
167
|
-
"playwright-core",
|
|
168
|
-
"jsdom",
|
|
169
|
-
"canvas",
|
|
170
|
-
"pdfjs-dist",
|
|
171
|
-
"pdf-to-png-converter",
|
|
172
|
-
"crypto",
|
|
173
|
-
"applicationinsights",
|
|
174
|
-
"fingerprint-generator",
|
|
175
|
-
"fingerprint-injector",
|
|
176
|
-
"node-fetch"
|
|
177
|
-
]
|
|
62
|
+
external: ["playwright", "playwright-core", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector", "node-fetch"]
|
|
178
63
|
});
|
|
179
|
-
console.log(
|
|
180
|
-
const outfileFolder =
|
|
181
|
-
const assetsDir =
|
|
182
|
-
|
|
183
|
-
"..",
|
|
184
|
-
"common",
|
|
185
|
-
"assets"
|
|
186
|
-
);
|
|
187
|
-
await fs3.copy(assetsDir, `${outfileFolder}/assets`);
|
|
64
|
+
console.log(`📦 Building ${outfile}`);
|
|
65
|
+
const outfileFolder = path.dirname(outfile);
|
|
66
|
+
const assetsDir = path.resolve(path.dirname(__filename), "..", "common", "assets");
|
|
67
|
+
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
188
68
|
await bundle.write({
|
|
189
69
|
format: "cjs",
|
|
190
70
|
file: outfile,
|
|
191
71
|
inlineDynamicImports: true
|
|
192
72
|
});
|
|
193
|
-
console.log(
|
|
73
|
+
console.log(`✨ Build succeeded: ${outfile}`);
|
|
194
74
|
} catch (error) {
|
|
195
75
|
buildFailed = true;
|
|
196
76
|
console.error("error", error);
|
|
@@ -200,4 +80,4 @@ async function build(outfile, mode, template) {
|
|
|
200
80
|
process.exit(1);
|
|
201
81
|
}
|
|
202
82
|
}
|
|
203
|
-
|
|
83
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as playwright from "playwright";
|
|
2
|
+
export declare const REMOTE_DEBUGGING_PORT = 9222;
|
|
3
|
+
export declare const getChromiumLaunchArgs: () => string[];
|
|
4
|
+
export declare function startOrRestartBrowser(): Promise<void>;
|
|
5
|
+
export interface SessionState {
|
|
6
|
+
cookies: any[];
|
|
7
|
+
storage: Record<string, {
|
|
8
|
+
localStorage: any;
|
|
9
|
+
sessionStorage: any;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare function saveSessionFromOpenedBrowser(path: string): Promise<void>;
|
|
13
|
+
export declare function loadState(path: string, context: playwright.BrowserContext): Promise<void>;
|
|
14
|
+
export declare function saveSession(path: string, context: playwright.BrowserContext): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getChromiumLaunchArgs = exports.REMOTE_DEBUGGING_PORT = void 0;
|
|
7
|
+
exports.loadState = loadState;
|
|
8
|
+
exports.saveSession = saveSession;
|
|
9
|
+
exports.saveSessionFromOpenedBrowser = saveSessionFromOpenedBrowser;
|
|
10
|
+
exports.startOrRestartBrowser = startOrRestartBrowser;
|
|
11
|
+
var _child_process = require("child_process");
|
|
12
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
13
|
+
var _fileUtils = require("./utils/fileUtils");
|
|
14
|
+
var _contextStorageStateHelpers = require("../../common/contextStorageStateHelpers");
|
|
15
|
+
var playwright = _interopRequireWildcard(require("playwright"));
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
17
|
+
const REMOTE_DEBUGGING_PORT = exports.REMOTE_DEBUGGING_PORT = 9222;
|
|
18
|
+
const getChromiumLaunchArgs = () => ["--no-sandbox", `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`, `--user-data-dir=/tmp/${Date.now()}`, "--new-window", "--start-maximized", "--disable-popup-blocking"];
|
|
19
|
+
exports.getChromiumLaunchArgs = getChromiumLaunchArgs;
|
|
20
|
+
async function getBrowser() {
|
|
21
|
+
let playwrightBrowser = null;
|
|
22
|
+
try {
|
|
23
|
+
playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error("Browser is not running");
|
|
26
|
+
}
|
|
27
|
+
return playwrightBrowser;
|
|
28
|
+
}
|
|
29
|
+
async function startOrRestartBrowser() {
|
|
30
|
+
const chromiumPath = playwright.chromium.executablePath();
|
|
31
|
+
const chromeInstanceProcess = (0, _child_process.spawn)(chromiumPath, getChromiumLaunchArgs());
|
|
32
|
+
chromeInstanceProcess.stdout.on("data", data => {
|
|
33
|
+
console.log(`Chrome stdout: ${data}`);
|
|
34
|
+
});
|
|
35
|
+
chromeInstanceProcess.stderr.on("data", data => {
|
|
36
|
+
console.error(`Chrome stderr: ${data}`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function saveSessionFromOpenedBrowser(path) {
|
|
40
|
+
const browser = await getBrowser();
|
|
41
|
+
const context = await browser.contexts()[0];
|
|
42
|
+
return saveSession(path, context);
|
|
43
|
+
}
|
|
44
|
+
async function loadState(path, context) {
|
|
45
|
+
const fullPath = (0, _fileUtils.getFullPathInProject)(path);
|
|
46
|
+
if (!(await fs.pathExists(fullPath))) {
|
|
47
|
+
throw new Error("session file does not exist");
|
|
48
|
+
}
|
|
49
|
+
const data = await fs.readJson(fullPath);
|
|
50
|
+
await context.addCookies(data.cookies);
|
|
51
|
+
}
|
|
52
|
+
async function saveSession(path, context) {
|
|
53
|
+
const fullState = await (0, _contextStorageStateHelpers.getStorageState)(context);
|
|
54
|
+
const fullPath = (0, _fileUtils.getFullPathInProject)(path);
|
|
55
|
+
fs.ensureFileSync(fullPath);
|
|
56
|
+
await fs.writeJSON(fullPath, fullState);
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SourceFile } from "ts-morph";
|
|
2
|
+
export declare function findFirstExecutableLine(sourceFile: SourceFile): -1 | {
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
};
|
|
6
|
+
export default function getFirstLineNumber(apiFilePath: string): Promise<{
|
|
7
|
+
sourceFileName: string;
|
|
8
|
+
lineNumber: number;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getFirstLineNumber;
|
|
7
|
+
exports.findFirstExecutableLine = findFirstExecutableLine;
|
|
8
|
+
var _tsMorph = require("ts-morph");
|
|
9
|
+
var _sourceMap = require("source-map");
|
|
10
|
+
function compileTypeScript(apiFilePath) {
|
|
11
|
+
const compilerOptions = {
|
|
12
|
+
lib: ["dom", "es2020"],
|
|
13
|
+
sourceMap: true,
|
|
14
|
+
inlineSourceMap: true,
|
|
15
|
+
inlineSources: true,
|
|
16
|
+
declaration: false,
|
|
17
|
+
noEmit: false,
|
|
18
|
+
module: _tsMorph.ModuleKind.CommonJS,
|
|
19
|
+
target: _tsMorph.ScriptTarget.ES2020
|
|
20
|
+
};
|
|
21
|
+
const project = new _tsMorph.Project({
|
|
22
|
+
compilerOptions
|
|
23
|
+
});
|
|
24
|
+
const sourceFile = project.addSourceFileAtPath(apiFilePath);
|
|
25
|
+
const outputJS = project.emitToMemory({
|
|
26
|
+
targetSourceFile: sourceFile
|
|
27
|
+
});
|
|
28
|
+
const outputJSText = outputJS.getFiles()[0].text;
|
|
29
|
+
return {
|
|
30
|
+
sourceFile,
|
|
31
|
+
outputJSText
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function findFirstExecutableLine(sourceFile) {
|
|
35
|
+
let functionBody;
|
|
36
|
+
const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
|
|
37
|
+
const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
|
|
38
|
+
if (defaultExportDeclaration) {
|
|
39
|
+
if (defaultExportDeclaration.getKind() === _tsMorph.ts.SyntaxKind.FunctionDeclaration) {
|
|
40
|
+
functionBody = defaultExportDeclaration.getBody();
|
|
41
|
+
} else {
|
|
42
|
+
const exportAssignments = sourceFile.getExportAssignments();
|
|
43
|
+
for (const exportAssignment of exportAssignments) {
|
|
44
|
+
const expression = exportAssignment.getExpression();
|
|
45
|
+
if (!expression) continue;
|
|
46
|
+
if (expression.getKind() === _tsMorph.ts.SyntaxKind.Identifier || expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction) {
|
|
47
|
+
const identifier = expression.getText();
|
|
48
|
+
const possiblyExportedFunction = sourceFile.getFunction(identifier) || sourceFile.getVariableStatement(identifier)?.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction);
|
|
49
|
+
if (possiblyExportedFunction) {
|
|
50
|
+
functionBody = possiblyExportedFunction.getBody();
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (_tsMorph.Node.hasBody(expression) && (expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction)) {
|
|
55
|
+
functionBody = expression.getBody();
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!functionBody || !_tsMorph.Node.isStatemented(functionBody)) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
if (functionBody.getStatements().length === 0) {
|
|
65
|
+
return -1;
|
|
66
|
+
}
|
|
67
|
+
const position = functionBody.getStatements()[0].getStart();
|
|
68
|
+
return sourceFile.getLineAndColumnAtPos(position);
|
|
69
|
+
}
|
|
70
|
+
async function getSourceMap(jsCode) {
|
|
71
|
+
const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") + "//# sourceMappingURL=data:application/json;base64,".length);
|
|
72
|
+
const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
|
|
73
|
+
const sourceMap = JSON.parse(sourceMapText);
|
|
74
|
+
return new _sourceMap.SourceMapConsumer(sourceMap);
|
|
75
|
+
}
|
|
76
|
+
async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
|
|
77
|
+
const sourceMap = await getSourceMap(jsCode);
|
|
78
|
+
const generatedLineNumber = sourceMap.generatedPositionFor({
|
|
79
|
+
source: sourceFileName,
|
|
80
|
+
line,
|
|
81
|
+
column
|
|
82
|
+
}).line;
|
|
83
|
+
if (!generatedLineNumber) return -1;
|
|
84
|
+
return generatedLineNumber;
|
|
85
|
+
}
|
|
86
|
+
async function getFirstLineNumber(apiFilePath) {
|
|
87
|
+
const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
|
|
88
|
+
const {
|
|
89
|
+
sourceFile,
|
|
90
|
+
outputJSText
|
|
91
|
+
} = compileTypeScript(apiFilePath);
|
|
92
|
+
const result = findFirstExecutableLine(sourceFile);
|
|
93
|
+
if (result === -1) return {
|
|
94
|
+
sourceFileName,
|
|
95
|
+
lineNumber: -1
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
sourceFileName,
|
|
99
|
+
lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column)
|
|
100
|
+
};
|
|
101
|
+
}
|