Skip to content

Commit

Permalink
Revert "Implement new forking technique for vendored packages. (verce…
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Aug 6, 2023
1 parent 5f9d2c5 commit 7bf3d77
Show file tree
Hide file tree
Showing 244 changed files with 1,732 additions and 6,623 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ examples/with-tigris/db/models/todoItems.ts
packages/next/src/bundles/webpack/packages/*.runtime.js
packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
packages/next/src/compiled/**/*
packages/next/vendored/**/*
packages/react-refresh-utils/**/*.js
packages/react-dev-overlay/lib/**
**/__tmp__/**
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ packages/next/wasm/@next

# dependencies
node_modules
!packages/next/vendored/node_modules
package-lock.json
yarn.lock
!/yarn.lock
Expand Down
1 change: 0 additions & 1 deletion .prettierignore_staged
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
**/dist/**
packages/next-swc/crates/**
packages/next/src/compiled/**/*
packages/next/vendored/**/*
packages/next/bundles/webpack/packages/*.runtime.js
lerna.json
packages/next-codemod/transforms/__testfixtures__/**/*
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"debug.javascript.unmapMissingSources": true,

"files.exclude": {
"*[!test]**/node_modules": true,
"**/node_modules": false
"**/node_modules": false,
"node_modules": true,
"*[!test]**/node_modules": true
},

// Ensure enough terminal history is preserved when running tests.
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@
"random-seed": "0.3.0",
"react": "18.2.0",
"react-17": "npm:[email protected]",
"react-builtin": "npm:[email protected]546fe4681-20230713",
"react-builtin": "npm:[email protected]9377e1010-20230712",
"react-dom": "18.2.0",
"react-dom-17": "npm:[email protected]",
"react-dom-builtin": "npm:[email protected]546fe4681-20230713",
"react-dom-experimental-builtin": "npm:[email protected]546fe4681-20230713",
"react-experimental-builtin": "npm:[email protected]546fe4681-20230713",
"react-server-dom-webpack": "18.3.0-canary-546fe4681-20230713",
"react-server-dom-webpack-experimental": "npm:[email protected]546fe4681-20230713",
"react-dom-builtin": "npm:[email protected]9377e1010-20230712",
"react-dom-experimental-builtin": "npm:[email protected]9377e1010-20230712",
"react-experimental-builtin": "npm:[email protected]9377e1010-20230712",
"react-server-dom-webpack": "18.3.0-canary-9377e1010-20230712",
"react-server-dom-webpack-experimental": "npm:[email protected]9377e1010-20230712",
"react-ssr-prepass": "1.0.8",
"react-virtualized": "9.22.3",
"relay-compiler": "13.0.2",
Expand All @@ -205,8 +205,8 @@
"resolve-from": "5.0.0",
"sass": "1.54.0",
"satori": "0.10.1",
"scheduler-builtin": "npm:[email protected]546fe4681-20230713",
"scheduler-experimental-builtin": "npm:[email protected]546fe4681-20230713",
"scheduler-builtin": "npm:[email protected]9377e1010-20230712",
"scheduler-experimental-builtin": "npm:[email protected]9377e1010-20230712",
"seedrandom": "3.0.5",
"selenium-webdriver": "4.0.0-beta.4",
"semver": "7.3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ReactDOMClient from 'react-dom/client'
import React, { use } from 'react'
import type { ReactElement } from 'react'
import { version } from 'next/package.json'
import { createFromReadableStream } from 'react-server-dom-webpack/client'
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack/client'
import { callServer } from 'next/dist/client/app-call-server'
import { linkGc } from 'next/dist/client/app-link-gc'

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module 'react-server-dom-webpack/client'
declare module 'next/dist/compiled/react-server-dom-webpack/client'
1 change: 1 addition & 0 deletions packages/next-swc/crates/next-core/js/types/modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare module 'next/dist/client/components/static-generation-async-storage.js'
declare module 'next/dist/client/components/request-async-storage.js'
declare module 'next/dist/client/components/hooks-server-context.js'
declare module 'next/dist/compiled/react-server-dom-webpack/server.edge'
171 changes: 84 additions & 87 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ pub async fn get_next_client_import_map(
)
.await?;

let vendor_dir = get_next_package(project_path).join("vendored".into());

match ty.into_value() {
ClientContextType::Pages { pages_dir } => {
insert_alias_to_alternatives(
Expand Down Expand Up @@ -87,35 +85,31 @@ pub async fn get_next_client_import_map(
],
);
}
ClientContextType::App { app_dir: _ } => {
ClientContextType::App { app_dir } => {
import_map.insert_exact_alias(
"react",
request_to_import_mapping(app_dir, "next/dist/compiled/react"),
);
import_map.insert_wildcard_alias(
"react/",
request_to_import_mapping(app_dir, "next/dist/compiled/react/*"),
);
import_map.insert_exact_alias(
"react-dom",
request_to_import_mapping(app_dir, "next/dist/compiled/react-dom"),
);
import_map.insert_wildcard_alias(
"react-dom/",
request_to_import_mapping(app_dir, "next/dist/compiled/react-dom/*"),
);
import_map.insert_wildcard_alias(
"react-server-dom-webpack/",
request_to_import_mapping(app_dir, "next/dist/compiled/react-server-dom-webpack/*"),
);
import_map.insert_exact_alias(
"next/dynamic",
request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"),
);

for (package_name, vendored_name) in [
("react", "react-vendored"),
("react-dom", "react-dom-vendored"),
(
"react-server-dom-webpack",
"react-server-dom-webpack-vendored",
),
("scheduler", "scheduler-vendored"),
("client-only", "client-only-vendored"),
("server-only", "server-only-vendored"),
] {
import_map.insert_exact_alias(
package_name,
request_to_import_mapping(vendor_dir, vendored_name),
);
import_map.insert_wildcard_alias(
format!("{}{}", package_name, "/"),
request_to_import_mapping(
vendor_dir,
format!("{}{}", vendored_name, "/*").as_str(),
),
);
}
}
ClientContextType::Fallback => {}
ClientContextType::Other => {}
Expand Down Expand Up @@ -217,7 +211,7 @@ pub async fn get_next_server_import_map(

let ty = ty.into_value();

insert_next_server_special_aliases(project_path, &mut import_map, ty, mode).await?;
insert_next_server_special_aliases(&mut import_map, ty, mode).await?;
let external = ImportMapping::External(None).cell();

match ty {
Expand Down Expand Up @@ -289,7 +283,7 @@ pub async fn get_next_edge_import_map(

let ty = ty.into_value();

insert_next_server_special_aliases(project_path, &mut import_map, ty, mode).await?;
insert_next_server_special_aliases(&mut import_map, ty, mode).await?;

match ty {
ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {}
Expand Down Expand Up @@ -363,12 +357,10 @@ static NEXT_ALIASES: [(&str, &str); 23] = [
];

pub async fn insert_next_server_special_aliases(
project_path: Vc<FileSystemPath>,
import_map: &mut ImportMap,
ty: ServerContextType,
mode: NextMode,
) -> Result<()> {
let vendor_dir = get_next_package(project_path).join("vendored".into());
match (mode, ty) {
(_, ServerContextType::Pages { pages_dir }) => {
import_map.insert_exact_alias(
Expand Down Expand Up @@ -417,30 +409,29 @@ pub async fn insert_next_server_special_aliases(
// @opentelemetry/api
request_to_import_mapping(app_dir, "next/dist/compiled/@opentelemetry/api"),
);

for (package_name, vendored_name) in [
("react", "react-vendored"),
("react-dom", "react-dom-vendored"),
(
"react-server-dom-webpack",
"react-server-dom-webpack-vendored",
import_map.insert_exact_alias(
"react",
request_to_import_mapping(app_dir, "next/dist/compiled/react"),
);
import_map.insert_wildcard_alias(
"react/",
request_to_import_mapping(app_dir, "next/dist/compiled/react/*"),
);
import_map.insert_exact_alias(
"react-dom",
request_to_import_mapping(
app_dir,
"next/dist/compiled/react-dom/server-rendering-stub.js",
),
("scheduler", "scheduler-vendored"),
("client-only", "client-only-vendored"),
("server-only", "server-only-vendored"),
] {
import_map.insert_exact_alias(
package_name,
request_to_import_mapping(vendor_dir, vendored_name),
);
import_map.insert_wildcard_alias(
format!("{}{}", package_name, "/"),
request_to_import_mapping(
vendor_dir,
format!("{}{}", vendored_name, "/*").as_str(),
),
);
}
);
import_map.insert_wildcard_alias(
"react-dom/",
request_to_import_mapping(app_dir, "next/dist/compiled/react-dom/*"),
);
import_map.insert_wildcard_alias(
"react-server-dom-webpack/",
request_to_import_mapping(app_dir, "next/dist/compiled/react-server-dom-webpack/*"),
);
}
// NOTE(alexkirsz) This logic maps loosely to
// `next.js/packages/next/src/build/webpack-config.ts`, where:
Expand All @@ -462,54 +453,60 @@ pub async fn insert_next_server_special_aliases(
// @opentelemetry/api
request_to_import_mapping(app_dir, "next/dist/compiled/@opentelemetry/api"),
);

for (package_name, vendored_name) in [
("react", "react-vendored"),
("react-dom", "react-dom-vendored"),
import_map.insert_exact_alias(
"react",
request_to_import_mapping(app_dir, "next/dist/compiled/react/react.shared-subset"),
);
import_map.insert_exact_alias(
"react-dom",
request_to_import_mapping(
app_dir,
"next/dist/compiled/react-dom/server-rendering-stub",
),
);
for (wildcard_alias, request) in [
("react/", "next/dist/compiled/react/*"),
("react-dom/", "next/dist/compiled/react-dom/*"),
(
"react-server-dom-webpack",
"react-server-dom-webpack-vendored",
"react-server-dom-webpack/",
"next/dist/compiled/react-server-dom-webpack/*",
),
("scheduler", "scheduler-vendored"),
("client-only", "client-only-vendored"),
("server-only", "server-only-vendored"),
] {
import_map.insert_exact_alias(
package_name,
request_to_import_mapping(vendor_dir, vendored_name),
);
import_map.insert_wildcard_alias(
format!("{}{}", package_name, "/"),
request_to_import_mapping(
vendor_dir,
format!("{}{}", vendored_name, "/*").as_str(),
),
wildcard_alias,
request_to_import_mapping(app_dir, request),
);
}
}
// ## SSR
//
// * always uses externals, to ensure we're using the same React instance as the Next.js
// runtime
// * maps react-dom -> react-dom/server-rendering-stub
// * passes through react and (react|react-dom|react-server-dom-webpack)/(.*) to
// next/dist/compiled/react and next/dist/compiled/$1/$2 resp.
(NextMode::Build | NextMode::Development, ServerContextType::AppSSR { .. }) => {
for package_name in [
import_map.insert_exact_alias(
"react",
external_request_to_import_mapping("next/dist/compiled/react"),
);
import_map.insert_exact_alias(
"react-dom",
"react-server-dom-webpack",
"scheduler",
"client-only",
"server-only",
external_request_to_import_mapping(
"next/dist/compiled/react-dom/server-rendering-stub",
),
);

for (wildcard_alias, request) in [
("react/", "next/dist/compiled/react/*"),
("react-dom/", "next/dist/compiled/react-dom/*"),
(
"react-server-dom-webpack/",
"next/dist/compiled/react-server-dom-webpack/*",
),
] {
import_map.insert_exact_alias(
package_name,
external_request_to_import_mapping(package_name),
);
import_map.insert_wildcard_alias(
format!("{}{}", package_name, "/"),
external_request_to_import_mapping(
format!("{}{}", package_name, "/*").as_str(),
),
);
let import_mapping = external_request_to_import_mapping(request);
import_map.insert_wildcard_alias(wildcard_alias, import_mapping);
}
}
(_, ServerContextType::Middleware) => {}
Expand Down
16 changes: 1 addition & 15 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"types": "index.d.ts",
"files": [
"dist",
"vendored",
"vendored/node_modules",
"app.js",
"app.d.ts",
"babel.js",
Expand Down Expand Up @@ -108,18 +106,6 @@
"optional": true
}
},
"optionalDependencies": {
"client-only-vendored": "file:vendored/node_modules/client-only-vendored",
"react-dom-experimental-vendored": "file:vendored/node_modules/react-dom-experimental-vendored",
"react-dom-vendored": "file:vendored/node_modules/react-dom-vendored",
"react-experimental-vendored": "file:vendored/node_modules/react-experimental-vendored",
"react-server-dom-webpack-experimental-vendored": "file:vendored/node_modules/react-server-dom-webpack-experimental-vendored",
"react-server-dom-webpack-vendored": "file:vendored/node_modules/react-server-dom-webpack-vendored",
"react-vendored": "file:vendored/node_modules/react-vendored",
"scheduler-experimental-vendored": "file:vendored/node_modules/scheduler-experimental-vendored",
"scheduler-vendored": "file:vendored/node_modules/scheduler-vendored",
"server-only-vendored": "file:vendored/node_modules/server-only-vendored"
},
"devDependencies": {
"@ampproject/toolbox-optimizer": "2.8.3",
"@babel/code-frame": "7.12.11",
Expand Down Expand Up @@ -197,7 +183,7 @@
"@types/webpack-sources1": "npm:@types/[email protected]",
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.23.0",
"@vercel/nft": "0.22.6",
"acorn": "8.5.0",
"ajv": "8.11.0",
"amphtml-validator": "1.0.35",
Expand Down
Loading

0 comments on commit 7bf3d77

Please sign in to comment.