@netlify/edge-bundler 4.0.2 → 4.1.0
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/dist/node/bundler.d.ts +2 -0
- package/dist/node/layer.d.ts +4 -0
- package/dist/node/layer.js +1 -0
- package/dist/node/manifest.d.ts +10 -3
- package/dist/node/manifest.js +4 -3
- package/dist/node/manifest.test.js +26 -0
- package/package.json +1 -1
package/dist/node/bundler.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Declaration } from './declaration.js';
|
|
|
3
3
|
import { EdgeFunction } from './edge_function.js';
|
|
4
4
|
import { FeatureFlags } from './feature_flags.js';
|
|
5
5
|
import { ImportMapFile } from './import_map.js';
|
|
6
|
+
import { Layer } from './layer.js';
|
|
6
7
|
import { LogFunction } from './logger.js';
|
|
7
8
|
interface BundleOptions {
|
|
8
9
|
basePath?: string;
|
|
@@ -11,6 +12,7 @@ interface BundleOptions {
|
|
|
11
12
|
distImportMapPath?: string;
|
|
12
13
|
featureFlags?: FeatureFlags;
|
|
13
14
|
importMaps?: ImportMapFile[];
|
|
15
|
+
layers?: Layer[];
|
|
14
16
|
onAfterDownload?: OnAfterDownloadHook;
|
|
15
17
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
16
18
|
systemLogger?: LogFunction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/node/manifest.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Bundle } from './bundle.js';
|
|
2
2
|
import type { Declaration } from './declaration.js';
|
|
3
3
|
import { EdgeFunction } from './edge_function.js';
|
|
4
|
+
import { Layer } from './layer.js';
|
|
4
5
|
interface GenerateManifestOptions {
|
|
5
6
|
bundles?: Bundle[];
|
|
6
|
-
functions: EdgeFunction[];
|
|
7
7
|
declarations?: Declaration[];
|
|
8
|
+
functions: EdgeFunction[];
|
|
9
|
+
layers?: Layer[];
|
|
8
10
|
}
|
|
9
11
|
interface Manifest {
|
|
10
12
|
bundler_version: string;
|
|
@@ -22,13 +24,18 @@ interface Manifest {
|
|
|
22
24
|
name?: string;
|
|
23
25
|
pattern: string;
|
|
24
26
|
}[];
|
|
27
|
+
layers: {
|
|
28
|
+
name: string;
|
|
29
|
+
flag: string;
|
|
30
|
+
}[];
|
|
25
31
|
}
|
|
26
|
-
declare const generateManifest: ({ bundles, declarations, functions }: GenerateManifestOptions) => Manifest;
|
|
32
|
+
declare const generateManifest: ({ bundles, declarations, functions, layers }: GenerateManifestOptions) => Manifest;
|
|
27
33
|
interface WriteManifestOptions {
|
|
28
34
|
bundles: Bundle[];
|
|
29
35
|
declarations: Declaration[];
|
|
30
36
|
distDirectory: string;
|
|
31
37
|
functions: EdgeFunction[];
|
|
38
|
+
layers?: Layer[];
|
|
32
39
|
}
|
|
33
|
-
declare const writeManifest: ({ bundles, declarations, distDirectory, functions }: WriteManifestOptions) => Promise<Manifest>;
|
|
40
|
+
declare const writeManifest: ({ bundles, declarations, distDirectory, functions, layers, }: WriteManifestOptions) => Promise<Manifest>;
|
|
34
41
|
export { generateManifest, Manifest, writeManifest };
|
package/dist/node/manifest.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from 'path';
|
|
|
3
3
|
import globToRegExp from 'glob-to-regexp';
|
|
4
4
|
import { getPackageVersion } from './package_json.js';
|
|
5
5
|
import { nonNullable } from './utils/non_nullable.js';
|
|
6
|
-
const generateManifest = ({ bundles = [], declarations = [], functions }) => {
|
|
6
|
+
const generateManifest = ({ bundles = [], declarations = [], functions, layers = [] }) => {
|
|
7
7
|
const preCacheRoutes = [];
|
|
8
8
|
const postCacheRoutes = [];
|
|
9
9
|
declarations.forEach((declaration) => {
|
|
@@ -34,6 +34,7 @@ const generateManifest = ({ bundles = [], declarations = [], functions }) => {
|
|
|
34
34
|
routes: preCacheRoutes.filter(nonNullable),
|
|
35
35
|
post_cache_routes: postCacheRoutes.filter(nonNullable),
|
|
36
36
|
bundler_version: getPackageVersion(),
|
|
37
|
+
layers,
|
|
37
38
|
};
|
|
38
39
|
return manifest;
|
|
39
40
|
};
|
|
@@ -50,8 +51,8 @@ const getRegularExpression = (declaration) => {
|
|
|
50
51
|
const normalizedSource = `^${regularExpression.source}\\/?$`;
|
|
51
52
|
return new RegExp(normalizedSource);
|
|
52
53
|
};
|
|
53
|
-
const writeManifest = async ({ bundles, declarations = [], distDirectory, functions }) => {
|
|
54
|
-
const manifest = generateManifest({ bundles, declarations, functions });
|
|
54
|
+
const writeManifest = async ({ bundles, declarations = [], distDirectory, functions, layers, }) => {
|
|
55
|
+
const manifest = generateManifest({ bundles, declarations, functions, layers });
|
|
55
56
|
const manifestPath = join(distDirectory, 'manifest.json');
|
|
56
57
|
await fs.writeFile(manifestPath, JSON.stringify(manifest));
|
|
57
58
|
return manifest;
|
|
@@ -116,3 +116,29 @@ test('Generates a manifest with pre and post-cache routes', () => {
|
|
|
116
116
|
expect(manifest.post_cache_routes).toEqual(expectedPostCacheRoutes);
|
|
117
117
|
expect(manifest.bundler_version).toBe(env.npm_package_version);
|
|
118
118
|
});
|
|
119
|
+
test('Generates a manifest with layers', () => {
|
|
120
|
+
const functions = [
|
|
121
|
+
{ name: 'func-1', path: '/path/to/func-1.ts' },
|
|
122
|
+
{ name: 'func-2', path: '/path/to/func-2.ts' },
|
|
123
|
+
];
|
|
124
|
+
const declarations = [
|
|
125
|
+
{ function: 'func-1', path: '/f1/*' },
|
|
126
|
+
{ function: 'func-2', path: '/f2/*' },
|
|
127
|
+
];
|
|
128
|
+
const expectedRoutes = [
|
|
129
|
+
{ function: 'func-1', pattern: '^/f1/.*/?$' },
|
|
130
|
+
{ function: 'func-2', pattern: '^/f2/.*/?$' },
|
|
131
|
+
];
|
|
132
|
+
const layers = [
|
|
133
|
+
{
|
|
134
|
+
name: 'onion',
|
|
135
|
+
flag: 'edge_functions_onion_layer',
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
const manifest1 = generateManifest({ bundles: [], declarations, functions });
|
|
139
|
+
const manifest2 = generateManifest({ bundles: [], declarations, functions, layers });
|
|
140
|
+
expect(manifest1.routes).toEqual(expectedRoutes);
|
|
141
|
+
expect(manifest1.layers).toEqual([]);
|
|
142
|
+
expect(manifest2.routes).toEqual(expectedRoutes);
|
|
143
|
+
expect(manifest2.layers).toEqual(layers);
|
|
144
|
+
});
|