Skip to content

Commit 53fc0ec

Browse files
committed
fix(regex): sort-regex-alternations — 8 rewrites + 1 order-significant disable
Reorder regex alternation arms alphabetically per socket/sort-regex-alternations. All reordered alternations have mutually-exclusive arms (different leading chars or anchors), so match semantics are preserved. One site (glob.mts `(\\.|[^{(])`) keeps the original order because `\\.` must be tried before `[^{(]` — otherwise `[^{(]` swallows the backslash and breaks escape-pair consumption — and gets an inline `socket-hook: allow regex-alternation-order` marker with rationale. Files: - packages/cli/.config/esbuild.cli.mts (2 alternations) - packages/cli/scripts/cover.mts (2 alternations) - packages/cli/src/commands/mcp/lib/artifacts.mts - packages/cli/src/utils/ecosystem/windows-shims.mts - packages/cli/src/utils/fs/glob.mts (disable) - packages/cli/src/utils/output/adapters/zpm.mts - packages/cli/test/integration/api/bundle-validation.test.mts (2) - packages/cli/test/integration/bundle-validation.test.mts (2)
1 parent e730082 commit 53fc0ec

8 files changed

Lines changed: 12 additions & 12 deletions

File tree

packages/cli/.config/esbuild.cli.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const rootPath = path.join(__dirname, '..')
2626
const inlinedEnvVars = getInlinedEnvVars()
2727

2828
// Matches ./external/, ../external/, ../../external/, etc. (forward and back slashes).
29-
const socketLibExternalPathRegExp = /^(?:\.[/\\]|(?:\.\.[/\\])+)external[/\\]/
29+
const socketLibExternalPathRegExp = /^(?:(?:\.\.[/\\])+|\.[/\\])external[/\\]/
3030

3131
export function findSocketLibPath(importerPath: string) {
3232
const match = importerPath.match(/^(.*\/@socketsecurity\/lib)\b/)
@@ -156,7 +156,7 @@ const config: BuildOptions = {
156156
setup(build: PluginBuild) {
157157
// Stub iconv-lite and encoding to avoid bundling issues.
158158
build.onResolve(
159-
{ filter: /^(encoding|iconv-lite)(\/|$)/ },
159+
{ filter: /^(encoding|iconv-lite)(?:$|\/)/ },
160160
(args: OnResolveArgs) => {
161161
return {
162162
path: args.path,

packages/cli/scripts/cover.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function main() {
136136
)
137137
const output = (codeCoverageResult.stdout + codeCoverageResult.stderr)
138138
.replace(ansiRegex, '')
139-
.replace(/(?:||)\s*/g, '')
139+
.replace(/(?:||)\s*/g, '')
140140
.trim()
141141

142142
// Extract and display test summary
@@ -215,7 +215,7 @@ async function main() {
215215
// Remove ANSI color codes
216216
.replace(ansiRegex, '')
217217
// Remove spinner artifacts
218-
.replace(/(?:||)\s*/g, '')
218+
.replace(/(?:||)\s*/g, '')
219219
.trim()
220220

221221
// Extract test summary (Test Files ... Duration)

packages/cli/src/commands/mcp/lib/artifacts.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function deduplicateArtifacts(
4747
}
4848

4949
export function isSourceDist(release: string): boolean {
50-
return /\.(tar\.gz|tar\.bz2|zip)$/i.test(release) || /sdist/i.test(release)
50+
return /\.(tar\.bz2|tar\.gz|zip)$/i.test(release) || /sdist/i.test(release)
5151
}
5252

5353
export function isUniversalWheel(release: string): boolean {

packages/cli/src/utils/ecosystem/windows-shims.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function resolveBinPathSync(binPath: string): string {
7070
// node "C:\path\to\npm-cli.js" "$@"
7171
// "%_prog%" "%dp0%\node_modules\npm\bin\npm-cli.js" %*
7272
const nodePathMatch = content.match(
73-
/(?:node\s+["']|"%dp0%\\)([^"'\s]+(?:npm-cli|pnpm|yarn)\.(?:c?js|mjs))["'\s]/i,
73+
/(?:"%dp0%\\|node\s+["'])([^"'\s]+(?:npm-cli|pnpm|yarn)\.(?:c?js|mjs))["'\s]/i,
7474
)
7575
if (nodePathMatch && nodePathMatch.length > 1 && nodePathMatch[1]) {
7676
const matchedPath = nodePathMatch[1]

packages/cli/src/utils/fs/glob.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function ignorePatternToMinimatch(pattern: string): string {
129129
// Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
130130
const escapedPatternWithoutLeadingSlash =
131131
patternWithoutLeadingSlash.replaceAll(
132-
/(?=((?:\\.|[^{(])*))\1([{(])/guy,
132+
/(?=((?:\\.|[^{(])*))\1([{(])/guy, // socket-hook: allow regex-alternation-order -- `\\.` must come first so escape pairs are consumed atomically.
133133
'$1\\$2',
134134
)
135135
const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : ''

packages/cli/src/utils/output/adapters/zpm.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { ScrubberAdapter } from '../scrubber.mts'
2424
// Matches lines like "➤ YN0000: ..." or "➤ Done in ..." regardless of
2525
// leading whitespace. Zpm uses U+27A4 BLACK RIGHTWARDS ARROWHEAD as
2626
// the bullet. The YN\d{4} code pattern is structured and distinctive.
27-
const ZPM_LOG_RE = /^\s*(?:|YN\d{4}:|Done in\s)/
27+
const ZPM_LOG_RE = /^\s*(?:Done in\s|YN\d{4}:|)/
2828

2929
export const zpmAdapter: ScrubberAdapter = {
3030
name: 'zpm',

packages/cli/test/integration/api/bundle-validation.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export function hasAbsolutePaths(content: string): {
8484
// Match absolute paths but exclude URLs and node: protocol.
8585
const patterns = [
8686
// Match require('/abs/path') or require('C:\\path').
87-
/require\(["'](?:\/[^"'\n]+|[A-Z]:\\[^"'\n]+)["']\)/g,
87+
/require\(["'](?:[A-Z]:\\[^"'\n]+|\/[^"'\n]+)["']\)/g,
8888
// Match import from '/abs/path'.
89-
/import\s+.*?from\s+["'](?:\/[^"'\n]+|[A-Z]:\\[^"'\n]+)["']/g,
89+
/import\s+.*?from\s+["'](?:[A-Z]:\\[^"'\n]+|\/[^"'\n]+)["']/g,
9090
]
9191

9292
const matches: string[] = []

packages/cli/test/integration/bundle-validation.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export function hasAbsolutePaths(content: string): {
8484
// Match absolute paths but exclude URLs and node: protocol.
8585
const patterns = [
8686
// Match require('/abs/path') or require('C:\\path').
87-
/require\(["'](?:\/[^"'\n]+|[A-Z]:\\[^"'\n]+)["']\)/g,
87+
/require\(["'](?:[A-Z]:\\[^"'\n]+|\/[^"'\n]+)["']\)/g,
8888
// Match import from '/abs/path'.
89-
/import\s+.*?from\s+["'](?:\/[^"'\n]+|[A-Z]:\\[^"'\n]+)["']/g,
89+
/import\s+.*?from\s+["'](?:[A-Z]:\\[^"'\n]+|\/[^"'\n]+)["']/g,
9090
]
9191

9292
const matches: string[] = []

0 commit comments

Comments
 (0)