Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Cypress io Cypress SetupV8Snapshots

From Leeroopedia
Knowledge Sources
Domains Performance, Build
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for generating V8 heap snapshots during the Electron packaging process provided by the after-pack hook and @tooling/v8-snapshot.

Description

The after-pack-hook.js (scripts/after-pack-hook.js:L42-213) is called by electron-builder after packaging. It invokes setupV8Snapshots from @tooling/v8-snapshot to generate the snapshot blob, consolidateDeps to optimize dependencies, and flipFuses from @electron/fuses to enable snapshot loading in Electron. The buildEntryPointAndCleanup function (scripts/binary/binary-cleanup.js:L157-189) prepares the entry point and removes unnecessary files.

Usage

This hook runs automatically as part of the electron-builder packaging pipeline. It is not invoked directly by developers.

Code Reference

Source Location

  • Repository: cypress-io/cypress
  • Files:
    • scripts/after-pack-hook.js:L42-213 (main hook, calls setupV8Snapshots at L174-177, L198-204)
    • scripts/binary/binary-cleanup.js:L157-189 (buildEntryPointAndCleanup)
    • packages/server/v8-snapshot-entry.js (snapshot entry point)

Signature

// after-pack-hook.js default export
module.exports = async function afterPackHook(context) {
  // context.appOutDir: string - electron-builder output directory
  // Calls: setupV8Snapshots({ buildAppDir })
  // Calls: consolidateDeps({ buildAppDir })
  // Calls: flipFuses(electron, ...)
  // Calls: buildEntryPointAndCleanup(buildAppDir)
}

Import

// Referenced in electron-builder.json:
// "afterPack": "./scripts/after-pack-hook.js"
const { setupV8Snapshots, consolidateDeps } = require('@tooling/v8-snapshot')

I/O Contract

Inputs

Name Type Required Description
context.appOutDir string Yes Electron-builder output directory with packaged app
buildAppDir string Yes Path to app resources directory within packaged output

Outputs

Name Type Description
V8 snapshot blob binary file Serialized V8 heap state for fast startup
Cleaned dependencies directory Optimized node_modules with unnecessary files removed

Usage Examples

electron-builder Configuration

{
  "afterPack": "./scripts/after-pack-hook.js",
  "afterSign": "./scripts/after-sign-hook.js"
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment