@netlify/edge-bundler 1.4.3 → 1.7.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 +3 -3
- package/dist/bridge.d.ts +2 -1
- package/dist/bridge.js +11 -7
- package/dist/bundler.d.ts +2 -1
- package/dist/bundler.js +10 -3
- package/dist/formats/eszip.d.ts +3 -1
- package/dist/formats/eszip.js +2 -1
- package/dist/formats/javascript.js +1 -1
- package/dist/import_map.js +1 -1
- package/dist/server/server.js +3 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.js +58 -0
- package/package.json +1 -1
package/deno/bundle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { writeStage2 } from 'https://
|
|
1
|
+
import { writeStage2 } from 'https://62d144a15553b50009af7ac6--edge.netlify.com/bundler/mod.ts'
|
|
2
2
|
|
|
3
3
|
const [payload] = Deno.args
|
|
4
|
-
const { basePath, destPath, functions } = JSON.parse(payload)
|
|
4
|
+
const { basePath, destPath, functions, imports } = JSON.parse(payload)
|
|
5
5
|
|
|
6
|
-
await writeStage2({ basePath, functions,
|
|
6
|
+
await writeStage2({ basePath, destPath, functions, imports })
|
package/dist/bridge.d.ts
CHANGED
|
@@ -29,13 +29,14 @@ 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;
|
|
34
|
+
ensureCacheDirectory(): Promise<void>;
|
|
35
35
|
getBinaryPath(): Promise<{
|
|
36
36
|
global: boolean;
|
|
37
37
|
path: string;
|
|
38
38
|
}>;
|
|
39
|
+
log(...data: unknown[]): void;
|
|
39
40
|
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
|
|
40
41
|
runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
|
|
41
42
|
}
|
package/dist/bridge.js
CHANGED
|
@@ -21,7 +21,7 @@ class DenoBridge {
|
|
|
21
21
|
async downloadBinary() {
|
|
22
22
|
var _a, _b, _c;
|
|
23
23
|
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
24
|
-
await
|
|
24
|
+
await this.ensureCacheDirectory();
|
|
25
25
|
this.log(`Downloading Deno CLI to ${this.cacheDirectory}...`);
|
|
26
26
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
27
27
|
const downloadedVersion = await DenoBridge.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);
|
|
@@ -98,9 +92,13 @@ class DenoBridge {
|
|
|
98
92
|
return runDeno;
|
|
99
93
|
}
|
|
100
94
|
async writeVersionFile(version) {
|
|
95
|
+
await this.ensureCacheDirectory();
|
|
101
96
|
const versionFilePath = path.join(this.cacheDirectory, DENO_VERSION_FILE);
|
|
102
97
|
await fs.writeFile(versionFilePath, version);
|
|
103
98
|
}
|
|
99
|
+
async ensureCacheDirectory() {
|
|
100
|
+
await fs.mkdir(this.cacheDirectory, { recursive: true });
|
|
101
|
+
}
|
|
104
102
|
async getBinaryPath() {
|
|
105
103
|
const globalPath = await this.getGlobalBinary();
|
|
106
104
|
if (globalPath !== undefined) {
|
|
@@ -115,6 +113,12 @@ class DenoBridge {
|
|
|
115
113
|
const downloadedPath = await this.getRemoteBinary();
|
|
116
114
|
return { global: false, path: downloadedPath };
|
|
117
115
|
}
|
|
116
|
+
log(...data) {
|
|
117
|
+
if (!this.debug) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
console.log(...data);
|
|
121
|
+
}
|
|
118
122
|
// Runs the Deno CLI in the background and returns a reference to the child
|
|
119
123
|
// process, awaiting its execution.
|
|
120
124
|
async run(args, { pipeOutput } = {}) {
|
package/dist/bundler.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { EdgeFunction } from './edge_function.js';
|
|
|
4
4
|
import { FeatureFlags } from './feature_flags.js';
|
|
5
5
|
import { ImportMapFile } from './import_map.js';
|
|
6
6
|
interface BundleOptions {
|
|
7
|
+
basePath?: string;
|
|
7
8
|
cacheDirectory?: string;
|
|
8
9
|
debug?: boolean;
|
|
9
10
|
distImportMapPath?: string;
|
|
@@ -12,7 +13,7 @@ interface BundleOptions {
|
|
|
12
13
|
onAfterDownload?: OnAfterDownloadHook;
|
|
13
14
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
14
15
|
}
|
|
15
|
-
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{
|
|
16
|
+
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{
|
|
16
17
|
functions: EdgeFunction[];
|
|
17
18
|
manifest: import("./manifest.js").Manifest;
|
|
18
19
|
}>;
|
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) {
|
|
@@ -19,6 +20,7 @@ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functi
|
|
|
19
20
|
deno,
|
|
20
21
|
distDirectory,
|
|
21
22
|
functions,
|
|
23
|
+
importMap,
|
|
22
24
|
}));
|
|
23
25
|
}
|
|
24
26
|
else {
|
|
@@ -33,7 +35,7 @@ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functi
|
|
|
33
35
|
}
|
|
34
36
|
return bundleOps;
|
|
35
37
|
};
|
|
36
|
-
const bundle = async (sourceDirectories, distDirectory, declarations = [], { cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
|
|
38
|
+
const bundle = async (sourceDirectories, distDirectory, declarations = [], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => {
|
|
37
39
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
38
40
|
const deno = new DenoBridge({
|
|
39
41
|
debug,
|
|
@@ -41,7 +43,8 @@ const bundle = async (sourceDirectories, distDirectory, declarations = [], { cac
|
|
|
41
43
|
onAfterDownload,
|
|
42
44
|
onBeforeDownload,
|
|
43
45
|
});
|
|
44
|
-
const basePath = getBasePath(sourceDirectories);
|
|
46
|
+
const basePath = getBasePath(sourceDirectories, inputBasePath);
|
|
47
|
+
await ensureLatestTypes(deno);
|
|
45
48
|
// The name of the bundle will be the hash of its contents, which we can't
|
|
46
49
|
// compute until we run the bundle process. For now, we'll use a random ID
|
|
47
50
|
// to create the bundle artifacts and rename them later.
|
|
@@ -84,7 +87,11 @@ const createFinalBundles = async (bundles, distDirectory, buildID) => {
|
|
|
84
87
|
});
|
|
85
88
|
await Promise.all(renamingOps);
|
|
86
89
|
};
|
|
87
|
-
const getBasePath = (sourceDirectories) => {
|
|
90
|
+
const getBasePath = (sourceDirectories, inputBasePath) => {
|
|
91
|
+
// If there's a specific base path supplied, that takes precedence.
|
|
92
|
+
if (inputBasePath !== undefined) {
|
|
93
|
+
return inputBasePath;
|
|
94
|
+
}
|
|
88
95
|
// `common-path-prefix` returns an empty string when called with a single
|
|
89
96
|
// path, so we check for that case and return the path itself instead.
|
|
90
97
|
if (sourceDirectories.length === 1) {
|
package/dist/formats/eszip.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DenoBridge } from '../bridge.js';
|
|
2
2
|
import type { Bundle } from '../bundle.js';
|
|
3
3
|
import { EdgeFunction } from '../edge_function.js';
|
|
4
|
+
import { ImportMap } from '../import_map.js';
|
|
4
5
|
interface BundleESZIPOptions {
|
|
5
6
|
basePath: string;
|
|
6
7
|
buildID: string;
|
|
@@ -8,6 +9,7 @@ interface BundleESZIPOptions {
|
|
|
8
9
|
deno: DenoBridge;
|
|
9
10
|
distDirectory: string;
|
|
10
11
|
functions: EdgeFunction[];
|
|
12
|
+
importMap: ImportMap;
|
|
11
13
|
}
|
|
12
|
-
declare const bundleESZIP: ({ basePath, buildID, debug, deno, distDirectory, functions, }: BundleESZIPOptions) => Promise<Bundle>;
|
|
14
|
+
declare const bundleESZIP: ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, }: BundleESZIPOptions) => Promise<Bundle>;
|
|
13
15
|
export { bundleESZIP as bundle };
|
package/dist/formats/eszip.js
CHANGED
|
@@ -2,7 +2,7 @@ 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 bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, functions, }) => {
|
|
5
|
+
const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, functions, importMap, }) => {
|
|
6
6
|
const extension = '.eszip';
|
|
7
7
|
const destPath = join(distDirectory, `${buildID}${extension}`);
|
|
8
8
|
const bundler = getESZIPBundler();
|
|
@@ -10,6 +10,7 @@ const bundleESZIP = async ({ basePath, buildID, debug, deno, distDirectory, func
|
|
|
10
10
|
basePath,
|
|
11
11
|
destPath,
|
|
12
12
|
functions,
|
|
13
|
+
imports: importMap.imports,
|
|
13
14
|
};
|
|
14
15
|
const flags = ['--allow-all'];
|
|
15
16
|
if (!debug) {
|
|
@@ -5,7 +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://
|
|
8
|
+
const BOOTSTRAP_LATEST = 'https://62d144a15553b50009af7ac6--edge.netlify.com/bootstrap/index-combined.ts';
|
|
9
9
|
const bundleJS = async ({ buildID, debug, deno, distDirectory, functions, importMap, }) => {
|
|
10
10
|
const stage2Path = await generateStage2({ distDirectory, functions, fileName: `${buildID}-pre.js` });
|
|
11
11
|
const extension = '.js';
|
package/dist/import_map.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Buffer } from 'buffer';
|
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
const INTERNAL_IMPORTS = {
|
|
5
|
-
'netlify:edge': 'https://edge
|
|
5
|
+
'netlify:edge': 'https://edge.netlify.com/v1/index.ts',
|
|
6
6
|
};
|
|
7
7
|
class ImportMap {
|
|
8
8
|
constructor(input = []) {
|
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,58 @@
|
|
|
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
|
+
await deno.ensureCacheDirectory();
|
|
55
|
+
const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
|
|
56
|
+
await fs.writeFile(versionFilePath, version);
|
|
57
|
+
};
|
|
58
|
+
export { ensureLatestTypes };
|