@@ -22,7 +22,12 @@ import type { FeatureFlags } from '../../utils/feature-flags.js'
2222import { MultiMap } from '../../utils/multimap.js'
2323import { getPathInProject } from '../settings.js'
2424
25- import { DIST_IMPORT_MAP_PATH , INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.js'
25+ import { DIST_IMPORT_MAP_PATH } from './consts.js'
26+ import {
27+ getFrameworkEdgeFunctionsDirectory ,
28+ getInternalEdgeFunctionsDirectory ,
29+ getUserEdgeFunctionsDirectory ,
30+ } from './get-directories.js'
2631
2732type DependencyCache = Record < string , string [ ] >
2833type EdgeFunctionEvent = 'buildError' | 'loaded' | 'reloaded' | 'reloading' | 'removed'
@@ -38,7 +43,6 @@ interface EdgeFunctionsRegistryOptions {
3843 config : NormalizedCachedConfigConfig
3944 configPath : string
4045 debug : boolean
41- directories : string [ ]
4246 env : Record < string , { sources : string [ ] ; value : string } >
4347 featureFlags : FeatureFlags
4448 getUpdatedConfig : ( ) => Promise < NormalizedCachedConfigConfig >
@@ -105,7 +109,6 @@ export class EdgeFunctionsRegistry {
105109 // Mapping file URLs to names of functions that use them as dependencies.
106110 private dependencyPaths = new MultiMap < string , string > ( )
107111
108- private directories : string [ ]
109112 private directoryWatchers = new Map < string , import ( 'chokidar' ) . FSWatcher > ( )
110113 private env : Record < string , string >
111114 private featureFlags : FeatureFlags
@@ -133,7 +136,6 @@ export class EdgeFunctionsRegistry {
133136 command,
134137 config,
135138 configPath,
136- directories,
137139 env,
138140 featureFlags,
139141 getUpdatedConfig,
@@ -146,7 +148,6 @@ export class EdgeFunctionsRegistry {
146148 this . command = command
147149 this . bundler = bundler
148150 this . configPath = configPath
149- this . directories = directories
150151 this . featureFlags = featureFlags
151152 this . getUpdatedConfig = getUpdatedConfig
152153 this . runIsolate = runIsolate
@@ -563,16 +564,12 @@ export class EdgeFunctionsRegistry {
563564 return { functionsConfig, graph, success }
564565 }
565566
566- private get internalDirectory ( ) {
567- return join ( this . projectDir , getPathInProject ( [ INTERNAL_EDGE_FUNCTIONS_FOLDER ] ) )
568- }
569-
570567 private get internalImportMapPath ( ) {
571568 return join ( this . projectDir , getPathInProject ( [ DIST_IMPORT_MAP_PATH ] ) )
572569 }
573570
574571 private async readDeployConfig ( ) {
575- const manifestPath = join ( this . internalDirectory , 'manifest.json' )
572+ const manifestPath = join ( getInternalEdgeFunctionsDirectory ( this . command ) , 'manifest.json' )
576573 try {
577574 const contents = await readFile ( manifestPath , 'utf8' )
578575 const manifest = JSON . parse ( contents )
@@ -592,15 +589,16 @@ export class EdgeFunctionsRegistry {
592589
593590 this . declarationsFromDeployConfig = deployConfig . functions
594591 this . importMapFromDeployConfig = deployConfig . import_map
595- ? join ( this . internalDirectory , deployConfig . import_map )
592+ ? join ( getInternalEdgeFunctionsDirectory ( this . command ) , deployConfig . import_map )
596593 : undefined
597594 }
598595
599596 private async scanForFunctions ( ) {
597+ const userFunctionDirectory = getUserEdgeFunctionsDirectory ( this . command )
600598 const [ frameworkFunctions , integrationFunctions , userFunctions ] = await Promise . all ( [
601- this . usesFrameworksAPI ? this . bundler . find ( [ this . command . netlify . frameworksAPIPaths . edgeFunctions . path ] ) : [ ] ,
602- this . bundler . find ( [ this . internalDirectory ] ) ,
603- this . bundler . find ( this . directories ) ,
599+ this . usesFrameworksAPI ? this . bundler . find ( [ getFrameworkEdgeFunctionsDirectory ( this . command ) ] ) : [ ] ,
600+ this . bundler . find ( [ getInternalEdgeFunctionsDirectory ( this . command ) ] ) ,
601+ userFunctionDirectory ? this . bundler . find ( [ userFunctionDirectory ] ) : [ ] ,
604602 this . scanForDeployConfig ( ) ,
605603 ] )
606604 const internalFunctions = [ ...frameworkFunctions , ...integrationFunctions ]
0 commit comments