@netlify/edge-bundler 4.2.0 → 4.3.0
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/deno/config.ts +4 -0
- package/dist/node/config.js +3 -0
- package/dist/node/config.test.js +76 -0
- package/package.json +1 -1
package/deno/config.ts
CHANGED
package/dist/node/config.js
CHANGED
|
@@ -12,6 +12,7 @@ var ConfigExitCode;
|
|
|
12
12
|
ConfigExitCode[ConfigExitCode["InvalidExport"] = 4] = "InvalidExport";
|
|
13
13
|
ConfigExitCode[ConfigExitCode["RuntimeError"] = 5] = "RuntimeError";
|
|
14
14
|
ConfigExitCode[ConfigExitCode["SerializationError"] = 6] = "SerializationError";
|
|
15
|
+
ConfigExitCode[ConfigExitCode["InvalidDefaultExport"] = 7] = "InvalidDefaultExport";
|
|
15
16
|
})(ConfigExitCode || (ConfigExitCode = {}));
|
|
16
17
|
const getConfigExtractor = () => {
|
|
17
18
|
const packagePath = getPackagePath();
|
|
@@ -82,6 +83,8 @@ const logConfigError = (func, exitCode, stderr, log) => {
|
|
|
82
83
|
case ConfigExitCode.SerializationError:
|
|
83
84
|
log.user(`'config' function in edge function at '${func.path}' must return an object with primitive values only`);
|
|
84
85
|
break;
|
|
86
|
+
case ConfigExitCode.InvalidDefaultExport:
|
|
87
|
+
throw new Error(`Default export in '${func.path}' must be a function. More on the Edge Functions API at https://ntl.fyi/edge-api.`);
|
|
85
88
|
default:
|
|
86
89
|
log.user(`Could not load configuration for edge function at '${func.path}'`);
|
|
87
90
|
log.user(stderr);
|
package/dist/node/config.test.js
CHANGED
|
@@ -15,6 +15,7 @@ const importMapFile = {
|
|
|
15
15
|
'alias:helper': pathToFileURL(join(fixturesDir, 'helper.ts')).toString(),
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
|
+
const invalidDefaultExportErr = (path) => `Default export in '${path}' must be a function. More on the Edge Functions API at https://ntl.fyi/edge-api.`;
|
|
18
19
|
test('`getFunctionConfig` extracts configuration properties from function file', async () => {
|
|
19
20
|
const { path: tmpDir } = await tmp.dir();
|
|
20
21
|
const deno = new DenoBridge({
|
|
@@ -184,3 +185,78 @@ test('Loads function paths from the in-source `config` function', async () => {
|
|
|
184
185
|
expect(postCacheRoutes[0]).toEqual({ function: 'user-func4', pattern: '^/user-func4/?$' });
|
|
185
186
|
await fs.rmdir(tmpDir.path, { recursive: true });
|
|
186
187
|
});
|
|
188
|
+
test('Passes validation if default export exists and is a function', async () => {
|
|
189
|
+
const { path: tmpDir } = await tmp.dir();
|
|
190
|
+
const deno = new DenoBridge({
|
|
191
|
+
cacheDirectory: tmpDir,
|
|
192
|
+
});
|
|
193
|
+
const func = {
|
|
194
|
+
name: 'func1',
|
|
195
|
+
source: `
|
|
196
|
+
const func = () => new Response("Hello world!")
|
|
197
|
+
export default func
|
|
198
|
+
`,
|
|
199
|
+
};
|
|
200
|
+
const logger = {
|
|
201
|
+
user: vi.fn().mockResolvedValue(null),
|
|
202
|
+
system: vi.fn().mockResolvedValue(null),
|
|
203
|
+
};
|
|
204
|
+
const path = join(tmpDir, `${func.name}.ts`);
|
|
205
|
+
await fs.writeFile(path, func.source);
|
|
206
|
+
expect(async () => {
|
|
207
|
+
await getFunctionConfig({
|
|
208
|
+
name: func.name,
|
|
209
|
+
path,
|
|
210
|
+
}, new ImportMap([importMapFile]), deno, logger);
|
|
211
|
+
}).not.toThrow();
|
|
212
|
+
await deleteAsync(tmpDir, { force: true });
|
|
213
|
+
});
|
|
214
|
+
test('Fails validation if default export is not function', async () => {
|
|
215
|
+
const { path: tmpDir } = await tmp.dir();
|
|
216
|
+
const deno = new DenoBridge({
|
|
217
|
+
cacheDirectory: tmpDir,
|
|
218
|
+
});
|
|
219
|
+
const func = {
|
|
220
|
+
name: 'func2',
|
|
221
|
+
source: `
|
|
222
|
+
const func = new Response("Hello world!")
|
|
223
|
+
export default func
|
|
224
|
+
`,
|
|
225
|
+
};
|
|
226
|
+
const logger = {
|
|
227
|
+
user: vi.fn().mockResolvedValue(null),
|
|
228
|
+
system: vi.fn().mockResolvedValue(null),
|
|
229
|
+
};
|
|
230
|
+
const path = join(tmpDir, `${func.name}.ts`);
|
|
231
|
+
await fs.writeFile(path, func.source);
|
|
232
|
+
const config = getFunctionConfig({
|
|
233
|
+
name: func.name,
|
|
234
|
+
path,
|
|
235
|
+
}, new ImportMap([importMapFile]), deno, logger);
|
|
236
|
+
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path));
|
|
237
|
+
await deleteAsync(tmpDir, { force: true });
|
|
238
|
+
});
|
|
239
|
+
test('Fails validation if default export is not present', async () => {
|
|
240
|
+
const { path: tmpDir } = await tmp.dir();
|
|
241
|
+
const deno = new DenoBridge({
|
|
242
|
+
cacheDirectory: tmpDir,
|
|
243
|
+
});
|
|
244
|
+
const func = {
|
|
245
|
+
name: 'func3',
|
|
246
|
+
source: `
|
|
247
|
+
export const func = () => new Response("Hello world!")
|
|
248
|
+
`,
|
|
249
|
+
};
|
|
250
|
+
const logger = {
|
|
251
|
+
user: vi.fn().mockResolvedValue(null),
|
|
252
|
+
system: vi.fn().mockResolvedValue(null),
|
|
253
|
+
};
|
|
254
|
+
const path = join(tmpDir, `${func.name}.ts`);
|
|
255
|
+
await fs.writeFile(path, func.source);
|
|
256
|
+
const config = getFunctionConfig({
|
|
257
|
+
name: func.name,
|
|
258
|
+
path,
|
|
259
|
+
}, new ImportMap([importMapFile]), deno, logger);
|
|
260
|
+
await expect(config).rejects.toThrowError(invalidDefaultExportErr(path));
|
|
261
|
+
await deleteAsync(tmpDir, { force: true });
|
|
262
|
+
});
|