@netlify/edge-bundler 5.3.1 → 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';
|
|
@@ -8,6 +9,7 @@ import { useFixture } from '../test/util.js';
|
|
|
8
9
|
import { BundleError } from './bundle_error.js';
|
|
9
10
|
import { bundle } from './bundler.js';
|
|
10
11
|
import { isNodeError } from './utils/error.js';
|
|
12
|
+
import { validateManifest } from './validation/manifest/index.js';
|
|
11
13
|
test('Produces an ESZIP bundle', async () => {
|
|
12
14
|
const { basePath, cleanup, distPath } = await useFixture('with_import_maps');
|
|
13
15
|
const declarations = [
|
|
@@ -27,6 +29,7 @@ test('Produces an ESZIP bundle', async () => {
|
|
|
27
29
|
expect(generatedFiles.length).toBe(3);
|
|
28
30
|
const manifestFile = await fs.readFile(resolve(distPath, 'manifest.json'), 'utf8');
|
|
29
31
|
const manifest = JSON.parse(manifestFile);
|
|
32
|
+
expect(() => validateManifest(manifest)).not.toThrowError();
|
|
30
33
|
const { bundles, import_map: importMapURL } = manifest;
|
|
31
34
|
expect(bundles.length).toBe(1);
|
|
32
35
|
expect(bundles[0].format).toBe('eszip2');
|
|
@@ -280,3 +283,33 @@ test('Loads declarations and import maps from the deploy configuration', async (
|
|
|
280
283
|
expect(generatedFiles.includes(bundles[0].asset)).toBe(true);
|
|
281
284
|
await cleanup();
|
|
282
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
|
|
39
|
-
|
|
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 = () => {
|
|
@@ -115,12 +115,12 @@ describe('layers', () => {
|
|
|
115
115
|
describe('import map URL', () => {
|
|
116
116
|
test('should accept string value', () => {
|
|
117
117
|
const manifest = getBaseManifest();
|
|
118
|
-
manifest.
|
|
118
|
+
manifest.import_map = 'file:///root/.netlify/edge-functions-dist/import_map.json';
|
|
119
119
|
expect(() => validateManifest(manifest)).not.toThrowError();
|
|
120
120
|
});
|
|
121
121
|
test('should throw on wrong type', () => {
|
|
122
122
|
const manifest = getBaseManifest();
|
|
123
|
-
manifest.
|
|
123
|
+
manifest.import_map = ['file:///root/.netlify/edge-functions-dist/import_map.json'];
|
|
124
124
|
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot();
|
|
125
125
|
});
|
|
126
126
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "5.3.
|
|
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": "^
|
|
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",
|