Skip to content

Commit 754cef2

Browse files
committed
Replace deprecated script with placeholder script for new win packages
Remove deprecated win32 template and script (use npm deprecate instead). Add script to publish placeholder @socketbin/cli-win-* packages for trusted publishing setup. Usage: node scripts/publish-win-placeholder-packages.mjs [--dry-run] After publishing, deprecate old packages: npm deprecate "@socketbin/cli-win32-x64@*" "Use @socketbin/cli-win-x64" npm deprecate "@socketbin/cli-win32-arm64@*" "Use @socketbin/cli-win-arm64"
1 parent fd87f2d commit 754cef2

File tree

4 files changed

+168
-193
lines changed

4 files changed

+168
-193
lines changed

packages/package-builder/templates/socketbin-deprecated/README.md.template

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/package-builder/templates/socketbin-deprecated/package.json.template

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/publish-deprecated-win32-packages.mjs

Lines changed: 0 additions & 159 deletions
This file was deleted.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Publish placeholder @socketbin/cli-win-* packages for trusted publishing setup.
4+
*
5+
* This is a one-time script to publish initial placeholder packages for the new
6+
* win-* naming convention. After this, the provenance workflow can use trusted
7+
* publishing.
8+
*
9+
* Usage:
10+
* node scripts/publish-win-placeholder-packages.mjs [--dry-run]
11+
*
12+
* After running this, deprecate the old win32 packages:
13+
* npm deprecate "@socketbin/cli-win32-x64@*" "Use @socketbin/cli-win-x64 instead"
14+
* npm deprecate "@socketbin/cli-win32-arm64@*" "Use @socketbin/cli-win-arm64 instead"
15+
*/
16+
17+
import { promises as fs } from 'node:fs'
18+
import path from 'node:path'
19+
import { fileURLToPath } from 'node:url'
20+
21+
import { parseArgs } from '@socketsecurity/lib/argv/parse'
22+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
23+
import { spawn } from '@socketsecurity/lib/spawn'
24+
25+
const logger = getDefaultLogger()
26+
27+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
28+
const BUILD_DIR = path.join(__dirname, '../packages/package-builder/build/win-placeholder')
29+
30+
const WIN_PACKAGES = [
31+
{ platform: 'win', arch: 'arm64', os: 'win32', cpu: 'arm64', description: 'Windows ARM64' },
32+
{ platform: 'win', arch: 'x64', os: 'win32', cpu: 'x64', description: 'Windows x64' },
33+
]
34+
35+
// Use a placeholder version that will be replaced by the first real publish.
36+
const PLACEHOLDER_VERSION = '0.0.0-placeholder.1'
37+
38+
async function generatePackage(config) {
39+
const { platform, arch, os, cpu, description } = config
40+
const packageName = `@socketbin/cli-${platform}-${arch}`
41+
const packageDir = path.join(BUILD_DIR, `socketbin-cli-${platform}-${arch}`)
42+
43+
await fs.mkdir(packageDir, { recursive: true })
44+
45+
const packageJson = {
46+
name: packageName,
47+
version: PLACEHOLDER_VERSION,
48+
description: `Socket CLI binary (${description}) - Placeholder for trusted publishing setup`,
49+
license: 'MIT',
50+
os: [os],
51+
cpu: [cpu],
52+
repository: {
53+
type: 'git',
54+
url: 'git+https://github.com/SocketDev/socket-cli.git',
55+
},
56+
publishConfig: {
57+
access: 'public',
58+
},
59+
}
60+
61+
await fs.writeFile(
62+
path.join(packageDir, 'package.json'),
63+
JSON.stringify(packageJson, null, 2) + '\n',
64+
)
65+
66+
const readme = `# ${packageName}
67+
68+
Socket CLI binary for ${description}.
69+
70+
This is a placeholder package for trusted publishing setup.
71+
The first real version will be published via GitHub Actions with provenance.
72+
73+
## Usage
74+
75+
This package is an optional dependency of the \`socket\` package.
76+
You don't need to install it directly.
77+
78+
\`\`\`bash
79+
npm install socket
80+
\`\`\`
81+
`
82+
83+
await fs.writeFile(path.join(packageDir, 'README.md'), readme)
84+
85+
return { packageDir, packageName }
86+
}
87+
88+
async function publishPackage(packageDir, packageName, dryRun) {
89+
if (dryRun) {
90+
logger.log(` [DRY RUN] Would publish ${packageName} from ${packageDir}`)
91+
return true
92+
}
93+
94+
const result = await spawn(
95+
'npm',
96+
['publish', '--access', 'public'],
97+
{ cwd: packageDir, stdio: 'pipe' },
98+
)
99+
100+
if (result.code !== 0) {
101+
logger.error(` stdout: ${result.stdout}`)
102+
logger.error(` stderr: ${result.stderr}`)
103+
}
104+
105+
return result.code === 0
106+
}
107+
108+
async function main() {
109+
const { values } = parseArgs({
110+
options: {
111+
'dry-run': { type: 'boolean', default: false },
112+
},
113+
})
114+
115+
const dryRun = values['dry-run']
116+
117+
logger.log('')
118+
logger.log('Publishing placeholder @socketbin/cli-win-* packages')
119+
logger.log('='.repeat(55))
120+
if (dryRun) {
121+
logger.log('[DRY RUN MODE]')
122+
}
123+
logger.log('')
124+
125+
// Clean build dir.
126+
await fs.rm(BUILD_DIR, { recursive: true, force: true })
127+
await fs.mkdir(BUILD_DIR, { recursive: true })
128+
129+
const results = { passed: [], failed: [] }
130+
131+
for (const config of WIN_PACKAGES) {
132+
const { packageDir, packageName } = await generatePackage(config)
133+
logger.log(`Generated ${packageName}`)
134+
135+
const success = await publishPackage(packageDir, packageName, dryRun)
136+
if (success) {
137+
results.passed.push(packageName)
138+
logger.log(` Published ${packageName}@${PLACEHOLDER_VERSION}`)
139+
} else {
140+
results.failed.push(packageName)
141+
logger.error(` Failed to publish ${packageName}`)
142+
}
143+
}
144+
145+
logger.log('')
146+
logger.log('Summary')
147+
logger.log('='.repeat(55))
148+
logger.log(`Published: ${results.passed.length}/${WIN_PACKAGES.length}`)
149+
150+
if (results.passed.length > 0) {
151+
logger.log('')
152+
logger.log('Next steps:')
153+
logger.log('1. Set up trusted publishing in npm for these packages')
154+
logger.log('2. Deprecate old win32 packages:')
155+
logger.log(' npm deprecate "@socketbin/cli-win32-x64@*" "Use @socketbin/cli-win-x64 instead"')
156+
logger.log(' npm deprecate "@socketbin/cli-win32-arm64@*" "Use @socketbin/cli-win-arm64 instead"')
157+
}
158+
159+
if (results.failed.length > 0) {
160+
logger.error(`Failed: ${results.failed.join(', ')}`)
161+
process.exitCode = 1
162+
}
163+
}
164+
165+
main().catch(e => {
166+
logger.error('Failed:', e.message)
167+
process.exitCode = 1
168+
})

0 commit comments

Comments
 (0)