Skip to content
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: package manager support #960

Merged
merged 60 commits into from
Feb 1, 2024
Merged

feat: package manager support #960

merged 60 commits into from
Feb 1, 2024

Conversation

0618
Copy link
Contributor

@0618 0618 commented Jan 30, 2024

Problem

Branch poc/package-manager-support has the following major changes:

  • add a 'poc-e2e-flow-test' to run package_manager_sanity_checks.test.ts check against supported Package Managers
  • refactored npmPackageManagerController to packageManagerContollerFactory and packageManagerController. And moved them to cli-core
  • refactored backed-deploy to use packageManagerContollerFactory

Related PR:

TODO:

Issue number, if available:

Changes

Corresponding docs PR, if applicable:

Validation

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

0618 and others added 30 commits October 30, 2023 11:51
* feat: add env ci support

* test: update unit tests

* feat: create amplify --yes option

* chore: remove un-used code

* feat: support Panage Manager env var

* chore: add comments

* chore: remove env.CI

* chore: update changeset

* chore: rename PACKAGE_MANAGER_EXECUTABLE

* fix: tests

* fix npm -> npx
* test: init e2e flow test

* fix GH hash

* use dynamic pkg manager

* setup nodejs with npm

* setup more pkg managers

* install pkg managers

* fix yarn1 and change step name

* fix yarn1

* fix yarn1

* split yarn1 into 2 steps

* fix yarn1

* fix yarn1 win

* exclude bun on windows

* yarn1 windows

* setup yarn3

* yarn3

* yarn3 yarnPath

* yarn use 3rd party action

* try yarn3

* set yarn 3.6.x

* set yarn berry

* set yarn stable and pass --yes

* feat: add env ci support

* test: update unit tests

* feat: create amplify --yes option

* chore: remove un-used code

* feat: support Panage Manager env var

* chore: add comments

* chore: remove env.CI

* chore: update changeset

* chore: rename PACKAGE_MANAGER_EXECUTABLE

* fix: tests

* use Env Var PACKAGE_MANAGER_EXECUTABLE

* fix npm -> npx, remove bun

* fix npm -> npx

* change -- --yes

* chore: update package.lock

* chore: remove @Alpha

* fix: clean up yarn

* fix: change yarn1 to yarn

* chore: rename yarn step

* chore: use env

* fix: yarn-stable env var

* add comments

