Skip to content

Commit fd87f2d

Browse files
committed
Add deprecation script for old win32 package names
Adds templates and script to publish deprecated @socketbin/cli-win32-* packages that redirect users to the new @socketbin/cli-win-* packages. Run manually after publishing the new win packages: node scripts/publish-deprecated-win32-packages.mjs --version=2.2.0
1 parent 3a4b36e commit fd87f2d

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @socketbin/cli-{{OLD_PLATFORM}}-{{ARCH}}
2+
3+
> **DEPRECATED**: This package has been renamed to `@socketbin/cli-{{NEW_PLATFORM}}-{{ARCH}}`.
4+
5+
Please install the new package instead:
6+
7+
```bash
8+
npm install @socketbin/cli-{{NEW_PLATFORM}}-{{ARCH}}
9+
```
10+
11+
This package is a placeholder that depends on the new package for backwards compatibility.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@socketbin/cli-{{OLD_PLATFORM}}-{{ARCH}}",
3+
"version": "0.0.0-replaced-by-publish",
4+
"description": "DEPRECATED: Use @socketbin/cli-{{NEW_PLATFORM}}-{{ARCH}} instead",
5+
"deprecated": "This package has been renamed. Please install @socketbin/cli-{{NEW_PLATFORM}}-{{ARCH}} instead.",
6+
"license": "MIT",
7+
"dependencies": {
8+
"@socketbin/cli-{{NEW_PLATFORM}}-{{ARCH}}": "*"
9+
},
10+
"os": [
11+
"{{OS}}"
12+
],
13+
"cpu": [
14+
"{{CPU}}"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/SocketDev/socket-cli.git"
19+
},
20+
"publishConfig": {
21+
"access": "public"
22+
}
23+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Publish deprecated @socketbin/cli-win32-* packages that redirect to cli-win-*.
4+
*
5+
* This is a one-time script to publish placeholder packages for the old win32 naming.
6+
* These packages depend on the new win-* packages for backwards compatibility.
7+
*
8+
* Usage:
9+
* node scripts/publish-deprecated-win32-packages.mjs --version=2.2.0 [--dry-run]
10+
*/
11+
12+
import { existsSync, promises as fs } from 'node:fs'
13+
import path from 'node:path'
14+
15+
import { parseArgs } from '@socketsecurity/lib/argv/parse'
16+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
17+
import { spawn } from '@socketsecurity/lib/spawn'
18+
19+
const logger = getDefaultLogger()
20+
21+
const DEPRECATED_PACKAGES = [
22+
{ oldPlatform: 'win32', newPlatform: 'win', arch: 'arm64', os: 'win32', cpu: 'arm64' },
23+
{ oldPlatform: 'win32', newPlatform: 'win', arch: 'x64', os: 'win32', cpu: 'x64' },
24+
]
25+
26+
const TEMPLATE_DIR = new URL(
27+
'../packages/package-builder/templates/socketbin-deprecated',
28+
import.meta.url,
29+
).pathname
30+
31+
const BUILD_DIR = new URL(
32+
'../packages/package-builder/build/deprecated',
33+
import.meta.url,
34+
).pathname
35+
36+
async function processTemplate(templatePath, context) {
37+
let content = await fs.readFile(templatePath, 'utf-8')
38+
for (const [key, value] of Object.entries(context)) {
39+
content = content.replaceAll(`{{${key}}}`, value)
40+
}
41+
return content
42+
}
43+
44+
async function generatePackage(config, version) {
45+
const { oldPlatform, newPlatform, arch, os, cpu } = config
46+
const packageName = `socketbin-cli-${oldPlatform}-${arch}`
47+
const packageDir = path.join(BUILD_DIR, packageName)
48+
49+
const context = {
50+
OLD_PLATFORM: oldPlatform,
51+
NEW_PLATFORM: newPlatform,
52+
ARCH: arch,
53+
OS: os,
54+
CPU: cpu,
55+
}
56+
57+
await fs.mkdir(packageDir, { recursive: true })
58+
59+
// Generate package.json.
60+
let packageJson = await processTemplate(
61+
path.join(TEMPLATE_DIR, 'package.json.template'),
62+
context,
63+
)
64+
// Set version.
65+
packageJson = packageJson.replace(
66+
'"version": "0.0.0-replaced-by-publish"',
67+
`"version": "${version}"`,
68+
)
69+
await fs.writeFile(path.join(packageDir, 'package.json'), packageJson)
70+
71+
// Generate README.md.
72+
const readme = await processTemplate(
73+
path.join(TEMPLATE_DIR, 'README.md.template'),
74+
context,
75+
)
76+
await fs.writeFile(path.join(packageDir, 'README.md'), readme)
77+
78+
return { packageDir, packageName }
79+
}
80+
81+
async function publishPackage(packageDir, dryRun) {
82+
if (dryRun) {
83+
logger.log(` [DRY RUN] Would publish from ${packageDir}`)
84+
return true
85+
}
86+
87+
const result = await spawn(
88+
'npm',
89+
['publish', '--provenance', '--access', 'public', '--tag', 'deprecated'],
90+
{ cwd: packageDir, stdio: 'pipe' },
91+
)
92+
93+
return result.code === 0
94+
}
95+
96+
async function main() {
97+
const { values } = parseArgs({
98+
options: {
99+
'dry-run': { type: 'boolean', default: false },
100+
version: { type: 'string' },
101+
},
102+
})
103+
104+
const { 'dry-run': dryRun, version } = values
105+
106+
if (!version) {
107+
logger.error('Usage: publish-deprecated-win32-packages.mjs --version=X.Y.Z [--dry-run]')
108+
process.exitCode = 1
109+
return
110+
}
111+
112+
logger.log('')
113+
logger.log('Publishing deprecated @socketbin/cli-win32-* packages')
114+
logger.log('='.repeat(50))
115+
if (dryRun) {
116+
logger.log('[DRY RUN MODE]')
117+
}
118+
logger.log('')
119+
120+
// Verify template exists.
121+
if (!existsSync(TEMPLATE_DIR)) {
122+
logger.error(`Template directory not found: ${TEMPLATE_DIR}`)
123+
process.exitCode = 1
124+
return
125+
}
126+
127+
// Clean build dir.
128+
await fs.rm(BUILD_DIR, { recursive: true, force: true })
129+
130+
const results = { passed: [], failed: [] }
131+
132+
for (const config of DEPRECATED_PACKAGES) {
133+
const { packageDir, packageName } = await generatePackage(config, version)
134+
logger.log(`Generated ${packageName}`)
135+
136+
const success = await publishPackage(packageDir, dryRun)
137+
if (success) {
138+
results.passed.push(packageName)
139+
logger.log(` Published @socketbin/cli-${config.oldPlatform}-${config.arch}`)
140+
} else {
141+
results.failed.push(packageName)
142+
logger.error(` Failed to publish @socketbin/cli-${config.oldPlatform}-${config.arch}`)
143+
}
144+
}
145+
146+
logger.log('')
147+
logger.log('Summary')
148+
logger.log('='.repeat(50))
149+
logger.log(`Published: ${results.passed.length}/${DEPRECATED_PACKAGES.length}`)
150+
if (results.failed.length > 0) {
151+
logger.error(`Failed: ${results.failed.join(', ')}`)
152+
process.exitCode = 1
153+
}
154+
}
155+
156+
main().catch(e => {
157+
logger.error('Failed:', e.message)
158+
process.exitCode = 1
159+
})

0 commit comments

Comments
 (0)