slnodejs 6.1.1084 → 6.1.1086
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/lib/preload.js +146 -57
- package/package.json +2 -2
package/lib/preload.js
CHANGED
|
@@ -4,74 +4,163 @@ const { LoggerFactory} = require('../tsOutputs/common/logger')
|
|
|
4
4
|
|
|
5
5
|
const logger = LoggerFactory.getCreateApplicationLogger();
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
// Split the node options string into tokens, handling quoted strings
|
|
8
|
+
function tokenizeNodeOptions(str) {
|
|
9
|
+
return (str.match(/(?:[^\s"]+|"[^"]*")+/g) || []).map((s) =>
|
|
10
|
+
s.replace(/^\"(.*)\"$/, "$1")
|
|
11
|
+
);
|
|
12
|
+
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
function isThisPreload(targetPath) {
|
|
15
|
+
try {
|
|
16
|
+
const resolvedTarget = resolve(process.cwd(), targetPath);
|
|
17
|
+
const thisFile = __filename;
|
|
18
|
+
// if the target path is the same as the current file, means we matched the preload target with the full path
|
|
19
|
+
if (resolvedTarget === thisFile) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
// check if the target path contains the slnodejs preloader path (covering relative path configuration)
|
|
23
|
+
if (targetPath.endsWith("slnodejs/lib/preload.js")) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
} catch (_) {}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
// Sanitize the node options by removing the preload target but keep the rest of the options, prevents endless recursion
|
|
31
|
+
function sanitizeNodeOptions(nodeOptions) {
|
|
32
|
+
const tokens = tokenizeNodeOptions(nodeOptions);
|
|
33
|
+
const sanitized = [];
|
|
34
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
35
|
+
const token = tokens[i];
|
|
36
|
+
if (token === "-r" || token === "--require") {
|
|
37
|
+
const nextToken = tokens[i + 1];
|
|
38
|
+
if (nextToken) {
|
|
39
|
+
if (isThisPreload(nextToken)) {
|
|
40
|
+
i++; // skip the preload target token
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
sanitized.push(token, nextToken);
|
|
44
|
+
i++; // consumed the next token as well
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
18
47
|
}
|
|
48
|
+
sanitized.push(token);
|
|
49
|
+
}
|
|
50
|
+
return sanitized.join(" ").trim();
|
|
51
|
+
}
|
|
19
52
|
|
|
20
|
-
|
|
53
|
+
function main() {
|
|
54
|
+
if (process.env.PRELOAD_EXECUTED) {
|
|
55
|
+
logger.info("Skipping preload logic on subsequent entry");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
21
58
|
|
|
22
|
-
|
|
23
|
-
if (process.env.SL_token || process.env.SL_TOKEN) {
|
|
24
|
-
token = `--token ${process.env.SL_token || process.env.SL_TOKEN}`;
|
|
25
|
-
} else if (process.env.SL_tokenFile || process.env.SL_TOKEN_FILE) {
|
|
26
|
-
token = `--tokenFile ${process.env.SL_tokenFile || process.env.SL_TOKEN_FILE}`;
|
|
27
|
-
}
|
|
59
|
+
process.env.PRELOAD_EXECUTED = 1;
|
|
28
60
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
bsid = `--buildSessionIdFile ${process.env.SL_buildSessionIdFile || process.env.SL_BUILD_SESSION_ID_FILE}`;
|
|
34
|
-
}
|
|
61
|
+
if (require.main === module) {
|
|
62
|
+
logger.info("preload.js is the main module, exiting.");
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
35
65
|
|
|
36
|
-
|
|
37
|
-
if (process.env.SL_projectRoot || process.env.SL_PROJECT_ROOT) {
|
|
38
|
-
projectRoot = `--projectRoot ${process.env.SL_projectRoot || process.env.SL_PROJECT_ROOT}`;
|
|
39
|
-
}
|
|
66
|
+
const pathToSlAgentCli = resolve(__dirname, "./cli.js");
|
|
40
67
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
labId = `--labId ${process.env.SL_labId || process.env.SL_LAB_ID}`;
|
|
44
|
-
}
|
|
68
|
+
const originalNodeOptions = process.env.NODE_OPTIONS || "";
|
|
69
|
+
const sanitizedNodeOptions = sanitizeNodeOptions(originalNodeOptions);
|
|
45
70
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
let token = "--tokenFile ./sltoken.txt";
|
|
72
|
+
if (process.env.SL_token || process.env.SL_TOKEN) {
|
|
73
|
+
token = `--token ${process.env.SL_token || process.env.SL_TOKEN}`;
|
|
74
|
+
} else if (process.env.SL_tokenFile || process.env.SL_TOKEN_FILE) {
|
|
75
|
+
token = `--tokenFile ${
|
|
76
|
+
process.env.SL_tokenFile || process.env.SL_TOKEN_FILE
|
|
77
|
+
}`;
|
|
78
|
+
}
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
let bsid = "--buildSessionIdFile ./buildSessionId";
|
|
81
|
+
if (process.env.SL_buildSessionId || process.env.SL_BUILD_SESSION_ID) {
|
|
82
|
+
bsid = `--buildSessionId ${
|
|
83
|
+
process.env.SL_buildSessionId || process.env.SL_BUILD_SESSION_ID
|
|
84
|
+
}`;
|
|
85
|
+
} else if (
|
|
86
|
+
process.env.SL_buildSessionIdFile ||
|
|
87
|
+
process.env.SL_BUILD_SESSION_ID_FILE
|
|
88
|
+
) {
|
|
89
|
+
bsid = `--buildSessionIdFile ${
|
|
90
|
+
process.env.SL_buildSessionIdFile || process.env.SL_BUILD_SESSION_ID_FILE
|
|
91
|
+
}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let projectRoot = "";
|
|
95
|
+
if (process.env.SL_projectRoot || process.env.SL_PROJECT_ROOT) {
|
|
96
|
+
projectRoot = `--projectRoot ${
|
|
97
|
+
process.env.SL_projectRoot || process.env.SL_PROJECT_ROOT
|
|
98
|
+
}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let labId = "";
|
|
102
|
+
if (process.env.SL_labId || process.env.SL_LAB_ID) {
|
|
103
|
+
labId = `--labId ${process.env.SL_labId || process.env.SL_LAB_ID}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let collectorUrl = "";
|
|
107
|
+
if (process.env.SL_collectorUrl || process.env.SL_COLLECTOR_URL) {
|
|
108
|
+
collectorUrl = `--collectorUrl ${
|
|
109
|
+
process.env.SL_collectorUrl || process.env.SL_COLLECTOR_URL
|
|
110
|
+
}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const [argv0, ...restArgv] = process.argv.map((x) =>
|
|
114
|
+
x.includes(" ") ? `"${x}"` : x
|
|
115
|
+
);
|
|
116
|
+
const originalArgv = process.argv.join(" ");
|
|
117
|
+
const args = [
|
|
118
|
+
"run",
|
|
119
|
+
...token.split(" "),
|
|
120
|
+
...bsid.split(" "),
|
|
121
|
+
...projectRoot.split(" "),
|
|
122
|
+
...labId.split(" "),
|
|
123
|
+
...collectorUrl.split(" "),
|
|
124
|
+
"--",
|
|
125
|
+
...restArgv,
|
|
126
|
+
].filter((x) => x); // remove unset arguments
|
|
127
|
+
const processArgs = [pathToSlAgentCli, ...args];
|
|
128
|
+
process.env.NODE_OPTIONS = "";
|
|
129
|
+
|
|
130
|
+
const childEnv = {
|
|
131
|
+
...process.env,
|
|
132
|
+
NODE_OPTIONS: sanitizedNodeOptions,
|
|
133
|
+
PRELOAD_EXECUTED: "1",
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
logger.info(`Rerun main module with args - ${JSON.stringify(processArgs)}`);
|
|
138
|
+
const result = spawnSync(process.argv[0], processArgs, {
|
|
139
|
+
stdio: "inherit",
|
|
140
|
+
shell: false,
|
|
141
|
+
env: childEnv,
|
|
142
|
+
});
|
|
143
|
+
if (result.error) {
|
|
144
|
+
throw result.error;
|
|
145
|
+
}
|
|
146
|
+
process.exit(result.status);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
logger.error("Error occurred while executing the target script:", error);
|
|
149
|
+
logger.info("Run main module with original args - ", originalArgv);
|
|
150
|
+
const result = spawnSync(argv0, originalArgv.split(" "), {
|
|
151
|
+
stdio: "inherit",
|
|
152
|
+
shell: false,
|
|
153
|
+
env: childEnv,
|
|
154
|
+
});
|
|
155
|
+
if (result.error) {
|
|
156
|
+
logger.error(
|
|
157
|
+
"Error occurred while executing the original script:",
|
|
158
|
+
result.error
|
|
159
|
+
);
|
|
160
|
+
process.exit(1);
|
|
74
161
|
}
|
|
162
|
+
process.exit(result.status);
|
|
163
|
+
}
|
|
75
164
|
}
|
|
76
165
|
|
|
77
166
|
process.on('uncaughtException', (error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slnodejs",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1086",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "tsOutputs/api.js",
|
|
6
6
|
"workspaces": [
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"sl-convert-source-map": "^1.0.1",
|
|
70
70
|
"sl-esprima-ast-utils": "0.0.7",
|
|
71
71
|
"sl-istanbul-lib-instrument": "6.0.7",
|
|
72
|
-
"sl-request": "1.0.
|
|
72
|
+
"sl-request": "1.0.6",
|
|
73
73
|
"source-map": "0.6.1",
|
|
74
74
|
"table": "6.7.1",
|
|
75
75
|
"triple-beam": "~1.3.0",
|