@netlify/edge-bundler 14.7.2 → 14.8.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.
- package/README.md +3 -4
- package/deno/vendor/deno.land/x/eszip@v0.55.2/eszip.ts +5 -0
- package/dist/node/bridge.js +3 -1
- package/dist/node/bundler.js +21 -3
- package/dist/node/bundler.test.js +59 -0
- package/dist/node/feature_flags.d.ts +2 -0
- package/dist/node/feature_flags.js +1 -0
- package/package.json +3 -4
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
|
-
|
|
41
|
+
This will go away soon as we move away from the ESZIP format.
|
|
42
42
|
|
|
43
43
|
> [!WARNING]
|
|
44
|
-
>
|
|
45
|
-
>
|
|
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,11 @@ 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
|
|
84
89
|
if (new URL(specifier).protocol !== "file:") continue
|
|
85
90
|
const module = await this.parser.getModuleSource(specifier);
|
|
86
91
|
await write(join(dest, "source", url2path(specifier)), module);
|
package/dist/node/bridge.js
CHANGED
|
@@ -32,7 +32,9 @@ export class DenoBridge {
|
|
|
32
32
|
this.onAfterDownload = options.onAfterDownload;
|
|
33
33
|
this.onBeforeDownload = options.onBeforeDownload;
|
|
34
34
|
this.useGlobal = options.useGlobal ?? true;
|
|
35
|
-
const useNextDeno = options.featureFlags?.
|
|
35
|
+
const useNextDeno = options.featureFlags?.edge_bundler_dry_run_generate_tarball ||
|
|
36
|
+
options.featureFlags?.edge_bundler_generate_tarball ||
|
|
37
|
+
options.featureFlags?.edge_bundler_deno_v2;
|
|
36
38
|
this.versionRange = options.versionRange ?? (useNextDeno ? NEXT_DENO_VERSION_RANGE : DENO_VERSION_RANGE);
|
|
37
39
|
}
|
|
38
40
|
async downloadBinary() {
|
package/dist/node/bundler.js
CHANGED
|
@@ -62,8 +62,8 @@ export const bundle = async (sourceDirectories, distDirectory, tomlDeclarations
|
|
|
62
62
|
vendorDirectory,
|
|
63
63
|
});
|
|
64
64
|
const bundles = [];
|
|
65
|
-
if (featureFlags.edge_bundler_generate_tarball) {
|
|
66
|
-
|
|
65
|
+
if (featureFlags.edge_bundler_generate_tarball || featureFlags.edge_bundler_dry_run_generate_tarball) {
|
|
66
|
+
const tarballPromise = bundleTarball({
|
|
67
67
|
basePath,
|
|
68
68
|
buildID,
|
|
69
69
|
debug,
|
|
@@ -73,7 +73,24 @@ export const bundle = async (sourceDirectories, distDirectory, tomlDeclarations
|
|
|
73
73
|
featureFlags,
|
|
74
74
|
importMap: importMap.clone(),
|
|
75
75
|
vendorDirectory: vendor?.directory,
|
|
76
|
-
})
|
|
76
|
+
});
|
|
77
|
+
if (featureFlags.edge_bundler_dry_run_generate_tarball) {
|
|
78
|
+
try {
|
|
79
|
+
await tarballPromise;
|
|
80
|
+
logger.system('Dry run: Tarball bundle generated successfully.');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
logger.system(`Dry run: Tarball bundle generation failed: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger.system(`Dry run: Tarball bundle generation failed: ${String(error)}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (featureFlags.edge_bundler_generate_tarball) {
|
|
92
|
+
bundles.push(await tarballPromise);
|
|
93
|
+
}
|
|
77
94
|
}
|
|
78
95
|
if (vendor) {
|
|
79
96
|
importMap.add(vendor.importMap);
|
|
@@ -145,6 +162,7 @@ const getFunctionConfigs = async ({ basePath, deno, eszipPath, featureFlags, imp
|
|
|
145
162
|
if (!(err instanceof Error && err.cause === 'IMPORT_ASSERT') || !eszipPath || !featureFlags?.edge_bundler_deno_v2) {
|
|
146
163
|
throw err;
|
|
147
164
|
}
|
|
165
|
+
log.user('WARNING: Import assertions are deprecated and will be removed soon. Refer to https://ntl.fyi/import-assert for more information.');
|
|
148
166
|
try {
|
|
149
167
|
// We failed to extract the configuration because there is an import assert
|
|
150
168
|
// in the function code, a deprecated feature that we used to support with
|
|
@@ -655,4 +655,63 @@ describe.skipIf(lt(denoVersion, '2.4.3'))('Produces a tarball bundle', () => {
|
|
|
655
655
|
await cleanup();
|
|
656
656
|
await rm(vendorDirectory.path, { force: true, recursive: true });
|
|
657
657
|
});
|
|
658
|
+
describe('Dry-run tarball generation flag enabled', () => {
|
|
659
|
+
test('Logs success message when tarball generation succeeded', async () => {
|
|
660
|
+
const systemLogger = vi.fn();
|
|
661
|
+
const { basePath, cleanup, distPath } = await useFixture('imports_node_builtin', { copyDirectory: true });
|
|
662
|
+
const declarations = [
|
|
663
|
+
{
|
|
664
|
+
function: 'func1',
|
|
665
|
+
path: '/func1',
|
|
666
|
+
},
|
|
667
|
+
];
|
|
668
|
+
await bundle([join(basePath, 'netlify/edge-functions')], distPath, declarations, {
|
|
669
|
+
basePath,
|
|
670
|
+
configPath: join(basePath, '.netlify/edge-functions/config.json'),
|
|
671
|
+
featureFlags: {
|
|
672
|
+
edge_bundler_dry_run_generate_tarball: true,
|
|
673
|
+
edge_bundler_generate_tarball: false,
|
|
674
|
+
},
|
|
675
|
+
systemLogger,
|
|
676
|
+
});
|
|
677
|
+
expect(systemLogger).toHaveBeenCalledWith('Dry run: Tarball bundle generated successfully.');
|
|
678
|
+
const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8');
|
|
679
|
+
const manifest = JSON.parse(manifestFile);
|
|
680
|
+
expect(manifest.bundles.length).toBe(1);
|
|
681
|
+
expect(manifest.bundles[0].format).toBe('eszip2');
|
|
682
|
+
await cleanup();
|
|
683
|
+
});
|
|
684
|
+
test('Logs error message when tarball generation failed and does not fail the overall build', async () => {
|
|
685
|
+
const systemLogger = vi.fn();
|
|
686
|
+
vi.resetModules();
|
|
687
|
+
vi.doMock('./formats/tarball.js', () => ({
|
|
688
|
+
bundle: vi.fn().mockRejectedValue(new Error('Simulated tarball bundling failure')),
|
|
689
|
+
}));
|
|
690
|
+
const { bundle: bundleUnderTest } = await import('./bundler.js');
|
|
691
|
+
const { basePath, cleanup, distPath } = await useFixture('imports_node_builtin', { copyDirectory: true });
|
|
692
|
+
const sourceDirectory = join(basePath, 'functions');
|
|
693
|
+
const declarations = [
|
|
694
|
+
{
|
|
695
|
+
function: 'func1',
|
|
696
|
+
path: '/func1',
|
|
697
|
+
},
|
|
698
|
+
];
|
|
699
|
+
await expect(bundleUnderTest([sourceDirectory], distPath, declarations, {
|
|
700
|
+
basePath,
|
|
701
|
+
configPath: join(sourceDirectory, 'config.json'),
|
|
702
|
+
featureFlags: {
|
|
703
|
+
edge_bundler_dry_run_generate_tarball: true,
|
|
704
|
+
edge_bundler_generate_tarball: false,
|
|
705
|
+
},
|
|
706
|
+
systemLogger,
|
|
707
|
+
})).resolves.toBeDefined();
|
|
708
|
+
expect(systemLogger).toHaveBeenCalledWith(`Dry run: Tarball bundle generation failed: Simulated tarball bundling failure`);
|
|
709
|
+
const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8');
|
|
710
|
+
const manifest = JSON.parse(manifestFile);
|
|
711
|
+
expect(manifest.bundles.length).toBe(1);
|
|
712
|
+
expect(manifest.bundles[0].format).toBe('eszip2');
|
|
713
|
+
await cleanup();
|
|
714
|
+
vi.resetModules();
|
|
715
|
+
});
|
|
716
|
+
});
|
|
658
717
|
}, 10_000);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
declare const defaultFlags: {
|
|
2
2
|
edge_bundler_generate_tarball: boolean;
|
|
3
|
+
edge_bundler_dry_run_generate_tarball: boolean;
|
|
3
4
|
edge_bundler_deno_v2: boolean;
|
|
4
5
|
};
|
|
5
6
|
type FeatureFlag = keyof typeof defaultFlags;
|
|
6
7
|
type FeatureFlags = Partial<Record<FeatureFlag, boolean>>;
|
|
7
8
|
declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
8
9
|
edge_bundler_generate_tarball: boolean;
|
|
10
|
+
edge_bundler_dry_run_generate_tarball: boolean;
|
|
9
11
|
edge_bundler_deno_v2: boolean;
|
|
10
12
|
}) => FeatureFlags;
|
|
11
13
|
export { defaultFlags, getFlags };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.8.1",
|
|
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": "
|
|
82
|
+
"gitHead": "e945f46a5b5e5c2b33f6ef164be73688ae7d61ed"
|
|
84
83
|
}
|