mapbox / mapbox/node-pre-gyp

Chaining publish and unpublish Commands Changes Their Default Behavior

Offen
#653 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
JavaScript
Sterne
1.2k
Forks
271
Ø Merge
23 Std. 40 Min.
Gemergte PRs (30 T.)
2

Beschreibung

## Describe the bug

Chaining `publish` and `unpublish` commands changes their default behavior in relation to staging/production hosts.

## Expected Behavior
Commands `publish` and `unpublish` should **always** default to staging when `production_host` and `staging_host` are defined under `binary` in package.json.

## Actual Behavior

When the commands `publish` and `unpublish` are executed by themselves they default to staging. However, if the command being executed is chained after another command (for example `package publish` or `info unpublish`) then the default reverts to `binary.production_host`. As a result - **accidental publishing/unpublishing is possible**.

## Steps to Reproduce

### 1) Prep package.json
Replace "host" with `staging_host` and `production_host` in package.json

Example:
```
"staging_host": "https://apm-appoptics-bindings-node-dev-staging.s3.us-east-1.amazonaws.com",
"production_host": "https://apm-appoptics-bindings-node-dev-production.s3.us-east-1.amazonaws.com",
```

### 2) Run Commands one after the other
`node-pre-gyp package`
`node-pre-gyp publish`

Results in: ✅
```
[node-pre-gyp-test-app1] published to https://apm-appoptics-bindings-node-dev-staging.s3.us-east-1.amazonaws.com/node-pre-gyp/node-pre-gyp-test-app1/v0.1.0/Release/
```

`node-pre-gyp info`
`node-pre-gyp unpublish`

Results in: ✅
```
[node-pre-gyp-test-app1] Success: removed https://apm-appoptics-bindings-node-dev-staging.s3.amazonaws.com/node-pre-gyp/node-pre-gyp-test-app1/v0.1.0/Release/node-v83-darwin-x64.tar.gz
```

### 3) Run Chained Commands
`node-pre-gyp package publish`

Results in: ❌
```
[node-pre-gyp-test-app1] published to https://apm-appoptics-bindings-node-dev-production.s3.us-east-1.amazonaws.com/node-pre-gyp/node-pre-gyp-test-app1/v0.1.0/Release/
```

`node-pre-gyp info unpublish`

Results in: ❌
```
[node-pre-gyp-test-app1] Success: removed https://apm-appoptics-bindings-node-dev-production.s3.amazonaws.com/node-pre-gyp/node-pre-gyp-test-app1/v0.1.0/Release/node-v83-darwin-x64.tar.gz
```
## Root Cause
When chained commands are executed, the first command in the chain will [raise the `binaryHostSet` flag](https://github.com/mapbox/node-pre-gyp/blob/master/lib/node-pre-gyp.js#L275). Subsequent `publish` or `unpublish` [will trigger the early return](https://github.com/mapbox/node-pre-gyp/blob/master/lib/node-pre-gyp.js#L247). Due to the early return, the host will not be configured correctly resulting in the bug described above.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in lib/node-pre-gyp.js bei der binaryHostSet-Verarbeitung um die Zeilen 247 und 275 und reproduziere dann das Problem mit den angegebenen package.json-Werten für staging_host und production_host. Überprüfe den Fix sowohl mit eigenständigen als auch mit verketteten publish/unpublish-Befehlen; verkettete Befehle sollten standardmäßig staging statt production verwenden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

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