Skip to content

Commit f5e75cf

Browse files
committed
Complete script consolidation and renaming
- Rename affected → changed throughout all scripts - Consolidate --pre-commit to --staged - Change --if-needed to --needed - Change --source to --src - Add --quiet/--silent aliases for suppressing output - Rename test-affected.mjs → test-changed.mjs - Rename affected-test-mapper.mjs → changed-test-mapper.mjs - Update .husky/pre-commit to use --staged - Clean up old scripts from package.json - Update sync script with all changes
1 parent 1e478cd commit f5e75cf

File tree

7 files changed

+52
-59
lines changed

7 files changed

+52
-59
lines changed

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
if [ -z "${DISABLE_PRECOMMIT_LINT}" ]; then
2-
pnpm lint --pre-commit
2+
pnpm lint --staged
33
else
44
echo "Skipping lint due to DISABLE_PRECOMMIT_LINT env var"
55
fi
66

77
if [ -z "${DISABLE_PRECOMMIT_TEST}" ]; then
8-
dotenvx -q run -f .env.precommit -- pnpm test --pre-commit
8+
dotenvx -q run -f .env.precommit -- pnpm test --staged
99
else
1010
echo "Skipping testing due to DISABLE_PRECOMMIT_TEST env var"
1111
fi

scripts/build.mjs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ async function main() {
157157
type: 'boolean',
158158
default: false,
159159
},
160-
'if-needed': {
160+
needed: {
161+
type: 'boolean',
162+
default: false,
163+
},
164+
silent: {
161165
type: 'boolean',
162166
default: false,
163167
},
@@ -179,28 +183,31 @@ async function main() {
179183
console.log(' --src Build source code only')
180184
console.log(' --types Build TypeScript declarations only')
181185
console.log(' --watch Watch mode for development')
182-
console.log(' --if-needed Only build if dist files are missing')
183-
console.log(' --quiet Suppress progress messages')
186+
console.log(' --needed Only build if dist files are missing')
187+
console.log(' --quiet, --silent Suppress progress messages')
184188
console.log('\nExamples:')
185189
console.log(' pnpm build # Full build (source + types)')
186190
console.log(' pnpm build --src # Build source only')
187191
console.log(' pnpm build --types # Build types only')
188192
console.log(' pnpm build --watch # Watch mode')
189-
console.log(' pnpm build --if-needed # Build only if needed')
193+
console.log(' pnpm build --needed # Build only if needed')
190194
process.exitCode = 0
191195
return
192196
}
193197

198+
// Handle aliases
199+
const quiet = values.quiet || values.silent
200+
194201
// Check if build is needed
195-
if (values['if-needed'] && !isBuildNeeded()) {
196-
if (!values.quiet) {
202+
if (values.needed && !isBuildNeeded()) {
203+
if (!quiet) {
197204
log.info('Build artifacts exist, skipping build')
198205
}
199206
process.exitCode = 0
200207
return
201208
}
202209

203-
if (!values.quiet) {
210+
if (!quiet) {
204211
console.log('═══════════════════════════════════════════════════════')
205212
console.log(' Socket PackageURL Build Runner')
206213
console.log('═══════════════════════════════════════════════════════')
@@ -210,49 +217,49 @@ async function main() {
210217

211218
// Handle watch mode
212219
if (values.watch) {
213-
exitCode = await watchBuild({ quiet: values.quiet })
220+
exitCode = await watchBuild({ quiet })
214221
}
215222
// Build types only
216223
else if (values.types && !values.src) {
217-
if (!values.quiet) {
224+
if (!quiet) {
218225
log.step('Building TypeScript declarations only')
219226
}
220-
exitCode = await buildTypes({ quiet: values.quiet })
227+
exitCode = await buildTypes({ quiet })
221228
}
222229
// Build source only
223230
else if (values.src && !values.types) {
224-
if (!values.quiet) {
231+
if (!quiet) {
225232
log.step('Building source only')
226233
}
227-
exitCode = await buildSource({ quiet: values.quiet })
234+
exitCode = await buildSource({ quiet })
228235
}
229236
// Build everything (default)
230237
else {
231-
if (!values.quiet) {
238+
if (!quiet) {
232239
log.step('Building package (source + types)')
233240
}
234241

235242
// Build source first
236-
exitCode = await buildSource({ quiet: values.quiet })
243+
exitCode = await buildSource({ quiet })
237244
if (exitCode !== 0) {
238-
if (!values.quiet) {
245+
if (!quiet) {
239246
log.error('Build failed')
240247
}
241248
process.exitCode = exitCode
242249
return
243250
}
244251

245252
// Then build types
246-
exitCode = await buildTypes({ quiet: values.quiet })
253+
exitCode = await buildTypes({ quiet })
247254
}
248255

249256
if (exitCode !== 0) {
250-
if (!values.quiet) {
257+
if (!quiet) {
251258
log.error('Build failed')
252259
}
253260
process.exitCode = exitCode
254261
} else {
255-
if (!values.quiet) {
262+
if (!quiet) {
256263
console.log('\n═══════════════════════════════════════════════════════')
257264
log.success('Build completed successfully!')
258265
console.log('═══════════════════════════════════════════════════════')

scripts/lint.mjs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,22 @@ async function runLintOnAll(options = {}) {
204204
* Get files to lint based on options.
205205
*/
206206
async function getFilesToLint(options) {
207-
const { affected, all, preCommit, staged } = options
207+
const { all, changed, staged } = options
208208

209209
// If --all, return early
210210
if (all) {
211211
return { files: 'all', reason: 'all flag specified' }
212212
}
213213

214214
// Get changed files
215-
const checkStaged = staged || preCommit
216215
let changedFiles = []
217216

218-
if (checkStaged) {
217+
if (staged) {
219218
changedFiles = await getStagedFiles({ absolute: false })
220219
if (!changedFiles.length) {
221220
return { files: null, reason: 'no staged files' }
222221
}
223-
} else if (affected) {
222+
} else if (changed) {
224223
changedFiles = await getChangedFiles({ absolute: false })
225224
if (!changedFiles.length) {
226225
return { files: null, reason: 'no changed files' }
@@ -262,18 +261,14 @@ async function main() {
262261
type: 'boolean',
263262
default: false,
264263
},
265-
affected: {
264+
changed: {
266265
type: 'boolean',
267266
default: false,
268267
},
269268
staged: {
270269
type: 'boolean',
271270
default: false,
272271
},
273-
'pre-commit': {
274-
type: 'boolean',
275-
default: false,
276-
},
277272
quiet: {
278273
type: 'boolean',
279274
default: false,
@@ -291,14 +286,13 @@ async function main() {
291286
console.log(' --help Show this help message')
292287
console.log(' --fix Automatically fix problems')
293288
console.log(' --all Lint all files (default if no target specified)')
294-
console.log(' --affected Lint files affected by changes')
289+
console.log(' --changed Lint changed files')
295290
console.log(' --staged Lint staged files')
296-
console.log(' --pre-commit Lint staged files (alias for --staged)')
297291
console.log(' --quiet Suppress progress messages')
298292
console.log('\nExamples:')
299293
console.log(' pnpm lint # Lint all files')
300294
console.log(' pnpm lint --fix # Fix all linting issues')
301-
console.log(' pnpm lint --affected # Lint changed files')
295+
console.log(' pnpm lint --changed # Lint changed files')
302296
console.log(' pnpm lint --staged --fix # Fix issues in staged files')
303297
console.log(' pnpm lint src/index.ts # Lint specific file(s)')
304298
process.exitCode = 0

scripts/sync-scripts.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const SOCKET_PROJECTS = [
2020

2121
const FILES_TO_SYNC = [
2222
'scripts/test.mjs',
23-
'scripts/test-affected.mjs',
23+
'scripts/test-changed.mjs',
2424
'scripts/lint.mjs',
2525
'scripts/build.mjs',
26-
'scripts/utils/affected-test-mapper.mjs',
26+
'scripts/utils/changed-test-mapper.mjs',
2727
]
2828

2929
async function fileExists(filepath) {
@@ -67,17 +67,21 @@ async function updatePackageJson(projectPath) {
6767
const toRemove = [
6868
'test:quick',
6969
'test:coverage',
70-
'test:affected',
7170
'test:unit',
7271
'test:unit:coverage',
7372
'test:unit:update',
7473
'test-pre-commit',
7574
'pretest:unit',
7675
'test:old',
76+
'test:affected',
77+
'test-affected',
7778
'build:src',
7879
'build:types',
7980
'build:src-only',
8081
'build:types-only',
82+
'build:dist',
83+
'build:dist:src',
84+
'build:dist:types',
8185
]
8286

8387
for (const script of toRemove) {
@@ -102,13 +106,13 @@ async function updateHuskyPreCommit(projectPath) {
102106
}
103107

104108
const newContent = `if [ -z "\${DISABLE_PRECOMMIT_LINT}" ]; then
105-
pnpm lint --pre-commit
109+
pnpm lint --staged
106110
else
107111
echo "Skipping lint due to DISABLE_PRECOMMIT_LINT env var"
108112
fi
109113
110114
if [ -z "\${DISABLE_PRECOMMIT_TEST}" ]; then
111-
dotenvx -q run -f .env.precommit -- pnpm test --pre-commit
115+
dotenvx -q run -f .env.precommit -- pnpm test --staged
112116
else
113117
echo "Skipping testing due to DISABLE_PRECOMMIT_TEST env var"
114118
fi
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview Affected test runner that runs only tests affected by changes.
2+
* @fileoverview Changed test runner that runs only tests affected by changes.
33
* Uses git utilities to detect changes and maps them to relevant test files.
44
*/
55

@@ -12,7 +12,7 @@ import { parseArgs } from 'node:util'
1212
import WIN32 from '@socketsecurity/registry/lib/constants/WIN32'
1313
import { logger } from '@socketsecurity/registry/lib/logger'
1414

15-
import { getTestsToRun } from './utils/affected-test-mapper.mjs'
15+
import { getTestsToRun } from './utils/changed-test-mapper.mjs'
1616

1717
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1818
const rootPath = path.join(__dirname, '..')
@@ -27,10 +27,6 @@ async function main() {
2727
type: 'boolean',
2828
default: false,
2929
},
30-
'pre-commit': {
31-
type: 'boolean',
32-
default: false,
33-
},
3430
staged: {
3531
type: 'boolean',
3632
default: false,
@@ -62,19 +58,18 @@ async function main() {
6258

6359
// Show help if requested
6460
if (values.help) {
65-
logger.info('Affected Test Runner')
66-
logger.info('\nUsage: node scripts/test-affected.mjs [options]')
61+
logger.info('Changed Test Runner')
62+
logger.info('\nUsage: node scripts/test-changed.mjs [options]')
6763
logger.info('\nOptions:')
6864
logger.info(' --help Show this help message')
6965
logger.info(' --all, --force Run all tests regardless of changes')
7066
logger.info(' --staged Run tests affected by staged changes')
71-
logger.info(' --pre-commit Run tests affected by staged changes (alias for --staged)')
7267
logger.info(' --cover, --coverage Run tests with code coverage')
7368
logger.info(' --update Update test snapshots')
7469
logger.info('\nExamples:')
75-
logger.info(' node scripts/test-affected.mjs # Run affected tests')
76-
logger.info(' node scripts/test-affected.mjs --staged # Run tests for staged changes')
77-
logger.info(' node scripts/test-affected.mjs --all # Force run all tests')
70+
logger.info(' node scripts/test-changed.mjs # Run changed tests')
71+
logger.info(' node scripts/test-changed.mjs --staged # Run tests for staged changes')
72+
logger.info(' node scripts/test-changed.mjs --all # Force run all tests')
7873
process.exitCode = 0
7974
return
8075
}
@@ -83,7 +78,6 @@ async function main() {
8378
// Support aliases
8479
const runAll = all || force
8580
const withCoverage = cover || coverage
86-
const checkStaged = values['pre-commit'] || staged
8781

8882
// Build first if dist doesn't exist
8983
const distIndexPath = path.join(rootPath, 'dist', 'index.js')
@@ -97,7 +91,7 @@ async function main() {
9791
}
9892

9993
// Get tests to run
100-
const testInfo = getTestsToRun({ staged: checkStaged, all: runAll })
94+
const testInfo = getTestsToRun({ staged, all: runAll })
10195
const { reason, tests: testsToRun } = testInfo
10296

10397
// No tests needed

scripts/test.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import colors from 'yoctocolors-cjs'
1414

1515
import WIN32 from '@socketsecurity/registry/lib/constants/WIN32'
1616

17-
import { getTestsToRun } from './utils/affected-test-mapper.mjs'
17+
import { getTestsToRun } from './utils/changed-test-mapper.mjs'
1818

1919
const __dirname = path.dirname(fileURLToPath(import.meta.url))
2020
const rootPath = path.join(__dirname, '..')
@@ -221,10 +221,6 @@ async function main() {
221221
type: 'boolean',
222222
default: false,
223223
},
224-
'pre-commit': {
225-
type: 'boolean',
226-
default: false,
227-
},
228224
staged: {
229225
type: 'boolean',
230226
default: false,
@@ -265,7 +261,6 @@ async function main() {
265261
console.log(' --update Update test snapshots')
266262
console.log(' --all, --force Run all tests regardless of changes')
267263
console.log(' --staged Run tests affected by staged changes')
268-
console.log(' --pre-commit Run tests affected by staged changes (alias for --staged)')
269264
console.log(' --skip-build Skip the build step')
270265
console.log('\nExamples:')
271266
console.log(' pnpm test # Run checks, build, and tests')
@@ -284,7 +279,6 @@ async function main() {
284279
// Handle aliases
285280
const skipChecks = values.fast || values.quick
286281
const withCoverage = values.cover || values.coverage
287-
const checkStaged = values['pre-commit'] || values.staged
288282

289283
let exitCode = 0
290284

@@ -310,7 +304,7 @@ async function main() {
310304
}
311305

312306
// Run tests
313-
exitCode = await runTests({ ...values, staged: checkStaged, coverage: withCoverage })
307+
exitCode = await runTests({ ...values, coverage: withCoverage })
314308

315309
if (exitCode !== 0) {
316310
log.error('Tests failed')

0 commit comments

Comments
 (0)