diff --git a/dist/index.js b/dist/index.js index c7cbc3422..46caa3c9c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -101894,6 +101894,37 @@ const install = () => { } } +/** + * Runs an explicit "cypress install" after the dependencies have been + * installed. This downloads the Cypress binary when it is missing and is a + * no-op when it is already present. + * + * Package managers may no longer run a dependency's `postinstall` script by + * default, which means the script that normally downloads the Cypress binary + * no longer runs during a package-manager install. Running the install + * explicitly keeps the binary available on a cold cache regardless of package + * manager. + * + * Like "cypress verify" and "cypress cache list", this is invoked via npx for + * all package managers so the Cypress binary is resolved consistently. + */ +const installCypressBinary = () => { + debug('installing Cypress binary') + + if (isCypressBinarySkipped()) { + debug('Skipping Cypress install, binary installation is disabled') + return Promise.resolve() + } + + return io.which('npx', true).then((npxPath) => { + return exec.exec( + quote(npxPath), + ['cypress', 'install'], + cypressCommandOptions + ) + }) +} + const listCypressBinaries = () => { debug( `Cypress versions in the cache folder ${CYPRESS_CACHE_FOLDER}` @@ -102628,19 +102659,22 @@ const installMaybe = () => { return install().then(() => { debug('install has finished') - return listCypressBinaries().then(() => { - if (npmCacheHit && cypressCacheHit) { - debug('no need to verify Cypress binary or save caches') - return Promise.resolve(undefined) - } - - debug('verifying Cypress binary') - const saveNpmPromise = packageManagerCacheEnabled - ? saveCachedNpm() - : Promise.resolve(undefined) - return verifyCypressBinary() - .then(() => saveNpmPromise) - .then(saveCachedCypressBinary) + return installCypressBinary().then(() => { + debug('Cypress binary install has finished') + return listCypressBinaries().then(() => { + if (npmCacheHit && cypressCacheHit) { + debug('no need to verify Cypress binary or save caches') + return Promise.resolve(undefined) + } + + debug('verifying Cypress binary') + const saveNpmPromise = packageManagerCacheEnabled + ? saveCachedNpm() + : Promise.resolve(undefined) + return verifyCypressBinary() + .then(() => saveNpmPromise) + .then(saveCachedCypressBinary) + }) }) }) }) diff --git a/index.js b/index.js index 75b790792..12d622a2d 100644 --- a/index.js +++ b/index.js @@ -273,6 +273,37 @@ const install = () => { } } +/** + * Runs an explicit "cypress install" after the dependencies have been + * installed. This downloads the Cypress binary when it is missing and is a + * no-op when it is already present. + * + * Package managers may no longer run a dependency's `postinstall` script by + * default, which means the script that normally downloads the Cypress binary + * no longer runs during a package-manager install. Running the install + * explicitly keeps the binary available on a cold cache regardless of package + * manager. + * + * Like "cypress verify" and "cypress cache list", this is invoked via npx for + * all package managers so the Cypress binary is resolved consistently. + */ +const installCypressBinary = () => { + debug('installing Cypress binary') + + if (isCypressBinarySkipped()) { + debug('Skipping Cypress install, binary installation is disabled') + return Promise.resolve() + } + + return io.which('npx', true).then((npxPath) => { + return exec.exec( + quote(npxPath), + ['cypress', 'install'], + cypressCommandOptions + ) + }) +} + const listCypressBinaries = () => { debug( `Cypress versions in the cache folder ${CYPRESS_CACHE_FOLDER}` @@ -1007,19 +1038,22 @@ const installMaybe = () => { return install().then(() => { debug('install has finished') - return listCypressBinaries().then(() => { - if (npmCacheHit && cypressCacheHit) { - debug('no need to verify Cypress binary or save caches') - return Promise.resolve(undefined) - } + return installCypressBinary().then(() => { + debug('Cypress binary install has finished') + return listCypressBinaries().then(() => { + if (npmCacheHit && cypressCacheHit) { + debug('no need to verify Cypress binary or save caches') + return Promise.resolve(undefined) + } - debug('verifying Cypress binary') - const saveNpmPromise = packageManagerCacheEnabled - ? saveCachedNpm() - : Promise.resolve(undefined) - return verifyCypressBinary() - .then(() => saveNpmPromise) - .then(saveCachedCypressBinary) + debug('verifying Cypress binary') + const saveNpmPromise = packageManagerCacheEnabled + ? saveCachedNpm() + : Promise.resolve(undefined) + return verifyCypressBinary() + .then(() => saveNpmPromise) + .then(saveCachedCypressBinary) + }) }) }) })