@package-pal/cli 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ppal +39 -8
- package/package.json +1 -1
- package/src/lib/install/functions/link-existing-binary.js +2 -2
- package/src/lib/install/functions/load-missing-binary.js +3 -3
- package/src/lib/install/functions/prepare-binary.js +5 -8
- package/src/lib/install/functions/clear-placeholder-binary.js +0 -17
package/bin/ppal
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// Fallback, if post-install script did not execute.
|
|
4
|
-
//
|
|
4
|
+
// Adds more overhead due to launching a Node process which launches the CLI process.
|
|
5
5
|
|
|
6
6
|
import { getPathInfo } from '../src/lib/install/functions/get-path-info.js';
|
|
7
7
|
import { getPlatformInfo } from '../src/lib/install/functions/get-platform-info.js';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { existsSync, mkdirSync, rmSync } from 'fs';
|
|
10
|
+
import { loadMissingBinary } from '../src/lib/install/functions/load-missing-binary.js';
|
|
8
11
|
|
|
9
|
-
const {
|
|
10
|
-
platform, targetPackage,
|
|
11
|
-
} = getPlatformInfo();
|
|
12
|
-
const { targetBinPath } = getPathInfo({ platform, targetPackage });
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @param binPath {string}
|
|
15
|
+
*/
|
|
16
|
+
const exec = (binPath) => {
|
|
17
|
+
require('child_process').execFileSync(binPath, process.argv.slice(2), {
|
|
18
|
+
stdio: 'inherit',
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
const {
|
|
24
|
+
platform, targetPackage, outputBinDir
|
|
25
|
+
} = getPlatformInfo();
|
|
26
|
+
const { targetBinPath, binExecutableName } = getPathInfo({ platform, targetPackage });
|
|
27
|
+
const binarySourceDir = join(outputBinDir, 'source');
|
|
28
|
+
|
|
29
|
+
if (targetBinPath) {
|
|
30
|
+
rmSync(binarySourceDir, { force: true, recursive: true });
|
|
31
|
+
return exec(targetBinPath);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const prevDownloadedBinPath = join(binarySourceDir, binExecutableName);
|
|
35
|
+
if (!existsSync(prevDownloadedBinPath)) {
|
|
36
|
+
rmSync(binarySourceDir, { force: true, recursive: true });
|
|
37
|
+
mkdirSync(binarySourceDir, { recursive: true });
|
|
38
|
+
await loadMissingBinary({binExecutableName, targetPackage, outputBinDir: binarySourceDir});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exec(targetBinPath);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
main().catch((err) => {
|
|
45
|
+
console.error(err);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from 'fs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @param {{ platform: Bun.Platform,
|
|
6
|
+
* @param {{ platform: Bun.Platform, targetBinPath: string, outputBinPath: string }} options
|
|
7
7
|
*/
|
|
8
8
|
export const linkExistingBinary = ({
|
|
9
|
-
platform,
|
|
9
|
+
platform, targetBinPath, outputBinPath,
|
|
10
10
|
}) => {
|
|
11
11
|
const isWin = platform === 'win32';
|
|
12
12
|
|
|
@@ -5,7 +5,7 @@ import { pipeline } from 'stream/promises';
|
|
|
5
5
|
import { x } from 'tar';
|
|
6
6
|
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const maxAttempts = 5;
|
|
9
9
|
const initialBackoffMs = 500;
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -60,14 +60,14 @@ const tryDownloadAndExtract = (
|
|
|
60
60
|
const downloadAndExtract = async (
|
|
61
61
|
tarballUrl, binExecutableName, outputBinDir,
|
|
62
62
|
) => {
|
|
63
|
-
for (let attempt = 1; attempt <=
|
|
63
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
64
64
|
try {
|
|
65
65
|
await tryDownloadAndExtract(
|
|
66
66
|
tarballUrl, binExecutableName, outputBinDir,
|
|
67
67
|
);
|
|
68
68
|
return;
|
|
69
69
|
} catch (error) {
|
|
70
|
-
if (attempt <
|
|
70
|
+
if (attempt < maxAttempts) {
|
|
71
71
|
const delay = initialBackoffMs * 2 ** (attempt - 1);
|
|
72
72
|
console.warn(`Download failed (attempt ${attempt.toString()}), retrying in ${delay.toString()}ms...`);
|
|
73
73
|
} else {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
mkdirSync, rmSync,
|
|
3
|
+
} from 'fs';
|
|
3
4
|
import { linkExistingBinary } from './link-existing-binary.js';
|
|
4
5
|
import { loadMissingBinary } from './load-missing-binary.js';
|
|
5
6
|
|
|
@@ -9,19 +10,15 @@ import { loadMissingBinary } from './load-missing-binary.js';
|
|
|
9
10
|
export const prepareBinary = ({
|
|
10
11
|
platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinBasePath, outputBinPath,
|
|
11
12
|
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
outputBinBasePath,
|
|
15
|
-
});
|
|
13
|
+
rmSync(outputBinBasePath, { force: true });
|
|
14
|
+
rmSync(outputBinPath, { force: true });
|
|
16
15
|
mkdirSync(outputBinDir, { recursive: true });
|
|
17
16
|
|
|
18
17
|
if (targetBinPath) {
|
|
19
18
|
console.info(`Expected CLI binary package is available in '${targetBinPath}'.`);
|
|
20
19
|
linkExistingBinary({
|
|
21
20
|
platform,
|
|
22
|
-
binExecutableName,
|
|
23
21
|
targetBinPath,
|
|
24
|
-
outputBinBasePath,
|
|
25
22
|
outputBinPath,
|
|
26
23
|
});
|
|
27
24
|
return Promise.resolve();
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'fs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {{ platform: Bun.Platform, outputBinBasePath: string }} options
|
|
5
|
-
*/
|
|
6
|
-
export const clearPlaceholderBinary = ({
|
|
7
|
-
platform, outputBinBasePath,
|
|
8
|
-
}) => {
|
|
9
|
-
console.info(`Clearing '${outputBinBasePath}' files.`);
|
|
10
|
-
|
|
11
|
-
rmSync(outputBinBasePath, { force: true });
|
|
12
|
-
|
|
13
|
-
if (platform === 'win32') {
|
|
14
|
-
rmSync(`${outputBinBasePath}.exe`, { force: true });
|
|
15
|
-
rmSync(`${outputBinBasePath}.cmd`, { force: true });
|
|
16
|
-
}
|
|
17
|
-
};
|