Skip to content

Commit

Permalink
Merge pull request #392 from Secreto31126/Secreto31126-patch-1
Browse files Browse the repository at this point in the history
Remove CJS native support
  • Loading branch information
Secreto31126 authored Dec 25, 2024
2 parents 19c23be + e142840 commit ef9bf82
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 62 deletions.
32 changes: 5 additions & 27 deletions build.js
Original file line number Diff line number Diff line change
@@ -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"
});
55 changes: 24 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
},
"//": [
Expand All @@ -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"
]
}
},
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"target": "ESNext",
"module": "Preserve",
"moduleResolution": "Bundler",
"outDir": "lib/types",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
Expand Down

0 comments on commit ef9bf82

Please sign in to comment.