@netlify/edge-bundler 1.7.0 → 1.10.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/dist/bridge.d.ts +9 -4
- package/dist/bridge.js +28 -20
- package/dist/bundler.d.ts +4 -1
- package/dist/bundler.js +11 -4
- package/dist/feature_flags.js +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +14 -0
- package/dist/server/server.d.ts +3 -1
- package/dist/server/server.js +5 -2
- package/dist/types.d.ts +2 -1
- package/dist/types.js +5 -5
- package/package.json +1 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ExecaChildProcess } from 'execa';
|
|
2
|
+
import { Logger } from './logger.js';
|
|
2
3
|
declare type OnBeforeDownloadHook = () => void | Promise<void>;
|
|
3
4
|
declare type OnAfterDownloadHook = (error?: Error) => void | Promise<void>;
|
|
4
5
|
interface DenoOptions {
|
|
5
6
|
cacheDirectory?: string;
|
|
6
7
|
debug?: boolean;
|
|
8
|
+
denoDir?: string;
|
|
9
|
+
logger?: Logger;
|
|
7
10
|
onAfterDownload?: OnAfterDownloadHook;
|
|
8
11
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
9
12
|
useGlobal?: boolean;
|
|
@@ -19,13 +22,15 @@ declare class DenoBridge {
|
|
|
19
22
|
cacheDirectory: string;
|
|
20
23
|
currentDownload?: ReturnType<DenoBridge['downloadBinary']>;
|
|
21
24
|
debug: boolean;
|
|
25
|
+
denoDir?: string;
|
|
26
|
+
logger: Logger;
|
|
22
27
|
onAfterDownload?: OnAfterDownloadHook;
|
|
23
28
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
24
29
|
useGlobal: boolean;
|
|
25
30
|
versionRange: string;
|
|
26
|
-
constructor(options
|
|
31
|
+
constructor(options: DenoOptions);
|
|
27
32
|
private downloadBinary;
|
|
28
|
-
|
|
33
|
+
private getBinaryVersion;
|
|
29
34
|
private getCachedBinary;
|
|
30
35
|
private getGlobalBinary;
|
|
31
36
|
private getRemoteBinary;
|
|
@@ -36,9 +41,9 @@ declare class DenoBridge {
|
|
|
36
41
|
global: boolean;
|
|
37
42
|
path: string;
|
|
38
43
|
}>;
|
|
39
|
-
|
|
44
|
+
getEnvironmentVariables(): Record<string, string>;
|
|
40
45
|
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
|
|
41
46
|
runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
|
|
42
47
|
}
|
|
43
48
|
export { DenoBridge };
|
|
44
|
-
export type { OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
|
|
49
|
+
export type { DenoOptions, OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
|
package/dist/bridge.js
CHANGED
|
@@ -5,26 +5,29 @@ import { execa } from 'execa';
|
|
|
5
5
|
import semver from 'semver';
|
|
6
6
|
import { download } from './downloader.js';
|
|
7
7
|
import { getPathInHome } from './home_path.js';
|
|
8
|
+
import { getLogger } from './logger.js';
|
|
8
9
|
import { getBinaryExtension } from './platform.js';
|
|
9
10
|
const DENO_VERSION_FILE = 'version.txt';
|
|
10
11
|
const DENO_VERSION_RANGE = '^1.20.3';
|
|
11
12
|
class DenoBridge {
|
|
12
|
-
constructor(options
|
|
13
|
-
var _a, _b, _c, _d;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
14
15
|
this.cacheDirectory = (_a = options.cacheDirectory) !== null && _a !== void 0 ? _a : getPathInHome('deno-cli');
|
|
15
16
|
this.debug = (_b = options.debug) !== null && _b !== void 0 ? _b : false;
|
|
17
|
+
this.denoDir = options.denoDir;
|
|
18
|
+
this.logger = (_c = options.logger) !== null && _c !== void 0 ? _c : getLogger(undefined, options.debug);
|
|
16
19
|
this.onAfterDownload = options.onAfterDownload;
|
|
17
20
|
this.onBeforeDownload = options.onBeforeDownload;
|
|
18
|
-
this.useGlobal = (
|
|
19
|
-
this.versionRange = (
|
|
21
|
+
this.useGlobal = (_d = options.useGlobal) !== null && _d !== void 0 ? _d : true;
|
|
22
|
+
this.versionRange = (_e = options.versionRange) !== null && _e !== void 0 ? _e : DENO_VERSION_RANGE;
|
|
20
23
|
}
|
|
21
24
|
async downloadBinary() {
|
|
22
25
|
var _a, _b, _c;
|
|
23
26
|
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
24
27
|
await this.ensureCacheDirectory();
|
|
25
|
-
this.
|
|
28
|
+
this.logger.system(`Downloading Deno CLI to ${this.cacheDirectory}`);
|
|
26
29
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
27
|
-
const downloadedVersion = await
|
|
30
|
+
const downloadedVersion = await this.getBinaryVersion(binaryPath);
|
|
28
31
|
// We should never get here, because it means that `DENO_VERSION_RANGE` is
|
|
29
32
|
// a malformed semver range. If this does happen, let's throw an error so
|
|
30
33
|
// that the tests catch it.
|
|
@@ -37,7 +40,7 @@ class DenoBridge {
|
|
|
37
40
|
await ((_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this));
|
|
38
41
|
return binaryPath;
|
|
39
42
|
}
|
|
40
|
-
|
|
43
|
+
async getBinaryVersion(binaryPath) {
|
|
41
44
|
try {
|
|
42
45
|
const { stdout } = await execa(binaryPath, ['--version']);
|
|
43
46
|
const version = stdout.match(/^deno ([\d.]+)/);
|
|
@@ -46,8 +49,8 @@ class DenoBridge {
|
|
|
46
49
|
}
|
|
47
50
|
return version[1];
|
|
48
51
|
}
|
|
49
|
-
catch {
|
|
50
|
-
|
|
52
|
+
catch (error) {
|
|
53
|
+
this.logger.system('Error checking Deno binary version', error);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
async getCachedBinary() {
|
|
@@ -70,7 +73,7 @@ class DenoBridge {
|
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
72
75
|
const globalBinaryName = 'deno';
|
|
73
|
-
const globalVersion = await
|
|
76
|
+
const globalVersion = await this.getBinaryVersion(globalBinaryName);
|
|
74
77
|
if (globalVersion === undefined || !semver.satisfies(globalVersion, this.versionRange)) {
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
@@ -82,9 +85,9 @@ class DenoBridge {
|
|
|
82
85
|
}
|
|
83
86
|
return this.currentDownload;
|
|
84
87
|
}
|
|
85
|
-
static runWithBinary(binaryPath, args, pipeOutput) {
|
|
88
|
+
static runWithBinary(binaryPath, args, options, pipeOutput) {
|
|
86
89
|
var _a, _b;
|
|
87
|
-
const runDeno = execa(binaryPath, args);
|
|
90
|
+
const runDeno = execa(binaryPath, args, options);
|
|
88
91
|
if (pipeOutput) {
|
|
89
92
|
(_a = runDeno.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
90
93
|
(_b = runDeno.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
@@ -102,34 +105,39 @@ class DenoBridge {
|
|
|
102
105
|
async getBinaryPath() {
|
|
103
106
|
const globalPath = await this.getGlobalBinary();
|
|
104
107
|
if (globalPath !== undefined) {
|
|
105
|
-
this.
|
|
108
|
+
this.logger.system('Using global installation of Deno CLI');
|
|
106
109
|
return { global: true, path: globalPath };
|
|
107
110
|
}
|
|
108
111
|
const cachedPath = await this.getCachedBinary();
|
|
109
112
|
if (cachedPath !== undefined) {
|
|
110
|
-
this.
|
|
113
|
+
this.logger.system('Using cached Deno CLI from', cachedPath);
|
|
111
114
|
return { global: false, path: cachedPath };
|
|
112
115
|
}
|
|
113
116
|
const downloadedPath = await this.getRemoteBinary();
|
|
114
117
|
return { global: false, path: downloadedPath };
|
|
115
118
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
getEnvironmentVariables() {
|
|
120
|
+
const env = {};
|
|
121
|
+
if (this.denoDir !== undefined) {
|
|
122
|
+
env.DENO_DIR = this.denoDir;
|
|
119
123
|
}
|
|
120
|
-
|
|
124
|
+
return env;
|
|
121
125
|
}
|
|
122
126
|
// Runs the Deno CLI in the background and returns a reference to the child
|
|
123
127
|
// process, awaiting its execution.
|
|
124
128
|
async run(args, { pipeOutput } = {}) {
|
|
125
129
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
126
|
-
|
|
130
|
+
const env = this.getEnvironmentVariables();
|
|
131
|
+
const options = { env };
|
|
132
|
+
return DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
127
133
|
}
|
|
128
134
|
// Runs the Deno CLI in the background, assigning a reference of the child
|
|
129
135
|
// process to a `ps` property in the `ref` argument, if one is supplied.
|
|
130
136
|
async runInBackground(args, pipeOutput, ref) {
|
|
131
137
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
132
|
-
const
|
|
138
|
+
const env = this.getEnvironmentVariables();
|
|
139
|
+
const options = { env };
|
|
140
|
+
const ps = DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
133
141
|
if (ref !== undefined) {
|
|
134
142
|
// eslint-disable-next-line no-param-reassign
|
|
135
143
|
ref.ps = ps;
|
package/dist/bundler.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Declaration } from './declaration.js';
|
|
|
3
3
|
import { EdgeFunction } from './edge_function.js';
|
|
4
4
|
import { FeatureFlags } from './feature_flags.js';
|
|
5
5
|
import { ImportMapFile } from './import_map.js';
|
|
6
|
+
import { LogFunction } from './logger.js';
|
|
6
7
|
interface BundleOptions {
|
|
7
8
|
basePath?: string;
|
|
8
9
|
cacheDirectory?: string;
|
|
@@ -12,9 +13,11 @@ interface BundleOptions {
|
|
|
12
13
|
importMaps?: ImportMapFile[];
|
|
13
14
|
onAfterDownload?: OnAfterDownloadHook;
|
|
14
15
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
16
|
+
systemLogger?: LogFunction;
|
|
15
17
|
}
|
|
16
|
-
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{
|
|
18
|
+
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, systemLogger, }?: BundleOptions) => Promise<{
|
|
17
19
|
functions: EdgeFunction[];
|
|
18
20
|
manifest: import("./manifest.js").Manifest;
|
|
19
21
|
}>;
|
|
20
22
|
export { bundle };
|
|
23
|
+
export type { BundleOptions };
|
package/dist/bundler.js
CHANGED
|
@@ -8,6 +8,7 @@ import { findFunctions } from './finder.js';
|
|
|
8
8
|
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
|
+
import { getLogger } from './logger.js';
|
|
11
12
|
import { writeManifest } from './manifest.js';
|
|
12
13
|
import { ensureLatestTypes } from './types.js';
|
|
13
14
|
const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, featureFlags, }) => {
|
|
@@ -35,16 +36,22 @@ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functi
|
|
|
35
36
|
}
|
|
36
37
|
return bundleOps;
|
|
37
38
|
};
|
|
38
|
-
const bundle = async (sourceDirectories, distDirectory, declarations = [], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
|
|
39
|
+
const bundle = async (sourceDirectories, distDirectory, declarations = [], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, systemLogger, } = {}) => {
|
|
40
|
+
const logger = getLogger(systemLogger, debug);
|
|
39
41
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
40
|
-
const
|
|
42
|
+
const options = {
|
|
41
43
|
debug,
|
|
42
44
|
cacheDirectory,
|
|
45
|
+
logger,
|
|
43
46
|
onAfterDownload,
|
|
44
47
|
onBeforeDownload,
|
|
45
|
-
}
|
|
48
|
+
};
|
|
49
|
+
if (cacheDirectory !== undefined && featureFlags.edge_functions_cache_deno_dir) {
|
|
50
|
+
options.denoDir = join(cacheDirectory, 'deno_dir');
|
|
51
|
+
}
|
|
52
|
+
const deno = new DenoBridge(options);
|
|
46
53
|
const basePath = getBasePath(sourceDirectories, inputBasePath);
|
|
47
|
-
await ensureLatestTypes(deno);
|
|
54
|
+
await ensureLatestTypes(deno, logger);
|
|
48
55
|
// The name of the bundle will be the hash of its contents, which we can't
|
|
49
56
|
// compute until we run the bundle process. For now, we'll use a random ID
|
|
50
57
|
// to create the bundle artifacts and rename them later.
|
package/dist/feature_flags.js
CHANGED
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare type LogFunction = (...args: unknown[]) => void;
|
|
2
|
+
interface Logger {
|
|
3
|
+
system: LogFunction;
|
|
4
|
+
user: LogFunction;
|
|
5
|
+
}
|
|
6
|
+
declare const getLogger: (systemLogger?: LogFunction, debug?: boolean) => Logger;
|
|
7
|
+
export { getLogger };
|
|
8
|
+
export type { LogFunction, Logger };
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const noopLogger = () => {
|
|
2
|
+
// no-op
|
|
3
|
+
};
|
|
4
|
+
const getLogger = (systemLogger, debug = false) => {
|
|
5
|
+
// If there is a system logger configured, we'll use that. If there isn't,
|
|
6
|
+
// we'll pipe system logs to stdout if `debug` is enabled and swallow them
|
|
7
|
+
// otherwise.
|
|
8
|
+
const system = systemLogger !== null && systemLogger !== void 0 ? systemLogger : (debug ? console.log : noopLogger);
|
|
9
|
+
return {
|
|
10
|
+
system,
|
|
11
|
+
user: console.log,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export { getLogger };
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js';
|
|
2
2
|
import type { EdgeFunction } from '../edge_function.js';
|
|
3
3
|
import { ImportMapFile } from '../import_map.js';
|
|
4
|
+
import { LogFunction } from '../logger.js';
|
|
4
5
|
declare type FormatFunction = (name: string) => string;
|
|
5
6
|
interface InspectSettings {
|
|
6
7
|
enabled: boolean;
|
|
@@ -18,8 +19,9 @@ interface ServeOptions {
|
|
|
18
19
|
formatExportTypeError?: FormatFunction;
|
|
19
20
|
formatImportError?: FormatFunction;
|
|
20
21
|
port: number;
|
|
22
|
+
systemLogger?: LogFunction;
|
|
21
23
|
}
|
|
22
|
-
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[]) => Promise<{
|
|
24
|
+
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[]) => Promise<{
|
|
23
25
|
graph: any;
|
|
24
26
|
success: boolean;
|
|
25
27
|
}>>;
|
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 { getLogger } from '../logger.js';
|
|
5
6
|
import { ensureLatestTypes } from '../types.js';
|
|
6
7
|
import { killProcess, waitForServer } from './util.js';
|
|
7
8
|
const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, port, }) => {
|
|
@@ -40,9 +41,11 @@ const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportType
|
|
|
40
41
|
};
|
|
41
42
|
return startIsolate;
|
|
42
43
|
};
|
|
43
|
-
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }) => {
|
|
44
|
+
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }) => {
|
|
45
|
+
const logger = getLogger(systemLogger, debug);
|
|
44
46
|
const deno = new DenoBridge({
|
|
45
47
|
debug,
|
|
48
|
+
logger,
|
|
46
49
|
onAfterDownload,
|
|
47
50
|
onBeforeDownload,
|
|
48
51
|
});
|
|
@@ -52,7 +55,7 @@ const serve = async ({ certificatePath, debug, distImportMapPath, inspectSetting
|
|
|
52
55
|
// Wait for the binary to be downloaded if needed.
|
|
53
56
|
await deno.getBinaryPath();
|
|
54
57
|
// Downloading latest types if needed.
|
|
55
|
-
await ensureLatestTypes(deno);
|
|
58
|
+
await ensureLatestTypes(deno, logger);
|
|
56
59
|
// Creating an ImportMap instance with any import maps supplied by the user,
|
|
57
60
|
// if any.
|
|
58
61
|
const importMap = new ImportMap(importMaps);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { DenoBridge } from './bridge.js';
|
|
2
|
-
|
|
2
|
+
import type { Logger } from './logger.js';
|
|
3
|
+
declare const ensureLatestTypes: (deno: DenoBridge, logger: Logger, customTypesURL?: string) => Promise<void>;
|
|
3
4
|
export { ensureLatestTypes };
|
package/dist/types.js
CHANGED
|
@@ -2,26 +2,26 @@ import { promises as fs } from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import fetch from 'node-fetch';
|
|
4
4
|
const TYPES_URL = 'https://edge.netlify.com';
|
|
5
|
-
const ensureLatestTypes = async (deno, customTypesURL) => {
|
|
5
|
+
const ensureLatestTypes = async (deno, logger, customTypesURL) => {
|
|
6
6
|
const typesURL = customTypesURL !== null && customTypesURL !== void 0 ? customTypesURL : TYPES_URL;
|
|
7
7
|
let [localVersion, remoteVersion] = [await getLocalVersion(deno), ''];
|
|
8
8
|
try {
|
|
9
9
|
remoteVersion = await getRemoteVersion(typesURL);
|
|
10
10
|
}
|
|
11
11
|
catch (error) {
|
|
12
|
-
|
|
12
|
+
logger.system('Could not check latest version of types:', error);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
if (localVersion === remoteVersion) {
|
|
16
|
-
|
|
16
|
+
logger.system('Local version of types is up-to-date:', localVersion);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
logger.system('Local version of types is outdated, updating:', localVersion);
|
|
20
20
|
try {
|
|
21
21
|
await deno.run(['cache', '-r', typesURL]);
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
|
-
|
|
24
|
+
logger.system('Could not download latest types:', error);
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
try {
|