@netlify/edge-bundler 7.1.0 → 8.0.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 +2 -12
- package/dist/node/bundler.test.js +22 -1
- package/dist/node/config.js +4 -9
- package/dist/node/config.test.js +4 -32
- package/dist/node/npm_import_error.js +6 -1
- package/package.json +1 -1
package/deno/config.ts
CHANGED
|
@@ -19,22 +19,12 @@ if (func.config === undefined) {
|
|
|
19
19
|
Deno.exit(exitCodes.NoConfig)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (typeof func.config !== '
|
|
22
|
+
if (typeof func.config !== 'object') {
|
|
23
23
|
Deno.exit(exitCodes.InvalidExport)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let config
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
config = await func.config()
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error(error)
|
|
32
|
-
|
|
33
|
-
Deno.exit(exitCodes.RuntimeError)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
try {
|
|
37
|
-
const result = JSON.stringify(config)
|
|
27
|
+
const result = JSON.stringify(func.config)
|
|
38
28
|
|
|
39
29
|
await Deno.writeTextFile(new URL(collectorURL), result)
|
|
40
30
|
} catch (error) {
|
|
@@ -110,7 +110,28 @@ test('Prints a nice error message when user tries importing NPM module', async (
|
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
112
|
expect(error).toBeInstanceOf(BundleError);
|
|
113
|
-
expect(error.message).toEqual(`It seems like you're trying to import an npm module. This is only supported
|
|
113
|
+
expect(error.message).toEqual(`It seems like you're trying to import an npm module. This is only supported via CDNs like esm.sh. Have you tried 'import mod from "https://esm.sh/p-retry"'?`);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await cleanup();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
test('Prints a nice error message when user tries importing NPM module with npm: scheme', async () => {
|
|
120
|
+
expect.assertions(2);
|
|
121
|
+
const { basePath, cleanup, distPath } = await useFixture('imports_npm_module_scheme');
|
|
122
|
+
const sourceDirectory = join(basePath, 'functions');
|
|
123
|
+
const declarations = [
|
|
124
|
+
{
|
|
125
|
+
function: 'func1',
|
|
126
|
+
path: '/func1',
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
try {
|
|
130
|
+
await bundle([sourceDirectory], distPath, declarations, { basePath });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
expect(error).toBeInstanceOf(BundleError);
|
|
134
|
+
expect(error.message).toEqual(`It seems like you're trying to import an npm module. This is only supported via CDNs like esm.sh. Have you tried 'import mod from "https://esm.sh/p-retry"'?`);
|
|
114
135
|
}
|
|
115
136
|
finally {
|
|
116
137
|
await cleanup();
|
package/dist/node/config.js
CHANGED
|
@@ -11,9 +11,8 @@ var ConfigExitCode;
|
|
|
11
11
|
ConfigExitCode[ConfigExitCode["ImportError"] = 2] = "ImportError";
|
|
12
12
|
ConfigExitCode[ConfigExitCode["NoConfig"] = 3] = "NoConfig";
|
|
13
13
|
ConfigExitCode[ConfigExitCode["InvalidExport"] = 4] = "InvalidExport";
|
|
14
|
-
ConfigExitCode[ConfigExitCode["
|
|
15
|
-
ConfigExitCode[ConfigExitCode["
|
|
16
|
-
ConfigExitCode[ConfigExitCode["InvalidDefaultExport"] = 7] = "InvalidDefaultExport";
|
|
14
|
+
ConfigExitCode[ConfigExitCode["SerializationError"] = 5] = "SerializationError";
|
|
15
|
+
ConfigExitCode[ConfigExitCode["InvalidDefaultExport"] = 6] = "InvalidDefaultExport";
|
|
17
16
|
})(ConfigExitCode || (ConfigExitCode = {}));
|
|
18
17
|
const getConfigExtractor = () => {
|
|
19
18
|
const packagePath = getPackagePath();
|
|
@@ -75,14 +74,10 @@ const logConfigError = (func, exitCode, stderr, log) => {
|
|
|
75
74
|
log.system(`No in-source config found for edge function at '${func.path}'`);
|
|
76
75
|
break;
|
|
77
76
|
case ConfigExitCode.InvalidExport:
|
|
78
|
-
log.user(`'config' export in edge function at '${func.path}' must be
|
|
79
|
-
break;
|
|
80
|
-
case ConfigExitCode.RuntimeError:
|
|
81
|
-
log.user(`Error while running 'config' function in edge function at '${func.path}'`);
|
|
82
|
-
log.user(stderr);
|
|
77
|
+
log.user(`'config' export in edge function at '${func.path}' must be an object`);
|
|
83
78
|
break;
|
|
84
79
|
case ConfigExitCode.SerializationError:
|
|
85
|
-
log.user(`'config'
|
|
80
|
+
log.user(`'config' object in edge function at '${func.path}' must contain primitive values only`);
|
|
86
81
|
break;
|
|
87
82
|
case ConfigExitCode.InvalidDefaultExport:
|
|
88
83
|
throw new BundleError(new Error(`Default export in '${func.path}' must be a function. More on the Edge Functions API at https://ntl.fyi/edge-api.`));
|
package/dist/node/config.test.js
CHANGED
|
@@ -35,7 +35,7 @@ test('`getFunctionConfig` extracts configuration properties from function file',
|
|
|
35
35
|
source: `
|
|
36
36
|
export default async () => new Response("Hello from function two")
|
|
37
37
|
|
|
38
|
-
export const config =
|
|
38
|
+
export const config = {}
|
|
39
39
|
`,
|
|
40
40
|
},
|
|
41
41
|
// Config with the wrong type
|
|
@@ -45,9 +45,9 @@ test('`getFunctionConfig` extracts configuration properties from function file',
|
|
|
45
45
|
source: `
|
|
46
46
|
export default async () => new Response("Hello from function two")
|
|
47
47
|
|
|
48
|
-
export const config = {}
|
|
48
|
+
export const config = () => ({})
|
|
49
49
|
`,
|
|
50
|
-
userLog: /^'config' export in edge function at '(.*)' must be
|
|
50
|
+
userLog: /^'config' export in edge function at '(.*)' must be an object$/,
|
|
51
51
|
},
|
|
52
52
|
// Config with a syntax error
|
|
53
53
|
{
|
|
@@ -60,19 +60,6 @@ test('`getFunctionConfig` extracts configuration properties from function file',
|
|
|
60
60
|
`,
|
|
61
61
|
userLog: /^Could not load edge function at '(.*)'$/,
|
|
62
62
|
},
|
|
63
|
-
// Config that throws
|
|
64
|
-
{
|
|
65
|
-
expectedConfig: {},
|
|
66
|
-
name: 'func5',
|
|
67
|
-
source: `
|
|
68
|
-
export default async () => new Response("Hello from function two")
|
|
69
|
-
|
|
70
|
-
export const config = () => {
|
|
71
|
-
throw new Error('uh-oh')
|
|
72
|
-
}
|
|
73
|
-
`,
|
|
74
|
-
userLog: /^Error while running 'config' function in edge function at '(.*)'$/,
|
|
75
|
-
},
|
|
76
63
|
// Config with `path`
|
|
77
64
|
{
|
|
78
65
|
expectedConfig: { path: '/home' },
|
|
@@ -80,23 +67,8 @@ test('`getFunctionConfig` extracts configuration properties from function file',
|
|
|
80
67
|
source: `
|
|
81
68
|
export default async () => new Response("Hello from function three")
|
|
82
69
|
|
|
83
|
-
export const config =
|
|
84
|
-
`,
|
|
85
|
-
},
|
|
86
|
-
// Config that prints to stdout
|
|
87
|
-
{
|
|
88
|
-
expectedConfig: { path: '/home' },
|
|
89
|
-
name: 'func7',
|
|
90
|
-
source: `
|
|
91
|
-
export default async () => new Response("Hello from function three")
|
|
92
|
-
|
|
93
|
-
export const config = () => {
|
|
94
|
-
console.log("Hello from config!")
|
|
95
|
-
|
|
96
|
-
return { path: "/home" }
|
|
97
|
-
}
|
|
70
|
+
export const config = { path: "/home" }
|
|
98
71
|
`,
|
|
99
|
-
userLog: /^Hello from config!$/,
|
|
100
72
|
},
|
|
101
73
|
];
|
|
102
74
|
for (const func of functions) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class NPMImportError extends Error {
|
|
2
2
|
constructor(originalError, moduleName) {
|
|
3
|
-
super(`It seems like you're trying to import an npm module. This is only supported
|
|
3
|
+
super(`It seems like you're trying to import an npm module. This is only supported via CDNs like esm.sh. Have you tried 'import mod from "https://esm.sh/${moduleName}"'?`);
|
|
4
4
|
this.name = 'NPMImportError';
|
|
5
5
|
this.stack = originalError.stack;
|
|
6
6
|
// https://github.com/microsoft/TypeScript-wiki/blob/8a66ecaf77118de456f7cd9c56848a40fe29b9b4/Breaking-Changes.md#implicit-any-error-raised-for-un-annotated-callback-arguments-with-no-matching-overload-arguments
|
|
@@ -14,6 +14,11 @@ const wrapNpmImportError = (input) => {
|
|
|
14
14
|
const [, moduleName] = match;
|
|
15
15
|
return new NPMImportError(input, moduleName);
|
|
16
16
|
}
|
|
17
|
+
const schemeMatch = input.message.match(/Error: Module not found "npm:(.*)"/);
|
|
18
|
+
if (schemeMatch !== null) {
|
|
19
|
+
const [, moduleName] = schemeMatch;
|
|
20
|
+
return new NPMImportError(input, moduleName);
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
return input;
|
|
19
24
|
};
|