Skip to content

Node.js: Built projects contain the absolute path of the build directory #187

Open
@coder17934

Description

@coder17934

Description:

This is more of a feature request, so apologies if this doesn't belong here. Many versions ago NPM introduced adding metadata into package.json when building a project. As far as I can tell it was done as an extension point that future version could use, see [1] for more details. The problem is that one of the added pieces of metadata is the absolute location of where the project was built, which in itself isn't great but coupled with the fact that SAM uses a directory hash for tracking changes and that AWS CodeBuild uses ephemeral build directories means that files will always appear to have changed even when the only thing that's changed is the location of the build directory. While it doesn't look like NPM will fix the issue any time soon my hope was that the Node lambda builder can run a command after build to remove the metadata. As the metadata isn't used by NPM this is currently completely safe. In fact my current workaround uses [2] to remove the metadata after running sam build. I am happy to submit a PR if it's deemed appropriate, although it might take some time due to work commitments.

[1] npm/npm#10393
[2] https://www.npmjs.com/package/removeNPMAbsolutePaths

Steps to reproduce the issue:

  1. Run sam build on an NPM project with external dependencies
  2. In the build directory, in node_modules, look at a package.json

Observed result:

You will see properties such as "_where": "/Users/jshore/Documents/Projects/weewikipaint", containing the absolute path of build directory.

Expected result:

A build should be idempotent and not dependent on build location.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Reproducible on both Mac and Amazon Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions