@netlify/edge-bundler 14.7.0 → 14.7.2
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.
|
@@ -81,6 +81,7 @@ class V2 {
|
|
|
81
81
|
const imports: Record<string, string> = {};
|
|
82
82
|
|
|
83
83
|
for (const specifier of this.specifiers) {
|
|
84
|
+
if (new URL(specifier).protocol !== "file:") continue
|
|
84
85
|
const module = await this.parser.getModuleSource(specifier);
|
|
85
86
|
await write(join(dest, "source", url2path(specifier)), module);
|
|
86
87
|
// Track import
|
|
@@ -107,11 +108,8 @@ export async function loadESZIP(filename: string): Promise<ESZIP> {
|
|
|
107
108
|
return await V1.load(bytes);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
function url2path(
|
|
111
|
-
|
|
112
|
-
const tail = url.pathname.split("/").filter(Boolean);
|
|
113
|
-
const relativePath = tail.length === 0 ? [".root"] : tail;
|
|
114
|
-
return join(url.hostname, ...relativePath);
|
|
111
|
+
function url2path(url: string) {
|
|
112
|
+
return join(...(new URL(url).pathname.split("/").filter(Boolean)));
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
async function write(path: string, content: string) {
|
package/dist/node/bridge.d.ts
CHANGED
|
@@ -40,7 +40,13 @@ export declare class DenoBridge {
|
|
|
40
40
|
versionRange: string;
|
|
41
41
|
constructor(options: DenoOptions);
|
|
42
42
|
private downloadBinary;
|
|
43
|
-
getBinaryVersion(binaryPath: string): Promise<
|
|
43
|
+
getBinaryVersion(binaryPath: string): Promise<{
|
|
44
|
+
version: string;
|
|
45
|
+
error?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
version?: undefined;
|
|
48
|
+
error: Error;
|
|
49
|
+
}>;
|
|
44
50
|
private getCachedBinary;
|
|
45
51
|
private getGlobalBinary;
|
|
46
52
|
private getRemoteBinary;
|
package/dist/node/bridge.js
CHANGED
|
@@ -40,17 +40,27 @@ export class DenoBridge {
|
|
|
40
40
|
await this.ensureCacheDirectory();
|
|
41
41
|
this.logger.system(`Downloading Deno CLI to ${this.cacheDirectory}`);
|
|
42
42
|
const binaryPath = await download(this.cacheDirectory, this.versionRange, this.logger);
|
|
43
|
-
const
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const result = await this.getBinaryVersion(binaryPath);
|
|
44
|
+
// If we can't execute the downloaded binary, provide actionable info to diagnose and self-heal if possible
|
|
45
|
+
if (result.error) {
|
|
46
|
+
const error = new Error(`Failed to set up Deno for Edge Functions.
|
|
47
|
+
Error: ${result.error.message}
|
|
48
|
+
Downloaded to: ${binaryPath}
|
|
49
|
+
Platform: ${process.platform}/${process.arch}
|
|
50
|
+
|
|
51
|
+
This may be caused by permissions, antivirus software, or platform incompatibility.
|
|
52
|
+
|
|
53
|
+
Try clearing the Deno cache directory and retrying:
|
|
54
|
+
${this.cacheDirectory}
|
|
55
|
+
|
|
56
|
+
Supported Deno versions: ${this.versionRange}
|
|
57
|
+
|
|
58
|
+
To install Deno manually: https://ntl.fyi/install-deno`);
|
|
49
59
|
await this.onAfterDownload?.(error);
|
|
50
60
|
this.logger.system('Could not run downloaded Deno CLI', error);
|
|
51
61
|
throw error;
|
|
52
62
|
}
|
|
53
|
-
await this.writeVersionFile(
|
|
63
|
+
await this.writeVersionFile(result.version);
|
|
54
64
|
await this.onAfterDownload?.();
|
|
55
65
|
return binaryPath;
|
|
56
66
|
}
|
|
@@ -60,12 +70,13 @@ export class DenoBridge {
|
|
|
60
70
|
const version = stdout.match(/^deno ([\d.]+)/);
|
|
61
71
|
if (!version) {
|
|
62
72
|
this.logger.system(`getBinaryVersion no version found. binaryPath ${binaryPath}`);
|
|
63
|
-
return;
|
|
73
|
+
return { error: new Error('Could not parse Deno version from output') };
|
|
64
74
|
}
|
|
65
|
-
return version[1];
|
|
75
|
+
return { version: version[1] };
|
|
66
76
|
}
|
|
67
77
|
catch (error) {
|
|
68
78
|
this.logger.system('getBinaryVersion failed', error);
|
|
79
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
async getCachedBinary() {
|
|
@@ -90,9 +101,9 @@ export class DenoBridge {
|
|
|
90
101
|
return;
|
|
91
102
|
}
|
|
92
103
|
const globalBinaryName = 'deno';
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
this.logger.system(`No globalVersion or semver not satisfied. globalVersion: ${
|
|
104
|
+
const result = await this.getBinaryVersion(globalBinaryName);
|
|
105
|
+
if (result.error || !semver.satisfies(result.version, this.versionRange)) {
|
|
106
|
+
this.logger.system(`No globalVersion or semver not satisfied. globalVersion: ${result.version}, versionRange: ${this.versionRange}`);
|
|
96
107
|
return;
|
|
97
108
|
}
|
|
98
109
|
return globalBinaryName;
|
package/dist/node/bridge.test.js
CHANGED
|
@@ -101,3 +101,41 @@ test('Does inherit environment variables if `extendEnv` is not set', async () =>
|
|
|
101
101
|
expect(environmentVariables).toEqual(['LULU=LALA', 'TADA=TUDU']);
|
|
102
102
|
await rm(tmpDir.path, { force: true, recursive: true, maxRetries: 10 });
|
|
103
103
|
});
|
|
104
|
+
test('Provides actionable error message when downloaded binary cannot be executed', async () => {
|
|
105
|
+
const tmpDir = await tmp.dir();
|
|
106
|
+
const latestVersion = semver.minVersion(DENO_VERSION_RANGE)?.version ?? '';
|
|
107
|
+
const data = new PassThrough();
|
|
108
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
109
|
+
archive.pipe(data);
|
|
110
|
+
// Create a binary that will fail to execute (invalid content)
|
|
111
|
+
archive.append(Buffer.from('invalid binary content'), {
|
|
112
|
+
name: platform === 'win32' ? 'deno.exe' : 'deno',
|
|
113
|
+
});
|
|
114
|
+
archive.finalize();
|
|
115
|
+
const target = getPlatformTarget();
|
|
116
|
+
nock('https://dl.deno.land').get('/release-latest.txt').reply(200, `v${latestVersion}`);
|
|
117
|
+
nock('https://dl.deno.land')
|
|
118
|
+
.get(`/release/v${latestVersion}/deno-${target}.zip`)
|
|
119
|
+
.reply(200, () => data);
|
|
120
|
+
const deno = new DenoBridge({
|
|
121
|
+
cacheDirectory: tmpDir.path,
|
|
122
|
+
useGlobal: false,
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
await deno.getBinaryPath();
|
|
126
|
+
expect.fail('Should have thrown an error');
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
expect(error).toBeInstanceOf(Error);
|
|
130
|
+
const errorMessage = error.message;
|
|
131
|
+
expect(errorMessage).toContain('Failed to set up Deno for Edge Functions');
|
|
132
|
+
expect(errorMessage).toMatch(/Error:/);
|
|
133
|
+
expect(errorMessage).toMatch(/Downloaded to: .+deno(\.exe)?/);
|
|
134
|
+
expect(errorMessage).toContain(tmpDir.path);
|
|
135
|
+
expect(errorMessage).toMatch(/Platform: (darwin|linux|win32)\/(x64|arm64|ia32)/);
|
|
136
|
+
expect(errorMessage).toContain('This may be caused by permissions, antivirus software, or platform incompatibility');
|
|
137
|
+
expect(errorMessage).toContain('Try clearing the Deno cache directory and retrying');
|
|
138
|
+
expect(errorMessage).toContain('https://ntl.fyi/install-deno');
|
|
139
|
+
}
|
|
140
|
+
await rm(tmpDir.path, { force: true, recursive: true, maxRetries: 10 });
|
|
141
|
+
});
|
package/dist/node/bundler.js
CHANGED
|
@@ -17,6 +17,7 @@ import { writeManifest } from './manifest.js';
|
|
|
17
17
|
import { vendorNPMSpecifiers } from './npm_dependencies.js';
|
|
18
18
|
import { ensureLatestTypes } from './types.js';
|
|
19
19
|
import { nonNullable } from './utils/non_nullable.js';
|
|
20
|
+
import { BundleError } from './bundle_error.js';
|
|
20
21
|
export const bundle = async (sourceDirectories, distDirectory, tomlDeclarations = [], { basePath: inputBasePath, cacheDirectory, configPath, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMapPaths = [], internalSrcFolder, onAfterDownload, onBeforeDownload, rootPath, userLogger, systemLogger, vendorDirectory, } = {}) => {
|
|
21
22
|
const logger = getLogger(systemLogger, userLogger, debug);
|
|
22
23
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
@@ -144,22 +145,27 @@ const getFunctionConfigs = async ({ basePath, deno, eszipPath, featureFlags, imp
|
|
|
144
145
|
if (!(err instanceof Error && err.cause === 'IMPORT_ASSERT') || !eszipPath || !featureFlags?.edge_bundler_deno_v2) {
|
|
145
146
|
throw err;
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
148
|
+
try {
|
|
149
|
+
// We failed to extract the configuration because there is an import assert
|
|
150
|
+
// in the function code, a deprecated feature that we used to support with
|
|
151
|
+
// Deno 1.x. To avoid a breaking change, we treat this error as a special
|
|
152
|
+
// case, using the generated ESZIP to extract the configuration. This works
|
|
153
|
+
// because import asserts are transpiled to import attributes.
|
|
154
|
+
const extractedESZIP = await extractESZIP(deno, eszipPath);
|
|
155
|
+
const configs = await Promise.all([...internalFunctions, ...userFunctions].map(async (func) => {
|
|
156
|
+
const relativePath = relative(basePath, func.path);
|
|
157
|
+
const functionPath = join(extractedESZIP.path, relativePath);
|
|
158
|
+
return [func.name, await getFunctionConfig({ functionPath, importMap, deno, log })];
|
|
159
|
+
}));
|
|
160
|
+
await extractedESZIP.cleanup();
|
|
161
|
+
return {
|
|
162
|
+
internalFunctions: Object.fromEntries(configs.slice(0, internalFunctions.length)),
|
|
163
|
+
userFunctions: Object.fromEntries(configs.slice(internalFunctions.length)),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
throw new BundleError(new Error('An error occurred while building an edge function that uses an import assertion. Refer to https://ntl.fyi/import-assert for more information.'), { cause: err });
|
|
168
|
+
}
|
|
163
169
|
}
|
|
164
170
|
};
|
|
165
171
|
const createFinalBundles = async (bundles, distDirectory, buildID) => {
|
package/dist/node/config.js
CHANGED
|
@@ -38,7 +38,8 @@ export const getFunctionConfig = async ({ deno, functionPath, importMap, log, })
|
|
|
38
38
|
// with the extractor.
|
|
39
39
|
const collector = await tmp.file();
|
|
40
40
|
// Retrieving the version of Deno.
|
|
41
|
-
const
|
|
41
|
+
const result = await deno.getBinaryVersion((await deno.getBinaryPath({ silent: true })).path);
|
|
42
|
+
const version = new SemVer(result.version || '');
|
|
42
43
|
// The extractor will use its exit code to signal different error scenarios,
|
|
43
44
|
// based on the list of exit codes we send as an argument. We then capture
|
|
44
45
|
// the exit code to know exactly what happened and guide people accordingly.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "14.7.
|
|
3
|
+
"version": "14.7.2",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"urlpattern-polyfill": "8.0.2",
|
|
81
81
|
"uuid": "^11.0.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "1cf876ef6b79ef8332044a3e32db846652be9f23"
|
|
84
84
|
}
|