Skip to content

Commit c843b57

Browse files
committed
Base JS runtime for builds
Currently we ship dev runtimes (with things like HMR logic) along with code for loading chunks. This separates them and allows us to include a minimal runtime for builds. Test Plan: `TURBOPACK=1 TURBOPACK_BUILD=1 pnpm build` on an app with a `middleware.ts` and verified it loads when started.
1 parent 05bcd01 commit c843b57

File tree

13 files changed

+1082
-10
lines changed

13 files changed

+1082
-10
lines changed

turbopack/crates/turbopack-browser/src/ecmascript/evaluate/chunk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl EcmascriptDevEvaluateChunk {
147147
let runtime_code = turbopack_ecmascript_runtime::get_browser_runtime_code(
148148
environment,
149149
chunking_context.chunk_base_path(),
150+
Value::new(chunking_context.runtime_type()),
150151
Vc::cell(output_root.to_string().into()),
151152
);
152153
code.push_code(&*runtime_code.await?);
@@ -155,6 +156,7 @@ impl EcmascriptDevEvaluateChunk {
155156
let runtime_code = turbopack_ecmascript_runtime::get_browser_runtime_code(
156157
environment,
157158
chunking_context.chunk_base_path(),
159+
Value::new(chunking_context.runtime_type()),
158160
Vc::cell(output_root.to_string().into()),
159161
);
160162
code.push_code(&*runtime_code.await?);

turbopack/crates/turbopack-ecmascript-runtime/js/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"check": "run-p check:*",
99
"check:nodejs": "tsc -p src/nodejs",
1010
"check:browser-dev-client": "tsc -p src/browser/dev/hmr-client",
11+
"check:browser-runtime-base": "tsc -p src/browser/runtime/base",
12+
"check:browser-runtime-dom": "tsc -p src/browser/runtime/dom",
13+
"check:browser-runtime-edge": "tsc -p src/browser/runtime/edge",
1114
"check:browser-dev-runtime-base": "tsc -p src/browser/dev/runtime/base",
1215
"check:browser-dev-runtime-dom": "tsc -p src/browser/dev/runtime/dom",
1316
"check:browser-dev-runtime-edge": "tsc -p src/browser/dev/runtime/edge"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* This file acts as a dummy implementor for the interface that
3+
* `runtime-base.ts` expects to be available in the global scope.
4+
*
5+
* This interface will be implemented by runtime backends.
6+
*/
7+
8+
/* eslint-disable @typescript-eslint/no-unused-vars */
9+
10+
/// <reference path="../../../shared/runtime-utils.ts" />
11+
/// <reference path="../../../shared/require-type.d.ts" />
12+
13+
declare var BACKEND: RuntimeBackend;
14+
declare var loadWebAssembly: (
15+
source: SourceInfo,
16+
wasmChunkPath: ChunkPath,
17+
imports: WebAssembly.Imports
18+
) => Exports;
19+
declare var loadWebAssemblyModule: (
20+
source: SourceInfo,
21+
wasmChunkPath: ChunkPath
22+
) => WebAssembly.Module;
23+
declare var relativeURL: (inputUrl: string) => void;

0 commit comments

Comments
 (0)