Skip to content

Commit e3083fb

Browse files
committed
share NEVER_EXTERNAL_RE
1 parent 3d4f6df commit e3083fb

File tree

11 files changed

+116
-93
lines changed

11 files changed

+116
-93
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/next-core/src/next_server/resolve.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::sync::LazyLock;
2-
31
use anyhow::Result;
4-
use regex::Regex;
2+
use next_taskless::NEVER_EXTERNAL_RE;
53
use serde::{Deserialize, Serialize};
64
use turbo_rcstr::{RcStr, rcstr};
75
use turbo_tasks::{NonLocalValue, ResolvedVc, Vc, trace::TraceRawVcs};
@@ -95,11 +93,6 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin {
9593
return Ok(ResolveResultOption::none());
9694
};
9795

98-
// from https://github.com/vercel/next.js/blob/8d1c619ad650f5d147207f267441caf12acd91d1/packages/next/src/build/handle-externals.ts#L188
99-
static NEVER_EXTERNAL_RE: LazyLock<Regex> = LazyLock::new(|| {
100-
Regex::new("^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|cache|document|link|form|head|image|legacy\\/image|constants|dynamic|script|navigation|headers|router|compat\\/router|server)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference|private-next-rsc-cache-wrapper$)").unwrap()
101-
});
102-
10396
let (Pattern::Constant(package), Pattern::Constant(package_subpath)) =
10497
(package, package_subpath)
10598
else {

crates/next-rspack/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.node

crates/next-rspack/Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/next-rspack/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ rustc-hash = { version = "2.1.1" }
2424
napi = { version = "=3.1.2" }
2525
napi-derive = { version = "=3.1.1" }
2626

27+
next-taskless = { path = "../next-taskless" }
28+
2729
# Enable SWC plugin feature for targets that support it
2830
# Skip: wasm32-wasip1-threads, i686-pc-windows-msvc, aarch64-pc-windows-msvc, armv7-linux-androideabi, armv7-unknown-linux-gnueabihf
2931
[target.'cfg(not(any(target_arch = "wasm32", target_arch = "arm", all(target_os = "windows", target_arch = "x86"), all(target_os = "windows", target_arch = "aarch64"))))'.dependencies]

crates/next-rspack/src/handle_externals.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
sync::{Arc, LazyLock},
66
};
77

8+
use next_taskless::NEVER_EXTERNAL_RE;
89
use once_cell::sync::OnceCell;
910
use regex::Regex;
1011
use rspack_core::{Alias, DependencyCategory, Resolve, ResolveOptionsWithDependencyType};
@@ -30,12 +31,6 @@ fn is_webpack_bundled_layer(layer: Option<&str>) -> bool {
3031
static REACT_PACKAGES_REGEX: LazyLock<Regex> =
3132
LazyLock::new(|| Regex::new(r"^(react|react-dom|react-server-dom-webpack)($|/)").unwrap());
3233

33-
static NOT_EXTERNAL_MODULES_REGEX: LazyLock<Regex> = LazyLock::new(|| {
34-
Regex::new(
35-
r"^(?:private-next-pages/|next/(?:dist/pages/|(?:app|cache|document|link|form|head|image|legacy/image|constants|dynamic|script|navigation|headers|router|compat/router|server)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference|private-next-rsc-cache-wrapper|private-next-rsc-track-dynamic-import$)"
36-
).unwrap()
37-
});
38-
3934
static NEXT_IMAGE_LOADER_REGEX: LazyLock<Regex> =
4035
LazyLock::new(|| Regex::new(r"^next[/\\]dist[/\\]shared[/\\]lib[/\\]image-loader").unwrap());
4136

@@ -268,7 +263,7 @@ impl ExternalHandler {
268263
}
269264

270265
// Skip modules that should not be external
271-
if NOT_EXTERNAL_MODULES_REGEX.is_match(&request) {
266+
if NEVER_EXTERNAL_RE.is_match(&request) {
272267
return Ok(None);
273268
}
274269
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
pub const BARREL_OPTIMIZATION_PREFIX: &str = "__barrel_optimize__";
2+
3+
pub const NODE_EXTERNALS: [&str; 64] = [
4+
"assert",
5+
"assert/strict",
6+
"async_hooks",
7+
"buffer",
8+
"child_process",
9+
"cluster",
10+
"console",
11+
"constants",
12+
"crypto",
13+
"dgram",
14+
"diagnostics_channel",
15+
"dns",
16+
"dns/promises",
17+
"domain",
18+
"events",
19+
"fs",
20+
"fs/promises",
21+
"http",
22+
"http2",
23+
"https",
24+
"inspector",
25+
"module",
26+
"net",
27+
"os",
28+
"path",
29+
"path/posix",
30+
"path/win32",
31+
"perf_hooks",
32+
"process",
33+
"punycode",
34+
"querystring",
35+
"readline",
36+
"repl",
37+
"stream",
38+
"stream/promises",
39+
"stream/web",
40+
"string_decoder",
41+
"sys",
42+
"timers",
43+
"timers/promises",
44+
"tls",
45+
"trace_events",
46+
"tty",
47+
"url",
48+
"util",
49+
"util/types",
50+
"v8",
51+
"vm",
52+
"wasi",
53+
"worker_threads",
54+
"zlib",
55+
"pnpapi",
56+
"_http_agent",
57+
"_http_client",
58+
"_http_common",
59+
"_http_incoming",
60+
"_http_outgoing",
61+
"_http_server",
62+
"_stream_duplex",
63+
"_stream_passthrough",
64+
"_stream_readable",
65+
"_stream_transform",
66+
"_stream_wrap",
67+
"_stream_writable",
68+
];
69+
70+
pub const EDGE_NODE_EXTERNALS: [&str; 5] = ["buffer", "events", "assert", "util", "async_hooks"];
71+
72+
pub const BUN_EXTERNALS: [&str; 6] = [
73+
"bun:ffi",
74+
"bun:jsc",
75+
"bun:sqlite",
76+
"bun:test",
77+
"bun:wrap",
78+
"bun",
79+
];

crates/next-taskless/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#![doc = include_str!("../README.md")]
22

3+
mod constants;
4+
mod patterns;
5+
36
use std::sync::LazyLock;
47

58
use anyhow::{Context, Result, bail};
9+
pub use constants::*;
10+
pub use patterns::*;
611
use regex::Regex;
712
use turbo_unix_path::{get_parent_path, get_relative_path_to, join_path, normalize_path};
813

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::sync::LazyLock;
2+
3+
use regex::Regex;
4+
5+
// from https://github.com/vercel/next.js/blob/8d1c619ad650f5d147207f267441caf12acd91d1/packages/next/src/build/handle-externals.ts#L188
6+
pub static NEVER_EXTERNAL_RE: LazyLock<Regex> = LazyLock::new(|| {
7+
Regex::new("^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|cache|document|link|form|head|image|legacy\\/image|constants|dynamic|script|navigation|headers|router|compat\\/router|server)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference|private-next-rsc-cache-wrapper|private-next-rsc-track-dynamic-import$)").unwrap()
8+
});

turbopack/crates/turbopack-resolve/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ turbo-rcstr = { workspace = true }
2222
turbo-tasks = { workspace = true }
2323
turbo-tasks-fs = { workspace = true }
2424
turbopack-core = { workspace = true }
25+
next-taskless = { workspace = true }
2526

2627
[build-dependencies]
2728
turbo-tasks-build = { workspace = true }

0 commit comments

Comments
 (0)