@netlify/edge-bundler 14.7.1 → 14.7.2

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.
@@ -81,6 +81,7 @@ class V2 {
81
81
  const imports: Record<string, string> = {};
82
82
 
83
83
  for (const specifier of this.specifiers) {
84
+ if (new URL(specifier).protocol !== "file:") continue
84
85
  const module = await this.parser.getModuleSource(specifier);
85
86
  await write(join(dest, "source", url2path(specifier)), module);
86
87
  // Track import
@@ -107,11 +108,8 @@ export async function loadESZIP(filename: string): Promise<ESZIP> {
107
108
  return await V1.load(bytes);
108
109
  }
109
110
 
110
- function url2path(urlString: string) {
111
- const url = new URL(urlString);
112
- const tail = url.pathname.split("/").filter(Boolean);
113
- const relativePath = tail.length === 0 ? [".root"] : tail;
114
- return join(url.hostname, ...relativePath);
111
+ function url2path(url: string) {
112
+ return join(...(new URL(url).pathname.split("/").filter(Boolean)));
115
113
  }
116
114
 
117
115
  async function write(path: string, content: string) {
@@ -17,6 +17,7 @@ import { writeManifest } from './manifest.js';
17
17
  import { vendorNPMSpecifiers } from './npm_dependencies.js';
18
18
  import { ensureLatestTypes } from './types.js';
19
19
  import { nonNullable } from './utils/non_nullable.js';
20
+ import { BundleError } from './bundle_error.js';
20
21
  export const bundle = async (sourceDirectories, distDirectory, tomlDeclarations = [], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths = [], internalSrcFolder, onAfterDownload, onBeforeDownload, rootPath, userLogger, systemLogger, vendorDirectory, } = {}) => {
21
22
  const logger = getLogger(systemLogger, userLogger, debug);
22
23
  const featureFlags = getFlags(inputFeatureFlags);
@@ -144,22 +145,27 @@ const getFunctionConfigs = async ({ basePath, deno, eszipPath, featureFlags, imp
144
145
  if (!(err instanceof Error && err.cause === 'IMPORT_ASSERT') || !eszipPath || !featureFlags?.edge_bundler_deno_v2) {
145
146
  throw err;
146
147
  }
147
- // We failed to extract the configuration because there is an import assert
148
- // in the function code, a deprecated feature that we used to support with
149
- // Deno 1.x. To avoid a breaking change, we treat this error as a special
150
- // case, using the generated ESZIP to extract the configuration. This works
151
- // because import asserts are transpiled to import attributes.
152
- const extractedESZIP = await extractESZIP(deno, eszipPath);
153
- const configs = await Promise.all([...internalFunctions, ...userFunctions].map(async (func) => {
154
- const relativePath = relative(basePath, func.path);
155
- const functionPath = join(extractedESZIP.path, relativePath);
156
- return [func.name, await getFunctionConfig({ functionPath, importMap, deno, log })];
157
- }));
158
- await extractedESZIP.cleanup();
159
- return {
160
- internalFunctions: Object.fromEntries(configs.slice(0, internalFunctions.length)),
161
- userFunctions: Object.fromEntries(configs.slice(internalFunctions.length)),
162
- };
148
+ try {
149
+ // We failed to extract the configuration because there is an import assert
150
+ // in the function code, a deprecated feature that we used to support with
151
+ // Deno 1.x. To avoid a breaking change, we treat this error as a special
152
+ // case, using the generated ESZIP to extract the configuration. This works
153
+ // because import asserts are transpiled to import attributes.
154
+ const extractedESZIP = await extractESZIP(deno, eszipPath);
155
+ const configs = await Promise.all([...internalFunctions, ...userFunctions].map(async (func) => {
156
+ const relativePath = relative(basePath, func.path);
157
+ const functionPath = join(extractedESZIP.path, relativePath);
158
+ return [func.name, await getFunctionConfig({ functionPath, importMap, deno, log })];
159
+ }));
160
+ await extractedESZIP.cleanup();
161
+ return {
162
+ internalFunctions: Object.fromEntries(configs.slice(0, internalFunctions.length)),
163
+ userFunctions: Object.fromEntries(configs.slice(internalFunctions.length)),
164
+ };
165
+ }
166
+ catch (err) {
167
+ throw new BundleError(new Error('An error occurred while building an edge function that uses an import assertion. Refer to https://ntl.fyi/import-assert for more information.'), { cause: err });
168
+ }
163
169
  }
164
170
  };
165
171
  const createFinalBundles = async (bundles, distDirectory, buildID) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "14.7.1",
3
+ "version": "14.7.2",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -80,5 +80,5 @@
80
80
  "urlpattern-polyfill": "8.0.2",
81
81
  "uuid": "^11.0.0"
82
82
  },
83
- "gitHead": "b08cf327fc8a631e3520c5f3326ace1d40e22c85"
83
+ "gitHead": "1cf876ef6b79ef8332044a3e32db846652be9f23"
84
84
  }