-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: enable pnpx with cdk init #30661
base: main
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -153,10 +153,14 @@ export class InitTemplate { | |||||||||
|
||||||||||
private async installProcessed(templatePath: string, toFile: string, language: string, project: ProjectInfo) { | ||||||||||
const template = await fs.readFile(templatePath, { encoding: 'utf-8' }); | ||||||||||
await fs.writeFile(toFile, this.expand(template, language, project)); | ||||||||||
let appCommandTool = 'npx'; | ||||||||||
if (toFile.includes('cdk.json') && await getCommand() === 'pnpm') { | ||||||||||
appCommandTool = 'pnpx'; | ||||||||||
} | ||||||||||
await fs.writeFile(toFile, this.expand(template, language, project, appCommandTool)); | ||||||||||
} | ||||||||||
|
||||||||||
private expand(template: string, language: string, project: ProjectInfo) { | ||||||||||
private expand(template: string, language: string, project: ProjectInfo, appCommandTool: string = 'npx') { | ||||||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||||||||||
const manifest = require(path.join(rootDir(), 'package.json')); | ||||||||||
const MATCH_VER_BUILD = /\+[a-f0-9]+$/; // Matches "+BUILD" in "x.y.z-beta+BUILD" | ||||||||||
|
@@ -173,6 +177,8 @@ export class InitTemplate { | |||||||||
break; | ||||||||||
} | ||||||||||
return template.replace(/%name%/g, project.name) | ||||||||||
// the appcommand is only added to the cdk.json file when initializing a Typescript app. | ||||||||||
.replace(/%appcommandtool%/g, appCommandTool) | ||||||||||
.replace(/%stackname%/, project.stackName ?? '%name.PascalCased%Stack') | ||||||||||
.replace(/%PascalNameSpace%/, project.stackName ? camelCase(project.stackName + 'Stack', { pascalCase: true }) : '%name.PascalCased%') | ||||||||||
.replace(/%PascalStackProps%/, project.stackName ? (camelCase(project.stackName, { pascalCase: true }) + 'StackProps') : 'StackProps') | ||||||||||
|
@@ -344,8 +350,7 @@ async function postInstallJavascript(canUseNetwork: boolean, cwd: string) { | |||||||||
} | ||||||||||
|
||||||||||
async function postInstallTypescript(canUseNetwork: boolean, cwd: string) { | ||||||||||
const command = 'npm'; | ||||||||||
|
||||||||||
const command = await getCommand(); | ||||||||||
if (!canUseNetwork) { | ||||||||||
warning(`Please run '${command} install'!`); | ||||||||||
return; | ||||||||||
|
@@ -359,6 +364,16 @@ async function postInstallTypescript(canUseNetwork: boolean, cwd: string) { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
async function getCommand(): Promise<string> { | ||||||||||
print('Getting command...'); | ||||||||||
if (process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')) { | ||||||||||
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
|
||||||||||
print(`Got exec path ${chalk.green(`${process.env.npm_execpath}`)}...`); | ||||||||||
print(`Got command ${chalk.green(`${'pnpm'}`)}...`); | ||||||||||
return 'pnpm'; | ||||||||||
Comment on lines
+370
to
+372
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
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. Adding it and testing as we speak |
||||||||||
} | ||||||||||
return 'npm'; | ||||||||||
} | ||||||||||
|
||||||||||
async function postInstallJava(canUseNetwork: boolean, cwd: string) { | ||||||||||
const mvnPackageWarning = 'Please run \'mvn package\'!'; | ||||||||||
if (!canUseNetwork) { | ||||||||||
|
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.
This is hard-coded for pnpm, but we wont support yarn or other package managers etc. Is that the approach we want?
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.
per my understanding we do not want to extend this feature pass
pnpm
following the comments in the original issue I think we should just expand the support topnpm
. Otherwise we expose ourselves into making changes every time there is a possibility of having a new package manager. Any thoughts?