@milaboratories/pl-deployments 2.15.17 → 2.15.19

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 (104) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/common/os_and_arch.cjs +22 -28
  3. package/dist/common/os_and_arch.cjs.map +1 -1
  4. package/dist/common/os_and_arch.js +23 -26
  5. package/dist/common/os_and_arch.js.map +1 -1
  6. package/dist/common/pl_binary.cjs +35 -33
  7. package/dist/common/pl_binary.cjs.map +1 -1
  8. package/dist/common/pl_binary.d.ts +13 -18
  9. package/dist/common/pl_binary.js +33 -31
  10. package/dist/common/pl_binary.js.map +1 -1
  11. package/dist/common/pl_binary_download.cjs +143 -155
  12. package/dist/common/pl_binary_download.cjs.map +1 -1
  13. package/dist/common/pl_binary_download.d.ts +15 -48
  14. package/dist/common/pl_binary_download.js +138 -133
  15. package/dist/common/pl_binary_download.js.map +1 -1
  16. package/dist/common/pl_version.cjs +5 -6
  17. package/dist/common/pl_version.cjs.map +1 -1
  18. package/dist/common/pl_version.d.ts +4 -1
  19. package/dist/common/pl_version.js +5 -4
  20. package/dist/common/pl_version.js.map +1 -1
  21. package/dist/index.cjs +21 -25
  22. package/dist/index.d.ts +6 -6
  23. package/dist/index.js +7 -6
  24. package/dist/local/pid.cjs +14 -13
  25. package/dist/local/pid.cjs.map +1 -1
  26. package/dist/local/pid.js +11 -11
  27. package/dist/local/pid.js.map +1 -1
  28. package/dist/local/pl.cjs +194 -223
  29. package/dist/local/pl.cjs.map +1 -1
  30. package/dist/local/pl.d.ts +65 -65
  31. package/dist/local/pl.js +190 -202
  32. package/dist/local/pl.js.map +1 -1
  33. package/dist/local/process.cjs +37 -59
  34. package/dist/local/process.cjs.map +1 -1
  35. package/dist/local/process.d.ts +10 -10
  36. package/dist/local/process.js +36 -57
  37. package/dist/local/process.js.map +1 -1
  38. package/dist/local/trace.cjs +14 -17
  39. package/dist/local/trace.cjs.map +1 -1
  40. package/dist/local/trace.d.ts +6 -7
  41. package/dist/local/trace.js +15 -15
  42. package/dist/local/trace.js.map +1 -1
  43. package/dist/package.cjs +12 -0
  44. package/dist/package.cjs.map +1 -0
  45. package/dist/package.js +6 -0
  46. package/dist/package.js.map +1 -0
  47. package/dist/ssh/connection_info.cjs +36 -53
  48. package/dist/ssh/connection_info.cjs.map +1 -1
  49. package/dist/ssh/connection_info.d.ts +691 -713
  50. package/dist/ssh/connection_info.js +35 -51
  51. package/dist/ssh/connection_info.js.map +1 -1
  52. package/dist/ssh/pl.cjs +551 -638
  53. package/dist/ssh/pl.cjs.map +1 -1
  54. package/dist/ssh/pl.d.ts +120 -117
  55. package/dist/ssh/pl.js +548 -636
  56. package/dist/ssh/pl.js.map +1 -1
  57. package/dist/ssh/pl_paths.cjs +22 -24
  58. package/dist/ssh/pl_paths.cjs.map +1 -1
  59. package/dist/ssh/pl_paths.js +21 -19
  60. package/dist/ssh/pl_paths.js.map +1 -1
  61. package/dist/ssh/ssh.cjs +554 -618
  62. package/dist/ssh/ssh.cjs.map +1 -1
  63. package/dist/ssh/ssh.d.ts +139 -136
  64. package/dist/ssh/ssh.js +548 -616
  65. package/dist/ssh/ssh.js.map +1 -1
  66. package/dist/ssh/ssh_errors.cjs +45 -60
  67. package/dist/ssh/ssh_errors.cjs.map +1 -1
  68. package/dist/ssh/ssh_errors.js +45 -58
  69. package/dist/ssh/ssh_errors.js.map +1 -1
  70. package/dist/ssh/supervisord.cjs +50 -68
  71. package/dist/ssh/supervisord.cjs.map +1 -1
  72. package/dist/ssh/supervisord.d.ts +11 -21
  73. package/dist/ssh/supervisord.js +50 -66
  74. package/dist/ssh/supervisord.js.map +1 -1
  75. package/package.json +10 -10
  76. package/dist/common/os_and_arch.d.ts +0 -9
  77. package/dist/common/os_and_arch.d.ts.map +0 -1
  78. package/dist/common/pl_binary.d.ts.map +0 -1
  79. package/dist/common/pl_binary_download.d.ts.map +0 -1
  80. package/dist/common/pl_version.d.ts.map +0 -1
  81. package/dist/index.cjs.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js.map +0 -1
  84. package/dist/local/options.d.ts +0 -31
  85. package/dist/local/options.d.ts.map +0 -1
  86. package/dist/local/pid.d.ts +0 -4
  87. package/dist/local/pid.d.ts.map +0 -1
  88. package/dist/local/pl.d.ts.map +0 -1
  89. package/dist/local/process.d.ts.map +0 -1
  90. package/dist/local/trace.d.ts.map +0 -1
  91. package/dist/package.json.cjs +0 -8
  92. package/dist/package.json.cjs.map +0 -1
  93. package/dist/package.json.js +0 -6
  94. package/dist/package.json.js.map +0 -1
  95. package/dist/ssh/__tests__/common-utils.d.ts +0 -12
  96. package/dist/ssh/__tests__/common-utils.d.ts.map +0 -1
  97. package/dist/ssh/connection_info.d.ts.map +0 -1
  98. package/dist/ssh/pl.d.ts.map +0 -1
  99. package/dist/ssh/pl_paths.d.ts +0 -20
  100. package/dist/ssh/pl_paths.d.ts.map +0 -1
  101. package/dist/ssh/ssh.d.ts.map +0 -1
  102. package/dist/ssh/ssh_errors.d.ts +0 -29
  103. package/dist/ssh/ssh_errors.d.ts.map +0 -1
  104. package/dist/ssh/supervisord.d.ts.map +0 -1
@@ -1,81 +1,81 @@
1
- import type { ProcessOptions } from "./process";
2
- import type { PlBinarySource } from "../common/pl_binary";
3
- import type { MiLogger } from "@milaboratories/ts-helpers";
4
- import type { SpawnOptions } from "node:child_process";
5
- import type { Trace } from "./trace";
6
- import type { Required } from "utility-types";
7
- import type { ProxySettings } from "@milaboratories/pl-http";
8
- export declare const LocalConfigYaml = "config-local.yaml";
1
+ import { ProcessOptions } from "./process.js";
2
+ import { PlBinarySource } from "../common/pl_binary.js";
3
+ import { Trace } from "./trace.js";
4
+ import { SpawnOptions } from "node:child_process";
5
+ import { MiLogger } from "@milaboratories/ts-helpers";
6
+ import { ProxySettings } from "@milaboratories/pl-http";
7
+ import { Required } from "utility-types";
8
+
9
+ //#region src/local/pl.d.ts
10
+ declare const LocalConfigYaml = "config-local.yaml";
9
11
  /**
10
12
  * Represents a local running pl-core,
11
13
  * and has methods to start, check if it's running, stop and wait for stopping it.
12
14
  * Also, a hook on pl-core closed can be provided.
13
15
  */
14
- export declare class LocalPl {
15
- private readonly logger;
16
- private readonly workingDir;
17
- private readonly startOptions;
18
- private readonly initialStartHistory;
19
- private readonly onClose?;
20
- private readonly onError?;
21
- private readonly onCloseAndError?;
22
- private readonly onCloseAndErrorNoStop?;
23
- private instance?;
24
- pid?: number;
25
- private nRuns;
26
- private lastRunHistory;
27
- private wasStopped;
28
- constructor(logger: MiLogger, workingDir: string, startOptions: ProcessOptions, initialStartHistory: Trace, onClose?: ((pl: LocalPl) => Promise<void>) | undefined, onError?: ((pl: LocalPl) => Promise<void>) | undefined, onCloseAndError?: ((pl: LocalPl) => Promise<void>) | undefined, onCloseAndErrorNoStop?: ((pl: LocalPl) => Promise<void>) | undefined);
29
- start(): Promise<void>;
30
- stop(): void;
31
- waitStopped(): Promise<void>;
32
- stopped(): boolean;
33
- isAlive(): Promise<boolean>;
34
- debugInfo(): {
35
- lastRunHistory: Trace;
36
- nRuns: number;
37
- pid: number | undefined;
38
- workingDir: string;
39
- initialStartHistory: Trace;
40
- wasStopped: boolean;
41
- };
16
+ declare class LocalPl {
17
+ private readonly logger;
18
+ private readonly workingDir;
19
+ private readonly startOptions;
20
+ private readonly initialStartHistory;
21
+ private readonly onClose?;
22
+ private readonly onError?;
23
+ private readonly onCloseAndError?;
24
+ private readonly onCloseAndErrorNoStop?;
25
+ private instance?;
26
+ pid?: number;
27
+ private nRuns;
28
+ private lastRunHistory;
29
+ private wasStopped;
30
+ constructor(logger: MiLogger, workingDir: string, startOptions: ProcessOptions, initialStartHistory: Trace, onClose?: ((pl: LocalPl) => Promise<void>) | undefined, onError?: ((pl: LocalPl) => Promise<void>) | undefined, onCloseAndError?: ((pl: LocalPl) => Promise<void>) | undefined, onCloseAndErrorNoStop?: ((pl: LocalPl) => Promise<void>) | undefined);
31
+ start(): Promise<void>;
32
+ stop(): void;
33
+ waitStopped(): Promise<void>;
34
+ stopped(): boolean;
35
+ isAlive(): Promise<boolean>;
36
+ debugInfo(): {
37
+ lastRunHistory: Trace;
38
+ nRuns: number;
39
+ pid: number | undefined;
40
+ workingDir: string;
41
+ initialStartHistory: Trace;
42
+ wasStopped: boolean;
43
+ };
42
44
  }
43
45
  /** Options to start a local pl-core. */
44
- export type LocalPlOptions = {
45
- /** From what directory start a process. */
46
- readonly workingDir: string;
47
- /** A string representation of yaml config. */
48
- readonly config: string;
49
- /** How to get a binary, download it or get an existing one (default: download latest version) */
50
- readonly plBinary?: PlBinarySource;
51
- /** Additional options for a process, environments, stdout, stderr etc. */
52
- readonly spawnOptions?: SpawnOptions;
53
- /**
54
- * If the previous pl-core was started from the same directory,
55
- * we can check if it's still running and then stop it before starting a new one.
56
- * (default: true)
57
- */
58
- readonly closeOld?: boolean;
59
- /**
60
- * Proxy settings to use to fetch the binary and pass it down
61
- * as a HTTPS_PROXY/HTTP_PROXY environment variable;
62
- * Backend only supports Basic auth.
63
- */
64
- readonly proxy?: ProxySettings;
65
- readonly onClose?: (pl: LocalPl) => Promise<void>;
66
- readonly onError?: (pl: LocalPl) => Promise<void>;
67
- readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;
68
- readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;
46
+ type LocalPlOptions = {
47
+ /** From what directory start a process. */readonly workingDir: string; /** A string representation of yaml config. */
48
+ readonly config: string; /** How to get a binary, download it or get an existing one (default: download latest version) */
49
+ readonly plBinary?: PlBinarySource; /** Additional options for a process, environments, stdout, stderr etc. */
50
+ readonly spawnOptions?: SpawnOptions;
51
+ /**
52
+ * If the previous pl-core was started from the same directory,
53
+ * we can check if it's still running and then stop it before starting a new one.
54
+ * (default: true)
55
+ */
56
+ readonly closeOld?: boolean;
57
+ /**
58
+ * Proxy settings to use to fetch the binary and pass it down
59
+ * as a HTTPS_PROXY/HTTP_PROXY environment variable;
60
+ * Backend only supports Basic auth.
61
+ */
62
+ readonly proxy?: ProxySettings;
63
+ readonly onClose?: (pl: LocalPl) => Promise<void>;
64
+ readonly onError?: (pl: LocalPl) => Promise<void>;
65
+ readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;
66
+ readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;
69
67
  };
70
- export type LocalPlOptionsFull = Required<LocalPlOptions, "plBinary" | "spawnOptions" | "closeOld">;
68
+ type LocalPlOptionsFull = Required<LocalPlOptions, "plBinary" | "spawnOptions" | "closeOld">;
71
69
  /**
72
70
  * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.
73
71
  */
74
- export declare function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl>;
72
+ declare function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl>;
75
73
  /** Gets default options for the whole init process
76
74
  * and overrides them with the provided options. */
77
- export declare function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull;
75
+ declare function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull;
78
76
  /** Gets default options for a platforma local binary
79
77
  * and overrides them with the provided options. */
80
- export declare function plProcessOps(binaryPath: any, configPath: string, ops: LocalPlOptionsFull, workDir: string, defaultEnv: Record<string, string | undefined>): ProcessOptions;
78
+ declare function plProcessOps(binaryPath: any, configPath: string, ops: LocalPlOptionsFull, workDir: string, defaultEnv: Record<string, string | undefined>): ProcessOptions;
79
+ //#endregion
80
+ export { LocalConfigYaml, LocalPl, LocalPlOptions, LocalPlOptionsFull, localPlatformaInit, mergeDefaultOps, plProcessOps };
81
81
  //# sourceMappingURL=pl.d.ts.map
package/dist/local/pl.js CHANGED
@@ -1,221 +1,209 @@
1
- import { processStop, processWaitStopped, isProcessAlive, processRun } from './process.js';
2
- import { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from '../common/pl_binary.js';
3
- import { notEmpty } from '@milaboratories/ts-helpers';
4
- import { filePid, writePid, readPid } from './pid.js';
5
- import { withTrace } from './trace.js';
6
- import upath from 'upath';
7
- import fsp from 'node:fs/promises';
8
- import * as os from 'node:os';
9
- import { defaultHttpDispatcher } from '@milaboratories/pl-http';
10
- import { parseHttpAuth } from '@milaboratories/pl-model-common';
1
+ import { isProcessAlive, processRun, processStop, processWaitStopped } from "./process.js";
2
+ import { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from "../common/pl_binary.js";
3
+ import { filePid, readPid, writePid } from "./pid.js";
4
+ import { withTrace } from "./trace.js";
5
+ import { notEmpty } from "@milaboratories/ts-helpers";
6
+ import fsp from "node:fs/promises";
7
+ import upath from "upath";
8
+ import * as os$1 from "node:os";
9
+ import { defaultHttpDispatcher } from "@milaboratories/pl-http";
10
+ import { parseHttpAuth } from "@milaboratories/pl-model-common";
11
11
 
12
+ //#region src/local/pl.ts
12
13
  const LocalConfigYaml = "config-local.yaml";
13
14
  /**
14
- * Represents a local running pl-core,
15
- * and has methods to start, check if it's running, stop and wait for stopping it.
16
- * Also, a hook on pl-core closed can be provided.
17
- */
18
- class LocalPl {
19
- logger;
20
- workingDir;
21
- startOptions;
22
- initialStartHistory;
23
- onClose;
24
- onError;
25
- onCloseAndError;
26
- onCloseAndErrorNoStop;
27
- instance;
28
- pid;
29
- nRuns = 0;
30
- lastRunHistory = {};
31
- wasStopped = false;
32
- constructor(logger, workingDir, startOptions, initialStartHistory, onClose, onError, onCloseAndError, onCloseAndErrorNoStop) {
33
- this.logger = logger;
34
- this.workingDir = workingDir;
35
- this.startOptions = startOptions;
36
- this.initialStartHistory = initialStartHistory;
37
- this.onClose = onClose;
38
- this.onError = onError;
39
- this.onCloseAndError = onCloseAndError;
40
- this.onCloseAndErrorNoStop = onCloseAndErrorNoStop;
41
- }
42
- async start() {
43
- await withTrace(this.logger, async (trace, t) => {
44
- this.wasStopped = false;
45
- const instance = processRun(this.logger, this.startOptions);
46
- instance.on("error", (e) => {
47
- this.logger.error(`error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`);
48
- // keep in mind there are no awaits here, it will be asynchronous
49
- if (this.onError !== undefined)
50
- void this.onError(this);
51
- if (this.onCloseAndError !== undefined)
52
- void this.onCloseAndError(this);
53
- if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)
54
- void this.onCloseAndErrorNoStop(this);
55
- });
56
- instance.on("close", () => {
57
- this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);
58
- // keep in mind there are no awaits here, it will be asynchronous
59
- if (this.onClose !== undefined)
60
- void this.onClose(this);
61
- if (this.onCloseAndError !== undefined)
62
- void this.onCloseAndError(this);
63
- if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)
64
- void this.onCloseAndErrorNoStop(this);
65
- });
66
- trace("started", true);
67
- const pidFile = trace("pidFile", filePid(this.workingDir));
68
- trace("pid", notEmpty(instance.pid));
69
- trace("pidWritten", await writePid(pidFile, notEmpty(instance.pid)));
70
- this.nRuns++;
71
- this.instance = instance;
72
- this.pid = instance.pid;
73
- this.lastRunHistory = t;
74
- });
75
- }
76
- stop() {
77
- // TODO use this.instance to stop the process
78
- this.wasStopped = true;
79
- processStop(notEmpty(this.pid));
80
- }
81
- async waitStopped() {
82
- await processWaitStopped(notEmpty(this.pid), 15000);
83
- }
84
- stopped() {
85
- return this.wasStopped;
86
- }
87
- async isAlive() {
88
- return await isProcessAlive(notEmpty(this.pid));
89
- }
90
- debugInfo() {
91
- return {
92
- lastRunHistory: this.lastRunHistory,
93
- nRuns: this.nRuns,
94
- pid: this.pid,
95
- workingDir: this.workingDir,
96
- initialStartHistory: this.initialStartHistory,
97
- wasStopped: this.wasStopped,
98
- };
99
- }
100
- }
15
+ * Represents a local running pl-core,
16
+ * and has methods to start, check if it's running, stop and wait for stopping it.
17
+ * Also, a hook on pl-core closed can be provided.
18
+ */
19
+ var LocalPl = class {
20
+ instance;
21
+ pid;
22
+ nRuns = 0;
23
+ lastRunHistory = {};
24
+ wasStopped = false;
25
+ constructor(logger, workingDir, startOptions, initialStartHistory, onClose, onError, onCloseAndError, onCloseAndErrorNoStop) {
26
+ this.logger = logger;
27
+ this.workingDir = workingDir;
28
+ this.startOptions = startOptions;
29
+ this.initialStartHistory = initialStartHistory;
30
+ this.onClose = onClose;
31
+ this.onError = onError;
32
+ this.onCloseAndError = onCloseAndError;
33
+ this.onCloseAndErrorNoStop = onCloseAndErrorNoStop;
34
+ }
35
+ async start() {
36
+ await withTrace(this.logger, async (trace, t) => {
37
+ this.wasStopped = false;
38
+ const instance = processRun(this.logger, this.startOptions);
39
+ instance.on("error", (e) => {
40
+ this.logger.error(`error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`);
41
+ if (this.onError !== void 0) this.onError(this);
42
+ if (this.onCloseAndError !== void 0) this.onCloseAndError(this);
43
+ if (this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped) this.onCloseAndErrorNoStop(this);
44
+ });
45
+ instance.on("close", () => {
46
+ this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);
47
+ if (this.onClose !== void 0) this.onClose(this);
48
+ if (this.onCloseAndError !== void 0) this.onCloseAndError(this);
49
+ if (this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped) this.onCloseAndErrorNoStop(this);
50
+ });
51
+ trace("started", true);
52
+ const pidFile = trace("pidFile", filePid(this.workingDir));
53
+ trace("pid", notEmpty(instance.pid));
54
+ trace("pidWritten", await writePid(pidFile, notEmpty(instance.pid)));
55
+ this.nRuns++;
56
+ this.instance = instance;
57
+ this.pid = instance.pid;
58
+ this.lastRunHistory = t;
59
+ });
60
+ }
61
+ stop() {
62
+ this.wasStopped = true;
63
+ processStop(notEmpty(this.pid));
64
+ }
65
+ async waitStopped() {
66
+ await processWaitStopped(notEmpty(this.pid), 15e3);
67
+ }
68
+ stopped() {
69
+ return this.wasStopped;
70
+ }
71
+ async isAlive() {
72
+ return await isProcessAlive(notEmpty(this.pid));
73
+ }
74
+ debugInfo() {
75
+ return {
76
+ lastRunHistory: this.lastRunHistory,
77
+ nRuns: this.nRuns,
78
+ pid: this.pid,
79
+ workingDir: this.workingDir,
80
+ initialStartHistory: this.initialStartHistory,
81
+ wasStopped: this.wasStopped
82
+ };
83
+ }
84
+ };
101
85
  /**
102
- * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.
103
- */
86
+ * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.
87
+ */
104
88
  async function localPlatformaInit(logger, _ops) {
105
- // filling-in default values
106
- // Backend could consume a lot of CPU power,
107
- // we want to keep at least a couple for UI and other apps to work.
108
- const numCpu = Math.max(os.cpus().length - 2, 1);
109
- const ops = mergeDefaultOps(_ops, numCpu);
110
- return await withTrace(logger, async (trace, t) => {
111
- trace("startOptions", { ...ops, config: "too wordy" });
112
- const workDir = upath.resolve(ops.workingDir);
113
- if (ops.closeOld) {
114
- trace("closeOld", await localPlatformaReadPidAndStop(logger, workDir));
115
- }
116
- const configPath = upath.join(workDir, LocalConfigYaml);
117
- logger.info(`writing configuration '${configPath}'...`);
118
- await fsp.writeFile(configPath, ops.config);
119
- const plBinPath = upath.join(workDir, "binaries");
120
- const baseBinaryPath = await resolveLocalPlBinaryPath({
121
- logger,
122
- downloadDir: plBinPath,
123
- src: ops.plBinary,
124
- dispatcher: defaultHttpDispatcher(ops.proxy),
125
- });
126
- const binaryPath = trace("binaryPath", upath.join("binaries", baseBinaryPath));
127
- const env = { ...process.env };
128
- if (ops.proxy?.url) {
129
- const url = new URL(ops.proxy.url);
130
- if (ops.proxy.auth) {
131
- const parsed = parseHttpAuth(ops.proxy.auth);
132
- if (parsed.scheme !== "Basic") {
133
- throw new Error(`\
89
+ const ops = mergeDefaultOps(_ops, Math.max(os$1.cpus().length - 2, 1));
90
+ return await withTrace(logger, async (trace, t) => {
91
+ trace("startOptions", {
92
+ ...ops,
93
+ config: "too wordy"
94
+ });
95
+ const workDir = upath.resolve(ops.workingDir);
96
+ if (ops.closeOld) trace("closeOld", await localPlatformaReadPidAndStop(logger, workDir));
97
+ const configPath = upath.join(workDir, LocalConfigYaml);
98
+ logger.info(`writing configuration '${configPath}'...`);
99
+ await fsp.writeFile(configPath, ops.config);
100
+ const baseBinaryPath = await resolveLocalPlBinaryPath({
101
+ logger,
102
+ downloadDir: upath.join(workDir, "binaries"),
103
+ src: ops.plBinary,
104
+ dispatcher: defaultHttpDispatcher(ops.proxy)
105
+ });
106
+ const binaryPath = trace("binaryPath", upath.join("binaries", baseBinaryPath));
107
+ const env = { ...process.env };
108
+ if (ops.proxy?.url) {
109
+ const url = new URL(ops.proxy.url);
110
+ if (ops.proxy.auth) {
111
+ const parsed = parseHttpAuth(ops.proxy.auth);
112
+ if (parsed.scheme !== "Basic") throw new Error(`\
134
113
  Unsupported auth scheme: ${parsed.scheme}. \
135
114
  Only Basic auth is supported by the backend.`);
136
- }
137
- url.username = parsed.username;
138
- url.password = parsed.password;
139
- }
140
- env.http_proxy = url.toString();
141
- env.https_proxy = url.toString();
142
- }
143
- const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);
144
- trace("processOpts", {
145
- cmd: processOpts.cmd,
146
- args: processOpts.args,
147
- cwd: processOpts.opts.cwd,
148
- });
149
- const pl = new LocalPl(logger, ops.workingDir, processOpts, t, ops.onClose, ops.onError, ops.onCloseAndError, ops.onCloseAndErrorNoStop);
150
- await pl.start();
151
- return pl;
152
- });
115
+ url.username = parsed.username;
116
+ url.password = parsed.password;
117
+ }
118
+ env.http_proxy = url.toString();
119
+ env.https_proxy = url.toString();
120
+ }
121
+ const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);
122
+ trace("processOpts", {
123
+ cmd: processOpts.cmd,
124
+ args: processOpts.args,
125
+ cwd: processOpts.opts.cwd
126
+ });
127
+ const pl = new LocalPl(logger, ops.workingDir, processOpts, t, ops.onClose, ops.onError, ops.onCloseAndError, ops.onCloseAndErrorNoStop);
128
+ await pl.start();
129
+ return pl;
130
+ });
153
131
  }
154
132
  /** Reads a pid of the old pl-core if it was started in the same working directory,
155
- * and closes it. */
133
+ * and closes it. */
156
134
  async function localPlatformaReadPidAndStop(logger, workingDir) {
157
- return await withTrace(logger, async (trace, t) => {
158
- const file = trace("pidFilePath", filePid(workingDir));
159
- const oldPid = trace("pid", await readPid(file));
160
- const alive = trace("wasAlive", await isProcessAlive(oldPid));
161
- if (oldPid !== undefined && alive) {
162
- trace("stopped", processStop(oldPid));
163
- try {
164
- trace("waitStopped", await processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.
165
- }
166
- catch {
167
- trace("forceStopped", processStop(oldPid, true));
168
- trace("waitForceStopped", await processWaitStopped(oldPid, 5_000));
169
- }
170
- }
171
- return t;
172
- });
135
+ return await withTrace(logger, async (trace, t) => {
136
+ const oldPid = trace("pid", await readPid(trace("pidFilePath", filePid(workingDir))));
137
+ const alive = trace("wasAlive", await isProcessAlive(oldPid));
138
+ if (oldPid !== void 0 && alive) {
139
+ trace("stopped", processStop(oldPid));
140
+ try {
141
+ trace("waitStopped", await processWaitStopped(oldPid, 15e3));
142
+ } catch {
143
+ trace("forceStopped", processStop(oldPid, true));
144
+ trace("waitForceStopped", await processWaitStopped(oldPid, 5e3));
145
+ }
146
+ }
147
+ return t;
148
+ });
173
149
  }
174
150
  /** Gets default options for the whole init process
175
- * and overrides them with the provided options. */
151
+ * and overrides them with the provided options. */
176
152
  function mergeDefaultOps(ops, numCpu) {
177
- const result = {
178
- plBinary: newDefaultPlBinarySource(),
179
- spawnOptions: {
180
- env: {
181
- GOMAXPROCS: String(numCpu),
182
- },
183
- },
184
- closeOld: true,
185
- };
186
- if (ops.spawnOptions?.env) {
187
- result.spawnOptions.env = { ...result.spawnOptions.env, ...ops.spawnOptions.env };
188
- }
189
- if (ops.spawnOptions) {
190
- const withoutEnv = { ...ops.spawnOptions };
191
- delete withoutEnv["env"];
192
- result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };
193
- }
194
- const withoutSpawnOps = { ...ops };
195
- delete withoutSpawnOps["spawnOptions"];
196
- return { ...result, ...withoutSpawnOps };
153
+ const result = {
154
+ plBinary: newDefaultPlBinarySource(),
155
+ spawnOptions: { env: { GOMAXPROCS: String(numCpu) } },
156
+ closeOld: true
157
+ };
158
+ if (ops.spawnOptions?.env) result.spawnOptions.env = {
159
+ ...result.spawnOptions.env,
160
+ ...ops.spawnOptions.env
161
+ };
162
+ if (ops.spawnOptions) {
163
+ const withoutEnv = { ...ops.spawnOptions };
164
+ delete withoutEnv["env"];
165
+ result.spawnOptions = {
166
+ ...result.spawnOptions,
167
+ ...withoutEnv
168
+ };
169
+ }
170
+ const withoutSpawnOps = { ...ops };
171
+ delete withoutSpawnOps["spawnOptions"];
172
+ return {
173
+ ...result,
174
+ ...withoutSpawnOps
175
+ };
197
176
  }
198
177
  /** Gets default options for a platforma local binary
199
- * and overrides them with the provided options. */
178
+ * and overrides them with the provided options. */
200
179
  function plProcessOps(binaryPath, configPath, ops, workDir, defaultEnv) {
201
- const result = {
202
- cmd: binaryPath,
203
- args: ["--config", configPath],
204
- opts: {
205
- env: { ...defaultEnv },
206
- cwd: workDir,
207
- stdio: ["pipe", "ignore", "inherit"],
208
- windowsHide: true, // hide a terminal on Windows
209
- },
210
- };
211
- if (ops.spawnOptions?.env) {
212
- result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };
213
- }
214
- const withoutEnv = { ...ops.spawnOptions };
215
- delete withoutEnv["env"];
216
- result.opts = { ...result.opts, ...withoutEnv };
217
- return result;
180
+ const result = {
181
+ cmd: binaryPath,
182
+ args: ["--config", configPath],
183
+ opts: {
184
+ env: { ...defaultEnv },
185
+ cwd: workDir,
186
+ stdio: [
187
+ "pipe",
188
+ "ignore",
189
+ "inherit"
190
+ ],
191
+ windowsHide: true
192
+ }
193
+ };
194
+ if (ops.spawnOptions?.env) result.opts.env = {
195
+ ...result.opts.env,
196
+ ...ops.spawnOptions.env
197
+ };
198
+ const withoutEnv = { ...ops.spawnOptions };
199
+ delete withoutEnv["env"];
200
+ result.opts = {
201
+ ...result.opts,
202
+ ...withoutEnv
203
+ };
204
+ return result;
218
205
  }
219
206
 
207
+ //#endregion
220
208
  export { LocalConfigYaml, LocalPl, localPlatformaInit, mergeDefaultOps, plProcessOps };
221
- //# sourceMappingURL=pl.js.map
209
+ //# sourceMappingURL=pl.js.map