Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@fengmk2 是否可以考虑通过URL重写的方式兼容CYPRESS_DOWNLOAD_MIRROR方案呢? #267

Closed
cnmission opened this issue Jul 19, 2022 · 12 comments

Comments

@cnmission
Copy link

@fengmk2 是否可以考虑通过URL重写的方式兼容CYPRESS_DOWNLOAD_MIRROR方案呢?

比如配置CYPRESS_DOWNLOAD_MIRROR=https://npm.taobao.org/mirrors/cypress/

然后将类似于https://npm.taobao.org/mirrors/cypress/desktop/4.5.0?platform=linux&arch=x64这种规则重写为https://npm.taobao.org/mirrors/cypress/4.5.0/linux-x64/cypress.zip

我看阿里云的CDN应该支持这种重写规则,无论如何,感谢镜像站的付出。

Originally posted by @abcfy2 in cnpm/mirrors#215 (comment)

@cnmission
Copy link
Author

cnmission commented Jul 19, 2022

一种折中的方案是cypress增加一级目录/desktop,即https://cdn.npmmirror.com/binaries/cypress/10.3.0/linux-x64/cypress.zip 改成 https://cdn.npmmirror.com/binaries/cypress/desktop/10.3.0/linux-x64/cypress.zip

这样就可以通过设置CYPRESS_DOWNLOAD_MIRROR和CYPRESS_DOWNLOAD_PATH_TEMPLATE来达到正确的下载地址
CYPRESS_DOWNLOAD_MIRROR "https://cdn.npmmirror.com/binaries/cypress/"
CYPRESS_DOWNLOAD_PATH_TEMPLATE "${endpoint}/${platform}-${arch}/cypress.zip"

华为镜像源有做过这样的改动,但只有3.2.0一个版本https://repo.huaweicloud.com/cypress/desktop
image

@fengmk2
Copy link
Member

fengmk2 commented Jul 19, 2022

cnpm i cypress 我测试了一下可以正确安装,你是遇到了什么问题吗?

@fengmk2
Copy link
Member

fengmk2 commented Jul 19, 2022

@fengmk2
Copy link
Member

fengmk2 commented Jul 19, 2022

@cnmission
Copy link
Author

cnpm i cypress 我测试了一下可以正确安装,你是遇到了什么问题吗?

yarn安装时下载慢的问题,不是cnpm问题。

@abcfy2
Copy link

abcfy2 commented Jul 20, 2022

是否可以支持CYPRESS_DOWNLOAD_MIRROR环境变量?

这个变量在官方文档提及: https://docs.cypress.io/guides/references/advanced-installation#Mirroring

❯ CYPRESS_DOWNLOAD_MIRROR="https://npmmirror.com/mirrors/cypress/" npm i -D cypress
(##################) ⠋ reify:rxjs: timing reifyNode:node_modules/cypress Completed in 604ms
> cypress@10.3.1 postinstall
> node index.js --exec install

Installing Cypress (version: 10.3.1)iming reifyNode:node_modules/cypress Completed in 604ms

✖ The Cypress App could not be downloaded.
  Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment v…
  Otherwise, please check network connectivity and try again:
  ----------
  URL: https://npmmirror.com/mirrors/cypress/desktop/10.3.1?platform=linux&arch=x64
  Error: Failed downloading the Cypress binary.
  Response code: 404
  Response message: Not Found
  ----------
  Platform: linux-x64 (Manjaro Linux - 21.3.4)
  Cypress Version: 10.3.1
The Cypress App could not be downloaded.

Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration

Otherwise, please check network connectivity and try again:

----------

URL: https://npmmirror.com/mirrors/cypress/desktop/10.3.1?platform=linux&arch=x64
Error: Failed downloading the Cypress binary.
Response code: 404
Response message: Not Found

----------

Platform: linux-x64 (Manjaro Linux - 21.3.4)
Cypress Version: 10.3.1
npm ERR! code 1
npm ERR! path /tmp/npm-test/node_modules/cypress
npm ERR! command failed
npm ERR! command sh -c node index.js --exec install

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/fengyu/.npm/_logs/2022-07-20T02_08_44_002Z-debug-0.log

@fengmk2

@cnmission
Copy link
Author

我的理解,淘宝源是通过cnpm工具做了支持,你说的这个npm问题和yarn遇到的问题是一样的,npm和yarn要求指定的源要按照cypress的下载路径格式存放,npm和yarn本身没有对这个地址做转化的功能。
cnpm是对cypress的地址做了特殊处理,所以可以正常通过淘宝源下载。
所以:npm和yarn目前无法通过环境变量支持淘宝源,需要淘宝源或者cypress的路径格式做修改才能支持。

@abcfy2
Copy link

abcfy2 commented Jul 20, 2022

@cnmission @fengmk2 看了下cypress的源码: https://github.com/cypress-io/cypress/blob/36278fca013e24c17f8060dba4c0eaed5c2d396f/cli/lib/tasks/download.js#L78-L86

cypress还支持CYPRESS_DOWNLOAD_PATH_TEMPLATE变量设置拼接下载路径。我尝试这么解决,更进了一步:

❯ CYPRESS_DOWNLOAD_MIRROR='https://npmmirror.com/mirrors/cypress/' CYPRESS_DOWNLOAD_PATH_TEMPLATE='${endpoint}/${platform}-${arch}/cypress.zip' npm i -D cypress
(##################) ⠦ reify:cypress: timing reifyNode:node_modules/lodash Completed in 652ms
> cypress@10.3.1 postinstall
> node index.js --exec install

Installing Cypress (version: 10.3.1)iming reifyNode:node_modules/cypress Completed in 666ms

✖ The Cypress App could not be downloaded.
  Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment v…
  Otherwise, please check network connectivity and try again:
  ----------
  URL: https://npmmirror.com/mirrors/cypress/desktop/10.3.1/linux-x64/cypress.zip
  Error: Failed downloading the Cypress binary.
  Response code: 404
  Response message: Not Found
  ----------
  Platform: linux-x64 (Manjaro Linux - 21.3.4)
  Cypress Version: 10.3.1
The Cypress App could not be downloaded.

Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration

Otherwise, please check network connectivity and try again:

----------

URL: https://npmmirror.com/mirrors/cypress/desktop/10.3.1/linux-x64/cypress.zip
Error: Failed downloading the Cypress binary.
Response code: 404
Response message: Not Found

----------

Platform: linux-x64 (Manjaro Linux - 21.3.4)
Cypress Version: 10.3.1
npm ERR! code 1
npm ERR! path /tmp/npm-test/node_modules/cypress
npm ERR! command failed
npm ERR! command sh -c node index.js --exec install

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/fengyu/.npm/_logs/2022-07-20T02_34_33_713Z-debug-0.log

是否可以再增加一级目录/desktop软连接到根目录?

/desktop --> ./

这样就可以解决cypress download binary的问题

@cnmission
Copy link
Author

cnmission commented Jul 20, 2022

或许cypress修改一下更好点
cypress-io/cypress#22864

@fengmk2
Copy link
Member

fengmk2 commented Nov 6, 2022

cnpm/binary-mirror-config#41 已经支持。

@SevenOutman
Copy link

所以 CYPRESS_DOWNLOAD_MIRROR 设置为何值才能正确下载到淘宝源上的文件呢?

@abcfy2
Copy link

abcfy2 commented Nov 18, 2022

所以 CYPRESS_DOWNLOAD_MIRROR 设置为何值才能正确下载到淘宝源上的文件呢?

见cnpm的配置文件用例: https://github.com/cnpm/binary-mirror-config/blob/master/package.json#L59

CYPRESS_DOWNLOAD_PATH_TEMPLATE=https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip

另外我给cypress提交了一个PR,可以支持通过npm config set CYPRESS_DOWNLOAD_PATH_TEMPLATE 'https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip'也实现同样的目的: cypress-io/cypress#24664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants