Skip to content

Commit

Permalink
backport turbopack changes (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Aug 16, 2024
1 parent 855bd70 commit 39b4cd9
Show file tree
Hide file tree
Showing 43 changed files with 253 additions and 362 deletions.
14 changes: 8 additions & 6 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ pub(crate) async fn collect_evaluated_chunk_group(
/// If an import is specified as dynamic, next.js does few things:
/// - Runs a next_dynamic [transform to the source file](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next-swc/crates/next-transform-dynamic/src/lib.rs#L22)
/// - This transform will [inject `loadableGenerated` property](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next-swc/crates/next-transform-dynamic/tests/fixture/wrapped-import/output-webpack-dev.js#L5),
/// which contains the list of the import ids in the form of `${origin} -> ${imported}`.
/// - Emits `react-loadable-manifest.json` which contains the mapping of the import ids to the chunk
/// ids.
/// which contains the list of the import ids in the form of `${origin} ->
/// ${imported}`.
/// - Emits `react-loadable-manifest.json` which contains the mapping of the
/// import ids to the chunk ids.
/// - Webpack: [implementation](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next/src/build/webpack/plugins/react-loadable-plugin.ts)
/// - Turbopack: [implementation 1](https://github.com/vercel/next.js/pull/56389/files#diff-3cac9d9bfe73e0619e6407f21f6fe652da0719d0ec9074ff813ad3e416d0eb1a),
/// [implementation 2](https://github.com/vercel/next.js/pull/56389/files#diff-791951bbe1fa09bcbad9be9173412d0848168f7d658758f11b6e8888a021552c),
Expand All @@ -123,16 +124,17 @@ pub(crate) async fn collect_evaluated_chunk_group(
/// - Server embeds those into __NEXT_DATA__ and [send to the client.](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/server/render.tsx#L1453)
/// - When client boots up, pass it to the [client preload](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/client/index.tsx#L943)
/// - Loadable runtime [injects preload fn](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/shared/lib/loadable.shared-runtime.tsx#L281)
/// to wait until all the dynamic components are being loaded, this ensures hydration mismatch
/// won't occur
/// to wait until all the dynamic components are being loaded, this ensures
/// hydration mismatch won't occur
#[tracing::instrument(level = Level::INFO, name = "collecting next/dynamic imports", skip_all)]
pub(crate) async fn collect_next_dynamic_imports(
server_entries: impl IntoIterator<Item = Vc<Box<dyn Module>>>,
client_asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<IndexMap<Vc<Box<dyn Module>>, DynamicImportedModules>> {
// Traverse referenced modules graph, collect all of the dynamic imports:
// - Read the Program AST of the Module, this is the origin (A)
// - If there's `dynamic(import(B))`, then B is the module that is being imported
// - If there's `dynamic(import(B))`, then B is the module that is being
// imported
// Returned import mappings are in the form of
// (Module<A>, Vec<(B, Module<B>)>) (where B is the raw import source string,
// and Module<B> is the actual resolved Module)
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_app/app_route_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
/// Computes the entry for a Next.js app route.
/// # Arguments
///
/// * `original_segment_config` - A next segment config to be specified explicitly for the given
/// source.
/// * `original_segment_config` - A next segment config to be specified
/// explicitly for the given source.
/// For some cases `source` may not be the original but the handler (dynamic
/// metadata) which will lose segment config.
#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;

/// An [EcmascriptClientReferenceModule] is a marker module, used by the
/// [super::ecmascript_client_reference_proxy_module::EcmascriptClientReferenceProxyModule] to
/// indicate which client reference should appear in the client reference manifest.
/// indicate which client reference should appear in the client reference
/// manifest.
#[turbo_tasks::value]
pub struct EcmascriptClientReferenceModule {
pub server_ident: Vc<AssetIdent>,
Expand All @@ -24,8 +25,8 @@ impl EcmascriptClientReferenceModule {
///
/// # Arguments
///
/// * `server_ident` - The identifier of the server module, used to identify the client
/// reference.
/// * `server_ident` - The identifier of the server module, used to identify
/// the client reference.
/// * `client_module` - The client module.
/// * `ssr_module` - The SSR module.
#[turbo_tasks::function]
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_font/local/font_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn calc_average_width(font: &mut Font<DynamicFontTableProvider>) -> Option<f32>
/// font file:
/// - Most of the text will have normal weight, use the one closest to 400
/// - Most of the text will have normal style, prefer normal over italic
/// - If two font files have the same distance from normal weight, the thinner one will most likely
/// be the bulk of the text
/// - If two font files have the same distance from normal weight, the thinner
/// one will most likely be the bulk of the text
fn pick_font_for_fallback_generation(
font_descriptors: &FontDescriptors,
) -> Result<&FontDescriptor> {
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_font/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub(crate) enum FontFamilyType {
}

/// Returns a uniquely scoped version of the font family, e.g.`__Roboto_c123b8`
/// * `ty` - Whether to generate a scoped classname for the main font or its fallback equivalent,
/// e.g. `__Roboto_Fallback_c123b8`
/// * `ty` - Whether to generate a scoped classname for the main font or its
/// fallback equivalent, e.g. `__Roboto_Fallback_c123b8`
/// * `font_family_name` - The font name to scope, e.g. `Roboto`
/// * `request_hash` - The hash value of the font request
#[turbo_tasks::function]
Expand Down
11 changes: 6 additions & 5 deletions crates/next-custom-transforms/src/transforms/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ pub enum NextDynamicMode {
/// the React Loadable Webpack plugin.
Webpack,
/// In Turbopack mode:
/// * in development, each `dynamic()` call will generate a key containing both the imported
/// module id and the chunks it needs. This removes the need for a manifest entry
/// * during build, each `dynamic()` call will import the module through the given transition,
/// which takes care of adding an entry to the manifest and returning an asset that exports
/// the entry's key.
/// * in development, each `dynamic()` call will generate a key containing
/// both the imported module id and the chunks it needs. This removes the
/// need for a manifest entry
/// * during build, each `dynamic()` call will import the module through the
/// given transition, which takes care of adding an entry to the manifest
/// and returning an asset that exports the entry's key.
Turbopack { dynamic_transition_name: String },
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl PageMode {
}

/// A transform that either:
/// * strips Next.js data exports (getServerSideProps, getStaticProps, getStaticPaths); or
/// * strips Next.js data exports (getServerSideProps, getStaticProps,
/// getStaticPaths); or
/// * strips the default export.
///
/// Note: This transform requires running `resolver` **before** running it.
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbo-tasks-fs/src/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ enum GlobPart {
// - file*.js = File(file), AnyFile, File(.js)
// - dir/file.js = File(dir), PathSeparator, File(file.js)
// - **/*.js = AnyDirectories, PathSeparator, AnyFile, File(.js)
// - {a/**,*}/file = Alternatives([File(a), PathSeparator, AnyDirectories], [AnyFile]),
// PathSeparator, File(file)
// - {a/**,*}/file = Alternatives([File(a), PathSeparator, AnyDirectories],
// [AnyFile]), PathSeparator, File(file)

// Note: a/**/b does match a/b, so we need some special logic about path
// separators
Expand Down
10 changes: 6 additions & 4 deletions turbopack/crates/turbo-tasks-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ impl DiskFileSystem {
///
/// * `name` - Name of the filesystem.
/// * `root` - Path to the given filesystem's root.
/// * `ignored_subpaths` - A list of subpaths that should not trigger invalidation. This should
/// be a full path, since it is possible that root & project dir is different and requires to
/// ignore specific subpaths from each.
/// * `ignored_subpaths` - A list of subpaths that should not trigger
/// invalidation. This should be a full path, since it is possible that
/// root & project dir is different and requires to ignore specific
/// subpaths from each.
#[turbo_tasks::function]
pub async fn new(name: RcStr, root: RcStr, ignored_subpaths: Vec<RcStr>) -> Result<Vc<Self>> {
mark_stateful();
Expand Down Expand Up @@ -1042,7 +1043,8 @@ impl FileSystemPath {
///
/// * [`None`], if there is no file name;
/// * The entire file name if there is no embedded `.`;
/// * The entire file name if the file name begins with `.` and has no other `.`s within;
/// * The entire file name if the file name begins with `.` and has no other
/// `.`s within;
/// * Otherwise, the portion of the file name before the final `.`
#[turbo_tasks::function]
pub async fn file_stem(self: Vc<Self>) -> Result<Vc<Option<RcStr>>> {
Expand Down
11 changes: 6 additions & 5 deletions turbopack/crates/turbo-tasks-fs/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ impl DiskWatcher {
/// `notify` provides 2 different debouncer implementations, `-full`
/// provides below differences for the easy of use:
///
/// - Only emits a single Rename event if the rename From and To events can be matched
/// - Only emits a single Rename event if the rename From and To events can
/// be matched
/// - Merges multiple Rename events
/// - Takes Rename events into account and updates paths for events that occurred before the
/// rename event, but which haven't been emitted, yet
/// - Optionally keeps track of the file system IDs all files and stitches rename events
/// together (FSevents, Windows)
/// - Takes Rename events into account and updates paths for events that
/// occurred before the rename event, but which haven't been emitted, yet
/// - Optionally keeps track of the file system IDs all files and stitches
/// rename events together (FSevents, Windows)
/// - Emits only one Remove event when deleting a directory (inotify)
/// - Doesn't emit duplicate create events
/// - Doesn't emit Modify events after a Create event
Expand Down
11 changes: 6 additions & 5 deletions turbopack/crates/turbo-tasks-macros-shared/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use syn::{
///
/// Requires several Fn helpers which perform expand different structures:
///
/// - [expand_named] handles the expansion of a struct or enum variant with named fields (e.g.
/// `struct Foo { bar: u32 }`, `Foo::Bar { baz: u32 }`).
/// - [expand_unnamed] handles the expansion of a struct or enum variant with unnamed fields (e.g.
/// `struct Foo(u32)`, `Foo::Bar(u32)`).
/// - [expand_unit] handles the expansion of a unit struct or enum (e.g. `struct Foo;`, `Foo::Bar`).
/// - [expand_named] handles the expansion of a struct or enum variant with
/// named fields (e.g. `struct Foo { bar: u32 }`, `Foo::Bar { baz: u32 }`).
/// - [expand_unnamed] handles the expansion of a struct or enum variant with
/// unnamed fields (e.g. `struct Foo(u32)`, `Foo::Bar(u32)`).
/// - [expand_unit] handles the expansion of a unit struct or enum (e.g. `struct
/// Foo;`, `Foo::Bar`).
///
/// These helpers should themselves call [generate_destructuring] to generate
/// the destructure necessary to access the fields of the value.
Expand Down
22 changes: 13 additions & 9 deletions turbopack/crates/turbo-tasks-macros/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,27 @@ impl<T: Parse> Parse for MaybeParenthesized<T> {
/// Arguments to the `#[turbo_tasks::function]` macro.
#[derive(Default)]
pub struct FunctionArguments {
/// Manually annotated metadata about what kind of IO this function does. Currently only used
/// by some static analysis tools. May be exposed via `tracing` or used as part of an
/// optimization heuristic in the future.
/// Manually annotated metadata about what kind of IO this function does.
/// Currently only used by some static analysis tools. May be exposed
/// via `tracing` or used as part of an optimization heuristic in the
/// future.
///
/// This should only be used by the task that directly performs the IO. Tasks that transitively
/// perform IO should not be manually annotated.
/// This should only be used by the task that directly performs the IO.
/// Tasks that transitively perform IO should not be manually annotated.
io_markers: HashSet<IoMarker>,
/// Should we check that the return type contains a `ResolvedValue`?
///
/// If there is an error due to this option being set, it should be reported to this span.
/// If there is an error due to this option being set, it should be reported
/// to this span.
///
/// If [`Self::local_cells`] is set, this will also be set to the same span.
resolved: Option<Span>,
/// Changes the behavior of `Vc::cell` to create local cells that are not cached across task
/// executions. Cells can be converted to their non-local versions by calling `Vc::resolve`.
/// Changes the behavior of `Vc::cell` to create local cells that are not
/// cached across task executions. Cells can be converted to their
/// non-local versions by calling `Vc::resolve`.
///
/// If there is an error due to this option being set, it should be reported to this span.
/// If there is an error due to this option being set, it should be reported
/// to this span.
///
/// Setting this option will also set [`Self::resolved`] to the same span.
pub local_cells: Option<Span>,
Expand Down
11 changes: 7 additions & 4 deletions turbopack/crates/turbo-tasks-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ pub fn derive_task_input(input: TokenStream) -> TokenStream {
///
/// Possible values:
///
/// - "auto" (default): Derives the serialization traits and enabled serialization.
/// - "auto_for_input": Same as "auto", but also adds the marker trait [turbo_tasks::TypedForInput].
/// - "custom": Prevents deriving the serialization traits, but still enables serialization (you
/// need to manually implement [serde::Serialize] and [serde::Deserialize]).
/// - "auto" (default): Derives the serialization traits and enabled
/// serialization.
/// - "auto_for_input": Same as "auto", but also adds the marker trait
/// [turbo_tasks::TypedForInput].
/// - "custom": Prevents deriving the serialization traits, but still enables
/// serialization (you need to manually implement [serde::Serialize] and
/// [serde::Deserialize]).
/// - "custom_for_input":Same as "auto", but also adds the marker trait
/// [turbo_tasks::TypedForInput].
/// - "none": Disables serialization and prevents deriving the traits.
Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/generics.rs
Loading

0 comments on commit 39b4cd9

Please sign in to comment.