@milaboratories/pl-deployments 2.8.2 → 2.9.0

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.
@@ -10,11 +10,19 @@ var os_and_arch = require('./os_and_arch.cjs');
10
10
  function newDefaultPlBinarySource() {
11
11
  return { type: 'Download', version: pl_version.getDefaultPlVersion() };
12
12
  }
13
- async function resolveLocalPlBinaryPath(logger, downloadDir, src) {
13
+ async function resolveLocalPlBinaryPath({ logger, downloadDir, src, dispatcher }) {
14
14
  switch (src.type) {
15
15
  case 'Download':
16
16
  // eslint-disable-next-line no-case-declarations
17
- const ops = await pl_binary_download.downloadBinary(logger, downloadDir, 'pl', `pl-${src.version}`, os.arch(), os.platform());
17
+ const ops = await pl_binary_download.downloadBinary({
18
+ logger,
19
+ baseDir: downloadDir,
20
+ softwareName: 'pl',
21
+ archiveName: `pl-${src.version}`,
22
+ arch: os.arch(),
23
+ platform: os.platform(),
24
+ dispatcher,
25
+ });
18
26
  return upath.join(ops.baseName, 'binaries', osToBinaryName[os_and_arch.newOs(os.platform())]);
19
27
  case 'Local':
20
28
  return src.path;
@@ -1 +1 @@
1
- {"version":3,"file":"pl_binary.cjs","sources":["../../src/common/pl_binary.ts"],"sourcesContent":["import type { MiLogger } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport { downloadBinary } from './pl_binary_download';\nimport { getDefaultPlVersion } from './pl_version';\nimport os from 'node:os';\nimport upath from 'upath';\nimport type { OSType } from './os_and_arch';\nimport { newOs } from './os_and_arch';\n\n/** Shows how the binary should be got. */\nexport type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;\n\nexport type PlBinarySourceDownload = {\n readonly type: 'Download';\n readonly version: string;\n};\n\nexport type PlBinarySourceLocal = {\n readonly type: 'Local';\n readonly path: string;\n};\n\nexport function newDefaultPlBinarySource(): PlBinarySourceDownload {\n return { type: 'Download', version: getDefaultPlVersion() };\n}\n\nexport async function resolveLocalPlBinaryPath(\n logger: MiLogger,\n downloadDir: string,\n src: PlBinarySource,\n): Promise<string> {\n switch (src.type) {\n case 'Download':\n // eslint-disable-next-line no-case-declarations\n const ops = await downloadBinary(logger, downloadDir, 'pl', `pl-${src.version}`, os.arch(), os.platform());\n return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os.platform())]);\n\n case 'Local':\n return src.path;\n\n default:\n assertNever(src);\n }\n}\n\nexport const osToBinaryName: Record<OSType, string> = {\n linux: 'platforma',\n macos: 'platforma',\n windows: 'platforma.exe',\n};\n"],"names":["getDefaultPlVersion","downloadBinary","newOs","assertNever"],"mappings":";;;;;;;;;SAsBgB,wBAAwB,GAAA;IACtC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAEA,8BAAmB,EAAE,EAAE;AAC7D;AAEO,eAAe,wBAAwB,CAC5C,MAAgB,EAChB,WAAmB,EACnB,GAAmB,EAAA;AAEnB,IAAA,QAAQ,GAAG,CAAC,IAAI;AACd,QAAA,KAAK,UAAU;;YAEb,MAAM,GAAG,GAAG,MAAMC,iCAAc,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA,GAAA,EAAM,GAAG,CAAC,OAAO,CAAA,CAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC;YAC1G,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,cAAc,CAACC,iBAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAEnF,QAAA,KAAK,OAAO;YACV,OAAO,GAAG,CAAC,IAAI;AAEjB,QAAA;YACEC,qBAAW,CAAC,GAAG,CAAC;;AAEtB;AAEO,MAAM,cAAc,GAA2B;AACpD,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,OAAO,EAAE,eAAe;;;;;;;"}
1
+ {"version":3,"file":"pl_binary.cjs","sources":["../../src/common/pl_binary.ts"],"sourcesContent":["import type { MiLogger } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport { downloadBinary } from './pl_binary_download';\nimport { getDefaultPlVersion } from './pl_version';\nimport os from 'node:os';\nimport upath from 'upath';\nimport type { OSType } from './os_and_arch';\nimport { newOs } from './os_and_arch';\nimport type { Dispatcher } from 'undici';\n\n/** Shows how the binary should be got. */\nexport type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;\n\nexport type PlBinarySourceDownload = {\n readonly type: 'Download';\n readonly version: string;\n};\n\nexport type PlBinarySourceLocal = {\n readonly type: 'Local';\n readonly path: string;\n};\n\nexport function newDefaultPlBinarySource(): PlBinarySourceDownload {\n return { type: 'Download', version: getDefaultPlVersion() };\n}\n\nexport async function resolveLocalPlBinaryPath(\n { logger, downloadDir, src, dispatcher }: {\n logger: MiLogger;\n downloadDir: string;\n src: PlBinarySource;\n dispatcher?: Dispatcher;\n },\n): Promise<string> {\n switch (src.type) {\n case 'Download':\n // eslint-disable-next-line no-case-declarations\n const ops = await downloadBinary({\n logger,\n baseDir: downloadDir,\n softwareName: 'pl',\n archiveName: `pl-${src.version}`,\n arch: os.arch(),\n platform: os.platform(),\n dispatcher,\n });\n return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os.platform())]);\n\n case 'Local':\n return src.path;\n\n default:\n assertNever(src);\n }\n}\n\nexport const osToBinaryName: Record<OSType, string> = {\n linux: 'platforma',\n macos: 'platforma',\n windows: 'platforma.exe',\n};\n"],"names":["getDefaultPlVersion","downloadBinary","newOs","assertNever"],"mappings":";;;;;;;;;SAuBgB,wBAAwB,GAAA;IACtC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAEA,8BAAmB,EAAE,EAAE;AAC7D;AAEO,eAAe,wBAAwB,CAC5C,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAKrC,EAAA;AAED,IAAA,QAAQ,GAAG,CAAC,IAAI;AACd,QAAA,KAAK,UAAU;;AAEb,YAAA,MAAM,GAAG,GAAG,MAAMC,iCAAc,CAAC;gBAC/B,MAAM;AACN,gBAAA,OAAO,EAAE,WAAW;AACpB,gBAAA,YAAY,EAAE,IAAI;AAClB,gBAAA,WAAW,EAAE,CAAA,GAAA,EAAM,GAAG,CAAC,OAAO,CAAA,CAAE;AAChC,gBAAA,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE;AACf,gBAAA,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE;gBACvB,UAAU;AACX,aAAA,CAAC;YACF,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,cAAc,CAACC,iBAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAEnF,QAAA,KAAK,OAAO;YACV,OAAO,GAAG,CAAC,IAAI;AAEjB,QAAA;YACEC,qBAAW,CAAC,GAAG,CAAC;;AAEtB;AAEO,MAAM,cAAc,GAA2B;AACpD,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,OAAO,EAAE,eAAe;;;;;;;"}
@@ -1,5 +1,6 @@
1
1
  import type { MiLogger } from '@milaboratories/ts-helpers';
2
2
  import type { OSType } from './os_and_arch';
3
+ import type { Dispatcher } from 'undici';
3
4
  /** Shows how the binary should be got. */
4
5
  export type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;
5
6
  export type PlBinarySourceDownload = {
@@ -11,6 +12,11 @@ export type PlBinarySourceLocal = {
11
12
  readonly path: string;
12
13
  };
13
14
  export declare function newDefaultPlBinarySource(): PlBinarySourceDownload;
14
- export declare function resolveLocalPlBinaryPath(logger: MiLogger, downloadDir: string, src: PlBinarySource): Promise<string>;
15
+ export declare function resolveLocalPlBinaryPath({ logger, downloadDir, src, dispatcher }: {
16
+ logger: MiLogger;
17
+ downloadDir: string;
18
+ src: PlBinarySource;
19
+ dispatcher?: Dispatcher;
20
+ }): Promise<string>;
15
21
  export declare const osToBinaryName: Record<OSType, string>;
16
22
  //# sourceMappingURL=pl_binary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pl_binary.d.ts","sourceRoot":"","sources":["../../src/common/pl_binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAM3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,mBAAmB,CAAC;AAE1E,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,wBAAwB,IAAI,sBAAsB,CAEjE;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,MAAM,CAAC,CAajB;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjD,CAAC"}
1
+ {"version":3,"file":"pl_binary.d.ts","sourceRoot":"","sources":["../../src/common/pl_binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAM3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,mBAAmB,CAAC;AAE1E,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,wBAAwB,IAAI,sBAAsB,CAEjE;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE;IACxC,MAAM,EAAE,QAAQ,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,cAAc,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,GACA,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjD,CAAC"}
@@ -8,11 +8,19 @@ import { newOs } from './os_and_arch.js';
8
8
  function newDefaultPlBinarySource() {
9
9
  return { type: 'Download', version: getDefaultPlVersion() };
10
10
  }
11
- async function resolveLocalPlBinaryPath(logger, downloadDir, src) {
11
+ async function resolveLocalPlBinaryPath({ logger, downloadDir, src, dispatcher }) {
12
12
  switch (src.type) {
13
13
  case 'Download':
14
14
  // eslint-disable-next-line no-case-declarations
15
- const ops = await downloadBinary(logger, downloadDir, 'pl', `pl-${src.version}`, os__default.arch(), os__default.platform());
15
+ const ops = await downloadBinary({
16
+ logger,
17
+ baseDir: downloadDir,
18
+ softwareName: 'pl',
19
+ archiveName: `pl-${src.version}`,
20
+ arch: os__default.arch(),
21
+ platform: os__default.platform(),
22
+ dispatcher,
23
+ });
16
24
  return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os__default.platform())]);
17
25
  case 'Local':
18
26
  return src.path;
@@ -1 +1 @@
1
- {"version":3,"file":"pl_binary.js","sources":["../../src/common/pl_binary.ts"],"sourcesContent":["import type { MiLogger } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport { downloadBinary } from './pl_binary_download';\nimport { getDefaultPlVersion } from './pl_version';\nimport os from 'node:os';\nimport upath from 'upath';\nimport type { OSType } from './os_and_arch';\nimport { newOs } from './os_and_arch';\n\n/** Shows how the binary should be got. */\nexport type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;\n\nexport type PlBinarySourceDownload = {\n readonly type: 'Download';\n readonly version: string;\n};\n\nexport type PlBinarySourceLocal = {\n readonly type: 'Local';\n readonly path: string;\n};\n\nexport function newDefaultPlBinarySource(): PlBinarySourceDownload {\n return { type: 'Download', version: getDefaultPlVersion() };\n}\n\nexport async function resolveLocalPlBinaryPath(\n logger: MiLogger,\n downloadDir: string,\n src: PlBinarySource,\n): Promise<string> {\n switch (src.type) {\n case 'Download':\n // eslint-disable-next-line no-case-declarations\n const ops = await downloadBinary(logger, downloadDir, 'pl', `pl-${src.version}`, os.arch(), os.platform());\n return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os.platform())]);\n\n case 'Local':\n return src.path;\n\n default:\n assertNever(src);\n }\n}\n\nexport const osToBinaryName: Record<OSType, string> = {\n linux: 'platforma',\n macos: 'platforma',\n windows: 'platforma.exe',\n};\n"],"names":["os"],"mappings":";;;;;;;SAsBgB,wBAAwB,GAAA;IACtC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE;AAC7D;AAEO,eAAe,wBAAwB,CAC5C,MAAgB,EAChB,WAAmB,EACnB,GAAmB,EAAA;AAEnB,IAAA,QAAQ,GAAG,CAAC,IAAI;AACd,QAAA,KAAK,UAAU;;YAEb,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA,GAAA,EAAM,GAAG,CAAC,OAAO,CAAA,CAAE,EAAEA,WAAE,CAAC,IAAI,EAAE,EAAEA,WAAE,CAAC,QAAQ,EAAE,CAAC;YAC1G,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAACA,WAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAEnF,QAAA,KAAK,OAAO;YACV,OAAO,GAAG,CAAC,IAAI;AAEjB,QAAA;YACE,WAAW,CAAC,GAAG,CAAC;;AAEtB;AAEO,MAAM,cAAc,GAA2B;AACpD,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,OAAO,EAAE,eAAe;;;;;"}
1
+ {"version":3,"file":"pl_binary.js","sources":["../../src/common/pl_binary.ts"],"sourcesContent":["import type { MiLogger } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport { downloadBinary } from './pl_binary_download';\nimport { getDefaultPlVersion } from './pl_version';\nimport os from 'node:os';\nimport upath from 'upath';\nimport type { OSType } from './os_and_arch';\nimport { newOs } from './os_and_arch';\nimport type { Dispatcher } from 'undici';\n\n/** Shows how the binary should be got. */\nexport type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;\n\nexport type PlBinarySourceDownload = {\n readonly type: 'Download';\n readonly version: string;\n};\n\nexport type PlBinarySourceLocal = {\n readonly type: 'Local';\n readonly path: string;\n};\n\nexport function newDefaultPlBinarySource(): PlBinarySourceDownload {\n return { type: 'Download', version: getDefaultPlVersion() };\n}\n\nexport async function resolveLocalPlBinaryPath(\n { logger, downloadDir, src, dispatcher }: {\n logger: MiLogger;\n downloadDir: string;\n src: PlBinarySource;\n dispatcher?: Dispatcher;\n },\n): Promise<string> {\n switch (src.type) {\n case 'Download':\n // eslint-disable-next-line no-case-declarations\n const ops = await downloadBinary({\n logger,\n baseDir: downloadDir,\n softwareName: 'pl',\n archiveName: `pl-${src.version}`,\n arch: os.arch(),\n platform: os.platform(),\n dispatcher,\n });\n return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os.platform())]);\n\n case 'Local':\n return src.path;\n\n default:\n assertNever(src);\n }\n}\n\nexport const osToBinaryName: Record<OSType, string> = {\n linux: 'platforma',\n macos: 'platforma',\n windows: 'platforma.exe',\n};\n"],"names":["os"],"mappings":";;;;;;;SAuBgB,wBAAwB,GAAA;IACtC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE;AAC7D;AAEO,eAAe,wBAAwB,CAC5C,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAKrC,EAAA;AAED,IAAA,QAAQ,GAAG,CAAC,IAAI;AACd,QAAA,KAAK,UAAU;;AAEb,YAAA,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC;gBAC/B,MAAM;AACN,gBAAA,OAAO,EAAE,WAAW;AACpB,gBAAA,YAAY,EAAE,IAAI;AAClB,gBAAA,WAAW,EAAE,CAAA,GAAA,EAAM,GAAG,CAAC,OAAO,CAAA,CAAE;AAChC,gBAAA,IAAI,EAAEA,WAAE,CAAC,IAAI,EAAE;AACf,gBAAA,QAAQ,EAAEA,WAAE,CAAC,QAAQ,EAAE;gBACvB,UAAU;AACX,aAAA,CAAC;YACF,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAACA,WAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAEnF,QAAA,KAAK,OAAO;YACV,OAAO,GAAG,CAAC,IAAI;AAEjB,QAAA;YACE,WAAW,CAAC,GAAG,CAAC;;AAEtB;AAEO,MAAM,cAAc,GAA2B;AACpD,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,OAAO,EAAE,eAAe;;;;;"}
@@ -34,28 +34,28 @@ const cdn = 'https://cdn.platforma.bio/software';
34
34
  // We'll download things from Global Access if downloading from CDN has failed
35
35
  // (it might be that it's blocked from the company's network.)
36
36
  const gaCdn = 'https://cdn-ga.pl-open.science/software';
37
- async function downloadBinaryNoExtract(logger, baseDir, softwareName, tgzName, arch, platform) {
37
+ async function downloadBinaryNoExtract({ logger, baseDir, softwareName, tgzName, arch, platform, dispatcher }) {
38
38
  const opts = getPathsForDownload(softwareName, tgzName, baseDir, os_and_arch.newArch(arch), os_and_arch.newOs(platform));
39
39
  const { archiveUrl, alternativeArchiveGAUrl, archivePath } = opts;
40
40
  try {
41
- await downloadArchive(logger, archiveUrl, archivePath);
41
+ await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
42
42
  opts.wasDownloadedFrom = archiveUrl;
43
43
  }
44
44
  catch (_e) {
45
- await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
45
+ await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });
46
46
  opts.wasDownloadedFrom = alternativeArchiveGAUrl;
47
47
  }
48
48
  return opts;
49
49
  }
50
- async function downloadBinary(logger, baseDir, softwareName, archiveName, arch, platform) {
50
+ async function downloadBinary({ logger, baseDir, softwareName, archiveName, arch, platform, dispatcher }) {
51
51
  const opts = getPathsForDownload(softwareName, archiveName, baseDir, os_and_arch.newArch(arch), os_and_arch.newOs(platform));
52
52
  const { archiveUrl, alternativeArchiveGAUrl, archivePath, archiveType, targetFolder } = opts;
53
53
  try {
54
- await downloadArchive(logger, archiveUrl, archivePath);
54
+ await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
55
55
  opts.wasDownloadedFrom = archiveUrl;
56
56
  }
57
57
  catch (_e) {
58
- await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
58
+ await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });
59
59
  opts.wasDownloadedFrom = alternativeArchiveGAUrl;
60
60
  }
61
61
  await extractArchive(logger, archivePath, archiveType, targetFolder);
@@ -79,19 +79,19 @@ function getPathsForDownload(softwareName, archiveName, baseDir, arch, os) {
79
79
  baseName,
80
80
  };
81
81
  }
82
- async function downloadArchive(logger, archiveUrl, dstArchiveFile) {
82
+ async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher }) {
83
83
  const state = {};
84
- state.dstArchive = dstArchiveFile;
84
+ state.archivePath = archivePath;
85
85
  try {
86
- state.fileExisted = await tsHelpers.fileExists(dstArchiveFile);
86
+ state.fileExisted = await tsHelpers.fileExists(archivePath);
87
87
  if (state.fileExisted) {
88
- logger.info(`Platforma Backend archive download skipped: '${dstArchiveFile}' already exists`);
88
+ logger.info(`Platforma Backend archive download skipped: '${archivePath}' already exists`);
89
89
  return state;
90
90
  }
91
- await fsp.mkdir(upath.dirname(dstArchiveFile), { recursive: true });
91
+ await fsp.mkdir(upath.dirname(archivePath), { recursive: true });
92
92
  state.dirnameCreated = true;
93
- logger.info(`Downloading archive:\n URL: ${archiveUrl}\n Save to: ${dstArchiveFile}`);
94
- const { body, statusCode } = await undici.request(archiveUrl);
93
+ logger.info(`Downloading archive:\n URL: ${archiveUrl}\n Save to: ${archivePath}`);
94
+ const { body, statusCode } = await undici.request(archiveUrl, { dispatcher });
95
95
  state.statusCode = statusCode;
96
96
  if (statusCode != 200) {
97
97
  // completely draining the stream to prevent leaving open connections
@@ -101,15 +101,15 @@ async function downloadArchive(logger, archiveUrl, dstArchiveFile) {
101
101
  throw new Error(state.errorMsg);
102
102
  }
103
103
  // to prevent incomplete downloads we first write in a temp file
104
- state.tmpPath = dstArchiveFile + '.tmp';
104
+ state.tmpPath = archivePath + '.tmp';
105
105
  // eslint-disable-next-line n/no-unsupported-features/node-builtins
106
106
  await node_stream.Readable.toWeb(body).pipeTo(node_stream.Writable.toWeb(fs.createWriteStream(state.tmpPath)));
107
107
  state.wroteTmp = true;
108
108
  state.tmpExisted = await tsHelpers.fileExists(state.tmpPath);
109
109
  // and then atomically rename it
110
- await fsp.rename(state.tmpPath, dstArchiveFile);
110
+ await fsp.rename(state.tmpPath, archivePath);
111
111
  state.renamed = true;
112
- state.newExisted = await tsHelpers.fileExists(dstArchiveFile);
112
+ state.newExisted = await tsHelpers.fileExists(archivePath);
113
113
  return state;
114
114
  }
115
115
  catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"pl_binary_download.cjs","sources":["../../src/common/pl_binary_download.ts"],"sourcesContent":["import fs from 'node:fs';\nimport fsp from 'node:fs/promises';\nimport upath from 'upath';\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: MiLogger,\n baseDir: string,\n softwareName: string,\n tgzName: string,\n arch: string,\n platform: string,\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);\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n return opts;\n}\n\nexport async function downloadBinary(\n logger: MiLogger,\n baseDir: string,\n softwareName: string,\n archiveName: string,\n arch: string,\n platform: string,\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);\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);\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 dstArchive?: 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: MiLogger, archiveUrl: string, dstArchiveFile: string,\n): Promise<DownloadInfo> {\n const state: DownloadInfo = {};\n state.dstArchive = dstArchiveFile;\n\n try {\n state.fileExisted = await fileExists(dstArchiveFile);\n if (state.fileExisted) {\n logger.info(`Platforma Backend archive download skipped: '${dstArchiveFile}' already exists`);\n return state;\n }\n\n await fsp.mkdir(upath.dirname(dstArchiveFile), { recursive: true });\n state.dirnameCreated = true;\n\n logger.info(`Downloading archive:\\n URL: ${archiveUrl}\\n Save to: ${dstArchiveFile}`);\n\n const { body, statusCode } = await request(archiveUrl);\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 = dstArchiveFile + '.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, dstArchiveFile);\n state.renamed = true;\n state.newExisted = await fileExists(dstArchiveFile);\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":["newArch","newOs","fileExists","request","text","Readable","Writable","tar","assertNever"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,GAAG,GAAG,oCAAoC;AAChD;AACA;AACA,MAAM,KAAK,GAAG,yCAAyC;AAYhD,eAAe,uBAAuB,CAC3C,MAAgB,EAChB,OAAe,EACf,YAAoB,EACpB,OAAe,EACf,IAAY,EACZ,QAAgB,EAAA;IAEhB,MAAM,IAAI,GAAG,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAEA,mBAAO,CAAC,IAAI,CAAC,EAAEC,iBAAK,CAAC,QAAQ,CAAC,CAAC;IAChG,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,GAAG,IAAI;AAEjE,IAAA,IAAI;QACF,MAAM,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC;AACtD,QAAA,IAAI,CAAC,iBAAiB,GAAG,UAAU;IACrC;IAAE,OAAO,EAAE,EAAE;QACX,MAAM,eAAe,CAAC,MAAM,EAAE,uBAAuB,EAAE,WAAW,CAAC;AACnE,QAAA,IAAI,CAAC,iBAAiB,GAAG,uBAAuB;IAClD;AAEA,IAAA,OAAO,IAAI;AACb;AAEO,eAAe,cAAc,CAClC,MAAgB,EAChB,OAAe,EACf,YAAoB,EACpB,WAAmB,EACnB,IAAY,EACZ,QAAgB,EAAA;IAE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;;;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.cjs","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":["newArch","newOs","fileExists","request","text","Readable","Writable","tar","assertNever"],"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,EAAEA,mBAAO,CAAC,IAAI,CAAC,EAAEC,iBAAK,CAAC,QAAQ,CAAC,CAAC;IAChG,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,GAAG,IAAI;AAEjE,IAAA,IAAI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E,CAAC;IAC9C;AAEA,IAAA,MAAM,CAAC,IAAI,CAAC,0BAA0B,SAAS,CAAA,CAAA,CAAG,CAAC;AACnD,IAAA,MAAM,GAAG,CAAC,KAAK,CAAC,SAAS,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,MAAMK,cAAG,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;YACEC,qBAAW,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,3 +1,4 @@
1
+ import type { Dispatcher } from 'undici';
1
2
  import type { MiLogger } from '@milaboratories/ts-helpers';
2
3
  export type DownloadBinaryResult = {
3
4
  archiveUrl: string;
@@ -8,10 +9,26 @@ export type DownloadBinaryResult = {
8
9
  targetFolder: string;
9
10
  baseName: string;
10
11
  };
11
- export declare function downloadBinaryNoExtract(logger: MiLogger, baseDir: string, softwareName: string, tgzName: string, arch: string, platform: string): Promise<DownloadBinaryResult>;
12
- export declare function downloadBinary(logger: MiLogger, baseDir: string, softwareName: string, archiveName: string, arch: string, platform: string): Promise<DownloadBinaryResult>;
12
+ export declare function downloadBinaryNoExtract({ logger, baseDir, softwareName, tgzName, arch, platform, dispatcher }: {
13
+ logger: MiLogger;
14
+ baseDir: string;
15
+ softwareName: string;
16
+ tgzName: string;
17
+ arch: string;
18
+ platform: string;
19
+ dispatcher?: Dispatcher;
20
+ }): Promise<DownloadBinaryResult>;
21
+ export declare function downloadBinary({ logger, baseDir, softwareName, archiveName, arch, platform, dispatcher }: {
22
+ logger: MiLogger;
23
+ baseDir: string;
24
+ softwareName: string;
25
+ archiveName: string;
26
+ arch: string;
27
+ platform: string;
28
+ dispatcher?: Dispatcher;
29
+ }): Promise<DownloadBinaryResult>;
13
30
  export type DownloadInfo = {
14
- dstArchive?: string;
31
+ archivePath?: string;
15
32
  fileExisted?: boolean;
16
33
  dirnameCreated?: boolean;
17
34
  statusCode?: number;
@@ -22,7 +39,12 @@ export type DownloadInfo = {
22
39
  renamed?: boolean;
23
40
  newExisted?: boolean;
24
41
  };
25
- export declare function downloadArchive(logger: MiLogger, archiveUrl: string, dstArchiveFile: string): Promise<DownloadInfo>;
42
+ export declare function downloadArchive({ logger, archiveUrl, archivePath, dispatcher }: {
43
+ logger: MiLogger;
44
+ archiveUrl: string;
45
+ archivePath: string;
46
+ dispatcher?: Dispatcher;
47
+ }): Promise<DownloadInfo>;
26
48
  export declare function extractArchive(logger: MiLogger, archivePath: string, archiveType: ArchiveType, dstFolder: string): Promise<void>;
27
49
  export type ArchiveType = 'tgz' | 'zip';
28
50
  //# sourceMappingURL=pl_binary_download.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pl_binary_download.d.ts","sourceRoot":"","sources":["../../src/common/pl_binary_download.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAW3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB,EAAE,MAAM,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,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U,CAAC;CACzB,GACA,OAAO,CAAC,oBAAoB,CAAC,CAe/B;AA6BD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wBAAsB,eAAe,CACnC,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE;IAC/C,MAAM,EAAE,QAAQ,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,GACA,OAAO,CAAC,YAAY,CAAC,CA4CvB;AAKD,wBAAsB,cAAc,CAClC,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,iBAoDlB;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,CAAC"}
@@ -13,28 +13,28 @@ 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
15
  const gaCdn = 'https://cdn-ga.pl-open.science/software';
16
- async function downloadBinaryNoExtract(logger, baseDir, softwareName, tgzName, arch, platform) {
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
- await downloadArchive(logger, archiveUrl, archivePath);
20
+ await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
21
21
  opts.wasDownloadedFrom = archiveUrl;
22
22
  }
23
23
  catch (_e) {
24
- await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
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) {
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
- await downloadArchive(logger, archiveUrl, archivePath);
33
+ await downloadArchive({ logger, archiveUrl, archivePath, dispatcher });
34
34
  opts.wasDownloadedFrom = archiveUrl;
35
35
  }
36
36
  catch (_e) {
37
- await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
37
+ await downloadArchive({ logger, archiveUrl: alternativeArchiveGAUrl, archivePath, dispatcher });
38
38
  opts.wasDownloadedFrom = alternativeArchiveGAUrl;
39
39
  }
40
40
  await extractArchive(logger, archivePath, archiveType, targetFolder);
@@ -58,19 +58,19 @@ function getPathsForDownload(softwareName, archiveName, baseDir, arch, os) {
58
58
  baseName,
59
59
  };
60
60
  }
61
- async function downloadArchive(logger, archiveUrl, dstArchiveFile) {
61
+ async function downloadArchive({ logger, archiveUrl, archivePath, dispatcher }) {
62
62
  const state = {};
63
- state.dstArchive = dstArchiveFile;
63
+ state.archivePath = archivePath;
64
64
  try {
65
- state.fileExisted = await fileExists(dstArchiveFile);
65
+ state.fileExisted = await fileExists(archivePath);
66
66
  if (state.fileExisted) {
67
- logger.info(`Platforma Backend archive download skipped: '${dstArchiveFile}' already exists`);
67
+ logger.info(`Platforma Backend archive download skipped: '${archivePath}' already exists`);
68
68
  return state;
69
69
  }
70
- await fsp.mkdir(upath.dirname(dstArchiveFile), { recursive: true });
70
+ await fsp.mkdir(upath.dirname(archivePath), { recursive: true });
71
71
  state.dirnameCreated = true;
72
- logger.info(`Downloading archive:\n URL: ${archiveUrl}\n Save to: ${dstArchiveFile}`);
73
- const { body, statusCode } = await request(archiveUrl);
72
+ logger.info(`Downloading archive:\n URL: ${archiveUrl}\n Save to: ${archivePath}`);
73
+ const { body, statusCode } = await request(archiveUrl, { dispatcher });
74
74
  state.statusCode = statusCode;
75
75
  if (statusCode != 200) {
76
76
  // completely draining the stream to prevent leaving open connections
@@ -80,15 +80,15 @@ async function downloadArchive(logger, archiveUrl, dstArchiveFile) {
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 = dstArchiveFile + '.tmp';
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;
87
87
  state.tmpExisted = await fileExists(state.tmpPath);
88
88
  // and then atomically rename it
89
- await fsp.rename(state.tmpPath, dstArchiveFile);
89
+ await fsp.rename(state.tmpPath, archivePath);
90
90
  state.renamed = true;
91
- state.newExisted = await fileExists(dstArchiveFile);
91
+ state.newExisted = await fileExists(archivePath);
92
92
  return state;
93
93
  }
94
94
  catch (e) {
@@ -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 { 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: MiLogger,\n baseDir: string,\n softwareName: string,\n tgzName: string,\n arch: string,\n platform: string,\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);\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);\n opts.wasDownloadedFrom = alternativeArchiveGAUrl;\n }\n\n return opts;\n}\n\nexport async function downloadBinary(\n logger: MiLogger,\n baseDir: string,\n softwareName: string,\n archiveName: string,\n arch: string,\n platform: string,\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);\n opts.wasDownloadedFrom = archiveUrl;\n } catch (_e) {\n await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);\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 dstArchive?: 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: MiLogger, archiveUrl: string, dstArchiveFile: string,\n): Promise<DownloadInfo> {\n const state: DownloadInfo = {};\n state.dstArchive = dstArchiveFile;\n\n try {\n state.fileExisted = await fileExists(dstArchiveFile);\n if (state.fileExisted) {\n logger.info(`Platforma Backend archive download skipped: '${dstArchiveFile}' already exists`);\n return state;\n }\n\n await fsp.mkdir(upath.dirname(dstArchiveFile), { recursive: true });\n state.dirnameCreated = true;\n\n logger.info(`Downloading archive:\\n URL: ${archiveUrl}\\n Save to: ${dstArchiveFile}`);\n\n const { body, statusCode } = await request(archiveUrl);\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 = dstArchiveFile + '.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, dstArchiveFile);\n state.renamed = true;\n state.newExisted = await fileExists(dstArchiveFile);\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":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AC,SAAS,CAAC,EAAE;AAC/B,QAAA,MAAM,CAAC,IAAI,CAAC,oDAAoD,SAAS,CAAA,CAAA,CAAG,CAAC;AAC7E,QAAA,MAAM,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC9C;AAEA,IAAA,MAAM,CAAC,IAAI,CAAC,0BAA0B,SAAS,CAAA,CAAA,CAAG,CAAC;AACnD,IAAA,MAAM,GAAG,CAAC,KAAK,CAAC,SAAS,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, 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,CAAC,iBAAiB,GAAG,UAAU;IACrC;IAAE,OAAO,EAAE,EAAE;AACX,QAAA,MAAM,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AAC/F,QAAA,IAAI,CAAC,iBAAiB,GAAG,uBAAuB;IAClD;AAEA,IAAA,OAAO,IAAI;AACb;AAEO,eAAe,cAAc,CAClC,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAQvE,EAAA;IAED,MAAM,IAAI,GAAG,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAA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F,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;;;;"}
package/dist/local/pl.cjs CHANGED
@@ -8,6 +8,8 @@ var trace = require('./trace.cjs');
8
8
  var upath = require('upath');
9
9
  var fsp = require('node:fs/promises');
10
10
  var os = require('node:os');
11
+ var plHttp = require('@milaboratories/pl-http');
12
+ var helpers = require('@milaboratories/helpers');
11
13
 
12
14
  function _interopNamespaceDefault(e) {
13
15
  var n = Object.create(null);
@@ -136,9 +138,30 @@ async function localPlatformaInit(logger, _ops) {
136
138
  logger.info(`writing configuration '${configPath}'...`);
137
139
  await fsp.writeFile(configPath, ops.config);
138
140
  const plBinPath = upath.join(workDir, 'binaries');
139
- const baseBinaryPath = await pl_binary.resolveLocalPlBinaryPath(logger, plBinPath, ops.plBinary);
141
+ const baseBinaryPath = await pl_binary.resolveLocalPlBinaryPath({
142
+ logger,
143
+ downloadDir: plBinPath,
144
+ src: ops.plBinary,
145
+ dispatcher: plHttp.defaultHttpDispatcher(ops.proxy),
146
+ });
140
147
  const binaryPath = trace('binaryPath', upath.join('binaries', baseBinaryPath));
141
- const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, process.env);
148
+ const env = { ...process.env };
149
+ if (ops.proxy?.url) {
150
+ const url = new URL(ops.proxy.url);
151
+ if (ops.proxy.auth) {
152
+ const parsed = helpers.parseHttpAuth(ops.proxy.auth);
153
+ if (parsed.scheme !== 'Basic') {
154
+ throw new Error(`\
155
+ Unsupported auth scheme: ${parsed.scheme}. \
156
+ Only Basic auth is supported by the backend.`);
157
+ }
158
+ url.username = parsed.username;
159
+ url.password = parsed.password;
160
+ }
161
+ env.http_proxy = url.toString();
162
+ env.https_proxy = url.toString();
163
+ }
164
+ const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, env);
142
165
  trace('processOpts', {
143
166
  cmd: processOpts.cmd,
144
167
  args: processOpts.args,
@@ -1 +1 @@
1
- {"version":3,"file":"pl.cjs","sources":["../../src/local/pl.ts"],"sourcesContent":["import type {\n 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';\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 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(logger, plBinPath, ops.plBinary);\n const binaryPath = trace('binaryPath', upath.join('binaries', baseBinaryPath));\n\n const processOpts = plProcessOps(binaryPath, configPath, ops, workDir, process.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","readPid","newDefaultPlBinarySource"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBO,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,CAAA,qBAAqB,GAArB,qBAAqB;IACrC;AAEH,IAAA,MAAM,KAAK,GAAA;AACT,QAAA,MAAMA,eAAS,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,KAAK,EAAE,CAAC,KAAI;AAC9C,YAAA,IAAI,CAAC,UAAU,GAAG,KAAK;AACvB,YAAA,MAAM,QAAQ,GAAGC,oBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC;YAC3D,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAM,KAAI;AAC9B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AQ,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;;;;;;;;"}
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/helpers';\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,qB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AE;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;;;;;;;;"}
@@ -4,6 +4,7 @@ import type { MiLogger } from '@milaboratories/ts-helpers';
4
4
  import type { SpawnOptions } from 'node:child_process';
5
5
  import type { Trace } from './trace';
6
6
  import type { Required } from 'utility-types';
7
+ import type { ProxySettings } from '@milaboratories/pl-http';
7
8
  export declare const LocalConfigYaml = "config-local.yaml";
8
9
  /**
9
10
  * Represents a local running pl-core,
@@ -55,6 +56,12 @@ export type LocalPlOptions = {
55
56
  * (default: true)
56
57
  */
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;
58
65
  readonly onClose?: (pl: LocalPl) => Promise<void>;
59
66
  readonly onError?: (pl: LocalPl) => Promise<void>;
60
67
  readonly onCloseAndError?: (pl: LocalPl) => Promise<void>;