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(aws-lambda-nodejs): Remove dependency on global parcel installation #6206

Merged
merged 1 commit into from
Feb 14, 2020
Merged

fix(aws-lambda-nodejs): Remove dependency on global parcel installation #6206

merged 1 commit into from
Feb 14, 2020

Conversation

mattsains
Copy link
Contributor

Fixes #6204


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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mattsains
Copy link
Contributor Author

mattsains commented Feb 10, 2020

I'm no longer sure whether this would fix the problem, the spawn command might mean that npx is running on the package using aws-lambda-nodejs rather than aws-lambda-nodejs itself. I'm trying to consume my local version of the CDK to see if it works.

Edit: I performed a test where I ran npm pack on aws-lambda-nodejs, then npm install aws-cdk-aws-lambda-nodejs-1.23.0.tgz from my repo that contains a nodejs function. I then ensured that parcel was not installed globally using npm remove -g parcel and ran cdk synth. Synthesis succeeded.

I think the answer to my concern above is that parcel is included as a transitive dependency, so as long as you're depending on @aws-cdk/aws-lambda-nodejs, parcel will be included as well, and npx will be able to find it.

@mattsains mattsains changed the title fix(aws-lambda-nodejs): Remove dependency on gloabl parcel installation fix(aws-lambda-nodejs): Remove dependency on global parcel installation Feb 10, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@jogold jogold left a comment

Choose a reason for hiding this comment

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

@mattsains what do you think of the suggested solution without npx? Can you test it with your setup?

@@ -72,7 +73,7 @@ export function build(options: BuildOptions): void {
: [],
].filter(Boolean) as string[];

const parcel = spawnSync('parcel', args);
const parcel = spawnSync('npx', args);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const parcel = spawnSync('npx', args);
const parcelPkgPath = require.resolve('parcel-bundler/package.json'); // eslint-disable-line @typescript-eslint/no-require-imports
const parcelDir = path.dirname(parcelPkgPath);
const parcelPkg = require(parcelPkgPath); // eslint-disable-line @typescript-eslint/no-require-imports
const binPath = path.join(parcelDir, parcelPkg.bin.parcel);
const parcel = spawnSync(binPath, args);

Copy link
Contributor

Choose a reason for hiding this comment

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

@eladb can you have a look?

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 will try this out, thanks for the suggestion!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that worked for me, and I think it's the right way to go, I'll update 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.

Yes this is how I would do it

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 updated the PR with that suggestion.

@@ -31,7 +31,8 @@ test('NodejsFunction', () => {
// THEN
const { spawnSync } = require('child_process'); // eslint-disable-line @typescript-eslint/no-require-imports

expect(spawnSync).toHaveBeenCalledWith('parcel', expect.arrayContaining([
expect(spawnSync).toHaveBeenCalledWith('npx', expect.arrayContaining([
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(spawnSync).toHaveBeenCalledWith('npx', expect.arrayContaining([
expect(spawnSync).toHaveBeenCalledWith(expect.stringContaining('parcel-bundler'), expect.arrayContaining([

@@ -50,7 +51,8 @@ test('NodejsFunction', () => {
]));

// Automatically finds .js handler file
expect(spawnSync).toHaveBeenCalledWith('parcel', expect.arrayContaining([
expect(spawnSync).toHaveBeenCalledWith('npx', expect.arrayContaining([
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(spawnSync).toHaveBeenCalledWith('npx', expect.arrayContaining([
expect(spawnSync).toHaveBeenCalledWith(expect.stringContaining('parcel-bundler'), expect.arrayContaining([

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 302b093
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Feb 14, 2020

Thank you for contributing! Your pull request is now being automatically merged.

@mergify mergify bot merged commit ce96e08 into aws:master Feb 14, 2020
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.

aws-lambda-nodejs doesn't build if parcel is not installed globally
5 participants