@netlify/edge-bundler 1.8.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 +5 -3
- package/dist/bridge.js +10 -15
- package/dist/bundler.d.ts +3 -1
- package/dist/bundler.js +5 -2
- 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,10 +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;
|
|
7
8
|
denoDir?: string;
|
|
9
|
+
logger: Logger;
|
|
8
10
|
onAfterDownload?: OnAfterDownloadHook;
|
|
9
11
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
10
12
|
useGlobal?: boolean;
|
|
@@ -21,13 +23,14 @@ declare class DenoBridge {
|
|
|
21
23
|
currentDownload?: ReturnType<DenoBridge['downloadBinary']>;
|
|
22
24
|
debug: boolean;
|
|
23
25
|
denoDir?: string;
|
|
26
|
+
logger: Logger;
|
|
24
27
|
onAfterDownload?: OnAfterDownloadHook;
|
|
25
28
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
26
29
|
useGlobal: boolean;
|
|
27
30
|
versionRange: string;
|
|
28
|
-
constructor(options
|
|
31
|
+
constructor(options: DenoOptions);
|
|
29
32
|
private downloadBinary;
|
|
30
|
-
|
|
33
|
+
private getBinaryVersion;
|
|
31
34
|
private getCachedBinary;
|
|
32
35
|
private getGlobalBinary;
|
|
33
36
|
private getRemoteBinary;
|
|
@@ -39,7 +42,6 @@ declare class DenoBridge {
|
|
|
39
42
|
path: string;
|
|
40
43
|
}>;
|
|
41
44
|
getEnvironmentVariables(): Record<string, string>;
|
|
42
|
-
log(...data: unknown[]): void;
|
|
43
45
|
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
|
|
44
46
|
runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
|
|
45
47
|
}
|
package/dist/bridge.js
CHANGED
|
@@ -9,11 +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
16
|
this.denoDir = options.denoDir;
|
|
17
|
+
this.logger = options.logger;
|
|
17
18
|
this.onAfterDownload = options.onAfterDownload;
|
|
18
19
|
this.onBeforeDownload = options.onBeforeDownload;
|
|
19
20
|
this.useGlobal = (_c = options.useGlobal) !== null && _c !== void 0 ? _c : true;
|
|
@@ -23,9 +24,9 @@ class DenoBridge {
|
|
|
23
24
|
var _a, _b, _c;
|
|
24
25
|
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
25
26
|
await this.ensureCacheDirectory();
|
|
26
|
-
this.
|
|
27
|
+
this.logger.system(`Downloading Deno CLI to ${this.cacheDirectory}`);
|
|
27
28
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
28
|
-
const downloadedVersion = await
|
|
29
|
+
const downloadedVersion = await this.getBinaryVersion(binaryPath);
|
|
29
30
|
// We should never get here, because it means that `DENO_VERSION_RANGE` is
|
|
30
31
|
// a malformed semver range. If this does happen, let's throw an error so
|
|
31
32
|
// that the tests catch it.
|
|
@@ -38,7 +39,7 @@ class DenoBridge {
|
|
|
38
39
|
await ((_c = this.onAfterDownload) === null || _c === void 0 ? void 0 : _c.call(this));
|
|
39
40
|
return binaryPath;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
async getBinaryVersion(binaryPath) {
|
|
42
43
|
try {
|
|
43
44
|
const { stdout } = await execa(binaryPath, ['--version']);
|
|
44
45
|
const version = stdout.match(/^deno ([\d.]+)/);
|
|
@@ -47,8 +48,8 @@ class DenoBridge {
|
|
|
47
48
|
}
|
|
48
49
|
return version[1];
|
|
49
50
|
}
|
|
50
|
-
catch {
|
|
51
|
-
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.logger.system('Error checking Deno binary version', error);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
async getCachedBinary() {
|
|
@@ -71,7 +72,7 @@ class DenoBridge {
|
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
const globalBinaryName = 'deno';
|
|
74
|
-
const globalVersion = await
|
|
75
|
+
const globalVersion = await this.getBinaryVersion(globalBinaryName);
|
|
75
76
|
if (globalVersion === undefined || !semver.satisfies(globalVersion, this.versionRange)) {
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
@@ -103,12 +104,12 @@ class DenoBridge {
|
|
|
103
104
|
async getBinaryPath() {
|
|
104
105
|
const globalPath = await this.getGlobalBinary();
|
|
105
106
|
if (globalPath !== undefined) {
|
|
106
|
-
this.
|
|
107
|
+
this.logger.system('Using global installation of Deno CLI');
|
|
107
108
|
return { global: true, path: globalPath };
|
|
108
109
|
}
|
|
109
110
|
const cachedPath = await this.getCachedBinary();
|
|
110
111
|
if (cachedPath !== undefined) {
|
|
111
|
-
this.
|
|
112
|
+
this.logger.system('Using cached Deno CLI from', cachedPath);
|
|
112
113
|
return { global: false, path: cachedPath };
|
|
113
114
|
}
|
|
114
115
|
const downloadedPath = await this.getRemoteBinary();
|
|
@@ -121,12 +122,6 @@ class DenoBridge {
|
|
|
121
122
|
}
|
|
122
123
|
return env;
|
|
123
124
|
}
|
|
124
|
-
log(...data) {
|
|
125
|
-
if (!this.debug) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
console.log(...data);
|
|
129
|
-
}
|
|
130
125
|
// Runs the Deno CLI in the background and returns a reference to the child
|
|
131
126
|
// process, awaiting its execution.
|
|
132
127
|
async run(args, { pipeOutput } = {}) {
|
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,8 +13,9 @@ 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
|
}>;
|
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,11 +36,13 @@ 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
42
|
const options = {
|
|
41
43
|
debug,
|
|
42
44
|
cacheDirectory,
|
|
45
|
+
logger,
|
|
43
46
|
onAfterDownload,
|
|
44
47
|
onBeforeDownload,
|
|
45
48
|
};
|
|
@@ -48,7 +51,7 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { bas
|
|
|
48
51
|
}
|
|
49
52
|
const deno = new DenoBridge(options);
|
|
50
53
|
const basePath = getBasePath(sourceDirectories, inputBasePath);
|
|
51
|
-
await ensureLatestTypes(deno);
|
|
54
|
+
await ensureLatestTypes(deno, logger);
|
|
52
55
|
// The name of the bundle will be the hash of its contents, which we can't
|
|
53
56
|
// compute until we run the bundle process. For now, we'll use a random ID
|
|
54
57
|
// to create the bundle artifacts and rename them later.
|
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 {
|