@netlify/edge-bundler 14.9.7 → 14.9.8

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.
@@ -38,12 +38,6 @@ export const bundle = async ({ buildID, deno, distDirectory, functions, importMa
38
38
  await fs.mkdir(path.dirname(destPath), { recursive: true });
39
39
  await fs.copyFile(sourceFile, destPath);
40
40
  }
41
- // Rewrite bare specifier imports to their resolved URLs so they can be
42
- // resolved by Deno's --vendor flag at runtime without needing the customer's import map.
43
- // At runtime, Deno discovers config from /platform/deno.json (the bootstrap entry
44
- // point), not /function/deno.json, so the customer's import map is unreachable.
45
- // This is because we boot Deno before we've mounted the customer's edge-functions directory, so it can't be used to resolve imports during the initial bundle phase.
46
- await rewriteBareSpecifiers(bundleDir.path, sourceFiles, commonPath, importMap);
47
41
  // Vendor all dependencies in the bundle directory
48
42
  await deno.run([
49
43
  'install',
@@ -78,6 +72,11 @@ export const bundle = async ({ buildID, deno, distDirectory, functions, importMa
78
72
  }
79
73
  // Map common path to relative paths
80
74
  prefixes[pathToFileURL(commonPath + path.sep).href] = './';
75
+ // Rewrite bare specifier imports to their resolved URLs so they can be
76
+ // resolved by Deno's --vendor flag at runtime without needing the customer's import map.
77
+ // At runtime, Deno discovers config from /platform/deno.json (the bootstrap entry
78
+ // point), not /function/deno.json, so the customer's import map is unreachable.
79
+ await rewriteBareSpecifiers(bundleDir.path, sourceFiles, commonPath, importMap, prefixes);
81
80
  // Get import map contents with file:// URLs transformed to relative paths
82
81
  const importMapContents = importMap.getContents(prefixes);
83
82
  // Create deno.json with import map contents for runtime resolution
@@ -130,10 +129,10 @@ const REWRITABLE_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.m
130
129
  * - Resolve to http/https or npm: URLs in the import map
131
130
  * - Are NOT node builtins or platform-provided imports
132
131
  */
133
- async function rewriteBareSpecifiers(bundleDirPath, sourceFiles, commonPath, importMap) {
134
- const contents = importMap.getContents();
132
+ async function rewriteBareSpecifiers(bundleDirPath, sourceFiles, commonPath, importMap, prefixes) {
133
+ const contents = importMap.getContents(prefixes);
135
134
  const builtinSet = new Set(builtinModules);
136
- // Collect bare specifiers that should be rewritten to URLs
135
+ // Collect bare specifiers that should be rewritten to URLs or relative paths
137
136
  const specifierEntries = Object.entries(contents.imports)
138
137
  .filter(([specifier, url]) => {
139
138
  // Skip node builtins
@@ -142,13 +141,17 @@ async function rewriteBareSpecifiers(bundleDirPath, sourceFiles, commonPath, imp
142
141
  // Skip platform-provided specifiers (handled by platform deno.json)
143
142
  if (PLATFORM_SPECIFIERS.has(specifier))
144
143
  return false;
145
- // Skip relative/absolute path specifiers
144
+ // Skip relative/absolute path specifiers in the specifier itself
146
145
  if (specifier.startsWith('.') || specifier.startsWith('/'))
147
146
  return false;
148
- // Only rewrite to http/https or npm: URLs
149
- if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('npm:'))
150
- return false;
151
- return true;
147
+ // Rewrite http/https, npm:, or vendored npm modules (relative paths with .netlify-npm-vendor)
148
+ if (url.startsWith('http://') ||
149
+ url.startsWith('https://') ||
150
+ url.startsWith('npm:') ||
151
+ url.includes('.netlify-npm-vendor')) {
152
+ return true;
153
+ }
154
+ return false;
152
155
  })
153
156
  // Sort longest first so prefix mappings like "lodash/" match before "lodash"
154
157
  .sort((a, b) => b[0].length - a[0].length);
@@ -167,8 +170,19 @@ async function rewriteBareSpecifiers(bundleDirPath, sourceFiles, commonPath, imp
167
170
  let modified = source;
168
171
  for (const [specifier, url] of specifierEntries) {
169
172
  const escaped = specifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
173
+ // Convert bundle-root-relative paths to source-file-relative paths
174
+ let targetUrl = url;
175
+ if (url.startsWith('./') || url.startsWith('../')) {
176
+ // URL is relative to bundle root (e.g., "./.netlify-npm-vendor/bundled-parent-1.js")
177
+ // Convert to absolute path in bundle, then to relative from source file
178
+ const targetAbsolutePath = path.resolve(bundleDirPath, url);
179
+ const relativeImport = path.relative(path.dirname(destPath), targetAbsolutePath);
180
+ // Ensure forward slashes and ./ prefix for clarity
181
+ targetUrl = relativeImport.startsWith('.') ? relativeImport : `./${relativeImport}`;
182
+ targetUrl = targetUrl.replace(/\\/g, '/');
183
+ }
170
184
  // Escape $ in URL for use in replacement string
171
- const safeUrl = url.replace(/\$/g, '$$$$');
185
+ const safeUrl = targetUrl.replace(/\$/g, '$$$$');
172
186
  for (const quote of ['"', "'"]) {
173
187
  if (specifier.endsWith('/')) {
174
188
  // Prefix mapping: "specifier/subpath" -> "url/subpath"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "14.9.7",
3
+ "version": "14.9.8",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -79,5 +79,5 @@
79
79
  "urlpattern-polyfill": "8.0.2",
80
80
  "uuid": "^11.0.0"
81
81
  },
82
- "gitHead": "55f6d3568bcea071e679b4152c3273eb48223159"
82
+ "gitHead": "4395795665bc891337d375d51b0a63f6551d7d83"
83
83
  }