豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 26cfeb8

Browse files
authored
Allow overriding outputHashSalt in modifyConfig (#92856)
1 parent f497222 commit 26cfeb8

File tree

17 files changed

+83
-75
lines changed

17 files changed

+83
-75
lines changed

crates/next-api/src/project.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ pub struct ProjectOptions {
370370

371371
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
372372
pub server_hmr: bool,
373-
374-
/// A salt to mix into chunk and asset content hashes, allowing users to
375-
/// force new filenames without changing file content. Empty string means
376-
/// no salt.
377-
pub hash_salt: RcStr,
378373
}
379374

380375
#[derive(Default)]
@@ -425,9 +420,6 @@ pub struct PartialProjectOptions {
425420
/// Debug build paths for selective builds.
426421
/// When set, only routes matching these paths will be included in the build.
427422
pub debug_build_paths: Option<DebugBuildPaths>,
428-
429-
/// An optional salt to mix into chunk and asset content hashes.
430-
pub hash_salt: Option<RcStr>,
431423
}
432424

433425
#[derive(
@@ -687,7 +679,6 @@ impl ProjectContainer {
687679
no_mangling,
688680
write_routes_hashes_manifest,
689681
debug_build_paths,
690-
hash_salt,
691682
} = options;
692683

693684
let mut new_options = this
@@ -738,9 +729,6 @@ impl ProjectContainer {
738729
if let Some(debug_build_paths) = debug_build_paths {
739730
new_options.debug_build_paths = Some(debug_build_paths);
740731
}
741-
if let Some(hash_salt) = hash_salt {
742-
new_options.hash_salt = hash_salt;
743-
}
744732

745733
// TODO: Handle mode switch, should prevent mode being switched.
746734
let watch = new_options.watch;
@@ -823,7 +811,6 @@ impl ProjectContainer {
823811
let deferred_entries;
824812
let is_persistent_caching_enabled;
825813
let server_hmr;
826-
let hash_salt;
827814
{
828815
let options = self.options_state.get();
829816
let options = options
@@ -852,7 +839,6 @@ impl ProjectContainer {
852839
deferred_entries = options.deferred_entries.clone().unwrap_or_default();
853840
is_persistent_caching_enabled = options.is_persistent_caching_enabled;
854841
server_hmr = options.server_hmr;
855-
hash_salt = options.hash_salt.clone();
856842
}
857843

858844
let root_path = ResolvedVc::cell(root_path_str);
@@ -884,7 +870,6 @@ impl ProjectContainer {
884870
deferred_entries,
885871
is_persistent_caching_enabled,
886872
server_hmr,
887-
hash_salt,
888873
}
889874
.cell())
890875
}
@@ -988,10 +973,6 @@ pub struct Project {
988973

989974
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
990975
server_hmr: bool,
991-
992-
/// A salt to mix into chunk and asset content hashes. Empty string means
993-
/// no salt.
994-
hash_salt: RcStr,
995976
}
996977

997978
#[turbo_tasks::value]
@@ -1249,11 +1230,6 @@ impl Project {
12491230
Vc::cell(self.no_mangling)
12501231
}
12511232

1252-
#[turbo_tasks::function]
1253-
pub(crate) fn hash_salt(&self) -> Vc<RcStr> {
1254-
Vc::cell(self.hash_salt.clone())
1255-
}
1256-
12571233
#[turbo_tasks::function]
12581234
pub(super) async fn execution_context(self: Vc<Self>) -> Result<Vc<ExecutionContext>> {
12591235
let node_root = self.node_root().owned().await?;
@@ -1609,7 +1585,7 @@ impl Project {
16091585
debug_ids: self.next_config().turbopack_debug_ids(),
16101586
should_use_absolute_url_references: self.next_config().inline_css(),
16111587
css_url_suffix,
1612-
hash_salt: self.hash_salt().to_resolved().await?,
1588+
hash_salt: self.next_config().output_hash_salt().to_resolved().await?,
16131589
cross_origin: self.next_config().cross_origin(),
16141590
}))
16151591
}
@@ -1645,7 +1621,7 @@ impl Project {
16451621
.await?,
16461622
asset_prefix: self.next_config().computed_asset_prefix().owned().await?,
16471623
css_url_suffix,
1648-
hash_salt: self.hash_salt().to_resolved().await?,
1624+
hash_salt: self.next_config().output_hash_salt().to_resolved().await?,
16491625
};
16501626
Ok(if client_assets {
16511627
get_server_chunking_context_with_client_assets(options)
@@ -1684,7 +1660,7 @@ impl Project {
16841660
.await?,
16851661
asset_prefix: self.next_config().computed_asset_prefix().owned().await?,
16861662
css_url_suffix,
1687-
hash_salt: self.hash_salt().to_resolved().await?,
1663+
hash_salt: self.next_config().output_hash_salt().to_resolved().await?,
16881664
cross_origin: self.next_config().cross_origin(),
16891665
};
16901666
Ok(if client_assets {

crates/next-api/src/project_asset_hashes_manifest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ impl Asset for AssetHashesManifestAsset {
143143
Ok((
144144
path,
145145
asset
146-
.content_hash(self.project.hash_salt(), HashAlgorithm::Xxh3Hash128Base38)
146+
.content_hash(
147+
self.project.next_config().output_hash_salt(),
148+
HashAlgorithm::Xxh3Hash128Base38,
149+
)
147150
.await?,
148151
))
149152
})

crates/next-build-test/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ fn main() {
190190
is_persistent_caching_enabled: false,
191191
next_version: rcstr!("0.0.0"),
192192
server_hmr: false,
193-
hash_salt: rcstr!(""),
194193
};
195194

196195
let json = serde_json::to_string_pretty(&options).unwrap();

crates/next-core/src/next_config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,10 @@ pub struct ExperimentalConfig {
10901090
runtime_server_deployment_id: Option<bool>,
10911091
supports_immutable_assets: Option<bool>,
10921092

1093+
/// A salt to mix into chunk and asset content hashes. Empty string means
1094+
/// no salt.
1095+
output_hash_salt: Option<RcStr>,
1096+
10931097
// ---
10941098
// UNSUPPORTED
10951099
// ---
@@ -2349,6 +2353,16 @@ impl NextConfig {
23492353
.collect::<Result<Vec<_>>>()?;
23502354
Ok(Vc::cell(rules))
23512355
}
2356+
2357+
#[turbo_tasks::function]
2358+
pub fn output_hash_salt(&self) -> Vc<RcStr> {
2359+
Vc::cell(
2360+
self.experimental
2361+
.output_hash_salt
2362+
.clone()
2363+
.unwrap_or_default(),
2364+
)
2365+
}
23522366
}
23532367

23542368
/// A subset of ts/jsconfig that next.js implicitly

crates/next-napi-bindings/src/next_api/project.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,6 @@ pub struct NapiProjectOptions {
216216

217217
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
218218
pub server_hmr: Option<bool>,
219-
220-
/// A salt to mix into chunk and asset content hashes, allowing users to
221-
/// force new filenames without changing file content. Empty string means
222-
/// no salt.
223-
pub hash_salt: RcStr,
224219
}
225220

226221
/// [NapiProjectOptions] with all fields optional.
@@ -271,9 +266,6 @@ pub struct NapiPartialProjectOptions {
271266
/// local names for variables, functions etc., which can be useful for
272267
/// debugging/profiling purposes.
273268
pub no_mangling: Option<bool>,
274-
275-
/// An optional salt to mix into chunk and asset content hashes.
276-
pub hash_salt: Option<RcStr>,
277269
}
278270

279271
#[napi(object)]
@@ -334,7 +326,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
334326
is_persistent_caching_enabled,
335327
next_version,
336328
server_hmr,
337-
hash_salt,
338329
} = val;
339330
ProjectOptions {
340331
root_path,
@@ -359,7 +350,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
359350
is_persistent_caching_enabled,
360351
next_version,
361352
server_hmr: server_hmr.unwrap_or(false),
362-
hash_salt,
363353
}
364354
}
365355
}
@@ -380,7 +370,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
380370
browserslist_query,
381371
no_mangling,
382372
write_routes_hashes_manifest,
383-
hash_salt,
384373
} = val;
385374
PartialProjectOptions {
386375
root_path,
@@ -397,7 +386,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
397386
no_mangling,
398387
write_routes_hashes_manifest,
399388
debug_build_paths: None,
400-
hash_salt,
401389
}
402390
}
403391
}

