Skip to content

Commit 38225d9

Browse files
committed
feat: Upgrade build to use tsup to properly support ESM and CJS
1 parent e809147 commit 38225d9

File tree

10 files changed

+671
-166
lines changed

10 files changed

+671
-166
lines changed
File renamed without changes.

.husky/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
yarn lint-staged

.prettierrc.js renamed to .prettierrc.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ module.exports = {
99
{
1010
files: '*.json',
1111
options: {
12-
tabWidth: 2,
13-
},
12+
tabWidth: 2
13+
}
1414
},
1515
{
1616
files: '*.yml',
1717
options: {
18-
tabWidth: 2,
19-
},
20-
},
18+
tabWidth: 2
19+
}
20+
}
2121
],
2222
editorconfig: true
2323
};

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "simple-sms-sender",
33
"version": "0.1.1",
44
"description": "Simple SMS sender to multiple recipients using Twilio",
5-
"main": "dist/index.js",
5+
"main": "dist/index.cjs",
6+
"module": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"type": "module",
69
"author": "Jorge Barnaby <jorge.barnaby@gmail.com>",
710
"license": "MIT",
811
"homepage": "https://github.com/yorch/simple-sms-sender#readme",
@@ -14,9 +17,7 @@
1417
"url": "https://github.com/yorch/simple-sms-sender"
1518
},
1619
"scripts": {
17-
"build": "run check && run build:ts",
18-
"build:ts": "tsc --declaration",
19-
"build:watch": "tsc -w",
20+
"build": "run check && tsup",
2021
"test": "vitest --run",
2122
"test:watch": "vitest",
2223
"test:coverage": "vitest run --coverage",
@@ -36,6 +37,9 @@
3637
"twilio": "^4.23.0"
3738
},
3839
"devDependencies": {
40+
"@microsoft/api-extractor": "7.52.2",
41+
"@tsconfig/node-lts": "22.0.1",
42+
"@tsconfig/strictest": "2.0.5",
3943
"@types/node": "20.17.30",
4044
"@typescript-eslint/eslint-plugin": "6.21.0",
4145
"@typescript-eslint/parser": "6.21.0",
@@ -47,7 +51,7 @@
4751
"lint-staged": "15.5.0",
4852
"prettier": "3.5.3",
4953
"rimraf": "6.0.1",
50-
"ts-node": "10.9.2",
54+
"tsup": "8.4.0",
5155
"typescript": "5.8.2",
5256
"vitest": "3.1.1",
5357
"yarn-or-npm": "3.0.1"

src/SmsSender.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test, vi } from 'vitest';
22

3-
import { SmsSender } from '../src/SmsSender';
3+
import { SmsSender } from './SmsSender.js';
44

55
vi.mock('twilio', () => ({
66
default: vi.fn(() => ({
@@ -55,7 +55,7 @@ describe('SmsSender', () => {
5555
const smsSender = new SmsSender({ ...commonConfig });
5656
await expect(
5757
smsSender.sendSms({
58-
body: undefined,
58+
body: '',
5959
recipients: ['+19991112223333']
6060
})
6161
).rejects.toThrowError('No body to send SMS');
@@ -66,7 +66,7 @@ describe('SmsSender', () => {
6666
await expect(
6767
smsSender.sendSms({
6868
body: 'Test',
69-
recipients: undefined
69+
recipients: []
7070
})
7171
).rejects.toThrowError('No recipients to send SMS');
7272
await expect(

src/SmsSender.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import twilio from 'twilio';
2-
import type Twilio from 'twilio/lib/rest/Twilio';
3-
import type { GenericLogger, Message } from './types';
1+
import twilio, { type Twilio } from 'twilio';
2+
import type { GenericLogger, Message } from './types.js';
43

54
export class SmsSender {
65
private accountSid: string;
@@ -47,7 +46,7 @@ export class SmsSender {
4746
}
4847

4948
const sendSmsToNumber = async (phoneNumber?: string) => {
50-
const to = phoneNumber.trim();
49+
const to = phoneNumber?.trim();
5150

5251
if (!to) {
5352
this.logger.error('Not a valid phone number to send SMS');
@@ -82,6 +81,8 @@ export class SmsSender {
8281
error
8382
);
8483
}
84+
85+
return;
8586
};
8687

8788
return Promise.all(recipients.map(sendSmsToNumber));

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { SmsSender } from './SmsSender';
1+
export { SmsSender } from './SmsSender.js';

tsconfig.json

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
{
2+
"extends": [
3+
"@tsconfig/node-lts/tsconfig.json",
4+
"@tsconfig/strictest/tsconfig.json"
5+
],
26
"compilerOptions": {
3-
"module": "commonjs",
4-
"esModuleInterop": true,
5-
"allowSyntheticDefaultImports": true,
6-
"target": "es6",
7-
"noImplicitAny": true,
8-
"moduleResolution": "node",
9-
"sourceMap": true,
10-
"outDir": "dist",
11-
"baseUrl": ".",
12-
"paths": {
13-
"*": [
14-
"node_modules/*",
15-
"src/types/*"
16-
]
17-
}
7+
"noEmit": true,
8+
"baseUrl": "."
189
},
19-
"include": [
20-
"src/**/*"
21-
]
10+
"include": ["src/**/*"]
2211
}

tsup.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig({
4+
entry: ['src/index.ts'],
5+
experimentalDts: true,
6+
format: ['cjs', 'esm'],
7+
splitting: false,
8+
sourcemap: false,
9+
clean: true
10+
});

0 commit comments

Comments
 (0)