@package-pal/cli 0.0.14 → 0.0.16
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 +16 -2
- package/package.json +9 -10
- package/src/lib/install/functions/clear-placeholder-binary.js +4 -3
- package/src/lib/install/functions/get-path-info.js +12 -5
- package/src/lib/install/functions/link-existing-binary.js +36 -32
- package/src/lib/install/functions/load-missing-binary.js +12 -6
- package/src/lib/install/functions/prepare-binary.js +19 -16
- package/src/lib/install/functions/validate-binary-version.js +3 -0
- package/src/lib/install/install-binary.js +27 -18
package/bin/ppal
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.16",
|
|
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.
|
|
29
|
-
"@package-pal/cli-linux-x64-musl": "0.0.
|
|
30
|
-
"@package-pal/cli-linux-arm64": "0.0.
|
|
31
|
-
"@package-pal/cli-linux-arm64-musl": "0.0.
|
|
32
|
-
"@package-pal/cli-darwin-arm64": "0.0.
|
|
33
|
-
"@package-pal/cli-darwin-x64": "0.0.
|
|
34
|
-
"@package-pal/cli-windows-x64": "0.0.
|
|
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,11 @@
|
|
|
1
1
|
import { rmSync } from 'fs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @param {Bun.Platform}
|
|
5
|
-
* @param {string} outputBinBasePath
|
|
4
|
+
* @param {{ platform: Bun.Platform, outputBinBasePath: string }} options
|
|
6
5
|
*/
|
|
7
|
-
export const clearPlaceholderBinary = (
|
|
6
|
+
export const clearPlaceholderBinary = ({
|
|
7
|
+
platform, outputBinBasePath,
|
|
8
|
+
}) => {
|
|
8
9
|
rmSync(outputBinBasePath, { force: true });
|
|
9
10
|
|
|
10
11
|
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}
|
|
12
|
-
* @param {string} targetPackage
|
|
11
|
+
* @param {{ platform: Bun.Platform, targetPackage: string }} options
|
|
13
12
|
*/
|
|
14
|
-
export const getPathInfo = (
|
|
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(
|
|
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,58 +1,62 @@
|
|
|
1
1
|
import {
|
|
2
|
-
copyFileSync, existsSync, linkSync, symlinkSync,
|
|
2
|
+
copyFileSync, existsSync, linkSync, symlinkSync, unlinkSync,
|
|
3
3
|
} from 'fs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @param {Bun.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
|
/**
|
|
18
|
-
*
|
|
14
|
+
* @param {string | undefined} method
|
|
19
15
|
*/
|
|
20
16
|
const verifyLinked = (method) => {
|
|
21
17
|
if (!existsSync(outputBinPath)) {
|
|
22
|
-
throw new Error(`Expected link not found after ${method}: '${outputBinPath}'.`);
|
|
18
|
+
throw new Error(`Expected link not found${method ? ` after ${method}` : ''}: '${outputBinPath}'.`);
|
|
23
19
|
}
|
|
24
20
|
};
|
|
25
21
|
|
|
22
|
+
const errs = [];
|
|
23
|
+
|
|
26
24
|
try {
|
|
27
|
-
|
|
25
|
+
unlinkSync(outputBinPath);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
errs.push(e);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isWin) {
|
|
31
|
+
try {
|
|
28
32
|
symlinkSync(targetBinPath, outputBinPath);
|
|
29
33
|
verifyLinked('symlinkSync');
|
|
34
|
+
|
|
30
35
|
return;
|
|
36
|
+
} catch (eSymlinkSync) {
|
|
37
|
+
errs.push(eSymlinkSync);
|
|
31
38
|
}
|
|
32
|
-
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
linkSync(targetBinPath, outputBinPath);
|
|
43
|
+
verifyLinked('linkSync');
|
|
44
|
+
} catch (eLinkSync) {
|
|
45
|
+
errs.push(eLinkSync);
|
|
46
|
+
|
|
33
47
|
try {
|
|
34
|
-
|
|
35
|
-
verifyLinked('
|
|
36
|
-
} catch (
|
|
37
|
-
|
|
38
|
-
copyFileSync(targetBinPath, outputBinPath);
|
|
39
|
-
verifyLinked('copyFileSync');
|
|
40
|
-
} catch (eCopy) {
|
|
41
|
-
const cause = [
|
|
42
|
-
eSym,
|
|
43
|
-
eLink,
|
|
44
|
-
eCopy,
|
|
45
|
-
].filter(Boolean);
|
|
46
|
-
throw new Error(`Failed to link to or copy target binary '${targetBinPath}'.`, { cause });
|
|
47
|
-
}
|
|
48
|
+
copyFileSync(targetBinPath, outputBinPath);
|
|
49
|
+
verifyLinked('copyFileSync');
|
|
50
|
+
} catch (eCopyFileSync) {
|
|
51
|
+
errs.push(eCopyFileSync);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.info(`Creating cmd shim '${shimPath}'.`);
|
|
56
|
-
writeFileSync(shimPath, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
|
|
55
|
+
try {
|
|
56
|
+
verifyLinked(undefined);
|
|
57
|
+
} catch {
|
|
58
|
+
throw new Error('Unable to link CLI binary.', { cause: errs });
|
|
57
59
|
}
|
|
60
|
+
|
|
61
|
+
console.info(`Successfully linked binary: '${outputBinPath}' → '${targetBinPath}'.`);
|
|
58
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
|
|
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}
|
|
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;
|
|
@@ -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}
|
|
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(
|
|
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,
|
|
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,
|
|
32
|
-
|
|
31
|
+
return loadMissingBinary({
|
|
32
|
+
binExecutableName,
|
|
33
|
+
targetPackage,
|
|
34
|
+
outputBinDir,
|
|
35
|
+
});
|
|
33
36
|
};
|
|
@@ -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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|