@package-pal/cli 0.0.10 → 0.0.12
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
|
@@ -18,9 +18,10 @@ export const getPathInfo = (platform, targetPackage) => {
|
|
|
18
18
|
throw new Error('Expected bin name.');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
__dirname, '..', '
|
|
21
|
+
const packageRootDir = resolve(
|
|
22
|
+
__dirname, '..', '..', '..',
|
|
23
23
|
);
|
|
24
|
+
const outputBinDir = join(packageRootDir, 'bin');
|
|
24
25
|
const outputBinTargetBasePath = join(outputBinDir, binName);
|
|
25
26
|
const binExecutableName = platform === 'win32' ? `${binName}.exe` : binName;
|
|
26
27
|
|
|
@@ -35,6 +36,7 @@ export const getPathInfo = (platform, targetPackage) => {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
return {
|
|
39
|
+
packageRootDir,
|
|
38
40
|
outputBinDir,
|
|
39
41
|
binName,
|
|
40
42
|
binExecutableName,
|
|
@@ -11,20 +11,34 @@ import {
|
|
|
11
11
|
export const linkExistingBinary = (
|
|
12
12
|
platform, binExecutableName, targetBinPath, outputBinTargetBasePath,
|
|
13
13
|
) => {
|
|
14
|
-
|
|
15
|
-
symlinkSync(targetBinPath, outputBinTargetBasePath);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
14
|
+
const isWin = platform === 'win32';
|
|
18
15
|
|
|
19
16
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (!isWin) {
|
|
18
|
+
symlinkSync(targetBinPath, outputBinTargetBasePath);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
} catch (eSym) {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
linkSync(targetBinPath, outputBinTargetBasePath);
|
|
24
|
+
} catch (eLink) {
|
|
25
|
+
try {
|
|
26
|
+
copyFileSync(targetBinPath, outputBinTargetBasePath);
|
|
27
|
+
} catch (eCopy) {
|
|
28
|
+
const cause = [
|
|
29
|
+
eSym,
|
|
30
|
+
eLink,
|
|
31
|
+
eCopy,
|
|
32
|
+
].filter(Boolean);
|
|
33
|
+
throw new Error(`Failed to link to or copy target binary '${targetBinPath}'.`, { cause });
|
|
34
|
+
}
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
console.info(`Successfully linked binary: '${outputBinTargetBasePath}' → '${targetBinPath}'.`);
|
|
39
|
+
|
|
40
|
+
if (isWin) {
|
|
41
|
+
console.info('Creating cmd shim.');
|
|
42
|
+
writeFileSync(`${outputBinTargetBasePath}.cmd`, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
|
|
43
|
+
}
|
|
30
44
|
};
|
|
@@ -41,7 +41,7 @@ const tryDownloadAndExtract = (
|
|
|
41
41
|
const extractStream = x({
|
|
42
42
|
cwd: outputBinDir,
|
|
43
43
|
strip: 1,
|
|
44
|
-
filter: path => path ===
|
|
44
|
+
filter: path => path === `package/${binExecutableName}`,
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
pipeline(res, extractStream).then(resolve)
|
|
@@ -83,7 +83,7 @@ const downloadAndExtract = async (
|
|
|
83
83
|
export const loadMissingBinary = async (
|
|
84
84
|
binExecutableName, targetPackage, outputBinDir,
|
|
85
85
|
) => {
|
|
86
|
-
const fullTargetPackageName =
|
|
86
|
+
const fullTargetPackageName = `@package-pal/${targetPackage}`;
|
|
87
87
|
/** @type {Record<string, string>} */
|
|
88
88
|
const optionalDeps = packageJson.optionalDependencies;
|
|
89
89
|
const targetPackageVersion = optionalDeps[fullTargetPackageName];
|
|
@@ -93,7 +93,7 @@ export const loadMissingBinary = async (
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const tarballUrl = `https://registry.npmjs.org/${fullTargetPackageName}/-/${targetPackage}-${targetPackageVersion}.tgz`;
|
|
96
|
-
console.
|
|
96
|
+
console.info(`Downloading '${fullTargetPackageName}' into '${outputBinDir}' from ${tarballUrl}...`);
|
|
97
97
|
|
|
98
98
|
await downloadAndExtract(
|
|
99
99
|
tarballUrl, binExecutableName, outputBinDir,
|