miniflare 0.0.0-e4fe35cc5 → 0.0.0-eaf71b86c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -574,6 +574,17 @@ parameter in module format Workers.
574
574
  have at most one consumer. If a `string[]` of queue names is specified,
575
575
  default consumer options will be used.
576
576
 
577
+ #### Assets
578
+
579
+ - `directory?: string`
580
+ Path to serve Workers static asset files from.
581
+
582
+ - `binding?: string`
583
+ Binding name to inject as a `Fetcher` binding to allow access to static assets from within the Worker.
584
+
585
+ - `assetOptions?: { html_handling?: HTMLHandlingOptions, not_found_handling?: NotFoundHandlingOptions}`
586
+ Configuration for file-based asset routing - see [docs](https://developers.cloudflare.com/workers/static-assets/routing/#routing-configuration) for options
587
+
577
588
  #### Analytics Engine, Sending Email, Vectorize and Workers for Platforms
578
589
 
579
590
  _Not yet supported_
@@ -58,21 +58,28 @@ export declare class __MiniflareFunctionWrapper {
58
58
 
59
59
  export declare type AnyHeaders = http.IncomingHttpHeaders | string[];
60
60
 
61
+ export declare type AssetReverseMap = {
62
+ [pathHash: string]: {
63
+ filePath: string;
64
+ contentType: string;
65
+ };
66
+ };
67
+
61
68
  export declare const ASSETS_PLUGIN: Plugin<typeof AssetsOptionsSchema>;
62
69
 
63
70
  export declare const AssetsOptionsSchema: z.ZodObject<{
64
71
  assets: z.ZodOptional<z.ZodObject<{
65
72
  workerName: z.ZodOptional<z.ZodString>;
66
- path: z.ZodEffects<z.ZodString, string, string>;
67
- bindingName: z.ZodOptional<z.ZodString>;
68
- routingConfig: z.ZodObject<{
73
+ directory: z.ZodEffects<z.ZodString, string, string>;
74
+ binding: z.ZodOptional<z.ZodString>;
75
+ routingConfig: z.ZodOptional<z.ZodObject<{
69
76
  has_user_worker: z.ZodOptional<z.ZodBoolean>;
70
77
  }, "strip", z.ZodTypeAny, {
71
78
  has_user_worker?: boolean;
72
79
  }, {
73
80
  has_user_worker?: boolean;
74
- }>;
75
- assetConfig: z.ZodObject<{
81
+ }>>;
82
+ assetConfig: z.ZodOptional<z.ZodObject<{
76
83
  html_handling: z.ZodOptional<z.ZodEnum<["auto-trailing-slash", "force-trailing-slash", "drop-trailing-slash", "none"]>>;
77
84
  not_found_handling: z.ZodOptional<z.ZodEnum<["single-page-application", "404-page", "none"]>>;
78
85
  }, "strip", z.ZodTypeAny, {
@@ -81,55 +88,55 @@ export declare const AssetsOptionsSchema: z.ZodObject<{
81
88
  }, {
82
89
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
83
90
  not_found_handling?: "none" | "single-page-application" | "404-page";
84
- }>;
91
+ }>>;
85
92
  }, "strip", z.ZodTypeAny, {
86
- path: string;
87
- routingConfig: {
93
+ directory: string;
94
+ workerName?: string | undefined;
95
+ binding?: string | undefined;
96
+ routingConfig?: {
88
97
  has_user_worker?: boolean;
89
- };
90
- assetConfig: {
98
+ } | undefined;
99
+ assetConfig?: {
91
100
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
92
101
  not_found_handling?: "none" | "single-page-application" | "404-page";
93
- };
94
- workerName?: string | undefined;
95
- bindingName?: string | undefined;
102
+ } | undefined;
96
103
  }, {
97
- path: string;
98
- routingConfig: {
104
+ directory: string;
105
+ workerName?: string | undefined;
106
+ binding?: string | undefined;
107
+ routingConfig?: {
99
108
  has_user_worker?: boolean;
100
- };
101
- assetConfig: {
109
+ } | undefined;
110
+ assetConfig?: {
102
111
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
103
112
  not_found_handling?: "none" | "single-page-application" | "404-page";
104
- };
105
- workerName?: string | undefined;
106
- bindingName?: string | undefined;
113
+ } | undefined;
107
114
  }>>;
108
115
  }, "strip", z.ZodTypeAny, {
109
116
  assets?: {
110
- path: string;
111
- routingConfig: {
117
+ directory: string;
118
+ workerName?: string | undefined;
119
+ binding?: string | undefined;
120
+ routingConfig?: {
112
121
  has_user_worker?: boolean;
113
- };
114
- assetConfig: {
122
+ } | undefined;
123
+ assetConfig?: {
115
124
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
116
125
  not_found_handling?: "none" | "single-page-application" | "404-page";
117
- };
118
- workerName?: string | undefined;
119
- bindingName?: string | undefined;
126
+ } | undefined;
120
127
  } | undefined;
121
128
  }, {
122
129
  assets?: {
123
- path: string;
124
- routingConfig: {
130
+ directory: string;
131
+ workerName?: string | undefined;
132
+ binding?: string | undefined;
133
+ routingConfig?: {
125
134
  has_user_worker?: boolean;
126
- };
127
- assetConfig: {
135
+ } | undefined;
136
+ assetConfig?: {
128
137
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
129
138
  not_found_handling?: "none" | "single-page-application" | "404-page";
130
- };
131
- workerName?: string | undefined;
132
- bindingName?: string | undefined;
139
+ } | undefined;
133
140
  } | undefined;
134
141
  }>;
135
142
 
@@ -141,7 +148,19 @@ export declare function base64Encode(value: string): string;
141
148
 
142
149
  export { BodyInit }
143
150
 
144
- export declare const buildAssetsManifest: (dir: string) => Promise<Uint8Array>;
151
+ /**
152
+ * The Asset Manifest and Asset Reverse Map are used to map a request path to an asset.
153
+ * 1. Hash path of request
154
+ * 2. Use this path hash to find the manifest entry
155
+ * 3. Get content hash from manifest entry
156
+ * 4a. In prod, use content hash to get asset from KV
157
+ * 4b. In dev, we fake out the KV store and use the file system instead.
158
+ * Use content hash to get file path from asset reverse map.
159
+ */
160
+ export declare const buildAssetManifest: (dir: string) => Promise<{
161
+ encodedAssetManifest: Uint8Array;
162
+ assetsReverseMap: AssetReverseMap;
163
+ }>;
145
164
 
146
165
  export declare const CACHE_PLUGIN: Plugin<typeof CacheOptionsSchema, typeof CacheSharedOptionsSchema>;
147
166
 
@@ -666,6 +685,10 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
666
685
  }>, "many">>;
667
686
  unsafeEvalBinding: z.ZodOptional<z.ZodString>;
668
687
  unsafeUseModuleFallbackService: z.ZodOptional<z.ZodBoolean>;
688
+ /** Used to set the vitest pool worker SELF binding to point to the router worker if there are assets.
689
+ (If there are assets but we're not using vitest, the miniflare entry worker can point directly to RW.)
690
+ */
691
+ hasAssetsAndIsVitest: z.ZodOptional<z.ZodBoolean>;
669
692
  }, "strip", z.ZodTypeAny, {
670
693
  name?: string | undefined;
671
694
  rootPath?: undefined;
@@ -745,6 +768,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
745
768
  }[] | undefined;
746
769
  unsafeEvalBinding?: string | undefined;
747
770
  unsafeUseModuleFallbackService?: boolean | undefined;
771
+ hasAssetsAndIsVitest?: boolean | undefined;
748
772
  }, {
749
773
  name?: string | undefined;
750
774
  rootPath?: string | undefined;
@@ -824,6 +848,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
824
848
  }[] | undefined;
