From 55aeee610ca0384dfb50f2207252f27befb8aa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Raiti?= <46955459+Secreto31126@users.noreply.github.com> Date: Fri, 20 Dec 2024 05:38:52 -0300 Subject: [PATCH 1/4] Remove CJS build step The file will most probably be deleted and replaced with a CLI command --- build.js | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/build.js b/build.js index 5bbe1241..283e2227 100644 --- a/build.js +++ b/build.js @@ -1,32 +1,10 @@ -/* eslint-disable tsdoc/syntax */ - import { build } from "esbuild"; import { glob } from "glob"; -import { writeFile } from "fs/promises"; -/** - * @type {import("esbuild").BuildOptions} - */ -const sharedConfig = { +await build({ entryPoints: await glob("src/**/*.ts", { ignore: ["src/standalone.ts"] }), sourcemap: true, - platform: "node" -}; - -await Promise.all([ - // ESM - build({ - ...sharedConfig, - format: "esm", - outdir: "lib/esm" - }), - - // CJS - build({ - ...sharedConfig, - format: "cjs", - outdir: "lib/cjs" - }) -]); - -await writeFile("./lib/cjs/package.json", '{"type":"commonjs"}'); + platform: "node", + format: "esm", + outdir: "lib" +}); From 94a053f2b611af4df37ffd32a50642b6a9a2f2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Raiti?= <46955459+Secreto31126@users.noreply.github.com> Date: Fri, 20 Dec 2024 05:44:44 -0300 Subject: [PATCH 2/4] Updated exposed path --- package.json | 55 +++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 486d8bcb..a2228e83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-api-js", - "version": "4.1.1", + "version": "5.0.0", "author": "Secreto31126", "description": "A TypeScript server agnostic Whatsapp's Official API framework", "license": "MIT", @@ -12,46 +12,39 @@ "files": [ "lib/**/*" ], - "types": "lib/types/index.d.ts", - "module": "lib/esm/index.js", - "main": "lib/cjs/index.js", + "types": "lib/index.d.ts", + "module": "lib/index.js", "exports": { ".": { - "types": "./lib/types/index.d.ts", - "import": "./lib/esm/index.js", - "require": "./lib/cjs/index.js" + "types": "./lib/index.d.ts", + "import": "./lib/index.js" }, "./messages": { - "types": "./lib/types/messages/index.d.ts", - "import": "./lib/esm/messages/index.js", - "require": "./lib/cjs/messages/index.js" + "types": "./lib/messages/index.d.ts", + "import": "./lib/messages/index.js" }, "./messages/*": { - "types": "./lib/types/messages/*.d.ts", - "import": "./lib/esm/messages/*.js", - "require": "./lib/cjs/messages/*.js" + "types": "./lib/messages/*.d.ts", + "import": "./lib/messages/*.js" }, "./setup": null, "./setup/index": null, "./setup/*": { - "types": "./lib/types/setup/*.d.ts", - "import": "./lib/esm/setup/*.js", - "require": "./lib/cjs/setup/*.js" + "types": "./lib/setup/*.d.ts", + "import": "./lib/setup/*.js" }, "./middleware": null, "./middleware/index": null, "./middleware/*": { - "types": "./lib/types/middleware/*.d.ts", - "import": "./lib/esm/middleware/*.js", - "require": "./lib/cjs/middleware/*.js" + "types": "./lib/middleware/*.d.ts", + "import": "./lib/middleware/*.js" }, "./emitters": { - "types": "./lib/types/emitters.d.ts" + "types": "./lib/emitters.d.ts" }, "./types": { - "types": "./lib/types/types.d.ts", - "import": "./lib/esm/types.js", - "require": "./lib/cjs/types.js" + "types": "./lib/types.d.ts", + "import": "./lib/types.js" } }, "//": [ @@ -62,27 +55,27 @@ "typesVersions": { "*": { ".": [ - "lib/types/index.d.ts" + "lib/index.d.ts" ], "messages": [ - "lib/types/messages/index.d.ts" + "lib/messages/index.d.ts" ], "messages/*": [ - "lib/types/messages/*.d.ts" + "lib/messages/*.d.ts" ], "setup/index": [], "setup/*": [ - "lib/types/setup/*.d.ts" + "lib/setup/*.d.ts" ], "middleware/index": [], "middleware/*": [ - "lib/types/middleware/*.d.ts" + "lib/middleware/*.d.ts" ], "emitters": [ - "lib/types/emitters.d.ts" + "lib/emitters.d.ts" ], "types": [ - "lib/types/types.d.ts" + "lib/types.d.ts" ] } }, @@ -92,7 +85,7 @@ "build:code": "node -r dotenv/config build.js", "build:code:dev": "npm run build:code", "build:types": "tsc", - "build:types:dev": "tsc --outDir ./lib/esm && tsc --outDir ./lib/cjs", + "build:types:dev": "npm run build:types", "build:standalone": "esbuild src/standalone.ts --outfile=lib/standalone.js --bundle --platform=neutral --target=node10 --minify-syntax", "test": "node --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout", "test:build": "npm run build && npm run test", From aeac17072845bb08dadb80798faffb7a570a5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Raiti?= <46955459+Secreto31126@users.noreply.github.com> Date: Fri, 20 Dec 2024 05:52:00 -0300 Subject: [PATCH 3/4] Update tsconfig.json --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index c1788242..72d6075d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "target": "ESNext", "module": "Preserve", "moduleResolution": "Bundler", - "outDir": "lib/types", + "outDir": "lib", "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, From e142840fce5472d8803868166dc18cb7a887df80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Raiti?= <46955459+Secreto31126@users.noreply.github.com> Date: Fri, 20 Dec 2024 06:49:08 -0300 Subject: [PATCH 4/4] Update index.test.js --- test/index.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 29290475..31cd4bda 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -7,9 +7,9 @@ import { spy as sinon_spy, assert as sinon_assert } from "sinon"; import { describe, it, beforeEach, afterEach } from "node:test"; // Import the module -import { WhatsAppAPI } from "../lib/esm/middleware/node-http.js"; -import { DEFAULT_API_VERSION } from "../lib/esm/types.js"; -import { Text } from "../lib/esm/messages/text.js"; +import { WhatsAppAPI } from "../lib/middleware/node-http.js"; +import { DEFAULT_API_VERSION } from "../lib/types.js"; +import { Text } from "../lib/messages/text.js"; // Mock the https requests import { agent, clientFacebook, clientExample } from "./server.mocks.js";