Ajoute la possibilité d'importer publicodes en ESModule natif

Pour cela, la solution la plus simple est de faire un wrapper autour de l'api exposée.
Il ne faudra pas oublier de le mettre à jour.

[A lire pour en savoir plus](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1)

fix #1239
pull/1309/head
Johan Girod 2020-12-11 10:18:40 +01:00 committed by Johan Girod
parent 6390307be6
commit 0d50e03777
3 changed files with 24 additions and 1 deletions

12
publicodes/esm/index.js Normal file
View File

@ -0,0 +1,12 @@
// ESM wrapper arrond publicodes CJS Module
// For a deep explanation see:
// https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1
import publicodes from '../dist/index.js';
export default publicodes.default
export const reduceAST = publicodes.reduceAST;
export const transformAST = publicodes.transformAST;
export const formatValue = publicodes.formatValue;
export const utils = publicodes.utils;
export const translateRules = publicodes.translateRules;
export const evaluateRule = publicodes.evaluateRule;

View File

@ -0,0 +1,6 @@
{
"type": "module",
"engines": {
"node": ">=15.0.0"
}
}

View File

@ -4,6 +4,10 @@
"description": "A declarative language for encoding public algorithm",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./esm/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/betagouv/mon-entreprise.git",
@ -15,7 +19,8 @@
"files": [
"dist/index.js",
"dist/types",
"dist/images"
"dist/images",
"esm"
],
"private": false,
"devDependencies": {