@netlify/edge-bundler 5.3.2 → 5.3.3

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.
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { join, resolve } from 'path';
3
3
  import process from 'process';
4
+ import { pathToFileURL } from 'url';
4
5
  import { deleteAsync } from 'del';
5
6
  import tmp from 'tmp-promise';
6
7
  import { test, expect } from 'vitest';
@@ -282,3 +283,33 @@ test('Loads declarations and import maps from the deploy configuration', async (
282
283
  expect(generatedFiles.includes(bundles[0].asset)).toBe(true);
283
284
  await cleanup();
284
285
  });
286
+ test('Uses an absolute URL for the import map when the dist directory is not a child of the base path', async () => {
287
+ const { basePath, cleanup } = await useFixture('with_import_maps');
288
+ const { path: distPath } = await tmp.dir();
289
+ const declarations = [
290
+ {
291
+ function: 'func1',
292
+ path: '/func1',
293
+ },
294
+ ];
295
+ const sourceDirectory = join(basePath, 'functions');
296
+ const result = await bundle([sourceDirectory], distPath, declarations, {
297
+ basePath,
298
+ configPath: join(sourceDirectory, 'config.json'),
299
+ });
300
+ const generatedFiles = await fs.readdir(distPath);
301
+ expect(result.functions.length).toBe(1);
302
+ // ESZIP, manifest and import map.
303
+ expect(generatedFiles.length).toBe(3);
304
+ const manifestFile = await fs.readFile(resolve(distPath, 'manifest.json'), 'utf8');
305
+ const manifest = JSON.parse(manifestFile);
306
+ expect(() => validateManifest(manifest)).not.toThrowError();
307
+ const { bundles, import_map: importMapURL } = manifest;
308
+ expect(bundles.length).toBe(1);
309
+ expect(bundles[0].format).toBe('eszip2');
310
+ expect(generatedFiles.includes(bundles[0].asset)).toBe(true);
311
+ const importMapPath = join(distPath, 'import_map.json');
312
+ expect(importMapURL).toBe(pathToFileURL(importMapPath).toString());
313
+ await cleanup();
314
+ await fs.rm(distPath, { recursive: true });
315
+ });
@@ -1,4 +1,5 @@
1
1
  import { join, relative } from 'path';
2
+ import { pathToFileURL } from 'url';
2
3
  import { virtualRoot } from '../../shared/consts.js';
3
4
  import { BundleFormat } from '../bundle.js';
4
5
  import { wrapBundleError } from '../bundle_error.js';
@@ -35,8 +36,16 @@ const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, exte
35
36
  const createUserImportMap = async (importMap, basePath, distDirectory) => {
36
37
  const destPath = join(distDirectory, 'import_map.json');
37
38
  await importMap.writeToFile(destPath);
38
- const relativePath = relative(basePath, destPath);
39
- const importMapURL = new URL(relativePath, virtualRoot);
39
+ const virtualPath = relative(basePath, destPath);
40
+ // If the dist directory is not a child of the base path, we can't represent
41
+ // the relative path as a file URL (because something like 'file://../foo' is
42
+ // not valid). This should never happen, but it's best to leave the absolute
43
+ // path untransformed to avoid getting a build error due to a missing import
44
+ // map.
45
+ if (virtualPath.startsWith('..')) {
46
+ return pathToFileURL(destPath).toString();
47
+ }
48
+ const importMapURL = new URL(virtualPath, virtualRoot);
40
49
  return importMapURL.toString();
41
50
  };
42
51
  const getESZIPPaths = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "5.3.2",
3
+ "version": "5.3.3",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -57,7 +57,7 @@
57
57
  "@types/node": "^14.18.32",
58
58
  "@types/semver": "^7.3.9",
59
59
  "@types/sinon": "^10.0.8",
60
- "@types/uuid": "^8.3.4",
60
+ "@types/uuid": "^9.0.0",
61
61
  "@vitest/coverage-c8": "^0.25.0",
62
62
  "archiver": "^5.3.1",
63
63
  "cpy": "^9.0.1",