Skip to content

Commit

Permalink
chore: compile as esm package only to not face cjs issues (not import…
Browse files Browse the repository at this point in the history
…ant since we publish as a cli program)
  • Loading branch information
sneko committed Jul 30, 2024
1 parent 6dd953d commit f4f3239
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
printWidth: 150,
semi: true,
singleQuote: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/clients/workaround.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@figpot/src/cli/program';
import '@figpot/src/cli/index';
4 changes: 2 additions & 2 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f4f3239

Please sign in to comment.