@netlify/edge-bundler 1.6.0 → 1.9.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 +24 -17
- package/dist/bundler.d.ts +5 -1
- package/dist/bundler.js +17 -6
- 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
|
@@ -9,10 +9,12 @@ import { getBinaryExtension } from './platform.js';
|
|
|
9
9
|
const DENO_VERSION_FILE = 'version.txt';
|
|
10
10
|
const DENO_VERSION_RANGE = '^1.20.3';
|
|
11
11
|
class DenoBridge {
|
|
12
|
-
constructor(options
|
|
12
|
+
constructor(options) {
|
|
13
13
|
var _a, _b, _c, _d;
|
|
14
14
|
this.cacheDirectory = (_a = options.cacheDirectory) !== null && _a !== void 0 ? _a : getPathInHome('deno-cli');
|
|
15
15
|
this.debug = (_b = options.debug) !== null && _b !== void 0 ? _b : false;
|
|
16
|
+
this.denoDir = options.denoDir;
|
|
17
|
+
this.logger = options.logger;
|
|
16
18
|
this.onAfterDownload = options.onAfterDownload;
|
|
17
19
|
this.onBeforeDownload = options.onBeforeDownload;
|
|
18
20
|
this.useGlobal = (_c = options.useGlobal) !== null && _c !== void 0 ? _c : true;
|
|
@@ -22,9 +24,9 @@ class DenoBridge {
|
|
|
22
24
|
var _a, _b, _c;
|
|
23
25
|
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
24
26
|
await this.ensureCacheDirectory();
|
|
25
|
-
this.
|
|
27
|
+
this.logger.system(`Downloading Deno CLI to ${this.cacheDirectory}`);
|
|
26
28
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
27
|
-
const downloadedVersion = await
|
|
29
|
+
const downloadedVersion = await this.getBinaryVersion(binaryPath);
|
|
28
30
|
// We should never get here, because it means that `DENO_VERSION_RANGE` is
|
|
29
31
|
// a malformed semver range. If this does happen, let's throw an error so
|
|
30
32
|
// that the tests catch it.
|
|
@@ -37,7 +39,7 @@ class DenoBridge {
|
|
|
37
39
|
await ((_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this));
|
|
38
40
|
return binaryPath;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
async getBinaryVersion(binaryPath) {
|
|
41
43
|
try {
|
|
42
44
|
const { stdout } = await execa(binaryPath, ['--version']);
|
|
43
45
|
const version = stdout.match(/^deno ([\d.]+)/);
|
|
@@ -46,8 +48,8 @@ class DenoBridge {
|
|
|
46
48
|
}
|
|
47
49
|
return version[1];
|
|
48
50
|
}
|
|
49
|
-
catch {
|
|
50
|
-
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.logger.system('Error checking Deno binary version', error);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
async getCachedBinary() {
|
|
@@ -70,7 +72,7 @@ class DenoBridge {
|
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
74
|
const globalBinaryName = 'deno';
|
|
73
|
-
const globalVersion = await
|
|
75
|
+
const globalVersion = await this.getBinaryVersion(globalBinaryName);
|
|
74
76
|
if (globalVersion === undefined || !semver.satisfies(globalVersion, this.versionRange)) {
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
@@ -82,9 +84,9 @@ class DenoBridge {
|
|
|
82
84
|
}
|
|
83
85
|
return this.currentDownload;
|
|
84
86
|
}
|
|
85
|
-
static runWithBinary(binaryPath, args, pipeOutput) {
|
|
87
|
+
static runWithBinary(binaryPath, args, options, pipeOutput) {
|
|
86
88
|
var _a, _b;
|
|
87
|
-
const runDeno = execa(binaryPath, args);
|
|
89
|
+
const runDeno = execa(binaryPath, args, options);
|
|
88
90
|
if (pipeOutput) {
|
|
89
91
|
(_a = runDeno.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
90
92
|
(_b = runDeno.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
@@ -102,34 +104,39 @@ class DenoBridge {
|
|
|
102
104
|
async getBinaryPath() {
|
|
103
105
|
const globalPath = await this.getGlobalBinary();
|
|
104
106
|
if (globalPath !== undefined) {
|
|
105
|
-
this.
|
|
107
|
+
this.logger.system('Using global installation of Deno CLI');
|
|
106
108
|
return { global: true, path: globalPath };
|
|
107
109
|
}
|
|
108
110
|
const cachedPath = await this.getCachedBinary();
|
|
109
111
|
if (cachedPath !== undefined) {
|
|
110
|
-
this.
|
|
112
|
+
this.logger.system('Using cached Deno CLI from', cachedPath);
|
|
111
113
|
return { global: false, path: cachedPath };
|
|
112
114
|
}
|
|
113
115
|
const downloadedPath = await this.getRemoteBinary();
|
|
114
116
|
return { global: false, path: downloadedPath };
|
|
115
117
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
getEnvironmentVariables() {
|
|
119
|
+
const env = {};
|
|
120
|
+
if (this.denoDir !== undefined) {
|
|
121
|
+
env.DENO_DIR = this.denoDir;
|
|
119
122
|
}
|
|
120
|
-
|
|
123
|
+
return env;
|
|
121
124
|
}
|
|
122
125
|
// Runs the Deno CLI in the background and returns a reference to the child
|
|
123
126
|
// process, awaiting its execution.
|
|
124
127
|
async run(args, { pipeOutput } = {}) {
|
|
125
128
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
126
|
-
|
|
129
|
+
const env = this.getEnvironmentVariables();
|
|
130
|
+
const options = { env };
|
|
131
|
+
return DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
127
132
|
}
|
|
128
133
|
// Runs the Deno CLI in the background, assigning a reference of the child
|
|
129
134
|
// process to a `ps` property in the `ref` argument, if one is supplied.
|
|
130
135
|
async runInBackground(args, pipeOutput, ref) {
|
|
131
136
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
132
|
-
const
|
|
137
|
+
const env = this.getEnvironmentVariables();
|
|
138
|
+
const options = { env };
|
|
139
|
+
const ps = DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
133
140
|
if (ref !== undefined) {
|
|
134
141
|
// eslint-disable-next-line no-param-reassign
|
|
135
142
|
ref.ps = ps;
|
package/dist/bundler.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ 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 {
|
|
8
|
+
basePath?: string;
|
|
7
9
|
cacheDirectory?: string;
|
|
8
10
|
debug?: boolean;
|
|
9
11
|
distImportMapPath?: string;
|
|
@@ -11,9 +13,11 @@ interface BundleOptions {
|
|
|
11
13
|
importMaps?: ImportMapFile[];
|
|
12
14
|
onAfterDownload?: OnAfterDownloadHook;
|
|
13
15
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
16
|
+
systemLogger?: LogFunction;
|
|
14
17
|
}
|
|
15
|
-
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { 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<{
|
|
16
19
|
functions: EdgeFunction[];
|
|
17
20
|
manifest: import("./manifest.js").Manifest;
|
|
18
21
|
}>;
|
|
19
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 = [], { 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
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
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);
|
|
53
|
+
const basePath = getBasePath(sourceDirectories, inputBasePath);
|
|
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.
|
|
@@ -87,7 +94,11 @@ const createFinalBundles = async (bundles, distDirectory, buildID) => {
|
|
|
87
94
|
});
|
|
88
95
|
await Promise.all(renamingOps);
|
|
89
96
|
};
|
|
90
|
-
const getBasePath = (sourceDirectories) => {
|
|
97
|
+
const getBasePath = (sourceDirectories, inputBasePath) => {
|
|
98
|
+
// If there's a specific base path supplied, that takes precedence.
|
|
99
|
+
if (inputBasePath !== undefined) {
|
|
100
|
+
return inputBasePath;
|
|
101
|
+
}
|
|
91
102
|
// `common-path-prefix` returns an empty string when called with a single
|
|
92
103
|
// path, so we check for that case and return the path itself instead.
|
|
93
104
|
if (sourceDirectories.length === 1) {
|
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 {
|