* chore: update sample app with new imports (#541)

* feat: use "use client"; directive in generated react components (#540)

* fix: flatten prop types auth (#534)

* fix: flatten auth login with types

* chore: update snapshots

* chore: update api

* chore: add changeset

* chore: add TODO

---------

Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com>
Co-authored-by: Spencer Stolworthy <sstol@amazon.com>
Co-authored-by: awsluja <110861985+awsluja@users.noreply.github.com>
* fix: npm_project_initializer to use env var

* fix: pnpm init
* feat: setup GH workflow for create amplify

* chore: changeset

* fix: add pkg type for modern yarn

* fix npm install

* feat: test Node v20 and Node v19

* feat: test Node v20 and yarn-stable with Node 19

* feat: exclude yarn-stable

* feat: include node 20 and exclude node 19

* feat: use node 20 for others, use node 19 for yarn-stable

* chore: add TODO to use Node 20
* chore: change branch to poc/pms-create-amplify

* fix: gitIgnore test

* fix: refactor e2e for pms

* chore: update package.lock

* chore: update package.lock

* temp: refactor

* temp: run 1 test

* temp: fix npx

* temp: install packages for yarn

* temp: update initial_project_file_generator

* temp: install ts for yarn

* temp: ignore node_modules and yarn.lock

* temp: create yarn.lock for yarn stable

* temp: fix yarn-stable init

* temp: fix --help

* fix: assert for gitignore

* chore: change yarn stable install

* fix: not install yarn stable globally

* add @yarnpkg/sdks base

* yarn stable use node-modules

* remove emoji

* remove @yarnpkg/sdks

* yarn stable use node 18.18

* yarn stable use node 20

* chore: re-enable all tests

* Revert "chore: re-enable all tests"

This reverts commit f7a167b.

* chore: uncomment test

* chore: enable all initialStatues

* test: change concurrencyLevel for yarn and yarn stable

* add yarn-stable to test fails fast

* chore: update changeset

* chore: change workflow trigger

* chore: yarn not install typescript in root folder

* chore: update package.lock

* Revert "chore: yarn not install typescript in root folder"

This reverts commit 0d83dd0.

* chore: remove comment

* chore: fix typo

* chore: rename yarn-classic and yarn modern
* chore: update package.lock

* init

* feat: dynamically get package manager

* chore: change workflow trigger

* chore: change workflow trigger

* chore: rename npm functions

* chore: update output log

* fix: pnpm cache clear command

* chore: refactor packageManager

* fix: remove pnpm store

* chore: create package_manager file

* chore: change workflow trigger

* chore: refactor PackageManager Controller and Initializer

* fix: update types

* chore: refactor to use factory

* chore: remove try catch from the controllers

* chore: change type

* chore: use abstract class

* fix tests

* fix: PackageManagerBase

* chore: refactor PackageManagerControllerFactory

* chore: refactor packageJsonExists

* chore: cleanup code

* fix: projectJsonExists

* remove package_manager file

* chore: refactor package_manager props into package manager controllers

* chore: rename packageManagerControllerFactory

* chore: make projectRoot, userAgent, getPackageManagerName private

* chore: refactor ensureInitialized

* chore: refactor PackageManagerController to extend PackageManagerControllerFactory

* Revert "chore: refactor PackageManagerController to extend PackageManagerControllerFactory"

This reverts commit 7ddc64f.

* chore: refactor to inject PackageManagerControllerFactory to xPackageManagerController

* chore: move initialProjectFileGenerator to packageManagerController

* fix: initializeAMplifyFolder

* fix: generateInitialProjectFiles

* fix: template path

* chore: refactor getPackageManagerController yarn-modern

* chore: create getWelcomeMessage

* Revert "chore: refactor getPackageManagerController yarn-modern"

This reverts commit 28da8a9.

* chore: refactor generateInitialProjectFiles for yarn-modern

* chore: cleanup code

* chore: remove PackageManagerControllerFactory index

* chore: remove ensureInitialized

* Revert "chore: remove ensureInitialized"

This reverts commit 96483ce.

* Revert "Revert "chore: remove ensureInitialized""

This reverts commit 7c59c80.

* temp: add initializeProject to PackageManagerController

* temp: revert InitialProjectFileGenerator

* fix: InitialProjectFileGenerator

* test: restore initial_project_file_generator

* move installDependencies and getWelcomeMessage to PackageManagerController

* add addLockFile

* add JSDocs and resolve some review comments

* fix: create_amplify.test

* chore: add addTypescript

* chore: refactor generateInitialProjectFiles

* Update packages/create-amplify/src/package-manager-controller/package_manager_controller_factory.ts

Co-authored-by: Edward Foyle <foyleef@amazon.com>

* chore: refactor generateInitialProjectFiles again

* chore: refactor welcomeMessage

* test: add package_manager_controller_factory

* test: fix test types

* chore: comments update

* chore: handle process.env.npm_config_user_agent undefined

* chore: move addLockFile and addTypescript into initializeTsConfig

* test: refactor packageManagerControllerFactory

* fix: yarn initializeTsConfig

* fix: yarn modern initializeTsConfig

* fix: amplify_project_creator test

* chore: refactor contructor

* chore: update package.lock

* fix: pnpm init, remove --debug, etc

* test: add test for NpmPackageManagerController

* fix build error

* chore: refactor NpmPackageManagerController

* test: add test for xPackageManagerController

* chore: convert fs to fsp

* fix yarn modern

---------

Co-authored-by: Edward Foyle <foyleef@amazon.com>
Comment on lines +111 to +118
/**
* TODO: This is a temporary fix for execa version inconsistency. Remove this once execa version is fixed.
* Issue: https://github.com/aws-amplify/amplify-backend/issues/962
*/
if (
dependencyVersionUsage.allVersions.size > 1 /* Issue-962 Start */ &&
dependencyName !== 'execa' /* Issue-962 End */
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for this one.

we should lift this as an option, so that it can be configured here

await glob('packages/*'),
{
'aws-amplify': { denyAll: true },
'@aws-amplify/datastore': { denyAll: true },
'@aws-amplify/core': { denyAll: true },
'@aws-amplify/cli-core': {
allowList: [
'@aws-amplify/backend-cli',
'@aws-amplify/sandbox',
'create-amplify',
],
},
},
[['aws-cdk', 'aws-cdk-lib']]
.

Can be a follow up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'@aws-amplify/plugin-types': minor
'@aws-amplify/cli-core': minor
'@aws-amplify/sandbox': minor
'@aws-amplify/backend-cli': minor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all of the versions minor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given where we are today (0.x versions and added feature with api breaks) yes that seems ok.

'@aws-amplify/backend-cli': minor
---

Support more package managers, such as yarn (version 1 and version 2+), pnpm.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want to add several examples in the changelog?

I'm thinking of adding:

For example the following commands:
yarn create amplify
yarn amplify pipeline-deploy
pnpm create amplify
pnpm amplify pipeline-deploy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes why not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however if you do you may want to split changeset into two files and add this only for CLI and create amplify

* add package-manager-tests to health-checks

* remove poc-e2e-flow-test

* add run_package_manager_tests_tests condition

* fix run_package_manager_tests_tests condition

* remove amplify-backend_windows-latest_8-core

* use re-usable action for run-e2e

* Revert "remove amplify-backend_windows-latest_8-core"

This reverts commit 547834a.

* Revert "use re-usable action for run-e2e"

This reverts commit 3159e01.

* revert re-usable action
@0618 0618 added the run-e2e Label that will include e2e tests in PR checks workflow label Feb 1, 2024
sobolk
sobolk previously approved these changes Feb 1, 2024
Copy link
Member

@sobolk sobolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Comment on lines 147 to 148
// const writeFileMock = mock.fn(() => Promise.resolve());
// mock.method(fsp, 'writeFile', writeFileMock);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 010277b

Co-authored-by: Kamil Sobol <sobkamil@amazon.com>
sobolk
sobolk previously approved these changes Feb 1, 2024
Copy link
Member

@sobolk sobolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it!

                                  .                   .
                              _..-''"""\          _.--'"""\
                              |         L         |        \
                  _           / _.-.---.\.        / .-.----.\
                _/-|---     _/<"---'"""""\\`.    /-'--''"""""\
               |       \     |            L`.`-. |            L
               /_.-.---.L    |            \  \  `|            J`.
             _/--'""""  \    F            \L  \  |             L
               L      `. L  J  _.---.-"""-.\`. L_/ _.--|"""""--.\ `.
               |        \+. /-"__.--'""""   \ `./'"---'""""""   \`. `.
               F   _____ \ `F"        `.     \  \                L `.
              /.-'"_|---'"\ |           `    JL |                 L  `.`.
             <-'""         \|    _.-.------._ A J    _.-.-----`.--|   ``.`.
              L         `. |/.-'"_.-`---'""\."| /-'"---'"""""   \`.\.  \ `.`.
              |  _.------\.<'"""            L\ L\                `.`\`. \  `.
         _.-'//'"--'"""   L\|       ________\ `.F     ___.-------._L \ `-\   \`.
        /___| F             F _.--'"_|-------L  /_.-'"_.-|-'"""""""\  L   L   `.`.
            | F  _.-'|"""""/'"-'"""          J <'"""                L J   |     `.`.
            |/-'-''/|""\ )-|\                 F \                   |  L .'"""`\""-\\_
             F`-'-'-(`-')  | \                F  \                  |___`"""`.""`.-'"
------------/        `-'---|  F               L   L             __     |"""""`-'"__________
          .'_         |    |__L          __  J__  |    _.--'""""   `".----'".'
         '""""""""""""|--._+--F _.-'""||"   """___/.-'"   ||-'"/""""" \_. .'
         J------------(___\__/'_____.--------'-------'""""""""           /
         `-.                                        _.__.__.__.____     J_.-._
    .'`-._ (-`--`---.'--._`---._.-'`-._.-'_.-'``-._'               `-''-'

.changeset/new-timers-warn.md Outdated Show resolved Hide resolved
@@ -0,0 +1,11 @@
---
'@aws-amplify/integration-tests': minor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this package is private so it doesn't need to be included in changesets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed 276b82a

@@ -42,7 +42,7 @@ void describe(() => {
throw new Error('test error');
});

await assert.rejects(
assert.throws(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if it works it works, but it seems like this should be reverted because executeWithDebugLogger is still returning a promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it works because executeWithDebugLogger return a promise, but itself is not async because it doesn't have the async key word

};

/**
* addTypescript - initializes a tsconfig.json file in the project root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: either update or remove this jsdoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done 223f9eb

import { AmplifyPrompter, LogLevel } from '@aws-amplify/cli-core';
import { printer } from './printer.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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this our only usage of yargs in this package? If so, I'd suggest we remove it an just do a check for process.argv.some(arg => arg === '--yes'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not.
This will break this:

await execa('npm', ['create', 'amplify', '--yes', '--', '--help'], {

And. we'll loose --help output :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having said that, we should probably refactor how do we use yargs in this package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then, looking at sources on main I don't see yargs usage in that package's src but I can see yargs in dependencies.
So I wonder how this works now...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bcd0740fa72c:testapp004 sobkamil$ npm create amplify@latest -- --help
? Where should we create your project? (.)
bcd0740fa72c:testapp004 sobkamil$ npm create amplify@0.4.4 -- --help
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --debug                                             [boolean] [default: false]

Looks like it regressed...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. that regression happened on main so if we want to fix it it can be a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't reproduce the regression on amplify@0.6.0, which is this PR ✌️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with cutting a ticket to track and doing this in a follow up

Copy link
Contributor Author

@0618 0618 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue to remove yargs in a follow-up PR #972

Co-authored-by: Edward Foyle <foyleef@amazon.com>
@sobolk sobolk merged commit b73d76a into main Feb 1, 2024
33 of 36 checks passed
@sobolk sobolk deleted the poc/package-manager-support branch February 1, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-e2e Label that will include e2e tests in PR checks workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants