Skip to content

Commit 734277e

Browse files
authored
feat: rename npm package to @coralogix/protofetch (#172)
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.
1 parent e45b641 commit 734277e

File tree

10 files changed

+155
-21
lines changed

10 files changed

+155
-21
lines changed

.github/npm/.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/package-lock.json
2-
/node_modules/
3-
/bin/
1+
dist/
2+
package-lock.json
3+
node_modules/
4+
bin/

.github/npm/prepare-package.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync, writeFileSync, rmSync, cpSync } from 'node:fs';
4+
import { join, dirname } from 'node:path';
5+
import { fileURLToPath } from 'node:url';
6+
import { parseArgs } from 'node:util';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
10+
const DEPRECATION_NOTICE = '> ⚠️ **DEPRECATION NOTICE**: This package has been replaced by `@coralogix/protofetch`. Please update your dependencies to use the new scoped package.\n\n';
11+
12+
const PACKAGES = {
13+
'cx-protofetch': {
14+
name: 'cx-protofetch',
15+
deprecated: true
16+
},
17+
'coralogix-protofetch': {
18+
name: '@coralogix/protofetch',
19+
deprecated: false
20+
}
21+
};
22+
23+
const REPO_ROOT = join(__dirname, '..', '..');
24+
25+
function getVersionFromCargo() {
26+
const cargoToml = readFileSync(join(REPO_ROOT, 'Cargo.toml'), 'utf-8');
27+
const versionMatch = cargoToml.match(/^version\s*=\s*"([^"]+)"/m);
28+
if (!versionMatch) {
29+
throw new Error('Could not find version in Cargo.toml');
30+
}
31+
return versionMatch[1];
32+
}
33+
34+
function preparePackage(packageKey, version) {
35+
const config = PACKAGES[packageKey];
36+
if (!config) {
37+
throw new Error(`Unknown package: ${packageKey}`);
38+
}
39+
40+
const templatePath = join(__dirname, 'src');
41+
const outputPath = join(__dirname, 'dist', packageKey);
42+
43+
rmSync(outputPath, { recursive: true, force: true });
44+
45+
cpSync(templatePath, outputPath, {
46+
recursive: true,
47+
filter: src => (config.deprecated || !src.endsWith('deprecation-notice.js'))
48+
});
49+
50+
const packageJsonPath = join(outputPath, 'package.json');
51+
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
52+
53+
if (config.deprecated) {
54+
pkg.scripts.postinstall = 'node deprecation-notice.js && node scripts.js install';
55+
}
56+
57+
const orderedPkg = {
58+
name: config.name,
59+
version,
60+
...pkg
61+
};
62+
63+
writeFileSync(packageJsonPath, JSON.stringify(orderedPkg, null, 2) + '\n', 'utf-8');
64+
65+
const mainReadme = readFileSync(join(REPO_ROOT, 'README.md'), 'utf-8');
66+
const readmeContent = config.deprecated ? DEPRECATION_NOTICE + mainReadme : mainReadme;
67+
writeFileSync(join(outputPath, 'README.md'), readmeContent, 'utf-8');
68+
69+
console.log(`✓ Package ${packageKey} prepared (${config.name} v${version})${config.deprecated ? ' with deprecation notice' : ''}`);
70+
71+
return outputPath;
72+
}
73+
74+
const { values } = parseArgs({
75+
options: {
76+
package: {
77+
type: 'string',
78+
short: 'p'
79+
},
80+
version: {
81+
type: 'string',
82+
short: 'v'
83+
}
84+
},
85+
strict: true
86+
});
87+
88+
const packageKey = values.package;
89+
90+
if (!packageKey || !PACKAGES[packageKey]) {
91+
console.error('Error: Valid package key is required');
92+
console.error('Usage: node prepare-npm-package.js --package <package-key> [--version <version>]');
93+
console.error(`Available packages: ${Object.keys(PACKAGES).join(', ')}`);
94+
process.exit(1);
95+
}
96+
97+
try {
98+
const version = values.version || getVersionFromCargo();
99+
console.log(`Preparing package ${packageKey} with version ${version}...`);
100+
const outputPath = preparePackage(packageKey, version);
101+
console.log(`✓ Package ready at ${outputPath}`);
102+
} catch (error) {
103+
console.error(`Error preparing package: ${error.message}`);
104+
process.exit(1);
105+
}
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"name": "cx-protofetch",
3-
"version": "VERSION#TO#REPLACE",
42
"description": "A source dependency management tool for Protobuf.",
53
"repository": "https://github.com/coralogix/protofetch.git",
64
"homepage": "https://github.com/coralogix/protofetch",

.github/workflows/ci.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ jobs:
195195
- name: Setup test environment
196196
shell: bash
197197
run: |
198-
cd .github/npm
199-
# Replace version placeholder with test version
200-
sed 's/VERSION#TO#REPLACE/0.0.0-test/g' package.json > package.test.json
201-
mv package.test.json package.json
198+
# Prepare test package with test version
199+
node .github/npm/prepare-package.js --package coralogix-protofetch --version 0.0.0-test
202200
203201
- name: Start HTTP server
204202
shell: bash
@@ -212,7 +210,7 @@ jobs:
212210
- name: Test npm installation
213211
shell: bash
214212
run: |
215-
cd .github/npm
213+
cd .github/npm/dist/coralogix-protofetch
216214
217215
# Install dependencies
218216
npm install --ignore-scripts
@@ -233,7 +231,7 @@ jobs:
233231
- name: Test pnpm installation
234232
shell: bash
235233
run: |
236-
cd .github/npm
234+
cd .github/npm/dist/coralogix-protofetch
237235
238236
# Install dependencies
239237
pnpm install --ignore-scripts
@@ -271,15 +269,17 @@ jobs:
271269
- name: Publish cargo package
272270
run: cargo publish --token ${{ env.CRATES_IO_TOKEN }}
273271

274-
- name: Publish npm package
272+
- name: Publish npm package (cx-protofetch)
275273
run: |
276-
VERSION=$(sed -n -e '/version/ s/.* = *//p' "Cargo.toml" | head -1 | tr -d '"')
277-
export VERSION
278-
# Tee had issue to write to the same file which is used for read so creating a temp package.json file
279-
mv .github/npm/package.json .github/npm/package.json.temp
280-
sed "s/VERSION#TO#REPLACE/${VERSION}/g" .github/npm/package.json.temp | tee .github/npm/package.json
274+
node .github/npm/prepare-package.js --package cx-protofetch
281275
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ".npmrc"
282-
npm publish .github/npm
276+
npm publish .github/npm/dist/cx-protofetch
277+
278+
- name: Publish npm package (@coralogix/protofetch)
279+
run: |
280+
node .github/npm/prepare-package.js --package coralogix-protofetch
281+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ".npmrc"
282+
npm publish .github/npm/dist/coralogix-protofetch
283283
284284
- name: Download artifacts
285285
uses: actions/download-artifact@v4

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
![CI](https://github.com/coralogix/protofetch/workflows/CI/badge.svg)
33
[![Apache 2 License License](http://img.shields.io/badge/license-APACHE2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
44
[![Crates.io](https://img.shields.io/crates/v/protofetch.svg)](https://crates.io/crates/protofetch)
5-
[![npm version](https://img.shields.io/npm/v/cx-protofetch.svg??style=flat)](https://www.npmjs.com/package/cx-protofetch)
5+
[![npm version](https://img.shields.io/npm/v/@coralogix/protofetch.svg??style=flat)](https://www.npmjs.com/package/@coralogix/protofetch)
66
![GitHub Stars](https://img.shields.io/github/stars/coralogix/protofetch.svg)
77

88
A source dependency management tool for Protobuf files.
@@ -44,9 +44,21 @@ We aim to achieve at least the following goals before releasing the first stable
4444

4545
## Getting Started
4646

47-
You can download pre-built binaries from the [GitHub Releases](https://github.com/coralogix/protofetch/releases/latest) page.
47+
**npm:**
48+
```bash
49+
npm install @coralogix/protofetch
50+
```
4851

49-
Protofetch is also released to [crates.io](https://crates.io/crates/protofetch), so if you have a Rust toolchain installed, you can build Protofetch from source with `cargo install protofetch`.
52+
**Cargo:**
53+
54+
Protofetch is also released to [crates.io](https://crates.io/crates/protofetch), so if you have a Rust toolchain installed, you can build Protofetch from source with:
55+
```bash
56+
cargo install protofetch
57+
```
58+
59+
**Pre-built binaries:**
60+
61+
You can download pre-built binaries from the [GitHub Releases](https://github.com/coralogix/protofetch/releases/latest) page.
5062

5163
### Usage
5264

node_modules/.package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)