Skip to content

Commit

Permalink
Adds hybrid JS exports for commonjs and mjs (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewMacmurray authored Dec 17, 2023
1 parent c7dce12 commit a3886f0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
"name": "@andrewmacmurray/elm-concurrent-task",
"version": "1.0.0",
"description": "Run a tree of Tasks concurrently, call JS functions as Tasks (Task Ports)",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "lib/cjs/index.js",
"module": "lib/mjs/index.js",
"types": "lib/mjs/index.d.ts",
"exports": {
".": {
"import": "./lib/mjs/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/mjs/index.d.ts"
}
},
"files": [
"lib"
],
Expand All @@ -14,7 +22,7 @@
"review": "elm-review --fix",
"review:ci": "elm-review",
"review:watch": "elm-review --watch",
"runner:compile": "tsc",
"runner:compile": "rm -rf lib/* && tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && ./scripts/package-fixup.sh",
"check-versions": "node ./scripts/versions.js"
},
"author": "Andrew MacMurray",
Expand Down
6 changes: 5 additions & 1 deletion runner/http/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export function http(request: HttpRequest): Promise<HttpResponse> {
signal: controller?.signal,
})
.then((res: Response) => {
const headers = Object.fromEntries(res.headers.entries());
const headers: { [key: string]: string } = {};
res.headers.forEach((val, key) => {
headers[key] = val;
});

switch (request.expect) {
case "STRING": {
return res.text().then((x) => ({
Expand Down
15 changes: 15 additions & 0 deletions scripts/package-fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /bin/bash

# Adds package.json files to cjs/mjs subtrees

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

cat >lib/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
16 changes: 2 additions & 14 deletions tsconfig.json → tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
{
"compilerOptions": {
"outDir": "lib",
"removeComments": true,
"target": "ESNext",
"declaration": true,

// Module resolution
"baseUrl": "runner",
"esModuleInterop": true,
"moduleResolution": "node",

// Source Map
"sourceMap": true,
"sourceRoot": "./runner",

// Strict Checks
"alwaysStrict": true,
"allowUnreachableCode": false,
"noImplicitAny": true,
"strictNullChecks": true,

// Linter Checks
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["runner/**/*.ts"],
"exclude": [
"node_modules/**/*"
]
}
"exclude": ["node_modules/**/*"]
}
8 changes: 8 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "lib/cjs",
"target": "ES2015"
}
}
8 changes: 8 additions & 0 deletions tsconfig-mjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "lib/mjs",
"target": "ESNext"
}
}

0 comments on commit a3886f0

Please sign in to comment.