zephyr: Zephyr, tree-shaking for the PureScript language

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Tree shaking tool and partial evaluator for PureScript CoreFn AST.


[Skip to Readme]

Properties

Versions 0.1.1.0, 0.1.4, 0.2.0, 0.2.1, 0.3.1, 0.3.1, 0.3.2, 0.5.3
Change log None available
Dependencies aeson (>=1.0 && <1.5), ansi-terminal (>=0.7.1 && <0.11), ansi-wl-pprint, async, base (>=4.8 && <5), base-compat (>=0.6.0), boxes (>=0.1.4 && <0.2), bytestring, containers, directory (>=1.2.3), filepath, formatting, Glob (>=0.9 && <0.11), language-javascript (>=0.7 && <0.8), mtl (>=2.1.0 && <2.3.0), optparse-applicative (>=0.13.0), purescript (>=0.13.8 && <0.14), safe (>=0.3.9 && <0.4), text, transformers (>=0.3.0 && <0.6), utf8-string (>=1 && <2), zephyr [details]
License MPL-2.0
Copyright (c) 2017-2018 Marcin Szamotulski
Author Marcin Szamotulski <profunctor@pm.me>
Maintainer Marcin Szamotulski <profunctor@pm.me>
Category Development
Home page https://github.com/coot/zephyr#readme
Source repo head: git clone https://github.com/coot/zephyr
Uploaded by coot at 2020-06-13T16:39:52Z

Modules

Flags

Automatic Flags
NameDescriptionDefault
test-with-stack

use `stack exec zephyr` in tests

Disabled
test-core-libs

test core libs

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for zephyr-0.3.1

[back to package description]

zephyr

Maintainer: coot zephyr

An experimental tree-shaking tool for PureScript.

Usage

# compile your project (or use `pulp build -- -g corefn`)
purs compile -g corefn bower_components/purescript-*/src/**/*.purs src/**/*.purs

# run `zephyr`
zephyr -f Main.main

# bundle your code
webpack

or you can bundle with pulp:

pulp browserify --skip-compile -o dce-output -t app.js

You can also specify modules as entry points, which is the same as specifying all exported identifiers.

# include all identifiers from Data.Eq module
zephyr Data.Eq

# as above
zephyr module:Data.Eq

# include Data.Eq.Eq identifier of Data.Eq module
zephyr ident:Data.Eq.Eq

# include Data.Eq.eq identifier (not the lower case of the identifier!)
zephyr Data.Eq.eq

zephyr reads corefn json representation from output directory, removes non transitive dependencies of entry points and dumps common js modules (or corefn representation) to dce-output directory.

Zephyr eval

Zephyr can evaluate some literal expressions.

import Config (isProduction)

a = if isProduction
  then "api/prod/"
  else "api/dev/"

will be transformed to

a = "api/prod/"

whenever isProduction is true. This allows you to have different development and production environment while still ship a minified code in your production environment. You may define isProduction in a module under a src-prod directory and include it when compiling production code with pulp build -I src-prod and to have another copy for your development environment under src-dev where isProduction is set to false.

Build & Test

cabal build exe:zephyr

To run tests

cabal run zephyr-test

Comments

The -f switch is not 100% safe. Upon running, zephyr will remove exports from foreign modules that seems to be not used: are not used in purescript code and seem not to be used in the foreign module. If you simply assign to exports using javascript dot notation then you will be fine, but if you use square notation exports[var] in a dynamic way (i.e. var is a true variable rather than a string literal), then zephyr might remove code that shouldn’t be removed.

The best practice is to run a JavaScript tree-shaking algorithm via webpack or rollup on the JavaScript code that is pulled in your bundle by foreign imports.