From 2efe0d7beec834f58c73a5da15f9f380bea15fe7 Mon Sep 17 00:00:00 2001 From: Vincent Ahrend <vincent.ahrend@ditto.live> Date: Thu, 23 May 2024 13:10:40 +0200 Subject: [PATCH] Use JS script --- .eslintrc | 1 + fix-exports-type.sh | 20 -------------------- scripts/fix-exports-type.js | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) delete mode 100755 fix-exports-type.sh create mode 100755 scripts/fix-exports-type.js diff --git a/.eslintrc b/.eslintrc index 0c08d53..c509e62 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "plugin:react/recommended", "prettier" ], + "exclude": ["scripts/*.js"], "rules": { "deprecation/deprecation": "error", "react-hooks/rules-of-hooks": "error", diff --git a/fix-exports-type.sh b/fix-exports-type.sh deleted file mode 100755 index 3e7ce8e..0000000 --- a/fix-exports-type.sh +++ /dev/null @@ -1,20 +0,0 @@ -#! /bin/bash - -# This script defines the type of exports in the dist directory using minimal -# package.json files. Setting the type in the main package.json file does not -# work because we want to support both CommonJS and ES Module exports in the -# same package. - -cat >dist/cjs/package.json <<!EOF -{ - "type": "commonjs" -} -!EOF -echo "Exports type set to CommonJS in dist/cjs/package.json" - -cat >dist/esm/package.json <<!EOF -{ - "type": "module" -} -!EOF -echo "Exports type set to ES Module in dist/esm/package.json" \ No newline at end of file diff --git a/scripts/fix-exports-type.js b/scripts/fix-exports-type.js new file mode 100755 index 0000000..410fc01 --- /dev/null +++ b/scripts/fix-exports-type.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node +// This script defines the type of exports in the dist directory using minimal +// package.json files. Setting the type in the main package.json file does not +// work because we want to support both CommonJS and ES Module exports in the +// same package. + +const FS = require('node:fs') + +const DIST_DIR = 'dist' + +FS.writeFileSync( + `${DIST_DIR}/cjs/package.json`, + JSON.stringify({ + type: 'commonjs', + }), +) + +FS.writeFileSync( + `${DIST_DIR}/esm/package.json`, + JSON.stringify({ + type: 'module', + }), +)