Skip to content

Commit 2e1f51c

Browse files
authored
Git argument parsing (#1141)
* new package for args-pathspec and argv-parser add dependency in simple-git * vulnerability analysis moved to argv-parser
1 parent cbf2993 commit 2e1f51c

68 files changed

Lines changed: 3002 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/petite-crews-thank.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@simple-git/args-pathspec": major
3+
"@simple-git/argv-parser": major
4+
"simple-git": patch
5+
---
6+
7+
Enhances scanning of arguments before passing on to the spawned `child_process`.
8+
9+
Caters for `-c` flags prefixing the `git` task (used when setting global inline config) and suffixing with either `-c`, `--config` or `--config-env`. Detects `git config` operations that write to the configuration.
10+

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
node-version: [18, 20, 22, 23, 24, 25]
17+
node-version: [20, 22, 23, 24, 25]
1818
steps:
1919
- uses: actions/checkout@v6
2020
- name: Use Node.js ${{ matrix.node-version }}
@@ -24,6 +24,7 @@ jobs:
2424
cache: yarn
2525
- run: yarn install --immutable
2626
- run: yarn build
27+
- run: yarn build:pkg
2728
- name: Test
2829
env:
2930
GIT_AUTHOR_NAME: 'Simple Git Tests'

biome.json

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
"packages/test-utils/**",
9494
"**/*.spec.ts",
9595
"**/__fixtures__/**",
96-
"**/__mocks__/**"
96+
"**/__mocks__/**",
97+
"!packages/args-pathspec/**",
98+
"!packages/argv-parser/**"
9799
],
98100
"assist": {
99101
"actions": {
@@ -123,6 +125,51 @@
123125
}
124126
}
125127
}
128+
},
129+
{
130+
"includes": ["devtools", "packages/args-pathspec/**", "packages/argv-parser/**"],
131+
"assist": {
132+
"actions": {
133+
"source": {
134+
"organizeImports": {
135+
"level": "on",
136+
"options": {
137+
"groups": [
138+
":URL:",
139+
":NODE:",
140+
":BLANK_LINE:",
141+
[":PACKAGE:", ":PACKAGE_WITH_PROTOCOL:"],
142+
":BLANK_LINE:",
143+
":ALIAS:",
144+
":PATH:"
145+
]
146+
}
147+
}
148+
}
149+
}
150+
},
151+
"linter": {
152+
"rules": {
153+
"complexity": {
154+
"noBannedTypes": "error",
155+
"noUselessEscapeInRegex": "error",
156+
"useArrowFunction": "error",
157+
"useOptionalChain": "error"
158+
},
159+
"correctness": {
160+
"noUnusedPrivateClassMembers": "error"
161+
},
162+
"style": {
163+
"useImportType": "error",
164+
"useConst": "error",
165+
"useTemplate": "error"
166+
},
167+
"suspicious": {
168+
"noExplicitAny": "error",
169+
"noImplicitAnyLet": "error"
170+
}
171+
}
172+
}
126173
}
127174
],
128175
"files": {

devtools/log.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function logger(name: string) {
2+
return (...args: unknown[]) => {
3+
console.log(`${name}:`, ...args);
4+
};
5+
}

devtools/package-json.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { readFile, writeFile } from 'fs/promises';
2+
import { existsSync } from 'fs';
3+
import { basename, resolve } from 'path';
4+
import { logger } from './log';
5+
6+
import { repoRoot } from './repo-root';
7+
8+
const input = process.argv[2];
9+
10+
if (!input?.startsWith('.')) {
11+
console.error(`❌ Supply a relative path to a package.json in this repo`);
12+
process.exit(1);
13+
}
14+
15+
const src = resolve(repoRoot, input);
16+
if (!existsSync(src) || basename(src) !== 'package.json') {
17+
console.error(`❌ Supply a valid path to a package.json in this repo`);
18+
process.exit(1);
19+
}
20+
21+
const log = logger('package.json');
22+
23+
async function main() {
24+
log('Generating content');
25+
const pkg = await createPackageJson();
26+
log('Writing content', pkg);
27+
await write(pkg);
28+
log('✅ Done');
29+
}
30+
31+
async function write(content: unknown) {
32+
await writeFile(src, JSON.stringify(content, null, 2), 'utf8');
33+
}
34+
35+
async function read() {
36+
return JSON.parse(await readFile(src, 'utf8'));
37+
}
38+
39+
async function createPackageJson() {
40+
const { publish, scripts: _scripts, devDependencies: _devDependencies, ...pkg } = await read();
41+
42+
return {
43+
...pkg,
44+
...publish,
45+
};
46+
}
47+
48+
main().then(() => {});

devtools/repo-root.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fileURLToPath } from 'url';
2+
import { dirname, resolve } from 'path';
3+
4+
const __filename = fileURLToPath(import.meta.url);
5+
const __dirname = dirname(__filename);
6+
7+
export const repoRoot = resolve(__dirname, '..');

