mapbox / mapbox/node-pre-gyp

Chaining publish and unpublish Commands Changes Their Default Behavior

未关闭
#653 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
1.2k
派生
271
平均合并
23 小时 40 分钟
30 天内合并 PR
2

描述

## 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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/node-pre-gyp.js 中第247行和第275行附近的 binaryHostSet 处理开始,然后使用所示的 package.json staging_host 和 production_host 值重现该问题。使用独立的和链式的 publish/unpublish 命令验证修复;链式命令应默认使用 staging,而不是 production。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。