Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove build output and .min.js from repository #772

Merged
merged 7 commits into from
Mar 5, 2021

Conversation

phillipj
Copy link
Collaborator

@phillipj phillipj commented Feb 22, 2021

TDLR; we only want the source code to be in git.

These changes effectively achieves what was raised in RFC: Remove build output from repository.

Getting here surely ended up taking more time than expected. Stumbled over a fair amount of rabbit holes a long the way, and striking the balance between maintainer experience and keeping our test suite as is w/supported Node.js & browser versions in tact, wasn't straight forward.

There's some interesting nitty gritty details in each respective commit for the curious ones, so I won't elaborate too much in the PR description. But here's the outcome with these changes in place:

In the git repository:

  • Rename mustache.mjs -> mustache.js meaning the source file is ES modules syntax
  • No other build output or minified files to exist

In the npm package:

  • mustache.js to be the build output with an UMD wrapper (like before)
  • mustache.min.js minified version of mustache.js (like before)
  • mustache.mjs to have ES modules syntax (like before)

In other words, unchanged from npm package consumers point of view.

Who will be affected?

Those who have been downloading mustache.js from github.com.

Alternative? unpkg.com serves many browser use cases, skypack.dev is rumoured to be a good fit for deno projects.

Closes #765

Although we'll now end up with only `mustache.js` in the git repo,
being written in ESM syntax, the npm package will still be as before:

- `mustache.js`: UMD, meaning CommonJS, AMD or global scope
- `mustache.mjs`: ESM
Primarily because installing `git` hooks are easy to forget for
maintainers, whilst telling `npm` to do something as a consequence of
`$ npm version <patch | minor | major>` is seamless.

Also worth mentioning we what we used to do in the pre-commit hook
script is now greatly simplified as we don't want to have the build
output and/or the `.min.js` in git anymore.

Therefore, as long as we've bumped the version number in the source
code, we're basically done, after having amended that change into the
git commit the `npm` CLI creates.
These changes are primarily aiming for having an acceptable developer
experience when working on changes locally and want to run the test
suite.

By using `esm` as a required package to be executed *before* the
individual test files are executed, `esm` allows CommonJS/`require()`
based code to use code written with ES Modules syntax.

In practise that means our existing CommonJS based test suite that is
`require()`ing the source code witten in ES Modules, is seamless and
totally transparent. It just works without any build or transpiling
pipeline like `babel` involved.

Caveat: the `esm` package only support Node.js 6.x and above.

That is more than okey, as we've got continous integration to verify
how our changes works on different versions of Node.js, browsers & deno.

Refs https://www.npmjs.com/package/esm
Because `esm` does not support legacy versions of Node.js, at least not
below Node.js 6 as of writing this, we have to avoid using that whenever
tests are running on legacy versions.

But now that the source code (`mustache.js`) is written in ESM syntax,
how on earth are we going to run tests on these legacy versions of
Node.js? We gotta run the build step first, so that we end up with a
`mustache.js` file in CJS, or strictly speaking it will be UMD.

That's kinda pain in the backside isn't it? Yes, but running tests on
legacy versions are not meant to be done locally, but rather in CI. That
means we can easily automate the flow of (1) building the source code
before (2) starting the test suite.

For our futureselves, if we want to stop running tests on legacy
versions of Node.js; the changes introduces in this commit, could be
removed completely.
Because the source code is written in ESM syntax and we cannot use the
`esm` package to make `require()` ESM compatible, since that package
does not support legacy versions of Node.js.

Also in our usage tests in CI, we need to mimck the npm packaging
behaviour where building is involved.
Noteworthy tweak is the fact that it seems `zuul` are eagerly loading
all `require('whatever-package-or-path')` it sees before pushing the
contents to Saucelabs.

That was troublesome because we don't want the `esm` package to be
loaded when running browser tests. But it was, even though we loaded
`esm` conditionally after checking the current Node.js version used.

The trick was to not use `require('esm')` but `module.require('esm')`
instead, to fool the assumed look-out for `require` somewhere inside
`zuul`'s code.
@phillipj phillipj merged commit f15befd into janl:master Mar 5, 2021
@phillipj phillipj deleted the remove-build-output-from-git branch March 5, 2021 20:30
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.

RFC: Remove build output from repository
1 participant