Skip to content

Commit 23b7129

Browse files
committed
Refactor publish script to check for existing npm version before publishing, and update package.json script name for clarity. Update README to reflect new script name.
1 parent 05f21d6 commit 23b7129

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

npx/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ npm run publish:npx
120120
**From npx directory:**
121121
```bash
122122
cd npx
123-
npm run publish
123+
npm run publish:package
124124
```
125125

126126
Or run directly:

npx/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "run-claude-artifact",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Run Claude AI Artifacts locally - quick preview, or create projects, build, deploy, and push to a Git repository.",
55
"bin": {
66
"run-claude-artifact": "./run-claude-artifact.js"
77
},
88
"scripts": {
99
"build": "echo \"nothing to build\"",
1010
"test": "node run-claude-artifact.js --help",
11-
"publish": "node publish.js"
11+
"publish:package": "node publish.js"
1212
},
1313
"author": "Cláudio Silva",
1414
"license": "MIT",

npx/publish.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,32 @@ async function main() {
116116
}
117117
}
118118

119-
// Step 6: Run npm publish
119+
// Step 6: Check if version already exists on npm
120+
console.log('\n🔍 Checking if version already exists on npm...');
121+
try {
122+
const npmViewOutput = execSync(`npm view ${require('./package.json').name}@${newVersion} version`, {
123+
encoding: 'utf8',
124+
stdio: 'pipe',
125+
cwd: __dirname
126+
});
127+
if (npmViewOutput.trim() === newVersion) {
128+
console.log(`⚠️ Version ${newVersion} already exists on npm.`);
129+
const continueAnswer = await question('Do you want to publish anyway? (y/n): ');
130+
if (continueAnswer.toLowerCase() !== 'y' && continueAnswer.toLowerCase() !== 'yes') {
131+
console.log('❌ Publishing cancelled.');
132+
process.exit(0);
133+
}
134+
}
135+
} catch (err) {
136+
// Version doesn't exist, which is fine - we can proceed
137+
console.log(`✅ Version ${newVersion} is available for publishing.`);
138+
}
139+
140+
// Step 7: Run npm publish
120141
console.log('\n🚀 Publishing to npm...');
121142
process.chdir(__dirname);
122-
execSync('npm publish --access public', { stdio: 'inherit' });
143+
// Use --ignore-scripts to prevent npm from running lifecycle hooks that might cause loops
144+
execSync('npm publish --access public --ignore-scripts', { stdio: 'inherit' });
123145
console.log('\n✅ Published successfully!');
124146

125147
} catch (error) {

0 commit comments

Comments
 (0)