Просмотр исходного кода

Add package.json `exports` field (#773)

These changes adds an `exports` field to package.json with the main
goal of allowing the root/main export to be our ESM syntax version of
the package, as opposed to the UMD/CommonJS version.

This will make it easier for using projects written with ESM to use
mustache.js out of the box, without having to figure out that they'd
have to `import mustache/mustache.mjs` to get the ESM version.

It is also assumed to be beneficial for tools like http://skypack.dev
to choose the correct ESM version when appropriate.

Refs https://nodejs.org/api/packages.html#packages_package_entry_points
tags/v4.2.0
Trevor Manz GitHub 5 лет назад
Родитель
Сommit
ea3adcfc93
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
3 измененных файлов: 21 добавлений и 0 удалений
  1. +2
    -0
      .github/workflows/usage.yml
  2. +7
    -0
      package.json
  3. +12
    -0
      test/module-systems/esm-test-exports.mjs

+ 2
- 0
.github/workflows/usage.yml Просмотреть файл

@@ -90,9 +90,11 @@ jobs:
export UNPACK_DESTINATION=$(mktemp -d) export UNPACK_DESTINATION=$(mktemp -d)
mv mustache.tgz $UNPACK_DESTINATION mv mustache.tgz $UNPACK_DESTINATION
cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION
cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION
cd $UNPACK_DESTINATION cd $UNPACK_DESTINATION
npm install mustache.tgz npm install mustache.tgz
node esm-test.mjs node esm-test.mjs
node esm-test-exports.mjs


browser-usage: browser-usage:
runs-on: ubuntu-latest runs-on: ubuntu-latest


+ 7
- 0
package.json Просмотреть файл

@@ -24,6 +24,13 @@
"mustache.min.js", "mustache.min.js",
"wrappers/" "wrappers/"
], ],
"exports": {
".": {
"import": "./mustache.mjs",
"require": "./mustache.js"
},
"./*": "./*"
},
"volo": { "volo": {
"url": "https://raw.github.com/janl/mustache.js/{version}/mustache.js" "url": "https://raw.github.com/janl/mustache.js/{version}/mustache.js"
}, },


+ 12
- 0
test/module-systems/esm-test-exports.mjs Просмотреть файл

@@ -0,0 +1,12 @@
import assert from 'assert';
import mustache from 'mustache';

const view = {
title: 'Joe',
calc: () => 2 + 4
};

assert.strictEqual(
mustache.render('{{title}} spends {{calc}}', view),
'Joe spends 6'
);

Загрузка…
Отмена
Сохранить