Skip to content

Commit

Permalink
create builds for cjs and module
Browse files Browse the repository at this point in the history
  • Loading branch information
minasaleeb-sp committed Jan 23, 2024
1 parent 8b25061 commit de6f74b
Show file tree
Hide file tree
Showing 8 changed files with 1,916 additions and 1,495 deletions.
11 changes: 11 additions & 0 deletions fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
27 changes: 17 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "badmagic",
"version": "0.0.39",
"version": "0.0.40",
"description": "Swagger UI alternative written in React",
"scripts": {
"build": "yarn clean && yarn copy-css && tsc -p ./",
"build": "yarn clean && yarn copy-css && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./fixup",
"start": "yarn clean && yarn copy-css && tsc --watch",
"clean": "rimraf dist",
"test": "jest",
Expand All @@ -15,8 +15,15 @@
"copy-css": "mkdir -p dist/css && cp ./src/css/*.min.css ./dist/css/",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src test"
},
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"typings": "./dist/mjs/index.d.ts",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"files": [
"dist"
],
Expand All @@ -34,8 +41,8 @@
"@types/lodash-es": "^4.17.3",
"@types/node": "^16.0.0",
"@types/openapi-v3": "^3.0.0",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"@types/yup": "^0.29.14",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
Expand All @@ -53,8 +60,8 @@
"typescript": "^4.5.2"
},
"peerDependencies": {
"react": ">= 16.8.x",
"react-dom": ">= 16.8.x"
"axios": ">=1.0.0",
"react": "^16.8.0-0 || ^17.0.0 || ^18.0.0"
},
"prettier": {
"printWidth": 80,
Expand All @@ -64,8 +71,8 @@
"arrowParens": "always"
},
"dependencies": {
"@smartrent/use-axios": "^2.0.0",
"axios": "^0.24.0",
"axios": "^1.6.5",
"axios-hooks": "^5.0.2",
"lodash-es": "^4.17.15",
"querystring": "^0.2.0",
"rc-tooltip": "^5.2.2",
Expand Down
12 changes: 7 additions & 5 deletions src/common/route/RequestResponse.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo } from "react";
import useAxios from "@smartrent/use-axios";
import { makeUseAxios } from "axios-hooks";
import axios from "axios";

import { useGlobalContext } from "../../context/GlobalContext";
Expand Down Expand Up @@ -86,13 +86,15 @@ export function RequestResponse({
: axiosInstance;
}, [route, storeHistoricResponseWithRoute]);

const { response, loading, error, reFetch } = useAxios({
const useAxios = makeUseAxios({
axios: axiosInstance,
})
const [{ response, loading, error }, reFetch] = useAxios({
method: method as Method,
url,
options: {
data: route.body ? requestResponse.body : null, // Don't send data if `body` is not specified by the `route` definition
},
data: route.body ? requestResponse.body : null, // Don't send data if `body` is not specified by the `route` definition
}, {
manual: true // call fetch manually
});

// When a Reset button is clicked, it resets all Params
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export { default as Required } from "./common/Required";
// Helper functions that can be used with interceptors
export { default as Helpers } from "./lib/helpers";

export { Method, WorkspaceConfig } from "./types";
export * from "./types";
25 changes: 25 additions & 0 deletions tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"jsx": "react-jsx",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true,
"listEmittedFiles": false,
"listFiles": false,
"pretty": true,
"traceResolution": false,
"types": ["node", "jest"]
},
"compileOnSave": false,
"exclude": ["node_modules", "dist"],
"include": ["./src/**/*"]
}
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": "dist/cjs",
"target": "es2015"
}
}
22 changes: 5 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"module": "commonjs",
"target": "es6",
"jsx": "react",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"lib": ["dom", "es7"],
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true
},
"include": ["./src/**/*"]
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext"
}
}
Loading

0 comments on commit de6f74b

Please sign in to comment.