-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate functions manifest (#33770)
## Feature Reuse most of the part from manifest plugin to generate similar assets Resolves #33667 - [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [x] Related issues linked using `fixes #number` - [x] Integration tests added
- Loading branch information
Showing
5 changed files
with
387 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/next/build/webpack/plugins/functions-manifest-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { sources, webpack5 } from 'next/dist/compiled/webpack/webpack' | ||
import { collectAssets, getEntrypointInfo } from './middleware-plugin' | ||
import { FUNCTIONS_MANIFEST } from '../../../shared/lib/constants' | ||
|
||
const PLUGIN_NAME = 'FunctionsManifestPlugin' | ||
export interface FunctionsManifest { | ||
version: 1 | ||
pages: { | ||
[page: string]: { | ||
runtime: string | ||
env: string[] | ||
files: string[] | ||
name: string | ||
page: string | ||
regexp: string | ||
} | ||
} | ||
} | ||
|
||
export default class FunctionsManifestPlugin { | ||
dev: boolean | ||
webServerRuntime: boolean | ||
|
||
constructor({ | ||
dev, | ||
webServerRuntime, | ||
}: { | ||
dev: boolean | ||
webServerRuntime: boolean | ||
}) { | ||
this.dev = dev | ||
this.webServerRuntime = webServerRuntime | ||
} | ||
|
||
createAssets( | ||
compilation: webpack5.Compilation, | ||
assets: any, | ||
envPerRoute: Map<string, string[]>, | ||
webServerRuntime: boolean | ||
) { | ||
const functionsManifest: FunctionsManifest = { | ||
version: 1, | ||
pages: {}, | ||
} | ||
|
||
const infos = getEntrypointInfo(compilation, envPerRoute, webServerRuntime) | ||
infos.forEach((info) => { | ||
functionsManifest.pages[info.page] = { | ||
runtime: 'web', | ||
...info, | ||
} | ||
}) | ||
|
||
const assetPath = | ||
(this.webServerRuntime ? '' : 'server/') + FUNCTIONS_MANIFEST | ||
assets[assetPath] = new sources.RawSource( | ||
JSON.stringify(functionsManifest, null, 2) | ||
) | ||
} | ||
|
||
apply(compiler: webpack5.Compiler) { | ||
collectAssets(compiler, this.createAssets.bind(this), { | ||
dev: this.dev, | ||
pluginName: PLUGIN_NAME, | ||
webServerRuntime: this.webServerRuntime, | ||
}) | ||
} | ||
} |
Oops, something went wrong.