@probelabs/probe 0.6.0-rc56

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.
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Post-install script for the probe package
5
+ *
6
+ * This script is executed after the package is installed.
7
+ * It downloads the probe binary and replaces the placeholder binary with the actual one.
8
+ */
9
+
10
+ import fs from 'fs-extra';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ import { downloadProbeBinary } from '../src/downloader.js';
14
+
15
+ // Get the directory of the current module
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = path.dirname(__filename);
18
+
19
+ // Path to the bin directory (relative to this script)
20
+ const binDir = path.resolve(__dirname, '..', 'bin');
21
+
22
+ /**
23
+ * Main function
24
+ */
25
+ async function main() {
26
+ try {
27
+ // Create the bin directory if it doesn't exist
28
+ console.log(`Creating bin directory at: ${binDir}`);
29
+ await fs.ensureDir(binDir);
30
+ console.log('Bin directory created successfully');
31
+
32
+ // Create a README file in the bin directory
33
+ const readmePath = path.join(binDir, 'README.md');
34
+ const readmeContent = `# Probe Binary Directory
35
+
36
+ This directory is used to store the downloaded probe binary.
37
+
38
+ The binary is automatically downloaded during package installation.
39
+ If you encounter any issues with the download, you can manually place the probe binary in this directory.
40
+
41
+ Binary name should be:
42
+ - \`probe\` (on Linux/macOS)
43
+ - \`probe.exe\` (on Windows)
44
+
45
+ You can download the binary from: https://github.com/probelabs/probe/releases
46
+ `;
47
+
48
+ await fs.writeFile(readmePath, readmeContent);
49
+ console.log('Created README file in bin directory');
50
+
51
+ // Create a .gitignore file to ignore binaries but keep the directory
52
+ const gitignorePath = path.join(binDir, '.gitignore');
53
+ const gitignoreContent = `# Ignore all files in this directory
54
+ *
55
+ # Except these files
56
+ !.gitignore
57
+ !.gitkeep
58
+ !README.md
59
+ !probe
60
+ `;
61
+
62
+ await fs.writeFile(gitignorePath, gitignoreContent);
63
+ console.log('Created .gitignore file in bin directory');
64
+
65
+ // Download the probe binary
66
+ console.log('Downloading probe binary...');
67
+ try {
68
+ // Try to get the package version
69
+ let packageVersion = '0.0.0';
70
+ const possiblePaths = [
71
+ path.resolve(__dirname, '..', 'package.json'), // When installed from npm: scripts/../package.json
72
+ path.resolve(__dirname, '..', '..', 'package.json') // In development: scripts/../../package.json
73
+ ];
74
+
75
+ for (const packageJsonPath of possiblePaths) {
76
+ try {
77
+ if (fs.existsSync(packageJsonPath)) {
78
+ console.log(`Found package.json at: ${packageJsonPath}`);
79
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
80
+ if (packageJson.version) {
81
+ packageVersion = packageJson.version;
82
+ console.log(`Using version from package.json: ${packageVersion}`);
83
+ break;
84
+ }
85
+ }
86
+ } catch (err) {
87
+ console.error(`Error reading package.json at ${packageJsonPath}:`, err);
88
+ }
89
+ }
90
+
91
+ // Download the binary
92
+ const binaryPath = await downloadProbeBinary(packageVersion);
93
+ console.log(`Successfully downloaded probe binary to: ${binaryPath}`);
94
+
95
+ // Get the path to the placeholder binary
96
+ const isWindows = process.platform === 'win32';
97
+ const placeholderBinaryName = 'probe' + (isWindows ? '.exe' : '');
98
+ const placeholderBinaryPath = path.join(binDir, placeholderBinaryName);
99
+
100
+ // Replace the placeholder binary with the actual binary
101
+ if (binaryPath !== placeholderBinaryPath) {
102
+ console.log(`Replacing placeholder binary at ${placeholderBinaryPath} with actual binary from ${binaryPath}`);
103
+ await fs.copyFile(binaryPath, placeholderBinaryPath);
104
+ await fs.chmod(placeholderBinaryPath, 0o755); // Make it executable
105
+ }
106
+
107
+ console.log('\nProbe binary was successfully downloaded and installed during installation.');
108
+ console.log('You can now use the probe command directly from the command line.');
109
+ } catch (error) {
110
+ console.error('Error downloading probe binary:', error);
111
+ console.error('\nNote: The probe binary will need to be downloaded when you first use the package.');
112
+ console.error('If you encounter any issues, you can manually place the binary in the bin directory.');
113
+ console.error('You can download it from: https://github.com/probelabs/probe/releases');
114
+
115
+ // Don't fail the installation, just warn the user
116
+ return;
117
+ }
118
+ } catch (error) {
119
+ console.error(`Error in postinstall script: ${error.message}`);
120
+ console.error('You may need to manually create the bin directory or run with elevated privileges.');
121
+ }
122
+ }
123
+
124
+ // Execute the main function
125
+ main().catch(error => {
126
+ console.error('Unexpected error during postinstall:', error);
127
+ });
package/src/cli.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI wrapper for the probe binary
5
+ *
6
+ * This script ensures the probe binary is downloaded and then executes it with the provided arguments.
7
+ * It's designed to be as lightweight as possible, essentially just passing through to the actual binary.
8
+ */
9
+
10
+ import { spawn } from 'child_process';
11
+ import { getBinaryPath } from './utils.js';
12
+
13
+ /**
14
+ * Main function
15
+ */
16
+ async function main() {
17
+ try {
18
+ // Get the path to the probe binary (this will download it if needed)
19
+ const binaryPath = await getBinaryPath();
20
+
21
+ // Get the arguments passed to the CLI
22
+ const args = process.argv.slice(2);
23
+
24
+ // Spawn the probe binary with the provided arguments
25
+ const probeProcess = spawn(binaryPath, args, {
26
+ stdio: 'inherit' // Pipe stdin/stdout/stderr to the parent process
27
+ });
28
+
29
+ // Handle process exit
30
+ probeProcess.on('close', (code) => {
31
+ process.exit(code);
32
+ });
33
+
34
+ // Handle process errors
35
+ probeProcess.on('error', (error) => {
36
+ console.error(`Error executing probe binary: ${error.message}`);
37
+ process.exit(1);
38
+ });
39
+ } catch (error) {
40
+ console.error(`Error: ${error.message}`);
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+ // Execute the main function
46
+ main().catch(error => {
47
+ console.error(`Unexpected error: ${error.message}`);
48
+ process.exit(1);
49
+ });