@netlify/edge-bundler 10.1.2 → 11.0.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.
@@ -6,5 +6,6 @@ export type { EdgeFunction } from './edge_function.js';
6
6
  export { findFunctions as find } from './finder.js';
7
7
  export { generateManifest } from './manifest.js';
8
8
  export type { EdgeFunctionConfig, Manifest } from './manifest.js';
9
- export { ModuleGraph, serve } from './server/server.js';
9
+ export type { ModuleGraphJson as ModuleGraph } from './vendor/module_graph/module_graph.js';
10
+ export { serve } from './server/server.js';
10
11
  export { validateManifest, ManifestValidationError } from './validation/manifest/index.js';
@@ -3,16 +3,16 @@
3
3
  /// <reference types="node" />
4
4
  /// <reference types="node" />
5
5
  /// <reference types="node" />
6
- import type { ModuleGraphJson } from '../../deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.js';
7
6
  import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js';
8
7
  import { FunctionConfig } from '../config.js';
9
8
  import type { EdgeFunction } from '../edge_function.js';
10
9
  import type { FeatureFlags } from '../feature_flags.js';
11
10
  import { LogFunction } from '../logger.js';
11
+ import type { ModuleGraphJson } from '../vendor/module_graph/module_graph.js';
12
12
  export type FormatFunction = (name: string) => string;
13
- export type ModuleGraph = ModuleGraphJson;
14
13
  interface StartServerOptions {
15
14
  getFunctionsConfig?: boolean;
15
+ importMapPaths?: string[];
16
16
  }
17
17
  interface InspectSettings {
18
18
  enabled: boolean;
@@ -27,7 +27,6 @@ interface ServeOptions {
27
27
  distImportMapPath?: string;
28
28
  featureFlags?: FeatureFlags;
29
29
  inspectSettings?: InspectSettings;
30
- importMapPaths?: string[];
31
30
  onAfterDownload?: OnAfterDownloadHook;
32
31
  onBeforeDownload?: OnBeforeDownloadHook;
33
32
  formatExportTypeError?: FormatFunction;
@@ -38,7 +37,7 @@ interface ServeOptions {
38
37
  userLogger?: LogFunction;
39
38
  systemLogger?: LogFunction;
40
39
  }
41
- export declare const serve: ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, featureFlags, formatExportTypeError, formatImportError, importMapPaths, onAfterDownload, onBeforeDownload, port, rootPath, servePath, userLogger, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
40
+ export declare const serve: ({ basePath, bootstrapURL, certificatePath, debug, distImportMapPath, inspectSettings, featureFlags, formatExportTypeError, formatImportError, onAfterDownload, onBeforeDownload, port, rootPath, servePath, userLogger, systemLogger, }: ServeOptions) => Promise<(functions: EdgeFunction[], env?: NodeJS.ProcessEnv, options?: StartServerOptions) => Promise<{
42
41
  features: Record<string, boolean>;
43
42
  functionsConfig: FunctionConfig[];
44
43
  graph: ModuleGraphJson;
@@ -18,9 +18,10 @@ const cleanDirectory = async (directory, except) => {
18
18
  const toBeDeleted = files.filter((file) => !except.includes(join(directory, file)));
19
19
  await Promise.all(toBeDeleted.map((file) => unlink(join(directory, file))));
20
20
  };
21
- const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImportMapPath, flags: denoFlags, formatExportTypeError, formatImportError, importMap: baseImportMap, logger, port, rootPath, }) => {
21
+ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImportMapPath, flags: denoFlags, formatExportTypeError, formatImportError, logger, port, rootPath, }) => {
22
22
  const processRef = {};
23
23
  const startServer = async (functions, env = {}, options = {}) => {
24
+ var _a;
24
25
  if ((processRef === null || processRef === void 0 ? void 0 : processRef.ps) !== undefined) {
25
26
  await killProcess(processRef.ps);
26
27
  }
@@ -38,7 +39,8 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
38
39
  formatImportError,
39
40
  });
