Skip to content

Commit a9d6c10

Browse files
committed
feat: rename npm package to @coralogix/protofetch
Renames the npm package from `cx-protofetch` to `@coralogix/protofetch` to align with the Coralogix organization. Includes a deprecation notice for the old package name to inform users about the change. Updates the CI workflow to publish both the old and new packages during the transition. FEC-1000
1 parent e45b641 commit a9d6c10

File tree

14 files changed

+319
-14
lines changed

14 files changed

+319
-14
lines changed

.github/npm/.gitignore renamed to .github/npm/coralogix-protofetch/.gitignore

File renamed without changes.

.github/npm/getBinary.js renamed to .github/npm/coralogix-protofetch/getBinary.js

File renamed without changes.

.github/npm/package.json renamed to .github/npm/coralogix-protofetch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cx-protofetch",
2+
"name": "@coralogix/protofetch",
33
"version": "VERSION#TO#REPLACE",
44
"description": "A source dependency management tool for Protobuf.",
55
"repository": "https://github.com/coralogix/protofetch.git",

.github/npm/scripts.js renamed to .github/npm/coralogix-protofetch/scripts.js

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/package-lock.json
2+
/node_modules/
3+
/bin/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
console.log('\x1b[33m%s\x1b[0m', `
2+
╔═══════════════════════════════════════════════════════════════╗
3+
║ ║
4+
║ DEPRECATION NOTICE ║
5+
║ ║
6+
║ This package has been replaced by "@coralogix/protofetch" ║
7+
║ ║
8+
║ Please update your package.json to use: ║
9+
║ "@coralogix/protofetch" instead of "cx-protofetch" ║
10+
║ ║
11+
╚═══════════════════════════════════════════════════════════════╝
12+
`);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { mkdirSync, chmodSync, existsSync, readFileSync } from 'node:fs';
2+
import { fileURLToPath } from 'node:url';
3+
import { dirname, join } from 'node:path';
4+
import { pipeline } from 'node:stream/promises';
5+
import * as tar from 'tar';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
9+
10+
function isPlatform(platform, arch) {
11+
return process.platform === platform && process.arch === arch;
12+
}
13+
14+
function getPlatform() {
15+
if (isPlatform('win32', 'x64')) return 'x86_64-pc-windows-msvc';
16+
if (isPlatform('linux', 'x64')) return 'x86_64-unknown-linux-musl';
17+
if (isPlatform('linux', 'arm64')) return 'aarch64-unknown-linux-musl';
18+
if (isPlatform('darwin', 'x64')) return 'x86_64-apple-darwin';
19+
if (isPlatform('darwin', 'arm64')) return 'aarch64-apple-darwin';
20+
21+
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}. Please create an issue at https://github.com/coralogix/protofetch/issues`);
22+
}
23+
24+
function getVersion() {
25+
const packageJsonPath = join(__dirname, 'package.json');
26+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
27+
return packageJson.version;
28+
}
29+
30+
async function downloadBinary(options = {}) {
31+
const platform = getPlatform();
32+
const version = getVersion();
33+
34+
// Support custom URL for testing (not exposed via postinstall, only via direct script call)
35+
const url = options.url || `https://github.com/coralogix/protofetch/releases/download/v${version}/protofetch_${platform}.tar.gz`;
36+
37+
const binDir = join(__dirname, 'bin');
38+
const isWindows = process.platform === 'win32';
39+
const binaryName = isWindows ? 'protofetch.exe' : 'protofetch';
40+
const binaryPath = join(binDir, binaryName);
41+
42+
if (!existsSync(binDir)) {
43+
mkdirSync(binDir, { recursive: true });
44+
}
45+
46+
console.log(`Downloading protofetch binary from ${url}...`);
47+
48+
let lastError;
49+
for (let attempt = 1; attempt <= 3; attempt++) {
50+
try {
51+
const response = await fetch(url, {
52+
redirect: 'follow'
53+
});
54+
55+
if (!response.ok) {
56+
throw new Error(`Failed to download binary (HTTP ${response.status}): ${response.statusText}`);
57+
}
58+
59+
await pipeline(
60+
response.body,
61+
tar.extract({
62+
cwd: binDir,
63+
strip: 1,
64+
strict: true,
65+
preservePaths: false,
66+
preserveOwner: false,
67+
filter: (path, entry) => {
68+
const allowedFiles = ['protofetch', 'protofetch.exe'];
69+
const fileName = path.split('/').pop();
70+
return entry.type === 'File' && allowedFiles.includes(fileName);
71+
}
72+
})
73+
);
74+
75+
if (!isWindows && existsSync(binaryPath)) {
76+
chmodSync(binaryPath, 0o755);
77+
}
78+
79+
if (existsSync(binaryPath)) {
80+
console.log('protofetch binary installed successfully');
81+
return;
82+
} else {
83+
throw new Error(`Binary extraction failed - ${binaryName} not found after extraction`);
84+
}
85+
} catch (error) {
86+
lastError = error;
87+
if (attempt < 3) {
88+
console.log(`Download attempt ${attempt} failed, retrying...`);
89+
await new Promise(resolve => setTimeout(resolve, attempt * 1000));
90+
}
91+
}
92+
}
93+
94+
throw new Error(`Failed to download protofetch after 3 attempts: ${lastError.message}`);
95+
}
96+
97+
export { downloadBinary };
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "cx-protofetch",
3+
"version": "VERSION#TO#REPLACE",
4+
"description": "A source dependency management tool for Protobuf.",
5+
"repository": "https://github.com/coralogix/protofetch.git",
6+
"homepage": "https://github.com/coralogix/protofetch",
7+
"license": "Apache-2.0",
8+
"type": "module",
9+
"bin": {
10+
"protofetch": "run.js"
11+
},
12+
"scripts": {
13+
"postinstall": "node deprecation-notice.js && node scripts.js install"
14+
},
15+
"engines": {
16+
"node": ">=20.0.0"
17+
},
18+
"dependencies": {
19+
"tar": "^7.4.3"
20+
},
21+
"keywords": [
22+
"proto",
23+
"cli",
24+
"toml",
25+
"protobuf",
26+
"dependencies",
27+
"dependency-manager",
28+
"grpc"
29+
],
30+
"main": "index.js"
31+
}

.github/npm/cx-protofetch/run.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
import { spawn } from 'node:child_process';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const isWindows = process.platform === 'win32';
10+
const binaryName = isWindows ? 'protofetch.exe' : 'protofetch';
11+
const binaryPath = path.join(__dirname, 'bin', binaryName);
12+
13+
const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
14+
15+
child.on('error', (error) => {
16+
console.error(`Failed to start protofetch: ${error.message}`);
17+
console.error('The binary may be missing or corrupted. Try reinstalling the package:');
18+
console.error(' npm install --force');
19+
console.error(' or');
20+
console.error(' pnpm install --force');
21+
process.exit(1);
22+
});
23+
24+
child.on('close', (code) => {
25+
process.exit(code);
26+
});

0 commit comments

Comments
 (0)