aws / aws/aws-lambda-builders

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

Offen
#187 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area/workflow/node_npm maintainer/need-response type/feature
Vorherrschende Sprache
Python
Sterne
381
Forks
162
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
2

Beschreibung

**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] https://github.com/npm/npm/issues/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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem Node.js-Lambda-Builder-Pfad, der von `sam build` verwendet wird, und reproduziere dann das Problem mit einem NPM-Projekt, das externe Abhängigkeiten hat. Untersuche `package.json`-Dateien unter `build/node_modules` auf `_where` und zugehörige Metadaten mit absoluten Pfaden; als abgeschlossen gilt die Untersuchung, wenn wiederholte Builds aus verschiedenen Verzeichnissen ein ortsunabhängiges Ergebnis erzeugen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
node.js
Bereich
build-system
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.