@netlify/edge-bundler 2.0.5 → 2.1.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/lib/stage2.ts
CHANGED
|
@@ -6,7 +6,30 @@ import type { InputFunction, WriteStage2Options } from '../../shared/stage2.ts'
|
|
|
6
6
|
import { PUBLIC_SPECIFIER, STAGE2_SPECIFIER, virtualRoot } from './consts.ts'
|
|
7
7
|
import { inlineModule, loadFromVirtualRoot, loadWithRetry } from './common.ts'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface FunctionReference {
|
|
10
|
+
exportLine: string
|
|
11
|
+
importLine: string
|
|
12
|
+
metadata: {
|
|
13
|
+
url: URL
|
|
14
|
+
}
|
|
15
|
+
name: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getMetadata = (references: FunctionReference[]) => {
|
|
19
|
+
const functions = references.reduce(
|
|
20
|
+
(acc, { metadata, name }) => ({
|
|
21
|
+
...acc,
|
|
22
|
+
[name]: metadata,
|
|
23
|
+
}),
|
|
24
|
+
{},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
functions,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getFunctionReference = (basePath: string, func: InputFunction, index: number): FunctionReference => {
|
|
10
33
|
const importName = `func${index}`
|
|
11
34
|
const exportLine = `"${func.name}": ${importName}`
|
|
12
35
|
const url = getVirtualPath(basePath, func.path)
|
|
@@ -14,16 +37,22 @@ const getFunctionReference = (basePath: string, func: InputFunction, index: numb
|
|
|
14
37
|
return {
|
|
15
38
|
exportLine,
|
|
16
39
|
importLine: `import ${importName} from "${url}";`,
|
|
40
|
+
metadata: {
|
|
41
|
+
url,
|
|
42
|
+
},
|
|
43
|
+
name: func.name,
|
|
17
44
|
}
|
|
18
45
|
}
|
|
19
46
|
|
|
20
|
-
const getStage2Entry = (basePath: string, functions: InputFunction[]) => {
|
|
47
|
+
export const getStage2Entry = (basePath: string, functions: InputFunction[]) => {
|
|
21
48
|
const lines = functions.map((func, index) => getFunctionReference(basePath, func, index))
|
|
22
49
|
const importLines = lines.map(({ importLine }) => importLine).join('\n')
|
|
23
50
|
const exportLines = lines.map(({ exportLine }) => exportLine).join(', ')
|
|
24
|
-
const
|
|
51
|
+
const metadata = getMetadata(lines)
|
|
52
|
+
const functionsExport = `export const functions = {${exportLines}};`
|
|
53
|
+
const metadataExport = `export const metadata = ${JSON.stringify(metadata)};`
|
|
25
54
|
|
|
26
|
-
return [importLines,
|
|
55
|
+
return [importLines, functionsExport, metadataExport].join('\n\n')
|
|
27
56
|
}
|
|
28
57
|
|
|
29
58
|
const getVirtualPath = (basePath: string, filePath: string) => {
|
|
@@ -12,7 +12,7 @@ const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, func
|
|
|
12
12
|
functions,
|
|
13
13
|
importMapURL: importMap.toDataURL(),
|
|
14
14
|
};
|
|
15
|
-
const flags = ['--allow-all'];
|
|
15
|
+
const flags = ['--allow-all', '--no-config'];
|
|
16
16
|
if (!debug) {
|
|
17
17
|
flags.push('--quiet');
|
|
18
18
|
}
|
|
@@ -22,4 +22,9 @@ interface GenerateStage2Options {
|
|
|
22
22
|
}
|
|
23
23
|
declare const generateStage2: ({ distDirectory, fileName, formatExportTypeError, formatImportError, functions, type, }: GenerateStage2Options) => Promise<string>;
|
|
24
24
|
declare const getBootstrapURL: () => string;
|
|
25
|
-
|
|
25
|
+
interface GetLocalEntryPointOptions {
|
|
26
|
+
formatExportTypeError?: FormatFunction;
|
|
27
|
+
formatImportError?: FormatFunction;
|
|
28
|
+
}
|
|
29
|
+
declare const getLocalEntryPoint: (functions: EdgeFunction[], { formatExportTypeError, formatImportError, }: GetLocalEntryPointOptions) => string;
|
|
30
|
+
export { bundleJS as bundle, generateStage2, getBootstrapURL, getLocalEntryPoint };
|
|
@@ -10,7 +10,7 @@ const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, import
|
|
|
10
10
|
const stage2Path = await generateStage2({ distDirectory, functions, fileName: `${buildID}-pre.js` });
|
|
11
11
|
const extension = '.js';
|
|
12
12
|
const jsBundlePath = join(distDirectory, `${buildID}${extension}`);
|
|
13
|
-
const flags = [`--import-map=${importMap.toDataURL()}
|
|
13
|
+
const flags = [`--import-map=${importMap.toDataURL()}`, '--no-config'];
|
|
14
14
|
if (!debug) {
|
|
15
15
|
flags.push('--quiet');
|
|
16
16
|
}
|
|
@@ -42,22 +42,29 @@ const getBootstrapURL = () => { var _a; return (_a = env.NETLIFY_EDGE_BOOTSTRAP)
|
|
|
42
42
|
// a valid default export.
|
|
43
43
|
const getLocalEntryPoint = (functions, { formatExportTypeError = defaultFormatExportTypeError, formatImportError = defaultFormatImpoortError, }) => {
|
|
44
44
|
const bootImport = `import { boot } from "${getBootstrapURL()}";`;
|
|
45
|
-
const declaration = `const functions = {};`;
|
|
46
|
-
const imports = functions.map((func) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
const declaration = `const functions = {}; const metadata = { functions: {} };`;
|
|
46
|
+
const imports = functions.map((func) => {
|
|
47
|
+
const url = pathToFileURL(func.path);
|
|
48
|
+
const metadata = {
|
|
49
|
+
url,
|
|
50
|
+
};
|
|
51
|
+
return `
|
|
52
|
+
try {
|
|
53
|
+
const { default: func } = await import("${url}");
|
|
54
|
+
|
|
55
|
+
if (typeof func === "function") {
|
|
56
|
+
functions["${func.name}"] = func;
|
|
57
|
+
metadata.functions["${func.name}"] = ${JSON.stringify(metadata)}
|
|
58
|
+
} else {
|
|
59
|
+
console.log(${JSON.stringify(formatExportTypeError(func.name))});
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.log(${JSON.stringify(formatImportError(func.name))});
|
|
63
|
+
console.error(error);
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
});
|
|
67
|
+
const bootCall = `boot(functions, metadata);`;
|
|
61
68
|
return [bootImport, declaration, ...imports, bootCall].join('\n\n');
|
|
62
69
|
};
|
|
63
70
|
const getProductionEntryPoint = (functions) => {
|
|
@@ -77,4 +84,4 @@ const getProductionEntryPoint = (functions) => {
|
|
|
77
84
|
const defaultExport = 'boot(functions);';
|
|
78
85
|
return [bootImport, importLines, exportDeclaration, defaultExport].join('\n\n');
|
|
79
86
|
};
|
|
80
|
-
export { bundleJS as bundle, generateStage2, getBootstrapURL };
|
|
87
|
+
export { bundleJS as bundle, generateStage2, getBootstrapURL, getLocalEntryPoint };
|
|
@@ -71,6 +71,7 @@ const serve = async ({ certificatePath, debug, distImportMapPath, inspectSetting
|
|
|
71
71
|
'--unstable',
|
|
72
72
|
`--import-map=${importMap.toDataURL()}`,
|
|
73
73
|
'--v8-flags=--disallow-code-generation-from-strings',
|
|
74
|
+
'--no-config',
|
|
74
75
|
];
|
|
75
76
|
if (certificatePath) {
|
|
76
77
|
flags.push(`--cert=${certificatePath}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"test:dev": "run-s build test:dev:*",
|
|
29
29
|
"test:ci": "run-s build test:ci:*",
|
|
30
30
|
"test:dev:ava": "ava",
|
|
31
|
-
"test:
|
|
31
|
+
"test:dev:deno": "deno test --allow-all test/deno",
|
|
32
|
+
"test:ci:ava": "nyc -r lcovonly -r text -r json ava",
|
|
33
|
+
"test:ci:deno": "deno test --allow-all test/deno"
|
|
32
34
|
},
|
|
33
35
|
"config": {
|
|
34
36
|
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{node,scripts,.github}/**/*.{js,ts,md,html}\" \"*.{js,ts,md,html}\"",
|
|
@@ -36,8 +38,8 @@
|
|
|
36
38
|
},
|
|
37
39
|
"ava": {
|
|
38
40
|
"files": [
|
|
39
|
-
"test/**/*.ts",
|
|
40
|
-
"!test/fixtures/**"
|
|
41
|
+
"test/node/**/*.ts",
|
|
42
|
+
"!test/node/fixtures/**"
|
|
41
43
|
],
|
|
42
44
|
"extensions": {
|
|
43
45
|
"ts": "module"
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
},
|
|
56
58
|
"author": "Netlify Inc.",
|
|
57
59
|
"directories": {
|
|
58
|
-
"test": "test"
|
|
60
|
+
"test": "test/node"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@ava/typescript": "^3.0.1",
|