Skip to content

Commit

Permalink
trying to fix node.js support (esm & cjs)
Browse files Browse the repository at this point in the history
  • Loading branch information
krutoo committed Jun 14, 2023
1 parent e245e4b commit a8195d0
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
{
"name": "@krutoo/fetch-tools",
"version": "0.0.0",
"description": " Set of utilities for JS fetch function",
"description": "Set of utilities for JS fetch function",
"files": [
"dist",
"src"
],
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
},
"./middleware": {
"types": "./dist/types/middleware.d.ts",
"node": "./dist/cjs/middleware.js",
"require": "./dist/cjs/middleware.js",
"import": "./dist/esm/middleware.js",
"default": "./dist/esm/middleware.js"
},
"./response": {
"types": "./dist/types/response.d.ts",
"node": "./dist/cjs/response.js",
"require": "./dist/cjs/response.js",
"import": "./dist/esm/response.js",
"default": "./dist/esm/response.js"
},
"./server": {
"types": "./dist/types/server.d.ts",
"node": "./dist/cjs/server.js",
"require": "./dist/cjs/server.js",
"import": "./dist/esm/server.js",
"default": "./dist/esm/server.js"
Expand Down
11 changes: 0 additions & 11 deletions test/index.test.ts

This file was deleted.

37 changes: 37 additions & 0 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "fetch-tools-tests",
"version": "0.0.0",
"description": "Tests",
"private": true,
"scripts": {
"test": "npm run test:cjs && npm run test:mjs",
"test:cjs": "node test.cjs",
"test:mjs": "node test.mjs"
},
"dependencies": {
"@krutoo/fetch-tools": "file:.."
}
}
14 changes: 14 additions & 0 deletions test/test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { configureFetch, applyMiddleware } = require('@krutoo/fetch-tools');
const { validateStatus } = require('@krutoo/fetch-tools/middleware');

console.assert(typeof configureFetch === 'function');
console.assert(typeof applyMiddleware === 'function');

const myFetch = configureFetch(
fetch,
applyMiddleware(validateStatus(status => status >= 200 && status < 300)),
);

myFetch('https://jsonplaceholder.typicode.com/posts/1')
.then(res => res.json())
.then(console.log);
14 changes: 14 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { configureFetch, applyMiddleware } from '@krutoo/fetch-tools';
import { validateStatus } from '@krutoo/fetch-tools/middleware';

console.assert(typeof configureFetch === 'function');
console.assert(typeof applyMiddleware === 'function');

const myFetch = configureFetch(
fetch,
applyMiddleware(validateStatus(status => status >= 200 && status < 300)),
);

myFetch('https://jsonplaceholder.typicode.com/posts/1')
.then(res => res.json())
.then(console.log);

0 comments on commit a8195d0

Please sign in to comment.