From 8bcd54354eb241b64d30acc05f0b031c842f92c5 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Tue, 9 May 2023 07:26:56 +0530 Subject: [PATCH] feat: support esm build courtesy -> https://github.com/epoberezkin/fast-deep-equal/pull/105 --- build.js | 17 ++++++++++++----- package.json | 4 +++- src/index.jst | 7 ++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index e236a9a..5ebb595 100644 --- a/build.js +++ b/build.js @@ -5,8 +5,15 @@ var doT = require('dot'); doT.templateSettings.strip = false; var jst = doT.compile(fs.readFileSync('./src/index.jst', 'utf8')); -fs.writeFileSync('./index.js', jst({es6: false})); -fs.writeFileSync('./react.js', jst({es6: false, react: true})); -try { fs.mkdirSync('./es6'); } catch(e) {} -fs.writeFileSync('./es6/index.js', jst({es6: true})); -fs.writeFileSync('./es6/react.js', jst({es6: true, react: true})); +fs.writeFileSync('./index.js', jst({ es6: false })); +fs.writeFileSync('./react.js', jst({ es6: false, react: true })); +try { + fs.mkdirSync('./es6'); +} catch (e) {} +fs.writeFileSync('./es6/index.js', jst({ es6: true })); +fs.writeFileSync('./es6/react.js', jst({ es6: true, react: true })); +try { + fs.mkdirSync('./esm'); +} catch (e) {} +fs.writeFileSync('./esm/index.js', jst({ es6: true, esm: true })); +fs.writeFileSync('./esm/react.js', jst({ es6: true, esm: true, react: true })); diff --git a/package.json b/package.json index 3cfe66c..767c3e4 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "3.1.3", "description": "Fast deep equal", "main": "index.js", + "module": "esm/index.js", "scripts": { "eslint": "eslint *.js benchmark/*.js spec/*.js", "build": "node build", @@ -55,7 +56,8 @@ "index.d.ts", "react.js", "react.d.ts", - "es6/" + "es6/", + "esm/" ], "types": "index.d.ts" } diff --git a/src/index.jst b/src/index.jst index 5d4ee2f..6f5e066 100644 --- a/src/index.jst +++ b/src/index.jst @@ -6,7 +6,12 @@ var envHasBigInt64Array = typeof BigInt64Array !== 'undefined'; {{?}} +{{? it.esm }} +export default function equal(a, b) { +{{?}} +{{? !it.esm }} module.exports = function equal(a, b) { +{{?}} if (a === b) return true; if (a && b && typeof a == 'object' && typeof b == 'object') { @@ -76,4 +81,4 @@ module.exports = function equal(a, b) { // true if both NaN, false otherwise return a!==a && b!==b; -}; +}; \ No newline at end of file