@package-pal/cli 0.0.35 → 0.0.37
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,71 +1,71 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import {
|
|
4
|
-
dirname, join, resolve,
|
|
5
|
-
} from 'path';
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
7
|
-
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
8
|
-
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {{ platform: Bun.Platform, targetPackage: string }} options
|
|
13
|
-
*/
|
|
14
|
-
export const getPathInfo = ({
|
|
15
|
-
platform, targetPackage,
|
|
16
|
-
}) => {
|
|
17
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
const binName = Object.keys(packageJson.bin)[0];
|
|
19
|
-
if (!binName) {
|
|
20
|
-
throw new Error(`Expected '${packageJson.name}' bin name.`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const baseVersion = packageJson.version;
|
|
24
|
-
if (!baseVersion) {
|
|
25
|
-
throw new Error(`Expected '${packageJson.name}' version.`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const packageRootDir = resolve(
|
|
29
|
-
__dirname, '..', '..', '..', '..',
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const binExecutableName = platform === 'win32' ? `${binName}.exe` : binName;
|
|
33
|
-
const outputBinDir = join(packageRootDir, 'bin');
|
|
34
|
-
const outputBinBasePath = join(outputBinDir, binName);
|
|
35
|
-
const outputBinPath = join(outputBinDir, binExecutableName);
|
|
36
|
-
|
|
37
|
-
/** @type {string | null} */
|
|
38
|
-
let targetBinPath = null;
|
|
39
|
-
/** @type {string | null} */
|
|
40
|
-
let targetVersion = null;
|
|
41
|
-
try {
|
|
42
|
-
targetBinPath = require.resolve(join(
|
|
43
|
-
'@package-pal', targetPackage, 'bin', binExecutableName,
|
|
44
|
-
));
|
|
45
|
-
|
|
46
|
-
if (targetBinPath) {
|
|
47
|
-
const targetPackageRoot = dirname(dirname(targetBinPath));
|
|
48
|
-
const targetPackageJsonPath = join(targetPackageRoot, 'package.json');
|
|
49
|
-
/** @type {Record<string, unknown> | null} */
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
51
|
-
const targetPackageJson = JSON.parse(readFileSync(targetPackageJsonPath, { encoding: 'utf8' }));
|
|
52
|
-
if (typeof targetPackageJson?.version === 'string') {
|
|
53
|
-
targetVersion = targetPackageJson.version;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
//
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
packageRootDir,
|
|
62
|
-
outputBinDir,
|
|
63
|
-
binName,
|
|
64
|
-
binExecutableName,
|
|
65
|
-
outputBinBasePath,
|
|
66
|
-
outputBinPath,
|
|
67
|
-
targetBinPath,
|
|
68
|
-
baseVersion,
|
|
69
|
-
targetVersion,
|
|
70
|
-
};
|
|
71
|
-
};
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import {
|
|
4
|
+
dirname, join, resolve,
|
|
5
|
+
} from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import packageJson from '../../../../package.json' with { type: 'json' };
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {{ platform: Bun.Platform, targetPackage: string }} options
|
|
13
|
+
*/
|
|
14
|
+
export const getPathInfo = ({
|
|
15
|
+
platform, targetPackage,
|
|
16
|
+
}) => {
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const binName = Object.keys(packageJson.bin)[0];
|
|
19
|
+
if (!binName) {
|
|
20
|
+
throw new Error(`Expected '${packageJson.name}' bin name.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const baseVersion = packageJson.version;
|
|
24
|
+
if (!baseVersion) {
|
|
25
|
+
throw new Error(`Expected '${packageJson.name}' version.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const packageRootDir = resolve(
|
|
29
|
+
__dirname, '..', '..', '..', '..',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const binExecutableName = platform === 'win32' ? `${binName}.exe` : binName;
|
|
33
|
+
const outputBinDir = join(packageRootDir, 'bin');
|
|
34
|
+
const outputBinBasePath = join(outputBinDir, binName);
|
|
35
|
+
const outputBinPath = join(outputBinDir, binExecutableName);
|
|
36
|
+
|
|
37
|
+
/** @type {string | null} */
|
|
38
|
+
let targetBinPath = null;
|
|
39
|
+
/** @type {string | null} */
|
|
40
|
+
let targetVersion = null;
|
|
41
|
+
try {
|
|
42
|
+
targetBinPath = require.resolve(join(
|
|
43
|
+
'@package-pal', targetPackage, 'bin', binExecutableName,
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
if (targetBinPath) {
|
|
47
|
+
const targetPackageRoot = dirname(dirname(targetBinPath));
|
|
48
|
+
const targetPackageJsonPath = join(targetPackageRoot, 'package.json');
|
|
49
|
+
/** @type {Record<string, unknown> | null} */
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
51
|
+
const targetPackageJson = JSON.parse(readFileSync(targetPackageJsonPath, { encoding: 'utf8' }));
|
|
52
|
+
if (typeof targetPackageJson?.version === 'string') {
|
|
53
|
+
targetVersion = targetPackageJson.version;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
//
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
packageRootDir,
|
|
62
|
+
outputBinDir,
|
|
63
|
+
binName,
|
|
64
|
+
binExecutableName,
|
|
65
|
+
outputBinBasePath,
|
|
66
|
+
outputBinPath,
|
|
67
|
+
targetBinPath,
|
|
68
|
+
baseVersion,
|
|
69
|
+
targetVersion,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -13,7 +13,7 @@ export const launchFallback = async () => {
|
|
|
13
13
|
platform, targetPackage,
|
|
14
14
|
} = getPlatformInfo();
|
|
15
15
|
const {
|
|
16
|
-
targetBinPath, binExecutableName, outputBinDir,
|
|
16
|
+
targetBinPath, binExecutableName, outputBinDir,
|
|
17
17
|
} = getPathInfo({
|
|
18
18
|
platform,
|
|
19
19
|
targetPackage,
|
|
@@ -25,8 +25,14 @@ export const prepareBinary = ({
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
rmSync(outputBinBasePath, {
|
|
29
|
-
|
|
28
|
+
rmSync(outputBinBasePath, {
|
|
29
|
+
force: true,
|
|
30
|
+
recursive: true,
|
|
31
|
+
});
|
|
32
|
+
rmSync(outputBinPath, {
|
|
33
|
+
force: true,
|
|
34
|
+
recursive: true,
|
|
35
|
+
});
|
|
30
36
|
mkdirSync(outputBinDir, { recursive: true });
|
|
31
37
|
|
|
32
38
|
if (targetBinPath) {
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param {string}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import packageJson from '../../../../package.json';
|
|
2
|
+
import { exec } from './exec.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string | null} targetVersion
|
|
6
|
+
* @param {string} targetBinPath
|
|
7
|
+
*/
|
|
8
|
+
export const validateBinaryVersion = (targetVersion, targetBinPath) => {
|
|
9
|
+
if (!targetVersion) {
|
|
10
|
+
throw new Error(`'${targetBinPath}' no binary version found.`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const stdout = exec(
|
|
14
|
+
targetBinPath, ['-v'], 'pipe',
|
|
15
|
+
).toString()
|
|
16
|
+
.trim();
|
|
17
|
+
|
|
18
|
+
const expectedVersion = `${packageJson.version}-${targetVersion}`;
|
|
19
|
+
|
|
20
|
+
if (stdout.toLowerCase() !== expectedVersion.toLowerCase()) {
|
|
21
|
+
throw new Error(`'${targetBinPath}' binary version mismatch; expected ${expectedVersion}, got ${stdout}.`);
|
|
22
|
+
}
|
|
23
|
+
};
|