40
41
  const features = {};
41
- const importMap = baseImportMap.clone();
42
+ const importMap = new ImportMap();
43
+ await importMap.addFiles((_a = options.importMapPaths) !== null && _a !== void 0 ? _a : [], logger);
42
44
  const npmSpecifiersWithExtraneousFiles = [];
43
45
  // we keep track of the files that are relevant to the user's code, so we can clean up leftovers from past executions later
44
46
  const relevantFiles = [stage2Path];
@@ -138,10 +140,6 @@ formatExportTypeError,
138
140
  * a function.
139
141
  */
140
142
  formatImportError,
141
- /**
142
- * Paths to any additional import map files.
143
- */
144
- importMapPaths = [],
145
143
  /**
146
144
  * Callback function to be triggered after the Deno CLI has been downloaded.
147
145
  */
@@ -205,8 +203,6 @@ systemLogger, }) => {
205
203
  flags.push(inspectSettings.address ? `--inspect=${inspectSettings.address}` : '--inspect');
206
204
  }
207
205
  }
208
- const importMap = new ImportMap();
209
- await importMap.addFiles(importMapPaths, logger);
210
206
  const server = prepareServer({
211
207
  basePath,
212
208
  bootstrapURL,
@@ -217,7 +213,6 @@ systemLogger, }) => {
217
213
  flags,
218
214
  formatExportTypeError,
219
215
  formatImportError,
220
- importMap,
221
216
  logger,
222
217
  port,
223
218
  rootPath,
@@ -19,7 +19,6 @@ test('Starts a server and serves requests for edge functions', async () => {
19
19
  const server = await serve({
20
20
  basePath,
21
21
  bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts',
22
- importMapPaths,
23
22
  port,
24
23
  servePath,
25
24
  });
@@ -39,6 +38,7 @@ test('Starts a server and serves requests for edge functions', async () => {
39
38
  ];
40
39
  const options = {
41
40
  getFunctionsConfig: true,
41
+ importMapPaths,
42
42
  };
43
43
  const { features, functionsConfig, graph, success, npmSpecifiersWithExtraneousFiles } = await server(functions, {
44
44
  very_secret_secret: 'i love netlify',
@@ -97,7 +97,6 @@ test('Serves edge functions in a monorepo setup', async () => {
97
97
  const server = await serve({
98
98
  basePath,
99
99
  bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts',
100
- importMapPaths,
101
100
  port,
102
101
  rootPath,
103
102
  servePath,
@@ -110,6 +109,7 @@ test('Serves edge functions in a monorepo setup', async () => {
110
109
  ];
111
110
  const options = {
112
111
  getFunctionsConfig: true,
112
+ importMapPaths,
113
113
  };
114
114
  const { features, functionsConfig, graph, success, npmSpecifiersWithExtraneousFiles } = await server(functions, {
115
115
  very_secret_secret: 'i love netlify',
@@ -0,0 +1,158 @@
1
+ import type { MediaType } from "./media_type.ts";
2
+ /** Additional meta data that is used to enrich the output of the module
3
+ * graph. */
4
+ export interface CacheInfo {
5
+ /** The string path to where the local version of the content is located. For
6
+ * non `file:` URLs, this is the location of the cached content, otherwise it
7
+ * is the absolute path to the local file. */
8
+ local?: string;
9
+ /** The string path to where a transpiled version of the source content is
10
+ * located, if any. */
11
+ emit?: string;
12
+ /** The string path to where an external source map of the transpiled source
13
+ * content is located, if any. */
14
+ map?: string;
15
+ }
16
+ export interface TypesDependency {
17
+ /** The string URL to the type information for the module. */
18
+ types: string;
19
+ /** An optional range which indicates the source of the dependency. */
20
+ source?: Range;
21
+ }
22
+ export interface LoadResponseModule {
23
+ /** A module with code has been loaded. */
24
+ kind: "module";
25
+ /** The string URL of the resource. If there were redirects, the final
26
+ * specifier should be set here, otherwise the requested specifier. */
27
+ specifier: string;
28
+ /** For remote resources, a record of headers should be set, where the key's
29
+ * have been normalized to be lower case values. */
30
+ headers?: Record<string, string>;
31
+ /** The string value of the loaded resources. */
32
+ content: string;
33
+ }
34
+ export interface LoadResponseExternal {
35
+ /** The loaded module is either _external_ or _built-in_ to the runtime. */
36
+ kind: "external";
37
+ /** The strung URL of the resource. If there were redirects, the final
38
+ * specifier should be set here, otherwise the requested specifier. */
39
+ specifier: string;
40
+ }
41
+ export type LoadResponse = LoadResponseModule | LoadResponseExternal;
42
+ export interface PositionJson {
43
+ /** The line number of a position within a source file. The number is a zero
44
+ * based index. */
45
+ line: number;
46
+ /** The character number of a position within a source file. The number is a
47
+ * zero based index. */
48
+ character: number;
49
+ }
50
+ export interface Range {
51
+ /** A string URL representing a source of a dependency. */
52
+ specifier: string;
53
+ /** The start location of a range of text in a source file. */
54
+ start?: PositionJson;
55
+ /** The end location of a range of text in a source file. */
56
+ end?: PositionJson;
57
+ }
58
+ export interface RangeJson {
59
+ /** The start location of a range of text in a source file. */
60
+ start: PositionJson;
61
+ /** The end location of a range of text in a source file. */
62
+ end: PositionJson;
63
+ }
64
+ export interface ResolvedDependency {
65
+ /** The fully resolved string URL of the dependency, which should be
66
+ * resolvable in the module graph. If there was an error, `error` will be set
67
+ * and this will be undefined. */
68
+ specifier?: string;
69
+ /** Any error encountered when trying to resolved the specifier. If this is
70
+ * defined, `specifier` will be undefined. */
71
+ error?: string;
72
+ /** The range within the source code where the specifier was identified. */
73
+ span: RangeJson;
74
+ }
75
+ export interface TypesDependencyJson {
76
+ /** The string specifier that was used for the dependency. */
77
+ specifier: string;
78
+ /** An object pointing to the resolved dependency. */
79
+ dependency: ResolvedDependency;
80
+ }
81
+ /** The kind of module.
82
+ *
83
+ * For asserted modules, the value of the `asserted` property is set to the
84
+ * `type` value of the import attribute.
85
+ *
86
+ * Dependency analysis is not performed for asserted or Script modules
87
+ * currently. Synthetic modules were injected into the graph with their own
88
+ * dependencies provided. */
89
+ export type ModuleKind = "asserted" | "esm" | "npm" | "external";
90
+ export interface DependencyJson {
91
+ /** The string specifier that was used for the dependency. */
92
+ specifier: string;
93
+ /** An object pointing to the resolved _code_ dependency. */
94
+ code?: ResolvedDependency;
95
+ /** An object pointing to the resolved _type_ dependency of a module. This is
96
+ * populated when the `@deno-types` directive was used to supply a type
97
+ * definition file for a dependency. */
98
+ type?: ResolvedDependency;
99
+ /** A flag indicating if the dependency was dynamic. (e.g.
100
+ * `await import("mod.ts")`) */
101
+ isDynamic?: true;
102
+ assertionType?: string;
103
+ }
104
+ export interface ModuleJson extends CacheInfo {
105
+ /** The string URL of the module. */
106
+ specifier: string;
107
+ /** Any error encountered when attempting to load the module. */
108
+ error?: string;
109
+ /** The module kind that was determined when the module was resolved. This is
110
+ * used by loaders to indicate how a module needs to be loaded at runtime. */
111
+ kind?: ModuleKind;
112
+ /** An array of dependencies that were identified in the module. */
113
+ dependencies?: DependencyJson[];
114
+ /** If the module had a types dependency, the information about that
115
+ * dependency. */
116
+ typesDependency?: TypesDependencyJson;
117
+ /** The resolved media type of the module, which determines how Deno will
118
+ * handle the module. */
119
+ mediaType?: MediaType;
120
+ /** The size of the source content of the module in bytes. */
121
+ size?: number;
122
+ }
123
+ export interface GraphImportJson {
124
+ /** The referrer (URL string) that was used as a base when resolving the
125
+ * imports added to the graph. */
126
+ referrer: string;
127
+ /** An array of resolved dependencies which were imported using the
128
+ * referrer. */
129
+ dependencies?: DependencyJson[];
130
+ }
131
+ /** The plain-object representation of a module graph that is suitable for
132
+ * serialization to JSON. */
133
+ export interface ModuleGraphJson {
134
+ /** The module specifiers (URL string) of the _roots_ of the module graph of
135
+ * which the module graph was built for. */
136
+ roots: string[];
137
+ /** An array of modules that are part of the module graph. */
138
+ modules: ModuleJson[];
139
+ /** External imports that were added to the graph when it was being built.
140
+ * The key is the referrer which was used as a base to resolve the
141
+ * dependency. The value is the resolved dependency. */
142
+ imports?: GraphImportJson[];
143
+ /** A record/map of any redirects encountered when resolving modules. The
144
+ * key was the requested module specifier and the value is the redirected
145
+ * module specifier. */
146
+ redirects: Record<string, string>;
147
+ }
148
+ export interface Dependency {
149
+ /** An object pointing to the resolved _code_ dependency. */
150
+ code?: ResolvedDependency;
151
+ /** An object pointing to the resolved _type_ dependency of a module. This is
152
+ * populated when the `@deno-types` directive was used to supply a type
153
+ * definition file for a dependency. */
154
+ type?: ResolvedDependency;
155
+ /** A flag indicating if the dependency was dynamic. (e.g.
156
+ * `await import("mod.ts")`) */
157
+ isDynamic?: true;
158
+ }
@@ -0,0 +1,2 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "10.1.2",
3
+ "version": "11.0.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -35,11 +35,11 @@
35
35
  "test:ci:vitest": "vitest run --coverage",
36
36
  "test:ci:deno": "deno test --allow-all deno",
37
37
  "test:integration": "node --experimental-modules test/integration/test.js",
38
- "vendor": "deno vendor --force --output deno/vendor https://deno.land/x/deno_graph@0.59.2/types.d.ts https://deno.land/x/eszip@v0.55.2/mod.ts https://deno.land/x/retry@v2.0.0/mod.ts https://deno.land/x/std@0.177.0/path/mod.ts"
38
+ "vendor": "deno vendor --force --output deno/vendor https://deno.land/x/eszip@v0.55.2/mod.ts https://deno.land/x/retry@v2.0.0/mod.ts https://deno.land/x/std@0.177.0/path/mod.ts"
39
39
  },
40
40
  "config": {
41
41
  "eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{node,scripts,.github}/**/*.{js,ts,md,html}\" \"*.{js,ts,md,html}\"",
42
- "prettier": "--ignore-path .gitignore --loglevel=warn \"{node,scripts,.github}/**/*.{js,ts,md,yml,json,html}\" \"*.{js,ts,yml,json,html}\" \".*.{js,ts,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\""
42
+ "prettier": "--ignore-path .gitignore --loglevel=warn \"{node,scripts,.github}/**/*.{js,ts,md,yml,json,html}\" \"*.{js,ts,yml,json,html}\" \".*.{js,ts,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\" \"!node/vendor/**\""
43
43
  },
44
44
  "keywords": [],
45
45
  "license": "MIT",
@@ -81,7 +81,7 @@
81
81
  "better-ajv-errors": "^1.2.0",
82
82
  "common-path-prefix": "^3.0.0",
83
83
  "env-paths": "^3.0.0",
84
- "esbuild": "0.19.5",
84
+ "esbuild": "0.19.9",
85
85
  "execa": "^6.0.0",
86
86
  "find-up": "^6.3.0",
87
87
  "get-package-name": "^2.2.0",
@@ -1,20 +0,0 @@
1
- // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
-
3
- export enum MediaType {
4
- JavaScript = "JavaScript",
5
- Mjs = "Mjs",
6
- Cjs = "Cjs",
7
- Jsx = "Jsx",
8
- TypeScript = "TypeScript",
9
- Mts = "Mts",
10
- Cts = "Cts",
11
- Dts = "Dts",
12
- Dmts = "Dmts",
13
- Dcts = "Dcts",
14
- Tsx = "Tsx",
15
- Json = "Json",
16
- Wasm = "Wasm",
17
- TsBuildInfo = "TsBuildInfo",
18
- SourceMap = "SourceMap",
19
- Unknown = "Unknown",
20
- }
@@ -1,182 +0,0 @@
1
- // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
-
3
- import type { MediaType } from "./media_type.ts";
4
-
5
- /** Additional meta data that is used to enrich the output of the module
6
- * graph. */
7
- export interface CacheInfo {
8
- /** The string path to where the local version of the content is located. For
9
- * non `file:` URLs, this is the location of the cached content, otherwise it
10
- * is the absolute path to the local file. */
11
- local?: string;
12
- /** The string path to where a transpiled version of the source content is
13
- * located, if any. */
14
- emit?: string;
15
- /** The string path to where an external source map of the transpiled source
16
- * content is located, if any. */
17
- map?: string;
18
- }
19
-
20
- export interface TypesDependency {
21
- /** The string URL to the type information for the module. */
22
- types: string;
23
- /** An optional range which indicates the source of the dependency. */
24
- source?: Range;
25
- }
26
-
27
- export interface LoadResponseModule {
28
- /** A module with code has been loaded. */
29
- kind: "module";
30
- /** The string URL of the resource. If there were redirects, the final
31
- * specifier should be set here, otherwise the requested specifier. */
32
- specifier: string;
33
- /** For remote resources, a record of headers should be set, where the key's
34
- * have been normalized to be lower case values. */
35
- headers?: Record<string, string>;
36
- /** The string value of the loaded resources. */
37
- content: string;
38
- }
39
-
40
- export interface LoadResponseExternal {
41
- /** The loaded module is either _external_ or _built-in_ to the runtime. */
42
- kind: "external";
43
- /** The strung URL of the resource. If there were redirects, the final
44
- * specifier should be set here, otherwise the requested specifier. */
45
- specifier: string;
46
- }
47
-
48
- export type LoadResponse = LoadResponseModule | LoadResponseExternal;
49
-
50
- export interface PositionJson {
51
- /** The line number of a position within a source file. The number is a zero
52
- * based index. */
53
- line: number;
54
- /** The character number of a position within a source file. The number is a
55
- * zero based index. */
56
- character: number;
57
- }
58
-
59
- export interface Range {
60
- /** A string URL representing a source of a dependency. */
61
- specifier: string;
62
- /** The start location of a range of text in a source file. */
63
- start?: PositionJson;
64
- /** The end location of a range of text in a source file. */
65
- end?: PositionJson;
66
- }
67
-
68
- export interface RangeJson {
69
- /** The start location of a range of text in a source file. */
70
- start: PositionJson;
71
- /** The end location of a range of text in a source file. */
72
- end: PositionJson;
73
- }
74
-
75
- export interface ResolvedDependency {
76
- /** The fully resolved string URL of the dependency, which should be
77
- * resolvable in the module graph. If there was an error, `error` will be set
78
- * and this will be undefined. */
79
- specifier?: string;
80
- /** Any error encountered when trying to resolved the specifier. If this is
81
- * defined, `specifier` will be undefined. */
82
- error?: string;
83
- /** The range within the source code where the specifier was identified. */
84
- span: RangeJson;
85
- }
86
-
87
- export interface TypesDependencyJson {
88
- /** The string specifier that was used for the dependency. */
89
- specifier: string;
90
- /** An object pointing to the resolved dependency. */
91
- dependency: ResolvedDependency;
92
- }
93
-
94
- /** The kind of module.
95
- *
96
- * For asserted modules, the value of the `asserted` property is set to the
97
- * `type` value of the import attribute.
98
- *
99
- * Dependency analysis is not performed for asserted or Script modules
100
- * currently. Synthetic modules were injected into the graph with their own
101
- * dependencies provided. */
102
- export type ModuleKind =
103
- | "asserted"
104
- | "esm"
105
- | "npm"
106
- | "external";
107
-
108
- export interface DependencyJson {
109
- /** The string specifier that was used for the dependency. */
110
- specifier: string;
111
- /** An object pointing to the resolved _code_ dependency. */
112
- code?: ResolvedDependency;
113
- /** An object pointing to the resolved _type_ dependency of a module. This is
114
- * populated when the `@deno-types` directive was used to supply a type
115
- * definition file for a dependency. */
116
- type?: ResolvedDependency;
117
- /** A flag indicating if the dependency was dynamic. (e.g.
118
- * `await import("mod.ts")`) */
119
- isDynamic?: true;
120
- assertionType?: string;
121
- }
122
-
123
- // todo(dsherret): split this up into separate types based on the "kind"
124
-
125
- export interface ModuleJson extends CacheInfo {
126
- /** The string URL of the module. */
127
- specifier: string;
128
- /** Any error encountered when attempting to load the module. */
129
- error?: string;
130
- /** The module kind that was determined when the module was resolved. This is
131
- * used by loaders to indicate how a module needs to be loaded at runtime. */
132
- kind?: ModuleKind;
133
- /** An array of dependencies that were identified in the module. */
134
- dependencies?: DependencyJson[];
135
- /** If the module had a types dependency, the information about that
136
- * dependency. */
137
- typesDependency?: TypesDependencyJson;
138
- /** The resolved media type of the module, which determines how Deno will
139
- * handle the module. */
140
- mediaType?: MediaType;
141
- /** The size of the source content of the module in bytes. */
142
- size?: number;
143
- }
144
-
145
- export interface GraphImportJson {
146
- /** The referrer (URL string) that was used as a base when resolving the
147
- * imports added to the graph. */
148
- referrer: string;
149
- /** An array of resolved dependencies which were imported using the
150
- * referrer. */
151
- dependencies?: DependencyJson[];
152
- }
153
-
154
- /** The plain-object representation of a module graph that is suitable for
155
- * serialization to JSON. */
156
- export interface ModuleGraphJson {
157
- /** The module specifiers (URL string) of the _roots_ of the module graph of
158
- * which the module graph was built for. */
159
- roots: string[];
160
- /** An array of modules that are part of the module graph. */
161
- modules: ModuleJson[];
162
- /** External imports that were added to the graph when it was being built.
163
- * The key is the referrer which was used as a base to resolve the
164
- * dependency. The value is the resolved dependency. */
165
- imports?: GraphImportJson[];
166
- /** A record/map of any redirects encountered when resolving modules. The
167
- * key was the requested module specifier and the value is the redirected
168
- * module specifier. */
169
- redirects: Record<string, string>;
170
- }
171
-
172
- export interface Dependency {
173
- /** An object pointing to the resolved _code_ dependency. */
174
- code?: ResolvedDependency;
175
- /** An object pointing to the resolved _type_ dependency of a module. This is
176
- * populated when the `@deno-types` directive was used to supply a type
177
- * definition file for a dependency. */
178
- type?: ResolvedDependency;
179
- /** A flag indicating if the dependency was dynamic. (e.g.
180
- * `await import("mod.ts")`) */
181
- isDynamic?: true;
182
- }