Skip to content

Create package.json for esm and cjs distributions #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
#
# Add package.json files to cjs/mjs subtrees
#

cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/esm/package.json <<!EOF
{
"type": "module"
}
!EOF

find src -name '*.d.ts' -exec cp {} dist/cjs \;
find src -name '*.d.ts' -exec cp {} dist/esm \;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"scripts": {
"clean": "rimraf './dist'",
"build": "npm run clean && tsc --project tsconfig.json && tsc --project tsconfig.cjs.json",
"build": "npm run clean && tsc --project tsconfig.json && tsc --project tsconfig.cjs.json && ./fixup",
"lint": "eslint .",
"prepare": "npm run build",
"test": "npm run build && jest",
Expand Down
2 changes: 1 addition & 1 deletion src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Request,
_TypedFetch,
TypedFetch,
} from './types'
} from './types.js'

const sendBody = (method: Method) =>
method === 'post' ||
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fetcher } from './fetcher'
import { arrayRequestBody } from './utils'
import { Fetcher } from './fetcher.js'
import { arrayRequestBody } from './utils.js'

import type {
ApiResponse,
Expand All @@ -14,7 +14,7 @@ import type {
TypedFetch,
} from './types'

import { ApiError } from './types'
import { ApiError } from './types.js'

export type {
OpArgType,
Expand Down