@devvit/build-pack 0.11.19-next-2025-07-02-19-55-03-bc5010226.0 → 0.11.19-next-2025-07-03-19-32-19-0edd6138a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esbuild/ESBuildPack.d.ts.map +1 -1
- package/esbuild/ESBuildPack.js +4 -2
- package/esbuild/templatizer/blocks.template.d.ts +9 -2
- package/esbuild/templatizer/blocks.template.d.ts.map +1 -1
- package/esbuild/templatizer/blocks.template.js +262 -5
- package/esbuild/templatizer/blocks.template.test.d.ts.map +1 -0
- package/package.json +11 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ESBuildPack.d.ts","sourceRoot":"","sources":["../../src/esbuild/ESBuildPack.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kEAAkE,CAAC;AAC1F,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,+CAA+C,CAAC;AAGvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAIjG,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;AAI5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAc1D,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,cAAc,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,EAAE,UAAU,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAA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AAE,SAAS,EACpB,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC;IA2BxC,aAAa,IAAI,UAAU,CAAC,eAAe,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAgH/B;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1D,CAAC;AAEF,qBAAa,WAAW;;IAWtB;;;OAGG;gBACS,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC;IAK5E,OAAO,CAAC,EACZ,MAAM,EACN,MAAM,EACN,IAAI,EACJ,eAAe,EACf,IAAI,GACL,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;IA2DrC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,aAAa,GAAG,UAAU,CAAC,eAAe,CAAC;CAkB1E;AAqSD,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED,sDAAsD;AACtD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,SAAS,GAC5C,IAAI,CAKN;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAMrF"}
|
package/esbuild/ESBuildPack.js
CHANGED
|
@@ -359,8 +359,10 @@ function esbuildConfig(config, disableExternDevvitProtos, targetRuntime, watchMo
|
|
|
359
359
|
alias: config?.blocks ? { '@devvit/public-api': '@devvit/public-api' } : {},
|
|
360
360
|
// Recursively inline any imported dependencies.
|
|
361
361
|
bundle: true,
|
|
362
|
-
// Tightly coupled to blocks.template.
|
|
363
|
-
define: {
|
|
362
|
+
// Tightly coupled to blocks.template.tsx.
|
|
363
|
+
define: {
|
|
364
|
+
'globalThis.__devvit__': config ? JSON.stringify({ config }, undefined, 2) : 'undefined',
|
|
365
|
+
},
|
|
364
366
|
external: [
|
|
365
367
|
'node:*',
|
|
366
368
|
// All .js files from https://github.com/nodejs/node/tree/b2405e9/lib that
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Devvit, type FormKey } from '@devvit/public-api';
|
|
2
|
+
import type { UiResponse } from '@devvit/shared/types/ui-response.js';
|
|
3
|
+
/** @internal [state] Map of devvit.json form keys to Devvit-singleton form keys. */
|
|
4
|
+
export declare const formKeyMap: {
|
|
5
|
+
[formKey: string]: FormKey;
|
|
6
|
+
};
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare function validateUiResponse(uiResponse: UiResponse): void;
|
|
9
|
+
export default Devvit;
|
|
3
10
|
//# sourceMappingURL=blocks.template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.template.d.ts","sourceRoot":"","sources":["../../../src/esbuild/templatizer/blocks.template.
|
|
1
|
+
{"version":3,"file":"blocks.template.d.ts","sourceRoot":"","sources":["../../../src/esbuild/templatizer/blocks.template.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,MAAM,EACN,KAAK,OAAO,EAMb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAgBtE,oFAAoF;AACpF,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAO,CAAC;AAqG7D,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CA4D/D;AAsJD,eAAe,MAAM,CAAC"}
|
|
@@ -1,6 +1,263 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { Devvit, useWebView, } from '@devvit/public-api';
|
|
2
|
+
import { getServerPort } from '@devvit/server';
|
|
3
|
+
// __devvit__ is undefined in tests only.
|
|
3
4
|
// @ts-expect-error no type.
|
|
4
|
-
|
|
5
|
-
/** @
|
|
6
|
-
export
|
|
5
|
+
const config = globalThis.__devvit__?.config;
|
|
6
|
+
/** @internal [state] Map of devvit.json form keys to Devvit-singleton form keys. */
|
|
7
|
+
export const formKeyMap = {};
|
|
8
|
+
function configurePermissions(permissions) {
|
|
9
|
+
// to-do: remove. This is a relic of LinkedBundle generation.
|
|
10
|
+
Devvit.configure({
|
|
11
|
+
http: {
|
|
12
|
+
enabled: permissions.http.enable,
|
|
13
|
+
domains: permissions.http.domains,
|
|
14
|
+
},
|
|
15
|
+
media: permissions.media,
|
|
16
|
+
// to-do: payments permissions.
|
|
17
|
+
realtime: permissions.realtime,
|
|
18
|
+
redditAPI: permissions.reddit.enable,
|
|
19
|
+
modLog: permissions.reddit.scope === 'moderator',
|
|
20
|
+
// to-do: configure userActions with API granularity.
|
|
21
|
+
userActions: !!permissions.reddit.asUser.length,
|
|
22
|
+
redis: permissions.redis,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function configurePost(post) {
|
|
26
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
27
|
+
const path = post.client.entry.replace(new RegExp(`^${post.client.dir}/?`), '');
|
|
28
|
+
Devvit.addCustomPostType({
|
|
29
|
+
name: post.create.title,
|
|
30
|
+
render: () => renderModal(path),
|
|
31
|
+
height: post.create.height,
|
|
32
|
+
});
|
|
33
|
+
if (post.create.menu.enable) {
|
|
34
|
+
Devvit.addMenuItem({
|
|
35
|
+
forUserType: post.create.menu.scope === 'moderator' ? 'moderator' : 'loggedOut',
|
|
36
|
+
label: post.create.menu.label,
|
|
37
|
+
location: 'subreddit',
|
|
38
|
+
async onPress(_ev, ctx) {
|
|
39
|
+
const newPost = await createPost(ctx, post.create);
|
|
40
|
+
ctx.ui.showToast({
|
|
41
|
+
text: `Created post "${newPost.title}" in ${ctx.subredditName}. Navigating to it now.`,
|
|
42
|
+
appearance: 'success',
|
|
43
|
+
});
|
|
44
|
+
ctx.ui.navigateTo(newPost);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (post.create.onInstall)
|
|
49
|
+
Devvit.addTrigger({
|
|
50
|
+
event: 'AppInstall',
|
|
51
|
+
async onEvent(_ev, ctx) {
|
|
52
|
+
await createPost(ctx, post.create);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function configureMenuActions(menuActions) {
|
|
57
|
+
for (const action of menuActions) {
|
|
58
|
+
const menuItem = {
|
|
59
|
+
label: action.label,
|
|
60
|
+
location: action.location,
|
|
61
|
+
onPress: async (ev, ctx) => {
|
|
62
|
+
const responseJson = await callWebbitEndpoint(action.endpoint, ev, ctx.debug.metadata);
|
|
63
|
+
const uiResponse = responseJson;
|
|
64
|
+
validateUiResponse(uiResponse);
|
|
65
|
+
await handleUiResponse(ctx, uiResponse);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
// "user" type is blank in Devvit classic. So if it's present in
|
|
69
|
+
// devvit.json, we add an extra menu item without forUserType set.
|
|
70
|
+
// "moderator" maps across as expected.
|
|
71
|
+
// "loggedOut" type (Devvit classic) we no longer support
|
|
72
|
+
if (action.forUserType === 'moderator')
|
|
73
|
+
menuItem.forUserType = 'moderator';
|
|
74
|
+
if (action.postFilter === 'currentApp')
|
|
75
|
+
menuItem.postFilter = action.postFilter;
|
|
76
|
+
if (action.description)
|
|
77
|
+
menuItem.description = action.description;
|
|
78
|
+
Devvit.addMenuItem(menuItem);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function configureForms(forms) {
|
|
82
|
+
for (const [name, endpoint] of Object.entries(forms)) {
|
|
83
|
+
formKeyMap[name] = Devvit.createForm({ fields: [] }, (ev, ctx) => handleFormResponse(endpoint, ev, ctx));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function handleFormResponse(endpoint, event, ctx) {
|
|
87
|
+
const responseJson = await callWebbitEndpoint(endpoint, event.values, ctx.debug.metadata);
|
|
88
|
+
const uiResponse = responseJson;
|
|
89
|
+
validateUiResponse(uiResponse);
|
|
90
|
+
await handleUiResponse(ctx, uiResponse);
|
|
91
|
+
}
|
|
92
|
+
// TODO: expand this to fully validate the UiResponse format, including Form definitions,
|
|
93
|
+
// and convert signature to validateUiResponse(uiResponse: JSONValue): uiResponse is UiResponse
|
|
94
|
+
/** @internal */
|
|
95
|
+
export function validateUiResponse(uiResponse) {
|
|
96
|
+
// Validations:
|
|
97
|
+
// (1) The only valid fields on uiResponse are showToast, navigateTo, and showForm.
|
|
98
|
+
const validKeys = ['showToast', 'navigateTo', 'showForm'];
|
|
99
|
+
const invalidKeys = Object.keys(uiResponse).filter((key) => !validKeys.includes(key));
|
|
100
|
+
if (invalidKeys.length > 0) {
|
|
101
|
+
throw new Error(`Invalid fields found in UiResponse: ${invalidKeys.join(', ')}. Valid fields are: ${validKeys.join(', ')}`);
|
|
102
|
+
}
|
|
103
|
+
// (2) showForm must have a name that exists in the formKeyMap.
|
|
104
|
+
if (uiResponse.showForm) {
|
|
105
|
+
if (!uiResponse.showForm.name) {
|
|
106
|
+
throw new Error('showForm must have a name');
|
|
107
|
+
}
|
|
108
|
+
if (!formKeyMap[uiResponse.showForm.name]) {
|
|
109
|
+
throw new Error(`Form with name ${uiResponse.showForm.name} not found in devvit.json. Consider adding '"forms"."${uiResponse.showForm.name}"="/internal/your/endpoint"'.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// (3) showToast must be a string or an object with only fields [text, appearance]
|
|
113
|
+
// and text is a mandatory string.
|
|
114
|
+
if (uiResponse.showToast !== undefined) {
|
|
115
|
+
if (typeof uiResponse.showToast === 'string') {
|
|
116
|
+
// Valid case: showToast is a string
|
|
117
|
+
}
|
|
118
|
+
else if (typeof uiResponse.showToast === 'object' && uiResponse.showToast !== null) {
|
|
119
|
+
// Check if it's an object with valid fields
|
|
120
|
+
const toastKeys = Object.keys(uiResponse.showToast);
|
|
121
|
+
const validToastKeys = ['text', 'appearance'];
|
|
122
|
+
const invalidToastKeys = toastKeys.filter((key) => !validToastKeys.includes(key));
|
|
123
|
+
if (invalidToastKeys.length > 0) {
|
|
124
|
+
throw new Error(`Invalid fields found in showToast: ${invalidToastKeys.join(', ')}. Valid fields are: ${validToastKeys.join(', ')}`);
|
|
125
|
+
}
|
|
126
|
+
if (typeof uiResponse.showToast.text !== 'string') {
|
|
127
|
+
throw new Error('showToast.text is required and must be a string');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
throw new Error('showToast must be a string or an object with text and optional appearance fields');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// (4) navigateTo must be a valid URL or a Post object. (this is validated client-side, so
|
|
135
|
+
// we don't need to validate it here).
|
|
136
|
+
// (5) navigateTo and showForm are mutually exclusive.
|
|
137
|
+
if (uiResponse.navigateTo && uiResponse.showForm) {
|
|
138
|
+
throw new Error('navigateTo and showForm cannot be used together in UiResponse');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Handle a UiResponse from a Webbit handler (menu action or form handler).
|
|
143
|
+
* This is used to create client-side UI effects in Reddit clients as responses
|
|
144
|
+
* to user actions in cases where the Devvit app is not in the direct code path.
|
|
145
|
+
*
|
|
146
|
+
* If multiple effects are present in the UiResponse, they will all be applied.
|
|
147
|
+
*/
|
|
148
|
+
async function handleUiResponse(ctx, uiResponse) {
|
|
149
|
+
if (uiResponse.showToast) {
|
|
150
|
+
ctx.ui.showToast(uiResponse.showToast);
|
|
151
|
+
}
|
|
152
|
+
if (uiResponse.navigateTo) {
|
|
153
|
+
ctx.ui.navigateTo(uiResponse.navigateTo);
|
|
154
|
+
}
|
|
155
|
+
if (uiResponse.showForm) {
|
|
156
|
+
ctx.ui.showFormInternal(formKeyMap[uiResponse.showForm.name], uiResponse.showForm.data, uiResponse.showForm.form);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function callWebbitEndpoint(endpoint, body, metadata) {
|
|
160
|
+
const url = new URL(endpoint, `http://webbit.local:${getServerPort()}/`);
|
|
161
|
+
const headers = {};
|
|
162
|
+
Object.entries(metadata).forEach(([key, metadata]) => {
|
|
163
|
+
headers[key] = metadata.values[0];
|
|
164
|
+
});
|
|
165
|
+
headers['Content-Type'] = 'application/json';
|
|
166
|
+
headers['Accept'] = 'application/json';
|
|
167
|
+
const response = await fetch(url, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
body: JSON.stringify(body),
|
|
170
|
+
headers,
|
|
171
|
+
});
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
const body = await response.text();
|
|
174
|
+
let errorMessage = `Failed to POST ${endpoint}: ${response.statusText}, `;
|
|
175
|
+
if (response.status === 404) {
|
|
176
|
+
errorMessage += `ensure that you're handling this endpoint in your server code.`;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
errorMessage += `body: ${body.substring(0, 100)}`;
|
|
180
|
+
}
|
|
181
|
+
throw new Error(errorMessage);
|
|
182
|
+
}
|
|
183
|
+
const contentType = response.headers.get('Content-Type');
|
|
184
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
185
|
+
throw new Error(`Failed to POST ${endpoint}: expected response type 'application/json', received '${contentType}'`);
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
return await response.json();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new Error(`Failed to POST ${endpoint}: ${error}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function configureScheduler(schedulerConfig) {
|
|
195
|
+
const cronTasks = {};
|
|
196
|
+
for (const [name, task] of Object.entries(schedulerConfig.tasks)) {
|
|
197
|
+
Devvit.addSchedulerJob({
|
|
198
|
+
name: name,
|
|
199
|
+
onRun: async (event, context) => {
|
|
200
|
+
await callWebbitEndpoint(task.endpoint, {
|
|
201
|
+
name: event.name,
|
|
202
|
+
data: event.data ?? null, // JSONObject wants null not undefined
|
|
203
|
+
}, context.debug.metadata);
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
// Tasks with cron specified require a bit more work further down
|
|
207
|
+
if (task.cron) {
|
|
208
|
+
cronTasks[name] = task;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// If provided, schedule any cron tasks the user asked for on install/upgrade, being careful to
|
|
212
|
+
// un-schedule any previously scheduled instances of these tasks
|
|
213
|
+
if (Object.keys(cronTasks).length > 0) {
|
|
214
|
+
Devvit.addTrigger({
|
|
215
|
+
events: ['AppInstall', 'AppUpgrade'],
|
|
216
|
+
onEvent: async (_event, context) => {
|
|
217
|
+
// Get all jobs
|
|
218
|
+
const existingJobs = await context.scheduler.listJobs();
|
|
219
|
+
// Filter down to just cron jobs
|
|
220
|
+
const jobsToCancel = existingJobs.filter((job) => {
|
|
221
|
+
// Only cancel cron jobs
|
|
222
|
+
return 'cron' in job;
|
|
223
|
+
});
|
|
224
|
+
// Cancel everything we need to
|
|
225
|
+
await Promise.all(jobsToCancel.map((job) => context.scheduler.cancelJob(job.id)));
|
|
226
|
+
// Schedule all the cron tasks we were given in the config
|
|
227
|
+
await Promise.all(Object.entries(cronTasks).map(async ([name, task]) => {
|
|
228
|
+
await context.scheduler.runJob({
|
|
229
|
+
name: name,
|
|
230
|
+
cron: task.cron,
|
|
231
|
+
});
|
|
232
|
+
}));
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function createPost(ctx, create) {
|
|
238
|
+
if (!ctx.subredditName)
|
|
239
|
+
throw Error('no sub name');
|
|
240
|
+
return await ctx.reddit.submitPost({
|
|
241
|
+
preview: Devvit.createElement("text", null, "Loading\u2026"),
|
|
242
|
+
subredditName: ctx.subredditName,
|
|
243
|
+
title: create.title,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function renderModal(path) {
|
|
247
|
+
const webView = useWebView({ url: path, onMessage() { } });
|
|
248
|
+
return (Devvit.createElement("vstack", { alignment: "center middle", height: "100%" },
|
|
249
|
+
Devvit.createElement("button", { onPress: webView.mount }, "Launch App"),
|
|
250
|
+
";"));
|
|
251
|
+
}
|
|
252
|
+
if (config) {
|
|
253
|
+
configurePermissions(config.permissions);
|
|
254
|
+
if (config.post)
|
|
255
|
+
configurePost(config.post);
|
|
256
|
+
if (config.menuActions)
|
|
257
|
+
configureMenuActions(config.menuActions);
|
|
258
|
+
if (config.scheduler)
|
|
259
|
+
configureScheduler(config.scheduler);
|
|
260
|
+
if (config.forms)
|
|
261
|
+
configureForms(config.forms);
|
|
262
|
+
}
|
|
263
|
+
export default Devvit;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.template.test.d.ts","sourceRoot":"","sources":["../../../src/esbuild/templatizer/blocks.template.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/build-pack",
|
|
3
|
-
"version": "0.11.19-next-2025-07-
|
|
3
|
+
"version": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,21 +23,23 @@
|
|
|
23
23
|
},
|
|
24
24
|
"types": "./index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@devvit/protos": "0.11.19-next-2025-07-
|
|
27
|
-
"@devvit/shared-types": "0.11.19-next-2025-07-
|
|
26
|
+
"@devvit/protos": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
27
|
+
"@devvit/shared-types": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
28
28
|
"esbuild": "0.23.0",
|
|
29
29
|
"rxjs": "7.8.1",
|
|
30
30
|
"tsv": "0.2.0",
|
|
31
31
|
"typescript": "5.8.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@devvit/server": "*"
|
|
34
|
+
"@devvit/server": "*",
|
|
35
|
+
"@devvit/shared": "*"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@devvit/public-api": "0.11.19-next-2025-07-
|
|
38
|
-
"@devvit/repo-tools": "0.11.19-next-2025-07-
|
|
39
|
-
"@devvit/server": "0.11.19-next-2025-07-
|
|
40
|
-
"@devvit/
|
|
38
|
+
"@devvit/public-api": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
39
|
+
"@devvit/repo-tools": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
40
|
+
"@devvit/server": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
41
|
+
"@devvit/shared": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
42
|
+
"@devvit/tsconfig": "0.11.19-next-2025-07-03-19-32-19-0edd6138a.0",
|
|
41
43
|
"@types/tsv": "0.2.1",
|
|
42
44
|
"eslint": "9.11.1",
|
|
43
45
|
"vitest": "1.6.1"
|
|
@@ -46,5 +48,5 @@
|
|
|
46
48
|
"directory": "dist"
|
|
47
49
|
},
|
|
48
50
|
"source": "./src/index.ts",
|
|
49
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "279c870c8e14bd96edb60db754adb7b733ea871f"
|
|
50
52
|
}
|