Skip to content

Commit 2c5e57c

Browse files
committed
refactor(publish): simplify package structure and validation
- Remove bin/ directory wrappers, point directly to dist/ files - Remove exports field (unnecessary for single-file bundles) - Remove shadow-bin from files array - Create package-specific verify-package.mjs scripts - Delete monolithic pre-publish-validate.mjs - Update provenance workflow to use pnpm --filter run verify - Add verify script to all 3 packages (socket, cli, cli-with-sentry) This simplifies the publish structure by removing unnecessary indirection layers and makes validation package-specific instead of trying to handle all packages in one script.
1 parent a94e8fe commit 2c5e57c

File tree

20 files changed

+384
-1082
lines changed

20 files changed

+384
-1082
lines changed

.github/workflows/provenance.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Build socket package
6262
run: INLINED_SOCKET_CLI_PUBLISHED_BUILD=1 pnpm run build
6363
- name: Validate socket package
64-
run: node scripts/pre-publish-validate.mjs packages/socket
64+
run: pnpm --filter socket run verify
6565
- name: Publish socket package
6666
working-directory: packages/socket
6767
run: npm publish --provenance --access public --no-git-checks
@@ -77,7 +77,7 @@ jobs:
7777
env:
7878
SOCKET_CLI_DEBUG: ${{ inputs.debug }}
7979
- name: Validate @socketsecurity/cli package
80-
run: node scripts/pre-publish-validate.mjs packages/cli
80+
run: pnpm --filter @socketsecurity/cli run verify
8181
- name: Publish @socketsecurity/cli package
8282
working-directory: packages/cli
8383
run: npm publish --provenance --access public --no-git-checks
@@ -93,7 +93,7 @@ jobs:
9393
env:
9494
SOCKET_CLI_DEBUG: ${{ inputs.debug }}
9595
- name: Validate @socketsecurity/cli-with-sentry package
96-
run: node scripts/pre-publish-validate.mjs packages/cli-with-sentry
96+
run: pnpm --filter @socketsecurity/cli-with-sentry run verify
9797
- name: Publish @socketsecurity/cli-with-sentry package
9898
working-directory: packages/cli-with-sentry
9999
run: npm publish --provenance --access public --no-git-checks

packages/cli-with-sentry/bin/cli.js

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

packages/cli-with-sentry/bin/npm-cli.js

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

packages/cli-with-sentry/bin/npx-cli.js

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

packages/cli-with-sentry/bin/pnpm-cli.js

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

packages/cli-with-sentry/bin/yarn-cli.js

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

packages/cli-with-sentry/package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@
1616
"url": "https://socket.dev"
1717
},
1818
"bin": {
19-
"socket": "bin/cli.js",
20-
"socket-npm": "bin/npm-cli.js",
21-
"socket-npx": "bin/npx-cli.js",
22-
"socket-pnpm": "bin/pnpm-cli.js",
23-
"socket-yarn": "bin/yarn-cli.js"
24-
},
25-
"exports": {
26-
"./bin/cli.js": "./dist/cli.js",
27-
"./bin/npm-cli.js": "./dist/npm-cli.js",
28-
"./bin/npx-cli.js": "./dist/npx-cli.js",
29-
"./bin/pnpm-cli.js": "./dist/pnpm-cli.js",
30-
"./bin/yarn-cli.js": "./dist/yarn-cli.js",
31-
"./package.json": "./package.json"
32-
},
19+
"socket": "dist/cli.js"
20+
},
21+
"files": [
22+
"data/**",
23+
"dist/**",
24+
"CHANGELOG.md",
25+
"logo-dark.png",
26+
"logo-light.png"
27+
],
3328
"scripts": {
3429
"build": "node scripts/build.mjs",
3530
"clean:dist": "del-cli 'dist'",
3631
"test": "vitest run",
37-
"test:watch": "vitest"
32+
"test:watch": "vitest",
33+
"verify": "node scripts/verify-package.mjs"
3834
},
3935
"keywords": [
4036
"socket",
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { promises as fs } from 'node:fs'
2+
import path from 'node:path'
3+
import process from 'node:process'
4+
import { fileURLToPath } from 'node:url'
5+
6+
import { logger } from '@socketsecurity/lib/logger'
7+
import colors from 'yoctocolors-cjs'
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
11+
const packageRoot = path.resolve(__dirname, '..')
12+
13+
/**
14+
* Format a success message.
15+
*/
16+
function success(msg) {
17+
return `${colors.green('✓')} ${msg}`
18+
}
19+
20+
/**
21+
* Format an error message.
22+
*/
23+
function error(msg) {
24+
return `${colors.red('✗')} ${msg}`
25+
}
26+
27+
/**
28+
* Format an info message.
29+
*/
30+
function info(msg) {
31+
return `${colors.blue('ℹ')} ${msg}`
32+
}
33+
34+
/**
35+
* Check if a file exists and is readable.
36+
*/
37+
async function fileExists(filePath) {
38+
try {
39+
await fs.access(filePath)
40+
return true
41+
} catch {
42+
return false
43+
}
44+
}
45+
46+
/**
47+
* Main validation function.
48+
*/
49+
async function validate() {
50+
logger.log('')
51+
logger.log('='.repeat(60))
52+
logger.log(`${colors.blue('CLI with Sentry Package Validation')}`)
53+
logger.log('='.repeat(60))
54+
logger.log('')
55+
56+
const errors = []
57+
58+
// Check package.json exists.
59+
logger.log(info('Checking package.json...'))
60+
const pkgPath = path.join(packageRoot, 'package.json')
61+
if (!(await fileExists(pkgPath))) {
62+
errors.push('package.json does not exist')
63+
} else {
64+
logger.log(success('package.json exists'))
65+
}
66+
67+
// Check dist/cli.js exists.
68+
logger.log(info('Checking dist/cli.js...'))
69+
const cliPath = path.join(packageRoot, 'dist', 'cli.js')
70+
if (!(await fileExists(cliPath))) {
71+
errors.push('dist/cli.js does not exist')
72+
} else {
73+
logger.log(success('dist/cli.js exists'))
74+
}
75+
76+
// Check data directory exists.
77+
logger.log(info('Checking data directory...'))
78+
const dataPath = path.join(packageRoot, 'data')
79+
if (!(await fileExists(dataPath))) {
80+
errors.push('data directory does not exist')
81+
} else {
82+
logger.log(success('data directory exists'))
83+
84+
// Check data files.
85+
const dataFiles = [
86+
'alert-translations.json',
87+
'command-api-requirements.json',
88+
]
89+
for (const file of dataFiles) {
90+
logger.log(info(`Checking data/${file}...`))
91+
const filePath = path.join(dataPath, file)
92+
if (!(await fileExists(filePath))) {
93+
errors.push(`data/${file} does not exist`)
94+
} else {
95+
logger.log(success(`data/${file} exists`))
96+
}
97+
}
98+
}
99+
100+
// Print summary.
101+
logger.log('')
102+
logger.log('='.repeat(60))
103+
logger.log(`${colors.blue('Validation Summary')}`)
104+
logger.log('='.repeat(60))
105+
logger.log('')
106+
107+
if (errors.length > 0) {
108+
logger.log(`${colors.red('Errors:')}`)
109+
for (const err of errors) {
110+
logger.log(` ${error(err)}`)
111+
}
112+
logger.log('')
113+
logger.log(error('Package validation FAILED'))
114+
logger.log('')
115+
process.exit(1)
116+
}
117+
118+
logger.log(success('Package validation PASSED'))
119+
logger.log('')
120+
process.exit(0)
121+
}
122+
123+
// Run validation.
124+
validate().catch(e => {
125+
logger.error('')
126+
logger.error(error(`Unexpected error: ${e.message}`))
127+
logger.error('')
128+
process.exit(1)
129+
})

packages/cli/bin/cli.js

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

packages/cli/bin/npm-cli.js

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

0 commit comments

Comments
 (0)