Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/build/tests/plugins/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1928,13 +1928,15 @@ Generated by [AVA](https://avajs.dev).
"extension": ".js",␊
"mainFile": "packages/build/tests/plugins/fixtures/functions_list/.netlify/functions-internal/internal_1.js",␊
"name": "internal_1",␊
"runtime": "js"␊
"runtime": "js",␊
"srcDir": "packages/build/tests/plugins/fixtures/functions_list/.netlify/functions-internal"␊
},␊
{␊
"extension": ".js",␊
"mainFile": "packages/build/tests/plugins/fixtures/functions_list/netlify/functions/user_1.js",␊
"name": "user_1",␊
"runtime": "js"␊
"runtime": "js",␊
"srcDir": "packages/build/tests/plugins/fixtures/functions_list/netlify/functions"␊
}␊
]␊
Expand Down
Binary file modified packages/build/tests/plugins/snapshots/tests.js.snap
Binary file not shown.
70 changes: 55 additions & 15 deletions packages/functions-utils/tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, rm } from 'fs/promises'
import { normalize } from 'path'
import { normalize, resolve } from 'path'
import { fileURLToPath } from 'url'

import cpy from 'cpy'
Expand Down Expand Up @@ -107,23 +107,30 @@ test('Should allow "fail" option to customize failures', async () => {
expect(fail).toHaveBeenCalledWith('No function source directory was specified')
})

const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extension, srcFile, schedule }) {
const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extension, srcDir, srcFile, schedule }) {
const mainFileA = normalize(`${fixtureDir}/${mainFile}`)
const srcFileA = srcFile === undefined ? {} : { srcFile: normalize(`${fixtureDir}/${srcFile}`) }
return { name, mainFile: mainFileA, runtime, extension, schedule, ...srcFileA }
const srcDirA = srcDir ? { srcDir: resolve(fixtureDir, srcDir) } : {}
return { name, mainFile: mainFileA, runtime, extension, schedule, ...srcFileA, ...srcDirA }
}

