11import { kCurrentWorker , Miniflare } from "miniflare" ;
2- import { getAssetsOptions } from "../../../assets" ;
2+ import { getAssetsOptions , NonExistentAssetsDirError } from "../../../assets" ;
33import { readConfig } from "../../../config" ;
44import { DEFAULT_MODULE_RULES } from "../../../deployment-bundle/rules" ;
55import { getBindings } from "../../../dev" ;
@@ -15,6 +15,7 @@ import { getLegacyAssetPaths, getSiteAssetPaths } from "../../../sites";
1515import { CacheStorage } from "./caches" ;
1616import { ExecutionContext } from "./executionContext" ;
1717import { getServiceBindings } from "./services" ;
18+ import type { AssetsOptions } from "../../../assets" ;
1819import type { Config , RawConfig , RawEnvironment } from "../../../config" ;
1920import type { IncomingRequestCfProperties } from "@cloudflare/workers-types/experimental" ;
2021import type { MiniflareOptions , ModuleRule , WorkerOptions } from "miniflare" ;
@@ -153,6 +154,24 @@ async function getMiniflareOptionsFromConfig(
153154 imagesLocalMode : false ,
154155 } ) ;
155156
157+ let processedAssetOptions : AssetsOptions | undefined ;
158+
159+ try {
160+ processedAssetOptions = getAssetsOptions ( { assets : undefined } , rawConfig ) ;
161+ } catch ( e ) {
162+ const isNonExistentError = e instanceof NonExistentAssetsDirError ;
163+ // we want to loosen up the assets directory existence restriction here,
164+ // since `getPlatformProxy` can be run when the assets directory doesn't actual
165+ // exist, but all other exceptions should still be thrown
166+ if ( ! isNonExistentError ) {
167+ throw e ;
168+ }
169+ }
170+
171+ const assetOptions = processedAssetOptions
172+ ? buildAssetOptions ( { assets : processedAssetOptions } )
173+ : { } ;
174+
156175 const persistOptions = getMiniflarePersistOptions ( options . persist ) ;
157176
158177 const serviceBindings = await getServiceBindings ( bindings . services ) ;
@@ -167,6 +186,7 @@ async function getMiniflareOptionsFromConfig(
167186 ...serviceBindings ,
168187 ...bindingOptions . serviceBindings ,
169188 } ,
189+ ...assetOptions ,
170190 } ,
171191 ...externalWorkers ,
172192 ] ,
0 commit comments