Przeglądaj źródła

Use `esm` package locally when testing to use ESM syntax from CJS code

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
tags/v4.2.0
Phillip Johnsen 5 lat temu
rodzic
commit
d4a50420c5
4 zmienionych plików z 47 dodań i 13 usunięć
  1. +8
    -0
      .esmrc
  2. +36
    -11
      package-lock.json
  3. +2
    -1
      package.json
  4. +1
    -1
      test/cli-test.js

+ 8
- 0
.esmrc Wyświetl plik

@@ -0,0 +1,8 @@
{
cjs: {
// Ensure ESM `export default` ends up as the root, e.g. `module.exports` when
// being `require()`d from CJS code. This is not spec compliant, but that does
// not matter because only use this `esm` package trickery locally while testing
dedefault: true
}
}

+ 36
- 11
package-lock.json Wyświetl plik

@@ -2178,6 +2178,12 @@
"integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==",
"dev": true
},
"esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
"dev": true
},
"espree": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/espree/-/espree-6.1.2.tgz",
@@ -2905,7 +2911,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@@ -2926,12 +2933,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -2946,17 +2955,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -3073,7 +3085,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@@ -3085,6 +3098,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -3099,6 +3113,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -3106,12 +3121,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -3130,6 +3147,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -3210,7 +3228,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -3222,6 +3241,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@@ -3307,7 +3327,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -3343,6 +3364,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -3362,6 +3384,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -3405,12 +3428,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
}
}
},


+ 2
- 1
package.json Wyświetl plik

@@ -31,7 +31,7 @@
"build": "cp mustache.js mustache.mjs && rollup mustache.mjs --file mustache.js --format umd --name Mustache && uglifyjs mustache.js > mustache.min.js",
"test": "npm run test-lint && npm run test-unit",
"test-lint": "eslint mustache.js bin/mustache test/**/*.js",
"test-unit": "mocha --reporter spec test/*-test.js",
"test-unit": "mocha --reporter spec --require esm test/*-test.js",
"test-render": "mocha --reporter spec test/render-test",
"pre-test-browser": "node test/create-browser-suite.js",
"test-browser": "npm run pre-test-browser && zuul -- test/context-test.js test/parse-test.js test/scanner-test.js test/render-test-browser.js",
@@ -41,6 +41,7 @@
"devDependencies": {
"chai": "^3.4.0",
"eslint": "^6.5.1",
"esm": "^3.2.25",
"jshint": "^2.9.5",
"mocha": "^3.0.2",
"puppeteer": "^2.0.0",


+ 1
- 1
test/cli-test.js Wyświetl plik

@@ -9,10 +9,10 @@ var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt');
var moduleVersion = require('../package').version;

function changeForOS (command) {
command = command.replace('bin/mustache', 'node --require esm bin/mustache')

if (process.platform === 'win32') {
return command
.replace(/bin\/mustache/g, 'node bin\\mustache')
.replace(/\bcat\b/g, 'type')
.replace(/\//g, '\\');
}


Ładowanie…
Anuluj
Zapisz