@netlify/edge-bundler 9.0.0 → 9.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.
|
@@ -15,7 +15,7 @@ export declare const vendorNPMSpecifiers: ({ basePath, directory, functions, imp
|
|
|
15
15
|
cleanup: () => Promise<void>;
|
|
16
16
|
directory: string;
|
|
17
17
|
importMap: {
|
|
18
|
-
baseURL: import("
|
|
18
|
+
baseURL: import("url").URL;
|
|
19
19
|
imports: Record<string, string>;
|
|
20
20
|
};
|
|
21
21
|
} | undefined>;
|
|
@@ -49,7 +49,7 @@ export const getDependencyTrackerPlugin = (specifiers, importMap, baseURL) => ({
|
|
|
49
49
|
if (specifier.startsWith(npmPrefix)) {
|
|
50
50
|
return { external: true };
|
|
51
51
|
}
|
|
52
|
-
const isLocalImport = specifier.startsWith(path.sep) || specifier.startsWith('.');
|
|
52
|
+
const isLocalImport = specifier.startsWith(path.sep) || specifier.startsWith('.') || path.isAbsolute(specifier);
|
|
53
53
|
// If this is a local import, return so that esbuild visits that path.
|
|
54
54
|
if (isLocalImport) {
|
|
55
55
|
return result;
|
|
@@ -115,7 +115,6 @@ export const vendorNPMSpecifiers = async ({ basePath, directory, functions, impo
|
|
|
115
115
|
if (specifiers.size === 0) {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
logger.user('You are using npm modules in Edge Functions, which is an experimental feature. Learn more at https://ntl.fyi/edge-functions-npm.');
|
|
119
118
|
// To bundle an entire module and all its dependencies, create a barrel file
|
|
120
119
|
// where we re-export everything from that specifier. We do this for every
|
|
121
120
|
// specifier, and each of these files will become entry points to esbuild.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js';
|
|
7
7
|
import { FunctionConfig } from '../config.js';
|
|
8
8
|
import type { EdgeFunction } from '../edge_function.js';
|
|
9
|
+
import type { FeatureFlags } from '../feature_flags.js';
|
|
9
10
|
import { LogFunction } from '../logger.js';
|
|
10
11
|
export type FormatFunction = (name: string) => string;
|
|
11
12
|
interface StartServerOptions {
|
|
@@ -22,6 +23,7 @@ interface ServeOptions {
|
|
|
22
23
|
certificatePath?: string;
|
|
23
24
|
debug?: boolean;
|
|
24
25
|
distImportMapPath?: string;
|
|
26
|
+
featureFlags?: FeatureFlags;
|
|
25
27
|
inspectSettings?: InspectSettings;
|
|
26
28
|
importMapPaths?: string[];
|
|
27
29
|
onAfterDownload?: OnAfterDownloadHook;
|
|
@@ -32,7 +34,8 @@ interface ServeOptions {
|
|
|
32
34
|
servePath: string;
|
|
33
35
|
systemLogger?: LogFunction;
|
|
34
36
|
}
|
|
35
|
-
export declare const serve: ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths, onAfterDownload, onBeforeDownload, port, servePath, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
|
|
37
|
+
export declare const serve: ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, featureFlags, formatExportTypeError, formatImportError, importMapPaths, onAfterDownload, onBeforeDownload, port, servePath, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
|
|
38
|
+
features: Record<string, boolean>;
|
|
36
39
|
functionsConfig: FunctionConfig[];
|
|
37
40
|
graph: any;
|
|
38
41
|
success: boolean;
|
|
@@ -6,7 +6,7 @@ import { getLogger } from '../logger.js';
|
|
|
6
6
|
import { vendorNPMSpecifiers } from '../npm_dependencies.js';
|
|
7
7
|
import { ensureLatestTypes } from '../types.js';
|
|
8
8
|
import { killProcess, waitForServer } from './util.js';
|
|
9
|
-
const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImportMapPath, flags: denoFlags, formatExportTypeError, formatImportError, importMap: baseImportMap, logger, port, }) => {
|
|
9
|
+
const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImportMapPath, featureFlags, flags: denoFlags, formatExportTypeError, formatImportError, importMap: baseImportMap, logger, port, }) => {
|
|
10
10
|
const processRef = {};
|
|
11
11
|
const startServer = async (functions, env = {}, options = {}) => {
|
|
12
12
|
if ((processRef === null || processRef === void 0 ? void 0 : processRef.ps) !== undefined) {
|
|
@@ -21,16 +21,20 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
|
|
|
21
21
|
formatExportTypeError,
|
|
22
22
|
formatImportError,
|
|
23
23
|
});
|
|
24
|
+
const features = {};
|
|
24
25
|
const importMap = baseImportMap.clone();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
if (featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.edge_functions_npm_modules) {
|
|
27
|
+
const vendor = await vendorNPMSpecifiers({
|
|
28
|
+
basePath,
|
|
29
|
+
directory: distDirectory,
|
|
30
|
+
functions: functions.map(({ path }) => path),
|
|
31
|
+
importMap,
|
|
32
|
+
logger,
|
|
33
|
+
});
|
|
34
|
+
if (vendor) {
|
|
35
|
+
features.npmModules = true;
|
|
36
|
+
importMap.add(vendor.importMap);
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
try {
|
|
36
40
|
// This command will print a JSON object with all the modules found in
|
|
@@ -62,6 +66,7 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
|
|
|
62
66
|
}
|
|
63
67
|
const success = await waitForServer(port, processRef.ps);
|
|
64
68
|
return {
|
|
69
|
+
features,
|
|
65
70
|
functionsConfig,
|
|
66
71
|
graph,
|
|
67
72
|
success,
|
|
@@ -69,7 +74,7 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
|
|
|
69
74
|
};
|
|
70
75
|
return startServer;
|
|
71
76
|
};
|
|
72
|
-
export const serve = async ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMapPaths = [], onAfterDownload, onBeforeDownload, port, servePath, systemLogger, }) => {
|
|
77
|
+
export const serve = async ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, featureFlags, formatExportTypeError, formatImportError, importMapPaths = [], onAfterDownload, onBeforeDownload, port, servePath, systemLogger, }) => {
|
|
73
78
|
const logger = getLogger(systemLogger, debug);
|
|
74
79
|
const deno = new DenoBridge({
|
|
75
80
|
debug,
|
|
@@ -107,6 +112,7 @@ export const serve = async ({ basePath, bootstrapURL, certificatePath, debug, di
|
|
|
107
112
|
deno,
|
|
108
113
|
distDirectory: servePath,
|
|
109
114
|
distImportMapPath,
|
|
115
|
+
featureFlags,
|
|
110
116
|
flags,
|
|
111
117
|
formatExportTypeError,
|
|
112
118
|
formatImportError,
|
|
@@ -39,9 +39,10 @@ test('Starts a server and serves requests for edge functions', async () => {
|
|
|
39
39
|
const options = {
|
|
40
40
|
getFunctionsConfig: true,
|
|
41
41
|
};
|
|
42
|
-
const { functionsConfig, graph, success } = await server(functions, {
|
|
42
|
+
const { features, functionsConfig, graph, success } = await server(functions, {
|
|
43
43
|
very_secret_secret: 'i love netlify',
|
|
44
44
|
}, options);
|
|
45
|
+
expect(features).toEqual({});
|
|
45
46
|
expect(success).toBe(true);
|
|
46
47
|
expect(functionsConfig).toEqual([{ path: '/my-function' }, {}, { path: '/global-netlify' }]);
|
|
47
48
|
for (const key in functions) {
|