Skip to content

Commit

Permalink
Base JS runtime for builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wbinnssmith committed Sep 16, 2024
1 parent 05bcd01 commit c843b57
Show file tree
Hide file tree
Showing 13 changed files with 1,082 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl EcmascriptDevEvaluateChunk {
let runtime_code = turbopack_ecmascript_runtime::get_browser_runtime_code(
environment,
chunking_context.chunk_base_path(),
Value::new(chunking_context.runtime_type()),
Vc::cell(output_root.to_string().into()),
);
code.push_code(&*runtime_code.await?);
Expand All @@ -155,6 +156,7 @@ impl EcmascriptDevEvaluateChunk {
let runtime_code = turbopack_ecmascript_runtime::get_browser_runtime_code(
environment,
chunking_context.chunk_base_path(),
Value::new(chunking_context.runtime_type()),
Vc::cell(output_root.to_string().into()),
);
code.push_code(&*runtime_code.await?);
Expand Down
3 changes: 3 additions & 0 deletions turbopack/crates/turbopack-ecmascript-runtime/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"check": "run-p check:*",
"check:nodejs": "tsc -p src/nodejs",
"check:browser-dev-client": "tsc -p src/browser/dev/hmr-client",
"check:browser-runtime-base": "tsc -p src/browser/runtime/base",
"check:browser-runtime-dom": "tsc -p src/browser/runtime/dom",
"check:browser-runtime-edge": "tsc -p src/browser/runtime/edge",
"check:browser-dev-runtime-base": "tsc -p src/browser/dev/runtime/base",
"check:browser-dev-runtime-dom": "tsc -p src/browser/dev/runtime/dom",
"check:browser-dev-runtime-edge": "tsc -p src/browser/dev/runtime/edge"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This file acts as a dummy implementor for the interface that
* `runtime-base.ts` expects to be available in the global scope.
*
* This interface will be implemented by runtime backends.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../../../shared/runtime-utils.ts" />
/// <reference path="../../../shared/require-type.d.ts" />

declare var BACKEND: RuntimeBackend;
declare var loadWebAssembly: (
source: SourceInfo,
wasmChunkPath: ChunkPath,
imports: WebAssembly.Imports
) => Exports;
declare var loadWebAssemblyModule: (
source: SourceInfo,
wasmChunkPath: ChunkPath
) => WebAssembly.Module;
declare var relativeURL: (inputUrl: string) => void;
Loading

0 comments on commit c843b57

Please sign in to comment.