Skip to content

Commit

Permalink
fix: yarn modern install workspace (aws-amplify#13197)
Browse files Browse the repository at this point in the history
* fix: yarn modern install workspace

* chore: update yarn.lock

* chore: update yarn.lock

* chore: update api

* test: add yarn 3 test to standalone

* Revert "test: add yarn 3 test to standalone"

This reverts commit 37be610.

* fix: build function error and add test

* chore: change fs.writeFile to Sync

* chore: add test to codeBuild

* fix: fix pr check

---------

Co-authored-by: 0.618 <[email protected]>
  • Loading branch information
0618 and 0.618 authored Mar 27, 2024
1 parent 41ec40a commit 3ca4aa9
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 208 deletions.
248 changes: 128 additions & 120 deletions codebuild_specs/e2e_workflow_generated.yml

Large diffs are not rendered by default.

119 changes: 60 additions & 59 deletions codebuild_specs/wait_for_ids.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[
"l_S3server_api_8_function_8",
"l_amplify_app",
"l_amplify_configure_env_2_init_d",
"l_analytics_kinesis_analytics_pinpoint_flutter_analytics_pinpoint_js",
"l_android_notifications_pinpoint_config_flutter_analytics_pinpoint_config_flutter_notifications_pinpoint_config",
"l_android_analytics_pinpoint_config_android_notifications_pinpoint_config_flutter_analytics_pinpoint_config",
"l_api_2b_api_6c_api_9a",
"l_api_3_api_6b_api_1",
"l_api_4_containers_api_secrets_storage_4",
"l_api_6a_auth_7b_export_pull_b",
"l_api_6b_api_1_layer_1",
"l_api_7_export_pull_a_function_9a",
"l_api_key_migration1_schema_auth_14_api_3",
"l_api_key_migration4_schema_iterative_update_4_function_1",
"l_api_key_migration_2_v8",
"l_api_key_migration_v8",
"l_api_lambda_auth_1_api_key_migration2_schema_searchable",
"l_apigw_api_lambda_auth_1_api_key_migration2",
"l_auth_12_auth_2g_auth_2h",
"l_auth_1a_auth_trigger_custom_policies_function",
"l_auth_1b_delete_geo_add_c",
Expand All @@ -25,7 +23,6 @@
"l_auth_4b_auth_8a_export_pull_d",
"l_auth_4c_auth_5a_auth_5c",
"l_auth_5g_admin_api_hosted_ui",
"l_auth_6_function_2a_schema_connection_2",
"l_auth_7a_auth_8c_feature_flags",
"l_auth_9_custom_resources_env_5",
"l_auth_app_client_secret_migration_v12",
Expand All @@ -36,39 +33,40 @@
"l_auth_migration_amplify_remove_api_2a",
"l_auth_migration_v12",
"l_auth_oauth_lambda_migration_v12",
"l_build_function_custom_resource_with_storage_dynamodb_simulator",
"l_container_hosting_init_b_notifications_apns",
"l_containers_api_1",
"l_containers_api_2",
"l_containers_api_secrets_storage_4_schema_auth_10",
"l_custom_resource_with_storage_dynamodb_simulator_export_pull_c",
"l_custom_policies_container_function_9b_schema_iterative_update_2",
"l_datastore_modelgen",
"l_diagnose_hooks_a_mock_api",
"l_env_1_geo_add_a_init_a",
"l_env_3",
"l_env_4_frontend_config_drift_schema_auth_4d",
"l_export_pull_c_function_12_function_13",
"l_flutter_notifications_pinpoint_config_ios_analytics_pinpoint_config_ios_notifications_pinpoint_config",
"l_function_10_function_9c_function_permissions",
"l_function_12_function_13_function_14",
"l_function_15_function_2d_general_config_headless_init",
"l_function_14_function_15_function_2d",
"l_function_1_storage_5",
"l_function_2b_function_7_api_connection_migration2",
"l_function_2c_function_3b_function_4",
"l_function_3a_init_special_case_http_migration",
"l_function_6_storage_2_export",
"l_function_7_api_connection_migration2_api_4",
"l_function_9b_schema_iterative_update_2_storage_1a",
"l_function_8_schema_iterative_update_locking_api_lambda_auth_2",
"l_general_config_headless_init_help_hooks_c",
"l_geo_add_b_s3_sse_schema_auth_4a",
"l_geo_add_d_geo_import_3_hosting",
"l_geo_add_e",
"l_geo_add_f",
"l_geo_headless_api_key_migration5_schema_auth_1a",
"l_geo_import_1a_geo_import_2_global_sandbox_b",
"l_geo_import_1b_global_sandbox_a_init_e",
"l_geo_multi_env_searchable_datastore_resolvers",
"l_geo_remove_1",
"l_geo_remove_2",
"l_geo_remove_3",
"l_geo_update_1",
"l_geo_update_2",
"l_git_clone_attach_init_c_layer_4",
"l_help_hooks_c_init_force_push",
"l_hooks_b_notifications_analytics_compatibility_sms_1_plugin",
"l_hostingPROD",
"l_iam_permissions_boundary_node_function_notifications_sms",
Expand All @@ -87,24 +85,26 @@
"l_import_s3_2c",
"l_import_s3_3",
"l_init_f_auth_5d_configure_project",
"l_interactions_1_interactions_2_minify_cloudformation",
"l_init_force_push_interactions_1_interactions_2",
"l_interactions_schema_model_a_tags",
"l_ios_analytics_pinpoint_config_ios_notifications_pinpoint_config_javascript_analytics_pinpoint_config",
"l_javascript_notifications_pinpoint_config_pr_previews_multi_env_1_pull_2",
"l_javascript_analytics_pinpoint_config_javascript_notifications_pinpoint_config_pr_previews_multi_env_1",
"l_js_frontend_config",
"l_layer_1_api_key_migration4_schema_iterative_update_4",
"l_layer_2_schema_auth_13_function_5",
"l_layer_3_api_connection_migration_api_key_migration3",
"l_minify_cloudformation_notifications_multi_env_notifications_sms_update",
"l_notifications_analytics_compatibility_in_app_2_schema_auth_11_c_schema_auth_2b",
"l_notifications_analytics_compatibility_sms_2_analytics_2_global_sandbox_c",
"l_notifications_fcm_notifications_in_app_messaging_env_2_with_babel_config",
"l_notifications_in_app_messaging",
"l_notifications_multi_env_notifications_sms_update_opensearch_simulator",
"l_notifications_sms_pull_pull_auth_10",
"l_parameter_store_1_parameter_store_2_android_analytics_pinpoint_config",
"l_opensearch_simulator_parameter_store_1_parameter_store_2",
"l_predictions_schema_auth_11_b_schema_auth_1b",
"l_push_smoketest_ios_smoketest",
"l_pull_2_push_smoketest_ios",
"l_resolvers_schema_key_api_5",
"l_schema_auth_10_geo_multi_env_searchable_datastore",
"l_schema_auth_11_a",
"l_schema_auth_12_schema_auth_3_schema_function_2",
"l_schema_auth_13_function_5_schema_iterative_update_1",
"l_schema_auth_15",
"l_schema_auth_2a_schema_auth_7a_schema_auth_7b",
"l_schema_auth_4b_schema_model_e_schema_versioned",
Expand All @@ -118,32 +118,38 @@
"l_schema_auth_9_b_schema_iterative_rollback_1_predictions_migration",
"l_schema_auth_9_c_storage_3_auth_11",
"l_schema_connection_1",
"l_schema_function_1_api_9b_custom_policies_container",
"l_schema_iterative_update_locking_api_lambda_auth_2_layer_2",
"l_schema_key_api_5_apigw",
"l_schema_connection_2_schema_function_1_api_9b",
"l_schema_iterative_update_1_auth_6_function_2a",
"l_schema_model_b_schema_model_d_auth_5f",
"l_schema_predictions_model_migration_auth_3c",
"l_schema_searchable_api_key_migration1_schema_auth_14",
"l_searchable_migration",
"l_smoketest_S3server_api_8",
"l_smoketest_amplify_app",
"l_storage_1b_function_11_function_2b",
"l_storage_5",
"l_storage_1a_storage_1b_function_11",
"l_studio_modelgen_custom_transformers_notifications_in_app_messaging_env_1",
"l_uibuilder",
"l_user_groups_s3_access_user_groups_build_function",
"l_user_groups_s3_access_user_groups_build_function_yarn_modern",
"w_amplify_configure_init_d",
"w_amplify_remove_api_2a",
"w_analytics_2_global_sandbox_c",
"w_analytics_kinesis_analytics_pinpoint_flutter",
"w_analytics_pinpoint_js_auth_2a",
"w_api_10_api_7",
"w_api_1_layer_1",
"w_api_2b_api_6c",
"w_api_4_containers_api_secrets",
"w_api_5_apigw",
"w_api_3_api_6b",
"w_api_6a_auth_7b",
"w_api_6b_api_1",
"w_api_8_schema_iterative_update_locking",
"w_api_9a_auth_2h",
"w_api_9b_custom_policies_container",
"w_api_connection_migration2_api_4",
"w_api_connection_migration_api_key_migration3",
"w_api_lambda_auth_1_api_key_migration2",
"w_api_key_migration1_schema_auth_14",
"w_api_key_migration2_schema_searchable",
"w_api_key_migration4_schema_iterative_update_4",
"w_api_lambda_auth_2_schema_auth_13",
"w_apigw_api_lambda_auth_1",
"w_auth_11_auth_1b",
"w_auth_2b_auth_2d",
"w_auth_2c",
Expand All @@ -155,38 +161,41 @@
"w_auth_5a_auth_5c",
"w_auth_5e_auth_8b",
"w_auth_5g_admin_api",
"w_auth_6_function_2a",
"w_auth_7a_auth_8c",
"w_auth_9_env_5",
"w_auth_trigger_custom_policies_function",
"w_build_function_dynamodb_simulator",
"w_configure_project_init_c",
"w_container_hosting_init_b",
"w_containers_api_1",
"w_containers_api_2",
"w_custom_policies_container_function_9b",
"w_containers_api_secrets_storage_4",
"w_custom_transformers_notifications_in_app_messaging_env_1",
"w_delete_geo_add_c",
"w_dynamodb_simulator_export_pull_c",
"w_env_1_geo_add_a",
"w_env_3",
"w_env_4_frontend_config_drift",
"w_export_pull_a_function_9a",
"w_export_pull_b_init_special_case",
"w_export_pull_c_function_12",
"w_export_pull_d_schema_auth_5a",
"w_feature_flags_geo_import_1b",
"w_function_1",
"w_function_10_function_9c",
"w_function_12_function_13",
"w_function_14_function_2d",
"w_function_2a_schema_connection_2",
"w_function_2b_api_connection_migration2",
"w_function_11_function_2b",
"w_function_13_function_14",
"w_function_2d_general_config_headless_init",
"w_function_5_schema_iterative_update_1",
"w_function_9b_schema_iterative_update_2",
"w_function_permissions_geo_import_1a",
"w_general_config_headless_init_help",
"w_geo_add_b_s3_sse",
"w_geo_add_d_geo_import_3",
"w_geo_headless_api_key_migration5",
"w_geo_import_2_global_sandbox_b",
"w_geo_multi_env_searchable_datastore",
"w_geo_remove_1",
"w_global_sandbox_a_init_e",
"w_help_init_force_push",
"w_hooks_b_notifications_analytics_compatibility_sms_1",
"w_hosted_ui_user_groups_s3_access",
"w_hostingPROD",
Expand All @@ -197,28 +206,24 @@
"w_import_s3_3",
"w_init_a_schema_auth_4c",
"w_init_f_auth_5d",
"w_init_force_push_interactions_1",
"w_interactions_2_minify_cloudformation",
"w_interactions_1_interactions_2",
"w_interactions_schema_model_a",
"w_js_frontend_config",
"w_layer_1_api_key_migration4",
"w_layer_4_function_2c",
"w_minify_cloudformation_notifications_multi_env",
"w_node_function_notifications_sms",
"w_notifications_analytics_compatibility_in_app_1_notifications_analytics_compatibility_sms_2",
"w_notifications_analytics_compatibility_in_app_2_schema_auth_11_c",
"w_notifications_apns_notifications_fcm",
"w_notifications_in_app_messaging",
"w_notifications_in_app_messaging_env_2_with_babel_config",
"w_notifications_multi_env_notifications_sms_update",
"w_notifications_sms_pull_auth_10",
"w_parameter_store_1_parameter_store_2",
"w_notifications_sms_update_parameter_store_1",
"w_parameter_store_2_push",
"w_plugin_studio_modelgen",
"w_predictions_schema_auth_11_b",
"w_push_smoketest_ios",
"w_resolvers_schema_key",
"w_schema_auth_10_geo_multi_env",
"w_schema_auth_11_a",
"w_schema_auth_13_function_5",
"w_schema_auth_14_api_3",
"w_schema_auth_15",
"w_schema_auth_1a_schema_auth_5b",
"w_schema_auth_1b_schema_auth_2a",
Expand All @@ -237,22 +242,18 @@
"w_schema_auth_9_b_predictions_migration",
"w_schema_auth_9_c_storage_3",
"w_schema_connection_1",
"w_schema_connection_2_schema_function_1",
"w_schema_data_access_patterns_schema_model_c",
"w_schema_function_1_api_9b",
"w_schema_iterative_update_1_auth_6",
"w_schema_iterative_update_2_storage_1a",
"w_schema_iterative_update_3_auth_migration",
"w_schema_iterative_update_4_function_1",
"w_schema_iterative_update_locking_api_lambda_auth_2",
"w_schema_key_api_5",
"w_schema_model_d_auth_5f",
"w_schema_predictions_model_migration",
"w_schema_searchable_api_key_migration1",
"w_schema_versioned_auth_1c",
"w_searchable_datastore_resolvers",
"w_searchable_migration",
"w_smoketest_api_8",
"w_storage_1b_function_11",
"w_smoketest_ios_smoketest",
"w_storage_1a_storage_1b",
"w_storage_2_iam_permissions_boundary",
"w_storage_4_schema_auth_10",
"w_tags_auth_1a",
"w_user_groups_build_function"
"w_user_groups_build_function_yarn_modern"
]
2 changes: 1 addition & 1 deletion packages/amplify-cli-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ export interface PackageManager {
// (undocumented)
readonly executable: string;
// (undocumented)
getInstallArgs: (buildType: BuildType) => string[];
getInstallArgs: (buildType: BuildType, resourceDir?: string) => string[];
// (undocumented)
getRunScriptArgs: (scriptName: string) => string[];
// (undocumented)
Expand Down
19 changes: 16 additions & 3 deletions packages/amplify-cli-core/src/utils/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface PackageManager {
readonly displayValue: string;
version?: SemVer;
getRunScriptArgs: (scriptName: string) => string[];
getInstallArgs: (buildType: BuildType) => string[];
getInstallArgs: (buildType: BuildType, resourceDir?: string) => string[];
}

class NpmPackageManager implements PackageManager {
Expand All @@ -43,9 +43,22 @@ class YarnPackageManager implements PackageManager {
version?: SemVer;

getRunScriptArgs = (scriptName: string) => [scriptName];
getInstallArgs = (buildType = BuildType.PROD) => {
getInstallArgs = (buildType = BuildType.PROD, resourceDir = '') => {
const useYarnModern = this.version?.major && this.version?.major > 1;
return (useYarnModern ? ['install'] : ['--no-bin-links']).concat(buildType === 'PROD' ? ['--production'] : []);
/**
* Since Yarn 2, resourceDir needs to be treated as a separate project,
* otherwise it'll be hoisted to use the lock.file from the parent directory,
* so we need to create a lock file for it.
* ref: https://github.com/yarnpkg/yarn/issues/5716#issuecomment-817330338
*/
if (useYarnModern) {
if (fs.existsSync(`${resourceDir}/${this.lockFile}`)) {
console.log(`${resourceDir}/${this.lockFile} already exists.`);
} else {
fs.writeFileSync(`${resourceDir}/${this.lockFile}`, '');
}
}
return (useYarnModern ? ['workspaces', 'focus'] : ['--no-bin-links']).concat(buildType === 'PROD' ? ['--production'] : []);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import execa from 'execa';
import {
addFunction,
createNewProjectDir,
deleteProject,
deleteProjectDir,
functionBuild,
initJSProjectWithProfile,
} from '@aws-amplify/amplify-e2e-core';

describe('build successfully via Yarn Modern', () => {
let projRoot: string;

beforeEach(async () => {
projRoot = await createNewProjectDir('analytics');
await execa('corepack', ['enable'], { cwd: projRoot });
await execa('yarn', ['init', '-2'], { cwd: projRoot });
await execa('yarn', ['--version'], { cwd: projRoot });
});

afterEach(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

it('add analytics and function', async () => {
await initJSProjectWithProfile(projRoot, {});
await addFunction(
projRoot,
{
functionTemplate: 'Hello World',
},
'nodejs',
);
await functionBuild(projRoot);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const runPackageManagerInstall = async (resourceDir: string, buildType: BuildTyp
return;
}

const args = packageManager.getInstallArgs(buildType);
const args = packageManager.getInstallArgs(buildType, resourceDir);
await runPackageManager(packageManager, args, resourceDir);
};

Expand Down
Loading

0 comments on commit 3ca4aa9

Please sign in to comment.