Skip to content

Commit 6c26ece

Browse files
committed
feat: upgrade twilio v5, use peer deps, enhance tooling
Upgrades core Twilio dependencies to v5.5.2 across the workspace. Resolves associated type conflicts using peer dependencies. Includes enhancements for create-twilio-function and twilio-run. Dependency & Type Alignment: - Upgraded `twilio` dependency to `5.5.2` in `runtime-handler`. - Changed `twilio` from a direct dependency to a `peerDependency (^5.5.2)` in `serverless-runtime-types` and `twilio-run`. - This enforces the use of the single root `twilio` instance, resolving type identity conflicts (TS2322/TS2352). - Updated type definitions within `serverless-runtime-types` (`types.d.ts`) to align with [email protected], primarily using `ClientOpts`. - Added compatibility export `ClientOpts as TwilioClientOptions`. - Updated `@twilio/test-dep` alias to `npm:[email protected]`. - Added root-level `peerDependency` for `twilio` for workspace checks. Package Enhancements: - `create-twilio-function`: Bumped to v3.5.0, updated default dependencies (`twilio`, `typescript`, `serverlessRuntimeTypes`), fixed TS template (#531). - `twilio-run`: fixed `require`->`import` conversion. Requires a clean install (removing node_modules and lockfile) after merging.
1 parent 50eae0a commit 6c26ece

File tree

8 files changed

+29
-19
lines changed

8 files changed

+29
-19
lines changed

Diff for: package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@changesets/cli": "^2.26.0",
2727
"@commitlint/cli": "^19.1.0",
2828
"@commitlint/config-conventional": "^19.1.0",
29-
"@twilio/test-dep": "npm:twilio@4.22.0",
29+
"@twilio/test-dep": "npm:twilio@5.2.2",
3030
"@types/jest": "^29.2.4",
3131
"all-contributors-cli": "^6.1.2",
3232
"commitizen": "^4.2.4",
@@ -45,6 +45,9 @@
4545
"typedoc": "^0.27.4",
4646
"typescript": "^5.3.3"
4747
},
48+
"peerDependencies": {
49+
"twilio": "^5.5.2"
50+
},
4851
"lint-staged": {
4952
"*.{js,jsx,ts,tsx}": [
5053
"prettier --write",
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const pkgJson = require('../../package.json');
22

33
module.exports = {
4-
twilio: '5.0.3',
4+
twilio: '5.5.2',
55
twilioRuntimeHandler: pkgJson.devDependencies[
66
'@twilio/runtime-handler'
77
].replace(/[\^~]/, ''),
88
twilioRun: pkgJson.dependencies['twilio-run'],
99
node: '18',
10-
typescript: '^5.3.3',
11-
serverlessRuntimeTypes: '^4.0.0',
10+
typescript: '^5.8.0',
11+
serverlessRuntimeTypes: '^4.0.1',
1212
copyfiles: '^2.4.1',
1313
};

Diff for: packages/runtime-handler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"nocache": "^2.1.0",
7171
"normalize.css": "^8.0.1",
7272
"serialize-error": "^7.0.1",
73-
"twilio": "4.23.0"
73+
"twilio": "5.5.2"
7474
},
7575
"gitHead": "6db273648ed19474f4125042556b10c051529912"
7676
}

Diff for: packages/serverless-runtime-types/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
},
3030
"dependencies": {
3131
"@types/express": "^4.17.21",
32-
"@types/qs": "^6.9.4",
33-
"twilio": "^4.23.0"
32+
"@types/qs": "^6.9.4"
3433
},
34+
"peerDependencies": {
35+
"twilio": "^5.5.2"
36+
},
3537
"devDependencies": {
3638
"all-contributors-cli": "^6.7.0",
37-
"typescript": "^5.3.3"
39+
"typescript": "^5.8.0"
3840
},
3941
"publishConfig": {
4042
"access": "public"

Diff for: packages/serverless-runtime-types/types.d.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import RequestClient from '@twilio/test-dep/lib/base/RequestClient';
2+
import { Request } from '@twilio/test-dep/lib/webhooks/webhooks';
13
import * as twilio from 'twilio';
24
import { ServiceContext } from 'twilio/lib/rest/sync/v1/service';
35
import { SyncListListInstance } from 'twilio/lib/rest/sync/v1/service/syncList';
46
import { SyncMapListInstance } from 'twilio/lib/rest/sync/v1/service/syncMap';
5-
import { TwilioClientOptions } from 'twilio/lib/rest/Twilio';
7+
import { ClientOpts } from 'twilio';
68

79
export type EnvironmentVariables = {
810
[key: string]: string | undefined;
@@ -187,7 +189,7 @@ export interface TwilioResponse {
187189
removeCookie(key: string): TwilioResponse;
188190
}
189191

190-
export type RuntimeSyncClientOptions = TwilioClientOptions & {
192+
export type RuntimeSyncClientOptions = ClientOpts & {
191193
serviceName?: string;
192194
};
193195

@@ -360,7 +362,7 @@ export type Context<T = {}> = {
360362
* };
361363
* ```
362364
*/
363-
getTwilioClient(options?: TwilioClientOptions): twilio.Twilio;
365+
getTwilioClient(options?: ClientOpts): twilio.Twilio;
364366
/**
365367
* The domain name for the Service that contains this Function.
366368
*/
@@ -412,6 +414,7 @@ export type GlobalTwilio = Omit<typeof twilio, 'default'> & {
412414
export { ServiceContext } from 'twilio/lib/rest/sync/v1/service';
413415
export { SyncListListInstance } from 'twilio/lib/rest/sync/v1/service/syncList';
414416
export { SyncMapListInstance } from 'twilio/lib/rest/sync/v1/service/syncMap';
415-
export { TwilioClientOptions } from 'twilio/lib/rest/Twilio';
417+
export { ClientOpts as TwilioClientOptions } from 'twilio/lib/rest/Twilio';
418+
416419
export type TwilioClient = twilio.Twilio;
417420
export type TwilioPackage = typeof twilio;

Diff for: packages/twilio-run/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@
7676
"serialize-error": "^7.0.1",
7777
"terminal-link": "^1.3.0",
7878
"title": "^3.4.1",
79-
"twilio": "^4.23.0",
8079
"type-fest": "^0.15.1",
8180
"window-size": "^1.1.1",
8281
"wrap-ansi": "^7.0.0",
8382
"yargs": "^17.2.1"
8483
},
84+
"peerDependencies": {
85+
"twilio": "^5.5.2"
86+
},
8587
"optionalDependencies": {
8688
"ngrok": "^3.3.0"
8789
},
@@ -113,7 +115,7 @@
113115
"nock": "^12.0.2",
114116
"supertest": "^3.1.0",
115117
"typescript": "^4.9.4",
116-
"@twilio/test-dep": "npm:twilio@4.22.0"
118+
"@twilio/test-dep": "npm:twilio@5.5.2"
117119
},
118120
"files": [
119121
"bin/",

Diff for: packages/twilio-run/src/runtime/internal/runtime.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getDebugFunction } from '../../utils/logger';
1616

1717
const debug = getDebugFunction('twilio-run:runtime');
1818

19-
const { getCachedResources } = require('./route-cache');
19+
import { getCachedResources } from './route-cache';
2020

2121
function getAssets(): AssetResourceMap {
2222
const { assets } = getCachedResources();
@@ -72,9 +72,9 @@ export function create({ env }: StartCliConfig): RuntimeInstance {
7272
.join(',')})`,
7373
});
7474
const client = twilio(env.ACCOUNT_SID, env.AUTH_TOKEN, options);
75-
const service = (client.sync.v1.services(
75+
const service = client.sync.v1.services(
7676
serviceName || 'default'
77-
) as unknown) as RuntimeSyncServiceContext;
77+
) as unknown as RuntimeSyncServiceContext;
7878

7979
service.maps = service.syncMaps;
8080
service.lists = service.syncLists;

Diff for: packages/twilio-run/src/runtime/route.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ServerlessEventObject,
55
ServerlessFunctionSignature,
66
} from '@twilio-labs/serverless-runtime-types/types';
7+
78
import { fork } from 'child_process';
89
import {
910
NextFunction,
@@ -23,7 +24,6 @@ import { cleanUpStackTrace } from '../utils/stack-trace/clean-up';
2324
import { Reply } from './internal/functionRunner';
2425
import { Response } from './internal/response';
2526
import * as Runtime from './internal/runtime';
26-
import * as PATH from 'path';
2727

2828
const RUNNER_PATH =
2929
process.env.NODE_ENV === 'test'
@@ -40,7 +40,7 @@ export function constructEvent<T extends ServerlessEventObject>(
4040
return { ...req.query, ...req.body };
4141
}
4242

43-
export function constructContext<T extends {} = {}>(
43+
export function constructContext(
4444
{ url, env }: StartCliConfig,
4545
functionPath: string
4646
): Context<{

0 commit comments

Comments
 (0)