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

Transition source code to be an ES module #728

Merged
merged 10 commits into from
Dec 18, 2019
Merged
11 changes: 10 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@
"no-use-before-define": 0,
"no-process-exit": 0,
"strict": 0
}
},
"overrides": [
{
"files": ["mustache.mjs"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2015
}
}
]
}
47 changes: 46 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Verify changes

on: [push, pull_request]

jobs:
jobs:
tests:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -58,6 +58,25 @@ jobs:
npm install $ARCHIVE_FILENAME
node commonjs-test.js

esm-usage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '>=13.2.0'
- name: Package, install and test
run: |
export ARCHIVE_FILENAME=$(npm pack | tail -n 1)
export UNPACK_DESTINATION=$(mktemp -d)
mv $ARCHIVE_FILENAME $UNPACK_DESTINATION
cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION
cd $UNPACK_DESTINATION
npm install $ARCHIVE_FILENAME
node esm-test.mjs

browser-usage:
runs-on: ubuntu-latest

Expand All @@ -71,3 +90,29 @@ jobs:
run: |
npm ci
npx mocha test/module-systems/browser-test.js

deno-usage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: denolib/setup-deno@v1
with:
deno-version: 'v0.23.0'
- run: deno --version
- run: deno test --allow-net=deno.land test/module-systems/deno-test.ts

build-output-sync:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install, build and check git diff
run: |
npm ci
npm run build
git diff --quiet HEAD --
5 changes: 0 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ task :test do
sh "./node_modules/.bin/mocha test"
end

desc "Make a compressed build in #{minified_file}"
task :minify do
sh "./node_modules/.bin/uglifyjs mustache.js > #{minified_file}"
end

desc "Run JSHint"
task :hint do
sh "./node_modules/.bin/jshint mustache.js"
Expand Down
10 changes: 5 additions & 5 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Bumper
# if bumped, do extra stuff and notify the user
if @bumped

# minify `mustache.js` using the Rakefile task
puts "> minifying `mustache.js`..."
`rake minify`
# keep .mjs & .js|.min.js in sync
puts "> building and minifying `mustache.mjs`..."
`npm run build`

# stage files for commit
`git add package.json`
Expand Down Expand Up @@ -78,7 +78,7 @@ class Bumper
end

bumper = Bumper.new([
Source.new('mustache.js', /mustache.version = '([\d\.]*)'/),
Source.new('mustache.js.nuspec', /<version>([\d\.]*)<\/version>/),
Source.new('mustache.mjs', /version: '([^']+)'/),
Source.new('mustache.js.nuspec', /<version>([^<]+)<\/version>/),
])
bumper.start
49 changes: 27 additions & 22 deletions mustache.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/

/*global define: false Mustache: true*/

(function defineMustache (global, factory) {
if (typeof exports === 'object' && exports && typeof exports.nodeName !== 'string') {
factory(exports); // CommonJS
} else if (typeof define === 'function' && define.amd) {
define(['exports'], factory); // AMD
} else {
global.Mustache = {};
factory(global.Mustache); // script, wsh, asp
}
}(this, function mustacheFactory (mustache) {
// This file has been generated from mustache.mjs
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Mustache = factory());
}(this, (function () { 'use strict';

/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/

var objectToString = Object.prototype.toString;
var isArray = Array.isArray || function isArrayPolyfill (object) {
Expand Down Expand Up @@ -533,7 +527,7 @@
*/
Writer.prototype.render = function render (template, view, partials, tags) {
var tokens = this.parse(template, tags);
var context = (view instanceof Context) ? view : new Context(view);
var context = (view instanceof Context) ? view : new Context(view, undefined);
return this.renderTokens(tokens, context, partials, template, tags);
};

Expand Down Expand Up @@ -655,9 +649,19 @@
return token[1];
};

mustache.name = 'mustache.js';
mustache.version = '3.1.0';
mustache.tags = [ '{{', '}}' ];
var mustache = {
name: 'mustache.js',
version: '3.2.0-beta.0',
tags: [ '{{', '}}' ],
clearCache: undefined,
escape: undefined,
parse: undefined,
render: undefined,
to_html: undefined,
Scanner: undefined,
Context: undefined,
Writer: undefined
};

// All high-level mustache.* functions use this writer.
var defaultWriter = new Writer();
Expand Down Expand Up @@ -718,4 +722,5 @@
mustache.Writer = Writer;

return mustache;
}));

})));
2 changes: 1 addition & 1 deletion mustache.js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>mustache.js</id>
<version>3.1.0</version>
<version>3.2.0-beta.0</version>
<authors>mustache.js Authors</authors>
<licenseUrl>https://github.com/janl/mustache.js/blob/master/LICENSE</licenseUrl>
<projectUrl>http://mustache.github.com/</projectUrl>
Expand Down
2 changes: 1 addition & 1 deletion mustache.min.js

Large diffs are not rendered by default.

Loading