@package-pal/cli 0.0.13 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@package-pal/cli",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "CLI tool exposing core PackagePal functionality.",
5
5
  "keywords": [
6
6
  "package",
@@ -2,13 +2,13 @@ import { rmSync } from 'fs';
2
2
 
3
3
  /**
4
4
  * @param {Bun.Platform} platform
5
- * @param {string} outputBinTargetBasePath
5
+ * @param {string} outputBinBasePath
6
6
  */
7
- export const clearPlaceholderBinary = (platform, outputBinTargetBasePath) => {
8
- rmSync(outputBinTargetBasePath, { force: true });
7
+ export const clearPlaceholderBinary = (platform, outputBinBasePath) => {
8
+ rmSync(outputBinBasePath, { force: true });
9
9
 
10
10
  if (platform === 'win32') {
11
- rmSync(`${outputBinTargetBasePath}.exe`, { force: true });
12
- rmSync(`${outputBinTargetBasePath}.cmd`, { force: true });
11
+ rmSync(`${outputBinBasePath}.exe`, { force: true });
12
+ rmSync(`${outputBinBasePath}.cmd`, { force: true });
13
13
  }
14
14
  };
@@ -21,9 +21,11 @@ export const getPathInfo = (platform, targetPackage) => {
21
21
  const packageRootDir = resolve(
22
22
  __dirname, '..', '..', '..', '..',
23
23
  );
24
- const outputBinDir = join(packageRootDir, 'bin');
25
- const outputBinTargetBasePath = join(outputBinDir, binName);
24
+
26
25
  const binExecutableName = platform === 'win32' ? `${binName}.exe` : binName;
26
+ const outputBinDir = join(packageRootDir, 'bin');
27
+ const outputBinBasePath = join(outputBinDir, binName);
28
+ const outputBinPath = join(outputBinDir, binExecutableName);
27
29
 
28
30
  /** @type {string | null} */
29
31
  let targetBinPath;
@@ -40,7 +42,8 @@ export const getPathInfo = (platform, targetPackage) => {
40
42
  outputBinDir,
41
43
  binName,
42
44
  binExecutableName,
43
- outputBinTargetBasePath,
45
+ outputBinBasePath,
46
+ outputBinPath,
44
47
  targetBinPath,
45
48
  };
46
49
  };
@@ -1,29 +1,42 @@
1
1
  import {
2
- copyFileSync, linkSync, symlinkSync, writeFileSync,
2
+ copyFileSync, existsSync, linkSync, symlinkSync, writeFileSync,
3
3
  } from 'fs';
4
4
 
5
5
  /**
6
6
  * @param {Bun.Platform} platform
7
7
  * @param {string} binExecutableName
8
8
  * @param {string} targetBinPath
9
- * @param {string} outputBinTargetBasePath
9
+ * @param {string} outputBinBasePath
10
+ * @param {string} outputBinPath
10
11
  */
11
12
  export const linkExistingBinary = (
12
- platform, binExecutableName, targetBinPath, outputBinTargetBasePath,
13
+ platform, binExecutableName, targetBinPath, outputBinBasePath, outputBinPath,
13
14
  ) => {
14
15
  const isWin = platform === 'win32';
15
16
 
17
+ /**
18
+ * @param {string} method
19
+ */
20
+ const verifyLinked = (method) => {
21
+ if (!existsSync(outputBinPath)) {
22
+ throw new Error(`Expected link not found after ${method}: '${outputBinPath}'.`);
23
+ }
24
+ };
25
+
16
26
  try {
17
27
  if (!isWin) {
18
- symlinkSync(targetBinPath, outputBinTargetBasePath);
28
+ symlinkSync(targetBinPath, outputBinPath);
29
+ verifyLinked('symlinkSync');
19
30
  return;
20
31
  }
21
32
  } catch (eSym) {
22
33
  try {
23
- linkSync(targetBinPath, outputBinTargetBasePath);
34
+ linkSync(targetBinPath, outputBinPath);
35
+ verifyLinked('linkSync');
24
36
  } catch (eLink) {
25
37
  try {
26
- copyFileSync(targetBinPath, outputBinTargetBasePath);
38
+ copyFileSync(targetBinPath, outputBinPath);
39
+ verifyLinked('copyFileSync');
27
40
  } catch (eCopy) {
28
41
  const cause = [
29
42
  eSym,
@@ -35,10 +48,10 @@ export const linkExistingBinary = (
35
48
  }
36
49
  }
37
50
 
38
- console.info(`Successfully linked binary: '${outputBinTargetBasePath}' → '${targetBinPath}'.`);
51
+ console.info(`Successfully linked binary: '${outputBinPath}' → '${targetBinPath}'.`);
39
52
 
40
53
  if (isWin) {
41
- const shimPath = `${outputBinTargetBasePath}.cmd`;
54
+ const shimPath = `${outputBinBasePath}.cmd`;
42
55
  console.info(`Creating cmd shim '${shimPath}'.`);
43
56
  writeFileSync(shimPath, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
44
57
  }
@@ -9,18 +9,19 @@ import { loadMissingBinary } from './load-missing-binary.js';
9
9
  * @param {string} targetPackage
10
10
  * @param {string | null} targetBinPath
11
11
  * @param {string} outputBinDir
12
- * @param {string} outputBinTargetBasePath
12
+ * @param {string} outputBinBasePath
13
+ * @param {string} outputBinPath
13
14
  */
14
15
  export const prepareBinary = (
15
- platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinTargetBasePath,
16
+ platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinBasePath, outputBinPath,
16
17
  ) => {
17
- clearPlaceholderBinary(platform, outputBinTargetBasePath);
18
+ clearPlaceholderBinary(platform, outputBinBasePath);
18
19
  mkdirSync(outputBinDir, { recursive: true });
19
20
 
20
21
  if (targetBinPath) {
21
22
  console.info(`Expected CLI binary package is available in '${targetBinPath}'.`);
22
23
  linkExistingBinary(
23
- platform, binExecutableName, targetBinPath, outputBinTargetBasePath,
24
+ platform, binExecutableName, targetBinPath, outputBinBasePath, outputBinPath,
24
25
  );
25
26
  return Promise.resolve();
26
27
  }
@@ -7,11 +7,11 @@ try {
7
7
  platform, targetPackage,
8
8
  } = getPlatformInfo();
9
9
  const {
10
- outputBinDir, binExecutableName, outputBinTargetBasePath, targetBinPath,
10
+ outputBinDir, binExecutableName, outputBinBasePath, outputBinPath, targetBinPath,
11
11
  } = getPathInfo(platform, targetPackage);
12
12
 
13
13
  await prepareBinary(
14
- platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinTargetBasePath,
14
+ platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinBasePath, outputBinPath,
15
15
  );
16
16
  } catch (e) {
17
17
  throw new Error('Postinstall failed to install CLI binary.', { cause: e });