devtools/reset-package-json.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import simpleGit from '../simple-git';
2+
import { repoRoot } from './repo-root';
3+
4+
const git = simpleGit({ baseDir: repoRoot });
5+
6+
git.status()
7+
.then((status) => {
8+
return status.files
9+
.filter((file) => file.path.endsWith('package.json'))
10+
.map((file) => file.path);
11+
})
12+
.then((paths) => git.raw('checkout', '--', ...paths));

devtools/vite-config.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { defineConfig } from 'vite';
2+
3+
export function legacyExportFormatPlugin() {
4+
return {
5+
name: 'legacy-export-format',
6+
renderChunk(code: string, chunk: { fileName: string }) {
7+
if (chunk.fileName.endsWith('.cjs.cjs')) {
8+
return {
9+
code: `${code}
10+
Object.defineProperties(
11+
module.exports = Object.assign(exports.default,exports),
12+
{
13+
__esModule: { value: true },
14+
[Symbol.toStringTag]: { value: 'Module' }
15+
}
16+
);
17+
`,
18+
map: null,
19+
};
20+
}
21+
22+
return null;
23+
},
24+
};
25+
}
26+
27+
export const baseConfig = (name: string) =>
28+
defineConfig({
29+
build: {
30+
target: 'es2020',
31+
lib: {
32+
name,
33+
entry: './index.ts',
34+
formats: ['cjs', 'es'],
35+
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
36+
},
37+
outDir: 'dist',
38+
rollupOptions: {
39+
external(id) {
40+
return /^(debug|node:|@kwsites|@simple-git\/)/.test(id);
41+
},
42+
plugins: [],
43+
},
44+
sourcemap: true,
45+
},
46+
test: {
47+
globals: true,
48+
environment: 'node',
49+
include: ['test/**/*.spec.ts'],
50+
},
51+
});

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
"simple-git"
88
],
99
"resolutions": {
10-
"jest": "29.7.0"
10+
"jest": "29.7.0",
11+
"typescript": "^5.7.3"
1112
},
1213
"scripts": {
1314
"build": "yarn workspaces foreach -A run build",
15+
"build:pkg": "yarn workspaces foreach -A run build:pkg",
16+
"build:pkg:reset": "tsx ./devtools/reset-package-json",
1417
"clean": "git clean -fxd -e .idea -e node_modules -e .yarn",
1518
"clean:cache": "git clean -fxd .yarn node_modules packages simple-git",
1619
"lint": "biome check",
@@ -20,7 +23,9 @@
2023
},
2124
"dependencies": {
2225
"@changesets/changelog-github": "^0.5.2",
23-
"@changesets/cli": "^2.29.8"
26+
"@changesets/cli": "^2.29.8",
27+
"tsx": "^4.21.0",
28+
"typescript": "^5"
2429
},
2530
"devDependencies": {
2631
"@biomejs/biome": "^2.1.4"

packages/args-pathspec/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { isPathSpec, pathspec, toPaths } from './src/pathspec';

0 commit comments

Comments
 (0)