From 76d4250991bb4ec24d0f389144fb8588e50e62ef Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 28 Mar 2023 10:31:27 -0500 Subject: [PATCH 01/29] feat: updated funcmetadata to include edge --- .../runtime/src/helpers/functionsMetaData.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index c8e0972ded..440d017f7a 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -15,6 +15,11 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath return useNodeModulesPath ? packagePlugin.version : packagePlugin.dependencies[NEXT_PLUGIN] } +// Getting the path to the nextjs-plugin package.json file +const nodeModulesPath = resolveModuleRoot(NEXT_PLUGIN) ? join(resolveModuleRoot(NEXT_PLUGIN), 'package.json') : null +const pluginPackagePath = '.netlify/plugins/package.json' + + // The information needed to create a function configuration file export interface FunctionInfo { // The name of the function, e.g. `___netlify-handler` @@ -34,9 +39,6 @@ export interface FunctionInfo { */ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => { const { functionName, functionTitle, functionsDir } = functionInfo - const pluginPackagePath = '.netlify/plugins/package.json' - const moduleRoot = resolveModuleRoot(NEXT_PLUGIN) - const nodeModulesPath = moduleRoot ? join(moduleRoot, 'package.json') : null const nextPluginVersion = (await getNextRuntimeVersion(nodeModulesPath, true)) || @@ -54,3 +56,13 @@ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => await writeFile(join(functionsDir, functionName, `${functionName}.json`), JSON.stringify(metadata)) } + +export const writeEdgeFunctionConfiguration = async () => { + const nextPluginVersion = + (await getNextRuntimeVersion(nodeModulesPath, true)) || + (await getNextRuntimeVersion(pluginPackagePath, false)) || + // The runtime version should always be available, but if it's not, return 'unknown' + 'unknown' + + return `${NEXT_PLUGIN_NAME}@${nextPluginVersion}` +} From bba71726047f0b707db637909b2d8a58e8e16fa5 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 28 Mar 2023 10:31:51 -0500 Subject: [PATCH 02/29] feat: add generator to edge --- package-lock.json | 2 +- packages/runtime/src/helpers/edge.ts | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0dedb7505..8ce0d16ec2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24211,7 +24211,7 @@ }, "packages/runtime": { "name": "@netlify/plugin-nextjs", - "version": "4.32.2", + "version": "4.33.0", "license": "MIT", "dependencies": { "@netlify/esbuild": "0.14.39", diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index c845aebd54..809a1f7fab 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -13,9 +13,9 @@ import { outdent } from 'outdent' import { IMAGE_FUNCTION_NAME } from '../constants' import { getRequiredServerFiles, NextConfig } from './config' +import { writeEdgeFunctionConfiguration } from './functionsMetaData' import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers' import { RoutesManifest } from './types' - // This is the format as of next@12.2 interface EdgeFunctionDefinitionV1 { env: string[] @@ -57,12 +57,14 @@ export interface FunctionManifest { name?: string path: string cache?: 'manual' + generator?: string } | { function: string name?: string pattern: string cache?: 'manual' + generator?: string } > import_map?: string @@ -220,15 +222,17 @@ const generateEdgeFunctionMiddlewareMatchers = ({ const middlewareMatcherToEdgeFunctionDefinition = ( matcher: MiddlewareMatcher, name: string, + generator: string, cache?: 'manual', ): { function: string name?: string pattern: string cache?: 'manual' + generator?: string } => { const pattern = transformCaptureGroups(stripLookahead(matcher.regexp)) - return { function: name, pattern, name, cache } + return { function: name, pattern, name, cache, generator } } export const cleanupEdgeFunctions = ({ @@ -262,7 +266,7 @@ export const writeDevEdgeFunction = async ({ * Writes an edge function that routes RSC data requests to the `.rsc` route */ -export const writeRscDataEdgeFunction = async ({ +export const writeRscDataEdgeFunction = async ({ prerenderManifest, appPathRoutesManifest, }: { @@ -343,6 +347,9 @@ export const writeEdgeFunctions = async ({ netlifyConfig: NetlifyConfig routesManifest: RoutesManifest }) => { + + const nextjsPluginVersion = await writeEdgeFunctionConfiguration() + const manifest: FunctionManifest = { functions: [], version: 1, @@ -400,7 +407,7 @@ export const writeEdgeFunctions = async ({ }) manifest.functions.push( - ...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)), + ...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion)), ) } // Functions (i.e. not middleware, but edge SSR and API routes) @@ -440,6 +447,7 @@ export const writeEdgeFunctions = async ({ pattern, // cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir cache: usesAppDir ? 'manual' : undefined, + generator: `${nextjsPluginVersion}`, }) // pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page) @@ -449,6 +457,7 @@ export const writeEdgeFunctions = async ({ name: edgeFunctionDefinition.name, pattern: dataRoute, cache: usesAppDir ? 'manual' : undefined, + generator: `${nextjsPluginVersion}` }) } } @@ -474,6 +483,7 @@ export const writeEdgeFunctions = async ({ function: 'ipx', name: 'next/image handler', path: '/_next/image*', + generator: `${nextjsPluginVersion}` }) } else { console.log( @@ -487,6 +497,6 @@ export const writeEdgeFunctions = async ({ This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge `) } - + console.log('MANIFEST', manifest, nextjsPluginVersion) await writeJson(join(edgeFunctionRoot, 'manifest.json'), manifest) } From a52235078da84b99024daf4f68507efa9ac10473 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 28 Mar 2023 10:32:48 -0500 Subject: [PATCH 03/29] chore: prettier --- packages/runtime/src/helpers/edge.ts | 11 ++++++----- packages/runtime/src/helpers/functionsMetaData.ts | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index 809a1f7fab..832ea0ced3 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -266,7 +266,7 @@ export const writeDevEdgeFunction = async ({ * Writes an edge function that routes RSC data requests to the `.rsc` route */ -export const writeRscDataEdgeFunction = async ({ +export const writeRscDataEdgeFunction = async ({ prerenderManifest, appPathRoutesManifest, }: { @@ -347,7 +347,6 @@ export const writeEdgeFunctions = async ({ netlifyConfig: NetlifyConfig routesManifest: RoutesManifest }) => { - const nextjsPluginVersion = await writeEdgeFunctionConfiguration() const manifest: FunctionManifest = { @@ -407,7 +406,9 @@ export const writeEdgeFunctions = async ({ }) manifest.functions.push( - ...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion)), + ...matchers.map((matcher) => + middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion), + ), ) } // Functions (i.e. not middleware, but edge SSR and API routes) @@ -457,7 +458,7 @@ export const writeEdgeFunctions = async ({ name: edgeFunctionDefinition.name, pattern: dataRoute, cache: usesAppDir ? 'manual' : undefined, - generator: `${nextjsPluginVersion}` + generator: `${nextjsPluginVersion}`, }) } } @@ -483,7 +484,7 @@ export const writeEdgeFunctions = async ({ function: 'ipx', name: 'next/image handler', path: '/_next/image*', - generator: `${nextjsPluginVersion}` + generator: `${nextjsPluginVersion}`, }) } else { console.log( diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 440d017f7a..9383d60770 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -19,7 +19,6 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath const nodeModulesPath = resolveModuleRoot(NEXT_PLUGIN) ? join(resolveModuleRoot(NEXT_PLUGIN), 'package.json') : null const pluginPackagePath = '.netlify/plugins/package.json' - // The information needed to create a function configuration file export interface FunctionInfo { // The name of the function, e.g. `___netlify-handler` From 3158b22e998ec24b72aeba3ae8f86577b2f8c931 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 28 Mar 2023 16:12:17 -0500 Subject: [PATCH 04/29] feat: refactored nextpluginversion to use within writeEdge --- .../runtime/src/helpers/functionsMetaData.ts | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 9383d60770..8ba8749f97 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -19,6 +19,12 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath const nodeModulesPath = resolveModuleRoot(NEXT_PLUGIN) ? join(resolveModuleRoot(NEXT_PLUGIN), 'package.json') : null const pluginPackagePath = '.netlify/plugins/package.json' +const nextPluginVersion = async () => + (await getNextRuntimeVersion(nodeModulesPath, true)) || + (await getNextRuntimeVersion(pluginPackagePath, false)) || + // The runtime version should always be available, but if it's not, return 'unknown' + 'unknown' + // The information needed to create a function configuration file export interface FunctionInfo { // The name of the function, e.g. `___netlify-handler` @@ -38,30 +44,19 @@ export interface FunctionInfo { */ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => { const { functionName, functionTitle, functionsDir } = functionInfo - - const nextPluginVersion = - (await getNextRuntimeVersion(nodeModulesPath, true)) || - (await getNextRuntimeVersion(pluginPackagePath, false)) || - // The runtime version should always be available, but if it's not, return 'unknown' - 'unknown' + const pluginVersion = await nextPluginVersion() const metadata = { config: { name: functionTitle, - generator: `${NEXT_PLUGIN_NAME}@${nextPluginVersion}`, + generator: `${NEXT_PLUGIN_NAME}@${pluginVersion}`, }, version: 1, } - await writeFile(join(functionsDir, functionName, `${functionName}.json`), JSON.stringify(metadata)) } export const writeEdgeFunctionConfiguration = async () => { - const nextPluginVersion = - (await getNextRuntimeVersion(nodeModulesPath, true)) || - (await getNextRuntimeVersion(pluginPackagePath, false)) || - // The runtime version should always be available, but if it's not, return 'unknown' - 'unknown' - - return `${NEXT_PLUGIN_NAME}@${nextPluginVersion}` + const pluginVersion = await nextPluginVersion() + return `${NEXT_PLUGIN_NAME}@${pluginVersion}` } From ade49600433c682282f832be66b5709576dc83f2 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Thu, 30 Mar 2023 15:00:18 -0500 Subject: [PATCH 05/29] fix: updated func causing tests fails --- .../runtime/src/helpers/functionsMetaData.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 8ba8749f97..cac066ed30 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -15,16 +15,19 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath return useNodeModulesPath ? packagePlugin.version : packagePlugin.dependencies[NEXT_PLUGIN] } -// Getting the path to the nextjs-plugin package.json file -const nodeModulesPath = resolveModuleRoot(NEXT_PLUGIN) ? join(resolveModuleRoot(NEXT_PLUGIN), 'package.json') : null const pluginPackagePath = '.netlify/plugins/package.json' -const nextPluginVersion = async () => - (await getNextRuntimeVersion(nodeModulesPath, true)) || - (await getNextRuntimeVersion(pluginPackagePath, false)) || - // The runtime version should always be available, but if it's not, return 'unknown' - 'unknown' +const nextPluginVersion = async () => { + const moduleRoot = resolveModuleRoot(NEXT_PLUGIN) + const nodeModulesPath = moduleRoot ? join(moduleRoot, 'package.json') : null + return ( + (await getNextRuntimeVersion(nodeModulesPath, true)) || + (await getNextRuntimeVersion(pluginPackagePath, false)) || + // The runtime version should always be available, but if it's not, return 'unknown' + 'unknown' + ) +} // The information needed to create a function configuration file export interface FunctionInfo { // The name of the function, e.g. `___netlify-handler` @@ -53,6 +56,7 @@ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => }, version: 1, } + await writeFile(join(functionsDir, functionName, `${functionName}.json`), JSON.stringify(metadata)) } From cfebd772f08d27374339d8881812d0efcf26cec4 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Thu, 30 Mar 2023 17:11:22 -0500 Subject: [PATCH 06/29] feat: added testing for edge function generator --- test/functionsMetaData.spec.ts | 162 ++++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 2 deletions(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index 9c130d454f..f74d703ad6 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -1,8 +1,9 @@ -import { readJSON } from 'fs-extra' +import { readJSON, writeJSON } from 'fs-extra' import mock from 'mock-fs' import { join } from 'pathe' import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants' import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' +import { writeEdgeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' describe('writeFunctionConfiguration', () => { afterEach(() => { @@ -17,7 +18,7 @@ describe('writeFunctionConfiguration', () => { name: 'test', version: '1.0.0', dependencies: { - '@netlify/plugin-nextjs': '29.3.4', + // '@netlify/plugin-nextjs': '29.3.4', }, }), 'node_modules/@netlify/plugin-nextjs/package.json': JSON.stringify({ @@ -103,3 +104,160 @@ describe('writeFunctionConfiguration', () => { expect(actual).toEqual(expected) }) }) + +// EDGE FUNCTIONS + +describe('writeEdgeFunctionConfiguration', () => { + afterEach(() => { + mock.restore() + }) + + it('should write the configuration for an edge function using node modules version of @netlify/plugin-nextjs', async () => { + const nextRuntimeVersion = '23.4.5' + + mock({ + '.netlify/plugins/package.json': JSON.stringify({ + name: 'test', + version: '1.0.0', + dependencies: { + '@netlify/plugin-nextjs': '29.3.4', + }, + }), + 'node_modules/@netlify/plugin-nextjs/package.json': JSON.stringify({ + name: '@netlify/plugin-nextjs', + version: nextRuntimeVersion, + }), + '.netlify/edge-functions/manifest.json': JSON.stringify({ + "functions":[], + "version":1 + }), + }) + + const manifest = { + functions:[], + version:1 + } + + const functionName = 'someFunction' + const name = 'someFunctionName' + + const pluginVersion = await writeEdgeFunctionConfiguration() + + manifest.functions.push({ + functions: functionName, + name: name, + generator: pluginVersion + }) + + const expected = { + functions: [ + { + functions: functionName, + name: name, + generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, + } + ], + version: 1, + } + + const filePathToSaveTo = '.netlify/edge-functions/manifest.json' + await writeJSON(filePathToSaveTo, manifest) + const actual = await readJSON(filePathToSaveTo) + + expect(actual).toEqual(expected) + }) + + it('should write the configuration for a function using version of @netlify/plugin-nextjs in package.json', async () => { + const nextRuntimeVersion = '23.4.5' + + mock({ + '.netlify/plugins/package.json': JSON.stringify({ + name: 'test', + version: '1.0.0', + dependencies: { + '@netlify/plugin-nextjs': nextRuntimeVersion, + }, + }), + '.netlify/edge-functions/manifest.json': JSON.stringify({ + "functions":[], + "version":1 + }), + }) + + const manifest = { + functions:[], + version:1 + } + + const functionName = 'someFunction' + const name = 'someFunctionName' + + const pluginVersion = await writeEdgeFunctionConfiguration() + + manifest.functions.push({ + functions: functionName, + name: name, + generator: pluginVersion + }) + + const expected = { + functions: [ + { + functions: functionName, + name: name, + generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, + } + ], + version: 1, + } + + const filePathToSaveTo = '.netlify/edge-functions/manifest.json' + await writeJSON(filePathToSaveTo, manifest) + const actual = await readJSON(filePathToSaveTo) + + expect(actual).toEqual(expected) + }) + + it('should write the configuration for an edge function with runtime version not found', async () => { + mock({ + '.netlify/edge-functions/manifest.json': JSON.stringify({ + "functions":[], + "version":1 + }), + }) + + const manifest = { + functions:[], + version:1 + } + + const functionName = 'someFunction' + const name = 'someFunctionName' + + const pluginVersion = await writeEdgeFunctionConfiguration() + + manifest.functions.push({ + functions: functionName, + name: name, + generator: pluginVersion + }) + + const expected = { + functions: [ + { + functions: functionName, + name: name, + generator: '@netlify/next-runtime@unknown', + } + ], + version: 1, + } + + const filePathToSaveTo = '.netlify/edge-functions/manifest.json' + await writeJSON(filePathToSaveTo, manifest) + const actual = await readJSON(filePathToSaveTo) + + expect(actual).toEqual(expected) + }) +}) + From 3f0c121e7ca526385835fbcd8095cfbd2dffa106 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 3 Apr 2023 10:27:14 -0500 Subject: [PATCH 07/29] chore: removed console.log --- packages/runtime/src/helpers/edge.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index 832ea0ced3..da27ecaf73 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -498,6 +498,5 @@ export const writeEdgeFunctions = async ({ This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge `) } - console.log('MANIFEST', manifest, nextjsPluginVersion) await writeJson(join(edgeFunctionRoot, 'manifest.json'), manifest) } From 9c55d4b31876b991894dda7222352f776632f4ad Mon Sep 17 00:00:00 2001 From: Tatyana <43764894+taty2010@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:49:36 -0500 Subject: [PATCH 08/29] Update variable naming to match constants Co-authored-by: Nick Taylor --- packages/runtime/src/helpers/functionsMetaData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index cac066ed30..0298d3818a 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -15,7 +15,7 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath return useNodeModulesPath ? packagePlugin.version : packagePlugin.dependencies[NEXT_PLUGIN] } -const pluginPackagePath = '.netlify/plugins/package.json' +const PLUGIN_PACKAGE_PATH = '.netlify/plugins/package.json' const nextPluginVersion = async () => { const moduleRoot = resolveModuleRoot(NEXT_PLUGIN) From f69e2abe4040408039fc38b87ab85814e22a2914 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 3 Apr 2023 14:59:29 -0500 Subject: [PATCH 09/29] fix: fixed naming --- packages/runtime/src/helpers/functionsMetaData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 0298d3818a..a7caaac0c7 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -23,7 +23,7 @@ const nextPluginVersion = async () => { return ( (await getNextRuntimeVersion(nodeModulesPath, true)) || - (await getNextRuntimeVersion(pluginPackagePath, false)) || + (await getNextRuntimeVersion(PLUGIN_PACKAGE_PATH, false)) || // The runtime version should always be available, but if it's not, return 'unknown' 'unknown' ) From 7f89ed31a3c41ca126942916a2453c6466a3cd4e Mon Sep 17 00:00:00 2001 From: Tatyana <43764894+taty2010@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:17:20 -0500 Subject: [PATCH 10/29] Update test/functionsMetaData.spec.ts Co-authored-by: Nick Taylor --- test/functionsMetaData.spec.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index f74d703ad6..58560ffa18 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -134,29 +134,24 @@ describe('writeEdgeFunctionConfiguration', () => { }) const manifest = { - functions:[], - version:1 + functions: [ + { + functions: functionName, + name, + generator: pluginVersion, + }, + ], + version: 1, } - const functionName = 'someFunction' - const name = 'someFunctionName' - - const pluginVersion = await writeEdgeFunctionConfiguration() - - manifest.functions.push({ - functions: functionName, - name: name, - generator: pluginVersion - }) - const expected = { functions: [ { functions: functionName, - name: name, + name, generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, - } - ], + }, + ], version: 1, } From 1fbbe28101be714f3defd5bc78f646005c010876 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 3 Apr 2023 15:44:15 -0500 Subject: [PATCH 11/29] chore: refactoring test --- test/functionsMetaData.spec.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index 58560ffa18..0760b3cc63 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -133,10 +133,15 @@ describe('writeEdgeFunctionConfiguration', () => { }), }) + const functionName = 'someFunction' + const name = 'someFunctionName' + + const pluginVersion = await writeEdgeFunctionConfiguration() + const manifest = { functions: [ { - functions: functionName, + function: functionName, name, generator: pluginVersion, }, @@ -147,7 +152,7 @@ describe('writeEdgeFunctionConfiguration', () => { const expected = { functions: [ { - functions: functionName, + function: functionName, name, generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, }, @@ -190,16 +195,16 @@ describe('writeEdgeFunctionConfiguration', () => { const pluginVersion = await writeEdgeFunctionConfiguration() manifest.functions.push({ - functions: functionName, - name: name, + function: functionName, + name, generator: pluginVersion }) const expected = { functions: [ { - functions: functionName, - name: name, + function: functionName, + name, generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, } ], @@ -232,16 +237,16 @@ describe('writeEdgeFunctionConfiguration', () => { const pluginVersion = await writeEdgeFunctionConfiguration() manifest.functions.push({ - functions: functionName, - name: name, + function: functionName, + name, generator: pluginVersion }) const expected = { functions: [ { - functions: functionName, - name: name, + function: functionName, + name, generator: '@netlify/next-runtime@unknown', } ], From 66505170b750bca084082619e1b954419cc93398 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 3 Apr 2023 16:48:09 -0500 Subject: [PATCH 12/29] chore: added functionManifest interface within tests to catch errors --- test/functionsMetaData.spec.ts | 63 ++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index 0760b3cc63..ccbb06b880 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -4,6 +4,7 @@ import { join } from 'pathe' import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants' import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' import { writeEdgeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' +import { FunctionManifest } from '../packages/runtime/src/helpers/edge' describe('writeFunctionConfiguration', () => { afterEach(() => { @@ -135,15 +136,19 @@ describe('writeEdgeFunctionConfiguration', () => { const functionName = 'someFunction' const name = 'someFunctionName' + const cache = 'manual' + const pattern = '\\/pattern\\' const pluginVersion = await writeEdgeFunctionConfiguration() - const manifest = { + const manifest: FunctionManifest = { functions: [ { function: functionName, name, generator: pluginVersion, + cache, + pattern, }, ], version: 1, @@ -155,6 +160,8 @@ describe('writeEdgeFunctionConfiguration', () => { function: functionName, name, generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, + cache, + pattern, }, ], version: 1, @@ -183,22 +190,26 @@ describe('writeEdgeFunctionConfiguration', () => { "version":1 }), }) - - const manifest = { - functions:[], - version:1 - } const functionName = 'someFunction' const name = 'someFunctionName' + const cache = 'manual' + const pattern = '\\/pattern\\' const pluginVersion = await writeEdgeFunctionConfiguration() - - manifest.functions.push({ - function: functionName, - name, - generator: pluginVersion - }) + + const manifest: FunctionManifest = { + functions: [ + { + function: functionName, + name, + generator: pluginVersion, + cache, + pattern, + }, + ], + version: 1, + } const expected = { functions: [ @@ -206,6 +217,8 @@ describe('writeEdgeFunctionConfiguration', () => { function: functionName, name, generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, + cache, + pattern, } ], version: 1, @@ -225,22 +238,26 @@ describe('writeEdgeFunctionConfiguration', () => { "version":1 }), }) - - const manifest = { - functions:[], - version:1 - } const functionName = 'someFunction' const name = 'someFunctionName' + const cache = 'manual' + const pattern = '\\/pattern\\' const pluginVersion = await writeEdgeFunctionConfiguration() - manifest.functions.push({ - function: functionName, - name, - generator: pluginVersion - }) + const manifest: FunctionManifest = { + functions: [ + { + function: functionName, + name, + generator: pluginVersion, + cache, + pattern, + }, + ], + version: 1, + } const expected = { functions: [ @@ -248,6 +265,8 @@ describe('writeEdgeFunctionConfiguration', () => { function: functionName, name, generator: '@netlify/next-runtime@unknown', + cache, + pattern, } ], version: 1, From d6e073d646a7ea7a4ae54600a9deeb7f824c21a6 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 3 Apr 2023 17:08:02 -0500 Subject: [PATCH 13/29] chore: removed comment --- test/functionsMetaData.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index ccbb06b880..31e6c44bc2 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -19,7 +19,7 @@ describe('writeFunctionConfiguration', () => { name: 'test', version: '1.0.0', dependencies: { - // '@netlify/plugin-nextjs': '29.3.4', + '@netlify/plugin-nextjs': '29.3.4', }, }), 'node_modules/@netlify/plugin-nextjs/package.json': JSON.stringify({ From 6c0fada86e5ec39689ea2f6b27542f9be1c9f1f6 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 4 Apr 2023 15:33:49 -0500 Subject: [PATCH 14/29] chore: removed comment --- test/functionsMetaData.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index 31e6c44bc2..9325436136 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -106,8 +106,6 @@ describe('writeFunctionConfiguration', () => { }) }) -// EDGE FUNCTIONS - describe('writeEdgeFunctionConfiguration', () => { afterEach(() => { mock.restore() From 98a7f1f6469a64ac333c01d89b35e818d7296775 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Wed, 5 Apr 2023 13:38:39 -0500 Subject: [PATCH 15/29] chore: updated naming, refactored functionality, and removed tests --- packages/runtime/src/helpers/edge.ts | 4 +- .../runtime/src/helpers/functionsMetaData.ts | 11 +- test/functionsMetaData.spec.ts | 179 +----------------- 3 files changed, 8 insertions(+), 186 deletions(-) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index da27ecaf73..148be1cec5 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -13,7 +13,7 @@ import { outdent } from 'outdent' import { IMAGE_FUNCTION_NAME } from '../constants' import { getRequiredServerFiles, NextConfig } from './config' -import { writeEdgeFunctionConfiguration } from './functionsMetaData' +import { getPluginVersion } from './functionsMetaData' import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers' import { RoutesManifest } from './types' // This is the format as of next@12.2 @@ -347,7 +347,7 @@ export const writeEdgeFunctions = async ({ netlifyConfig: NetlifyConfig routesManifest: RoutesManifest }) => { - const nextjsPluginVersion = await writeEdgeFunctionConfiguration() + const nextjsPluginVersion = await getPluginVersion() const manifest: FunctionManifest = { functions: [], diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index a7caaac0c7..ad71c26e6d 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -28,6 +28,9 @@ const nextPluginVersion = async () => { 'unknown' ) } + +export const getPluginVersion = async () => `${NEXT_PLUGIN_NAME}@${await nextPluginVersion()}` + // The information needed to create a function configuration file export interface FunctionInfo { // The name of the function, e.g. `___netlify-handler` @@ -47,20 +50,14 @@ export interface FunctionInfo { */ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => { const { functionName, functionTitle, functionsDir } = functionInfo - const pluginVersion = await nextPluginVersion() const metadata = { config: { name: functionTitle, - generator: `${NEXT_PLUGIN_NAME}@${pluginVersion}`, + generator: await getPluginVersion(), }, version: 1, } await writeFile(join(functionsDir, functionName, `${functionName}.json`), JSON.stringify(metadata)) } - -export const writeEdgeFunctionConfiguration = async () => { - const pluginVersion = await nextPluginVersion() - return `${NEXT_PLUGIN_NAME}@${pluginVersion}` -} diff --git a/test/functionsMetaData.spec.ts b/test/functionsMetaData.spec.ts index 9325436136..b69e067d82 100644 --- a/test/functionsMetaData.spec.ts +++ b/test/functionsMetaData.spec.ts @@ -1,10 +1,8 @@ -import { readJSON, writeJSON } from 'fs-extra' +import { readJSON } from 'fs-extra' import mock from 'mock-fs' import { join } from 'pathe' import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants' import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' -import { writeEdgeFunctionConfiguration } from '../packages/runtime/src/helpers/functionsMetaData' -import { FunctionManifest } from '../packages/runtime/src/helpers/edge' describe('writeFunctionConfiguration', () => { afterEach(() => { @@ -104,177 +102,4 @@ describe('writeFunctionConfiguration', () => { expect(actual).toEqual(expected) }) -}) - -describe('writeEdgeFunctionConfiguration', () => { - afterEach(() => { - mock.restore() - }) - - it('should write the configuration for an edge function using node modules version of @netlify/plugin-nextjs', async () => { - const nextRuntimeVersion = '23.4.5' - - mock({ - '.netlify/plugins/package.json': JSON.stringify({ - name: 'test', - version: '1.0.0', - dependencies: { - '@netlify/plugin-nextjs': '29.3.4', - }, - }), - 'node_modules/@netlify/plugin-nextjs/package.json': JSON.stringify({ - name: '@netlify/plugin-nextjs', - version: nextRuntimeVersion, - }), - '.netlify/edge-functions/manifest.json': JSON.stringify({ - "functions":[], - "version":1 - }), - }) - - const functionName = 'someFunction' - const name = 'someFunctionName' - const cache = 'manual' - const pattern = '\\/pattern\\' - - const pluginVersion = await writeEdgeFunctionConfiguration() - - const manifest: FunctionManifest = { - functions: [ - { - function: functionName, - name, - generator: pluginVersion, - cache, - pattern, - }, - ], - version: 1, - } - - const expected = { - functions: [ - { - function: functionName, - name, - generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, - cache, - pattern, - }, - ], - version: 1, - } - - const filePathToSaveTo = '.netlify/edge-functions/manifest.json' - await writeJSON(filePathToSaveTo, manifest) - const actual = await readJSON(filePathToSaveTo) - - expect(actual).toEqual(expected) - }) - - it('should write the configuration for a function using version of @netlify/plugin-nextjs in package.json', async () => { - const nextRuntimeVersion = '23.4.5' - - mock({ - '.netlify/plugins/package.json': JSON.stringify({ - name: 'test', - version: '1.0.0', - dependencies: { - '@netlify/plugin-nextjs': nextRuntimeVersion, - }, - }), - '.netlify/edge-functions/manifest.json': JSON.stringify({ - "functions":[], - "version":1 - }), - }) - - const functionName = 'someFunction' - const name = 'someFunctionName' - const cache = 'manual' - const pattern = '\\/pattern\\' - - const pluginVersion = await writeEdgeFunctionConfiguration() - - const manifest: FunctionManifest = { - functions: [ - { - function: functionName, - name, - generator: pluginVersion, - cache, - pattern, - }, - ], - version: 1, - } - - const expected = { - functions: [ - { - function: functionName, - name, - generator: `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}`, - cache, - pattern, - } - ], - version: 1, - } - - const filePathToSaveTo = '.netlify/edge-functions/manifest.json' - await writeJSON(filePathToSaveTo, manifest) - const actual = await readJSON(filePathToSaveTo) - - expect(actual).toEqual(expected) - }) - - it('should write the configuration for an edge function with runtime version not found', async () => { - mock({ - '.netlify/edge-functions/manifest.json': JSON.stringify({ - "functions":[], - "version":1 - }), - }) - - const functionName = 'someFunction' - const name = 'someFunctionName' - const cache = 'manual' - const pattern = '\\/pattern\\' - - const pluginVersion = await writeEdgeFunctionConfiguration() - - const manifest: FunctionManifest = { - functions: [ - { - function: functionName, - name, - generator: pluginVersion, - cache, - pattern, - }, - ], - version: 1, - } - - const expected = { - functions: [ - { - function: functionName, - name, - generator: '@netlify/next-runtime@unknown', - cache, - pattern, - } - ], - version: 1, - } - - const filePathToSaveTo = '.netlify/edge-functions/manifest.json' - await writeJSON(filePathToSaveTo, manifest) - const actual = await readJSON(filePathToSaveTo) - - expect(actual).toEqual(expected) - }) -}) - +}) \ No newline at end of file From 22f19621a0aceeeee98983e8887924cbb662c29f Mon Sep 17 00:00:00 2001 From: taty2010 Date: Fri, 7 Apr 2023 11:20:03 -0500 Subject: [PATCH 16/29] chore: added new tests and added generator to rsc in edge --- packages/runtime/src/helpers/edge.ts | 3 + test/__snapshots__/index.spec.js.snap | 348 ++++++++++++++++++++++++++ test/index.spec.js | 33 +++ 3 files changed, 384 insertions(+) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index 148be1cec5..73df6ba79a 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -273,6 +273,7 @@ export const writeRscDataEdgeFunction = async ({ prerenderManifest?: PrerenderManifest appPathRoutesManifest?: Record }): Promise => { + const nextjsPluginVersion = await getPluginVersion() if (!prerenderManifest || !appPathRoutesManifest) { return [] } @@ -303,11 +304,13 @@ export const writeRscDataEdgeFunction = async ({ function: 'rsc-data', name: 'RSC data routing', path, + generator: `${nextjsPluginVersion}`, })), ...dynamicAppDirRoutes.map((pattern) => ({ function: 'rsc-data', name: 'RSC data routing', pattern, + generator: `${nextjsPluginVersion}`, })), ] } diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 2ed4316548..4fcfb68991 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -340,6 +340,354 @@ exports.resolvePages = () => { }" `; +exports[`onBuild() generates generator field within the edge-functions manifest 1`] = ` +Object { + "functions": Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image*", + }, + ], + "version": 1, +} +`; + +exports[`onBuild() generates generator field within the edge-functions manifest includes IPX 1`] = ` +Object { + "functions": Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image*", + }, + ], + "version": 1, +} +`; + exports[`onBuild() generates static files manifest 1`] = ` Array [ Array [ diff --git a/test/index.spec.js b/test/index.spec.js index 06a22330e8..70cdecb611 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -9,6 +9,14 @@ jest.mock('../packages/runtime/src/helpers/utils', () => { } }) +jest.mock('../packages/runtime/src/helpers/functionsMetaData', () => { + const { NEXT_PLUGIN_NAME } = require('../packages/runtime/src/constants') + return { + ...jest.requireActual('../packages/runtime/src/helpers/functionsMetaData'), + getPluginVersion: async () => `${NEXT_PLUGIN_NAME}@1.0.0`, + } +}) + const Chance = require('chance') const { writeJSON, @@ -730,6 +738,31 @@ describe('onBuild()', () => { expect(existsSync(path.join('.netlify', 'edge-functions', 'ipx', 'index.ts'))).toBeTruthy() }) + test('generates edge-functions manifest', async () => { + await moveNextDist() + await nextRuntime.onBuild(defaultArgs) + expect(existsSync(path.join('.netlify', 'edge-functions', 'manifest.json'))).toBeTruthy() + }) + + test('generates generator field within the edge-functions manifest', async () => { + await moveNextDist() + await nextRuntime.onBuild(defaultArgs) + const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') + const manifest = await readJson(manifestPath) + console.log(manifest.functions) + expect(manifest).toMatchSnapshot() + }) + + + test('generates generator field within the edge-functions manifest includes IPX', async () => { + process.env.NEXT_FORCE_EDGE_IMAGES = '1' + await moveNextDist() + await nextRuntime.onBuild(defaultArgs) + const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') + const manifest = await readJson(manifestPath) + expect(manifest).toMatchSnapshot() + }) + test('does not generate an ipx function when DISABLE_IPX is set', async () => { process.env.DISABLE_IPX = '1' await moveNextDist() From fc0e0159f1a37ad3b5adfe4ab742a18db8d6d760 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Fri, 7 Apr 2023 14:22:48 -0500 Subject: [PATCH 17/29] chore: updated snapshot --- test/__snapshots__/index.spec.js.snap | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 4fcfb68991..ea7dac225d 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -507,7 +507,13 @@ Object { "function": "ipx", "generator": "@netlify/next-runtime@1.0.0", "name": "next/image handler", - "path": "/_next/image*", + "path": "/_next/image/", + }, + ], + "layers": Array [ + Object { + "flag": "ipx-edge-function-layer-url", + "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", }, ], "version": 1, @@ -681,7 +687,13 @@ Object { "function": "ipx", "generator": "@netlify/next-runtime@1.0.0", "name": "next/image handler", - "path": "/_next/image*", + "path": "/_next/image/", + }, + ], + "layers": Array [ + Object { + "flag": "ipx-edge-function-layer-url", + "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", }, ], "version": 1, From af9ceac7df66fdaa075bbc3db250f5e356135bba Mon Sep 17 00:00:00 2001 From: taty2010 Date: Fri, 7 Apr 2023 14:44:12 -0500 Subject: [PATCH 18/29] fix: snapshot update with most recent changes --- test/__snapshots__/index.spec.js.snap | 116 +++++++++++++------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index ea7dac225d..29dd762789 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -347,133 +347,133 @@ Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", @@ -484,24 +484,24 @@ Object { }, Object { "cache": "manual", - "function": "next_pages_edge__id_", + "function": "next_pages_api_og", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", + "name": "pages/api/og", + "pattern": "^/api/og/?$", }, Object { "cache": "manual", "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + "pattern": "^/edge/([^/]+?)(?:/)?$", }, Object { "cache": "manual", - "function": "next_pages_api_og", + "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, Object { "function": "ipx", @@ -527,133 +527,133 @@ Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", @@ -664,24 +664,24 @@ Object { }, Object { "cache": "manual", - "function": "next_pages_edge__id_", + "function": "next_pages_api_og", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", + "name": "pages/api/og", + "pattern": "^/api/og/?$", }, Object { "cache": "manual", "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + "pattern": "^/edge/([^/]+?)(?:/)?$", }, Object { "cache": "manual", - "function": "next_pages_api_og", + "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, Object { "function": "ipx", From 07f997c829455681aa3d51f5ec2854d3f57528b4 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 10 Apr 2023 10:09:18 -0500 Subject: [PATCH 19/29] fix: new tests snapshot fix --- test/__snapshots__/index.spec.js.snap | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 29dd762789..c9faf551d3 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -482,13 +482,6 @@ Object { "name": "app/app-edge/page", "pattern": "^/app\\\\-edge(?:/)?$", }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, Object { "cache": "manual", "function": "next_pages_edge__id_", @@ -503,6 +496,13 @@ Object { "name": "pages/edge/[id]", "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, Object { "function": "ipx", "generator": "@netlify/next-runtime@1.0.0", @@ -662,13 +662,6 @@ Object { "name": "app/app-edge/page", "pattern": "^/app\\\\-edge(?:/)?$", }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, Object { "cache": "manual", "function": "next_pages_edge__id_", @@ -683,6 +676,13 @@ Object { "name": "pages/edge/[id]", "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, Object { "function": "ipx", "generator": "@netlify/next-runtime@1.0.0", From b701ddb97b99141ffd2aea6a36b54c4e92932088 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 10 Apr 2023 11:38:39 -0500 Subject: [PATCH 20/29] fix: testing --- test/__snapshots__/index.spec.js.snap | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index c9faf551d3..29dd762789 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -484,24 +484,24 @@ Object { }, Object { "cache": "manual", - "function": "next_pages_edge__id_", + "function": "next_pages_api_og", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", + "name": "pages/api/og", + "pattern": "^/api/og/?$", }, Object { "cache": "manual", "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + "pattern": "^/edge/([^/]+?)(?:/)?$", }, Object { "cache": "manual", - "function": "next_pages_api_og", + "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, Object { "function": "ipx", @@ -664,24 +664,24 @@ Object { }, Object { "cache": "manual", - "function": "next_pages_edge__id_", + "function": "next_pages_api_og", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", + "name": "pages/api/og", + "pattern": "^/api/og/?$", }, Object { "cache": "manual", "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + "pattern": "^/edge/([^/]+?)(?:/)?$", }, Object { "cache": "manual", - "function": "next_pages_api_og", + "function": "next_pages_edge__id_", "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", }, Object { "function": "ipx", From 75b214a86a7acb5baf8955f0fa595417546b0b6a Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 10 Apr 2023 11:54:33 -0500 Subject: [PATCH 21/29] fix: testing to see if tests pass after removing new test/snpshot --- test/__snapshots__/index.spec.js.snap | 360 -------------------------- test/index.spec.js | 19 -- 2 files changed, 379 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 29dd762789..2ed4316548 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -340,366 +340,6 @@ exports.resolvePages = () => { }" `; -exports[`onBuild() generates generator field within the edge-functions manifest 1`] = ` -Object { - "functions": Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, - ], - "layers": Array [ - Object { - "flag": "ipx-edge-function-layer-url", - "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", - }, - ], - "version": 1, -} -`; - -exports[`onBuild() generates generator field within the edge-functions manifest includes IPX 1`] = ` -Object { - "functions": Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, - ], - "layers": Array [ - Object { - "flag": "ipx-edge-function-layer-url", - "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", - }, - ], - "version": 1, -} -`; - exports[`onBuild() generates static files manifest 1`] = ` Array [ Array [ diff --git a/test/index.spec.js b/test/index.spec.js index 70cdecb611..98e4869a3a 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -744,25 +744,6 @@ describe('onBuild()', () => { expect(existsSync(path.join('.netlify', 'edge-functions', 'manifest.json'))).toBeTruthy() }) - test('generates generator field within the edge-functions manifest', async () => { - await moveNextDist() - await nextRuntime.onBuild(defaultArgs) - const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') - const manifest = await readJson(manifestPath) - console.log(manifest.functions) - expect(manifest).toMatchSnapshot() - }) - - - test('generates generator field within the edge-functions manifest includes IPX', async () => { - process.env.NEXT_FORCE_EDGE_IMAGES = '1' - await moveNextDist() - await nextRuntime.onBuild(defaultArgs) - const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') - const manifest = await readJson(manifestPath) - expect(manifest).toMatchSnapshot() - }) - test('does not generate an ipx function when DISABLE_IPX is set', async () => { process.env.DISABLE_IPX = '1' await moveNextDist() From 8b2a424a3651037b6066d8277b6a38e2ff3ca926 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 10 Apr 2023 13:06:01 -0500 Subject: [PATCH 22/29] chore: adding new tests back in --- test/__snapshots__/index.spec.js.snap | 360 ++++++++++++++++++++++++++ test/index.spec.js | 19 ++ 2 files changed, 379 insertions(+) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 2ed4316548..29dd762789 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -340,6 +340,366 @@ exports.resolvePages = () => { }" `; +exports[`onBuild() generates generator field within the edge-functions manifest 1`] = ` +Object { + "functions": Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image/", + }, + ], + "layers": Array [ + Object { + "flag": "ipx-edge-function-layer-url", + "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", + }, + ], + "version": 1, +} +`; + +exports[`onBuild() generates generator field within the edge-functions manifest includes IPX 1`] = ` +Object { + "functions": Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image/", + }, + ], + "layers": Array [ + Object { + "flag": "ipx-edge-function-layer-url", + "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", + }, + ], + "version": 1, +} +`; + exports[`onBuild() generates static files manifest 1`] = ` Array [ Array [ diff --git a/test/index.spec.js b/test/index.spec.js index 98e4869a3a..70cdecb611 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -744,6 +744,25 @@ describe('onBuild()', () => { expect(existsSync(path.join('.netlify', 'edge-functions', 'manifest.json'))).toBeTruthy() }) + test('generates generator field within the edge-functions manifest', async () => { + await moveNextDist() + await nextRuntime.onBuild(defaultArgs) + const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') + const manifest = await readJson(manifestPath) + console.log(manifest.functions) + expect(manifest).toMatchSnapshot() + }) + + + test('generates generator field within the edge-functions manifest includes IPX', async () => { + process.env.NEXT_FORCE_EDGE_IMAGES = '1' + await moveNextDist() + await nextRuntime.onBuild(defaultArgs) + const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') + const manifest = await readJson(manifestPath) + expect(manifest).toMatchSnapshot() + }) + test('does not generate an ipx function when DISABLE_IPX is set', async () => { process.env.DISABLE_IPX = '1' await moveNextDist() From 0b5f70ca38c7b3c59526147052e63b1c420154c0 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Thu, 13 Apr 2023 23:23:41 -0500 Subject: [PATCH 23/29] chore: removed string literals --- packages/runtime/src/helpers/edge.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index 9c2f75c306..bae94df565 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -305,13 +305,13 @@ export const writeRscDataEdgeFunction = async ({ function: 'rsc-data', name: 'RSC data routing', path, - generator: `${nextjsPluginVersion}`, + generator: nextjsPluginVersion, })), ...dynamicAppDirRoutes.map((pattern) => ({ function: 'rsc-data', name: 'RSC data routing', pattern, - generator: `${nextjsPluginVersion}`, + generator: nextjsPluginVersion, })), ] } @@ -453,7 +453,7 @@ export const writeEdgeFunctions = async ({ pattern, // cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir cache: usesAppDir ? 'manual' : undefined, - generator: `${nextjsPluginVersion}`, + generator: nextjsPluginVersion, }) // pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page) @@ -463,7 +463,7 @@ export const writeEdgeFunctions = async ({ name: edgeFunctionDefinition.name, pattern: dataRoute, cache: usesAppDir ? 'manual' : undefined, - generator: `${nextjsPluginVersion}`, + generator: nextjsPluginVersion, }) } } @@ -489,7 +489,7 @@ export const writeEdgeFunctions = async ({ function: 'ipx', name: 'next/image handler', path: nextConfig.images.path || '/_next/image', - generator: `${nextjsPluginVersion}`, + generator: nextjsPluginVersion, }) manifest.layers.push({ From 472bde3a6a4fa094ae0d3fc507f0f783ff620917 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Thu, 13 Apr 2023 23:24:32 -0500 Subject: [PATCH 24/29] fix: updated tests to now sort manifest data --- test/__snapshots__/index.spec.js.snap | 690 +++++++++++++------------- test/index.spec.js | 11 +- 2 files changed, 342 insertions(+), 359 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 29dd762789..ea0cf9a6bd 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -341,363 +341,345 @@ exports.resolvePages = () => { `; exports[`onBuild() generates generator field within the edge-functions manifest 1`] = ` -Object { - "functions": Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, - ], - "layers": Array [ - Object { - "flag": "ipx-edge-function-layer-url", - "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", - }, - ], - "version": 1, -} +Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image/", + }, +] `; exports[`onBuild() generates generator field within the edge-functions manifest includes IPX 1`] = ` -Object { - "functions": Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, - ], - "layers": Array [ - Object { - "flag": "ipx-edge-function-layer-url", - "name": "https://ipx-edge-function-layer.netlify.app/mod.ts", - }, - ], - "version": 1, -} +Array [ + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob/second-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica/first-post.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/nick.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/sarah.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/rob.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "path": "/blog/erica.rsc", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)(?:/)?$", + }, + Object { + "function": "rsc-data", + "generator": "@netlify/next-runtime@1.0.0", + "name": "RSC data routing", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", + }, + Object { + "cache": "manual", + "function": "next_app_app_edge_page", + "generator": "@netlify/next-runtime@1.0.0", + "name": "app/app-edge/page", + "pattern": "^/app\\\\-edge(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_api_og", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/api/og", + "pattern": "^/api/og/?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/edge/([^/]+?)(?:/)?$", + }, + Object { + "cache": "manual", + "function": "next_pages_edge__id_", + "generator": "@netlify/next-runtime@1.0.0", + "name": "pages/edge/[id]", + "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", + }, + Object { + "function": "ipx", + "generator": "@netlify/next-runtime@1.0.0", + "name": "next/image handler", + "path": "/_next/image/", + }, +] `; exports[`onBuild() generates static files manifest 1`] = ` diff --git a/test/index.spec.js b/test/index.spec.js index 70cdecb611..4a2fb7e511 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -747,9 +747,9 @@ describe('onBuild()', () => { test('generates generator field within the edge-functions manifest', async () => { await moveNextDist() await nextRuntime.onBuild(defaultArgs) - const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') - const manifest = await readJson(manifestPath) - console.log(manifest.functions) + const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) + const manifest = manifestPath.functions.sort() + expect(manifest).toMatchSnapshot() }) @@ -758,8 +758,9 @@ describe('onBuild()', () => { process.env.NEXT_FORCE_EDGE_IMAGES = '1' await moveNextDist() await nextRuntime.onBuild(defaultArgs) - const manifestPath = path.join('.netlify', 'edge-functions', 'manifest.json') - const manifest = await readJson(manifestPath) + const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) + const manifest = manifestPath.functions.sort() + expect(manifest).toMatchSnapshot() }) From 2dc856a468bffe5925bc6c041aae89f54f32eb98 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 17 Apr 2023 11:07:45 -0500 Subject: [PATCH 25/29] chore: renaming and adding gen to dev edge --- packages/runtime/src/helpers/edge.ts | 26 +++--- .../runtime/src/helpers/functionsMetaData.ts | 3 +- test/__snapshots__/index.spec.js.snap | 88 +++++++++---------- 3 files changed, 59 insertions(+), 58 deletions(-) diff --git a/packages/runtime/src/helpers/edge.ts b/packages/runtime/src/helpers/edge.ts index bae94df565..12c5977d47 100644 --- a/packages/runtime/src/helpers/edge.ts +++ b/packages/runtime/src/helpers/edge.ts @@ -57,14 +57,14 @@ export interface FunctionManifest { name?: string path: string cache?: 'manual' - generator?: string + generator: string } | { function: string name?: string pattern: string cache?: 'manual' - generator?: string + generator: string } > layers?: Array<{ name: `https://${string}/mod.ts`; flag: string }> @@ -230,7 +230,7 @@ const middlewareMatcherToEdgeFunctionDefinition = ( name?: string pattern: string cache?: 'manual' - generator?: string + generator: string } => { const pattern = transformCaptureGroups(stripLookahead(matcher.regexp)) return { function: name, pattern, name, cache, generator } @@ -243,12 +243,14 @@ export const cleanupEdgeFunctions = ({ export const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions', }: NetlifyPluginConstants) => { + const generator = await getPluginVersion() const manifest: FunctionManifest = { functions: [ { function: 'next-dev', name: 'netlify dev handler', path: '/*', + generator, }, ], version: 1, @@ -274,7 +276,7 @@ export const writeRscDataEdgeFunction = async ({ prerenderManifest?: PrerenderManifest appPathRoutesManifest?: Record }): Promise => { - const nextjsPluginVersion = await getPluginVersion() + const generator = await getPluginVersion() if (!prerenderManifest || !appPathRoutesManifest) { return [] } @@ -305,13 +307,13 @@ export const writeRscDataEdgeFunction = async ({ function: 'rsc-data', name: 'RSC data routing', path, - generator: nextjsPluginVersion, + generator, })), ...dynamicAppDirRoutes.map((pattern) => ({ function: 'rsc-data', name: 'RSC data routing', pattern, - generator: nextjsPluginVersion, + generator, })), ] } @@ -351,7 +353,7 @@ export const writeEdgeFunctions = async ({ netlifyConfig: NetlifyConfig routesManifest: RoutesManifest }) => { - const nextjsPluginVersion = await getPluginVersion() + const generator = await getPluginVersion() const manifest: FunctionManifest = { functions: [], @@ -411,9 +413,7 @@ export const writeEdgeFunctions = async ({ }) manifest.functions.push( - ...matchers.map((matcher) => - middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion), - ), + ...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, generator)), ) } // Functions (i.e. not middleware, but edge SSR and API routes) @@ -453,7 +453,7 @@ export const writeEdgeFunctions = async ({ pattern, // cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir cache: usesAppDir ? 'manual' : undefined, - generator: nextjsPluginVersion, + generator, }) // pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page) @@ -463,7 +463,7 @@ export const writeEdgeFunctions = async ({ name: edgeFunctionDefinition.name, pattern: dataRoute, cache: usesAppDir ? 'manual' : undefined, - generator: nextjsPluginVersion, + generator, }) } } @@ -489,7 +489,7 @@ export const writeEdgeFunctions = async ({ function: 'ipx', name: 'next/image handler', path: nextConfig.images.path || '/_next/image', - generator: nextjsPluginVersion, + generator, }) manifest.layers.push({ diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index ad71c26e6d..897de45f9d 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -50,11 +50,12 @@ export interface FunctionInfo { */ export const writeFunctionConfiguration = async (functionInfo: FunctionInfo) => { const { functionName, functionTitle, functionsDir } = functionInfo + const generator = await getPluginVersion() const metadata = { config: { name: functionTitle, - generator: await getPluginVersion(), + generator, }, version: 1, } diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index ea0cf9a6bd..f186e012f4 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -346,133 +346,133 @@ Array [ "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", @@ -517,133 +517,133 @@ Array [ "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", From 430e985ac5951f2a1ebe66c210c248531fd25cfb Mon Sep 17 00:00:00 2001 From: taty2010 Date: Mon, 17 Apr 2023 11:40:03 -0500 Subject: [PATCH 26/29] fix: snapshot --- test/__snapshots__/index.spec.js.snap | 88 +++++++++++++-------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index f186e012f4..ea0cf9a6bd 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -346,133 +346,133 @@ Array [ "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", @@ -517,133 +517,133 @@ Array [ "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick", + "path": "/blog/nick/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick.rsc", + "path": "/blog/nick/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah", + "path": "/blog/nick/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah.rsc", + "path": "/blog/nick/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob", + "path": "/blog/sarah/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob.rsc", + "path": "/blog/sarah/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica", + "path": "/blog/rob/second-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica.rsc", + "path": "/blog/rob/second-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post", + "path": "/blog/erica/first-post", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", + "path": "/blog/erica/first-post.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post", + "path": "/blog/nick", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", + "path": "/blog/nick.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post", + "path": "/blog/sarah", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", + "path": "/blog/sarah.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post", + "path": "/blog/rob", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", + "path": "/blog/rob.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post", + "path": "/blog/erica", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", + "path": "/blog/erica.rsc", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", + "pattern": "^/blog/([^/]+?)(?:/)?$", }, Object { "function": "rsc-data", "generator": "@netlify/next-runtime@1.0.0", "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", + "pattern": "^/blog/([^/]+?)\\\\.rsc$", }, Object { "cache": "manual", From 85f8f22f41a316cd3b8e3bb714a146985faf91bc Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 18 Apr 2023 13:10:14 -0500 Subject: [PATCH 27/29] fix: removed snapshot testing and updated rsc tests --- test/edge.spec.ts | 12 ++++++++++++ test/index.spec.js | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/test/edge.spec.ts b/test/edge.spec.ts index 80d6d782ce..a3411714d3 100644 --- a/test/edge.spec.ts +++ b/test/edge.spec.ts @@ -1,6 +1,14 @@ import { generateRscDataEdgeManifest } from '../packages/runtime/src/helpers/edge' import type { PrerenderManifest } from 'next/dist/build' +jest.mock('../packages/runtime/src/helpers/functionsMetaData', () => { + const { NEXT_PLUGIN_NAME } = require('../packages/runtime/src/constants') + return { + ...jest.requireActual('../packages/runtime/src/helpers/functionsMetaData'), + getPluginVersion: async () => `${NEXT_PLUGIN_NAME}@1.0.0`, + } +}) + const basePrerenderManifest: PrerenderManifest = { version: 3, routes: {}, @@ -33,11 +41,13 @@ describe('generateRscDataEdgeManifest', () => { expect(edgeManifest).toEqual([ { function: 'rsc-data', + generator: "@netlify/next-runtime@1.0.0", name: 'RSC data routing', path: '/', }, { function: 'rsc-data', + generator: "@netlify/next-runtime@1.0.0", name: 'RSC data routing', path: '/index.rsc', }, @@ -84,11 +94,13 @@ describe('generateRscDataEdgeManifest', () => { expect(edgeManifest).toEqual([ { function: 'rsc-data', + generator: "@netlify/next-runtime@1.0.0", name: 'RSC data routing', pattern: '^/blog/([^/]+?)(?:/)?$', }, { function: 'rsc-data', + generator: "@netlify/next-runtime@1.0.0", name: 'RSC data routing', pattern: '^/blog/([^/]+?)\\.rsc$', }, diff --git a/test/index.spec.js b/test/index.spec.js index 4a2fb7e511..a2a23b4751 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -750,7 +750,13 @@ describe('onBuild()', () => { const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) const manifest = manifestPath.functions.sort() - expect(manifest).toMatchSnapshot() + expect(manifest).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + generator: '@netlify/next-runtime@1.0.0' + }) + ]) + ) }) @@ -761,7 +767,13 @@ describe('onBuild()', () => { const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) const manifest = manifestPath.functions.sort() - expect(manifest).toMatchSnapshot() + expect(manifest).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + generator: '@netlify/next-runtime@1.0.0' + }) + ]) + ) }) test('does not generate an ipx function when DISABLE_IPX is set', async () => { From 0f3252e50e9212a17acb34204d1e5e1cf6f9ca76 Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 18 Apr 2023 14:04:43 -0500 Subject: [PATCH 28/29] chore: forgot to remove obsolete snapshots --- test/__snapshots__/index.spec.js.snap | 342 -------------------------- 1 file changed, 342 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index ea0cf9a6bd..2ed4316548 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -340,348 +340,6 @@ exports.resolvePages = () => { }" `; -exports[`onBuild() generates generator field within the edge-functions manifest 1`] = ` -Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, -] -`; - -exports[`onBuild() generates generator field within the edge-functions manifest includes IPX 1`] = ` -Array [ - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob/second-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica/first-post.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/nick.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/sarah.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/rob.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "path": "/blog/erica.rsc", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)/([^/]+?)\\\\.rsc$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)(?:/)?$", - }, - Object { - "function": "rsc-data", - "generator": "@netlify/next-runtime@1.0.0", - "name": "RSC data routing", - "pattern": "^/blog/([^/]+?)\\\\.rsc$", - }, - Object { - "cache": "manual", - "function": "next_app_app_edge_page", - "generator": "@netlify/next-runtime@1.0.0", - "name": "app/app-edge/page", - "pattern": "^/app\\\\-edge(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_api_og", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/api/og", - "pattern": "^/api/og/?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/edge/([^/]+?)(?:/)?$", - }, - Object { - "cache": "manual", - "function": "next_pages_edge__id_", - "generator": "@netlify/next-runtime@1.0.0", - "name": "pages/edge/[id]", - "pattern": "^/_next/data/build\\\\-id/edge/([^/]+?)\\\\.json$", - }, - Object { - "function": "ipx", - "generator": "@netlify/next-runtime@1.0.0", - "name": "next/image handler", - "path": "/_next/image/", - }, -] -`; - exports[`onBuild() generates static files manifest 1`] = ` Array [ Array [ From 63e791d539c6001b64ff8af0beac0d1c18bf7a7d Mon Sep 17 00:00:00 2001 From: taty2010 Date: Tue, 18 Apr 2023 23:10:40 -0500 Subject: [PATCH 29/29] chore: sort not needed --- test/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index a2a23b4751..a188544851 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -748,7 +748,7 @@ describe('onBuild()', () => { await moveNextDist() await nextRuntime.onBuild(defaultArgs) const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) - const manifest = manifestPath.functions.sort() + const manifest = manifestPath.functions expect(manifest).toEqual( expect.arrayContaining([ @@ -765,7 +765,7 @@ describe('onBuild()', () => { await moveNextDist() await nextRuntime.onBuild(defaultArgs) const manifestPath = await readJson(path.resolve('.netlify/edge-functions/manifest.json')) - const manifest = manifestPath.functions.sort() + const manifest = manifestPath.functions expect(manifest).toEqual( expect.arrayContaining([