Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: stop logging V2 function detection (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored Feb 20, 2024
1 parent ee501c7 commit 2c25489
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ModuleFormat } from './runtimes/node/utils/module_format.js'
import { GetSrcFilesFunction, RuntimeName, RUNTIME } from './runtimes/runtime.js'
import { RuntimeCache } from './utils/cache.js'
import { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js'
import { getLogger } from './utils/logger.js'

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

const staticAnalysisResult = await parseFile(func.mainFile, {
functionName: func.name,
logger: getLogger(),
})

return { ...func, staticAnalysisResult }
Expand Down
13 changes: 3 additions & 10 deletions src/runtimes/node/in_source_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName

import { InvocationMode, INVOCATION_MODE } from '../../../function.js'
import { FunctionBundlingUserError } from '../../../utils/error.js'
import { Logger } from '../../../utils/logger.js'
import { nonNullable } from '../../../utils/non_nullable.js'
import { getRoutes, Route } from '../../../utils/routes.js'
import { RUNTIME } from '../../runtime.js'
Expand Down Expand Up @@ -31,7 +30,6 @@ export interface StaticAnalysisResult extends ISCValues {

interface FindISCDeclarationsOptions {
functionName: string
logger: Logger
}

const validateScheduleFunction = (functionFound: boolean, scheduleFound: boolean, functionName: string): void => {
Expand Down Expand Up @@ -79,26 +77,23 @@ const normalizeMethods = (input: unknown, name: string): string[] | undefined =>
*/
export const parseFile = async (
sourcePath: string,
{ functionName, logger }: FindISCDeclarationsOptions,
{ functionName }: FindISCDeclarationsOptions,
): Promise<StaticAnalysisResult> => {
const source = await safelyReadSource(sourcePath)

if (source === null) {
return {}
}

return parseSource(source, { functionName, logger })
return parseSource(source, { functionName })
}

/**
* Takes a JS/TS source as a string, parses it into an AST, and returns a
* series of data points, such as in-source configuration properties and
* other metadata.
*/
export const parseSource = (
source: string,
{ functionName, logger }: FindISCDeclarationsOptions,
): StaticAnalysisResult => {
export const parseSource = (source: string, { functionName }: FindISCDeclarationsOptions): StaticAnalysisResult => {
const ast = safelyParseSource(source)

if (ast === null) {
Expand All @@ -121,8 +116,6 @@ export const parseSource = (
runtimeAPIVersion: 2,
}

logger.system('detected v2 function')

if (typeof configExport.schedule === 'string') {
result.schedule = configExport.schedule
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const zipFunction: ZipFunction = async function ({
return { config, path: destPath, entryFilename: '' }
}

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

const pluginsModulesPath = await getPluginsModulesPath(srcDir)
Expand Down
9 changes: 2 additions & 7 deletions tests/unit/runtimes/node/in_source_config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test, vi } from 'vitest'
import { describe, expect, test } from 'vitest'

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

const systemLog = vi.fn()

const isc = parseSource(source, { ...options, logger: getLogger(systemLog) })

expect(systemLog).toHaveBeenCalledOnce()
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
expect(isc).toEqual({ inputModuleFormat: 'esm', routes: [], runtimeAPIVersion: 2 })
})

Expand Down
14 changes: 0 additions & 14 deletions tests/v2api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,6 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
expect(files[0].runtimeVersion).toBeUndefined()
})

test('Logs to systemlog', async () => {
const systemLog = vi.fn()

await zipFixture('v2-api', {
fixtureDir: FIXTURES_ESM_DIR,
opts: {
systemLog,
},
})

expect(systemLog).toHaveBeenCalledOnce()
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
})

test('Does not log to systemlog for v1', async () => {
const systemLog = vi.fn()

Expand Down
13 changes: 0 additions & 13 deletions tests/zip_function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,6 @@ describe('zipFunction', () => {
expect(result.entryFilename).toEqual('___netlify-entry-point.mjs')
})

test('Logs to systemlog', async () => {
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
const mainFile = join(FIXTURES_ESM_DIR, 'v2-api', 'function.js')
const systemLog = vi.fn()

await zipFunction(mainFile, tmpDir, {
systemLog,
})

expect(systemLog).toHaveBeenCalledOnce()
expect(systemLog).toHaveBeenCalledWith('detected v2 function')
})

test('Does not log to systemlog for v1', async () => {
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
const mainFile = join(FIXTURES_DIR, 'simple', 'function.js')
Expand Down

1 comment on commit 2c25489

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 1.3s
  • largeDepsNft: 5.6s
  • largeDepsZisi: 10.7s

Please sign in to comment.