@devvit/build-pack 0.12.0-next-2025-04-24-137462f28.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.
@@ -445,6 +445,7 @@ function esbuildConfig(disableExternDevvitProtos, targetRuntime, watchMode = fal
445
445
  // Do not show any console output. Warnings and errors are reported in the
446
446
  // response.
447
447
  logLevel: 'silent',
448
+ platform: targetRuntime === TargetRuntime.UNIVERSAL ? 'node' : 'browser',
448
449
  target: 'es2020',
449
450
  // Write to in-memory buffers.
450
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,CAsGxE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9D"}
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
- const absPath = path.resolve(path.dirname(args.importer), args.path);
87
- if (!projectDirs.some((projectDir) => absPath.startsWith(projectDir))) {
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(args.resolveDir, resolved.path);
89
+ resolved.path = path.relative(process.cwd(), resolved.path);
106
90
  resolved.namespace = SERVER_ONLY_NAMESPACE;
107
91
  return resolved;
108
92
  });
@@ -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,IAA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AC;AAEvC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,8BAAsB,SAAU,YAAW,gBAAgB;IACzD,oDAAoD;IACpD,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAa;IAElD,QAAQ,CAAC,OAAO,CACd,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,GACrC,OAAO,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
- // favor src/ if it exists. single file projects may point directly to the
23
- // source directory.
24
- const src = path.join(root, ACTOR_SRC_DIR);
25
- // With the advent of webviews and LLMs, it's nice to have all devvit
26
- // code in a single folder. This helps tsconfig.json support, LLM inference
27
- // and general code hygiene!
28
- const srcDevvit = path.join(src, 'devvit');
29
- const dir = fs.existsSync(srcDevvit) ? srcDevvit : fs.existsSync(src) ? src : root;
30
- // Support TSX files and give them priority is they exist.
31
- // This is used to power UI (aka BlockKit)
32
- // TS needs to have the `.tsx` extension separately because JSX has some
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
- return ts;
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-24-137462f28.0",
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-24-137462f28.0",
27
- "@devvit/shared-types": "0.12.0-next-2025-04-24-137462f28.0",
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,9 +32,9 @@
32
32
  "typescript": "5.3.2"
33
33
  },
34
34
  "devDependencies": {
35
- "@devvit/public-api": "0.12.0-next-2025-04-24-137462f28.0",
36
- "@devvit/repo-tools": "0.12.0-next-2025-04-24-137462f28.0",
37
- "@devvit/tsconfig": "0.12.0-next-2025-04-24-137462f28.0",
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",
@@ -44,5 +44,5 @@
44
44
  "directory": "dist"
45
45
  },
46
46
  "source": "./src/index.ts",
47
- "gitHead": "6c680b1ce74f21ae0200dc527053c7382e75fd58"
47
+ "gitHead": "67447f61a9459bee03909b59c8889a915e2be256"
48
48
  }