Skip to content

Commit

Permalink
🎨 Properly build commonjs
Browse files Browse the repository at this point in the history
Fixes #247
  • Loading branch information
elbywan committed Sep 11, 2024
1 parent cdad424 commit c7f00fc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export default tseslint.config(
"AudioWorkletGlobalScope": false
}
},
ignores: ["node_modules", "dist"],
ignores: [ "dist/"],
}
)
66 changes: 49 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,64 @@
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/bundle/wretch.min.cjs",
"import": "./dist/index.js"
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./all": {
"types": "./dist/index.all.d.ts",
"require": "./dist/bundle/wretch.all.min.cjs",
"import": "./dist/index.all.js"
"require": {
"types": "./dist/cjs/index.all.d.ts",
"default": "./dist/cjs/index.all.js"
},
"import": {
"types": "./dist/index.all.d.ts",
"default:": "./dist/index.all.js"
}
},
"./addons": {
"types": "./dist/addons/index.d.ts",
"import": "./dist/addons/index.js"
"require": {
"types": "./dist/cjs/addons/index.d.ts",
"default": "./dist/cjs/addons/index.js"
},
"import": {
"types": "./dist/addons/index.d.ts",
"default": "./dist/addons/index.js"
}
},
"./addons/*": {
"types": "./dist/addons/*.d.ts",
"require": "./dist/bundle/addons/*.min.cjs",
"import": "./dist/addons/*.js"
"require": {
"types": "./dist/cjs/addons/*.d.ts",
"default": "./dist/cjs/addons/*.js"
},
"import": {
"types": "./dist/addons/*.d.ts",
"default": "./dist/addons/*.js"
}
},
"./middlewares": {
"types": "./dist/middlewares/index.d.ts",
"import": "./dist/middlewares/index.js"
"require": {
"types": "./dist/cjs/middlewares/index.d.ts",
"default": "./dist/cjs/middlewares/index.js"
},
"import": {
"types": "./dist/middlewares/index.d.ts",
"default": "./dist/middlewares/index.js"
}
},
"./middlewares/*": {
"types": "./dist/middlewares/*.d.ts",
"require": "./dist/bundle/middlewares/*.min.cjs",
"import": "./dist/middlewares/*.js"
"require": {
"types": "./dist/cjs/middlewares/*.d.ts",
"default": "./dist/cjs/middlewares/*.js"
},
"import": {
"types": "./dist/middlewares/*.d.ts",
"default": "./dist/middlewares/*.js"
}
},
"./package.json": "./package.json",
"./*.mjs": {
Expand All @@ -82,7 +114,7 @@
"lint": "eslint '{src,test}/**/*.{js,ts}'",
"lint:fix": "eslint '{src,test}/**/*.{js,ts}' --fix",
"prebuild": "rimraf dist && rimraf coverage && npm run lint",
"build": "tsc -p . && rollup -c",
"build": "tsc && tsc --project tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && rollup -c",
"mock": "node scripts/mockServer.js",
"mock:wait": "wait-on -t 10000 http://localhost:9876/ping",
"test": "concurrently --success first -k 'npm run mock:wait && jest' 'npm run mock'",
Expand Down
3 changes: 3 additions & 0 deletions src/index.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import factory from "./index.js";

module.exports = factory.default;
9 changes: 9 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "dist/cjs",
"declarationDir": "dist/cjs"
},
"exclude": []
}
13 changes: 4 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "ES2018",
"lib": [
"es2020",
"dom",
"dom.iterable"
],
"lib": ["es2020", "dom", "dom.iterable"],
"module": "es2015",
"outDir": "dist",
"declaration": true,
Expand All @@ -16,7 +12,6 @@
"moduleResolution": "node",
"isolatedModules": true
},
"include": [
"src/**/*"
]
}
"include": ["src/**/*"],
"exclude": ["src/**/index.cts"]
}

0 comments on commit c7f00fc

Please sign in to comment.