@devvit/build-pack 0.11.1-next-2024-10-21-dbc4313a2.0 → 0.11.1
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Metadata } from '@devvit/protos';
|
|
2
2
|
import { type CompileParams, CompileResponse } from '@devvit/protos/types/devvit/plugin/buildpack/buildpack_common.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { ActorSpec } from '@devvit/protos/types/devvit/runtime/bundle.js';
|
|
4
4
|
import type { Namespace } from '@devvit/shared-types/Namespace.js';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
import type { BuildPack, ProjectRootDir } from '../lib/BuildPack.js';
|
|
@@ -21,7 +21,6 @@ type ESBuildPackOptions = {
|
|
|
21
21
|
readonly typeChecker?: TypeChecker | undefined;
|
|
22
22
|
/** @deprecated use the type checker where possible. */
|
|
23
23
|
readonly disableTypeCheckerWarning?: boolean | undefined;
|
|
24
|
-
readonly targetRuntimes?: TargetRuntime[] | undefined;
|
|
25
24
|
};
|
|
26
25
|
export declare class ESBuildPack implements BuildPack {
|
|
27
26
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ESBuildPack.d.ts","sourceRoot":"","sources":["../../src/esbuild/ESBuildPack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ESBuildPack.d.ts","sourceRoot":"","sources":["../../src/esbuild/ESBuildPack.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAEL,KAAK,aAAa,EAClB,eAAe,EAEhB,MAAM,kEAAkE,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,+CAA+C,CAAC;AAG/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAKnE,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;AAI5D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAS5D,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEhD,qBAAa,OAAO;;IAqBlB;;;OAGG;gBAED,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,EAC9B,IAAI,EAAE,cAAc,EACpB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC;IAuBpC,aAAa,IAAI,UAAU,CAAC,eAAe,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA2E/B;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/C,uDAAuD;IACvD,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1D,CAAC;AAEF,qBAAa,WAAY,YAAW,SAAS;;IAiB3C;;;OAGG;gBACS,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC;IAO5E,OAAO,CACX,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,aAAa,EACzC,SAAS,EAAE,QAAQ,GAAG,SAAS,GAC9B,OAAO,CAAC,eAAe,CAAC;IAoDrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,KAAK,CACH,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,aAAa,EACjC,SAAS,EAAE,QAAQ,GAAG,SAAS,GAC9B,UAAU,CAAC,eAAe,CAAC;CAe/B"}
|
package/esbuild/ESBuildPack.js
CHANGED
|
@@ -9,12 +9,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Watcher_instances, _Watcher_disableExternDevvitProtos, _Watcher_typeChecker,
|
|
13
|
-
import crypto from 'node:crypto';
|
|
12
|
+
var _Watcher_instances, _Watcher_disableExternDevvitProtos, _Watcher_typeChecker, _Watcher_root, _Watcher_observable, _Watcher_disposedNotifier, _Watcher_disposeWatcher, _Watcher_namespace, _Watcher_init, _Watcher_onBuildEnd, _ESBuildPack_bundleWatchers, _ESBuildPack_namespace, _ESBuildPack_disableExternDevvitProtos, _ESBuildPack_typeChecker, _ESBuildPack_disableTypeCheckerWarning;
|
|
14
13
|
import fs from 'node:fs';
|
|
15
|
-
import {
|
|
16
|
-
import { TargetRuntime, } from '@devvit/protos/types/devvit/runtime/bundle.js';
|
|
17
|
-
import { CircuitBreak } from '@devvit/shared-types/CircuitBreaker.js';
|
|
14
|
+
import { CompileLog, CompileResponse, Minify, } from '@devvit/protos/types/devvit/plugin/buildpack/buildpack_common.js';
|
|
18
15
|
import { ConfigImpl as Config } from '@devvit/shared-types/ConfigImpl.js';
|
|
19
16
|
import { assertNonNull, NonNull } from '@devvit/shared-types/NonNull.js';
|
|
20
17
|
import { StringUtil } from '@devvit/shared-types/StringUtil.js';
|
|
@@ -31,7 +28,6 @@ const FAKE_FACTORY = {
|
|
|
31
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
29
|
Build() { },
|
|
33
30
|
};
|
|
34
|
-
const BUILD_TARGETS = [TargetRuntime.UNIVERSAL, TargetRuntime.CLIENT];
|
|
35
31
|
export class Watcher {
|
|
36
32
|
/**
|
|
37
33
|
* The default behavior is to externalize @devvit/protos. Set
|
|
@@ -41,7 +37,6 @@ export class Watcher {
|
|
|
41
37
|
_Watcher_instances.add(this);
|
|
42
38
|
_Watcher_disableExternDevvitProtos.set(this, void 0);
|
|
43
39
|
_Watcher_typeChecker.set(this, void 0);
|
|
44
|
-
_Watcher_targetRuntimes.set(this, void 0);
|
|
45
40
|
_Watcher_root.set(this, void 0);
|
|
46
41
|
/**
|
|
47
42
|
* the actual emitter of updates
|
|
@@ -56,13 +51,10 @@ export class Watcher {
|
|
|
56
51
|
*/
|
|
57
52
|
_Watcher_disposeWatcher.set(this, void 0);
|
|
58
53
|
_Watcher_namespace.set(this, void 0);
|
|
59
|
-
_Watcher_buildTargets.set(this, new Map());
|
|
60
|
-
_Watcher_ready.set(this, void 0);
|
|
61
54
|
__classPrivateFieldSet(this, _Watcher_namespace, namespace, "f");
|
|
62
55
|
__classPrivateFieldSet(this, _Watcher_root, root, "f");
|
|
63
56
|
__classPrivateFieldSet(this, _Watcher_disableExternDevvitProtos, options?.disableExternDevvitProtos ?? false, "f");
|
|
64
57
|
__classPrivateFieldSet(this, _Watcher_typeChecker, options?.typeChecker, "f");
|
|
65
|
-
__classPrivateFieldSet(this, _Watcher_targetRuntimes, options?.targetRuntimes ?? BUILD_TARGETS, "f");
|
|
66
58
|
// observers of this will be subscribed until this.disposedNotifier emits a value
|
|
67
59
|
const sourceObservable = new Observable().pipe(takeUntil(__classPrivateFieldGet(this, _Watcher_disposedNotifier, "f")));
|
|
68
60
|
// our observable is a BehaviorSubject used to multicast the source observer
|
|
@@ -70,7 +62,7 @@ export class Watcher {
|
|
|
70
62
|
// multi-casts (shares) here
|
|
71
63
|
sourceObservable.subscribe(__classPrivateFieldGet(this, _Watcher_observable, "f"));
|
|
72
64
|
// #init handles errors.
|
|
73
|
-
|
|
65
|
+
void __classPrivateFieldGet(this, _Watcher_instances, "m", _Watcher_init).call(this, actorSpec);
|
|
74
66
|
}
|
|
75
67
|
getObservable() {
|
|
76
68
|
return __classPrivateFieldGet(this, _Watcher_observable, "f");
|
|
@@ -83,44 +75,22 @@ export class Watcher {
|
|
|
83
75
|
__classPrivateFieldGet(this, _Watcher_disposedNotifier, "f").complete();
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
|
-
_Watcher_disableExternDevvitProtos = new WeakMap(), _Watcher_typeChecker = new WeakMap(),
|
|
87
|
-
// Building for Universal and Client targets. May include Server in the future.
|
|
88
|
-
for (const target of __classPrivateFieldGet(this, _Watcher_targetRuntimes, "f")) {
|
|
89
|
-
__classPrivateFieldGet(this, _Watcher_buildTargets, "f").set(target, {
|
|
90
|
-
ctx: await __classPrivateFieldGet(this, _Watcher_instances, "m", _Watcher_makeEsbuildContext).call(this, actorSpec, target),
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
__classPrivateFieldSet(this, _Watcher_disposeWatcher, async () => {
|
|
94
|
-
for (const [_, target] of __classPrivateFieldGet(this, _Watcher_buildTargets, "f")) {
|
|
95
|
-
await target.ctx.dispose();
|
|
96
|
-
}
|
|
97
|
-
}, "f");
|
|
98
|
-
if (__classPrivateFieldGet(this, _Watcher_observable, "f").isStopped) {
|
|
99
|
-
// Disposed while await-ing and prior to setting disposeWatcher.
|
|
100
|
-
await __classPrivateFieldGet(this, _Watcher_disposeWatcher, "f").call(this);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const watchers = [];
|
|
104
|
-
for (const [_, target] of __classPrivateFieldGet(this, _Watcher_buildTargets, "f")) {
|
|
105
|
-
watchers.push(target.ctx.watch());
|
|
106
|
-
}
|
|
107
|
-
await Promise.all(watchers);
|
|
108
|
-
}, _Watcher_makeEsbuildContext = async function _Watcher_makeEsbuildContext(actorSpec, targetRuntime) {
|
|
78
|
+
_Watcher_disableExternDevvitProtos = new WeakMap(), _Watcher_typeChecker = new WeakMap(), _Watcher_root = new WeakMap(), _Watcher_observable = new WeakMap(), _Watcher_disposedNotifier = new WeakMap(), _Watcher_disposeWatcher = new WeakMap(), _Watcher_namespace = new WeakMap(), _Watcher_instances = new WeakSet(), _Watcher_init = async function _Watcher_init(actorSpec) {
|
|
109
79
|
const entryPoint = getModuleEntrypoint(__classPrivateFieldGet(this, _Watcher_root, "f"));
|
|
110
|
-
const cfg = esbuildConfig(__classPrivateFieldGet(this, _Watcher_disableExternDevvitProtos, "f")
|
|
111
|
-
|
|
80
|
+
const cfg = esbuildConfig(__classPrivateFieldGet(this, _Watcher_disableExternDevvitProtos, "f"));
|
|
81
|
+
const esbuildCtx = await esbuild.context({
|
|
112
82
|
...cfg,
|
|
113
83
|
entryPoints: [entryPoint],
|
|
114
84
|
minify: false,
|
|
115
|
-
sourcemap: 'external',
|
|
116
85
|
outfile: 'main.js',
|
|
86
|
+
sourcemap: 'external',
|
|
117
87
|
// esbuild now supports hooks through the onEnd callback in the build API.
|
|
118
88
|
plugins: [
|
|
119
89
|
{
|
|
120
90
|
name: 'optionally-type-check-and-publish-compile-result-on-build-end',
|
|
121
91
|
setup: (build) => {
|
|
122
92
|
build.onEnd(async (result) => {
|
|
123
|
-
await __classPrivateFieldGet(this, _Watcher_instances, "m", _Watcher_onBuildEnd).call(this, actorSpec, result, entryPoint
|
|
93
|
+
await __classPrivateFieldGet(this, _Watcher_instances, "m", _Watcher_onBuildEnd).call(this, actorSpec, result, entryPoint);
|
|
124
94
|
});
|
|
125
95
|
},
|
|
126
96
|
},
|
|
@@ -128,21 +98,21 @@ _Watcher_disableExternDevvitProtos = new WeakMap(), _Watcher_typeChecker = new W
|
|
|
128
98
|
...(cfg.plugins || []),
|
|
129
99
|
],
|
|
130
100
|
});
|
|
101
|
+
if (__classPrivateFieldGet(this, _Watcher_observable, "f").isStopped) {
|
|
102
|
+
// Disposed while await-ing and prior to setting disposeWatcher.
|
|
103
|
+
await esbuildCtx.dispose();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
__classPrivateFieldSet(this, _Watcher_disposeWatcher, async () => {
|
|
107
|
+
await esbuildCtx.dispose();
|
|
108
|
+
}, "f");
|
|
109
|
+
await esbuildCtx.watch();
|
|
131
110
|
}, _Watcher_onBuildEnd =
|
|
132
111
|
/**
|
|
133
112
|
* @description The callback function for esbuild's onEnd hook. This is called after esbuild has finished building.
|
|
134
113
|
*/
|
|
135
|
-
async function _Watcher_onBuildEnd(actorSpec, esbuildResult, entryPoint
|
|
136
|
-
await __classPrivateFieldGet(this,
|
|
137
|
-
__classPrivateFieldGet(this, _Watcher_buildTargets, "f").get(targetRuntime).result = esbuildResult;
|
|
138
|
-
const results = new Map();
|
|
139
|
-
// bail early if any builds are incomplete
|
|
140
|
-
for (const [targetRuntime, target] of __classPrivateFieldGet(this, _Watcher_buildTargets, "f")) {
|
|
141
|
-
if (!target.result)
|
|
142
|
-
return;
|
|
143
|
-
results.set(targetRuntime, target.result);
|
|
144
|
-
}
|
|
145
|
-
const esbuildCompileRes = await newCompileResponse(__classPrivateFieldGet(this, _Watcher_namespace, "f"), actorSpec, results, entryPoint);
|
|
114
|
+
async function _Watcher_onBuildEnd(actorSpec, esbuildResult, entryPoint) {
|
|
115
|
+
const esbuildCompileRes = await newCompileResponse(__classPrivateFieldGet(this, _Watcher_namespace, "f"), actorSpec, esbuildResult, entryPoint);
|
|
146
116
|
// to-do: why is type-checking disabled for projects with tsx files (nearly
|
|
147
117
|
// all projects).
|
|
148
118
|
if (!__classPrivateFieldGet(this, _Watcher_typeChecker, "f") || (await hasTsxFiles(__classPrivateFieldGet(this, _Watcher_root, "f")))) {
|
|
@@ -179,39 +149,35 @@ export class ESBuildPack {
|
|
|
179
149
|
__classPrivateFieldSet(this, _ESBuildPack_disableTypeCheckerWarning, options?.disableTypeCheckerWarning ?? false, "f");
|
|
180
150
|
}
|
|
181
151
|
async Compile({ filename, minify, info }, _metadata) {
|
|
182
|
-
// TODO: add flag to conditionally compile stripped bundle
|
|
183
152
|
if (filename == null) {
|
|
184
153
|
// TODO: implement virtualFileSystem
|
|
185
154
|
throw new Error('Bundling virtual file system not implemented yet');
|
|
186
155
|
}
|
|
187
156
|
assertNonNull(info, "Expected 'info' of CompileParams to be non-null");
|
|
188
157
|
const entrypoint = getModuleEntrypoint(filename);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const cfg = esbuildConfig(__classPrivateFieldGet(this, _ESBuildPack_disableExternDevvitProtos, "f")
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
? await newCompileResponse(__classPrivateFieldGet(this, _ESBuildPack_namespace, "f"), info, new Map([[targetRuntime, err]]), entrypoint)
|
|
209
|
-
: unknownToErrorCompileResponse('Compilation', err);
|
|
210
|
-
}
|
|
158
|
+
let bundleResult;
|
|
159
|
+
try {
|
|
160
|
+
const cfg = esbuildConfig(__classPrivateFieldGet(this, _ESBuildPack_disableExternDevvitProtos, "f"));
|
|
161
|
+
bundleResult = await esbuild.build({
|
|
162
|
+
...cfg,
|
|
163
|
+
entryPoints: [entrypoint],
|
|
164
|
+
metafile: true,
|
|
165
|
+
sourcemap: 'external',
|
|
166
|
+
outfile: 'main.js',
|
|
167
|
+
plugins: [excludeNodeModulesFromSourceMapsPlugin(), ...(cfg.plugins || [])],
|
|
168
|
+
sourcesContent: false,
|
|
169
|
+
minify: minify === Minify.ALL,
|
|
170
|
+
treeShaking: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
return isEsbuildResult(err)
|
|
175
|
+
? await newCompileResponse(__classPrivateFieldGet(this, _ESBuildPack_namespace, "f"), info, err, entrypoint)
|
|
176
|
+
: unknownToErrorCompileResponse('Compilation', err);
|
|
211
177
|
}
|
|
212
|
-
const esbuildCompileResult = await newCompileResponse(__classPrivateFieldGet(this, _ESBuildPack_namespace, "f"), info,
|
|
213
|
-
if (esbuildCompileResult.
|
|
214
|
-
throw new Error(esbuildCompileResult.errors?.[0]
|
|
178
|
+
const esbuildCompileResult = await newCompileResponse(__classPrivateFieldGet(this, _ESBuildPack_namespace, "f"), info, bundleResult, entrypoint);
|
|
179
|
+
if (esbuildCompileResult.bundle == null) {
|
|
180
|
+
throw new Error(esbuildCompileResult.errors?.[0].text ?? 'Missing bundle');
|
|
215
181
|
}
|
|
216
182
|
// to-do: why is type-checking disabled for projects with tsx files (nearly
|
|
217
183
|
// all projects).
|
|
@@ -243,77 +209,47 @@ export class ESBuildPack {
|
|
|
243
209
|
_ESBuildPack_bundleWatchers = new WeakMap(), _ESBuildPack_namespace = new WeakMap(), _ESBuildPack_disableExternDevvitProtos = new WeakMap(), _ESBuildPack_typeChecker = new WeakMap(), _ESBuildPack_disableTypeCheckerWarning = new WeakMap();
|
|
244
210
|
// TODO: Complete way to determine dependencies from module's config.ts or config.yaml. See DX-61
|
|
245
211
|
// TODO: Owner should come from project root's config file
|
|
246
|
-
async function newCompileResponse(namespace, actorSpec,
|
|
212
|
+
async function newCompileResponse(namespace, actorSpec, buildResult, entryPoint) {
|
|
213
|
+
prefixBuildResultLogs(buildResult, 'esbuild');
|
|
247
214
|
assertNonNull(actorSpec, 'Expected actorSpec to be non-null');
|
|
248
|
-
const errors =
|
|
249
|
-
const warnings =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
warnings.push(...buildResult.warnings.map(esbuildMessageToBuildLog));
|
|
257
|
-
let code = '';
|
|
258
|
-
let sourceMap = '';
|
|
259
|
-
for (const outputFile of buildResult.outputFiles || []) {
|
|
260
|
-
if (outputFile.path?.endsWith('.js')) {
|
|
261
|
-
if (code) {
|
|
262
|
-
throw new Error('There should only be one bundle after build');
|
|
263
|
-
}
|
|
264
|
-
code = outputFile.text;
|
|
265
|
-
}
|
|
266
|
-
else if (outputFile.path?.endsWith('.js.map')) {
|
|
267
|
-
sourceMap = outputFile.text;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
throw new Error('Unexpected output file: ' + outputFile.path);
|
|
215
|
+
const errors = buildResult.errors.map(esbuildMessageToBuildLog);
|
|
216
|
+
const warnings = buildResult.warnings.map(esbuildMessageToBuildLog);
|
|
217
|
+
let code = '';
|
|
218
|
+
let sourceMap = '';
|
|
219
|
+
for (const outputFile of buildResult.outputFiles || []) {
|
|
220
|
+
if (outputFile.path?.endsWith('.js')) {
|
|
221
|
+
if (code) {
|
|
222
|
+
throw new Error('There should only be one bundle after build');
|
|
271
223
|
}
|
|
224
|
+
code = outputFile.text;
|
|
272
225
|
}
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
const warnings = buildResult.warnings.map(esbuildMessageToBuildLog);
|
|
276
|
-
return CompileResponse.fromPartial({
|
|
277
|
-
errors,
|
|
278
|
-
warnings,
|
|
279
|
-
});
|
|
226
|
+
else if (outputFile.path?.endsWith('.js.map')) {
|
|
227
|
+
sourceMap = outputFile.text;
|
|
280
228
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const ActorClass = await dangerouslyGetBundleActor(code);
|
|
284
|
-
dependencies = await makeDependencySpec(namespace, actorSpec, ActorClass);
|
|
229
|
+
else {
|
|
230
|
+
throw new Error('Unexpected output file: ' + outputFile.path);
|
|
285
231
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
232
|
+
}
|
|
233
|
+
if (!code)
|
|
234
|
+
return CompileResponse.fromPartial({ errors, warnings });
|
|
235
|
+
let dependencies;
|
|
236
|
+
try {
|
|
237
|
+
const ActorClass = await dangerouslyGetBundleActor(code);
|
|
238
|
+
dependencies = await makeDependencySpec(namespace, actorSpec, ActorClass);
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
return unknownToErrorCompileResponse('Evaluation', err);
|
|
242
|
+
}
|
|
243
|
+
return CompileResponse.fromPartial({
|
|
244
|
+
bundle: {
|
|
290
245
|
code,
|
|
291
246
|
sourceMap,
|
|
292
247
|
dependencies,
|
|
293
248
|
buildInfo: {
|
|
294
249
|
created: new Date(),
|
|
295
250
|
dependencies: newBuildInfoDependencies(entryPoint),
|
|
296
|
-
targetRuntime,
|
|
297
251
|
},
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// remove duplicate bundles
|
|
301
|
-
const filteredBundles = [];
|
|
302
|
-
const bundleHashes = new Set();
|
|
303
|
-
bundles.forEach((bundle) => {
|
|
304
|
-
const algo = crypto.createHash('sha256');
|
|
305
|
-
algo.update(bundle.code);
|
|
306
|
-
const hash = algo.digest('hex');
|
|
307
|
-
if (!bundleHashes.has(hash)) {
|
|
308
|
-
bundleHashes.add(hash);
|
|
309
|
-
filteredBundles.push(bundle);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
if (filteredBundles.length === 1) {
|
|
313
|
-
filteredBundles[0].buildInfo.targetRuntime = TargetRuntime.UNIVERSAL;
|
|
314
|
-
}
|
|
315
|
-
return CompileResponse.fromPartial({
|
|
316
|
-
bundles: filteredBundles,
|
|
252
|
+
},
|
|
317
253
|
errors,
|
|
318
254
|
warnings,
|
|
319
255
|
});
|
|
@@ -354,16 +290,13 @@ function esbuildMessageToBuildLog(msg) {
|
|
|
354
290
|
function isEsbuildResult(err) {
|
|
355
291
|
return err instanceof Object && 'errors' in err && 'warnings' in err;
|
|
356
292
|
}
|
|
357
|
-
function esbuildConfig(disableExternDevvitProtos
|
|
293
|
+
function esbuildConfig(disableExternDevvitProtos) {
|
|
358
294
|
return {
|
|
359
295
|
// Recursively inline any imported dependencies.
|
|
360
296
|
bundle: true,
|
|
361
297
|
// Split the @devvit/protos from the LinkedBundle. This means apps assume
|
|
362
298
|
// @devvit/protos is available for import at execution time.
|
|
363
|
-
plugins: [
|
|
364
|
-
externalizeDevvitProtosPlugin(disableExternDevvitProtos),
|
|
365
|
-
...getTargetPlugins(targetRuntime),
|
|
366
|
-
],
|
|
299
|
+
plugins: [externalizeDevvitProtosPlugin(disableExternDevvitProtos)],
|
|
367
300
|
// to-do: uncomment once runtime is split aware and deployed everywhere.
|
|
368
301
|
// external: ['@devvit/protos'],
|
|
369
302
|
// Both format and target are intended to align to
|
|
@@ -407,38 +340,6 @@ function externalizeDevvitProtosPlugin(disableExternDevvitProtos) {
|
|
|
407
340
|
},
|
|
408
341
|
};
|
|
409
342
|
}
|
|
410
|
-
function getTargetPlugins(targetRuntime) {
|
|
411
|
-
if (targetRuntime === TargetRuntime.CLIENT) {
|
|
412
|
-
return clientBundlePlugins();
|
|
413
|
-
}
|
|
414
|
-
return [];
|
|
415
|
-
}
|
|
416
|
-
function clientBundlePlugins() {
|
|
417
|
-
return [
|
|
418
|
-
{
|
|
419
|
-
name: 'removeServerCode',
|
|
420
|
-
setup(build) {
|
|
421
|
-
build.onResolve({ filter: /(\/server\/)|(\.server\.(js|ts)x?$)/ }, () => {
|
|
422
|
-
return {
|
|
423
|
-
path: 'server-stub.js',
|
|
424
|
-
namespace: 'server-only',
|
|
425
|
-
};
|
|
426
|
-
});
|
|
427
|
-
build.onLoad({ filter: /.*/, namespace: 'server-only' }, async () => {
|
|
428
|
-
const contents = `
|
|
429
|
-
${CircuitBreak}
|
|
430
|
-
module.exports = new Proxy({}, {
|
|
431
|
-
has: () => true,
|
|
432
|
-
get: () => { throw CircuitBreak() },
|
|
433
|
-
apply: () => { throw CircuitBreak() },
|
|
434
|
-
});
|
|
435
|
-
`;
|
|
436
|
-
return { contents, loader: 'js' };
|
|
437
|
-
});
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
];
|
|
441
|
-
}
|
|
442
343
|
/**
|
|
443
344
|
* Plugin for excluding code from inclusion in the source map by filename. This helps keep bundle size manageable.
|
|
444
345
|
* @arg {RegExp} config.filter - A filter for what paths to exclude, if they match.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TscTypeChecker.d.ts","sourceRoot":"","sources":["../../../src/esbuild/type-checkers/TscTypeChecker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,kEAAkE,CAAC;AAC1E,OAAO,GAAG,MAAM,YAAY,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAqC/D;;;;GAIG;AACH,qBAAa,cAAe,YAAW,WAAW;IAC1C,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;CAehE;AAMD,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"TscTypeChecker.d.ts","sourceRoot":"","sources":["../../../src/esbuild/type-checkers/TscTypeChecker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,kEAAkE,CAAC;AAC1E,OAAO,GAAG,MAAM,YAAY,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAqC/D;;;;GAIG;AACH,qBAAa,cAAe,YAAW,WAAW;IAC1C,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;CAehE;AAMD,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,eAAe,CAyC/F"}
|
package/esbuild/utils.js
CHANGED
|
@@ -10,21 +10,21 @@ export function prefixBuildResultLogs(buildResult, prefix) {
|
|
|
10
10
|
}
|
|
11
11
|
export function mergeCompileRes(...compileRes) {
|
|
12
12
|
const mergedCompileRes = CompileResponse.fromPartial({});
|
|
13
|
-
let
|
|
13
|
+
let bundle = null;
|
|
14
14
|
for (const res of compileRes) {
|
|
15
|
-
if (res.
|
|
16
|
-
if (
|
|
17
|
-
throw new Error('Cannot merge two compile responses both with
|
|
15
|
+
if (res.bundle != null) {
|
|
16
|
+
if (bundle != null) {
|
|
17
|
+
throw new Error('Cannot merge two compile responses both with a bundle');
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
|
|
20
|
+
bundle = res.bundle;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
mergedCompileRes.errors.push(...res.errors);
|
|
24
24
|
mergedCompileRes.warnings.push(...res.warnings);
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
27
|
-
mergedCompileRes.
|
|
26
|
+
if (bundle != null) {
|
|
27
|
+
mergedCompileRes.bundle = bundle;
|
|
28
28
|
}
|
|
29
29
|
return mergedCompileRes;
|
|
30
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/build-pack",
|
|
3
|
-
"version": "0.11.1
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"types": "./index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@devvit/protos": "0.11.1
|
|
27
|
-
"@devvit/shared-types": "0.11.1
|
|
26
|
+
"@devvit/protos": "0.11.1",
|
|
27
|
+
"@devvit/shared-types": "0.11.1",
|
|
28
28
|
"esbuild": "0.23.0",
|
|
29
29
|
"rxjs": "7.8.1",
|
|
30
30
|
"tiny-glob": "0.2.9",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"typescript": "5.3.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@devvit/public-api": "0.11.1
|
|
36
|
-
"@devvit/repo-tools": "0.11.1
|
|
37
|
-
"@devvit/tsconfig": "0.11.1
|
|
35
|
+
"@devvit/public-api": "0.11.1",
|
|
36
|
+
"@devvit/repo-tools": "0.11.1",
|
|
37
|
+
"@devvit/tsconfig": "0.11.1",
|
|
38
38
|
"@types/tsv": "0.2.1",
|
|
39
39
|
"eslint": "9.11.1",
|
|
40
40
|
"typescript": "5.3.2",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"directory": "dist"
|
|
45
45
|
},
|
|
46
46
|
"source": "./src/index.ts",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "b7e0214655df6dcdd70c7944b9a14b0d752577ae"
|
|
48
48
|
}
|