@package-pal/cli 0.0.8 → 0.0.10
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 +1 -1
- package/src/lib/install/functions/get-path-info.js +15 -3
- package/src/lib/install/functions/link-existing-binary.js +3 -3
- package/src/lib/install/functions/load-missing-binary.js +12 -11
- package/src/lib/install/functions/prepare-binary.js +8 -10
- package/src/lib/install/install-binary.js +2 -2
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
1
2
|
import {
|
|
2
3
|
dirname, join, resolve,
|
|
3
4
|
} from 'path';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
6
|
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
6
7
|
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* @param {Bun.Platform} platform
|
|
9
12
|
* @param {string} targetPackage
|
|
@@ -19,13 +22,22 @@ export const getPathInfo = (platform, targetPackage) => {
|
|
|
19
22
|
__dirname, '..', 'bin',
|
|
20
23
|
);
|
|
21
24
|
const outputBinTargetBasePath = join(outputBinDir, binName);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const binExecutableName = platform === 'win32' ? `${binName}.exe` : binName;
|
|
26
|
+
|
|
27
|
+
/** @type {string | null} */
|
|
28
|
+
let targetBinPath;
|
|
29
|
+
try {
|
|
30
|
+
targetBinPath = require.resolve(join(
|
|
31
|
+
'@package-pal', targetPackage, binExecutableName,
|
|
32
|
+
));
|
|
33
|
+
} catch {
|
|
34
|
+
targetBinPath = null;
|
|
35
|
+
}
|
|
25
36
|
|
|
26
37
|
return {
|
|
27
38
|
outputBinDir,
|
|
28
39
|
binName,
|
|
40
|
+
binExecutableName,
|
|
29
41
|
outputBinTargetBasePath,
|
|
30
42
|
targetBinPath,
|
|
31
43
|
};
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {Bun.Platform} platform
|
|
7
|
+
* @param {string} binExecutableName
|
|
7
8
|
* @param {string} targetBinPath
|
|
8
|
-
* @param {string} binName
|
|
9
9
|
* @param {string} outputBinTargetBasePath
|
|
10
10
|
*/
|
|
11
11
|
export const linkExistingBinary = (
|
|
12
|
-
platform,
|
|
12
|
+
platform, binExecutableName, targetBinPath, outputBinTargetBasePath,
|
|
13
13
|
) => {
|
|
14
14
|
if (platform !== 'win32') {
|
|
15
15
|
symlinkSync(targetBinPath, outputBinTargetBasePath);
|
|
@@ -26,5 +26,5 @@ export const linkExistingBinary = (
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
writeFileSync(`${outputBinTargetBasePath}.cmd`, `@echo off\r\n"%~dp0\\${
|
|
29
|
+
writeFileSync(`${outputBinTargetBasePath}.cmd`, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
|
|
30
30
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { get } from 'https';
|
|
2
|
+
import { join } from 'path';
|
|
2
3
|
import { pipeline } from 'stream/promises';
|
|
3
4
|
import { x } from 'tar';
|
|
4
5
|
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
@@ -8,11 +9,11 @@ const initialBackoffMs = 500;
|
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @param {string} tarballUrl
|
|
11
|
-
* @param {string}
|
|
12
|
+
* @param {string} binExecutableName
|
|
12
13
|
* @param {string} outputBinDir
|
|
13
14
|
*/
|
|
14
15
|
const tryDownloadAndExtract = (
|
|
15
|
-
tarballUrl,
|
|
16
|
+
tarballUrl, binExecutableName, outputBinDir,
|
|
16
17
|
) => {
|
|
17
18
|
return new Promise((resolve, reject) => {
|
|
18
19
|
get(tarballUrl, (res) => {
|
|
@@ -25,7 +26,7 @@ const tryDownloadAndExtract = (
|
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
28
|
downloadAndExtract(
|
|
28
|
-
res.headers.location,
|
|
29
|
+
res.headers.location, binExecutableName, outputBinDir,
|
|
29
30
|
)
|
|
30
31
|
.then(resolve)
|
|
31
32
|
.catch(reject);
|
|
@@ -40,7 +41,7 @@ const tryDownloadAndExtract = (
|
|
|
40
41
|
const extractStream = x({
|
|
41
42
|
cwd: outputBinDir,
|
|
42
43
|
strip: 1,
|
|
43
|
-
filter: path => path ===
|
|
44
|
+
filter: path => path === join('package', binExecutableName),
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
pipeline(res, extractStream).then(resolve)
|
|
@@ -51,16 +52,16 @@ const tryDownloadAndExtract = (
|
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* @param {string} tarballUrl
|
|
54
|
-
* @param {string}
|
|
55
|
+
* @param {string} binExecutableName
|
|
55
56
|
* @param {string} outputBinDir
|
|
56
57
|
*/
|
|
57
58
|
const downloadAndExtract = async (
|
|
58
|
-
tarballUrl,
|
|
59
|
+
tarballUrl, binExecutableName, outputBinDir,
|
|
59
60
|
) => {
|
|
60
61
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
61
62
|
try {
|
|
62
63
|
await tryDownloadAndExtract(
|
|
63
|
-
tarballUrl,
|
|
64
|
+
tarballUrl, binExecutableName, outputBinDir,
|
|
64
65
|
);
|
|
65
66
|
return;
|
|
66
67
|
} catch (error) {
|
|
@@ -75,14 +76,14 @@ const downloadAndExtract = async (
|
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
|
-
* @param {string}
|
|
79
|
+
* @param {string} binExecutableName
|
|
79
80
|
* @param {string} targetPackage
|
|
80
81
|
* @param {string} outputBinDir
|
|
81
82
|
*/
|
|
82
83
|
export const loadMissingBinary = async (
|
|
83
|
-
|
|
84
|
+
binExecutableName, targetPackage, outputBinDir,
|
|
84
85
|
) => {
|
|
85
|
-
const fullTargetPackageName =
|
|
86
|
+
const fullTargetPackageName = join('@package-pal', targetPackage);
|
|
86
87
|
/** @type {Record<string, string>} */
|
|
87
88
|
const optionalDeps = packageJson.optionalDependencies;
|
|
88
89
|
const targetPackageVersion = optionalDeps[fullTargetPackageName];
|
|
@@ -95,6 +96,6 @@ export const loadMissingBinary = async (
|
|
|
95
96
|
console.log(`Downloading '${fullTargetPackageName}' into '${outputBinDir}' from ${tarballUrl}...`);
|
|
96
97
|
|
|
97
98
|
await downloadAndExtract(
|
|
98
|
-
tarballUrl,
|
|
99
|
+
tarballUrl, binExecutableName, outputBinDir,
|
|
99
100
|
);
|
|
100
101
|
};
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync, mkdirSync,
|
|
3
|
-
} from 'fs';
|
|
1
|
+
import { mkdirSync } from 'fs';
|
|
4
2
|
import { clearPlaceholderBinary } from './clear-placeholder-binary.js';
|
|
5
3
|
import { linkExistingBinary } from './link-existing-binary.js';
|
|
6
4
|
import { loadMissingBinary } from './load-missing-binary.js';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @param {Bun.Platform} platform
|
|
10
|
-
* @param {string}
|
|
8
|
+
* @param {string} binExecutableName
|
|
11
9
|
* @param {string} targetPackage
|
|
12
|
-
* @param {string} targetBinPath
|
|
10
|
+
* @param {string | null} targetBinPath
|
|
13
11
|
* @param {string} outputBinDir
|
|
14
12
|
* @param {string} outputBinTargetBasePath
|
|
15
13
|
*/
|
|
16
14
|
export const prepareBinary = (
|
|
17
|
-
platform,
|
|
15
|
+
platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinTargetBasePath,
|
|
18
16
|
) => {
|
|
19
17
|
clearPlaceholderBinary(platform, outputBinTargetBasePath);
|
|
20
18
|
mkdirSync(outputBinDir, { recursive: true });
|
|
21
19
|
|
|
22
|
-
if (
|
|
20
|
+
if (targetBinPath) {
|
|
23
21
|
console.info(`Expected CLI binary package is available in '${targetBinPath}'.`);
|
|
24
22
|
linkExistingBinary(
|
|
25
|
-
platform,
|
|
23
|
+
platform, binExecutableName, targetBinPath, outputBinTargetBasePath,
|
|
26
24
|
);
|
|
27
25
|
return Promise.resolve();
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
console.warn(`Expected CLI binary was not found
|
|
28
|
+
console.warn(`Expected CLI binary was not found for '${targetPackage}'.`);
|
|
31
29
|
return loadMissingBinary(
|
|
32
|
-
|
|
30
|
+
binExecutableName, targetPackage, outputBinDir,
|
|
33
31
|
);
|
|
34
32
|
};
|
|
@@ -7,11 +7,11 @@ try {
|
|
|
7
7
|
platform, targetPackage,
|
|
8
8
|
} = getPlatformInfo();
|
|
9
9
|
const {
|
|
10
|
-
outputBinDir,
|
|
10
|
+
outputBinDir, binExecutableName, outputBinTargetBasePath, targetBinPath,
|
|
11
11
|
} = getPathInfo(platform, targetPackage);
|
|
12
12
|
|
|
13
13
|
await prepareBinary(
|
|
14
|
-
platform,
|
|
14
|
+
platform, binExecutableName, targetPackage, targetBinPath, outputBinDir, outputBinTargetBasePath,
|
|
15
15
|
);
|
|
16
16
|
} catch (e) {
|
|
17
17
|
throw new Error('Postinstall failed to install CLI binary.', { cause: e });
|