test('Can list function main files with list()', async () => {
const fixtureDir = `${FIXTURES_DIR}/list`
const functions = await list(fixtureDir)
expect(sortOn(functions, ['mainFile', 'extension'])).toEqual(
[
{ name: 'four', mainFile: 'four.js/four.js.js', runtime: 'js', extension: '.js' },
{ name: 'one', mainFile: 'one/index.js', runtime: 'js', extension: '.js' },
{ name: 'test', mainFile: 'test', runtime: 'go', extension: '' },
{ name: 'test', mainFile: 'test.js', runtime: 'js', extension: '.js' },
{ name: 'test', mainFile: 'test.zip', runtime: 'js', extension: '.zip' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js' },
{ name: 'four', mainFile: 'four.js/four.js.js', runtime: 'js', extension: '.js', srcDir: 'four.js' },
{
name: 'one',
mainFile: 'one/index.js',
runtime: 'js',
extension: '.js',
srcDir: 'one',
},
{ name: 'test', mainFile: 'test', runtime: 'go', extension: '', srcDir: '.' },
{ name: 'test', mainFile: 'test.js', runtime: 'js', extension: '.js', srcDir: '.' },
{ name: 'test', mainFile: 'test.zip', runtime: 'js', extension: '.zip', srcDir: '.' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcDir: 'two' },
].map(normalizeFiles.bind(null, fixtureDir)),
)
})
Expand All @@ -139,40 +146,73 @@ test('Can list all function files with listAll()', async () => {
runtime: 'js',
extension: '.js',
srcFile: 'four.js/four.js.js',
srcDir: 'four.js',
},
{
name: 'four',
mainFile: 'four.js/four.js.js',
runtime: 'js',
extension: '.json',
srcFile: '../../../package.json',
srcDir: 'four.js',
},
{
name: 'one',
mainFile: 'one/index.js',
runtime: 'js',
extension: '.js',
srcFile: 'one/index.js',
srcDir: 'one',
},
{ name: 'one', mainFile: 'one/index.js', runtime: 'js', extension: '.js', srcFile: 'one/index.js' },
{
name: 'one',
mainFile: 'one/index.js',
runtime: 'js',
extension: '.json',
srcFile: '../../../package.json',
srcDir: 'one',
},
{
name: 'test',
mainFile: 'test',
runtime: 'go',
extension: '',
srcFile: 'test',
srcDir: '.',
},
{
name: 'test',
mainFile: 'test.js',
runtime: 'js',
extension: '.js',
srcFile: 'test.js',
srcDir: '.',
},
{ name: 'test', mainFile: 'test', runtime: 'go', extension: '', srcFile: 'test' },
{ name: 'test', mainFile: 'test.js', runtime: 'js', extension: '.js', srcFile: 'test.js' },
{
name: 'test',
mainFile: 'test.js',
runtime: 'js',
extension: '.json',
srcFile: '../../../package.json',
srcDir: '.',
},
{
name: 'test',
mainFile: 'test.zip',
runtime: 'js',
extension: '.zip',
srcFile: 'test.zip',
srcDir: '.',
},
{ name: 'test', mainFile: 'test.zip', runtime: 'js', extension: '.zip', srcFile: 'test.zip' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/two.js' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/three.js' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/two.js', srcDir: 'two' },
{ name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/three.js', srcDir: 'two' },
{
name: 'two',
mainFile: 'two/two.js',
runtime: 'js',
extension: '.json',
srcFile: '../../../package.json',
srcDir: 'two',
},
].map(normalizeFiles.bind(null, fixtureDir)),
)
Expand Down
3 changes: 3 additions & 0 deletions packages/zip-it-and-ship-it/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ListedFunction {
inputModuleFormat?: ModuleFormat
excludedRoutes?: Route[]
routes?: ExtendedRoute[]
srcDir?: string
}

type ListedFunctionFile = ListedFunction & {
Expand Down Expand Up @@ -152,6 +153,7 @@ const getListedFunction = function ({
mainFile,
name,
runtime,
srcDir,
}: AugmentedFunctionSource): ListedFunction {
return {
displayName: config.name,
Expand All @@ -166,6 +168,7 @@ const getListedFunction = function ({
runtimeAPIVersion: staticAnalysisResult ? (staticAnalysisResult?.runtimeAPIVersion ?? 1) : undefined,
schedule: staticAnalysisResult?.config?.schedule ?? config.schedule,
inputModuleFormat: staticAnalysisResult?.inputModuleFormat,
srcDir,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`listFunction > V2 API > listFunction includes metadata properties when
"runtime": "js",
"runtimeAPIVersion": 2,
"schedule": undefined,
"srcDir": "v2-api-esm-ts-aliases",
"srcFile": undefined,
"timeout": undefined,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`listFunctions > V2 API > listFunctions includes routes when parseISC is
"runtime": "js",
"runtimeAPIVersion": 2,
"schedule": undefined,
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
}
Expand All @@ -43,6 +44,7 @@ exports[`listFunctions > V2 API > listFunctions includes runtimeAPIVersion when
"runtime": "js",
"runtimeAPIVersion": 2,
"schedule": undefined,
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
}
Expand All @@ -62,6 +64,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": ".netlify/internal-functions",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -77,6 +80,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": ".netlify/internal-functions",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -92,6 +96,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "netlify/functions",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -107,6 +112,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "netlify/functions",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -127,6 +133,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -142,6 +149,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -157,6 +165,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "five",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -172,6 +181,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "four.js",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -187,6 +197,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "one",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -202,6 +213,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "js",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "two",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -217,6 +229,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtime": "go",
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -237,6 +250,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -252,6 +266,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -267,6 +282,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -282,6 +298,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -297,6 +314,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -312,6 +330,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -327,6 +346,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -342,6 +362,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -357,6 +378,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -372,6 +394,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -387,6 +410,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -402,6 +426,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand All @@ -417,6 +442,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtime": "js",
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcDir": "",
"srcFile": undefined,
"timeout": undefined,
},
Expand Down
Loading
Loading