@package-pal/cli 0.0.15 → 0.0.17

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,2 +1,16 @@
1
- #!/usr/bin/env node
2
- throw new Error("Native binary not linked yet. Re-run `npm install` or check postinstall script.");
1
+ #!/usr/bin/env node
2
+
3
+ // Fallback, if post-install script did not execute.
4
+ // Requires more overhead due to launching Node process which then launches the CLI process.
5
+
6
+ import { getPathInfo } from '../src/lib/install/functions/get-path-info.js';
7
+ import { getPlatformInfo } from '../src/lib/install/functions/get-platform-info.js';
8
+
9
+ const {
10
+ platform, targetPackage,
11
+ } = getPlatformInfo();
12
+ const { targetBinPath } = getPathInfo({ platform, targetPackage });
13
+
14
+ require('child_process').execFileSync(targetBinPath, process.argv.slice(2), {
15
+ stdio: 'inherit',
16
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@package-pal/cli",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "CLI tool exposing core PackagePal functionality.",
5
5
  "keywords": [
6
6
  "package",
@@ -25,17 +25,16 @@
25
25
  "yoctocolors": "^2.1.1"
26
26
  },
27
27
  "optionalDependencies": {
28
- "@package-pal/cli-linux-x64": "0.0.1",
29
- "@package-pal/cli-linux-x64-musl": "0.0.1",
30
- "@package-pal/cli-linux-arm64": "0.0.1",
31
- "@package-pal/cli-linux-arm64-musl": "0.0.1",
32
- "@package-pal/cli-darwin-arm64": "0.0.1",
33
- "@package-pal/cli-darwin-x64": "0.0.1",
34
- "@package-pal/cli-windows-x64": "0.0.1"
28
+ "@package-pal/cli-linux-x64": "0.0.2",
29
+ "@package-pal/cli-linux-x64-musl": "0.0.2",
30
+ "@package-pal/cli-linux-arm64": "0.0.2",
31
+ "@package-pal/cli-linux-arm64-musl": "0.0.2",
32
+ "@package-pal/cli-darwin-arm64": "0.0.2",
33
+ "@package-pal/cli-darwin-x64": "0.0.2",
34
+ "@package-pal/cli-windows-x64": "0.0.2"
35
35
  },
36
36
  "bin": {
37
- "ppal": "bin/ppal",
38
- "dppal": "./src/index.ts"
37
+ "ppal": "bin/ppal"
39
38
  },
40
39
  "files": [
41
40
  "src/lib/install",
@@ -1,10 +1,13 @@
1
1
  import { rmSync } from 'fs';
2
2
 
3
3
  /**
4
- * @param {Bun.Platform} platform
5
- * @param {string} outputBinBasePath
4
+ * @param {{ platform: Bun.Platform, outputBinBasePath: string }} options
6
5
  */
7
- export const clearPlaceholderBinary = (platform, outputBinBasePath) => {
6
+ export const clearPlaceholderBinary = ({
7
+ platform, outputBinBasePath,
8
+ }) => {
9
+ console.info(`Clearing '${outputBinBasePath}' files.`);
10
+
8
11
  rmSync(outputBinBasePath, { force: true });
9
12
 
10
13
  if (platform === 'win32') {
@@ -8,14 +8,20 @@ import packageJson from '../../../../package.json' with { type: 'json' };
8
8
  const require = createRequire(import.meta.url);
9
9
 
10
10
  /**
11
- * @param {Bun.Platform} platform
12
- * @param {string} targetPackage
11
+ * @param {{ platform: Bun.Platform, targetPackage: string }} options
13
12
  */
14
- export const getPathInfo = (platform, targetPackage) => {
13
+ export const getPathInfo = ({
14
+ platform, targetPackage,
15
+ }) => {
15
16
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
17
  const binName = Object.keys(packageJson.bin)[0];
17
18
  if (!binName) {
18
- throw new Error('Expected bin name.');
19
+ throw new Error(`Expected '${targetPackage}' bin name.`);
20
+ }
21
+
22
+ const targetVersion = packageJson.version;
23
+ if (!targetVersion) {
24
+ throw new Error(`Expected '${targetPackage}' version.`);
19
25
  }
20
26
 
21
27
  const packageRootDir = resolve(
@@ -31,7 +37,7 @@ export const getPathInfo = (platform, targetPackage) => {
31
37
  let targetBinPath;
32
38
  try {
33
39
  targetBinPath = require.resolve(join(
34
- '@package-pal', targetPackage, binExecutableName,
40
+ '@package-pal', targetPackage, 'bin', binExecutableName,
35
41
  ));
36
42
  } catch {
37
43
  targetBinPath = null;
@@ -45,5 +51,6 @@ export const getPathInfo = (platform, targetPackage) => {
45
51
  outputBinBasePath,
46
52
  outputBinPath,
47
53
  targetBinPath,
54
+ targetVersion,
48
55
  };
49
56
  };
@@ -1,17 +1,13 @@
1
1
  import {
2
- copyFileSync, existsSync, linkSync, symlinkSync, writeFileSync,
2
+ copyFileSync, existsSync, linkSync, symlinkSync, unlinkSync,
3
3
  } from 'fs';
4
4
 
5
5
  /**
6
- * @param {Bun.Platform} platform
7
- * @param {string} binExecutableName
8
- * @param {string} targetBinPath
9
- * @param {string} outputBinBasePath
10
- * @param {string} outputBinPath
6
+ * @param {{ platform: Bun.Platform, binExecutableName: string, targetBinPath: string, outputBinBasePath: string, outputBinPath: string }} options
11
7
  */
12
- export const linkExistingBinary = (
8
+ export const linkExistingBinary = ({
13
9
  platform, binExecutableName, targetBinPath, outputBinBasePath, outputBinPath,
14
- ) => {
10
+ }) => {
15
11
  const isWin = platform === 'win32';
16
12
 
17
13
  /**
@@ -25,6 +21,12 @@ export const linkExistingBinary = (
25
21
 
26
22
  const errs = [];
27
23
 
24
+ try {
25
+ unlinkSync(outputBinPath);
26
+ } catch (e) {
27
+ errs.push(e);
28
+ }
29
+
28
30
  if (!isWin) {
29
31
  try {
30
32
  symlinkSync(targetBinPath, outputBinPath);
@@ -57,10 +59,4 @@ export const linkExistingBinary = (
57
59
  }
58
60
 
59
61
  console.info(`Successfully linked binary: '${outputBinPath}' → '${targetBinPath}'.`);
60
-
61
- if (isWin) {
62
- const shimPath = `${outputBinBasePath}.cmd`;
63
- console.info(`Creating cmd shim '${shimPath}'.`);
64
- writeFileSync(shimPath, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
65
- }
66
62
  };
@@ -1,3 +1,4 @@
1
+ import { chmod } from 'fs/promises';
1
2
  import { get } from 'https';
2
3
  import { join } from 'path';
3
4
  import { pipeline } from 'stream/promises';
@@ -17,7 +18,8 @@ const tryDownloadAndExtract = (
17
18
  ) => {
18
19
  return new Promise((resolve, reject) => {
19
20
  get(tarballUrl, (res) => {
20
- const isRedirect = res.statusCode === 301 || res.statusCode === 302;
21
+ const isRedirect = res.statusCode && (res.statusCode >= 300
22
+ && res.statusCode < 400);
21
23
  const isSuccess = res.statusCode === 200;
22
24
 
23
25
  if (isRedirect) {
@@ -73,16 +75,20 @@ const downloadAndExtract = async (
73
75
  }
74
76
  }
75
77
  }
78
+
79
+ try {
80
+ await chmod(join(outputBinDir, binExecutableName), 0o755);
81
+ } catch {
82
+ //
83
+ }
76
84
  };
77
85
 
78
86
  /**
79
- * @param {string} binExecutableName
80
- * @param {string} targetPackage
81
- * @param {string} outputBinDir
87
+ * @param {{ binExecutableName: string, targetPackage: string, outputBinDir: string }} options
82
88
  */
83
- export const loadMissingBinary = async (
89
+ export const loadMissingBinary = async ({
84
90
  binExecutableName, targetPackage, outputBinDir,
85
- ) => {
91
+ }) => {
86
92
  const fullTargetPackageName = `@package-pal/${targetPackage}`;
87
93
  /** @type {Record<string, string>} */
88
94
  const optionalDeps = packageJson.optionalDependencies;
@@ -92,7 +98,7 @@ export const loadMissingBinary = async (
92
98
  throw new Error(`No version found for target package '${fullTargetPackageName}'.`);
93
99
  }
94
100
 
95
- const tarballUrl = `https://registry.npmjs.org/${fullTargetPackageName}/-/${targetPackage}-${targetPackageVersion}.tgz`;
101
+ const tarballUrl = `https://registry.npmjs.org/${fullTargetPackageName}/-/bin/${targetPackage}-${targetPackageVersion}.tgz`;
96
102
  console.info(`Downloading '${fullTargetPackageName}' into '${outputBinDir}' from ${tarballUrl}...`);
97
103
 
98
104
  await downloadAndExtract(
@@ -4,30 +4,33 @@ import { linkExistingBinary } from './link-existing-binary.js';
4
4
  import { loadMissingBinary } from './load-missing-binary.js';
5
5
 
6
6
  /**
7
- * @param {Bun.Platform} platform
8
- * @param {string} binExecutableName
9
- * @param {string} targetPackage
10
- * @param {string | null} targetBinPath
11
- * @param {string} outputBinDir
12
- * @param {string} outputBinBasePath
13
- * @param {string} outputBinPath
7
+ * @param {{ platform: Bun.Platform, binExecutableName: string, targetPackage: string, targetBinPath: string | null, outputBinDir: string, outputBinBasePath: string, outputBinPath: string }} options
14
8
  */
15
- export const prepareBinary = (
9
+ export const prepareBinary = ({
16
10
  platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinBasePath, outputBinPath,
17
- ) => {
18
- clearPlaceholderBinary(platform, outputBinBasePath);
11
+ }) => {
12
+ clearPlaceholderBinary({
13
+ platform,
14
+ outputBinBasePath,
15
+ });
19
16
  mkdirSync(outputBinDir, { recursive: true });
20
17
 
21
18
  if (targetBinPath) {
22
19
  console.info(`Expected CLI binary package is available in '${targetBinPath}'.`);
23
- linkExistingBinary(
24
- platform, binExecutableName, targetBinPath, outputBinBasePath, outputBinPath,
25
- );
20
+ linkExistingBinary({
21
+ platform,
22
+ binExecutableName,
23
+ targetBinPath,
24
+ outputBinBasePath,
25
+ outputBinPath,
26
+ });
26
27
  return Promise.resolve();
27
28
  }
28
29
 
29
30
  console.warn(`Expected CLI binary was not found for '${targetPackage}'.`);
30
- return loadMissingBinary(
31
- binExecutableName, targetPackage, outputBinDir,
32
- );
31
+ return loadMissingBinary({
32
+ binExecutableName,
33
+ targetPackage,
34
+ outputBinDir,
35
+ });
33
36
  };
@@ -0,0 +1,3 @@
1
+ // export const validateBinaryVersion = (targetVersion) => {
2
+ // //
3
+ // };
@@ -1,18 +1,27 @@
1
- import { getPathInfo } from './functions/get-path-info.js';
2
- import { getPlatformInfo } from './functions/get-platform-info.js';
3
- import { prepareBinary } from './functions/prepare-binary.js';
4
-
5
- try {
6
- const {
7
- platform, targetPackage,
8
- } = getPlatformInfo();
9
- const {
10
- outputBinDir, binExecutableName, outputBinBasePath, outputBinPath, targetBinPath,
11
- } = getPathInfo(platform, targetPackage);
12
-
13
- await prepareBinary(
14
- platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinBasePath, outputBinPath,
15
- );
16
- } catch (e) {
17
- throw new Error('Postinstall failed to install CLI binary.', { cause: e });
18
- }
1
+ import { getPathInfo } from './functions/get-path-info.js';
2
+ import { getPlatformInfo } from './functions/get-platform-info.js';
3
+ import { prepareBinary } from './functions/prepare-binary.js';
4
+
5
+ try {
6
+ const {
7
+ platform, targetPackage,
8
+ } = getPlatformInfo();
9
+ const {
10
+ outputBinDir, binExecutableName, outputBinBasePath, outputBinPath, targetBinPath,
11
+ } = getPathInfo({
12
+ platform,
13
+ targetPackage,
14
+ });
15
+
16
+ await prepareBinary({
17
+ platform,
18
+ binExecutableName,
19
+ targetPackage,
20
+ targetBinPath,
21
+ outputBinDir,
22
+ outputBinBasePath,
23
+ outputBinPath,
24
+ });
25
+ } catch (e) {
26
+ throw new Error('Postinstall failed to install CLI binary.', { cause: e });
27
+ }