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

fix: remove vm2 #12989

Merged
merged 7 commits into from
Jul 26, 2023
Merged

fix: remove vm2 #12989

merged 7 commits into from
Jul 26, 2023

Conversation

awsluja
Copy link
Contributor

@awsluja awsluja commented Jul 22, 2023

Description of changes

Remove dependency on vm2. Remaining references should be removed with API changes

Issue #, if available

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

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

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 113 to 117
formatter.list(['No override File Found', `To override ${this.resourceName} run amplify override auth`]);
return '';
});

const sandboxNode = new vm.NodeVM({
console: 'inherit',
timeout: 5000,
sandbox: {},
require: {
context: 'sandbox',
builtin: ['path'],
external: true,
},
});
const overrideJSFilePath = path.join(overrideDir, 'build', 'override.js');
const projectInfo = getProjectInfo();
try {
await sandboxNode
.run(overrideCode, path.join(overrideDir, 'build', 'override.js'))
.override(this._authTemplateObj as AmplifyAuthCognitoStack & AmplifyStackTemplate, projectInfo);
const overrideImport = await import(overrideJSFilePath);
if (overrideImport && overrideImport?.override && typeof overrideImport?.override === 'function') {
overrideImport.override(this._authTemplateObj, projectInfo);
}
Copy link
Member

Choose a reason for hiding this comment

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

now that all these overrides look very similar consider extracting common code somewhere here https://github.com/aws-amplify/amplify-cli/tree/dev/packages/amplify-cli-core/src/overrides-manager . e.g. create override-runner.ts and extract code in such a way that what remains here is await runOverride(overrideDir, this._authTemplateObj).
Project info can be looked up in core I think, if not add one more parameter.

yarn.lock Outdated
@@ -29815,7 +29812,7 @@ node-pty@beta:
languageName: node
linkType: hard

"vm2@npm:^3.9.19, vm2@npm:^3.9.3, vm2@npm:^3.9.8":
"vm2@npm:^3.9.3, vm2@npm:^3.9.8":
Copy link
Member

Choose a reason for hiding this comment

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

I suggest we get this into dev first and merge to this PR #12986 .
So that we can remove vm2 entries entirely.

Comment on lines 4 to 11
export const runOverride = (overrideDir: string, templateObject: $TSAny, projectInfo: $TSAny): void => {
const overrideJSFilePath = path.join(overrideDir, 'build', 'override.js');
delete require.cache[require.resolve(overrideJSFilePath)];
const overrideImport = require(overrideJSFilePath);
if (overrideImport && overrideImport?.override && typeof overrideImport?.override === 'function') {
overrideImport.override(templateObject, projectInfo);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

In some places we had.

await sandboxNode
            .run(overrideCode, overrideJSFilePath)
            .override(this._resourceTemplateObj as AmplifyDDBResourceTemplate, projectInfo);

we should make this function async and await overrideImport.override(templateObject, projectInfo);.

This works even if overrideImport.override is sync and returns void . The way compiler handles awaits is that it inspects return object coming from function at runtime.

@@ -30715,7 +30712,7 @@ node-pty@beta:
languageName: node
linkType: hard

"vm2@npm:^3.9.19, vm2@npm:^3.9.3":
"vm2@npm:^3.9.3":
Copy link
Member

Choose a reason for hiding this comment

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

I was expecting this to be gone.
Could you yarn why vm2 --recursive to see where this is still coming from ?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like.


$ yarn why vm2
└─ degenerator@npm:3.0.1
   └─ vm2@npm:3.9.19 (via npm:^3.9.3)

$ yarn why degenerator
└─ pac-resolver@npm:5.0.0
   └─ degenerator@npm:3.0.1 (via npm:^3.0.1)

$ yarn why pac-resolver
└─ pac-proxy-agent@npm:5.0.0
   └─ pac-resolver@npm:5.0.0 (via npm:^5.0.0)

$ yarn why pac-proxy-agent
└─ proxy-agent@npm:5.0.0
   └─ pac-proxy-agent@npm:5.0.0 (via npm:^5.0.0)


$ yarn why proxy-agent
├─ @aws-amplify/amplify-category-notifications@workspace:packages/amplify-category-notifications
│  └─ proxy-agent@npm:5.0.0 (via npm:^5.0.0)
│
├─ @aws-amplify/amplify-cli-core@workspace:packages/amplify-cli-core
│  └─ proxy-agent@npm:5.0.0 (via npm:^5.0.0)
│
└─ @aws-amplify/amplify-provider-awscloudformation@workspace:packages/amplify-provider-awscloudformation
   └─ proxy-agent@npm:5.0.0 (via npm:^5.0.0)

Copy link
Member

Choose a reason for hiding this comment

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

So we should seek proxy-agent update. But that should happen in separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

sobolk
sobolk previously approved these changes Jul 25, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #12989 (01d4225) into dev (ec9a2ba) will increase coverage by 48.39%.
Report is 259 commits behind head on dev.
The diff coverage is 54.85%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@             Coverage Diff             @@
##              dev   #12989       +/-   ##
===========================================
+ Coverage    0.00%   48.39%   +48.39%     
===========================================
  Files        1296      841      -455     
  Lines      149743    38029   -111714     
  Branches     1296     7781     +6485     
===========================================
+ Hits            0    18406    +18406     
+ Misses     148447    18031   -130416     
- Partials     1296     1592      +296     
Files Changed Coverage Δ
...rmation/auth-stack-builder/auth-stack-transform.ts 91.30% <0.00%> (+91.30%) ⬆️
...h-stack-builder/user-pool-group-stack-transform.ts 94.59% <0.00%> (+94.59%) ⬆️
.../src/provider-utils/awscloudformation/constants.ts 100.00% <ø> (+100.00%) ⬆️
...e-walkthrough-types/awsCognito-user-input-types.ts 100.00% <ø> (+100.00%) ⬆️
...vice-walkthrough-types/cognito-user-input-types.ts 100.00% <ø> (+100.00%) ⬆️
...y-category-function/src/commands/function/build.ts 0.00% <0.00%> (ø)
...ify-category-function/src/events/prePushHandler.ts 33.33% <0.00%> (+33.33%) ⬆️
...ider-utils/awscloudformation/utils/layerHelpers.ts 21.80% <0.00%> (+21.80%) ⬆️
...er-utils/awscloudformation/utils/storeResources.ts 30.38% <ø> (+30.38%) ⬆️
...ib/S3AndCloudFront/helpers/configure-CloudFront.js 87.06% <ø> (+87.06%) ⬆️
... and 64 more

... and 1234 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@awsluja awsluja marked this pull request as ready for review July 25, 2023 21:24
@awsluja awsluja requested a review from a team as a code owner July 25, 2023 21:24
@awsluja awsluja added the do-not-merge PRs that are approved and green, but should not be merged yet label Jul 25, 2023
@awsluja awsluja changed the title fix: remove vm2 DO NOT MERGE YET: fix: remove vm2 Jul 25, 2023
@awsluja awsluja changed the title DO NOT MERGE YET: fix: remove vm2 fix: remove vm2 Jul 26, 2023
@awsluja awsluja merged commit 7bc0b56 into aws-amplify:dev Jul 26, 2023
@awsluja awsluja removed the do-not-merge PRs that are approved and green, but should not be merged yet label Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants