Files
cypress/scripts/after-pack-hook.js
Bill Glesias b85dd752f2 dependency: update to electron 25 and node 18 (#27715)
* feat: update to electron 25 and bump node dependencies. need to remove
custom docker image

* chore: update node versions to 18+ [run ci]

* chore: bump @types/node from v16 to v18 and bump the typescript supported CLI version from 3.9 to 4.4

* update mock-fs to 5.2.0 to fix BigInt issue (see https://github.com/tschaub/mock-fs/releases/tag/v5.1.4) [run ci]

* chore: update electron integrity check to pass create binary job

* chore: fix issues with achrinza/node-ipc not yet having node 18 engine support (only up to 17 by patching from 9.2.2 to 9.2.5 as seen in https://github.com/achrinza/node-ipc/pull/38. vue/cli-service is not maintained and we should migrate these over to vue create at some point in the near future to get rid of these resolutions

* allow for TLSv1 tests to work with node 18 as the express server running node 18 with tlsv1 needs to allow legacy ciphers

* chore: update snyk workflows to use node 18

* chore: add changelog

* update timeout

* more cleanup during binary build

* bump cache and run ci. include ignore engines for rwa and get rid of
16.16 image references

* chore: update FF tests to 115 as serialization now works with errors and click events do not get fired on buttons being typed into

* chore: don't error when symlink already exists

* chore: fix serialization test for newer versions of firefox

* chore: fix CI config

* chore: fix chrome system tests to work with chrome 114. updates mostly caused by bugs in screen height in chrome. see https://bugs.chromium.org/p/chromium/issues/detail?id=1416398

* chore: test binary against vite update in RWA

* remove wait for RWA as it shouldnt be needed for vite. link example recipes update to node 18

chore: remove commented out code

* chore: print message when DISABLE_SNAPSHOT_REQUIRE is set

* chore: clean out unneeded dependencies always

* chore: remove trailing space

* fix: propagate click events for enter and typing on firefox 106 or later

* chore: fix changelog failures

* fix: correctly simulate click events for buttons on keyup and space type  in Firefox versions greater than 91 and simulate click for buttons on enter in Firefox versions greater than or equal to 106

* chore: add documentation to type to clarify firefox synthetic events

* chore: update protocol snapshot as order or log messages seems to have changed

* update comments

* sort commandLogChanged events for protocol

* chore: remove PR ids from CRA and CER as the PRs are merged into develop

---------

Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Chris Breiding <chrisbreiding@gmail.com>
Co-authored-by: Matt Schile <mschile@cypress.io>
2023-09-07 15:26:09 -04:00

113 lines
4.8 KiB
JavaScript

const fs = require('fs-extra')
const { join } = require('path')
const glob = require('glob')
const os = require('os')
const path = require('path')
const { setupV8Snapshots } = require('@tooling/v8-snapshot')
const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses')
const { buildEntryPointAndCleanup, cleanupUnneededDependencies } = require('./binary/binary-cleanup')
const { getIntegrityCheckSource, getBinaryEntryPointSource, getEncryptionFileSource, getCloudEnvironmentFileSource, validateEncryptionFile, getProtocolFileSource, validateCloudEnvironmentFile, validateProtocolFile } = require('./binary/binary-sources')
const CY_ROOT_DIR = path.join(__dirname, '..')
module.exports = async function (params) {
try {
console.log('****************************')
console.log('After pack hook')
console.log(params.appOutDir)
console.log(params.outDir)
console.log(params.electronPlatformName)
console.log('****************************')
const packages = glob.sync('packages/*/node_modules', {
cwd: params.packager.info._appDir,
})
const buildSubfoldersPerPlatform = {
darwin: join('Cypress.app', 'Contents', 'Resources', 'app'),
linux: join('resources', 'app'),
win32: join('resources', 'app'), // TODO check this path
}
const buildSubfolder = buildSubfoldersPerPlatform[os.platform()]
const outputFolder = join(params.appOutDir, buildSubfolder)
console.log('copying node_modules to', outputFolder)
for await (const packageNodeModules of packages) {
console.log('copying', packageNodeModules)
const sourceFolder = join(params.packager.info._appDir, packageNodeModules)
const destinationFolder = join(outputFolder, packageNodeModules)
await fs.copy(sourceFolder, destinationFolder)
}
const distNodeModules = path.join(params.packager.info._appDir, 'node_modules')
const appNodeModules = path.join(outputFolder, 'node_modules')
console.log('copying ', distNodeModules, ' to', appNodeModules)
await fs.copy(distNodeModules, appNodeModules)
console.log('all node_modules subfolders copied to', outputFolder)
const exePathPerPlatform = {
darwin: join(params.appOutDir, 'Cypress.app', 'Contents', 'MacOS', 'Cypress'),
linux: join(params.appOutDir, 'Cypress'),
win32: join(params.appOutDir, 'Cypress.exe'),
}
if (!['1', 'true'].includes(process.env.DISABLE_SNAPSHOT_REQUIRE)) {
const binaryEntryPointSource = await getBinaryEntryPointSource()
const encryptionFilePath = path.join(CY_ROOT_DIR, 'packages/server/lib/cloud/encryption.ts')
const encryptionFileSource = await getEncryptionFileSource(encryptionFilePath)
const cloudEnvironmentFilePath = path.join(CY_ROOT_DIR, 'packages/server/lib/cloud/environment.ts')
const cloudEnvironmentFileSource = await getCloudEnvironmentFileSource(cloudEnvironmentFilePath)
const cloudApiFilePath = path.join(CY_ROOT_DIR, 'packages/server/lib/cloud/api.ts')
const cloudApiFileSource = await getProtocolFileSource(cloudApiFilePath)
const cloudProtocolFilePath = path.join(CY_ROOT_DIR, 'packages/server/lib/cloud/protocol.ts')
const cloudProtocolFileSource = await getProtocolFileSource(cloudProtocolFilePath)
await Promise.all([
fs.writeFile(encryptionFilePath, encryptionFileSource),
fs.writeFile(cloudEnvironmentFilePath, cloudEnvironmentFileSource),
fs.writeFile(cloudApiFilePath, cloudApiFileSource),
fs.writeFile(cloudProtocolFilePath, cloudProtocolFileSource),
fs.writeFile(path.join(outputFolder, 'index.js'), binaryEntryPointSource),
])
await Promise.all([
validateEncryptionFile(encryptionFilePath),
validateCloudEnvironmentFile(cloudEnvironmentFilePath),
validateProtocolFile(cloudApiFilePath),
validateProtocolFile(cloudProtocolFilePath),
])
await flipFuses(
exePathPerPlatform[os.platform()],
{
version: FuseVersion.V1,
[FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
},
)
process.env.V8_UPDATE_METAFILE = '1'
// Build out the entry point and clean up prior to setting up v8 snapshots so that the state of the binary is correct
await buildEntryPointAndCleanup(outputFolder)
await cleanupUnneededDependencies(outputFolder)
await setupV8Snapshots({
cypressAppPath: params.appOutDir,
integrityCheckSource: getIntegrityCheckSource(outputFolder),
})
} else {
console.log(`value of DISABLE_SNAPSHOT_REQUIRE was ${process.env.DISABLE_SNAPSHOT_REQUIRE}. Skipping snapshot require...`)
await cleanupUnneededDependencies(outputFolder)
}
} catch (error) {
console.log(error)
throw error
}
}