-
Notifications
You must be signed in to change notification settings - Fork 50
fix: support .cmd/.bat shims on Windows in exec() (#446) #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src/**/*.ts"] | ||
| } | ||
| "include": [ | ||
| "src/**/*.ts" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src/**/*.ts"] | ||
| } | ||
| "include": [ | ||
| "src/**/*.ts" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src/**/*.ts"] | ||
| } | ||
| "include": [ | ||
| "src/**/*.ts" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src/**/*.ts"] | ||
| } | ||
| "include": [ | ||
| "src/**/*.ts" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src/**/*.ts"] | ||
| } | ||
| "include": [ | ||
| "src/**/*.ts" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,10 +28,14 @@ export async function exec(cmd: string, args: string[], opts: ExecOptions): Prom | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return new Promise<ExecResult>((resolve, reject) => { | ||||||||||||||||||||||||
| const child = spawn(cmd, args, { | ||||||||||||||||||||||||
| // On Windows, .cmd/.bat shims must be spawned with shell:true or via cmd.exe | ||||||||||||||||||||||||
| const isWin = process.platform === 'win32'; | ||||||||||||||||||||||||
| const needsShell = isWin && (cmd.endsWith('.cmd') || cmd.endsWith('.bat')); | ||||||||||||||||||||||||
| const child = spawn(needsShell ? 'cmd' : cmd, needsShell ? ['/d', '/s', '/c', cmd, ...args] : args, { | ||||||||||||||||||||||||
| cwd: opts.cwd, | ||||||||||||||||||||||||
| env: { ...process.env, ...extraEnv }, | ||||||||||||||||||||||||
| stdio: ['ignore', 'pipe', 'pipe'], | ||||||||||||||||||||||||
| ...(needsShell ? { shell: true } : {}), | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
Comment on lines
+34
to
39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let stdout = ''; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -123,14 +123,19 @@ export default defineDns<Config>({ | |||||||||||
| const token = await getAccessToken(); | ||||||||||||
| const project = config.projectId ?? _secret('GOOGLE_PROJECT_ID'); | ||||||||||||
| if (!project) throw new Error('GOOGLE_PROJECT_ID not set'); | ||||||||||||
| const [type, name] = recordId.split('/'); | ||||||||||||
| const parts = recordId.split('/'); | ||||||||||||
| const type = parts[0]; | ||||||||||||
| const name = parts.slice(1).join('/'); | ||||||||||||
| if (!type || !name) throw new Error(`Invalid recordId "${recordId}" — expected "<type>/<FQDN>"`); | ||||||||||||
| // Need to fetch the rrset to get current rrdatas for the deletion entry. | ||||||||||||
| const existing = (await this.listRecords(zoneId, config)).filter( | ||||||||||||
| r => r.type === type && (r.name === name || r.name === name.replace(/\.$/, '')), | ||||||||||||
| ); | ||||||||||||
| if (existing.length === 0) return; | ||||||||||||
| const first = existing[0]; | ||||||||||||
| if (!first) return; | ||||||||||||
|
Comment on lines
134
to
+136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||
| const fqdn = name.endsWith('.') ? name : `${name}.`; | ||||||||||||
| const ttl = existing[0].ttl; | ||||||||||||
| const ttl = first.ttl; | ||||||||||||
| const res = await fetch(`${API}/projects/${project}/managedZones/${zoneId}/changes`, { | ||||||||||||
| method: 'POST', | ||||||||||||
| headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' }, | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows file systems are case-insensitive, so shims named
foo.CMDorfoo.BAT(uppercase) will not be detected, and spawning them without the shell wrapper will fail withENOENT. Lowercasing before the check avoids this edge case.