@netlify/edge-bundler 14.7.1 → 14.8.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/README.md CHANGED
@@ -38,12 +38,11 @@ Intelligently prepare Netlify Edge Functions for deployment.
38
38
  To avoid pulling in additional dependencies at runtime, this package vendors some Deno modules in the `deno/vendor`
39
39
  directory.
40
40
 
41
- You can recreate this directory by running `npm run vendor`.
41
+ This will go away soon as we move away from the ESZIP format.
42
42
 
43
43
  > [!WARNING]
44
- > At the time of writing, the underlying Deno CLI command doesn't correctly pull the WASM binary required by the ESZIP
45
- > module. If you run the command to update the list of vendores modules, please ensure you're not deleting
46
- > `eszip_wasm_bg.wasm`.
44
+ > The `eszip` module contains a set of custom changes that diverge from the upstream. If you need to update this module,
45
+ > make sure to backport them.
47
46
 
48
47
  ## Contributors
49
48
 
@@ -81,6 +81,12 @@ class V2 {
81
81
  const imports: Record<string, string> = {};
82
82
 
83
83
  for (const specifier of this.specifiers) {
84
+ // NOTE: This is specific to Netlify, to address the fact that we can't
85
+ // unpack remote URL specifiers to paths on disk.
86
+ // https://github.com/netlify/build/pull/6716
87
+ // https://github.com/netlify/build/pull/6720
88
+ // https://github.com/netlify/build/pull/6722
89
+ if (new URL(specifier).protocol !== "file:") continue
84
90
  const module = await this.parser.getModuleSource(specifier);
85
91
  await write(join(dest, "source", url2path(specifier)), module);
86
92
  // Track import
@@ -107,11 +113,8 @@ export async function loadESZIP(filename: string): Promise<ESZIP> {
107
113
  return await V1.load(bytes);
108
114
  }
109
115
 
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);
116
+ function url2path(url: string) {
117
+ return join(...(new URL(url).pathname.split("/").filter(Boolean)));
115
118
  }
116
119
 
117
120
  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,28 @@ 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
+ log.user('WARNING: Import assertions are deprecated and will be removed soon. Refer to https://ntl.fyi/import-assert for more information.');
149
+ try {
150
+ // We failed to extract the configuration because there is an import assert
151
+ // in the function code, a deprecated feature that we used to support with
152
+ // Deno 1.x. To avoid a breaking change, we treat this error as a special
153
+ // case, using the generated ESZIP to extract the configuration. This works
154
+ // because import asserts are transpiled to import attributes.
155
+ const extractedESZIP = await extractESZIP(deno, eszipPath);
156
+ const configs = await Promise.all([...internalFunctions, ...userFunctions].map(async (func) => {
157
+ const relativePath = relative(basePath, func.path);
158
+ const functionPath = join(extractedESZIP.path, relativePath);
159
+ return [func.name, await getFunctionConfig({ functionPath, importMap, deno, log })];
160
+ }));
161
+ await extractedESZIP.cleanup();
162
+ return {
163
+ internalFunctions: Object.fromEntries(configs.slice(0, internalFunctions.length)),
164
+ userFunctions: Object.fromEntries(configs.slice(internalFunctions.length)),
165
+ };
166
+ }
167
+ catch (err) {
168
+ 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 });
169
+ }
163
170
  }
164
171
  };
165
172
  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.8.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -24,8 +24,7 @@
24
24
  "test:dev:deno": "deno test --allow-all deno",
25
25
  "test:ci:vitest": "vitest run --coverage",
26
26
  "test:ci:deno": "deno test --allow-all deno",
27
- "test:integration": "node --experimental-modules test/integration/test.js",
28
- "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"
27
+ "test:integration": "node --experimental-modules test/integration/test.js"
29
28
  },
30
29
  "keywords": [],
31
30
  "license": "MIT",
@@ -80,5 +79,5 @@
80
79
  "urlpattern-polyfill": "8.0.2",
81
80
  "uuid": "^11.0.0"
82
81
  },
83
- "gitHead": "b08cf327fc8a631e3520c5f3326ace1d40e22c85"
82
+ "gitHead": "01a7441fcbc82d415247bf990414ad937e9533c4"
84
83
  }