@netlify/edge-bundler 7.0.0 → 7.0.1

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, vi } from 'vitest';
@@ -286,23 +287,35 @@ test('Loads declarations and import maps from the deploy configuration', async (
286
287
  test("Ignores entries in `importMapPaths` that don't point to an existing import map file", async () => {
287
288
  const systemLogger = vi.fn();
288
289
  const { basePath, cleanup, distPath } = await useFixture('with_import_maps');
289
- const sourceDirectory = join(basePath, 'functions');
290
- const importMapPath = join(distPath, 'some-file-that-does-not-exist.json');
291
- const declarations = [
290
+ const sourceDirectory = join(basePath, 'user-functions');
291
+ // Creating import map file
292
+ const importMap = await tmp.file();
293
+ const importMapContents = {
294
+ imports: {
295
+ helper: pathToFileURL(join(basePath, 'helper.ts')).toString(),
296
+ },
297
+ scopes: {
298
+ [pathToFileURL(join(sourceDirectory, 'func3')).toString()]: {
299
+ helper: pathToFileURL(join(basePath, 'helper2.ts')).toString(),
300
+ },
301
+ },
302
+ };
303
+ await fs.writeFile(importMap.path, JSON.stringify(importMapContents));
304
+ const nonExistingImportMapPath = join(distPath, 'some-file-that-does-not-exist.json');
305
+ const result = await bundle([sourceDirectory], distPath, [
292
306
  {
293
307
  function: 'func1',
294
308
  path: '/func1',
295
309
  },
296
- ];
297
- const result = await bundle([sourceDirectory], distPath, declarations, {
310
+ ], {
298
311
  basePath,
299
- configPath: join(sourceDirectory, 'config.json'),
300
- importMapPaths: [importMapPath],
312
+ importMapPaths: [nonExistingImportMapPath, importMap.path],
301
313
  systemLogger,
302
314
  });
303
315
  const generatedFiles = await fs.readdir(distPath);
304
- expect(result.functions.length).toBe(1);
316
+ expect(result.functions.length).toBe(2);
305
317
  expect(generatedFiles.length).toBe(2);
306
- expect(systemLogger).toHaveBeenCalledWith(`Did not find an import map file at '${importMapPath}'.`);
318
+ expect(systemLogger).toHaveBeenCalledWith(`Did not find an import map file at '${nonExistingImportMapPath}'.`);
307
319
  await cleanup();
320
+ await importMap.cleanup();
308
321
  });
@@ -85,7 +85,7 @@ class ImportMap {
85
85
  async addFiles(paths, logger) {
86
86
  for (const path of paths) {
87
87
  if (path === undefined) {
88
- return;
88
+ continue;
89
89
  }
90
90
  await this.addFile(path, logger);
91
91
  }
package/dist/test/util.js CHANGED
@@ -12,13 +12,12 @@ const url = new URL(import.meta.url);
12
12
  const dirname = fileURLToPath(url);
13
13
  const fixturesDir = resolve(dirname, '..', 'fixtures');
14
14
  const useFixture = async (fixtureName) => {
15
- const tmpDir = await tmp.dir();
16
- const cleanup = () => fs.rmdir(tmpDir.path, { recursive: true });
15
+ const tmpDir = await tmp.dir({ unsafeCleanup: true });
17
16
  const fixtureDir = resolve(fixturesDir, fixtureName);
18
17
  const distPath = join(tmpDir.path, '.netlify', 'edge-functions-dist');
19
18
  return {
20
19
  basePath: fixtureDir,
21
- cleanup,
20
+ cleanup: tmpDir.cleanup,
22
21
  distPath,
23
22
  };
24
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",