-
Notifications
You must be signed in to change notification settings - Fork 74
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: create amplify skip prompts for --yes
option
#507
Changes from all commits
b41bb05
e722f11
7dca6da
70fad76
dc2df4b
c423170
518a43c
7b88772
a085162
988637e
be3a456
01d8792
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'create-amplify': patch | ||
--- | ||
|
||
1. Create Amplify (temporarily) uses environment variable for Package Manager | ||
2. Create Amplify uses `yes` option to choose the default value for prompts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import fsp from 'fs/promises'; | ||
import path from 'path'; | ||
import yargs from 'yargs'; | ||
import { AmplifyPrompter } from '@aws-amplify/cli-core'; | ||
import { logger } from './logger.js'; | ||
|
||
/** | ||
* Returns the project root directory. | ||
*/ | ||
export const getProjectRoot = async () => { | ||
const useDefault = process.env.npm_config_yes === 'true'; | ||
const argv = await yargs(process.argv.slice(2)).options({ | ||
yes: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
}).argv; | ||
const useDefault = process.env.npm_config_yes === 'true' || argv.yes === true; | ||
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. why couple ourselves to 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 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. In that case, why have argv.yes? 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.
|
||
const defaultProjectRoot = '.'; | ||
let projectRoot: string = useDefault | ||
? defaultProjectRoot | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ export class NpmPackageManagerController implements PackageManagerController { | |
private readonly projectRoot: string, | ||
private readonly execa = _execa | ||
) {} | ||
private readonly executableName = 'npm'; | ||
private readonly executableName = | ||
process.env.PACKAGE_MANAGER_EXECUTABLE || 'npm'; // TODO: replace `process.env.PACKAGE_MANAGER_EXECUTABLE` with `getPackageManagerName()` once the test infra is ready. | ||
|
||
/** | ||
* Installs the given package names as devDependencies | ||
|
@@ -24,9 +25,11 @@ export class NpmPackageManagerController implements PackageManagerController { | |
packageNames: string[], | ||
type: DependencyType | ||
): Promise<void> => { | ||
const args = ['install'].concat(...packageNames); | ||
const args = [this.executableName === 'yarn' ? 'add' : 'install'].concat( | ||
...packageNames | ||
); | ||
if (type === 'dev') { | ||
args.push('--save-dev'); | ||
args.push('-D'); | ||
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. does this work for both ? 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. Yes, 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. we shouldn't be making admissions for 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. The command and options of 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. We should be careful not to create accidental coupling in the name of reducing duplication. Just because two implementations are the same now doesn't mean they will evolve in the same way. There's nothing but convention keeping the args of these tools similar. But they are all separate and will have their own evolutions over time. I still think we should have completely separate controllers for each one even if each controller does 90% of the same stuff as the others. Consider the case where pnpm updates some flag and we make a change to our uber controller to handle this but it also borks yarn and npm. Vs a separate controller for each where we can update the pnpm controller with confidence that there won't be side-effects for the other controllers. 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. That makes sense! It'll be handled in a separated issue #517 before the feature branch |
||
} | ||
await this.execa(this.executableName, args, { | ||
stdio: 'inherit', | ||
|
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.
if 'yes' is intended to mean 'default', we should name the flag 'default'. This is a huge source of confusion in the current CLI
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.
That makes sense. I almost udpated the PR, but just realized that we can't change it for
npm
becausenpm_config_yes
is set by--yes
.Do we want to have
--default
works for all, and--yes
only works for npm?