@devvit/build-pack 0.12.0-next-2025-04-12-5721a9506.0 → 0.12.0-next-2025-04-28-276a82082.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/BundleModule.d.ts.map +1 -1
- package/esbuild/BundleModule.js +15 -1
- package/esbuild/ESBuildPack.js +53 -1
- package/esbuild/plugins/serverClientCodeSplit.d.ts.map +1 -1
- package/esbuild/plugins/serverClientCodeSplit.js +3 -19
- package/lib/BuildPack.d.ts.map +1 -1
- package/lib/BuildPack.js +29 -17
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleModule.d.ts","sourceRoot":"","sources":["../../src/esbuild/BundleModule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"BundleModule.d.ts","sourceRoot":"","sources":["../../src/esbuild/BundleModule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAqB7D;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUxF;AAyCD,cAAM,aAAc,SAAQ,KAAK;gBACnB,GAAG,EAAE,MAAM;CAGxB;AAED,2DAA2D;AAC3D,MAAM,MAAM,iBAAiB,GAAG,OAAO,aAAa,CAAC"}
|
package/esbuild/BundleModule.js
CHANGED
|
@@ -4,6 +4,20 @@ import { Actor } from '@devvit/shared-types/Actor.js';
|
|
|
4
4
|
// Define require for server builds which may have externalized dependencies.
|
|
5
5
|
// ESM does not define require but bundles are CJS and evaluated inline .
|
|
6
6
|
globalThis.require ??= createRequire(import.meta.url);
|
|
7
|
+
// because we evaluate the code to create the actor bundle webbit apps fail because they cannot
|
|
8
|
+
// open their HTTP port. This overrides http.createServer().listen(), so it's a no-op
|
|
9
|
+
const webbitBundlingHack = `
|
|
10
|
+
const http = require('http');
|
|
11
|
+
const createServer = http.createServer;
|
|
12
|
+
http.createServer = () => {
|
|
13
|
+
const srv = createServer();
|
|
14
|
+
srv.listen = () => {};
|
|
15
|
+
return srv;
|
|
16
|
+
};
|
|
17
|
+
`;
|
|
18
|
+
const webbitBundlingHackRevert = `
|
|
19
|
+
http.createServer = createServer;
|
|
20
|
+
`;
|
|
7
21
|
/**
|
|
8
22
|
* Dangerously executes untrusted code and returns the Actor class. An Error is
|
|
9
23
|
* thrown if the code does not adhere to the BundleModule interface.
|
|
@@ -39,7 +53,7 @@ async function dangerouslyGetBundleDefaultExport(code) {
|
|
|
39
53
|
// JS please forgive us
|
|
40
54
|
// TODO DX-63
|
|
41
55
|
// eslint-disable-next-line security/detect-eval-with-expression
|
|
42
|
-
eval(code);
|
|
56
|
+
eval(webbitBundlingHack + code + webbitBundlingHackRevert);
|
|
43
57
|
return module.exports?.default;
|
|
44
58
|
}
|
|
45
59
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/esbuild/ESBuildPack.js
CHANGED
|
@@ -372,7 +372,58 @@ function esbuildConfig(disableExternDevvitProtos, targetRuntime, watchMode = fal
|
|
|
372
372
|
return {
|
|
373
373
|
// Recursively inline any imported dependencies.
|
|
374
374
|
bundle: true,
|
|
375
|
-
external: [
|
|
375
|
+
external: [
|
|
376
|
+
'node:*',
|
|
377
|
+
// All .js files from https://github.com/nodejs/node/tree/b2405e9/lib that
|
|
378
|
+
// don't start with _. Another option is to mark everything external for
|
|
379
|
+
// server builds but then the user can't bundle _anything_.
|
|
380
|
+
'assert',
|
|
381
|
+
'async_hooks',
|
|
382
|
+
'buffer',
|
|
383
|
+
'child_process',
|
|
384
|
+
'cluster',
|
|
385
|
+
'console',
|
|
386
|
+
'constants',
|
|
387
|
+
'crypto',
|
|
388
|
+
'dgram',
|
|
389
|
+
'diagnostics_channel',
|
|
390
|
+
'dns',
|
|
391
|
+
'domain',
|
|
392
|
+
'events',
|
|
393
|
+
'fs',
|
|
394
|
+
'http',
|
|
395
|
+
'http2',
|
|
396
|
+
'https',
|
|
397
|
+
'inspector',
|
|
398
|
+
'module',
|
|
399
|
+
'net',
|
|
400
|
+
'os',
|
|
401
|
+
'path',
|
|
402
|
+
'perf_hooks',
|
|
403
|
+
'process',
|
|
404
|
+
'punycode',
|
|
405
|
+
'querystring',
|
|
406
|
+
'quic',
|
|
407
|
+
'readline',
|
|
408
|
+
'repl',
|
|
409
|
+
'sea',
|
|
410
|
+
'sqlite',
|
|
411
|
+
'stream',
|
|
412
|
+
'string_decoder',
|
|
413
|
+
'sys',
|
|
414
|
+
'test',
|
|
415
|
+
'timers',
|
|
416
|
+
'tls',
|
|
417
|
+
'trace_events',
|
|
418
|
+
'tty',
|
|
419
|
+
'url',
|
|
420
|
+
'util',
|
|
421
|
+
'v8',
|
|
422
|
+
'vm',
|
|
423
|
+
'wasi',
|
|
424
|
+
'worker_threads',
|
|
425
|
+
'zlib',
|
|
426
|
+
],
|
|
376
427
|
// Split the @devvit/protos from the LinkedBundle. This means apps assume
|
|
377
428
|
// @devvit/protos is available for import at execution time.
|
|
378
429
|
plugins: [
|
|
@@ -394,6 +445,7 @@ function esbuildConfig(disableExternDevvitProtos, targetRuntime, watchMode = fal
|
|
|
394
445
|
// Do not show any console output. Warnings and errors are reported in the
|
|
395
446
|
// response.
|
|
396
447
|
logLevel: 'silent',
|
|
448
|
+
platform: targetRuntime === TargetRuntime.UNIVERSAL ? 'node' : 'browser',
|
|
397
449
|
target: 'es2020',
|
|
398
450
|
// Write to in-memory buffers.
|
|
399
451
|
write: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverClientCodeSplit.d.ts","sourceRoot":"","sources":["../../../src/esbuild/plugins/serverClientCodeSplit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAKV,MAAM,EAEP,MAAM,SAAS,CAAC;AAgDjB;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,GAAE,OAAe,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"serverClientCodeSplit.d.ts","sourceRoot":"","sources":["../../../src/esbuild/plugins/serverClientCodeSplit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAKV,MAAM,EAEP,MAAM,SAAS,CAAC;AAgDjB;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,GAAE,OAAe,GAAG,MAAM,CAmFxE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9D"}
|
|
@@ -52,7 +52,6 @@ export function serverClientCodeSplit(watchMode = false) {
|
|
|
52
52
|
name: 'removeServerCode',
|
|
53
53
|
setup(build) {
|
|
54
54
|
let publicApiDir;
|
|
55
|
-
let projectDirs;
|
|
56
55
|
// We can't call build.resolve() outside of one of the plugin callbacks
|
|
57
56
|
build.onStart(async () => {
|
|
58
57
|
const { path: resolvedPath } = await build.resolve('@devvit/public-api', {
|
|
@@ -61,21 +60,6 @@ export function serverClientCodeSplit(watchMode = false) {
|
|
|
61
60
|
pluginData: 'removeServerCodeStart',
|
|
62
61
|
});
|
|
63
62
|
publicApiDir = path.dirname(resolvedPath);
|
|
64
|
-
projectDirs = [];
|
|
65
|
-
if (!build.initialOptions.entryPoints) {
|
|
66
|
-
throw new Error('Invalid state: no entry points defined');
|
|
67
|
-
}
|
|
68
|
-
// Gather the list of project entrypoint directories so we can ensure we're only stubbing project code
|
|
69
|
-
let entrypoints;
|
|
70
|
-
if (Array.isArray(build.initialOptions.entryPoints)) {
|
|
71
|
-
entrypoints = build.initialOptions.entryPoints.map((entry) => typeof entry === 'string' ? entry : entry.in);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
entrypoints = Object.keys(build.initialOptions.entryPoints);
|
|
75
|
-
}
|
|
76
|
-
entrypoints.forEach((entrypoint) => {
|
|
77
|
-
projectDirs.push(path.dirname(path.resolve(entrypoint)));
|
|
78
|
-
});
|
|
79
63
|
});
|
|
80
64
|
// Remove code the developer has marked as server-only by naming convention:
|
|
81
65
|
build.onResolve({ filter: /(\/server\/)|(\.server\.(js|ts)x?$)/ }, async (args) => {
|
|
@@ -83,8 +67,8 @@ export function serverClientCodeSplit(watchMode = false) {
|
|
|
83
67
|
if (args.pluginData) {
|
|
84
68
|
return {};
|
|
85
69
|
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
70
|
+
// Only the local project code should be stubbed
|
|
71
|
+
if (args.path.includes('node_modules')) {
|
|
88
72
|
return {};
|
|
89
73
|
}
|
|
90
74
|
if (!watchMode) {
|
|
@@ -102,7 +86,7 @@ export function serverClientCodeSplit(watchMode = false) {
|
|
|
102
86
|
pluginData: true,
|
|
103
87
|
});
|
|
104
88
|
// clean up the paths so we don't stamp local paths in the final output
|
|
105
|
-
resolved.path = path.relative(
|
|
89
|
+
resolved.path = path.relative(process.cwd(), resolved.path);
|
|
106
90
|
resolved.namespace = SERVER_ONLY_NAMESPACE;
|
|
107
91
|
return resolved;
|
|
108
92
|
});
|
package/lib/BuildPack.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildPack.d.ts","sourceRoot":"","sources":["../../src/lib/BuildPack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,2DAA2D,CAAC;AAC/G,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,eAAe,EAChB,MAAM,kEAAkE,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,8BAAsB,SAAU,YAAW,gBA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AO,CAAC,eAAe,CAAC;IAE3B,QAAQ,CAAC,KAAK,CACZ,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,GACrC,UAAU,CAAC,eAAe,CAAC;IAE9B,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAClC;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,QAAQ,CAAC,UAAU,CAAC,EAAE,GAAG,MAAM,CAExE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,CAO3D;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAsChE"}
|
package/lib/BuildPack.js
CHANGED
|
@@ -19,22 +19,34 @@ export function formatLog(log) {
|
|
|
19
19
|
}
|
|
20
20
|
/** Returns path to source input. Eg, src/main.tsx or main.ts. */
|
|
21
21
|
export function getModuleEntrypoint(root) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// minor syntax ambiguities with angle brackets for jsx vs type assertions
|
|
34
|
-
const ts = path.join(dir, BuildPack.DevvitModuleEntryPoint);
|
|
35
|
-
const tsx = `${ts}x`;
|
|
36
|
-
if (fs.existsSync(tsx)) {
|
|
37
|
-
return tsx;
|
|
22
|
+
const srcDir = path.join(root, ACTOR_SRC_DIR);
|
|
23
|
+
const srcDevvitDir = path.join(srcDir, 'devvit');
|
|
24
|
+
const entrypointBase = BuildPack.DevvitModuleEntryPoint; // e.g., 'main.ts'
|
|
25
|
+
const entrypointBaseNoExt = entrypointBase.replace(/\.(ts|js)$/, ''); // e.g., 'main'
|
|
26
|
+
const tsxEntrypoint = `${entrypointBaseNoExt}.tsx`;
|
|
27
|
+
const tsEntrypoint = `${entrypointBaseNoExt}.ts`;
|
|
28
|
+
const potentialPaths = [];
|
|
29
|
+
// Priority 1: src/devvit directory if it exists
|
|
30
|
+
if (fs.existsSync(srcDevvitDir)) {
|
|
31
|
+
potentialPaths.push(path.join(srcDevvitDir, tsxEntrypoint));
|
|
32
|
+
potentialPaths.push(path.join(srcDevvitDir, tsEntrypoint));
|
|
38
33
|
}
|
|
39
|
-
|
|
34
|
+
// Priority 2: src directory if it exists
|
|
35
|
+
if (fs.existsSync(srcDir)) {
|
|
36
|
+
potentialPaths.push(path.join(srcDir, tsxEntrypoint));
|
|
37
|
+
potentialPaths.push(path.join(srcDir, tsEntrypoint));
|
|
38
|
+
}
|
|
39
|
+
// Priority 3: root directory
|
|
40
|
+
potentialPaths.push(path.join(root, tsxEntrypoint));
|
|
41
|
+
potentialPaths.push(path.join(root, tsEntrypoint)); // Default fallback
|
|
42
|
+
// Find the first existing path in the priority order
|
|
43
|
+
for (const p of potentialPaths) {
|
|
44
|
+
if (fs.existsSync(p)) {
|
|
45
|
+
return p;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Fallback to the root main.ts path if nothing else exists.
|
|
49
|
+
// This line should technically be unreachable if root always exists,
|
|
50
|
+
// but provides a safety net.
|
|
51
|
+
return path.join(root, tsEntrypoint);
|
|
40
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/build-pack",
|
|
3
|
-
"version": "0.12.0-next-2025-04-
|
|
3
|
+
"version": "0.12.0-next-2025-04-28-276a82082.0",
|
|
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.12.0-next-2025-04-
|
|
27
|
-
"@devvit/shared-types": "0.12.0-next-2025-04-
|
|
26
|
+
"@devvit/protos": "0.12.0-next-2025-04-28-276a82082.0",
|
|
27
|
+
"@devvit/shared-types": "0.12.0-next-2025-04-28-276a82082.0",
|
|
28
28
|
"esbuild": "0.23.0",
|
|
29
29
|
"rxjs": "7.8.1",
|
|
30
30
|
"tiny-glob": "0.2.9",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"typescript": "5.3.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@devvit/public-api": "0.12.0-next-2025-04-
|
|
36
|
-
"@devvit/repo-tools": "0.12.0-next-2025-04-
|
|
37
|
-
"@devvit/tsconfig": "0.12.0-next-2025-04-
|
|
35
|
+
"@devvit/public-api": "0.12.0-next-2025-04-28-276a82082.0",
|
|
36
|
+
"@devvit/repo-tools": "0.12.0-next-2025-04-28-276a82082.0",
|
|
37
|
+
"@devvit/tsconfig": "0.12.0-next-2025-04-28-276a82082.0",
|
|
38
38
|
"@types/tsv": "0.2.1",
|
|
39
39
|
"eslint": "9.11.1",
|
|
40
40
|
"typescript": "5.3.2",
|
|
41
|
-
"vitest": "1.6.
|
|
41
|
+
"vitest": "1.6.1"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"directory": "dist"
|
|
45
45
|
},
|
|
46
46
|
"source": "./src/index.ts",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "67447f61a9459bee03909b59c8889a915e2be256"
|
|
48
48
|
}
|