@netlify/edge-bundler 1.10.0 → 1.11.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 CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { ExecaChildProcess } from 'execa';
2
3
  import { Logger } from './logger.js';
3
4
  declare type OnBeforeDownloadHook = () => void | Promise<void>;
@@ -17,6 +18,8 @@ interface ProcessRef {
17
18
  }
18
19
  interface RunOptions {
19
20
  pipeOutput?: boolean;
21
+ env?: NodeJS.ProcessEnv;
22
+ extendEnv?: boolean;
20
23
  }
21
24
  declare class DenoBridge {
22
25
  cacheDirectory: string;
@@ -41,9 +44,9 @@ declare class DenoBridge {
41
44
  global: boolean;
42
45
  path: string;
43
46
  }>;
44
- getEnvironmentVariables(): Record<string, string>;
45
- run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
46
- runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>;
47
+ getEnvironmentVariables(inputEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
48
+ run(args: string[], { pipeOutput, env: inputEnv, extendEnv }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>;
49
+ runInBackground(args: string[], ref?: ProcessRef, { pipeOutput, env: inputEnv, extendEnv }?: RunOptions): Promise<void>;
47
50
  }
48
51
  export { DenoBridge };
49
52
  export type { DenoOptions, OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef };
package/dist/bridge.js CHANGED
@@ -116,8 +116,8 @@ class DenoBridge {
116
116
  const downloadedPath = await this.getRemoteBinary();
117
117
  return { global: false, path: downloadedPath };
118
118
  }
119
- getEnvironmentVariables() {
120
- const env = {};
119
+ getEnvironmentVariables(inputEnv = {}) {
120
+ const env = { ...inputEnv };
121
121
  if (this.denoDir !== undefined) {
122
122
  env.DENO_DIR = this.denoDir;
123
123
  }
@@ -125,18 +125,18 @@ class DenoBridge {
125
125
  }
126
126
  // Runs the Deno CLI in the background and returns a reference to the child
127
127
  // process, awaiting its execution.
128
- async run(args, { pipeOutput } = {}) {
128
+ async run(args, { pipeOutput, env: inputEnv, extendEnv = true } = {}) {
129
129
  const { path: binaryPath } = await this.getBinaryPath();
130
- const env = this.getEnvironmentVariables();
131
- const options = { env };
130
+ const env = this.getEnvironmentVariables(inputEnv);
131
+ const options = { env, extendEnv };
132
132
  return DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
133
133
  }
134
134
  // Runs the Deno CLI in the background, assigning a reference of the child
135
135
  // process to a `ps` property in the `ref` argument, if one is supplied.
136
- async runInBackground(args, pipeOutput, ref) {
136
+ async runInBackground(args, ref, { pipeOutput, env: inputEnv, extendEnv = true } = {}) {
137
137
  const { path: binaryPath } = await this.getBinaryPath();
138
- const env = this.getEnvironmentVariables();
139
- const options = { env };
138
+ const env = this.getEnvironmentVariables(inputEnv);
139
+ const options = { env, extendEnv };
140
140
  const ps = DenoBridge.runWithBinary(binaryPath, args, options, pipeOutput);
141
141
  if (ref !== undefined) {
142
142
  // eslint-disable-next-line no-param-reassign
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
1
5
  import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js';
2
6
  import type { EdgeFunction } from '../edge_function.js';
3
7
  import { ImportMapFile } from '../import_map.js';
@@ -21,7 +25,7 @@ interface ServeOptions {
21
25
  port: number;
22
26
  systemLogger?: LogFunction;
23
27
  }
24
- declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[]) => Promise<{
28
+ declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[], env?: NodeJS.ProcessEnv) => Promise<{
25
29
  graph: any;
26
30
  success: boolean;
27
31
  }>>;
@@ -7,7 +7,7 @@ import { ensureLatestTypes } from '../types.js';
7
7
  import { killProcess, waitForServer } from './util.js';
8
8
  const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportTypeError, formatImportError, port, }) => {
9
9
  const processRef = {};
10
- const startIsolate = async (newFunctions) => {
10
+ const startIsolate = async (newFunctions, env = {}) => {
11
11
  if ((processRef === null || processRef === void 0 ? void 0 : processRef.ps) !== undefined) {
12
12
  await killProcess(processRef.ps);
13
13
  }
@@ -32,7 +32,14 @@ const prepareServer = ({ deno, distDirectory, flags: denoFlags, formatExportType
32
32
  // no-op
33
33
  }
34
34
  const bootstrapFlags = ['--port', port.toString()];
35
- await deno.runInBackground(['run', ...denoFlags, stage2Path, ...bootstrapFlags], true, processRef);
35
+ // We set `extendEnv: false` to avoid polluting the edge function context
36
+ // with variables from the user's system, since those will not be available
37
+ // in the production environment.
38
+ await deno.runInBackground(['run', ...denoFlags, stage2Path, ...bootstrapFlags], processRef, {
39
+ pipeOutput: true,
40
+ env,
41
+ extendEnv: false,
42
+ });
36
43
  const success = await waitForServer(port, processRef.ps);
37
44
  return {
38
45
  graph,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",