Chaining publish and unpublish Commands Changes Their Default Behavior
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 1.2k
- Forks
- 271
- Merge medio
- 23 h 40 min
- PR fusionados (30 d)
- 2
Descripción
## 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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en lib/node-pre-gyp.js, en el manejo de binaryHostSet alrededor de las líneas 247 y 275, y luego reproduce el problema con los valores de staging_host y production_host de package.json que se muestran. Verifica la corrección tanto con comandos publish/unpublish independientes como encadenados; los comandos encadenados deben usar staging de forma predeterminada en lugar de production.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- cli
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 48/100