Skip to content

Commit b3766e4

Browse files
feat: stop logging V2 function detection (netlify/zip-it-and-ship-it#1711)
1 parent fb18992 commit b3766e4

File tree

6 files changed

+6
-47
lines changed

6 files changed

+6
-47
lines changed

packages/zip-it-and-ship-it/src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ModuleFormat } from './runtimes/node/utils/module_format.js'
99
import { GetSrcFilesFunction, RuntimeName, RUNTIME } from './runtimes/runtime.js'
1010
import { RuntimeCache } from './utils/cache.js'
1111
import { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js'
12-
import { getLogger } from './utils/logger.js'
1312

1413
export { Config, FunctionConfig } from './config.js'
1514
export { zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js'
@@ -54,7 +53,6 @@ const augmentWithStaticAnalysis = async (func: FunctionSource): Promise<Augmente
5453

5554
const staticAnalysisResult = await parseFile(func.mainFile, {
5655
functionName: func.name,
57-
logger: getLogger(),
5856
})
5957

6058
return { ...func, staticAnalysisResult }

packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName
22

33
import { InvocationMode, INVOCATION_MODE } from '../../../function.js'
44
import { FunctionBundlingUserError } from '../../../utils/error.js'
5-
import { Logger } from '../../../utils/logger.js'
65
import { nonNullable } from '../../../utils/non_nullable.js'
76
import { getRoutes, Route } from '../../../utils/routes.js'
87
import { RUNTIME } from '../../runtime.js'
@@ -31,7 +30,6 @@ export interface StaticAnalysisResult extends ISCValues {
3130

3231
interface FindISCDeclarationsOptions {
3332
functionName: string
34-
logger: Logger
3533
}
3634

3735
const validateScheduleFunction = (functionFound: boolean, scheduleFound: boolean, functionName: string): void => {
@@ -79,26 +77,23 @@ const normalizeMethods = (input: unknown, name: string): string[] | undefined =>
7977
*/
8078
export const parseFile = async (
8179
sourcePath: string,
82-
{ functionName, logger }: FindISCDeclarationsOptions,
80+
{ functionName }: FindISCDeclarationsOptions,
8381
): Promise<StaticAnalysisResult> => {
8482
const source = await safelyReadSource(sourcePath)
8583

8684
if (source === null) {
8785
return {}
8886
}
8987

90-
return parseSource(source, { functionName, logger })
88+
return parseSource(source, { functionName })
9189
}
9290

9391
/**
9492
* Takes a JS/TS source as a string, parses it into an AST, and returns a
9593
* series of data points, such as in-source configuration properties and
9694
* other metadata.
9795
*/
98-
export const parseSource = (
99-
source: string,
100-
{ functionName, logger }: FindISCDeclarationsOptions,
101-
): StaticAnalysisResult => {
96+
export const parseSource = (source: string, { functionName }: FindISCDeclarationsOptions): StaticAnalysisResult => {
10297
const ast = safelyParseSource(source)
10398

10499
if (ast === null) {
@@ -121,8 +116,6 @@ export const parseSource = (
121116
runtimeAPIVersion: 2,
122117
}
123118

124-
logger.system('detected v2 function')
125-
126119
if (typeof configExport.schedule === 'string') {
127120
result.schedule = configExport.schedule
128121
}

packages/zip-it-and-ship-it/src/runtimes/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const zipFunction: ZipFunction = async function ({
6262
return { config, path: destPath, entryFilename: '' }
6363
}
6464

65-
const staticAnalysisResult = await parseFile(mainFile, { functionName: name, logger })
65+
const staticAnalysisResult = await parseFile(mainFile, { functionName: name })
6666
const runtimeAPIVersion = staticAnalysisResult.runtimeAPIVersion === 2 ? 2 : 1
6767

6868
const pluginsModulesPath = await getPluginsModulesPath(srcDir)

packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test, vi } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22

33
import { parseSource } from '../../../../src/runtimes/node/in_source_config/index.js'
44
import { getLogger } from '../../../../src/utils/logger.js'
@@ -126,13 +126,8 @@ describe('V2 API', () => {
126126
const source = `export default async () => {
127127
return new Response("Hello!")
128128
}`
129+
const isc = parseSource(source, { ...options })
129130

130-
const systemLog = vi.fn()
131-
132-
const isc = parseSource(source, { ...options, logger: getLogger(systemLog) })
133-
134-
expect(systemLog).toHaveBeenCalledOnce()
135-
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
136131
expect(isc).toEqual({ inputModuleFormat: 'esm', routes: [], runtimeAPIVersion: 2 })
137132
})
138133

packages/zip-it-and-ship-it/tests/v2api.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,6 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
372372
expect(files[0].runtimeVersion).toBeUndefined()
373373
})
374374

375-
test('Logs to systemlog', async () => {
376-
const systemLog = vi.fn()
377-
378-
await zipFixture('v2-api', {
379-
fixtureDir: FIXTURES_ESM_DIR,
380-
opts: {
381-
systemLog,
382-
},
383-
})
384-
385-
expect(systemLog).toHaveBeenCalledOnce()
386-
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
387-
})
388-
389375
test('Does not log to systemlog for v1', async () => {
390376
const systemLog = vi.fn()
391377

packages/zip-it-and-ship-it/tests/zip_function.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,6 @@ describe('zipFunction', () => {
188188
expect(result.entryFilename).toEqual('___netlify-entry-point.mjs')
189189
})
190190

191-
test('Logs to systemlog', async () => {
192-
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
193-
const mainFile = join(FIXTURES_ESM_DIR, 'v2-api', 'function.js')
194-
const systemLog = vi.fn()
195-
196-
await zipFunction(mainFile, tmpDir, {
197-
systemLog,
198-
})
199-
200-
expect(systemLog).toHaveBeenCalledOnce()
201-
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
202-
})
203-
204191
test('Does not log to systemlog for v1', async () => {
205192
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
206193
const mainFile = join(FIXTURES_DIR, 'simple', 'function.js')

0 commit comments

Comments
 (0)