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: lambda support for yarn2/3 and pnpm package managers #12750

Merged
merged 68 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
cbaa0a5
feat: add support for pnpm and yarn2 for lambda function
git-alazara Jun 2, 2023
eeee557
feat: add support for pnpm and yarn2 for lambda function
git-alazara Jun 2, 2023
46647df
feat: add support for pnpm and yarn2 for lambda function
git-alazara Jun 2, 2023
8744d5c
feat: add support for pnpm and yarn2 for lambda function
git-alazara Jun 2, 2023
7db5f8e
test: fix unit tests
git-alazara Jun 2, 2023
cdfd77b
chore: fix tests
pavellazar Jun 5, 2023
450dd39
chore: merged dev
pavellazar Jun 5, 2023
a7e2a0c
chore: merged dev
pavellazar Jun 5, 2023
01c8725
chore: merged dev
pavellazar Jun 5, 2023
5a5519a
chore: fix tests
pavellazar Jun 5, 2023
a61c835
chore: fix tests
pavellazar Jun 5, 2023
a5bc020
chore: merged dev
git-alazara Jun 6, 2023
3ef0414
chore: test fix
git-alazara Jun 6, 2023
49e5af3
chore: fix versions
git-alazara Jun 6, 2023
aebf364
feat: version bump
git-alazara Jun 6, 2023
798e03b
chore: test fix
git-alazara Jun 6, 2023
3620213
chore: test fix
git-alazara Jun 6, 2023
d319260
chore: test fix
git-alazara Jun 6, 2023
1467977
chore: test fix
git-alazara Jun 6, 2023
bb23ade
chore: fix tests
pavellazar Jun 6, 2023
49bf64b
chore: fix lambda migration tests
git-alazara Jun 6, 2023
af3bd74
chore: fix lambda migration tests
git-alazara Jun 6, 2023
c2bfc83
chore: fix lambda migration tests
git-alazara Jun 6, 2023
e4b60f3
chore: fix lambda migration tests
git-alazara Jun 6, 2023
7ff3d8a
chore: fix lambda migration tests
git-alazara Jun 6, 2023
7211f63
chore: fix lambda migration tests
git-alazara Jun 6, 2023
113d1c0
chore: fix lambda migration tests
git-alazara Jun 6, 2023
d10b2d8
chore: fix lambda migration tests
git-alazara Jun 7, 2023
c8931f9
chore: fix lambda migration tests
git-alazara Jun 7, 2023
b6ad529
chore: fix lambda migration tests
git-alazara Jun 7, 2023
caae45d
chore: fix lambda migration tests
git-alazara Jun 7, 2023
16186a2
chore: fix lambda migration tests
git-alazara Jun 7, 2023
e0e2282
chore: fix lambda migration tests
git-alazara Jun 7, 2023
4018c5b
chore: fix lambda migration tests
git-alazara Jun 7, 2023
518bf9c
chore: fix lambda migration tests
git-alazara Jun 7, 2023
052b55b
Merge branch 'dev' into lambda-package-manager
git-alazara Jun 7, 2023
d76de19
chore: fix lambda migration tests
git-alazara Jun 7, 2023
38c2d27
chore: fix lambda migration tests
git-alazara Jun 7, 2023
3ce4621
chore: fix lambda migration tests
git-alazara Jun 7, 2023
677220c
chore: fix lambda migration tests
git-alazara Jun 7, 2023
18dcd7c
chore: fix lambda migration tests
git-alazara Jun 8, 2023
f487228
Merge branch 'dev' into lambda-package-manager
git-alazara Jun 8, 2023
253d8e5
test: fix test
git-alazara Jun 8, 2023
4b58a4c
chore: addressed PR feedback
git-alazara Jun 14, 2023
67b401b
chore: merged dev
git-alazara Jun 14, 2023
d4ace69
chore: extract api fix
git-alazara Jun 14, 2023
04ba8bc
feat: bump version commit
git-alazara Jun 14, 2023
8fb438e
chore: address PR feedback test failures
git-alazara Jun 14, 2023
bd3f13b
chore: fix build parameters
git-alazara Jun 14, 2023
c188a91
chore: fix build parameters
git-alazara Jun 14, 2023
8f9dd3e
chore: fix build parameters
git-alazara Jun 14, 2023
b656a52
chore: fix amplify-cli-internal package manger related tests
git-alazara Jun 15, 2023
ada5251
chore: fix amplify-cli-internal package manger related tests
git-alazara Jun 15, 2023
f4b5ed2
chore: fix amplify-cli-internal package manger related tests
git-alazara Jun 15, 2023
ab37c07
chore: address PR feedback
pavellazar Jun 15, 2023
735f584
Update packages/amplify-cli-core/src/amplify-node-pkg-detector/parser…
pavellazar Jun 15, 2023
d2665f5
chore: run prettier on changed files
git-alazara Jun 15, 2023
8e2e33e
chore: update error message
git-alazara Jun 15, 2023
8238cbc
Merge branch 'dev' into lambda-package-manager
git-alazara Jun 16, 2023
e271a1e
Update packages/amplify-category-custom/src/utils/build-custom-resour…
pavellazar Jun 16, 2023
22ce95b
chore: add .npmrc for pnpm category custom build
git-alazara Jun 16, 2023
b35fc7e
test: update create custom test
git-alazara Jun 16, 2023
2690380
test: update create custom test
git-alazara Jun 17, 2023
2b823c6
chore: pr feedback
git-alazara Jun 20, 2023
92d3732
chore: pr feedback
git-alazara Jun 20, 2023
30e7886
fix: converted package manager interface fields to readonly
git-alazara Jun 21, 2023
411b7a9
chore: PR feedback
git-alazara Jun 21, 2023
e516075
chore: PR feedback
git-alazara Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/amplify-cli-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1484,17 +1484,17 @@ export const overriddenCategories: string[];
// @public (undocumented)
export interface PackageManager {
// (undocumented)
displayValue: string;
readonly displayValue: string;
// (undocumented)
executable: string;
readonly executable: string;
// (undocumented)
getInstallArgs: (buildType: BuildType) => string[];
// (undocumented)
getRunScriptArgs: (scriptName: string) => string[];
// (undocumented)
lockFile: string;
readonly lockFile: string;
// (undocumented)
packageManager: PackageManagerType;
readonly packageManager: PackageManagerType;
// (undocumented)
version?: SemVer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from 'path';
import { AmplifyNodePkgDetectorProps, AmplifyNodePkgDetector } from '../../amplify-node-pkg-detector';
import { getPackageManager, getPackageManagerByType } from '../../utils/packageManager';
import { coerce } from 'semver';
import { $TSAny } from '@aws-amplify/amplify-cli-core';

jest.mock('../../utils/packageManager', () => ({
...(jest.requireActual('../../utils/packageManager') as {}),
Expand All @@ -26,7 +27,7 @@ const npmPackageManager = getPackageManagerByType('npm');

describe('parsing yarn lock files', () => {
it('throws error when lock file not found', async () => {
yarnPackageManager.lockFile = 'yarn-test-not-found.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test-not-found.lock';
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like there's probably a way to updates these tests to check the same behavior without overriding this value, but I'm okay if that is out of scope for now


(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand All @@ -39,7 +40,7 @@ describe('parsing yarn lock files', () => {
});

it('throw error on corrupted lock file', async () => {
yarnPackageManager.lockFile = 'yarn-test-error.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test-error.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const amplifyDetectorProps: AmplifyNodePkgDetectorProps = {
Expand All @@ -51,7 +52,7 @@ describe('parsing yarn lock files', () => {
});

it('correctly detect dependencies for @aws-cdk/core', async () => {
yarnPackageManager.lockFile = 'yarn-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('parsing yarn lock files', () => {
`);
});
it('correctly detect dependencies for amplify-cli-core', async () => {
yarnPackageManager.lockFile = 'yarn-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -125,7 +126,7 @@ describe('parsing yarn lock files', () => {
});

it('correctly detect dependencies for fs-extra', async () => {
yarnPackageManager.lockFile = 'yarn-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -173,7 +174,7 @@ describe('parsing yarn lock files', () => {
});

it('correctly detect dependencies for aws-cdk-lib', async () => {
yarnPackageManager.lockFile = 'yarn-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand All @@ -184,7 +185,7 @@ describe('parsing yarn lock files', () => {

it('should handle cycle in graph with yarn 1', async () => {
// this test will error with stack overflow if dfs is following cycle
yarnPackageManager.lockFile = 'yarn-test-with-cycle.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-test-with-cycle.lock';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand All @@ -197,7 +198,7 @@ describe('parsing yarn lock files', () => {

describe('parsing package lock files', () => {
it('throws error when package lock file is missing', async () => {
npmPackageManager.lockFile = 'package-lock-not-found.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-not-found.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
expect(
Expand All @@ -209,7 +210,7 @@ describe('parsing package lock files', () => {
});

it('throw error on corrupted package lock file', async () => {
npmPackageManager.lockFile = 'package-lock-test-error.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test-error.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const amplifyDetectorProps: AmplifyNodePkgDetectorProps = {
Expand All @@ -223,7 +224,7 @@ describe('parsing package lock files', () => {
});

it('correctly detect dependencies', async () => {
npmPackageManager.lockFile = 'package-lock-test.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -264,7 +265,7 @@ describe('parsing package lock files', () => {
});

it('correctly detect dependencies for @aws-cdk/core when present in peer dependencies', async () => {
npmPackageManager.lockFile = 'package-lock-test-peer-dependencies.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test-peer-dependencies.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand All @@ -283,7 +284,7 @@ describe('parsing package lock files', () => {
`);
});
it('correctly detect dependencies for amplify-cli-core', async () => {
npmPackageManager.lockFile = 'package-lock-test.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -317,7 +318,7 @@ describe('parsing package lock files', () => {
});

it('correctly detect dependencies for fs-extra', async () => {
npmPackageManager.lockFile = 'package-lock-test.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand Down Expand Up @@ -365,7 +366,7 @@ describe('parsing package lock files', () => {
});

it('correctly detect dependencies for aws-cdk-lib', async () => {
npmPackageManager.lockFile = 'package-lock-test.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand All @@ -375,7 +376,7 @@ describe('parsing package lock files', () => {
});

it('should handle cycle in graph with npm', async () => {
npmPackageManager.lockFile = 'package-lock-test-with-cycle.json';
(npmPackageManager as $TSAny).lockFile = 'package-lock-test-with-cycle.json';
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(npmPackageManager);
const projectRoot = path.join(__dirname, 'resources');
const dec = await AmplifyNodePkgDetector.getInstance({
Expand All @@ -387,7 +388,7 @@ describe('parsing package lock files', () => {

describe('parsing yarn2 lock files', () => {
it('throw error on corrupted lock file', async () => {
yarnPackageManager.lockFile = 'yarn-2-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-2-test.lock';
yarnPackageManager.version = coerce('1.22.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand All @@ -402,7 +403,7 @@ describe('parsing yarn2 lock files', () => {
});

it('correctly detect dependencies for @aws-cdk/core', async () => {
yarnPackageManager.lockFile = 'yarn-2-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-2-test.lock';
yarnPackageManager.version = coerce('2.0.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand Down Expand Up @@ -444,7 +445,7 @@ describe('parsing yarn2 lock files', () => {
});

it('correctly detect dependencies for amplify-cli-core', async () => {
yarnPackageManager.lockFile = 'yarn-2-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-2-test.lock';
yarnPackageManager.version = coerce('2.0.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand Down Expand Up @@ -479,7 +480,7 @@ describe('parsing yarn2 lock files', () => {
});

it('correctly detect dependencies for fs-extra', async () => {
yarnPackageManager.lockFile = 'yarn-2-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-2-test.lock';
yarnPackageManager.version = coerce('2.0.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand Down Expand Up @@ -528,7 +529,7 @@ describe('parsing yarn2 lock files', () => {
});

it('correctly detect dependencies for aws-cdk-lib', async () => {
yarnPackageManager.lockFile = 'yarn-2-test.lock';
(yarnPackageManager as $TSAny).lockFile = 'yarn-2-test.lock';
yarnPackageManager.version = coerce('2.0.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(yarnPackageManager);
const projectRoot = path.join(__dirname, 'resources');
Expand Down
8 changes: 4 additions & 4 deletions packages/amplify-cli-core/src/utils/packageManager.ts
pavellazar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const packageJson = 'package.json';
* package Manager type
*/
export interface PackageManager {
jhockett marked this conversation as resolved.
Show resolved Hide resolved
packageManager: PackageManagerType;
lockFile: string;
executable: string;
displayValue: string;
readonly packageManager: PackageManagerType;
readonly lockFile: string;
readonly executable: string;
readonly displayValue: string;
version?: SemVer;
getRunScriptArgs: (scriptName: string) => string[];
getInstallArgs: (buildType: BuildType) => string[];
Expand Down
5 changes: 3 additions & 2 deletions packages/amplify-cli/src/__tests__/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
pathManager,
stateManager,
getPackageManagerByType,
$TSAny,
} from '@aws-amplify/amplify-cli-core';
import { execSync } from 'child_process';
import { ensureDir, existsSync, readFileSync, readJSON, readdirSync } from 'fs-extra';
Expand Down Expand Up @@ -38,8 +39,8 @@ jest.mock('which');
(sync as jest.MockedFunction<typeof sync>).mockReturnValue('mock/path');

const packageManager = getPackageManagerByType('yarn');
packageManager.lockFile = 'mock.lock';
packageManager.version = coerce('1.22.0') ?? undefined;
(packageManager as $TSAny).lockFile = 'mock.lock';
(packageManager as $TSAny).version = coerce('1.22.0') ?? undefined;
(getPackageManager as jest.MockedFunction<typeof getPackageManager>).mockResolvedValue(packageManager);

describe('amplify init:', () => {
Expand Down