Skip to content

Commit 34d385c

Browse files
committed
feat: enhance socket build script with spinners and structured logging
Improve build output with: - withSpinner for all long-running operations with shimmer effects - logger.group() and logger.groupEnd() for structured output sections - logger.substep() for detailed progress within groups This provides better visual feedback during builds with organized, hierarchical output and smooth shimmer animations.
1 parent 49e8da3 commit 34d385c

File tree

1 file changed

+91
-51
lines changed

1 file changed

+91
-51
lines changed

packages/socket/scripts/build.mjs

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import path from 'node:path'
1414
import { fileURLToPath } from 'node:url'
1515

1616
import { build } from 'esbuild'
17+
import { getSpinner } from '@socketsecurity/lib/constants/process'
1718
import { WIN32 } from '@socketsecurity/lib/constants/platform'
1819
import { logger } from '@socketsecurity/lib/logger'
20+
import { Spinner, withSpinner } from '@socketsecurity/lib/spinner'
1921
import { spawn } from '@socketsecurity/lib/spawn'
2022

2123
import seaConfig from './esbuild.bootstrap.config.mjs'
@@ -36,118 +38,156 @@ async function ensureBootstrapPackageBuilt() {
3638
'packages/bootstrap/dist/bootstrap-npm.js'
3739
)
3840

41+
logger.group('Checking bootstrap package')
42+
3943
// Check if bootstrap source and dist exist.
4044
if (!existsSync(bootstrapSource)) {
41-
logger.error('✗ Bootstrap source not found:', bootstrapSource)
45+
logger.groupEnd()
46+
logger.error('Bootstrap source not found:', bootstrapSource)
4247
process.exit(1)
4348
}
4449

4550
// If dist exists, assume it's up to date.
4651
if (existsSync(bootstrapDist)) {
52+
logger.substep('Bootstrap package already built')
53+
logger.groupEnd()
4754
return
4855
}
4956

50-
logger.log('→ Building @socketsecurity/bootstrap package (dependency)...\n')
57+
logger.substep('Bootstrap package needs building')
58+
logger.groupEnd()
59+
60+
const result = await withSpinner({
61+
message: 'Building @socketsecurity/bootstrap package',
62+
spinner: Spinner({ shimmer: { dir: 'ltr' } }),
63+
operation: async () => {
64+
const spawnResult = await spawn(
65+
'pnpm',
66+
['--filter', '@socketsecurity/bootstrap', 'run', 'build'],
67+
{
68+
cwd: monorepoRoot,
69+
shell: WIN32,
70+
stdio: 'pipe',
71+
}
72+
)
73+
74+
if (spawnResult.code !== 0) {
75+
throw new Error('Failed to build @socketsecurity/bootstrap')
76+
}
5177

52-
const result = await spawn(
53-
'pnpm',
54-
['--filter', '@socketsecurity/bootstrap', 'run', 'build'],
55-
{
56-
cwd: monorepoRoot,
57-
shell: WIN32,
58-
stdio: 'inherit',
59-
}
60-
)
78+
return spawnResult
79+
},
80+
})
6181

6282
if (result.code !== 0) {
63-
logger.error('\n✗ Failed to build @socketsecurity/bootstrap')
83+
logger.error('Failed to build @socketsecurity/bootstrap')
6484
process.exit(1)
6585
}
66-
67-
logger.log('')
6886
}
6987

7088
async function copyFilesFromRepoRoot() {
71-
logger.log('→ Copying files from repo root...')
72-
7389
const filesToCopy = [
7490
'CHANGELOG.md',
7591
'LICENSE',
7692
'logo-dark.png',
7793
'logo-light.png',
7894
]
7995

80-
for (const file of filesToCopy) {
81-
const srcPath = path.join(monorepoRoot, file)
82-
const destPath = path.join(packageRoot, file)
83-
84-
try {
85-
await fs.cp(srcPath, destPath)
86-
logger.log(` ✓ ${file}`)
87-
} catch (error) {
88-
logger.error(` ✗ Failed to copy ${file}:`, error.message)
89-
throw error
90-
}
91-
}
96+
await withSpinner({
97+
message: 'Copying files from repo root',
98+
spinner: Spinner({ shimmer: { dir: 'ltr' } }),
99+
operation: async () => {
100+
logger.group('Copying assets')
101+
102+
for (const file of filesToCopy) {
103+
const srcPath = path.join(monorepoRoot, file)
104+
const destPath = path.join(packageRoot, file)
105+
106+
try {
107+
await fs.cp(srcPath, destPath)
108+
logger.substep(`Copied ${file}`)
109+
} catch (error) {
110+
logger.groupEnd()
111+
throw new Error(`Failed to copy ${file}: ${error.message}`)
112+
}
113+
}
92114

93-
logger.log('✓ Files copied from repo root\n')
115+
logger.groupEnd()
116+
},
117+
})
94118
}
95119

96120
async function buildBootstrap() {
97-
logger.log('Building Socket npm wrapper bootstrap with esbuild...\n')
121+
logger.group('Building bootstrap bundles')
98122

99123
try {
100124
// Create dist directory.
125+
logger.substep('Creating dist directory')
101126
mkdirSync(path.join(packageRoot, 'dist'), { recursive: true })
102127

103128
// Build standard version for SEA.
104-
logger.log('→ Building standard bootstrap (SEA)...')
105-
const seaResult = await build(seaConfig)
106-
107-
logger.log(`✓ ${seaConfig.outfile}`)
129+
const seaResult = await withSpinner({
130+
message: 'Building standard bootstrap (SEA)',
131+
spinner: Spinner({ shimmer: { dir: 'ltr' } }),
132+
operation: async () => {
133+
const result = await build(seaConfig)
134+
return result
135+
},
136+
})
108137

109138
if (seaResult.metafile) {
110139
const outputSize = Object.values(seaResult.metafile.outputs)[0]?.bytes
111140
if (outputSize) {
112-
logger.log(` Size: ${(outputSize / 1024).toFixed(2)} KB`)
141+
logger.substep(`SEA bundle: ${(outputSize / 1024).toFixed(2)} KB`)
113142
}
114143
}
115144

116145
// Build transformed version for smol.
117-
logger.log('\n→ Building transformed bootstrap (smol)...')
118-
const smolResult = await build(smolConfig)
119-
120-
// Write the transformed output (build had write: false).
121-
if (smolResult.outputFiles && smolResult.outputFiles.length > 0) {
122-
for (const output of smolResult.outputFiles) {
123-
writeFileSync(output.path, output.contents)
124-
}
125-
}
126-
127-
logger.log(`✓ ${smolConfig.outfile}`)
146+
const smolResult = await withSpinner({
147+
message: 'Building transformed bootstrap (smol)',
148+
spinner: Spinner({ shimmer: { dir: 'ltr' } }),
149+
operation: async () => {
150+
const result = await build(smolConfig)
151+
152+
// Write the transformed output (build had write: false).
153+
if (result.outputFiles && result.outputFiles.length > 0) {
154+
for (const output of result.outputFiles) {
155+
writeFileSync(output.path, output.contents)
156+
}
157+
}
158+
159+
return result
160+
},
161+
})
128162

129163
if (smolResult.metafile) {
130164
const outputSize = Object.values(smolResult.metafile.outputs)[0]?.bytes
131165
if (outputSize) {
132-
logger.log(` Size: ${(outputSize / 1024).toFixed(2)} KB`)
166+
logger.substep(`Smol bundle: ${(outputSize / 1024).toFixed(2)} KB`)
133167
}
134168
}
135169

136-
logger.log('\n✓ Bootstrap build completed')
170+
logger.groupEnd()
137171
} catch (error) {
138-
logger.error('\n✗ Bootstrap build failed:', error)
172+
logger.groupEnd()
173+
logger.error('Bootstrap build failed:', error)
139174
throw error
140175
}
141176
}
142177

143178
async function main() {
179+
logger.group('Socket Package Build')
180+
144181
try {
145182
await ensureBootstrapPackageBuilt()
146183
await buildBootstrap()
147184
await copyFilesFromRepoRoot()
148-
logger.log('✓ Build completed successfully')
185+
186+
logger.groupEnd()
187+
logger.success('Build completed successfully')
149188
} catch (error) {
150-
logger.error('✗ Build failed:', error)
189+
logger.groupEnd()
190+
logger.error('Build failed:', error)
151191
process.exit(1)
152192
}
153193
}

0 commit comments

Comments
 (0)