825
849
  unsafeEvalBinding?: string | undefined;
826
850
  unsafeUseModuleFallbackService?: boolean | undefined;
851
+ hasAssetsAndIsVitest?: boolean | undefined;
827
852
  }>>, ({
828
853
  modules: {
829
854
  type: "ESModule" | "CommonJS" | "NodeJsCompatModule" | "Text" | "Data" | "CompiledWasm" | "PythonModule" | "PythonRequirement";
@@ -910,6 +935,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
910
935
  }[] | undefined;
911
936
  unsafeEvalBinding?: string | undefined;
912
937
  unsafeUseModuleFallbackService?: boolean | undefined;
938
+ hasAssetsAndIsVitest?: boolean | undefined;
913
939
  }) | ({
914
940
  script: string;
915
941
  scriptPath?: string | undefined;
@@ -999,6 +1025,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
999
1025
  }[] | undefined;
1000
1026
  unsafeEvalBinding?: string | undefined;
1001
1027
  unsafeUseModuleFallbackService?: boolean | undefined;
1028
+ hasAssetsAndIsVitest?: boolean | undefined;
1002
1029
  }) | ({
1003
1030
  scriptPath: string;
1004
1031
  modules?: boolean | undefined;
@@ -1087,6 +1114,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
1087
1114
  }[] | undefined;
1088
1115
  unsafeEvalBinding?: string | undefined;
1089
1116
  unsafeUseModuleFallbackService?: boolean | undefined;
1117
+ hasAssetsAndIsVitest?: boolean | undefined;
1090
1118
  }), ({
1091
1119
  modules: {
1092
1120
  type: "ESModule" | "CommonJS" | "NodeJsCompatModule" | "Text" | "Data" | "CompiledWasm" | "PythonModule" | "PythonRequirement";
@@ -1192,6 +1220,7 @@ export declare const CoreOptionsSchema: z.ZodEffects<z.ZodIntersection<z.ZodUnio
1192
1220
  }[] | undefined;
1193
1221
  unsafeEvalBinding?: string | undefined;
1194
1222
  unsafeUseModuleFallbackService?: boolean | undefined;
1223
+ hasAssetsAndIsVitest?: boolean | undefined;
1195
1224
  }>;
1196
1225
 
1197
1226
  export declare const CoreSharedOptionsSchema: z.ZodObject<{
@@ -1475,6 +1504,30 @@ export declare function getGlobalServices({ sharedOptions, allWorkerRoutes, fall
1475
1504
 
1476
1505
  export declare function getMiniflareObjectBindings(unsafeStickyBlobs: boolean): Worker_Binding[];
1477
1506
 
1507
+ /**
1508
+ * Computes the Node.js compatibility mode we are running.
1509
+ *
1510
+ * NOTES:
1511
+ * - The v2 mode is configured via `nodejs_compat_v2` compat flag or via `nodejs_compat` plus a compatibility date of Sept 23rd. 2024 or later.
1512
+ * - See `EnvironmentInheritable` for `nodeCompat` and `noBundle`.
1513
+ *
1514
+ * @param compatibilityDateStr The compatibility date
1515
+ * @param compatibilityFlags The compatibility flags
1516
+ * @param opts.nodeCompat Whether the legacy node_compat arg is being used
1517
+ * @returns the mode and flags to indicate specific configuration for validating.
1518
+ */
1519
+ export declare function getNodeCompat(compatibilityDate: string | undefined, // Default to some arbitrary old date
1520
+ compatibilityFlags: string[], opts?: {
1521
+ nodeCompat?: boolean;
1522
+ }): {
1523
+ mode: NodeJSCompatMode;
1524
+ hasNodejsAlsFlag: boolean;
1525
+ hasNodejsCompatFlag: boolean;
1526
+ hasNodejsCompatV2Flag: boolean;
1527
+ hasNoNodejsCompatV2Flag: boolean;
1528
+ hasExperimentalNodejsCompatV2Flag: boolean;
1529
+ };
1530
+
1478
1531
  export declare function getPersistPath(pluginName: string, tmpPath: string, persist: Persistence): string;
1479
1532
 
1480
1533
  export declare function getRootPath(opts: unknown): string;
@@ -1673,6 +1726,11 @@ export declare interface LogOptions {
1673
1726
  suffix?: string;
1674
1727
  }
1675
1728
 
1729
+ export declare type ManifestEntry = {
1730
+ pathHash: Uint8Array;
1731
+ contentHash: Uint8Array;
1732
+ };
1733
+
1676
1734
  export declare interface MatcherRegExps {
1677
1735
  include: RegExp[];
1678
1736
  exclude: RegExp[];
@@ -1797,6 +1855,17 @@ export declare interface Network {
1797
1855
 
1798
1856
  export declare const NODE_PLATFORM_IMPL: PlatformImpl<ReadableStream_2>;
1799
1857
 
1858
+ /**
1859
+ * We can provide Node.js compatibility in a number of different modes:
1860
+ * - "legacy" - this mode adds compile-time polyfills that are not well maintained and cannot work with workerd runtime builtins.
1861
+ * - "als": this mode tells the workerd runtime to enable only the Async Local Storage builtin library (accessible via `node:async_hooks`).
1862
+ * - "v1" - this mode tells the workerd runtime to enable some Node.js builtin libraries (accessible only via `node:...` imports) but no globals.
1863
+ * - "v2" - this mode tells the workerd runtime to enable more Node.js builtin libraries (accessible both with and without the `node:` prefix)
1864
+ * and also some Node.js globals such as `Buffer`; it also turns on additional compile-time polyfills for those that are not provided by the runtime.
1865
+ * - null - no Node.js compatibility.
1866
+ */
1867
+ export declare type NodeJSCompatMode = "legacy" | "als" | "v1" | "v2" | null;
1868
+
1800
1869
  export declare class NoOpLog extends Log {
1801
1870
  constructor();
1802
1871
  protected log(): void;
@@ -2364,6 +2433,7 @@ export declare const PLUGINS: {
2364
2433
  }>, "many">>;
2365
2434
  unsafeEvalBinding: z.ZodOptional<z.ZodString>;
2366
2435
  unsafeUseModuleFallbackService: z.ZodOptional<z.ZodBoolean>;
2436
+ hasAssetsAndIsVitest: z.ZodOptional<z.ZodBoolean>;
2367
2437
  }, "strip", z.ZodTypeAny, {
2368
2438
  name?: string | undefined;
2369
2439
  rootPath?: undefined;
@@ -2443,6 +2513,7 @@ export declare const PLUGINS: {
2443
2513
  }[] | undefined;
2444
2514
  unsafeEvalBinding?: string | undefined;
2445
2515
  unsafeUseModuleFallbackService?: boolean | undefined;
2516
+ hasAssetsAndIsVitest?: boolean | undefined;
2446
2517
  }, {
2447
2518
  name?: string | undefined;
2448
2519
  rootPath?: string | undefined;
@@ -2522,6 +2593,7 @@ export declare const PLUGINS: {
2522
2593
  }[] | undefined;
2523
2594
  unsafeEvalBinding?: string | undefined;
2524
2595
  unsafeUseModuleFallbackService?: boolean | undefined;
2596
+ hasAssetsAndIsVitest?: boolean | undefined;
2525
2597
  }>>, ({
2526
2598
  modules: {
2527
2599
  type: "ESModule" | "CommonJS" | "NodeJsCompatModule" | "Text" | "Data" | "CompiledWasm" | "PythonModule" | "PythonRequirement";
@@ -2608,6 +2680,7 @@ export declare const PLUGINS: {
2608
2680
  }[] | undefined;
2609
2681
  unsafeEvalBinding?: string | undefined;
2610
2682
  unsafeUseModuleFallbackService?: boolean | undefined;
2683
+ hasAssetsAndIsVitest?: boolean | undefined;
2611
2684
  }) | ({
2612
2685
  script: string;
2613
2686
  scriptPath?: string | undefined;
@@ -2697,6 +2770,7 @@ export declare const PLUGINS: {
2697
2770
  }[] | undefined;
2698
2771
  unsafeEvalBinding?: string | undefined;
2699
2772
  unsafeUseModuleFallbackService?: boolean | undefined;
2773
+ hasAssetsAndIsVitest?: boolean | undefined;
2700
2774
  }) | ({
2701
2775
  scriptPath: string;
2702
2776
  modules?: boolean | undefined;
@@ -2785,6 +2859,7 @@ export declare const PLUGINS: {
2785
2859
  }[] | undefined;
2786
2860
  unsafeEvalBinding?: string | undefined;
2787
2861
  unsafeUseModuleFallbackService?: boolean | undefined;
2862
+ hasAssetsAndIsVitest?: boolean | undefined;
2788
2863
  }), ({
2789
2864
  modules: {
2790
2865
  type: "ESModule" | "CommonJS" | "NodeJsCompatModule" | "Text" | "Data" | "CompiledWasm" | "PythonModule" | "PythonRequirement";
@@ -2890,6 +2965,7 @@ export declare const PLUGINS: {
2890
2965
  }[] | undefined;
2891
2966
  unsafeEvalBinding?: string | undefined;
2892
2967
  unsafeUseModuleFallbackService?: boolean | undefined;
2968
+ hasAssetsAndIsVitest?: boolean | undefined;
2893
2969
  }>, z.ZodObject<{
2894
2970
  rootPath: z.ZodOptional<z.ZodEffects<z.ZodString, undefined, string>>;
2895
2971
  host: z.ZodOptional<z.ZodString>;
@@ -3158,16 +3234,16 @@ export declare const PLUGINS: {
3158
3234
  assets: Plugin<z.ZodObject<{
3159
3235
  assets: z.ZodOptional<z.ZodObject<{
3160
3236
  workerName: z.ZodOptional<z.ZodString>;
3161
- path: z.ZodEffects<z.ZodString, string, string>;
3162
- bindingName: z.ZodOptional<z.ZodString>;
3163
- routingConfig: z.ZodObject<{
3237
+ directory: z.ZodEffects<z.ZodString, string, string>;
3238
+ binding: z.ZodOptional<z.ZodString>;
3239
+ routingConfig: z.ZodOptional<z.ZodObject<{
3164
3240
  has_user_worker: z.ZodOptional<z.ZodBoolean>;
3165
3241
  }, "strip", z.ZodTypeAny, {
3166
3242
  has_user_worker?: boolean;
3167
3243
  }, {
3168
3244
  has_user_worker?: boolean;
3169
- }>;
3170
- assetConfig: z.ZodObject<{
3245
+ }>>;
3246
+ assetConfig: z.ZodOptional<z.ZodObject<{
3171
3247
  html_handling: z.ZodOptional<z.ZodEnum<["auto-trailing-slash", "force-trailing-slash", "drop-trailing-slash", "none"]>>;
3172
3248
  not_found_handling: z.ZodOptional<z.ZodEnum<["single-page-application", "404-page", "none"]>>;
3173
3249
  }, "strip", z.ZodTypeAny, {
@@ -3176,55 +3252,55 @@ export declare const PLUGINS: {
3176
3252
  }, {
3177
3253
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
3178
3254
  not_found_handling?: "none" | "single-page-application" | "404-page";
3179
- }>;
3255
+ }>>;
3180
3256
  }, "strip", z.ZodTypeAny, {
3181
- path: string;
3182
- routingConfig: {
3257
+ directory: string;
3258
+ workerName?: string | undefined;
3259
+ binding?: string | undefined;
3260
+ routingConfig?: {
3183
3261
  has_user_worker?: boolean;
3184
- };
3185
- assetConfig: {
3262
+ } | undefined;
3263
+ assetConfig?: {
3186
3264
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
3187
3265
  not_found_handling?: "none" | "single-page-application" | "404-page";
3188
- };
3189
- workerName?: string | undefined;
3190
- bindingName?: string | undefined;
3266
+ } | undefined;
3191
3267
  }, {
3192
- path: string;
3193
- routingConfig: {
3268
+ directory: string;
3269
+ workerName?: string | undefined;
3270
+ binding?: string | undefined;
3271
+ routingConfig?: {
3194
3272
  has_user_worker?: boolean;
3195
- };
3196
- assetConfig: {
3273
+ } | undefined;
3274
+ assetConfig?: {
3197
3275
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
3198
3276
  not_found_handling?: "none" | "single-page-application" | "404-page";
3199
- };
3200
- workerName?: string | undefined;
3201
- bindingName?: string | undefined;
3277
+ } | undefined;
3202
3278
  }>>;
3203
3279
  }, "strip", z.ZodTypeAny, {
3204
3280
  assets?: {
3205
- path: string;
3206
- routingConfig: {
3281
+ directory: string;
3282
+ workerName?: string | undefined;
3283
+ binding?: string | undefined;
3284
+ routingConfig?: {
3207
3285
  has_user_worker?: boolean;
3208
- };
3209
- assetConfig: {
3286
+ } | undefined;
3287
+ assetConfig?: {
3210
3288
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
3211
3289
  not_found_handling?: "none" | "single-page-application" | "404-page";
3212
- };
3213
- workerName?: string | undefined;
3214
- bindingName?: string | undefined;
3290
+ } | undefined;
3215
3291
  } | undefined;
3216
3292
  }, {
3217
3293
  assets?: {
3218
- path: string;
3219
- routingConfig: {
3294
+ directory: string;
3295
+ workerName?: string | undefined;
3296
+ binding?: string | undefined;
3297
+ routingConfig?: {
3220
3298
  has_user_worker?: boolean;
3221
- };
3222
- assetConfig: {
3299
+ } | undefined;
3300
+ assetConfig?: {
3223
3301
  html_handling?: "none" | "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash";
3224
3302
  not_found_handling?: "none" | "single-page-application" | "404-page";
3225
- };
3226
- workerName?: string | undefined;
3227
- bindingName?: string | undefined;
3303
+ } | undefined;
3228
3304
  } | undefined;
3229
3305
  }>>;
3230
3306
  };