From f4f3239a111d2395841b09424ecff2fc443fa157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Rame=CC=81?= Date: Tue, 30 Jul 2024 12:05:42 +0200 Subject: [PATCH] chore: compile as esm package only to not face cjs issues (not important since we publish as a cli program) --- .eslintrc.js => .eslintrc.cjs | 0 .prettierrc.js | 2 +- package.json | 1 + src/clients/workaround.ts | 4 ++-- src/index.ts | 2 +- src/utils/file.ts | 4 ++-- tsup.config.ts | 6 +++++- 7 files changed, 12 insertions(+), 7 deletions(-) rename .eslintrc.js => .eslintrc.cjs (100%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/.prettierrc.js b/.prettierrc.js index 4835ac8..dea7831 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ -module.exports = { +export default { printWidth: 150, semi: true, singleQuote: true, diff --git a/package.json b/package.json index 836d2ba..f4566d8 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "publishConfig": { "access": "public" }, + "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/clients/workaround.ts b/src/clients/workaround.ts index 6bf3cac..023dcf0 100644 --- a/src/clients/workaround.ts +++ b/src/clients/workaround.ts @@ -1,7 +1,7 @@ import { Readable } from 'stream'; import streamChain from 'stream-chain'; -import Asm from 'stream-json/Assembler'; -import streamJsonParser from 'stream-json/Parser'; +import Asm from 'stream-json/Assembler.js'; +import streamJsonParser from 'stream-json/Parser.js'; import { ReadableStream } from 'stream/web'; const { chain } = streamChain; diff --git a/src/index.ts b/src/index.ts index 782c405..f58abe1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -import '@figpot/src/cli/program'; +import '@figpot/src/cli/index'; diff --git a/src/utils/file.ts b/src/utils/file.ts index 21b3a06..5ed3ae9 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -6,8 +6,8 @@ import { mimeData } from 'human-filetypes'; import { JsonStreamStringify } from 'json-stream-stringify'; import path from 'path'; import streamChain from 'stream-chain'; -import Asm from 'stream-json/Assembler'; -import streamJsonParser from 'stream-json/Parser'; +import Asm from 'stream-json/Assembler.js'; +import streamJsonParser from 'stream-json/Parser.js'; const { chain } = streamChain; const { parser } = streamJsonParser; diff --git a/tsup.config.ts b/tsup.config.ts index 4c8706c..b4aaadc 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -7,7 +7,11 @@ export default defineConfig((options) => { return { entry: [entryPattern], outDir: 'dist', - format: ['cjs', 'esm', 'iife'], + // Librairies like `change-case` are ESM-only and cannot be imported from a CJS package, so we decided to only package the ESM format + // It should be fine since `figpot` is intended to be used as a CLI, and not directly imported into third-party code + // Other formats can be reconsidered once Node v22 has more traction, since from this version it's allowed for CJS to import ESM modules + format: ['esm'], + // format: ['cjs', 'esm', 'iife'], globalName: 'Figpot', minify: !options.watch, splitting: true,