Skip to content

Commit

Permalink
feat(export): Setup ESM first
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Jun 23, 2024
1 parent 5514d36 commit 1f624f3
Show file tree
Hide file tree
Showing 12 changed files with 1,108 additions and 68 deletions.
4 changes: 2 additions & 2 deletions eslint.config.mjs → eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export default eslintTs.config(
"@stylistic/switch-colon-spacing": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-exports": "off",
"@typescript-eslint/consistent-type-imports": ["off", { fixStyle: "inline-type-imports" }],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }],
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true }],
"@typescript-eslint/explicit-member-accessibility": "error",
Expand Down
35 changes: 26 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,42 @@
"rxjs",
"rxjs-observable"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"source": "./src/main.ts",
"main": "./dist/main.cjs",
"module": "./dist/main.js",
"unpkg": "./dist/main.umd.cjs",
"types": "./dist/main.d.ts",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/main.js",
"require": "./dist/main.cjs",
"types": "./dist/main.d.ts",
"default": "./dist/main.js"
},
"./package.json": "./package.json"
},
"files": [
"dist/",
"src/"
"./dist",
"./src",
"./package.json"
],
"engines": {
"node": ">=18"
},
"scripts": {
"build": "tsc -p tsconfig.prod.json",
"build": "vite build",
"check": "yarn compile && yarn lint && yarn test --forbid-only",
"compile": "tsc",
"lint": "eslint .",
"release": "semantic-release",
"test": "NODE_ENV=test mocha"
},
"packageManager": "[email protected]",
"dependencies": {
"pino": "^9.2.0"
},
"devDependencies": {
"@assertive-ts/core": "^2.1.0",
"@assertive-ts/sinon": "^1.0.0",
Expand Down Expand Up @@ -66,7 +84,9 @@
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.2",
"typescript-eslint": "^7.13.1"
"typescript-eslint": "^7.13.1",
"vite": "^5.3.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
"axios": ">=1.0.0",
Expand All @@ -83,8 +103,5 @@
"publishConfig": {
"access": "public",
"provenance": true
},
"dependencies": {
"pino": "^9.2.0"
}
}
27 changes: 14 additions & 13 deletions src/lib/RxjsAxios.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import axios, {
AxiosError,
AxiosInstance,
AxiosInterceptorManager,
AxiosRequestConfig,
AxiosRequestHeaders,
AxiosResponseHeaders,
Cancel,
CreateAxiosDefaults,
FormSerializerOptions,
GenericFormData,
GenericHTMLFormElement,
AxiosResponse as OriginalAxiosResponse,
type AxiosError,
type AxiosInstance,
type AxiosInterceptorManager,
type AxiosRequestConfig,
type AxiosRequestHeaders,
type AxiosResponseHeaders,
type Cancel,
type CreateAxiosDefaults,
type FormSerializerOptions,
type GenericFormData,
type GenericHTMLFormElement,
type AxiosResponse as OriginalAxiosResponse,
} from "axios";
import pino from "pino";
import { Observable } from "rxjs";

import { observify } from "./observify";

import type { Observable } from "rxjs";

export type AxiosResponse<T, D = unknown> = OriginalAxiosResponse<T, D>;

export type AxiosObservable<T> = Observable<AxiosResponse<T>>;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/helpers/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpResponse, PathParams, http } from "msw";
import { HttpResponse, type PathParams, http } from "msw";

export interface User {
id?: number;
Expand Down
5 changes: 3 additions & 2 deletions test/lib/RxjsAxios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Observable } from "rxjs";
import { delay, map, repeat } from "rxjs/operators";
import Sinon from "sinon";

import { axios } from "../../src";
import { RxjsAxios } from "../../src/lib/RxjsAxios";
import { User } from "../helpers/mocks";
import { axios } from "../../src/main";

import type { User } from "../helpers/mocks";

describe("[Unit] RxjsAxios.test.ts", () => {
describe(".of", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/observify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { expect } from "@assertive-ts/core";
import { AxiosError, AxiosHeaders } from "axios";
import Sinon from "sinon";

import { AxiosResponse } from "../../src/lib/RxjsAxios";
import { observify } from "../../src/lib/observify";
import { delay } from "../helpers/async.helpers";

import type { AxiosResponse } from "../../src/lib/RxjsAxios";

const RESPONSE: AxiosResponse<string> = {
config: { headers: AxiosHeaders.from() },
data: "ok",
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts → test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@assertive-ts/core";

import { Axios, axios } from "../src";
import { RxjsAxios } from "../src/lib/RxjsAxios";
import { Axios, axios } from "../src/main";

describe("[Unit] index.test.ts", () => {
context("the default instance is imported", () => {
Expand Down
24 changes: 12 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"incremental": true,
"module": "CommonJS",
"moduleResolution": "Node",
"isolatedModules": true,
"module": "ES2022",
"moduleResolution": "Bundler",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./build/",
"outDir": "./build",
"pretty": true,
"removeComments": false,
"resolveJsonModule": true,
Expand All @@ -24,17 +25,16 @@
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "ES6",
"typeRoots" : [
"./node_modules/@types/",
"./typings/"
],
"target": "ES2022",
"useDefineForClassFields": true,
"useUnknownInCatchVariables": true,
"verbatimModuleSyntax": true
},
"exclude": [
".yarn/*",
"build/*",
"dist/*",
"node_modules/*"
"./.yarn/**",
"./build/**",
"./dist/**",
"./node_modules/**"
],
"ts-node": {
"transpileOnly": true
Expand Down
11 changes: 0 additions & 11 deletions tsconfig.prod.json

This file was deleted.

22 changes: 22 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";

export default defineConfig({
build: {
lib: {
entry: "./src/main.ts",
fileName: "main",
formats: ["cjs", "es", "umd"],
name: "RxjsAxios",
},
},
plugins: [
dts({
compilerOptions: {
emitDeclarationOnly: true,
incremental: false,
},
include: "./src/**",
}),
],
});
Loading

0 comments on commit 1f624f3

Please sign in to comment.