Historically jQuery was seen as an absolute minimal to create
anything with JavaScript. That time has past now that relatively
modern browsers has excellent support for a lot of the things
jQuery helped us with -- at least with the trivial examples shown
in our README.
Therefore removing jQuery usage from our examples as that should
not be a necessary dependency in these examples.
These changes allows the internal template cache to
be customised, either by disabling it complete or
providing a custom implementation of how templates
are cached.
The git pre-commit hook we've been using the last years to keeping
.version found in `package.json` in sync with the .version field
exposed by the source code, did not handle version numbers often
used for pre-relases like `beta | new` etc.
Therefore making sure it searches for versions that also contains
characters, not only numbers separated by dots. That will make sure
the following is also seen as valid versions: `3.2.0-beta.0`,
whereas before the `-beta` part would cause trouble.
This changes the pre-commit hook that we've used for years to keep the
version value found in `package.json` in sync with the one in
`mustache.js`, to change `mustache.mjs` instead since that's where the
source code lives now.
With the introduction of a build step, where we take the source in .mjs
and build it into .js for non-ES Module systems, it's very important
that we remember to keep those two in sync.
That's what the CI job created in these changes ensure;
1. Run the build script
2. See if there are any pending git changes as a result
As long as there are no pending git changes, we're all fine and dandy,
or else we need to run the `npm run build` and commit the changes.
To ensure the ES module and source exposed by this package is compatible
with Deno going forward.
Added benefit is we get some sanity checks of the source code for free
due to Deno's built-in TypeScript compiler getting angry if it sees
things that does not make sense, in terms of missing function arguments
and so on.
Minor adjustments needed to make the TypeScript compiler
that is built into Deno, be happy with how mustache.js'
ES module source looks in terms of function parameters
passed and object mutability.
Refs https://github.com/phillipj/mustache.js/pull/1
By making the main source code an ES module placed in `mustache.mjs`,
what used to be in `mustache.js` is now built based off of the ES module
source inside `mustache.mjs`.
This is done primarily to avoid breaking existing projects already using
mustache.js, by keeping the UMD-version in `mustache.js` part of the git
repository in addition to the minified version in `mustache.min.js`.
After experiment with several compilers;
- Babel
- TypeScript
- Rollup
and examining their build output, [Rollup](https://rollupjs.org/) was chosen
because of the UMD output it creates which closely resembles what we've
historically had in the previous `mustache.js` source code.
The contents of `.js | .min.js` files has been generated by running
the following npm script:
```
$ npm run build
```
Also change linting w/eslint to target the `.mjs` file, since the output
of rollup that ends up in the old `mustache.js` file is not sensible to
do linting on.
As part of transition the source code to be a proper plain ES module,
we're removing the handcrafted UMD wrapper around the source code.
This means the UMD wrapper will have to come from elsewhere; a build
step introduced later.
In an effort of moving with recent changes in Node.js and its built-in
support for ES modules, we're making the main source code reside inside
`mustache.mjs`. This will also allow Deno users to use this package as
an ES module directly by importing `mustache.mjs`.
An ES3 / UMD version of the source code is still planned to exist in
`mustache.js`, but will involve a build step to transform the ES module
source into a plain .js version.
By renaming the file *before* changing any contents, git will
recognise the file has been renamed and therefore allows us to see all
historical changes to the old .js source code with the `--follow` argument:
```
$ git log --follow -- mustache.mjs
```
Without ensuring git sees this is a file rename, we will in practise
loose the old source code's history, or at least make it quite weird
and less intuitive to find. That's not fair to the historical
contributors and in general getting hold of a well documented log of
changes to a file in git, is extremely valuable in those few scenarios
where it's *really* needed.
This is a precursor to introducing a build step that will change what
we expose from this package. Better off writing some tests to verify
existing projects with different module systems continue to work as
expected.
This is a precursor to introducing a build step that will change what
we expose from this package. Better off writing some tests to verify
existing projects with different module systems continue to work as
expected.
This is a precursor to introducing a build step that will change what
we expose from this package. Better off writing some tests to verify
existing projects with different module systems continue to work as
expected.
Because standard dev dependencies being installed for not-legacy versions,
has introduced some features or syntax constructs that simply won't
run for Node.js 6 and below.
Therefor running render-and-run-in-browser tests with Node.js 8 instead.
Primarily because it's been ages since we bumped eslint and as a precursor
to allowing some future test files to be written in a more modern type
of JavaScript. Especially think about tests written using puppeteer.js
which is heavily `Promise` based, where the async-await syntax makes
it soooo less painful to write.
Silly not being able to use that because of an outdated eslint version
doesn't understand that syntax construct at all.
Because there has been a deliberate effort from the Node.js project
to use the term `Node.js` rather than anything else. It also helps beginners
by being more explicit and self-descriptive.
When initially creating the GitHub Actions
workflow, it was obviously forgotten to make
it also run on pull requests, not only when
changes are pushed to branches in the
original repository (not a fork).
This small change fixes the output of functions used in partials with
indentation. Bug reports has shown that the functions output is shifted
with the amount of indentation the partial has.
The bug itself is best illustrated in the tests added in 621ae80652.
Closes https://github.com/janl/mustache.js/issues/712
While creating the `$ npm install` step in the
GitHub Actions workflow, I forgot to state the fact that
the `$ npm test` step "needs" the install deps step
to have successfully run first.
As a means of seeing how GitHub Actions
work compared to Travis CI, these changes creates
a so-called workflow that runs `$ npm test`
upon every `$ git push` to the repository.
In an effort of ensuring consistent code style in test files as with
the "production" source code, we should run eslint as part of the
`$ npm test` script as well.
Most of the related fixes was done by `eslint` using the `--fix` argument.
Only special configuration tweaks for tests compared to the other
source code, is to allow functions declaration without names. The
rationale for allowing that in tests, is that the important reason we
have them in the source code (proper stacktraces) aren't as important
in test files.
Fixes this failure:
1) Mustache CLI without partials writes rendered template into the file specified by the third argument:
Uncaught TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at makeCallback (fs.js:136:11)
at Object.unlink (fs.js:943:14)
at test/cli-test.js:86:12
at ChildProcess.exithandler (child_process.js:285:7)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Primarily because it's very painful to install 3rd party packages
in the test phase of our CI runs, because many of them requires at least
Node.js 0.10 or even higher.
Therefore getting the test suite to run when using Node.js 0.8 is
far from trivial, and the benefit of ensure Node.js 0.8 support these
days is not obvious because it should really not be used knowing that
it has reached end-of-life a long time ago.
Worth noting there's no breaking changes in this commit to
mustache.js's source code, we just don't want to struggle getting our
CI to care about it. In other words, it should still be possible to use
Node.js 0.8, but we won't care much making sure it keeps working going
forward.