Package Events

Sometimes a package needs to perform custom actions when it is downloaded, installed, or uninstalled. To support such custom actions, Pak triggers events that can be hooked at various points of the package management lifecycle.

EventDescription
preinstallBefore installing and after caching package
preupdateBefore updating cached packages
preupgradeBefore upgrading installed packages
installAfter installing files locally
postcacheAfter saving package to the cache
postpruneAfter removing a package from the cache
postuninstallAfter uninstalling package locally
uninstallBefore uninstalling package locally

Hooking Events

Events may be hooked by defining event scripts via the pak.scripts package.json property. Event handlers be defined inside the scripts collection. For example:

"pak": {
    "scripts": {
        "postcache": {
            "script": "print('Any script in here')"
        }
    }
}

Literal Scripts

Each event may define a literal script or define a script filename. If the event value is a string, it will be interpreted as a literal script to execute. For example:

"pak": {
    "scripts": {
        "postcache": "run('npm install -g babel')"
    }
}

This is quivalent to the following:

"pak": {
    "scripts": {
        "postcache": {
            "script": "run('npm install -g babel')"
        }
    }
}

Event Script Files

You can externalize the event script in a file by using the path property inside the event definition.

"pak": { "scripts": { "postcache": { "path": "run('npm install -g babel')" } } }

MakeMe Scripts

If the script file has a .me extension, the script will be interpreted as a MakeMe build file and will be invoked with:

me -q --file PATH

Automatic MakeMe Events

If the package does not define event handlers, but provides a MakeMe file of the same name as the package: NAME.me, then then it will be invoked with the name of the event, prefixed with pak- as a target.

For example:

me -q --file PATH pak-postcache

This can be a convenient way of handling Pak events via MakeMe project files.

© Embedthis Software, 2003-2015. All rights reserved.