-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(init-templates): csharp and fsharp app init fails when path conta…
…ins space (#21049) When running `cdk init --language=csharp` or `cdk init --language=fsharp` with one or more spaces in the path to the project, `init` will fail. This fix adds in handling for spaces and other special characters in the file path for both windows systems and posix systems. This PR moves the temporary hook directory to the same directory as the source directory so that it can use the local `os.ts` file and other dependencies. `ShellOptions` was also removed because it wasn't used. Tests have been added for posix and manual testing was performed on a windows machine. Closes issue #18803. ---- ### All Submissions: *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
0ad307b
commit 79c9ca1
Showing
7 changed files
with
99 additions
and
137 deletions.
There are no files selected for viewing
32 changes: 6 additions & 26 deletions
32
packages/aws-cdk/lib/init-templates/app/csharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../../../os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const csprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.csproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', csprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
try { | ||
await shell(['dotnet', 'sln', slnPath, 'add', csprojPath]); | ||
} catch (e) { | ||
throw new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. ${e.message}`); | ||
} | ||
}; |
32 changes: 6 additions & 26 deletions
32
packages/aws-cdk/lib/init-templates/app/fsharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../../../os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const fsprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.fsproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', fsprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
try { | ||
await shell(['dotnet', 'sln', slnPath, 'add', fsprojPath]); | ||
} catch (e) { | ||
throw new Error(`Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln. ${e.message}`); | ||
} | ||
}; |
32 changes: 6 additions & 26 deletions
32
packages/aws-cdk/lib/init-templates/sample-app/csharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../../../os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const csprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.csproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', csprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
try { | ||
await shell(['dotnet', 'sln', slnPath, 'add', csprojPath]); | ||
} catch (e) { | ||
throw new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. ${e.message}`); | ||
} | ||
}; |
32 changes: 6 additions & 26 deletions
32
packages/aws-cdk/lib/init-templates/sample-app/fsharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../../../os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const fsprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.fsproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', fsprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
try { | ||
await shell(['dotnet', 'sln', slnPath, 'add', fsprojPath]); | ||
} catch (e) { | ||
throw new Error(`Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln. ${e.message}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters