electron / get

Download Electron release artifacts
https://npm.im/@electron/get
MIT License
338 stars 106 forks source link

The link to download the zip is wrong #149

Closed daydayhappychao closed 4 years ago

daydayhappychao commented 4 years ago

env: MacOS I just set electron_mirror=https://npm.taobao.org/mirrors/electron/ in ~/.npmrc, I executed npm i electron --save in my project, and I got an error

(node:12375) UnhandledPromiseRejectionWarning: HTTPError: Response code 404 (Not Found) for https://npm.taobao.org/mirrors/electron/v8.0.2/electron-v8.0.2-darwin-x64.zip
    at EventEmitter.emitter.on.response (/Users/maxiaojin/project/electron-test/node_modules/got/source/as-stream.js:35:24)
    at EventEmitter.emit (events.js:198:13)
    at module.exports (/Users/maxiaojin/project/electron-test/node_modules/got/source/get-response.js:22:10)
    at ClientRequest.handleResponse (/Users/maxiaojin/project/electron-test/node_modules/got/source/request-as-event-emitter.js:155:5)
    at Object.onceWrapper (events.js:286:20)
    at ClientRequest.emit (events.js:203:15)
    at ClientRequest.origin.emit.args [as emit] (/Users/maxiaojin/project/electron-test/node_modules/@szmarczak/http-timer/source/index.js:37:11)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at TLSSocket.socketOnData (_http_client.js:442:20)
(node:12375) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12375) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I make it work by change the source code at node_modules/@electron/get/dist/cjs/artifact-util.js: 33 getArtifactRemoteURL like this:

function getArtifactRemoteURL(details) {
    const opts = details.mirrorOptions || {};
    let base = mirrorVar('mirror', opts, BASE_URL);
    if (details.version.includes('nightly')) {
        base = mirrorVar('nightly_mirror', opts, NIGHTLY_BASE_URL);
    }
    const path = mirrorVar('customDir', opts, details.version).replace('{{ version }}', details.version.replace(/^v/, ''));
    path = path.replace('v', '');
    const file = mirrorVar('customFilename', opts, getArtifactFileName(details));
    return `${base}${path}/${file}`;
}

This is a bad way, please fix it!

malept commented 4 years ago

Where are you finding the instructions to use https://npm.taobao.org/mirrors/electron/ ? On https://www.electronjs.org/docs/tutorial/installation#custom-mirrors-and-caches it says to use https://cdn.npm.taobao.org/dist/electron/ .

daydayhappychao commented 4 years ago

fix!

malept commented 4 years ago

@Magin-CC It would still help to know where you found the first mirror URL, to see if it can be updated.

aprilandjan commented 2 years ago

@malept probably people get the first invalid mirror URL from the official mirror instruction. In the document:

ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"

is ok for download, but the second part

ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
ELECTRON_CUSTOM_DIR="{{ version }}"

is not able for download because the workable customDir is in fact v{{ version }}. To be honest, the instruction is somehow misleading. Many people(me included) are anxious to find a solution and will not read the instructions carefully at first glance.