From 77fbdad04f01a7b735c0c00f73036e85ef5d81c3 Mon Sep 17 00:00:00 2001 From: Jonathan Delgado Date: Thu, 21 Mar 2024 14:18:23 -0300 Subject: [PATCH] perf: enhance project structure and introduce normalization This commit significantly restructures the project to improve its maintainability and compatibility across different systems. Changes include: - Added `.editorconfig` settings for `Makefile` to ensure consistent indentation using tabs, promoting a unified coding style across different IDEs/environments. - Updated `.gitignore` and introduced `.npmignore` to refine what files are excluded from version control and what files are ignored when publishing the package. This ensures that only relevant files are packaged, reducing the package size and enhancing security. - Adjusted `package.json` to simplify the project's structure by removing outdated configurations and introducing `types`, `typesVersions`, and updated `exports` to better support TypeScript type definitions and module resolution. This aims to provide clearer entry points for different module systems (ESM, CommonJS), making the library more accessible to various consumers. - Introduced specific `tsconfig` files (`tsconfig.bundler.json`, `tsconfig.cjs.json`, `tsconfig.esm.json`, and `tsconfig.types.json`) to cater to different build targets (AMD, CommonJS, ES Modules, and type declarations). This modularized approach allows for more tailored compilation settings, improving build performance and compatibility. - Updated the build and prepack scripts to incorporate these changes, ensuring that the library is properly built before it is packed and published. These changes collectively aim to make the library more robust, flexible, and easier to use across diverse environments. By adopting common conventions and optimizing for current JavaScript toolchains, the project sets a strong foundation for future development and collaboration. --- .editorconfig | 5 ++++- .gitignore | 3 +++ .npmignore | 6 ++++++ bun.lockb | Bin 3532 -> 4582 bytes package.json | 41 ++++++++++++++++++++++++++++++++++------- tsconfig.bundler.json | 13 +++++++++++++ tsconfig.cjs.json | 15 +++++++++++++++ tsconfig.esm.json | 12 ++++++++++-- tsconfig.types.json | 18 ++++++++++++++++++ 9 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 .npmignore create mode 100644 tsconfig.bundler.json create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.types.json diff --git a/.editorconfig b/.editorconfig index ebe51d3..94a66d4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,4 +9,7 @@ indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = false -insert_final_newline = false \ No newline at end of file +insert_final_newline = false + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore index 4abcf36..0320b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ !.editorconfig +!.npmignore +lib/ +!Makefile # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..0bc92e5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +src/ +Makefile +tsconfig.* +*.lockb +.* +*.tgz diff --git a/bun.lockb b/bun.lockb index 57137562ca124a947cbb62a5803c75dced76d3fa..4ef2a4519ec354e0ba2d0da44dd3a234b87519e1 100755 GIT binary patch delta 1305 zcmX>j{Y-g+p4N?Et?=jZ{K6Y6kEG6ynI7?&*KXm#W3y5}I%s@uymX2$OppN#xEUq} zh)vAnsE_A{2tY^y28IS8X5a$S#i_YvsYMJ7Yk_=DAipv(CnvMGgrT4)wWK67wMYu8 zZZRW7{u7jb4y1vGHe@m}Fz^8ByJq&sKQx}NpRd}WqurXCB+ zFcBs*#>ribc1(GUlTQJuHH?$FnCuvTPxfT8XVPby+{I+aRLV5@6q8jwD^M#4g8+yI zI+uYBN`tHg0c08^&jG|h?|{MutR56-AaS7o;DAVT)xa7+7T`5_awYSbdZ8Neww(nr zCv6*6@BI6-@Y(7AS#{M+E}2tuANs7@6TLBz=l+r(PaFH!`Mlp-Yvo{bv*_Tl?cx`f zwD&*#$??K33~b3i{(nH5nBneZU|><}o2%}}G*jcLmMr0uXRz{4p3CCR$UgZcOE@FPWJlI;M$XAIfh5=DkF3=KuoRgC z)X58sd|=#b08<0Y*d;i#VL58UFo; z08nUvBJ%}QUVvxvISxHFP$+?-1{9Z|I0vSCaM}Q=a)3s50Z6Hq87Rqsl!1~3C?-K# zS%4U%9i$DW9c0S_sMZ_2lhZiWCQsn>tB3gomK!)g=70e#|H1ML2VFu?LAEGq$JOdv9_+*$o5{cMNOYb7Q|L!g9_oFxMTETc};kLp$1 zYHP{FSZ8FQXK1Kr{Asc-m!uu0ycX1nu&m9QZ*%Nb;H=$1ou+z5W_l(J8hj8X8GMsl zxLhV5<8tDf0TuESoGipWjT7Q=y{zKNYk8!VAUu6teF#I>To2@=r jkTNMa52zB()&(h@yn;tT9O`|bB$TBK_WkAs+&WAEH!x1H delta 655 zcmaE+d`5bLp5_%bEv5(a=G7(r^!mtSQ?oO1;RM5i#4A;+O4bV5d{k1g;bi~=j)~#& zQ5hT%4ulk7U}ykh1}-37P?TCyl9^g01?9g4(wsnX3q}a73#7S${PjSZ2T0#Fvp@c! z@qGP!)dn5y*3_g)j60ZW7$#RS*)eTln7j)}ePWpWi^-1Bak3?|JyR*;VWDB3n z!NxmTmff3?b#f+q_~acx-dP}zeX=A+_2dg29IQD&dj%#h_{990+pv2dFd;=VU1!t;rv_S)@Qt26>GQh(WRzQ2)e$lql(ee8>#M zAfJQSAmt#XFfAZcCqT7SaZRq`Q3I)-JfFwk6c&T9nBV}J0R}IDBv4O7^_%pw9YU{_ zm>3Q94D^gF85ndY7xGFnT1@Wdm6U_q*jUbU^ZmQ0LVQ2px}Cm-OI;5q?JA0WWN fJ^2x@%VZ5c2QCX>QUC!H-pNIL(>5RCS78DG9%^?z diff --git a/package.json b/package.json index a55a1e9..e9dc49a 100644 --- a/package.json +++ b/package.json @@ -2,34 +2,61 @@ "name": "streamable-tools", "description": "`streamable-tools` is a JS/TS library for easy stream manipulation in web apps, offering utilities like `MultiplyStream` for data propagation, `SplitStream` for data splitting, and tools for stream creation and control.", "version": "0.1.5", - "module": "index.ts", - "type": "module", "license": "MIT", + "types": "./index.d.ts", + "typesVersions": { + "*": { + "*": [ + "./lib/types/*" + ] + } + }, "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "default": "./lib/cjs/index.js" + }, "./multiply-stream": { - "default": "./dist/esm/multiply-stream.js" + "types": "./lib/types/multiply-stream.d.ts", + "import": "./lib/esm/multiply-stream.js", + "default": "./lib/cjs/multiply-stream.js" }, "./readable-stream-with-controller": { - "default": "./dist/esm/readable-stream-with-controller.js" + "types": "./lib/types/readable-stream-with-controller.d.ts", + "import": "./lib/esm/readable-stream-with-controller.js", + "default": "./lib/cjs/readable-stream-with-controller.js" }, "./split-stream": { - "default": "./dist/esm/split-stream.js" + "types": "./lib/types/split-stream.d.ts", + "import": "./lib/esm/split-stream.js", + "default": "./lib/cjs/split-stream.js" }, "./iterable-to-readable-stream": { - "default": "./dist/esm/iterable-to-readable-stream.js" + "types": "./lib/types/iterable-to-readable-stream.d.ts", + "import": "./lib/esm/iterable-to-readable-stream.js", + "default": "./lib/cjs/iterable-to-readable-stream.js" } }, "repository": { "type": "git", "url": "https://github.com/JonDotsoy/streamable-tools.git" }, + "files": [ + "./src/", + "./lib/cjs/", + "./lib/types/", + "./lib/esm/" + ], "scripts": { - "build@esm": "tsc --project tsconfig.esm.json --outdir ./dist/esm", + "prepack": "make build", + "build": "make build", "fmt": "prettier -w ." }, "devDependencies": { "@types/bun": "latest", "prettier": "^3.2.5", + "semver": "^7.6.0", "typescript": "^5.4.2" }, "peerDependencies": { diff --git a/tsconfig.bundler.json b/tsconfig.bundler.json new file mode 100644 index 0000000..28f124c --- /dev/null +++ b/tsconfig.bundler.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "allowImportingTsExtensions": false, + "moduleResolution": "Bundler", + "target": "ES2015", + "module": "amd", + "verbatimModuleSyntax": false + }, + "exclude": ["./dist/", "**/*.spec.ts"] +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..40deefa --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "allowImportingTsExtensions": false, + "moduleResolution": "Node", + "target": "ES2016", + "module": "CommonJS", + "verbatimModuleSyntax": false, + "sourceRoot": "./src/", + "inlineSourceMap": true + }, + "exclude": ["./dist/", "./lib/", "**/*.spec.ts", "**/tests/**"] +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 3d7165c..75c23ba 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -3,7 +3,15 @@ "compilerOptions": { "noEmit": false, "declaration": true, - "allowImportingTsExtensions": false + "allowImportingTsExtensions": false, + "sourceRoot": "./src/", + "inlineSourceMap": true }, - "exclude": ["**/*.spec.ts"] + "exclude": [ + "./dist/", + "./lib/", + "**/*.spec.ts", + "**/tests/**", + "**/__templates__/**" + ] } diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..083758d --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,18 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "allowImportingTsExtensions": false, + "sourceRoot": "./src/", + "inlineSourceMap": true, + "emitDeclarationOnly": true + }, + "exclude": [ + "./dist/", + "./lib/", + "**/*.spec.ts", + "**/tests/**", + "**/__templates__/**" + ] +}