@netlify/edge-bundler 1.4.1 → 1.5.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/bundle.ts +1 -1
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +9 -9
- package/dist/bundler.js +2 -0
- package/dist/formats/eszip.d.ts +2 -2
- package/dist/formats/eszip.js +7 -10
- package/dist/formats/javascript.d.ts +2 -2
- package/dist/formats/javascript.js +8 -11
- package/dist/import_map.js +4 -4
- package/dist/server/server.js +3 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.js +57 -0
- package/package.json +1 -1
package/deno/bundle.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeStage2 } from 'https://
|
|
1
|
+
import { writeStage2 } from 'https://62bae4994570970008142f1e--edge-bootstrap.netlify.app/bundler/mod.ts'
|
|
2
2
|
|
|
3
3
|
const [payload] = Deno.args
|
|
4
4
|
const { basePath, destPath, functions } = JSON.parse(payload)
|
package/dist/bridge.d.ts
CHANGED
|
@@ -29,13 +29,13 @@ declare class DenoBridge {
|
|
|
29
29
|
private getCachedBinary;
|
|
30
30
|
private getGlobalBinary;
|
|
31
31
|
private getRemoteBinary;
|
|
32
|
-
private log;
|
|
33
32
|
private static runWithBinary;
|
|
34
33
|
private writeVersionFile;
|
|
35
34
|
getBinaryPath(): Promise<{
|
|
36
35
|
global: boolean;
|
|
37
36
|
path: string;
|
|
38
37
|
}>;
|
|
38
|
+
log(...data: unknown[]): void;
|
|
39
39
|
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
|
|
40
40
|
runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
|
|
41
41
|
}
|
package/dist/bridge.js
CHANGED
|
@@ -20,7 +20,7 @@ class DenoBridge {
|
|
|
20
20
|
}
|
|
21
21
|
async downloadBinary() {
|
|
22
22
|
var _a, _b, _c;
|
|
23
|
-
(_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
23
|
+
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
24
24
|
await fs.mkdir(this.cacheDirectory, { recursive: true });
|
|
25
25
|
this.log(`Downloading Deno CLI to ${this.cacheDirectory}...`);
|
|
26
26
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
@@ -30,11 +30,11 @@ class DenoBridge {
|
|
|
30
30
|
// that the tests catch it.
|
|
31
31
|
if (downloadedVersion === undefined) {
|
|
32
32
|
const error = new Error('There was a problem setting up the Edge Functions environment. To try a manual installation, visit https://ntl.fyi/install-deno.');
|
|
33
|
-
(_b = this.onAfterDownload) === null || _b === void 0 ? void 0 : _b.call(this, error);
|
|
33
|
+
await ((_b = this.onAfterDownload) === null || _b === void 0 ? void 0 : _b.call(this, error));
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
36
|
await this.writeVersionFile(downloadedVersion);
|
|
37
|
-
(_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
37
|
+
await ((_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this));
|
|
38
38
|
return binaryPath;
|
|
39
39
|
}
|
|
40
40
|
static async getBinaryVersion(binaryPath) {
|
|
@@ -82,12 +82,6 @@ class DenoBridge {
|
|
|
82
82
|
}
|
|
83
83
|
return this.currentDownload;
|
|
84
84
|
}
|
|
85
|
-
log(...data) {
|
|
86
|
-
if (!this.debug) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
console.log(...data);
|
|
90
|
-
}
|
|
91
85
|
static runWithBinary(binaryPath, args, pipeOutput) {
|
|
92
86
|
var _a, _b;
|
|
93
87
|
const runDeno = execa(binaryPath, args);
|
|
@@ -115,6 +109,12 @@ class DenoBridge {
|
|
|
115
109
|
const downloadedPath = await this.getRemoteBinary();
|
|
116
110
|
return { global: false, path: downloadedPath };
|
|
117
111
|
}
|
|
112
|
+
log(...data) {
|
|
113
|
+
if (!this.debug) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
console.log(...data);
|
|
117
|
+
}
|
|
118
118
|
// Runs the Deno CLI in the background and returns a reference to the child
|
|
119
119
|
// process, awaiting its execution.
|
|
120
120
|
async run(args, { pipeOutput } = {}) {
|
package/dist/bundler.js
CHANGED
|
@@ -9,6 +9,7 @@ import { bundle as bundleESZIP } from './formats/eszip.js';
|
|
|
9
9
|
import { bundle as bundleJS } from './formats/javascript.js';
|
|
10
10
|
import { ImportMap } from './import_map.js';
|
|
11
11
|
import { writeManifest } from './manifest.js';
|
|
12
|
+
import { ensureLatestTypes } from './types.js';
|
|
12
13
|
const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, featureFlags, }) => {
|
|
13
14
|
const bundleOps = [];
|
|
14
15
|
if (featureFlags.edge_functions_produce_eszip) {
|
|
@@ -42,6 +43,7 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
|
|
|
42
43
|
onBeforeDownload,
|
|
43
44
|
});
|
|
44
45
|
const basePath = getBasePath(sourceDirectories);
|
|
46
|
+
await ensureLatestTypes(deno);
|
|
45
47
|
// The name of the bundle will be the hash of its contents, which we can't
|
|
46
48
|
// compute until we run the bundle process. For now, we'll use a random ID
|
|
47
49
|
// to create the bundle artifacts and rename them later.
|
package/dist/formats/eszip.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ interface BundleESZIPOptions {
|
|
|
9
9
|
distDirectory: string;
|
|
10
10
|
functions: EdgeFunction[];
|
|
11
11
|
}
|
|
12
|
-
declare const
|
|
13
|
-
export { bundle };
|
|
12
|
+
declare const bundleESZIP: ({ basePath, buildID, debug, deno, distDirectory, functions, }: BundleESZIPOptions) => Promise<Bundle>;
|
|
13
|
+
export { bundleESZIP as bundle };
|
package/dist/formats/eszip.js
CHANGED
|
@@ -2,14 +2,6 @@ import { join, resolve } from 'path';
|
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { wrapBundleError } from '../bundle_error.js';
|
|
4
4
|
import { getFileHash } from '../utils/sha256.js';
|
|
5
|
-
const bundle = async (options) => {
|
|
6
|
-
try {
|
|
7
|
-
return await bundleESZIP(options);
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
throw wrapBundleError(error, { format: 'eszip' });
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
5
|
const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, functions, }) => {
|
|
14
6
|
const extension = '.eszip';
|
|
15
7
|
const destPath = join(distDirectory, `${buildID}${extension}`);
|
|
@@ -23,7 +15,12 @@ const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, func
|
|
|
23
15
|
if (!debug) {
|
|
24
16
|
flags.push('--quiet');
|
|
25
17
|
}
|
|
26
|
-
|
|
18
|
+
try {
|
|
19
|
+
await deno.run(['run', ...flags, bundler, JSON.stringify(payload)], { pipeOutput: true });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw wrapBundleError(error, { format: 'eszip' });
|
|
23
|
+
}
|
|
27
24
|
const hash = await getFileHash(destPath);
|
|
28
25
|
return { extension, format: 'eszip2', hash };
|
|
29
26
|
};
|
|
@@ -33,4 +30,4 @@ const getESZIPBundler = () => {
|
|
|
33
30
|
const bundlerPath = resolve(pathname, '../../../deno/bundle.ts');
|
|
34
31
|
return bundlerPath;
|
|
35
32
|
};
|
|
36
|
-
export { bundle };
|
|
33
|
+
export { bundleESZIP as bundle };
|
|
@@ -11,7 +11,7 @@ interface BundleJSOptions {
|
|
|
11
11
|
functions: EdgeFunction[];
|
|
12
12
|
importMap: ImportMap;
|
|
13
13
|
}
|
|
14
|
-
declare const
|
|
14
|
+
declare const bundleJS: ({ buildID, debug, deno, distDirectory, functions, importMap, }: BundleJSOptions) => Promise<Bundle>;
|
|
15
15
|
interface GenerateStage2Options {
|
|
16
16
|
distDirectory: string;
|
|
17
17
|
fileName: string;
|
|
@@ -22,4 +22,4 @@ 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
|
-
export { bundle, generateStage2, getBootstrapURL };
|
|
25
|
+
export { bundleJS as bundle, generateStage2, getBootstrapURL };
|
|
@@ -5,15 +5,7 @@ import { pathToFileURL } from 'url';
|
|
|
5
5
|
import del from 'del';
|
|
6
6
|
import { wrapBundleError } from '../bundle_error.js';
|
|
7
7
|
import { getFileHash } from '../utils/sha256.js';
|
|
8
|
-
const BOOTSTRAP_LATEST = 'https://
|
|
9
|
-
const bundle = async (options) => {
|
|
10
|
-
try {
|
|
11
|
-
return await bundleJS(options);
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
throw wrapBundleError(error, { format: 'javascript' });
|
|
15
|
-
}
|
|
16
|
-
};
|
|
8
|
+
const BOOTSTRAP_LATEST = 'https://62bae4994570970008142f1e--edge-bootstrap.netlify.app/bootstrap/index-combined.ts';
|
|
17
9
|
const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, importMap, }) => {
|
|
18
10
|
const stage2Path = await generateStage2({ distDirectory, functions, fileName: `${buildID}-pre.js` });
|
|
19
11
|
const extension = '.js';
|
|
@@ -22,7 +14,12 @@ const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, import
|
|
|
22
14
|
if (!debug) {
|
|
23
15
|
flags.push('--quiet');
|
|
24
16
|
}
|
|
25
|
-
|
|
17
|
+
try {
|
|
18
|
+
await deno.run(['bundle', ...flags, stage2Path, jsBundlePath], { pipeOutput: true });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw wrapBundleError(error, { format: 'javascript' });
|
|
22
|
+
}
|
|
26
23
|
await fs.unlink(stage2Path);
|
|
27
24
|
const hash = await getFileHash(jsBundlePath);
|
|
28
25
|
return { extension, format: 'js', hash };
|
|
@@ -80,4 +77,4 @@ const getProductionEntryPoint = (functions) => {
|
|
|
80
77
|
const defaultExport = 'boot(functions);';
|
|
81
78
|
return [bootImport, importLines, exportDeclaration, defaultExport].join('\n\n');
|
|
82
79
|
};
|
|
83
|
-
export { bundle, generateStage2, getBootstrapURL };
|
|
80
|
+
export { bundleJS as bundle, generateStage2, getBootstrapURL };
|
package/dist/import_map.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
|
-
const
|
|
4
|
+
const INTERNAL_IMPORTS = {
|
|
5
5
|
'netlify:edge': 'https://edge-bootstrap.netlify.app/v1/index.ts',
|
|
6
6
|
};
|
|
7
7
|
class ImportMap {
|
|
8
8
|
constructor(input = []) {
|
|
9
9
|
const inputImports = input.reduce((acc, { imports }) => ({ ...acc, ...imports }), {});
|
|
10
|
-
// `
|
|
11
|
-
//
|
|
12
|
-
this.imports = { ...inputImports, ...
|
|
10
|
+
// `INTERNAL_IMPORTS` must come last,
|
|
11
|
+
// because we need to guarantee `netlify:edge` isn't user-defined.
|
|
12
|
+
this.imports = { ...inputImports, ...INTERNAL_IMPORTS };
|
|
13
13
|
}
|
|
14
14
|
getContents() {
|
|
15
15
|
const contents = {
|
package/dist/server/server.js
CHANGED
|
@@ -2,6 +2,7 @@ import { tmpName } from 'tmp-promise';
|
|
|
2
2
|
import { DenoBridge } from '../bridge.js';
|
|
3
3
|
import { generateStage2 } from '../formats/javascript.js';
|
|
4
4
|
import { ImportMap } from '../import_map.js';
|
|
5
|
+
import { ensureLatestTypes } from '../types.js';
|
|
5
6
|
import { killProcess, waitForServer } from './util.js';
|
|
6
7
|
const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, port, }) => {
|
|
7
8
|
const processRef = {};
|
|
@@ -39,7 +40,6 @@ const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportType
|
|
|
39
40
|
};
|
|
40
41
|
return startIsolate;
|
|
41
42
|
};
|
|
42
|
-
// eslint-disable-next-line complexity, max-statements
|
|
43
43
|
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }) => {
|
|
44
44
|
const deno = new DenoBridge({
|
|
45
45
|
debug,
|
|
@@ -51,6 +51,8 @@ const serve = async ({ certificatePath, debug, distImportMapPath, inspectSetting
|
|
|
51
51
|
const distDirectory = await tmpName();
|
|
52
52
|
// Wait for the binary to be downloaded if needed.
|
|
53
53
|
await deno.getBinaryPath();
|
|
54
|
+
// Downloading latest types if needed.
|
|
55
|
+
await ensureLatestTypes(deno);
|
|
54
56
|
// Creating an ImportMap instance with any import maps supplied by the user,
|
|
55
57
|
// if any.
|
|
56
58
|
const importMap = new ImportMap(importMaps);
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fetch from 'node-fetch';
|
|
4
|
+
const TYPES_URL = 'https://edge.netlify.com';
|
|
5
|
+
const ensureLatestTypes = async (deno, customTypesURL) => {
|
|
6
|
+
const typesURL = customTypesURL !== null && customTypesURL !== void 0 ? customTypesURL : TYPES_URL;
|
|
7
|
+
let [localVersion, remoteVersion] = [await getLocalVersion(deno), ''];
|
|
8
|
+
try {
|
|
9
|
+
remoteVersion = await getRemoteVersion(typesURL);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
deno.log('Could not check latest version of types:', error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (localVersion === remoteVersion) {
|
|
16
|
+
deno.log('Local version of types is up-to-date:', localVersion);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
deno.log('Local version of types is outdated, updating:', localVersion);
|
|
20
|
+
try {
|
|
21
|
+
await deno.run(['cache', '-r', typesURL]);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
deno.log('Could not download latest types:', error);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await writeVersionFile(deno, remoteVersion);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// no-op
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const getLocalVersion = async (deno) => {
|
|
35
|
+
const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
|
|
36
|
+
try {
|
|
37
|
+
const version = await fs.readFile(versionFilePath, 'utf8');
|
|
38
|
+
return version;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// no-op
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const getRemoteVersion = async (typesURL) => {
|
|
45
|
+
const versionURL = new URL('/version.txt', typesURL);
|
|
46
|
+
const res = await fetch(versionURL.toString());
|
|
47
|
+
if (res.status !== 200) {
|
|
48
|
+
throw new Error('Unexpected status code from version endpoint');
|
|
49
|
+
}
|
|
50
|
+
const version = await res.text();
|
|
51
|
+
return version;
|
|
52
|
+
};
|
|
53
|
+
const writeVersionFile = async (deno, version) => {
|
|
54
|
+
const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
|
|
55
|
+
await fs.writeFile(versionFilePath, version);
|
|
56
|
+
};
|
|
57
|
+
export { ensureLatestTypes };
|