@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@package-pal/cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "CLI tool exposing core PackagePal functionality.",
5
5
  "keywords": [
6
6
  "package",
@@ -18,9 +18,10 @@ export const getPathInfo = (platform, targetPackage) => {
18
18
  throw new Error('Expected bin name.');
19
19
  }
20
20
 
21
- const outputBinDir = resolve(
22
- __dirname, '..', 'bin',
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
- if (platform !== 'win32') {
15
- symlinkSync(targetBinPath, outputBinTargetBasePath);
16
- return;
17
- }
14
+ const isWin = platform === 'win32';
18
15
 
19
16
  try {
20
- linkSync(targetBinPath, outputBinTargetBasePath);
21
- } catch {
17
+ if (!isWin) {
18
+ symlinkSync(targetBinPath, outputBinTargetBasePath);
19
+ return;
20
+ }
21
+ } catch (eSym) {
22
22
  try {
23
- copyFileSync(targetBinPath, outputBinTargetBasePath);
24
- } catch (e) {
25
- throw new Error(`Failed to link to or copy target binary '${targetBinPath}'.`, { cause: e });
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
- writeFileSync(`${outputBinTargetBasePath}.cmd`, `@echo off\r\n"%~dp0\\${binExecutableName}" %*\r\n`);
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 === join('package', binExecutableName),
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 = join('@package-pal', targetPackage);
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.log(`Downloading '${fullTargetPackageName}' into '${outputBinDir}' from ${tarballUrl}...`);
96
+ console.info(`Downloading '${fullTargetPackageName}' into '${outputBinDir}' from ${tarballUrl}...`);
97
97
 
98
98
  await downloadAndExtract(
99
99
  tarballUrl, binExecutableName, outputBinDir,