Skip to content

Top down PS#2

Open
joneshf wants to merge 7 commits into
oceanofthelost:masterfrom
joneshf:top-down
Open

Top down PS#2
joneshf wants to merge 7 commits into
oceanofthelost:masterfrom
joneshf:top-down

Conversation

@joneshf

@joneshf joneshf commented Sep 29, 2018

Copy link
Copy Markdown
Contributor
What it does

Sets up the PS conversion. The behavior ought to be the same as before once everything is built. This is a top-down approach where PS is effectively the entry-point and it calls out to JS to do stuff.

I threw together a Makefile so it was a bit clearer what all has to happen. Assuming you have make, you ought to be able to say make or make index.js and have everything work. I don't know if it'll actually work, since I assume you're on Windows and cross-platform stuff is hard.

In any case, it's probably easiest to look at this commit by commit rather than all in one go. I tried to explain stuff in the commit messages as I went along.

Lemme know if you have any questions or if something should be changed!

`node_modules` are development dependencies that differ per platform.
In particular, the committed files are for a Windows machine.
They don't work for a Linux machine.

Having them committed means developing on a different platform requires:
1. Deleting the committed files.
2. Installing the dependencies.
3. Remembering not to commit anything in the `node_modules` directory.

We can make it a smidge easier by untracking these files.
The workflow on all platforms becomes:
1. Install the dependencies.
I don't know if this is cross-platform.
Hopefully, whatever doesn't work on Windows can be a small fix.
The idea isn't to write-off Windows nor make it second class,
more to track the dependency graph of the project explicitly.

We make an important change to the browserify command.
If we list the top-level entry point,
browserify will "do the right thing."
By that I mean, it will find all the dependencies.
It does this by following `require`s.

This change becomes helpful when we start to lean on npm more
for dependency management.
Since the move to npm, we can use it to manage dependencies.
Should make for easier management of future dependencies going forward.
This is all the output of `pulp init`.
We're not doing anything fancy aside from integrating it.

Let's talk about the dependencies:

* bower - We use this dependency to install PS dependencies.
    Although the JS community has moved on from it,
    the PS community has not.
    The problems that affect the JS community,
    are not the same problems that affect the PS community.
    So, using bower isn't bad for PS.
* pscid - We use this dependency to run a fast file-watcher/compiler.
    How it works is kind of complex; suffice to say,
    it provides a much smaller feedback loop from the compiler.
* pulp - We use this dependency to make working with the compiler easier.
    `pulp` is a wrapper around `purs` that makes it easier to use.
    It speaks more at the user-level (`pulp build`, `pulp test`, etc.),
    rather than at the tool-level.
    The distinction might seem artificial (and is, in some sense).
    But, using both in anger shows when one is easier than the other.
    For the most part, `pulp` is always easier.
* purescript - We use this dependency to pull down the actual compiler.
    Not much else to say about it.
    Tracking the compiler as an npm dependency means we can ensure
    everyone is using a compatible version.
    It doesn't really work in the face of SemVer, but it's close enough.
* purescript-psa - We use this dependency for better errors and warnings.
    `psa` is a frontend to `purs` that makes working with errors
    and warnings easier than using `purs` directly.
We make PS effectively the entry-point to the program.
It takes the `htmlFunction`s and invokes them.
The rest of the program should work the same.

There is a bit of glue code with this approach.
Due to how FFI files work and require paths,
we take the PS output and the JS sources,
and massage the interfaces together.

As we need more JS modules in PS,
this glue module should be the place to add them.
When we take-over more functionality in PS,
this glue module shouldn't have to change.
We arbitrarily choose to take the last three calls and move them to PS.
We could've started from the start and worked down.
Either way would ensure the same ordering.

There's nothing really special about what's happening here.
We're calling more JS code and letting it work how it works.

The PS is written to resemble the JS to help know show similarities.
It's not a requirement to stay this way.
In fact, it should most likely change once it's all converted.
Following the pattern setup.
Again, it's written to look like the JS to ease the transition.
@joneshf joneshf mentioned this pull request Sep 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant