@milaboratories/pl-deployments 2.15.7 → 2.15.8
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/README.md +18 -5
- package/dist/common/os_and_arch.cjs +19 -19
- package/dist/common/os_and_arch.cjs.map +1 -1
- package/dist/common/os_and_arch.js +19 -19
- package/dist/common/os_and_arch.js.map +1 -1
- package/dist/common/pl_binary.cjs +9 -9
- package/dist/common/pl_binary.cjs.map +1 -1
- package/dist/common/pl_binary.d.ts +6 -6
- package/dist/common/pl_binary.d.ts.map +1 -1
- package/dist/common/pl_binary.js +9 -9
- package/dist/common/pl_binary.js.map +1 -1
- package/dist/common/pl_binary_download.cjs +16 -16
- package/dist/common/pl_binary_download.cjs.map +1 -1
- package/dist/common/pl_binary_download.d.ts +6 -6
- package/dist/common/pl_binary_download.d.ts.map +1 -1
- package/dist/common/pl_binary_download.js +16 -16
- package/dist/common/pl_binary_download.js.map +1 -1
- package/dist/common/pl_version.cjs +1 -1
- package/dist/common/pl_version.cjs.map +1 -1
- package/dist/common/pl_version.js +1 -1
- package/dist/common/pl_version.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/local/options.d.ts +4 -4
- package/dist/local/pid.cjs +1 -1
- package/dist/local/pid.cjs.map +1 -1
- package/dist/local/pid.js +1 -1
- package/dist/local/pid.js.map +1 -1
- package/dist/local/pl.cjs +26 -26
- package/dist/local/pl.cjs.map +1 -1
- package/dist/local/pl.d.ts +8 -8
- package/dist/local/pl.d.ts.map +1 -1
- package/dist/local/pl.js +26 -26
- package/dist/local/pl.js.map +1 -1
- package/dist/local/process.cjs +16 -16
- package/dist/local/process.cjs.map +1 -1
- package/dist/local/process.d.ts +2 -2
- package/dist/local/process.js +16 -16
- package/dist/local/process.js.map +1 -1
- package/dist/local/trace.cjs.map +1 -1
- package/dist/local/trace.d.ts +1 -1
- package/dist/local/trace.js.map +1 -1
- package/dist/package.json.cjs +2 -1
- package/dist/package.json.cjs.map +1 -1
- package/dist/package.json.js +2 -1
- package/dist/package.json.js.map +1 -1
- package/dist/ssh/__tests__/common-utils.d.ts +2 -2
- package/dist/ssh/__tests__/common-utils.d.ts.map +1 -1
- package/dist/ssh/connection_info.cjs +13 -7
- package/dist/ssh/connection_info.cjs.map +1 -1
- package/dist/ssh/connection_info.d.ts +1 -1
- package/dist/ssh/connection_info.d.ts.map +1 -1
- package/dist/ssh/connection_info.js +13 -7
- package/dist/ssh/connection_info.js.map +1 -1
- package/dist/ssh/pl.cjs +79 -76
- package/dist/ssh/pl.cjs.map +1 -1
- package/dist/ssh/pl.d.ts +18 -18
- package/dist/ssh/pl.d.ts.map +1 -1
- package/dist/ssh/pl.js +79 -76
- package/dist/ssh/pl.js.map +1 -1
- package/dist/ssh/pl_paths.cjs +13 -13
- package/dist/ssh/pl_paths.cjs.map +1 -1
- package/dist/ssh/pl_paths.d.ts.map +1 -1
- package/dist/ssh/pl_paths.js +13 -13
- package/dist/ssh/pl_paths.js.map +1 -1
- package/dist/ssh/ssh.cjs +43 -40
- package/dist/ssh/ssh.cjs.map +1 -1
- package/dist/ssh/ssh.d.ts +9 -9
- package/dist/ssh/ssh.d.ts.map +1 -1
- package/dist/ssh/ssh.js +43 -40
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/ssh_errors.cjs +7 -5
- package/dist/ssh/ssh_errors.cjs.map +1 -1
- package/dist/ssh/ssh_errors.d.ts.map +1 -1
- package/dist/ssh/ssh_errors.js +7 -5
- package/dist/ssh/ssh_errors.js.map +1 -1
- package/dist/ssh/supervisord.cjs +15 -13
- package/dist/ssh/supervisord.cjs.map +1 -1
- package/dist/ssh/supervisord.d.ts +2 -2
- package/dist/ssh/supervisord.d.ts.map +1 -1
- package/dist/ssh/supervisord.js +15 -13
- package/dist/ssh/supervisord.js.map +1 -1
- package/package.json +37 -36
- package/src/common/os_and_arch.ts +19 -19
- package/src/common/pl_binary.ts +30 -27
- package/src/common/pl_binary_download.ts +80 -59
- package/src/common/pl_version.ts +2 -2
- package/src/index.ts +5 -5
- package/src/local/config.test.yaml +19 -19
- package/src/local/options.ts +4 -4
- package/src/local/pid.ts +4 -4
- package/src/local/pl.test.ts +245 -253
- package/src/local/pl.ts +45 -50
- package/src/local/process.ts +21 -21
- package/src/local/trace.ts +1 -1
- package/src/ssh/__tests__/common-utils.ts +21 -19
- package/src/ssh/__tests__/pl-docker.test.ts +68 -59
- package/src/ssh/__tests__/ssh-docker.test.ts +152 -90
- package/src/ssh/__tests__/ssh-upload.test.ts +42 -31
- package/src/ssh/connection_info.ts +33 -27
- package/src/ssh/pl.test.ts +15 -13
- package/src/ssh/pl.ts +228 -143
- package/src/ssh/pl_paths.ts +22 -18
- package/src/ssh/ssh.ts +151 -74
- package/src/ssh/ssh_errors.test.ts +39 -39
- package/src/ssh/ssh_errors.ts +8 -6
- package/src/ssh/supervisord.ts +28 -28
|
@@ -9,31 +9,31 @@ import { fileExists, assertNever } from '@milaboratories/ts-helpers';
|
|
|
9
9
|
import decompress from 'decompress';
|
|
10
10
|
import { newOs, newArch } from './os_and_arch.js';
|
|
11
11
|
|
|
12
|
-
const cdn =
|
|
12
|
+
const cdn = "https://cdn.platforma.bio/software";
|
|
13
13
|
// We'll download things from Global Access if downloading from CDN has failed
|
|
14
14
|
// (it might be that it's blocked from the company's network.)
|
|
15
|
-
const gaCdn =
|
|
16
|
-
async function downloadBinaryNoExtract({ logger, baseDir, softwareName, tgzName, arch, platform, dispatcher }) {
|
|
15
|
+
const gaCdn = "https://cdn-ga.pl-open.science/software";
|
|
16
|
+
async function downloadBinaryNoExtract({ logger, baseDir, softwareName, tgzName, arch, platform, dispatcher, }) {
|
|
17
17
|
const opts = getPathsForDownload(softwareName, tgzName, baseDir, newArch(arch), newOs(platform));
|
|
18
18
|
const { archiveUrl, alternativeArchiveGAUrl, archivePath } = opts;
|
|
19
19
|
try {
|
|
20
20
|
await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
|
|
21
21
|
opts.wasDownloadedFrom = archiveUrl;
|
|
22
22
|
}
|
|
23
|
-
catch
|
|
23
|
+
catch {
|
|
24
24
|
await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });
|
|
25
25
|
opts.wasDownloadedFrom = alternativeArchiveGAUrl;
|
|
26
26
|
}
|
|
27
27
|
return opts;
|
|
28
28
|
}
|
|
29
|
-
async function downloadBinary({ logger, baseDir, softwareName, archiveName, arch, platform, dispatcher }) {
|
|
29
|
+
async function downloadBinary({ logger, baseDir, softwareName, archiveName, arch, platform, dispatcher, }) {
|
|
30
30
|
const opts = getPathsForDownload(softwareName, archiveName, baseDir, newArch(arch), newOs(platform));
|
|
31
31
|
const { archiveUrl, alternativeArchiveGAUrl, archivePath, archiveType, targetFolder } = opts;
|
|
32
32
|
try {
|
|
33
33
|
await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
|
|
34
34
|
opts.wasDownloadedFrom = archiveUrl;
|
|
35
35
|
}
|
|
36
|
-
catch
|
|
36
|
+
catch {
|
|
37
37
|
await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });
|
|
38
38
|
opts.wasDownloadedFrom = alternativeArchiveGAUrl;
|
|
39
39
|
}
|
|
@@ -58,7 +58,7 @@ function getPathsForDownload(softwareName, archiveName, baseDir, arch, os) {
|
|
|
58
58
|
baseName,
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher }) {
|
|
61
|
+
async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher, }) {
|
|
62
62
|
const state = {};
|
|
63
63
|
state.archivePath = archivePath;
|
|
64
64
|
try {
|
|
@@ -80,7 +80,7 @@ async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher })
|
|
|
80
80
|
throw new Error(state.errorMsg);
|
|
81
81
|
}
|
|
82
82
|
// to prevent incomplete downloads we first write in a temp file
|
|
83
|
-
state.tmpPath = archivePath +
|
|
83
|
+
state.tmpPath = archivePath + ".tmp";
|
|
84
84
|
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
85
85
|
await Readable.toWeb(body).pipeTo(Writable.toWeb(fs.createWriteStream(state.tmpPath)));
|
|
86
86
|
state.wroteTmp = true;
|
|
@@ -98,9 +98,9 @@ async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher })
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/** Used to prevent mid-way interrupted unarchived folders to be used */
|
|
101
|
-
const MarkerFileName =
|
|
101
|
+
const MarkerFileName = ".ok";
|
|
102
102
|
async function extractArchive(logger, archivePath, archiveType, dstFolder) {
|
|
103
|
-
logger.info(
|
|
103
|
+
logger.info("extracting archive...");
|
|
104
104
|
logger.info(` archive path: '${archivePath}'`);
|
|
105
105
|
logger.info(` target dir: '${dstFolder}'`);
|
|
106
106
|
if (!(await fileExists(archivePath))) {
|
|
@@ -121,27 +121,27 @@ async function extractArchive(logger, archivePath, archiveType, dstFolder) {
|
|
|
121
121
|
await fsp.mkdir(dstFolder, { recursive: true });
|
|
122
122
|
logger.info(`Unpacking Platforma Backend archive:\n Archive: ${archivePath}\n Target dir: ${dstFolder}`);
|
|
123
123
|
switch (archiveType) {
|
|
124
|
-
case
|
|
124
|
+
case "tgz":
|
|
125
125
|
await tar.x({
|
|
126
126
|
file: archivePath,
|
|
127
127
|
cwd: dstFolder,
|
|
128
128
|
gzip: true,
|
|
129
129
|
});
|
|
130
130
|
break;
|
|
131
|
-
case
|
|
131
|
+
case "zip":
|
|
132
132
|
await decompress(archivePath, dstFolder);
|
|
133
133
|
break;
|
|
134
134
|
default:
|
|
135
135
|
assertNever(archiveType);
|
|
136
136
|
}
|
|
137
137
|
// writing marker file, to be able in the future detect that we completely unarchived the tar file
|
|
138
|
-
await fsp.writeFile(markerFilePath,
|
|
138
|
+
await fsp.writeFile(markerFilePath, "ok");
|
|
139
139
|
logger.info(` ... unpack done.`);
|
|
140
140
|
}
|
|
141
141
|
const osToArchiveType = {
|
|
142
|
-
linux:
|
|
143
|
-
macos:
|
|
144
|
-
windows:
|
|
142
|
+
linux: "tgz",
|
|
143
|
+
macos: "tgz",
|
|
144
|
+
windows: "zip",
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
export { downloadArchive, downloadBinary, downloadBinaryNoExtract, extractArchive };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl_binary_download.js","sources":["../../src/common/pl_binary_download.ts"],"sourcesContent":["import fs from 'node:fs';\nimport fsp from 'node:fs/promises';\nimport upath from 'upath';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { Writable, Readable } from 'node:stream';\nimport { text } from 'node:stream/consumers';\nimport * as tar from 'tar';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { assertNever, fileExists } from '@milaboratories/ts-helpers';\nimport decompress from 'decompress';\nimport type { ArchType, OSType } from './os_and_arch';\nimport { newOs, newArch } from './os_and_arch';\n\nconst cdn = 'https://cdn.platforma.bio/software';\n// We'll download things from Global Access if downloading from CDN has failed\n// (it might be that it's blocked from the company's network.)\nconst gaCdn = 'https://cdn-ga.pl-open.science/software';\n\nexport type DownloadBinaryResult = {\n archiveUrl: string;\n alternativeArchiveGAUrl: string;\n wasDownloadedFrom?: string;\n archivePath: string;\n archiveType: ArchiveType;\n targetFolder: string;\n baseName: string;\n};\n\nexport async function downloadBinaryNoExtract(\n { logger, baseDir, softwareName, tgzName, arch, platform, dispatcher }: {\n logger: MiLogger;\n baseDir: string;\n softwareName: string;\n tgzName: string;\n arch: string;\n platform: string;\n dispatcher?: Dispatcher;\n },\n): Promise<DownloadBinaryResult> {\n const opts = getPathsForDownload(softwareName, tgzName, baseDir, newArch(arch), newOs(platform));\n const { archiveUrl, alternativeArchiveGAUrl, archivePath } = opts;\n\n try {\n await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n return opts;\n}\n\nexport async function downloadBinary(\n { logger, baseDir, softwareName, archiveName, arch, platform, dispatcher }: {\n logger: MiLogger;\n baseDir: string;\n softwareName: string;\n archiveName: string;\n arch: string;\n platform: string;\n dispatcher?: Dispatcher;\n },\n): Promise<DownloadBinaryResult> {\n const opts = getPathsForDownload(softwareName, archiveName, baseDir, newArch(arch), newOs(platform));\n const { archiveUrl, alternativeArchiveGAUrl, archivePath, archiveType, targetFolder } = opts;\n\n try {\n await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n await extractArchive(logger, archivePath, archiveType, targetFolder);\n\n return opts;\n}\n\nfunction getPathsForDownload(\n softwareName: string,\n archiveName: string,\n baseDir: string,\n arch: ArchType,\n os: OSType,\n): DownloadBinaryResult {\n const baseName = `${archiveName}-${arch}`;\n const archiveType = osToArchiveType[os];\n\n const archiveFileName = `${baseName}.${archiveType}`;\n const archiveUrl = `${cdn}/${softwareName}/${os}/${archiveFileName}`;\n const alternativeArchiveGAUrl = `${gaCdn}/${softwareName}/${os}/${archiveFileName}`;\n const archivePath = upath.join(baseDir, archiveFileName);\n // folder where binary distribution of pl will be unpacked\n const targetFolder = upath.join(baseDir, baseName);\n\n return {\n archiveUrl,\n alternativeArchiveGAUrl,\n archivePath,\n archiveType,\n targetFolder,\n baseName,\n };\n}\n\nexport type DownloadInfo = {\n archivePath?: string;\n fileExisted?: boolean;\n dirnameCreated?: boolean;\n statusCode?: number;\n errorMsg?: string;\n tmpPath?: string;\n wroteTmp?: boolean;\n tmpExisted?: boolean;\n renamed?: boolean;\n newExisted?: boolean;\n};\n\nexport async function downloadArchive(\n { logger, archiveUrl, archivePath, dispatcher }: {\n logger: MiLogger;\n archiveUrl: string;\n archivePath: string;\n dispatcher?: Dispatcher;\n },\n): Promise<DownloadInfo> {\n const state: DownloadInfo = {};\n state.archivePath = archivePath;\n\n try {\n state.fileExisted = await fileExists(archivePath);\n if (state.fileExisted) {\n logger.info(`Platforma Backend archive download skipped: '${archivePath}' already exists`);\n return state;\n }\n\n await fsp.mkdir(upath.dirname(archivePath), { recursive: true });\n state.dirnameCreated = true;\n\n logger.info(`Downloading archive:\\n URL: ${archiveUrl}\\n Save to: ${archivePath}`);\n\n const { body, statusCode } = await request(archiveUrl, { dispatcher });\n state.statusCode = statusCode;\n if (statusCode != 200) {\n // completely draining the stream to prevent leaving open connections\n const textBody = await text(body);\n state.errorMsg = `failed to download archive: ${statusCode}, response: ${textBody.slice(0, 1000)}`;\n logger.error(state.errorMsg);\n throw new Error(state.errorMsg);\n }\n\n // to prevent incomplete downloads we first write in a temp file\n state.tmpPath = archivePath + '.tmp';\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n await Readable.toWeb(body).pipeTo(Writable.toWeb(fs.createWriteStream(state.tmpPath)));\n state.wroteTmp = true;\n state.tmpExisted = await fileExists(state.tmpPath);\n\n // and then atomically rename it\n await fsp.rename(state.tmpPath, archivePath);\n state.renamed = true;\n state.newExisted = await fileExists(archivePath);\n\n return state;\n } catch (e: unknown) {\n const msg = `downloadArchive: ${JSON.stringify(e)}, state: ${JSON.stringify(state)}`;\n logger.error(msg);\n throw new Error(msg);\n }\n}\n\n/** Used to prevent mid-way interrupted unarchived folders to be used */\nconst MarkerFileName = '.ok';\n\nexport async function extractArchive(\n logger: MiLogger,\n archivePath: string,\n archiveType: ArchiveType,\n dstFolder: string,\n) {\n logger.info('extracting archive...');\n logger.info(` archive path: '${archivePath}'`);\n logger.info(` target dir: '${dstFolder}'`);\n\n if (!(await fileExists(archivePath))) {\n const msg = `Platforma Backend binary archive not found at '${archivePath}'`;\n logger.error(msg);\n throw new Error(msg);\n }\n\n const markerFilePath = upath.join(dstFolder, MarkerFileName);\n\n if (await fileExists(markerFilePath)) {\n logger.info(`Platforma Backend binaries unpack skipped: '${dstFolder}' exists`);\n return;\n }\n\n if (await fileExists(dstFolder)) {\n logger.info(`Removing previous incompletely unpacked folder: '${dstFolder}'`);\n await fsp.rm(dstFolder, { recursive: true });\n }\n\n logger.info(` creating target dir '${dstFolder}'`);\n await fsp.mkdir(dstFolder, { recursive: true });\n\n logger.info(\n `Unpacking Platforma Backend archive:\\n Archive: ${archivePath}\\n Target dir: ${dstFolder}`,\n );\n\n switch (archiveType) {\n case 'tgz':\n await tar.x({\n file: archivePath,\n cwd: dstFolder,\n gzip: true,\n });\n break;\n\n case 'zip':\n await decompress(archivePath, dstFolder);\n break;\n\n default:\n assertNever(archiveType);\n }\n\n // writing marker file, to be able in the future detect that we completely unarchived the tar file\n await fsp.writeFile(markerFilePath, 'ok');\n\n logger.info(` ... unpack done.`);\n}\n\nexport type ArchiveType = 'tgz' | 'zip';\n\nconst osToArchiveType: Record<OSType, ArchiveType> = {\n linux: 'tgz',\n macos: 'tgz',\n windows: 'zip',\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAcA,MAAM,GAAG,GAAG,oCAAoC;AAChD;AACA;AACA,MAAM,KAAK,GAAG,yCAAyC;AAYhD,eAAe,uBAAuB,CAC3C,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAQnE,EAAA;IAED,MAAM,IAAI,GAAG,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChG,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,GAAG,IAAI;AAEjE,IAAA,IAAI;AACF,QAAA,MAAM,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACtE,QAAA,IAAI,C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AS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE/C,MAAM,CAAC,IAAI,CACT,CAAA,mDAAA,EAAsD,WAAW,CAAA,gBAAA,EAAmB,SAAS,CAAA,CAAE,CAChG;IAED,QAAQ,WAAW;AACjB,QAAA,KAAK,KAAK;YACR,MAAM,GAAG,CAAC,CAAC,CAAC;AACV,gBAAA,IAAI,EAAE,WAAW;AACjB,gBAAA,GAAG,EAAE,SAAS;AACd,gBAAA,IAAI,EAAE,IAAI;AACX,aAAA,CAAC;YACF;AAEF,QAAA,KAAK,KAAK;AACR,YAAA,MAAM,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC;YACxC;AAEF,QAAA;YACE,WAAW,CAAC,WAAW,CAAC;;;IAI5B,MAAM,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC;AAEzC,IAAA,MAAM,CAAC,IAAI,CAAC,CAAA,kBAAA,CAAoB,CAAC;AACnC;AAIA,MAAM,eAAe,GAAgC;AACnD,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,OAAO,EAAE,KAAK;CACf;;;;"}
|
|
1
|
+
{"version":3,"file":"pl_binary_download.js","sources":["../../src/common/pl_binary_download.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport fsp from \"node:fs/promises\";\nimport upath from \"upath\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { Writable, Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport * as tar from \"tar\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { assertNever, fileExists } from \"@milaboratories/ts-helpers\";\nimport decompress from \"decompress\";\nimport type { ArchType, OSType } from \"./os_and_arch\";\nimport { newOs, newArch } from \"./os_and_arch\";\n\nconst cdn = \"https://cdn.platforma.bio/software\";\n// We'll download things from Global Access if downloading from CDN has failed\n// (it might be that it's blocked from the company's network.)\nconst gaCdn = \"https://cdn-ga.pl-open.science/software\";\n\nexport type DownloadBinaryResult = {\n archiveUrl: string;\n alternativeArchiveGAUrl: string;\n wasDownloadedFrom?: string;\n archivePath: string;\n archiveType: ArchiveType;\n targetFolder: string;\n baseName: string;\n};\n\nexport async function downloadBinaryNoExtract({\n logger,\n baseDir,\n softwareName,\n tgzName,\n arch,\n platform,\n dispatcher,\n}: {\n logger: MiLogger;\n baseDir: string;\n softwareName: string;\n tgzName: string;\n arch: string;\n platform: string;\n dispatcher?: Dispatcher;\n}): Promise<DownloadBinaryResult> {\n const opts = getPathsForDownload(softwareName, tgzName, baseDir, newArch(arch), newOs(platform));\n const { archiveUrl, alternativeArchiveGAUrl, archivePath } = opts;\n\n try {\n await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = archiveUrl;\n } catch {\n await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n return opts;\n}\n\nexport async function downloadBinary({\n logger,\n baseDir,\n softwareName,\n archiveName,\n arch,\n platform,\n dispatcher,\n}: {\n logger: MiLogger;\n baseDir: string;\n softwareName: string;\n archiveName: string;\n arch: string;\n platform: string;\n dispatcher?: Dispatcher;\n}): Promise<DownloadBinaryResult> {\n const opts = getPathsForDownload(\n softwareName,\n archiveName,\n baseDir,\n newArch(arch),\n newOs(platform),\n );\n const { archiveUrl, alternativeArchiveGAUrl, archivePath, archiveType, targetFolder } = opts;\n\n try {\n await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = archiveUrl;\n } catch {\n await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n await extractArchive(logger, archivePath, archiveType, targetFolder);\n\n return opts;\n}\n\nfunction getPathsForDownload(\n softwareName: string,\n archiveName: string,\n baseDir: string,\n arch: ArchType,\n os: OSType,\n): DownloadBinaryResult {\n const baseName = `${archiveName}-${arch}`;\n const archiveType = osToArchiveType[os];\n\n const archiveFileName = `${baseName}.${archiveType}`;\n const archiveUrl = `${cdn}/${softwareName}/${os}/${archiveFileName}`;\n const alternativeArchiveGAUrl = `${gaCdn}/${softwareName}/${os}/${archiveFileName}`;\n const archivePath = upath.join(baseDir, archiveFileName);\n // folder where binary distribution of pl will be unpacked\n const targetFolder = upath.join(baseDir, baseName);\n\n return {\n archiveUrl,\n alternativeArchiveGAUrl,\n archivePath,\n archiveType,\n targetFolder,\n baseName,\n };\n}\n\nexport type DownloadInfo = {\n archivePath?: string;\n fileExisted?: boolean;\n dirnameCreated?: boolean;\n statusCode?: number;\n errorMsg?: string;\n tmpPath?: string;\n wroteTmp?: boolean;\n tmpExisted?: boolean;\n renamed?: boolean;\n newExisted?: boolean;\n};\n\nexport async function downloadArchive({\n logger,\n archiveUrl,\n archivePath,\n dispatcher,\n}: {\n logger: MiLogger;\n archiveUrl: string;\n archivePath: string;\n dispatcher?: Dispatcher;\n}): Promise<DownloadInfo> {\n const state: DownloadInfo = {};\n state.archivePath = archivePath;\n\n try {\n state.fileExisted = await fileExists(archivePath);\n if (state.fileExisted) {\n logger.info(`Platforma Backend archive download skipped: '${archivePath}' already exists`);\n return state;\n }\n\n await fsp.mkdir(upath.dirname(archivePath), { recursive: true });\n state.dirnameCreated = true;\n\n logger.info(`Downloading archive:\\n URL: ${archiveUrl}\\n Save to: ${archivePath}`);\n\n const { body, statusCode } = await request(archiveUrl, { dispatcher });\n state.statusCode = statusCode;\n if (statusCode != 200) {\n // completely draining the stream to prevent leaving open connections\n const textBody = await text(body);\n state.errorMsg = `failed to download archive: ${statusCode}, response: ${textBody.slice(0, 1000)}`;\n logger.error(state.errorMsg);\n throw new Error(state.errorMsg);\n }\n\n // to prevent incomplete downloads we first write in a temp file\n state.tmpPath = archivePath + \".tmp\";\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n await Readable.toWeb(body).pipeTo(Writable.toWeb(fs.createWriteStream(state.tmpPath)));\n state.wroteTmp = true;\n state.tmpExisted = await fileExists(state.tmpPath);\n\n // and then atomically rename it\n await fsp.rename(state.tmpPath, archivePath);\n state.renamed = true;\n state.newExisted = await fileExists(archivePath);\n\n return state;\n } catch (e: unknown) {\n const msg = `downloadArchive: ${JSON.stringify(e)}, state: ${JSON.stringify(state)}`;\n logger.error(msg);\n throw new Error(msg);\n }\n}\n\n/** Used to prevent mid-way interrupted unarchived folders to be used */\nconst MarkerFileName = \".ok\";\n\nexport async function extractArchive(\n logger: MiLogger,\n archivePath: string,\n archiveType: ArchiveType,\n dstFolder: string,\n) {\n logger.info(\"extracting archive...\");\n logger.info(` archive path: '${archivePath}'`);\n logger.info(` target dir: '${dstFolder}'`);\n\n if (!(await fileExists(archivePath))) {\n const msg = `Platforma Backend binary archive not found at '${archivePath}'`;\n logger.error(msg);\n throw new Error(msg);\n }\n\n const markerFilePath = upath.join(dstFolder, MarkerFileName);\n\n if (await fileExists(markerFilePath)) {\n logger.info(`Platforma Backend binaries unpack skipped: '${dstFolder}' exists`);\n return;\n }\n\n if (await fileExists(dstFolder)) {\n logger.info(`Removing previous incompletely unpacked folder: '${dstFolder}'`);\n await fsp.rm(dstFolder, { recursive: true });\n }\n\n logger.info(` creating target dir '${dstFolder}'`);\n await fsp.mkdir(dstFolder, { recursive: true });\n\n logger.info(\n `Unpacking Platforma Backend archive:\\n Archive: ${archivePath}\\n Target dir: ${dstFolder}`,\n );\n\n switch (archiveType) {\n case \"tgz\":\n await tar.x({\n file: archivePath,\n cwd: dstFolder,\n gzip: true,\n });\n break;\n\n case \"zip\":\n await decompress(archivePath, dstFolder);\n break;\n\n default:\n assertNever(archiveType);\n }\n\n // writing marker file, to be able in the future detect that we completely unarchived the tar file\n await fsp.writeFile(markerFilePath, \"ok\");\n\n logger.info(` ... unpack done.`);\n}\n\nexport type ArchiveType = \"tgz\" | \"zip\";\n\nconst osToArchiveType: Record<OSType, ArchiveType> = {\n linux: \"tgz\",\n macos: \"tg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,IAAA,OAAO,EAAE,KAAK;CACf;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl_version.cjs","sources":["../../src/common/pl_version.ts"],"sourcesContent":["import packageJson from
|
|
1
|
+
{"version":3,"file":"pl_version.cjs","sources":["../../src/common/pl_version.ts"],"sourcesContent":["import packageJson from \"../../package.json\";\n\nexport function getDefaultPlVersion(): string {\n // drop build error if pl-version is not defined\n return packageJson[\"pl-version\"];\n}\n"],"names":["packageJson"],"mappings":";;;;SAEgB,mBAAmB,GAAA;;AAEjC,IAAA,OAAOA,QAAW,CAAC,YAAY,CAAC;AAClC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl_version.js","sources":["../../src/common/pl_version.ts"],"sourcesContent":["import packageJson from
|
|
1
|
+
{"version":3,"file":"pl_version.js","sources":["../../src/common/pl_version.ts"],"sourcesContent":["import packageJson from \"../../package.json\";\n\nexport function getDefaultPlVersion(): string {\n // drop build error if pl-version is not defined\n return packageJson[\"pl-version\"];\n}\n"],"names":[],"mappings":";;SAEgB,mBAAmB,GAAA;;AAEjC,IAAA,OAAO,WAAW,CAAC,YAAY,CAAC;AAClC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./local/pl";
|
|
2
|
+
export * from "./common/pl_version";
|
|
3
|
+
export * from "./ssh/ssh";
|
|
4
|
+
export * from "./ssh/pl";
|
|
5
|
+
export * from "./ssh/connection_info";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/local/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SpawnOptions } from
|
|
2
|
-
import type { PlBinarySource } from
|
|
1
|
+
import type { SpawnOptions } from "node:child_process";
|
|
2
|
+
import type { PlBinarySource } from "../common/pl_binary";
|
|
3
3
|
/** Options to start a local pl-core. */
|
|
4
4
|
export type LocalPlOptions = {
|
|
5
5
|
/** From what directory start a process. */
|
|
@@ -21,11 +21,11 @@ export type LocalPlOptions = {
|
|
|
21
21
|
export type LocalPlRestart = LocalPlRestartSilent | LocalPlRestartHook;
|
|
22
22
|
/** Do nothing if the error happened or a process exited. */
|
|
23
23
|
export type LocalPlRestartSilent = {
|
|
24
|
-
type:
|
|
24
|
+
type: "silent";
|
|
25
25
|
};
|
|
26
26
|
/** Run a hook if the error happened or a process exited. */
|
|
27
27
|
export type LocalPlRestartHook = {
|
|
28
|
-
type:
|
|
28
|
+
type: "hook";
|
|
29
29
|
hook(pl: any): void;
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/local/pid.cjs
CHANGED
package/dist/local/pid.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pid.cjs","sources":["../../src/local/pid.ts"],"sourcesContent":["import { fileExists } from
|
|
1
|
+
{"version":3,"file":"pid.cjs","sources":["../../src/local/pid.ts"],"sourcesContent":["import { fileExists } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs/promises\";\nimport upath from \"upath\";\n\nexport function filePid(dir: string) {\n return upath.join(dir, \"pl_pid\");\n}\n\nexport async function readPid(filePath: string): Promise<number | undefined> {\n if (!(await fileExists(filePath))) {\n return undefined;\n }\n\n const text = await fs.readFile(filePath);\n\n return Number(text.toString());\n}\n\nexport async function writePid(filePath: string, pid: number) {\n await fs.writeFile(filePath, JSON.stringify(pid));\n}\n"],"names":["fileExists","fs"],"mappings":";;;;;;AAIM,SAAU,OAAO,CAAC,GAAW,EAAA;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC;AAClC;AAEO,eAAe,OAAO,CAAC,QAAgB,EAAA;IAC5C,IAAI,EAAE,MAAMA,oBAAU,CAAC,QAAQ,CAAC,CAAC,EAAE;AACjC,QAAA,OAAO,SAAS;IAClB;IAEA,MAAM,IAAI,GAAG,MAAMC,GAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAExC,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;AAChC;AAEO,eAAe,QAAQ,CAAC,QAAgB,EAAE,GAAW,EAAA;AAC1D,IAAA,MAAMA,GAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AACnD;;;;;;"}
|
package/dist/local/pid.js
CHANGED
package/dist/local/pid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pid.js","sources":["../../src/local/pid.ts"],"sourcesContent":["import { fileExists } from
|
|
1
|
+
{"version":3,"file":"pid.js","sources":["../../src/local/pid.ts"],"sourcesContent":["import { fileExists } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs/promises\";\nimport upath from \"upath\";\n\nexport function filePid(dir: string) {\n return upath.join(dir, \"pl_pid\");\n}\n\nexport async function readPid(filePath: string): Promise<number | undefined> {\n if (!(await fileExists(filePath))) {\n return undefined;\n }\n\n const text = await fs.readFile(filePath);\n\n return Number(text.toString());\n}\n\nexport async function writePid(filePath: string, pid: number) {\n await fs.writeFile(filePath, JSON.stringify(pid));\n}\n"],"names":["fs"],"mappings":";;;;AAIM,SAAU,OAAO,CAAC,GAAW,EAAA;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC;AAClC;AAEO,eAAe,OAAO,CAAC,QAAgB,EAAA;IAC5C,IAAI,EAAE,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE;AACjC,QAAA,OAAO,SAAS;IAClB;IAEA,MAAM,IAAI,GAAG,MAAMA,GAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAExC,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;AAChC;AAEO,eAAe,QAAQ,CAAC,QAAgB,EAAE,GAAW,EAAA;AAC1D,IAAA,MAAMA,GAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AACnD;;;;"}
|
package/dist/local/pl.cjs
CHANGED
|
@@ -30,7 +30,7 @@ function _interopNamespaceDefault(e) {
|
|
|
30
30
|
|
|
31
31
|
var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
|
|
32
32
|
|
|
33
|
-
const LocalConfigYaml =
|
|
33
|
+
const LocalConfigYaml = "config-local.yaml";
|
|
34
34
|
/**
|
|
35
35
|
* Represents a local running pl-core,
|
|
36
36
|
* and has methods to start, check if it's running, stop and wait for stopping it.
|
|
@@ -64,7 +64,7 @@ class LocalPl {
|
|
|
64
64
|
await trace.withTrace(this.logger, async (trace, t) => {
|
|
65
65
|
this.wasStopped = false;
|
|
66
66
|
const instance = process$1.processRun(this.logger, this.startOptions);
|
|
67
|
-
instance.on(
|
|
67
|
+
instance.on("error", (e) => {
|
|
68
68
|
this.logger.error(`error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`);
|
|
69
69
|
// keep in mind there are no awaits here, it will be asynchronous
|
|
70
70
|
if (this.onError !== undefined)
|
|
@@ -74,7 +74,7 @@ class LocalPl {
|
|
|
74
74
|
if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)
|
|
75
75
|
void this.onCloseAndErrorNoStop(this);
|
|
76
76
|
});
|
|
77
|
-
instance.on(
|
|
77
|
+
instance.on("close", () => {
|
|
78
78
|
this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);
|
|
79
79
|
// keep in mind there are no awaits here, it will be asynchronous
|
|
80
80
|
if (this.onClose !== undefined)
|
|
@@ -84,10 +84,10 @@ class LocalPl {
|
|
|
84
84
|
if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)
|
|
85
85
|
void this.onCloseAndErrorNoStop(this);
|
|
86
86
|
});
|
|
87
|
-
trace(
|
|
88
|
-
const pidFile = trace(
|
|
89
|
-
trace(
|
|
90
|
-
trace(
|
|
87
|
+
trace("started", true);
|
|
88
|
+
const pidFile = trace("pidFile", pid.filePid(this.workingDir));
|
|
89
|
+
trace("pid", tsHelpers.notEmpty(instance.pid));
|
|
90
|
+
trace("pidWritten", await pid.writePid(pidFile, tsHelpers.notEmpty(instance.pid)));
|
|
91
91
|
this.nRuns++;
|
|
92
92
|
this.instance = instance;
|
|
93
93
|
this.pid = instance.pid;
|
|
@@ -129,28 +129,28 @@ async function localPlatformaInit(logger, _ops) {
|
|
|
129
129
|
const numCpu = Math.max(os__namespace.cpus().length - 2, 1);
|
|
130
130
|
const ops = mergeDefaultOps(_ops, numCpu);
|
|
131
131
|
return await trace.withTrace(logger, async (trace, t) => {
|
|
132
|
-
trace(
|
|
132
|
+
trace("startOptions", { ...ops, config: "too wordy" });
|
|
133
133
|
const workDir = upath.resolve(ops.workingDir);
|
|
134
134
|
if (ops.closeOld) {
|
|
135
|
-
trace(
|
|
135
|
+
trace("closeOld", await localPlatformaReadPidAndStop(logger, workDir));
|
|
136
136
|
}
|
|
137
137
|
const configPath = upath.join(workDir, LocalConfigYaml);
|
|
138
138
|
logger.info(`writing configuration '${configPath}'...`);
|
|
139
139
|
await fsp.writeFile(configPath, ops.config);
|
|
140
|
-
const plBinPath = upath.join(workDir,
|
|
140
|
+
const plBinPath = upath.join(workDir, "binaries");
|
|
141
141
|
const baseBinaryPath = await pl_binary.resolveLocalPlBinaryPath({
|
|
142
142
|
logger,
|
|
143
143
|
downloadDir: plBinPath,
|
|
144
144
|
src: ops.plBinary,
|
|
145
145
|
dispatcher: plHttp.defaultHttpDispatcher(ops.proxy),
|
|
146
146
|
});
|
|
147
|
-
const binaryPath = trace(
|
|
147
|
+
const binaryPath = trace("binaryPath", upath.join("binaries", baseBinaryPath));
|
|
148
148
|
const env = { ...process.env };
|
|
149
149
|
if (ops.proxy?.url) {
|
|
150
150
|
const url = new URL(ops.proxy.url);
|
|
151
151
|
if (ops.proxy.auth) {
|
|
152
152
|
const parsed = plModelCommon.parseHttpAuth(ops.proxy.auth);
|
|
153
|
-
if (parsed.scheme !==
|
|
153
|
+
if (parsed.scheme !== "Basic") {
|
|
154
154
|
throw new Error(`\
|
|
155
155
|
Unsupported auth scheme: ${parsed.scheme}. \
|
|
156
156
|
Only Basic auth is supported by the backend.`);
|
|
@@ -162,7 +162,7 @@ Only Basic auth is supported by the backend.`);
|
|
|
162
162
|
env.https_proxy = url.toString();
|
|
163
163
|
}
|
|
164
164
|
const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);
|
|
165
|
-
trace(
|
|
165
|
+
trace("processOpts", {
|
|
166
166
|
cmd: processOpts.cmd,
|
|
167
167
|
args: processOpts.args,
|
|
168
168
|
cwd: processOpts.opts.cwd,
|
|
@@ -176,17 +176,17 @@ Only Basic auth is supported by the backend.`);
|
|
|
176
176
|
* and closes it. */
|
|
177
177
|
async function localPlatformaReadPidAndStop(logger, workingDir) {
|
|
178
178
|
return await trace.withTrace(logger, async (trace, t) => {
|
|
179
|
-
const file = trace(
|
|
180
|
-
const oldPid = trace(
|
|
181
|
-
const alive = trace(
|
|
179
|
+
const file = trace("pidFilePath", pid.filePid(workingDir));
|
|
180
|
+
const oldPid = trace("pid", await pid.readPid(file));
|
|
181
|
+
const alive = trace("wasAlive", await process$1.isProcessAlive(oldPid));
|
|
182
182
|
if (oldPid !== undefined && alive) {
|
|
183
|
-
trace(
|
|
183
|
+
trace("stopped", process$1.processStop(oldPid));
|
|
184
184
|
try {
|
|
185
|
-
trace(
|
|
185
|
+
trace("waitStopped", await process$1.processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.
|
|
186
186
|
}
|
|
187
|
-
catch
|
|
188
|
-
trace(
|
|
189
|
-
trace(
|
|
187
|
+
catch {
|
|
188
|
+
trace("forceStopped", process$1.processStop(oldPid, true));
|
|
189
|
+
trace("waitForceStopped", await process$1.processWaitStopped(oldPid, 5_000));
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
return t;
|
|
@@ -209,11 +209,11 @@ function mergeDefaultOps(ops, numCpu) {
|
|
|
209
209
|
}
|
|
210
210
|
if (ops.spawnOptions) {
|
|
211
211
|
const withoutEnv = { ...ops.spawnOptions };
|
|
212
|
-
delete withoutEnv[
|
|
212
|
+
delete withoutEnv["env"];
|
|
213
213
|
result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };
|
|
214
214
|
}
|
|
215
215
|
const withoutSpawnOps = { ...ops };
|
|
216
|
-
delete withoutSpawnOps[
|
|
216
|
+
delete withoutSpawnOps["spawnOptions"];
|
|
217
217
|
return { ...result, ...withoutSpawnOps };
|
|
218
218
|
}
|
|
219
219
|
/** Gets default options for a platforma local binary
|
|
@@ -221,11 +221,11 @@ function mergeDefaultOps(ops, numCpu) {
|
|
|
221
221
|
function plProcessOps(binaryPath, configPath, ops, workDir, defaultEnv) {
|
|
222
222
|
const result = {
|
|
223
223
|
cmd: binaryPath,
|
|
224
|
-
args: [
|
|
224
|
+
args: ["--config", configPath],
|
|
225
225
|
opts: {
|
|
226
226
|
env: { ...defaultEnv },
|
|
227
227
|
cwd: workDir,
|
|
228
|
-
stdio: [
|
|
228
|
+
stdio: ["pipe", "ignore", "inherit"],
|
|
229
229
|
windowsHide: true, // hide a terminal on Windows
|
|
230
230
|
},
|
|
231
231
|
};
|
|
@@ -233,7 +233,7 @@ function plProcessOps(binaryPath, configPath, ops, workDir, defaultEnv) {
|
|
|
233
233
|
result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };
|
|
234
234
|
}
|
|
235
235
|
const withoutEnv = { ...ops.spawnOptions };
|
|
236
|
-
delete withoutEnv[
|
|
236
|
+
delete withoutEnv["env"];
|
|
237
237
|
result.opts = { ...result.opts, ...withoutEnv };
|
|
238
238
|
return result;
|
|
239
239
|
}
|
package/dist/local/pl.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.cjs","sources":["../../src/local/pl.ts"],"sourcesContent":["import type { ProcessOptions } from './process';\nimport {\n isProcessAlive,\n processStop,\n processWaitStopped,\n processRun,\n} from './process';\nimport type { PlBinarySource } from '../common/pl_binary';\nimport { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from '../common/pl_binary';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport type { ChildProcess, SpawnOptions } from 'node:child_process';\nimport { filePid, readPid, writePid } from './pid';\nimport type { Trace } from './trace';\nimport { withTrace } from './trace';\nimport upath from 'upath';\nimport fsp from 'node:fs/promises';\nimport type { Required } from 'utility-types';\nimport * as os from 'node:os';\nimport type { ProxySettings } from '@milaboratories/pl-http';\nimport { defaultHttpDispatcher } from '@milaboratories/pl-http';\nimport { parseHttpAuth } from '@milaboratories/pl-model-common';\n\nexport const LocalConfigYaml = 'config-local.yaml';\n\n/**\n * Represents a local running pl-core,\n * and has methods to start, check if it's running, stop and wait for stopping it.\n * Also, a hook on pl-core closed can be provided.\n */\nexport class LocalPl {\n private instance?: ChildProcess;\n public pid?: number;\n private nRuns: number = 0;\n private lastRunHistory: Trace = {};\n private wasStopped = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly workingDir: string,\n private readonly startOptions: ProcessOptions,\n private readonly initialStartHistory: Trace,\n private readonly onClose?: (pl: LocalPl) => Promise<void>,\n private readonly onError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>,\n ) {}\n\n async start() {\n await withTrace(this.logger, async (trace, t) => {\n this.wasStopped = false;\n const instance = processRun(this.logger, this.startOptions);\n instance.on('error', (e: any) => {\n this.logger.error(\n `error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`,\n );\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onError !== undefined) void this.onError(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n instance.on('close', () => {\n this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onClose !== undefined) void this.onClose(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n\n trace('started', true);\n\n const pidFile = trace('pidFile', filePid(this.workingDir));\n trace('pid', notEmpty(instance.pid));\n trace('pidWritten', await writePid(pidFile, notEmpty(instance.pid)));\n\n this.nRuns++;\n this.instance = instance;\n this.pid = instance.pid;\n this.lastRunHistory = t;\n });\n }\n\n stop() {\n // TODO use this.instance to stop the process\n this.wasStopped = true;\n processStop(notEmpty(this.pid));\n }\n\n async waitStopped() {\n await processWaitStopped(notEmpty(this.pid), 15000);\n }\n\n stopped() {\n return this.wasStopped;\n }\n\n async isAlive(): Promise<boolean> {\n return await isProcessAlive(notEmpty(this.pid));\n }\n\n debugInfo() {\n return {\n lastRunHistory: this.lastRunHistory,\n nRuns: this.nRuns,\n pid: this.pid,\n workingDir: this.workingDir,\n initialStartHistory: this.initialStartHistory,\n wasStopped: this.wasStopped,\n };\n }\n}\n\n/** Options to start a local pl-core. */\nexport type LocalPlOptions = {\n /** From what directory start a process. */\n readonly workingDir: string;\n /** A string representation of yaml config. */\n readonly config: string;\n /** How to get a binary, download it or get an existing one (default: download latest version) */\n readonly plBinary?: PlBinarySource;\n /** Additional options for a process, environments, stdout, stderr etc. */\n readonly spawnOptions?: SpawnOptions;\n /**\n * If the previous pl-core was started from the same directory,\n * we can check if it's still running and then stop it before starting a new one.\n * (default: true)\n */\n readonly closeOld?: boolean;\n /**\n * Proxy settings to use to fetch the binary and pass it down\n * as a HTTPS_PROXY/HTTP_PROXY environment variable;\n * Backend only supports Basic auth.\n */\n readonly proxy?: ProxySettings;\n\n readonly onClose?: (pl: LocalPl) => Promise<void>;\n readonly onError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;\n};\n\nexport type LocalPlOptionsFull = Required<LocalPlOptions, 'plBinary' | 'spawnOptions' | 'closeOld'>;\n\n/**\n * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.\n */\nexport async function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl> {\n // filling-in default values\n\n // Backend could consume a lot of CPU power,\n // we want to keep at least a couple for UI and other apps to work.\n const numCpu = Math.max(os.cpus().length - 2, 1);\n const ops = mergeDefaultOps(_ops, numCpu);\n\n return await withTrace(logger, async (trace, t) => {\n trace('startOptions', { ...ops, config: 'too wordy' });\n\n const workDir = upath.resolve(ops.workingDir);\n\n if (ops.closeOld) {\n trace('closeOld', await localPlatformaReadPidAndStop(logger, workDir));\n }\n\n const configPath = upath.join(workDir, LocalConfigYaml);\n\n logger.info(`writing configuration '${configPath}'...`);\n await fsp.writeFile(configPath, ops.config);\n\n const plBinPath = upath.join(workDir, 'binaries');\n const baseBinaryPath = await resolveLocalPlBinaryPath({\n logger,\n downloadDir: plBinPath,\n src: ops.plBinary,\n dispatcher: defaultHttpDispatcher(ops.proxy),\n });\n const binaryPath = trace('binaryPath', upath.join('binaries', baseBinaryPath));\n\n const env = { ...process.env };\n\n if (ops.proxy?.url) {\n const url = new URL(ops.proxy.url);\n if (ops.proxy.auth) {\n const parsed = parseHttpAuth(ops.proxy.auth);\n if (parsed.scheme !== 'Basic') {\n throw new Error(`\\\nUnsupported auth scheme: ${parsed.scheme}. \\\nOnly Basic auth is supported by the backend.`);\n }\n url.username = parsed.username;\n url.password = parsed.password;\n }\n env.http_proxy = url.toString();\n env.https_proxy = url.toString();\n }\n\n const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);\n trace('processOpts', {\n cmd: processOpts.cmd,\n args: processOpts.args,\n cwd: processOpts.opts.cwd,\n });\n\n const pl = new LocalPl(\n logger,\n ops.workingDir,\n processOpts,\n t,\n ops.onClose,\n ops.onError,\n ops.onCloseAndError,\n ops.onCloseAndErrorNoStop,\n );\n await pl.start();\n\n return pl;\n });\n}\n\n/** Reads a pid of the old pl-core if it was started in the same working directory,\n * and closes it. */\nasync function localPlatformaReadPidAndStop(\n logger: MiLogger,\n workingDir: string,\n): Promise<Record<string, any>> {\n return await withTrace(logger, async (trace, t) => {\n const file = trace('pidFilePath', filePid(workingDir));\n\n const oldPid = trace('pid', await readPid(file));\n const alive = trace('wasAlive', await isProcessAlive(oldPid));\n\n if (oldPid !== undefined && alive) {\n trace('stopped', processStop(oldPid));\n try {\n trace('waitStopped', await processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.\n } catch (_e) {\n trace('forceStopped', processStop(oldPid, true));\n trace('waitForceStopped', await processWaitStopped(oldPid, 5_000));\n }\n }\n\n return t;\n });\n}\n\n/** Gets default options for the whole init process\n * and overrides them with the provided options. */\nexport function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull {\n const result: {\n plBinary: PlBinarySource;\n spawnOptions: SpawnOptions;\n closeOld: boolean;\n } = {\n plBinary: newDefaultPlBinarySource(),\n spawnOptions: {\n env: {\n GOMAXPROCS: String(numCpu),\n },\n },\n closeOld: true,\n };\n\n if (ops.spawnOptions?.env) {\n result.spawnOptions.env = { ...result.spawnOptions.env, ...ops.spawnOptions.env };\n }\n\n if (ops.spawnOptions) {\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv['env'];\n result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };\n }\n\n const withoutSpawnOps = { ...ops };\n delete withoutSpawnOps['spawnOptions'];\n\n return { ...result, ...withoutSpawnOps };\n}\n\n/** Gets default options for a platforma local binary\n * and overrides them with the provided options. */\nexport function plProcessOps(\n binaryPath: any,\n configPath: string,\n ops: LocalPlOptionsFull,\n workDir: string,\n defaultEnv: Record<string, string | undefined>,\n): ProcessOptions {\n const result: ProcessOptions = {\n cmd: binaryPath,\n args: ['--config', configPath],\n opts: {\n env: { ...defaultEnv },\n cwd: workDir,\n stdio: ['pipe', 'ignore', 'inherit'],\n windowsHide: true, // hide a terminal on Windows\n },\n };\n\n if (ops.spawnOptions?.env) {\n result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };\n }\n\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv['env'];\n result.opts = { ...result.opts, ...withoutEnv };\n\n return result;\n}\n"],"names":["withTrace","processRun","filePid","notEmpty","writePid","processStop","processWaitStopped","isProcessAlive","os","resolveLocalPlBinaryPath","defaultHttpDispatcher","parseHttpAuth","readPid","newDefaultPlBinarySource"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,MAAM,eAAe,GAAG;AAE/B;;;;AAIG;MACU,OAAO,CAAA;AAQC,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA;AACA,IAAA,mBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA,eAAA;AACA,IAAA,qBAAA;AAdX,IAAA,QAAQ;AACT,IAAA,GAAG;IACF,KAAK,GAAW,CAAC;IACjB,cAAc,GAAU,EAAE;IAC1B,UAAU,GAAG,KAAK;AAE1B,IAAA,WAAA,CACmB,MAAgB,EAChB,UAAkB,EAClB,YAA4B,EAC5B,mBAA0B,EAC1B,OAAwC,EACxC,OAAwC,EACxC,eAAgD,EAChD,qBAAsD,EAAA;QAPtD,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,mBAAmB,GAAnB,mBAAmB;QACnB,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,eAAe,GAAf,eAAe;QACf,IAAA,CAA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IAAI;AAClB,SAAA;KACF;AAED,IAAA,IAAI,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE;IACnE;IAEA,MAAM,UAAU,GAAG,EAAE,GAAG,GAAG,CAAC,YAAY,EAAE;AAC1C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC;AACxB,IAAA,MAAM,CAAC,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,UAAU,EAAE;AAE/C,IAAA,OAAO,MAAM;AACf;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"pl.cjs","sources":["../../src/local/pl.ts"],"sourcesContent":["import type { ProcessOptions } from \"./process\";\nimport { isProcessAlive, processStop, processWaitStopped, processRun } from \"./process\";\nimport type { PlBinarySource } from \"../common/pl_binary\";\nimport { newDefaultPlBinarySource, resolveLocalPlBinaryPath } from \"../common/pl_binary\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { ChildProcess, SpawnOptions } from \"node:child_process\";\nimport { filePid, readPid, writePid } from \"./pid\";\nimport type { Trace } from \"./trace\";\nimport { withTrace } from \"./trace\";\nimport upath from \"upath\";\nimport fsp from \"node:fs/promises\";\nimport type { Required } from \"utility-types\";\nimport * as os from \"node:os\";\nimport type { ProxySettings } from \"@milaboratories/pl-http\";\nimport { defaultHttpDispatcher } from \"@milaboratories/pl-http\";\nimport { parseHttpAuth } from \"@milaboratories/pl-model-common\";\n\nexport const LocalConfigYaml = \"config-local.yaml\";\n\n/**\n * Represents a local running pl-core,\n * and has methods to start, check if it's running, stop and wait for stopping it.\n * Also, a hook on pl-core closed can be provided.\n */\nexport class LocalPl {\n private instance?: ChildProcess;\n public pid?: number;\n private nRuns: number = 0;\n private lastRunHistory: Trace = {};\n private wasStopped = false;\n\n constructor(\n private readonly logger: MiLogger,\n private readonly workingDir: string,\n private readonly startOptions: ProcessOptions,\n private readonly initialStartHistory: Trace,\n private readonly onClose?: (pl: LocalPl) => Promise<void>,\n private readonly onError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndError?: (pl: LocalPl) => Promise<void>,\n private readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>,\n ) {}\n\n async start() {\n await withTrace(this.logger, async (trace, t) => {\n this.wasStopped = false;\n const instance = processRun(this.logger, this.startOptions);\n instance.on(\"error\", (e: any) => {\n this.logger.error(\n `error '${e}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`,\n );\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onError !== undefined) void this.onError(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n instance.on(\"close\", () => {\n this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`);\n\n // keep in mind there are no awaits here, it will be asynchronous\n if (this.onClose !== undefined) void this.onClose(this);\n if (this.onCloseAndError !== undefined) void this.onCloseAndError(this);\n if (this.onCloseAndErrorNoStop !== undefined && !this.wasStopped)\n void this.onCloseAndErrorNoStop(this);\n });\n\n trace(\"started\", true);\n\n const pidFile = trace(\"pidFile\", filePid(this.workingDir));\n trace(\"pid\", notEmpty(instance.pid));\n trace(\"pidWritten\", await writePid(pidFile, notEmpty(instance.pid)));\n\n this.nRuns++;\n this.instance = instance;\n this.pid = instance.pid;\n this.lastRunHistory = t;\n });\n }\n\n stop() {\n // TODO use this.instance to stop the process\n this.wasStopped = true;\n processStop(notEmpty(this.pid));\n }\n\n async waitStopped() {\n await processWaitStopped(notEmpty(this.pid), 15000);\n }\n\n stopped() {\n return this.wasStopped;\n }\n\n async isAlive(): Promise<boolean> {\n return await isProcessAlive(notEmpty(this.pid));\n }\n\n debugInfo() {\n return {\n lastRunHistory: this.lastRunHistory,\n nRuns: this.nRuns,\n pid: this.pid,\n workingDir: this.workingDir,\n initialStartHistory: this.initialStartHistory,\n wasStopped: this.wasStopped,\n };\n }\n}\n\n/** Options to start a local pl-core. */\nexport type LocalPlOptions = {\n /** From what directory start a process. */\n readonly workingDir: string;\n /** A string representation of yaml config. */\n readonly config: string;\n /** How to get a binary, download it or get an existing one (default: download latest version) */\n readonly plBinary?: PlBinarySource;\n /** Additional options for a process, environments, stdout, stderr etc. */\n readonly spawnOptions?: SpawnOptions;\n /**\n * If the previous pl-core was started from the same directory,\n * we can check if it's still running and then stop it before starting a new one.\n * (default: true)\n */\n readonly closeOld?: boolean;\n /**\n * Proxy settings to use to fetch the binary and pass it down\n * as a HTTPS_PROXY/HTTP_PROXY environment variable;\n * Backend only supports Basic auth.\n */\n readonly proxy?: ProxySettings;\n\n readonly onClose?: (pl: LocalPl) => Promise<void>;\n readonly onError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;\n readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;\n};\n\nexport type LocalPlOptionsFull = Required<LocalPlOptions, \"plBinary\" | \"spawnOptions\" | \"closeOld\">;\n\n/**\n * Starts pl-core, if the option was provided downloads a binary, reads license environments etc.\n */\nexport async function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions): Promise<LocalPl> {\n // filling-in default values\n\n // Backend could consume a lot of CPU power,\n // we want to keep at least a couple for UI and other apps to work.\n const numCpu = Math.max(os.cpus().length - 2, 1);\n const ops = mergeDefaultOps(_ops, numCpu);\n\n return await withTrace(logger, async (trace, t) => {\n trace(\"startOptions\", { ...ops, config: \"too wordy\" });\n\n const workDir = upath.resolve(ops.workingDir);\n\n if (ops.closeOld) {\n trace(\"closeOld\", await localPlatformaReadPidAndStop(logger, workDir));\n }\n\n const configPath = upath.join(workDir, LocalConfigYaml);\n\n logger.info(`writing configuration '${configPath}'...`);\n await fsp.writeFile(configPath, ops.config);\n\n const plBinPath = upath.join(workDir, \"binaries\");\n const baseBinaryPath = await resolveLocalPlBinaryPath({\n logger,\n downloadDir: plBinPath,\n src: ops.plBinary,\n dispatcher: defaultHttpDispatcher(ops.proxy),\n });\n const binaryPath = trace(\"binaryPath\", upath.join(\"binaries\", baseBinaryPath));\n\n const env = { ...process.env };\n\n if (ops.proxy?.url) {\n const url = new URL(ops.proxy.url);\n if (ops.proxy.auth) {\n const parsed = parseHttpAuth(ops.proxy.auth);\n if (parsed.scheme !== \"Basic\") {\n throw new Error(`\\\nUnsupported auth scheme: ${parsed.scheme}. \\\nOnly Basic auth is supported by the backend.`);\n }\n url.username = parsed.username;\n url.password = parsed.password;\n }\n env.http_proxy = url.toString();\n env.https_proxy = url.toString();\n }\n\n const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);\n trace(\"processOpts\", {\n cmd: processOpts.cmd,\n args: processOpts.args,\n cwd: processOpts.opts.cwd,\n });\n\n const pl = new LocalPl(\n logger,\n ops.workingDir,\n processOpts,\n t,\n ops.onClose,\n ops.onError,\n ops.onCloseAndError,\n ops.onCloseAndErrorNoStop,\n );\n await pl.start();\n\n return pl;\n });\n}\n\n/** Reads a pid of the old pl-core if it was started in the same working directory,\n * and closes it. */\nasync function localPlatformaReadPidAndStop(\n logger: MiLogger,\n workingDir: string,\n): Promise<Record<string, any>> {\n return await withTrace(logger, async (trace, t) => {\n const file = trace(\"pidFilePath\", filePid(workingDir));\n\n const oldPid = trace(\"pid\", await readPid(file));\n const alive = trace(\"wasAlive\", await isProcessAlive(oldPid));\n\n if (oldPid !== undefined && alive) {\n trace(\"stopped\", processStop(oldPid));\n try {\n trace(\"waitStopped\", await processWaitStopped(oldPid, 15_000)); // larger, that 10s we provide to backend in config.\n } catch {\n trace(\"forceStopped\", processStop(oldPid, true));\n trace(\"waitForceStopped\", await processWaitStopped(oldPid, 5_000));\n }\n }\n\n return t;\n });\n}\n\n/** Gets default options for the whole init process\n * and overrides them with the provided options. */\nexport function mergeDefaultOps(ops: LocalPlOptions, numCpu: number): LocalPlOptionsFull {\n const result: {\n plBinary: PlBinarySource;\n spawnOptions: SpawnOptions;\n closeOld: boolean;\n } = {\n plBinary: newDefaultPlBinarySource(),\n spawnOptions: {\n env: {\n GOMAXPROCS: String(numCpu),\n },\n },\n closeOld: true,\n };\n\n if (ops.spawnOptions?.env) {\n result.spawnOptions.env = { ...result.spawnOptions.env, ...ops.spawnOptions.env };\n }\n\n if (ops.spawnOptions) {\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.spawnOptions = { ...result.spawnOptions, ...withoutEnv };\n }\n\n const withoutSpawnOps = { ...ops };\n delete withoutSpawnOps[\"spawnOptions\"];\n\n return { ...result, ...withoutSpawnOps };\n}\n\n/** Gets default options for a platforma local binary\n * and overrides them with the provided options. */\nexport function plProcessOps(\n binaryPath: any,\n configPath: string,\n ops: LocalPlOptionsFull,\n workDir: string,\n defaultEnv: Record<string, string | undefined>,\n): ProcessOptions {\n const result: ProcessOptions = {\n cmd: binaryPath,\n args: [\"--config\", configPath],\n opts: {\n env: { ...defaultEnv },\n cwd: workDir,\n stdio: [\"pipe\", \"ignore\", \"inherit\"],\n windowsHide: true, // hide a terminal on Windows\n },\n };\n\n if (ops.spawnOptions?.env) {\n result.opts.env = { ...result.opts.env, ...ops.spawnOptions.env };\n }\n\n const withoutEnv = { ...ops.spawnOptions };\n delete withoutEnv[\"env\"];\n result.opts = { ...result.opts, ...withoutEnv };\n\n return result;\n}\n"],"names":["withTrace","processRun","filePid","notEmpty","writePid","processStop","processWaitStopped","isProcessAlive","os","resolveLocalPlBinaryPath","defaultHttpDispatcher","parseHttpAuth","readPid","newDefaultPlBinarySource"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAM,eAAe,GAAG;AAE/B;;;;AAIG;MACU,OAAO,CAAA;AAQC,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA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E,GAAG,UAAU,EAAE;IACjE;AAEA,IAAA,MAAM,eAAe,GAAG,EAAE,GAAG,GAAG,EAAE;AAClC,IAAA,OAAO,eAAe,CAAC,cAAc,CAAC;AAEtC,IAAA,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,eAAe,EAAE;AAC1C;AAEA;AACmD;AAC7C,SAAU,YAAY,CAC1B,UAAe,EACf,UAAkB,EAClB,GAAuB,EACvB,OAAe,EACf,UAA8C,EAAA;AAE9C,IAAA,MAAM,MAAM,GAAmB;AAC7B,QAAA,GAAG,EAAE,UAAU;AACf,QAAA,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;AAC9B,QAAA,IAAI,EAAE;AACJ,YAAA,GAAG,EAAE,EAAE,GAAG,UAAU,EAAE;AACtB,YAAA,GAAG,EAAE,OAAO;AACZ,YAAA,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC;YACpC,WAAW,EAAE,IAAI;AAClB,SAAA;KACF;AAED,IAAA,IAAI,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE;IACnE;IAEA,MAAM,UAAU,GAAG,EAAE,GAAG,GAAG,CAAC,YAAY,EAAE;AAC1C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC;AACxB,IAAA,MAAM,CAAC,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,UAAU,EAAE;AAE/C,IAAA,OAAO,MAAM;AACf;;;;;;;;"}
|
package/dist/local/pl.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ProcessOptions } from
|
|
2
|
-
import type { PlBinarySource } from
|
|
3
|
-
import type { MiLogger } from
|
|
4
|
-
import type { SpawnOptions } from
|
|
5
|
-
import type { Trace } from
|
|
6
|
-
import type { Required } from
|
|
7
|
-
import type { ProxySettings } from
|
|
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
8
|
export declare const LocalConfigYaml = "config-local.yaml";
|
|
9
9
|
/**
|
|
10
10
|
* Represents a local running pl-core,
|
|
@@ -67,7 +67,7 @@ export type LocalPlOptions = {
|
|
|
67
67
|
readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;
|
|
68
68
|
readonly onCloseAndErrorNoStop?: (pl: LocalPl) => Promise<void>;
|
|
69
69
|
};
|
|
70
|
-
export type LocalPlOptionsFull = Required<LocalPlOptions,
|
|
70
|
+
export type LocalPlOptionsFull = Required<LocalPlOptions, "plBinary" | "spawnOptions" | "closeOld">;
|
|
71
71
|
/**
|
|
72
72
|
* Starts pl-core, if the option was provided downloads a binary, reads license environments etc.
|
|
73
73
|
*/
|
package/dist/local/pl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.d.ts","sourceRoot":"","sources":["../../src/local/pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"pl.d.ts","sourceRoot":"","sources":["../../src/local/pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,oBAAoB,CAAC;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