Skip to content

Commit 7116931

Browse files
committed
fix: give precedence to functions from Frameworks API
1 parent f849de2 commit 7116931

File tree

8 files changed

+39
-2
lines changed

8 files changed

+39
-2
lines changed

packages/build/src/plugins_core/functions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const zipFunctionsAndLogResults = async ({
9292
// Printing an empty line before bundling output.
9393
log(logs, '')
9494

95-
const sourceDirectories = [frameworkFunctionsSrc, internalFunctionsSrc, functionsSrc].filter(Boolean)
95+
const sourceDirectories = [internalFunctionsSrc, frameworkFunctionsSrc, functionsSrc].filter(Boolean)
9696
const results = await zipItAndShipIt.zipFunctions(sourceDirectories, functionsDist, zisiParameters)
9797

9898
validateCustomRoutes(results)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default () => new Response("Generated in the internal functions directory")
2+
3+
export const config = {
4+
path: "/frameworks-internal-conflict/internal"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default () => new Response("Generated by the Frameworks API")
2+
3+
export const config = {
4+
path: "/frameworks-internal-conflict/frameworks"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default () => new Response("Generated by the Frameworks API")
2+
3+
export const config = {
4+
path: "/frameworks-user-conflict/frameworks"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default () => new Response("Generated by the user")
2+
3+
export const config = {
4+
path: "/frameworks-user-conflict/user"
5+
}

packages/build/tests/functions/snapshots/tests.js.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,16 @@ Generated by [AVA](https://avajs.dev).
423423
────────────────────────────────────────────────────────────────␊
424424
425425
Packaging Functions from .netlify/functions-internal directory:␊
426+
- frameworks-internal-conflict.mjs␊
426427
- server-internal.mjs␊
427428
428429
Packaging Functions generated by your framework:␊
430+
- frameworks-internal-conflict.mjs␊
431+
- frameworks-user-conflict.mjs␊
429432
- server.mjs␊
430433
431434
Packaging Functions from netlify/functions directory:␊
435+
- frameworks-user-conflict.mjs␊
432436
- user.ts␊
433437
434438
31 Bytes
Binary file not shown.

packages/build/tests/functions/tests.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readdir, rm, stat, writeFile } from 'fs/promises'
1+
import { readdir, readFile, rm, stat, writeFile } from 'fs/promises'
22
import { resolve } from 'path'
33
import { version as nodeVersion } from 'process'
44
import { fileURLToPath } from 'url'
@@ -149,6 +149,19 @@ test('Functions: loads functions from the `.netlify/functions-internal` director
149149
t.true(functionsDist.includes('user.zip'))
150150
t.true(functionsDist.includes('server-internal.zip'))
151151

152+
const manifest = await readFile(resolve(fixture.repositoryRoot, '.netlify/functions/manifest.json'), 'utf8')
153+
const { functions } = JSON.parse(manifest)
154+
155+
t.is(functions.length, 5)
156+
157+
// The Frameworks API takes precedence over the legacy internal directory.
158+
const frameworksInternalConflict = functions.find(({ name }) => name === 'frameworks-internal-conflict')
159+
t.is(frameworksInternalConflict.routes[0].pattern, '/frameworks-internal-conflict/frameworks')
160+
161+
// User code takes precedence over the Frameworks API.
162+
const frameworksUserConflict = functions.find(({ name }) => name === 'frameworks-user-conflict')
163+
t.is(frameworksUserConflict.routes[0].pattern, '/frameworks-user-conflict/user')
164+
152165
t.snapshot(normalizeOutput(output))
153166
})
154167

0 commit comments

Comments
 (0)