@package-pal/cli 0.0.18 → 0.0.20

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 CHANGED
@@ -1,16 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Fallback, if post-install script did not execute.
4
- // Requires more overhead due to launching Node process which then launches the CLI process.
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
- require('child_process').execFileSync(targetBinPath, process.argv.slice(2), {
15
- stdio: 'inherit',
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
25
+ } = getPlatformInfo();
26
+ const { targetBinPath, binExecutableName, outputBinDir } = 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@package-pal/cli",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "CLI tool exposing core PackagePal functionality.",
5
5
  "keywords": [
6
6
  "package",
@@ -33,6 +33,9 @@
33
33
  "@package-pal/cli-darwin-x64": "0.0.2",
34
34
  "@package-pal/cli-windows-x64": "0.0.2"
35
35
  },
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
36
39
  "bin": {
37
40
  "ppal": "bin/ppal"
38
41
  },
@@ -3,10 +3,10 @@ import {
3
3
  } from 'fs';
4
4
 
5
5
  /**
6
- * @param {{ platform: Bun.Platform, binExecutableName: string, targetBinPath: string, outputBinBasePath: string, outputBinPath: string }} options
6
+ * @param {{ platform: Bun.Platform, targetBinPath: string, outputBinPath: string }} options
7
7
  */
8
8
  export const linkExistingBinary = ({
9
- platform, binExecutableName, targetBinPath, outputBinBasePath, outputBinPath,
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 maxRetries = 3;
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 <= maxRetries; 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 < maxRetries) {
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 { mkdirSync } from 'fs';
2
- import { clearPlaceholderBinary } from './clear-placeholder-binary.js';
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
- clearPlaceholderBinary({
13
- platform,
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
- };