Unverified Commit 19048b82 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add metadata to server reference manifest (#82695)

This exposes additional metadata in the server reference manifest, it is
not directly used at this time though.
parent 2ad342a0
......@@ -174,16 +174,33 @@ async fn build_manifest(
NextRuntime::NodeJs => &mut manifest.node,
};
for (hash_id, (layer, _name, _module)) in actions_value {
// Collect all the action metadata including filenames
let mut action_metadata: Vec<(String, (ActionLayer, String, String))> = Vec::new();
for (hash_id, (layer, name, module)) in actions_value.iter() {
// Get the module path and use the full path
let module_path = module.ident().path().await?;
let full_path = module_path.to_string();
action_metadata.push((hash_id.clone(), (*layer, name.clone(), full_path)));
}
// Now create the manifest entries
for (hash_id, (layer, name, filename)) in &action_metadata {
let entry = mapping.entry(hash_id.as_str()).or_default();
entry.workers.insert(
&key,
ActionManifestWorkerEntry {
module_id: ActionManifestModuleId::String(loader_id.as_str()),
is_async: *async_module_info.is_async(chunk_item.module()).await?,
exported_name: name.as_str(),
filename: filename.as_str(),
},
);
entry.layer.insert(&key, *layer);
// Hoist the filename and exported_name to the entry level
entry.exported_name = name.as_str();
entry.filename = filename.as_str();
}
Ok(ResolvedVc::upcast(
......
......@@ -311,6 +311,11 @@ pub struct ActionManifestEntry<'a> {
pub workers: FxIndexMap<&'a str, ActionManifestWorkerEntry<'a>>,
pub layer: FxIndexMap<&'a str, ActionLayer>,
#[serde(rename = "exportedName")]
pub exported_name: &'a str,
pub filename: &'a str,
}
#[derive(Serialize, Debug)]
......@@ -319,6 +324,9 @@ pub struct ActionManifestWorkerEntry<'a> {
pub module_id: ActionManifestModuleId<'a>,
#[serde(rename = "async")]
pub is_async: bool,
#[serde(rename = "exportedName")]
pub exported_name: &'a str,
pub filename: &'a str,
}
#[derive(Serialize, Debug)]
......
......@@ -6,7 +6,7 @@ export type NextFlightActionEntryLoaderOptions = {
export type FlightActionEntryLoaderActions = [
path: string,
actions: { id: string; exportedName: string }[],
actions: { id: string; exportedName?: string; filename?: string }[],
][]
function nextFlightActionEntryLoader(
......
......@@ -62,8 +62,13 @@ const PLUGIN_NAME = 'FlightClientEntryPlugin'
type Actions = {
[actionId: string]: {
exportedName?: string
filename?: string
workers: {
[name: string]: { moduleId: string | number; async: boolean }
[name: string]: {
moduleId: string | number
async: boolean
}
}
// Record which layer the action is in (rsc or sc_action), in the specific entry.
layer: {
......@@ -72,7 +77,7 @@ type Actions = {
}
}
type ActionIdNamePair = { id: string; exportedName: string }
type ActionIdNamePair = { id: string; exportedName?: string; filename?: string }
export type ActionManifest = {
// Assign a unique encryption key during production build.
......@@ -92,11 +97,17 @@ const pluginState = getProxiedPluginState({
edgeServerActions: {} as ActionManifest['edge'],
serverActionModules: {} as {
[workerName: string]: { server?: ModuleInfo; client?: ModuleInfo }
[workerName: string]: {
server?: ModuleInfo
client?: ModuleInfo
}
},
edgeServerActionModules: {} as {
[workerName: string]: { server?: ModuleInfo; client?: ModuleInfo }
[workerName: string]: {
server?: ModuleInfo
client?: ModuleInfo
}
},
ssrModules: {} as { [ssrModuleId: string]: ModuleInfo },
......@@ -183,6 +194,7 @@ function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
export class FlightClientEntryPlugin {
dev: boolean
appDir: string
projectDir: string
encryptionKey: string
isEdgeServer: boolean
assetPrefix: string
......@@ -191,6 +203,7 @@ export class FlightClientEntryPlugin {
constructor(options: Options) {
this.dev = options.dev
this.appDir = options.appDir
this.projectDir = path.join(options.appDir, '..')
this.isEdgeServer = options.isEdgeServer
this.assetPrefix = !this.dev && !this.isEdgeServer ? '../' : ''
this.encryptionKey = options.encryptionKey
......@@ -628,6 +641,7 @@ export class FlightClientEntryPlugin {
Object.entries(actionIds).map(([id, exportedName]) => ({
id,
exportedName,
filename: path.posix.relative(this.projectDir, modResource),
}))
)
}
......@@ -728,6 +742,7 @@ export class FlightClientEntryPlugin {
Object.entries(actionIds).map(([id, exportedName]) => ({
id,
exportedName,
filename: path.posix.relative(this.projectDir, modResource),
})),
])
}
......@@ -949,11 +964,13 @@ export class FlightClientEntryPlugin {
: pluginState.serverActions
for (const [, actionsFromModule] of actionsArray) {
for (const { id } of actionsFromModule) {
for (const { id, exportedName, filename } of actionsFromModule) {
if (typeof currentCompilerServerActions[id] === 'undefined') {
currentCompilerServerActions[id] = {
workers: {},
layer: {},
filename,
exportedName,
}
}
currentCompilerServerActions[id].workers[bundlePath] = {
......@@ -1060,6 +1077,7 @@ export class FlightClientEntryPlugin {
if (!mapping[chunkGroup.name]) {
mapping[chunkGroup.name] = {}
}
mapping[chunkGroup.name][fromClient ? 'client' : 'server'] = {
moduleId: modId,
async: compilation.moduleGraph.isAsync(mod),
......
......@@ -203,6 +203,8 @@ export class TurbopackManifestLoader {
workers: {},
layer: {},
})
action.filename = other[key].filename
action.exportedName = other[key].exportedName
Object.assign(action.workers, other[key].workers)
Object.assign(action.layer, other[key].layer)
}
......
......@@ -29,6 +29,49 @@ describe('app-dir action handling', () => {
},
})
if (isNextStart) {
it('should output exportName and filename info in manifest', async () => {
const referenceManifest = await next.readJSON(
'.next/server/server-reference-manifest.json'
)
let foundExportNames = []
for (const item in referenceManifest.node) {
try {
const itemInfo = referenceManifest.node[item]
foundExportNames.push(itemInfo.exportedName)
expect(itemInfo.filename).toBeString()
// can be outside app dir but this test suite has them all in app
expect(itemInfo.filename.startsWith('app/')).toBe(true)
expect(itemInfo.exportedName).toBeString()
} catch (err) {
require('console').error(`Invalid action entry ${item}`, err)
throw err
}
}
for (const item in referenceManifest.edge) {
try {
const itemInfo = referenceManifest.edge[item]
foundExportNames.push(itemInfo.exportedName)
expect(itemInfo.filename).toBeString()
expect(itemInfo.exportedName).toBeString()
} catch (err) {
require('console').error(`Invalid action entry ${item}`, err)
throw err
}
}
expect(foundExportNames).toContain('setCookie')
expect(foundExportNames).toContain('getCookie')
expect(foundExportNames).toContain('getHeader')
expect(foundExportNames).toContain('setCookieWithMaxAge')
})
}
it('should handle action correctly with middleware rewrite', async () => {
const browser = await next.browser('/rewrite-to-static-first')
let actionRequestStatus: number | undefined
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment