@netlify/edge-bundler 1.5.0 → 1.8.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 +5 -1
- package/dist/bridge.js +21 -5
- package/dist/bundler.d.ts +3 -1
- package/dist/bundler.js +14 -5
- package/dist/feature_flags.js +1 -0
- 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/types.js +1 -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
|
@@ -4,6 +4,7 @@ declare type OnAfterDownloadHook = (error?: Error) => void | Promise<void>;
|
|
|
4
4
|
interface DenoOptions {
|
|
5
5
|
cacheDirectory?: string;
|
|
6
6
|
debug?: boolean;
|
|
7
|
+
denoDir?: string;
|
|
7
8
|
onAfterDownload?: OnAfterDownloadHook;
|
|
8
9
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
9
10
|
useGlobal?: boolean;
|
|
@@ -19,6 +20,7 @@ declare class DenoBridge {
|
|
|
19
20
|
cacheDirectory: string;
|
|
20
21
|
currentDownload?: ReturnType<DenoBridge['downloadBinary']>;
|
|
21
22
|
debug: boolean;
|
|
23
|
+
denoDir?: string;
|
|
22
24
|
onAfterDownload?: OnAfterDownloadHook;
|
|
23
25
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
24
26
|
useGlobal: boolean;
|
|
@@ -31,13 +33,15 @@ declare class DenoBridge {
|
|
|
31
33
|
private getRemoteBinary;
|
|
32
34
|
private static runWithBinary;
|
|
33
35
|
private writeVersionFile;
|
|
36
|
+
ensureCacheDirectory(): Promise<void>;
|
|
34
37
|
getBinaryPath(): Promise<{
|
|
35
38
|
global: boolean;
|
|
36
39
|
path: string;
|
|
37
40
|
}>;
|
|
41
|
+
getEnvironmentVariables(): Record<string, string>;
|
|
38
42
|
log(...data: unknown[]): void;
|
|
39
43
|
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
|
|
40
44
|
runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
|
|
41
45
|
}
|
|
42
46
|
export { DenoBridge };
|
|
43
|
-
export type { OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
|
|
47
|
+
export type { DenoOptions, OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
|
package/dist/bridge.js
CHANGED
|
@@ -13,6 +13,7 @@ class DenoBridge {
|
|
|
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;
|
|
16
17
|
this.onAfterDownload = options.onAfterDownload;
|
|
17
18
|
this.onBeforeDownload = options.onBeforeDownload;
|
|
18
19
|
this.useGlobal = (_c = options.useGlobal) !== null && _c !== void 0 ? _c : true;
|
|
@@ -21,7 +22,7 @@ class DenoBridge {
|
|
|
21
22
|
async downloadBinary() {
|
|
22
23
|
var _a, _b, _c;
|
|
23
24
|
await ((_a = this.onBeforeDownload) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
24
|
-
await
|
|
25
|
+
await this.ensureCacheDirectory();
|
|
25
26
|
this.log(`Downloading Deno CLI to ${this.cacheDirectory}...`);
|
|
26
27
|
const binaryPath = await download(this.cacheDirectory, this.versionRange);
|
|
27
28
|
const downloadedVersion = await DenoBridge.getBinaryVersion(binaryPath);
|
|
@@ -82,9 +83,9 @@ class DenoBridge {
|
|
|
82
83
|
}
|
|
83
84
|
return this.currentDownload;
|
|
84
85
|
}
|
|
85
|
-
static runWithBinary(binaryPath, args, pipeOutput) {
|
|
86
|
+
static runWithBinary(binaryPath, args, options, pipeOutput) {
|
|
86
87
|
var _a, _b;
|
|
87
|
-
const runDeno = execa(binaryPath, args);
|
|
88
|
+
const runDeno = execa(binaryPath, args, options);
|
|
88
89
|
if (pipeOutput) {
|
|
89
90
|
(_a = runDeno.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
90
91
|
(_b = runDeno.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
@@ -92,9 +93,13 @@ class DenoBridge {
|
|
|
92
93
|
return runDeno;
|
|
93
94
|
}
|
|
94
95
|
async writeVersionFile(version) {
|
|
96
|
+
await this.ensureCacheDirectory();
|
|
95
97
|
const versionFilePath = path.join(this.cacheDirectory, DENO_VERSION_FILE);
|
|
96
98
|
await fs.writeFile(versionFilePath, version);
|
|
97
99
|
}
|
|
100
|
+
async ensureCacheDirectory() {
|
|
101
|
+
await fs.mkdir(this.cacheDirectory, { recursive: true });
|
|
102
|
+
}
|
|
98
103
|
async getBinaryPath() {
|
|
99
104
|
const globalPath = await this.getGlobalBinary();
|
|
100
105
|
if (globalPath !== undefined) {
|
|
@@ -109,6 +114,13 @@ class DenoBridge {
|
|
|
109
114
|
const downloadedPath = await this.getRemoteBinary();
|
|
110
115
|
return { global: false, path: downloadedPath };
|
|
111
116
|
}
|
|
117
|
+
getEnvironmentVariables() {
|
|
118
|
+
const env = {};
|
|
119
|
+
if (this.denoDir !== undefined) {
|
|
120
|
+
env.DENO_DIR = this.denoDir;
|
|
121
|
+
}
|
|
122
|
+
return env;
|
|
123
|
+
}
|
|
112
124
|
log(...data) {
|
|
113
125
|
if (!this.debug) {
|
|
114
126
|
return;
|
|
@@ -119,13 +131,17 @@ class DenoBridge {
|
|
|
119
131
|
// process, awaiting its execution.
|
|
120
132
|
async run(args, { pipeOutput } = {}) {
|
|
121
133
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
122
|
-
|
|
134
|
+
const env = this.getEnvironmentVariables();
|
|
135
|
+
const options = { env };
|
|
136
|
+
return DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
123
137
|
}
|
|
124
138
|
// Runs the Deno CLI in the background, assigning a reference of the child
|
|
125
139
|
// process to a `ps` property in the `ref` argument, if one is supplied.
|
|
126
140
|
async runInBackground(args, pipeOutput, ref) {
|
|
127
141
|
const { path: binaryPath } = await this.getBinaryPath();
|
|
128
|
-
const
|
|
142
|
+
const env = this.getEnvironmentVariables();
|
|
143
|
+
const options = { env };
|
|
144
|
+
const ps = DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
|
|
129
145
|
if (ref !== undefined) {
|
|
130
146
|
// eslint-disable-next-line no-param-reassign
|
|
131
147
|
ref.ps = ps;
|
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,8 +13,9 @@ 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
|
}>;
|
|
19
20
|
export { bundle };
|
|
21
|
+
export type { BundleOptions };
|
package/dist/bundler.js
CHANGED
|
@@ -20,6 +20,7 @@ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functi
|
|
|
20
20
|
deno,
|
|
21
21
|
distDirectory,
|
|
22
22
|
functions,
|
|
23
|
+
importMap,
|
|
23
24
|
}));
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
@@ -34,15 +35,19 @@ const createBundleOps = ({ basePath, buildID, debug, deno, distDirectory, functi
|
|
|
34
35
|
}
|
|
35
36
|
return bundleOps;
|
|
36
37
|
};
|
|
37
|
-
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, } = {}) => {
|
|
38
39
|
const featureFlags = getFlags(inputFeatureFlags);
|
|
39
|
-
const
|
|
40
|
+
const options = {
|
|
40
41
|
debug,
|
|
41
42
|
cacheDirectory,
|
|
42
43
|
onAfterDownload,
|
|
43
44
|
onBeforeDownload,
|
|
44
|
-
}
|
|
45
|
-
|
|
45
|
+
};
|
|
46
|
+
if (cacheDirectory !== undefined && featureFlags.edge_functions_cache_deno_dir) {
|
|
47
|
+
options.denoDir = join(cacheDirectory, 'deno_dir');
|
|
48
|
+
}
|
|
49
|
+
const deno = new DenoBridge(options);
|
|
50
|
+
const basePath = getBasePath(sourceDirectories, inputBasePath);
|
|
46
51
|
await ensureLatestTypes(deno);
|
|
47
52
|
// The name of the bundle will be the hash of its contents, which we can't
|
|
48
53
|
// compute until we run the bundle process. For now, we'll use a random ID
|
|
@@ -86,7 +91,11 @@ const createFinalBundles = async (bundles, distDirectory, buildID) => {
|
|
|
86
91
|
});
|
|
87
92
|
await Promise.all(renamingOps);
|
|
88
93
|
};
|
|
89
|
-
const getBasePath = (sourceDirectories) => {
|
|
94
|
+
const getBasePath = (sourceDirectories, inputBasePath) => {
|
|
95
|
+
// If there's a specific base path supplied, that takes precedence.
|
|
96
|
+
if (inputBasePath !== undefined) {
|
|
97
|
+
return inputBasePath;
|
|
98
|
+
}
|
|
90
99
|
// `common-path-prefix` returns an empty string when called with a single
|
|
91
100
|
// path, so we check for that case and return the path itself instead.
|
|
92
101
|
if (sourceDirectories.length === 1) {
|
package/dist/feature_flags.js
CHANGED
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/types.js
CHANGED
|
@@ -51,6 +51,7 @@ const getRemoteVersion = async (typesURL) => {
|
|
|
51
51
|
return version;
|
|
52
52
|
};
|
|
53
53
|
const writeVersionFile = async (deno, version) => {
|
|
54
|
+
await deno.ensureCacheDirectory();
|
|
54
55
|
const versionFilePath = join(deno.cacheDirectory, 'types-version.txt');
|
|
55
56
|
await fs.writeFile(versionFilePath, version);
|
|
56
57
|
};
|