packages/next/src/build/swc/generated-native.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,6 @@ export interface NapiProjectOptions {
258258
nextVersion: RcStr
259259
/** Whether server-side HMR is enabled (disabled with --no-server-fast-refresh). */
260260
serverHmr?: boolean
261-
/**
262-
* A salt to mix into chunk and asset content hashes, allowing users to
263-
* force new filenames without changing file content. Empty string means
264-
* no salt.
265-
*/
266-
hashSalt: RcStr
267261
}
268262
/** [NapiProjectOptions] with all fields optional. */
269263
export interface NapiPartialProjectOptions {
@@ -308,8 +302,6 @@ export interface NapiPartialProjectOptions {
308302
* debugging/profiling purposes.
309303
*/
310304
noMangling?: boolean
311-
/** An optional salt to mix into chunk and asset content hashes. */
312-
hashSalt?: RcStr
313305
}
314306
export interface NapiDefineEnv {
315307
client: Array<NapiOptionEnvVar>

packages/next/src/build/turbopack-analyze/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export async function turbopackAnalyze(
9191
currentNodeJsVersion,
9292
isPersistentCachingEnabled: persistentCaching,
9393
nextVersion: process.env.__NEXT_VERSION as string,
94-
hashSalt: config.hashSalt,
9594
},
9695
{
9796
memoryLimit: config.experimental?.turbopackMemoryLimit,

packages/next/src/build/turbopack-build/impl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export async function turbopackBuild(): Promise<{
114114
isPersistentCachingEnabled: persistentCaching,
115115
deferredEntries: config.experimental.deferredEntries,
116116
nextVersion: process.env.__NEXT_VERSION as string,
117-
hashSalt: config.hashSalt,
118117
}
119118

120119
const sharedTurboOptions = {

packages/next/src/build/webpack-config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,9 @@ export default async function getBaseWebpackConfig(
13471347
hashDigestLength: 16,
13481348
// Webpack requires hashSalt to be a non-empty string; omit it entirely
13491349
// when no salt is configured.
1350-
...(config.hashSalt ? { hashSalt: config.hashSalt } : {}),
1350+
...(config.experimental?.outputHashSalt
1351+
? { hashSalt: config.experimental.outputHashSalt }
1352+
: {}),
13511353
},
13521354
performance: false,
13531355
resolve: resolveConfig,
@@ -1799,7 +1801,7 @@ export default async function getBaseWebpackConfig(
17991801
compilerType,
18001802
basePath: config.basePath,
18011803
assetPrefix: config.assetPrefix,
1802-
hashSalt: config.hashSalt,
1804+
outputHashSalt: config.experimental?.outputHashSalt,
18031805
},
18041806
},
18051807
]

packages/next/src/build/webpack/loaders/next-image-loader/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ interface Options {
1010
isDev: boolean
1111
assetPrefix: string
1212
basePath: string
13-
hashSalt: string
13+
outputHashSalt: string
1414
}
1515

1616
function nextImageLoader(this: any, content: Buffer) {
1717
const imageLoaderSpan = this.currentTraceSpan.traceChild('next-image-loader')
1818
return imageLoaderSpan.traceAsyncFn(async () => {
1919
const options: Options = this.getOptions()
20-
const { compilerType, isDev, assetPrefix, basePath, hashSalt } = options
20+
const { compilerType, isDev, assetPrefix, basePath, outputHashSalt } =
21+
options
2122
const context = this.rootContext
2223

2324
// Prepend the hash salt to the content for filename hash computation, so
2425
// that NEXT_HASH_SALT causes image filenames to change (like it does for
2526
// chunks). The actual file content is unaffected.
26-
const contentForHash = hashSalt
27-
? Buffer.concat([Buffer.from(hashSalt, 'utf8'), content])
27+
const contentForHash = outputHashSalt
28+
? Buffer.concat([Buffer.from(outputHashSalt, 'utf8'), content])
2829
: content
2930
const opts = { context, content: contentForHash }
3031
const interpolatedName = loaderUtils.interpolateName(

0 commit comments

Comments
 (0)