Skip to content

Commit e0e8471

Browse files
chore: run prettier
1 parent 9058bec commit e0e8471

File tree

4 files changed

+55
-36
lines changed

4 files changed

+55
-36
lines changed

examples/example-esm.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ async function sendMessageAsync() {
106106
}
107107

108108
// Uncomment to run async example
109-
// sendMessageAsync();
109+
// sendMessageAsync();

lib-esm/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ESM wrapper for twilio-node
2-
import { createRequire } from 'module';
2+
import { createRequire } from "module";
33
const require = createRequire(import.meta.url);
44

55
// Import the CommonJS module
6-
const TwilioSDK = require('../lib/index.js');
6+
const TwilioSDK = require("../lib/index.js");
77

88
// Extract all exports from the CJS module
99
const {
@@ -22,7 +22,7 @@ const {
2222
validateIncomingRequest,
2323
getExpectedBodyHash,
2424
getExpectedTwilioSignature,
25-
webhook
25+
webhook,
2626
} = TwilioSDK;
2727

2828
// Export everything as named exports
@@ -42,7 +42,7 @@ export {
4242
validateIncomingRequest,
4343
getExpectedBodyHash,
4444
getExpectedTwilioSignature,
45-
webhook
45+
webhook,
4646
};
4747

4848
// Also provide default export for convenience

scripts/build-esm.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require("fs");
2+
const path = require("path");
33

44
// Create lib-esm directory
5-
const libEsmDir = path.join(__dirname, '..', 'lib-esm');
5+
const libEsmDir = path.join(__dirname, "..", "lib-esm");
66
if (!fs.existsSync(libEsmDir)) {
77
fs.mkdirSync(libEsmDir);
88
}
@@ -59,16 +59,19 @@ export {
5959
export default TwilioSDK;
6060
`;
6161

62-
fs.writeFileSync(path.join(libEsmDir, 'index.js'), esmIndexContent);
62+
fs.writeFileSync(path.join(libEsmDir, "index.js"), esmIndexContent);
6363

6464
// Create package.json for ESM directory
6565
const esmPackageJson = {
66-
"type": "module"
66+
type: "module",
6767
};
6868

69-
fs.writeFileSync(path.join(libEsmDir, 'package.json'), JSON.stringify(esmPackageJson, null, 2));
69+
fs.writeFileSync(
70+
path.join(libEsmDir, "package.json"),
71+
JSON.stringify(esmPackageJson, null, 2)
72+
);
7073

71-
console.log('ESM build completed!');
72-
console.log('Generated files:');
73-
console.log('- lib-esm/index.js');
74-
console.log('- lib-esm/package.json');
74+
console.log("ESM build completed!");
75+
console.log("Generated files:");
76+
console.log("- lib-esm/index.js");
77+
console.log("- lib-esm/package.json");

scripts/verify-esm.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,57 @@
44
* Verification script to test both CommonJS and ESM imports work correctly
55
*/
66

7-
console.log('🧪 Testing twilio-node ESM support...\n');
7+
console.log("🧪 Testing twilio-node ESM support...\n");
88

99
// Test CommonJS
10-
console.log('📦 Testing CommonJS import...');
10+
console.log("📦 Testing CommonJS import...");
1111
try {
12-
const twilio = require('../lib/index.js');
13-
console.log('✅ CommonJS import successful');
12+
const twilio = require("../lib/index.js");
13+
console.log("✅ CommonJS import successful");
1414
console.log(` - Default export type: ${typeof twilio}`);
15-
console.log(` - Twilio class available: ${typeof twilio.Twilio === 'function'}`);
16-
console.log(` - JWT utilities available: ${typeof twilio.jwt === 'object'}`);
17-
console.log(` - TwiML utilities available: ${typeof twilio.twiml === 'object'}`);
18-
console.log(` - Webhook validation available: ${typeof twilio.validateBody === 'function'}`);
15+
console.log(
16+
` - Twilio class available: ${typeof twilio.Twilio === "function"}`
17+
);
18+
console.log(
19+
` - JWT utilities available: ${typeof twilio.jwt === "object"}`
20+
);
21+
console.log(
22+
` - TwiML utilities available: ${typeof twilio.twiml === "object"}`
23+
);
24+
console.log(
25+
` - Webhook validation available: ${
26+
typeof twilio.validateBody === "function"
27+
}`
28+
);
1929
} catch (error) {
20-
console.log('❌ CommonJS import failed:', error.message);
30+
console.log("❌ CommonJS import failed:", error.message);
2131
process.exit(1);
2232
}
2333

24-
console.log('\n📦 Testing ESM dynamic import...');
34+
console.log("\n📦 Testing ESM dynamic import...");
2535
// Test ESM with dynamic import (works in both CommonJS and ESM contexts)
26-
import('../lib-esm/index.js')
36+
import("../lib-esm/index.js")
2737
.then((esm) => {
28-
console.log('✅ ESM import successful');
38+
console.log("✅ ESM import successful");
2939
console.log(` - Default export type: ${typeof esm.default}`);
30-
console.log(` - Named Twilio export: ${typeof esm.Twilio === 'function'}`);
31-
console.log(` - Named JWT export: ${typeof esm.jwt === 'object'}`);
32-
console.log(` - Named TwiML export: ${typeof esm.twiml === 'object'}`);
33-
console.log(` - Named validateBody export: ${typeof esm.validateBody === 'function'}`);
34-
35-
console.log('\n🎉 All tests passed! ESM support is working correctly.');
36-
console.log('\n📚 Usage examples:');
40+
console.log(
41+
` - Named Twilio export: ${typeof esm.Twilio === "function"}`
42+
);
43+
console.log(` - Named JWT export: ${typeof esm.jwt === "object"}`);
44+
console.log(` - Named TwiML export: ${typeof esm.twiml === "object"}`);
45+
console.log(
46+
` - Named validateBody export: ${
47+
typeof esm.validateBody === "function"
48+
}`
49+
);
50+
51+
console.log("\n🎉 All tests passed! ESM support is working correctly.");
52+
console.log("\n📚 Usage examples:");
3753
console.log(' CommonJS: const twilio = require("twilio");');
3854
console.log(' ESM: import twilio from "twilio";');
3955
console.log(' ESM: import { Twilio, jwt, twiml } from "twilio";');
4056
})
4157
.catch((error) => {
42-
console.log('❌ ESM import failed:', error.message);
58+
console.log("❌ ESM import failed:", error.message);
4359
process.exit(1);
44-
});
60+
});

0 commit comments

Comments
 (0)