Skip to content

Commit 0d48c28

Browse files
authored
feat!: remove support for deprecated netlify-lambda package (#7236)
* feat!: remove support for deprecated netlify-lambda package https://github.com/netlify/netlify-lambda was deprecated in Feb 2023 This removes support for it from Netlify CLI. To migrate away from netlify-lambda, see https://github.com/netlify/netlify-lambda/blob/main/MIGRATE.md. * fix: restore hidden important side effect * style: change todo comment style
1 parent 9cece71 commit 0d48c28

File tree

8 files changed

+16
-351
lines changed

8 files changed

+16
-351
lines changed

docs/commands/deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Build binaries of your Go language functions into the functions folder as part o
3232
Single file Node.js functions:
3333
-----------------------------
3434

35-
Build dependency bundled Node.js lambda functions with tools like netlify-lambda, webpack or browserify into the function folder as part of your build process.
35+
Build dependency bundled Node.js lambda functions with tools like webpack or browserify into the function folder as part of your build process.
3636

3737
```
3838
functions/

src/commands/deploy/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Build binaries of your Go language functions into the functions folder as part o
3535
Single file Node.js functions:
3636
-----------------------------
3737
38-
Build dependency bundled Node.js lambda functions with tools like netlify-lambda, webpack or browserify into the function folder as part of your build process.
38+
Build dependency bundled Node.js lambda functions with tools like webpack or browserify into the function folder as part of your build process.
3939
4040
\`\`\`
4141
functions/

src/lib/functions/registry.ts

+3-20
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,9 @@ export class FunctionsRegistry {
167167
}
168168
}
169169

170-
/**
171-
* Runs before `scan` and calls any `onDirectoryScan` hooks defined by the
172-
* runtime before the directory is read. This gives runtime the opportunity
173-
* to run additional logic when a directory is scanned.
174-
*/
175-
static async prepareDirectoryScan(directory: string) {
170+
// TODO(serhalp): Is this really the right place to do this mutation? Should we do this at all?
171+
static async prepareDirectory(directory: string) {
176172
await mkdir(directory, { recursive: true })
177-
178-
// We give runtimes the opportunity to react to a directory scan and run
179-
// additional logic before the directory is read. So if they implement a
180-
// `onDirectoryScan` hook, we run it.
181-
await Promise.all(
182-
Object.values(runtimes).map((runtime) => {
183-
if (!('onDirectoryScan' in runtime)) {
184-
return null
185-
}
186-
187-
return runtime.onDirectoryScan({ directory })
188-
}),
189-
)
190173
}
191174

192175
/**
@@ -480,7 +463,7 @@ export class FunctionsRegistry {
480463
return
481464
}
482465

483-
await Promise.all(directories.map((path) => FunctionsRegistry.prepareDirectoryScan(path)))
466+
await Promise.all(directories.map((path) => FunctionsRegistry.prepareDirectory(path)))
484467

485468
const functions = await this.listFunctions(directories, {
486469
featureFlags: {

src/lib/functions/runtimes/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ export type InvokeFunction<BuildResult extends BaseBuildResult> = (params: {
5454
timeout: number
5555
}) => Promise<InvokeFunctionResult>
5656

57-
export type OnDirectoryScanFunction = (params: { directory: string }) => Promise<void>
58-
5957
export type OnRegisterFunction<BuildResult extends BaseBuildResult> = (
6058
func: NetlifyFunction<BuildResult>,
6159
) => NetlifyFunction<BuildResult> | null
6260

6361
export interface Runtime<BuildResult extends BaseBuildResult> {
6462
getBuildFunction: GetBuildFunction<BuildResult>
6563
invokeFunction: InvokeFunction<BuildResult>
66-
onDirectoryScan?: OnDirectoryScanFunction
6764
onRegister?: OnRegisterFunction<BuildResult>
6865
name: string
6966
}

src/lib/functions/runtimes/js/builders/netlify-lambda.ts

-83
This file was deleted.

src/lib/functions/runtimes/js/index.ts

+7-36
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,36 @@ import { Worker } from 'worker_threads'
55

66
import lambdaLocal, { type LambdaEvent } from 'lambda-local'
77

8-
import type { BuildFunction, GetBuildFunction, InvokeFunction, OnDirectoryScanFunction } from '../index.js'
8+
import type { BuildFunction, GetBuildFunction, InvokeFunction } from '../index.js'
99
import { BLOBS_CONTEXT_VARIABLE } from '../../../blobs/blobs.js'
1010
import type NetlifyFunction from '../../netlify-function.js'
1111

12-
import detectNetlifyLambdaBuilder, {
13-
type NetlifyLambdaBuildResult,
14-
type NetlifyLambdaBuilder,
15-
} from './builders/netlify-lambda.js'
1612
import detectZisiBuilder, { getFunctionMetadata, ZisiBuildResult } from './builders/zisi.js'
1713
import { SECONDS_TO_MILLISECONDS } from './constants.js'
1814
import type { WorkerMessage } from './worker.js'
1915

2016
export const name = 'js'
2117

22-
export type JsBuildResult = ZisiBuildResult | NetlifyLambdaBuildResult
18+
type SimpleJsBuildResult = {
19+
schedule?: string
20+
srcFiles: string[]
21+
}
22+
23+
export type JsBuildResult = ZisiBuildResult | SimpleJsBuildResult
2324

2425
// TODO(serhalp): Unify these. This is bonkers that the two underlying invocation mechanisms are encapsulated but we
2526
// return slightly different shapes for them.
2627
export type JsInvokeFunctionResult = WorkerMessage | LambdaEvent
2728

28-
let netlifyLambdaDetectorCache: undefined | NetlifyLambdaBuilder
29-
3029
lambdaLocal.getLogger().level = 'alert'
3130

32-
// The netlify-lambda builder can't be enabled or disabled on a per-function
33-
// basis and its detection mechanism is also quite expensive, so we detect
34-
// it once and cache the result.
35-
const detectNetlifyLambdaWithCache = async () => {
36-
if (netlifyLambdaDetectorCache === undefined) {
37-
netlifyLambdaDetectorCache = await detectNetlifyLambdaBuilder()
38-
}
39-
40-
return netlifyLambdaDetectorCache
41-
}
42-
4331
export async function getBuildFunction({
4432
config,
4533
directory,
4634
errorExit,
4735
func,
4836
projectRoot,
4937
}: Parameters<GetBuildFunction<JsBuildResult>>[0]) {
50-
const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
51-
52-
if (netlifyLambdaBuilder) {
53-
return netlifyLambdaBuilder.build
54-
}
55-
5638
const metadata = await getFunctionMetadata({ mainFile: func.mainFile, config, projectRoot })
5739
const zisiBuilder = await detectZisiBuilder({ config, directory, errorExit, func, metadata, projectRoot })
5840

@@ -168,14 +150,3 @@ export const invokeFunctionDirectly = async <BuildResult extends JsBuildResult>(
168150

169151
return result
170152
}
171-
172-
export const onDirectoryScan: OnDirectoryScanFunction = async () => {
173-
const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
174-
175-
// Before we start a directory scan, we check whether netlify-lambda is being
176-
// used. If it is, we run it, so that the functions directory is populated
177-
// with the compiled files before the scan begins.
178-
if (netlifyLambdaBuilder) {
179-
await netlifyLambdaBuilder.build()
180-
}
181-
}

tests/unit/lib/functions/registry.test.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ test('registry should only pass functions config to zip-it-and-ship-it', async (
5757
plugins: ['test'],
5858
},
5959
})
60-
const prepareDirectoryScanStub = vi
61-
.spyOn(FunctionsRegistry, 'prepareDirectoryScan')
62-
.mockImplementation(async () => {})
60+
const prepareDirectoryStub = vi.spyOn(FunctionsRegistry, 'prepareDirectory').mockImplementation(async () => {})
6361
const setupDirectoryWatcherStub = vi
6462
.spyOn(functionsRegistry, 'setupDirectoryWatcher')
6563
.mockImplementation(async () => {})
@@ -69,7 +67,7 @@ test('registry should only pass functions config to zip-it-and-ship-it', async (
6967
t.onTestFinished(() => {
7068
listFunctionsStub.mockRestore()
7169
setupDirectoryWatcherStub.mockRestore()
72-
prepareDirectoryScanStub.mockRestore()
70+
prepareDirectoryStub.mockRestore()
7371
})
7472

7573
await functionsRegistry.scan([
@@ -112,16 +110,14 @@ describe('the registry handles duplicate functions based on extension precedence
112110
},
113111
frameworksAPIPaths: getFrameworksAPIPaths(projectRoot),
114112
})
115-
const prepareDirectoryScanStub = vi
116-
.spyOn(FunctionsRegistry, 'prepareDirectoryScan')
117-
.mockImplementation(async () => {})
113+
const prepareDirectoryStub = vi.spyOn(FunctionsRegistry, 'prepareDirectory').mockImplementation(async () => {})
118114
const setupDirectoryWatcherStub = vi
119115
.spyOn(functionsRegistry, 'setupDirectoryWatcher')
120116
.mockImplementation(async () => {})
121117

122118
t.onTestFinished(() => {
123119
setupDirectoryWatcherStub.mockRestore()
124-
prepareDirectoryScanStub.mockRestore()
120+
prepareDirectoryStub.mockRestore()
125121
})
126122

127123
await functionsRegistry.scan([functionsDirectory])

0 commit comments

Comments
 (0)